-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix build on Plan 9 #17
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package fslock | ||
|
||
import "strings" | ||
|
||
// Opening an exclusive-use file returns an error. | ||
// The expected error strings are: | ||
// | ||
// - "open/create -- file is locked" (cwfs, kfs) | ||
// - "exclusive lock" (fossil) | ||
// - "exclusive use file already open" (ramfs) | ||
// | ||
// See https://github.com/golang/go/blob/go1.15rc1/src/cmd/go/internal/lockedfile/lockedfile_plan9.go#L16 | ||
var lockedErrStrings = [...]string{ | ||
"file is locked", | ||
"exclusive lock", | ||
"exclusive use file already open", | ||
} | ||
|
||
// isLockedPlan9 return whether an os.OpenFile error indicates that | ||
// a file with the ModeExclusive bit set is already open. | ||
func isLockedPlan9(s string) bool { | ||
for _, frag := range lockedErrStrings { | ||
if strings.Contains(s, frag) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
func lockedByOthers(err error) bool { | ||
s := err.Error() | ||
return strings.Contains(s, "Lock Create of") && isLockedPlan9(s) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// +build !plan9 | ||
|
||
package fslock | ||
|
||
import ( | ||
"strings" | ||
"syscall" | ||
) | ||
|
||
func lockedByOthers(err error) bool { | ||
return err == syscall.EAGAIN || strings.Contains(err.Error(), "resource temporarily unavailable") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree that the structure you've added here seems like a reasonable way to extend the lock function to plan9, and this follows the definitions in the standard library, so seems fine.
The one semantic thing I'm not clear on that is worth checking if you haven't yet, is that these errors will cover both the "someone else has the lock" error that they will trigger the overall
Lock
method returning, and thelock is already held by us
case in the main lock switch statement.I haven't looked to see if any of the callers of
Lock
do different things based on those errors, and my quick read at how plan9 is structuring its errors doesn't leave me overly optimistic that we'd be able to efficiently learn if the existing exclusive fid is in the same process, but it's probably worth checking to make sure there isn't code that's using those semantics.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the lock is held by us, we get this error:
If the lock is held by another process, we get this error:
I think I already distinguish between these two errors by checking if the error string contains "Lock Create of" (similar to
isLockCreatePermFail
function). We depends ongo4.org/lock
returning two kinds of errors, but I think it's good enough solution.