-
Notifications
You must be signed in to change notification settings - Fork 341
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
implement file locking: getlk/setlk/setlkw/flock #199
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
I signed it! |
CLAs look good, thanks! |
fuse/nodefs/api.go
Outdated
@@ -102,6 +102,11 @@ type Node interface { | |||
SetXAttr(attr string, data []byte, flags int, context *fuse.Context) fuse.Status | |||
ListXAttr(context *fuse.Context) (attrs []string, code fuse.Status) | |||
|
|||
// File locking | |||
GetLk(file File, owner uint64, lk *fuse.FileLock, flags uint32, padding uint32, out *fuse.FileLock, context *fuse.Context) (code fuse.Status) |
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.
padding should never be part of function signatures.
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.
Fixed
fuse/test/file_lock_test.go
Outdated
@@ -14,8 +14,7 @@ import ( | |||
"testing" | |||
) | |||
|
|||
// See https://github.com/hanwen/go-fuse/issues/170 | |||
func disabledTestFlock(t *testing.T) { | |||
func TestFlock(t *testing.T) { |
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.
this test was a nice try, but I don't trust it. Can you make something that implements a lock, and verifies that the user-space locking code gets called?
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.
Fixed
Hi, we also tested this with nfs v4 and locking works, so we would appreciate if this PR would be merged. |
Hi! Thanks for reminding me. I'll have a look this week
Op 16 mrt. 2018 20:22 schreef "Maria Shaldibina" <[email protected]>:
… Hi, we also tested this with nfs v4 and locking works, so we would
appreciate if this PR would be merged.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#199 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAB7O7CJOdZT9TyYPkVtzJiNkoac9u5pks5tfBD-gaJpZM4RfWdj>
.
|
r := fuse.ToStatus(syscall.Flock(int(f.File.Fd()), flags)) | ||
f.lock.Unlock() | ||
const ( | ||
F_OFD_GETLK = 36 |
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.
this looks like a syscall interface. Is this the same on OSX ? I would expect this defs to be a linux-specific file (I assume you wrote and tested this under linux.)
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.
We tested these constant on OSX and they seem to be working.
@@ -102,6 +102,11 @@ type Node interface { | |||
SetXAttr(attr string, data []byte, flags int, context *fuse.Context) fuse.Status | |||
ListXAttr(context *fuse.Context) (attrs []string, code fuse.Status) | |||
|
|||
// File locking |
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.
I know this wasn't documented well before, but could you add some more wording here? I guess Lkw locks for write and Lk is a concurrent (?) read lock? If you don't want to write docs, add a manpage reference.
default: | ||
return fuse.EINVAL | ||
} | ||
if !blocking { |
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 this is controlled from a field in the flags, why have the separate argument 'blocking' ?
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.
Given this signature:
setLock(owner uint64, lk *fuse.FileLock, flags uint32, blocking bool)
we understand your comment to mean that flags
will indicate whether the lock call should be blocking, or not.
So we tested this with the loopback mounter and flock, running:
flock -n /tmp/mnt1/foo -c 'echo bar'
and
flock /tmp/mnt1/foo -c 'echo bar'
and in fact
flock -x /tmp/mnt1/foo -c 'echo bar'
In all three cases the lk.Typ
and flags
were 0x1
.
It is entirely possible that we have misunderstood. We also haven't tested with fcntl
yet either but maybe this is why @kaoet added a blocking
flag. I think we agree that if flags
does indicate blocking then it is better to use those than duplicate the intention with an additional boolean but we can't see how it does. What are we missing?
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.
blocking is determined by SetLk vs SetLkw
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.
Since it is determined by which one of the methods was called (SetLk or SetLkw) and flags do not indicate whether it is blocking we have to pass a separate argument to setLock
method. Or we can collapse setLock
method into SetLk and SetLkw if that makes it more readable?
@@ -0,0 +1,125 @@ | |||
// Copyright 2016 the Go-FUSE Authors. All rights reserved. |
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.
2018
did you add your name to the AUTHORS file?
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.
Not sure who he is but we added his name to the authors file on his behalf. Hope that's ok with you Kaoet?
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.
I missed update to AUTHORs in your commit?
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.
done
} | ||
|
||
if out, err := runExternalFlock(cmd, tc.mountFile); !bytes.Contains(out, []byte("failed to get lock")) { | ||
t.Errorf("runExternalFlock(%q): %s (%v)", tc.mountFile, out, err) |
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.
use %q iso. %s. For []byte %s will use [1 2 3] as formatting.
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.
ping
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.
This test was slightly changed. Since on Ubuntu Trusty flock does not have a verbose option we can't assert an output. So we relaxed an assertion that command fails which in turn removed this Errorf
line.
https://github.com/hanwen/go-fuse/pull/220/files#diff-49306d0ec901b97786aec218f18ee349R21
defer f.Close() | ||
cmd := exec.Command(flockPath, "--verbose", "--exclusive", "--nonblock", "3") | ||
cmd.Env = append(cmd.Env, "LC_ALL=C") // in case the user's shell language is different | ||
cmd.ExtraFiles = []*os.File{f} |
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.
this needs some more comment. Why do you not pass the filename to the flock command line?
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.
ping
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.
|
||
node := &lockingNode{ | ||
Node: nodefs.NewDefaultNode(), | ||
flockInvoked: false, |
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.
drop (is implicit)
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.
Can you clarify? By drop (is implicit)
do you mean that flockinvoked
doesn't need to be set to false
because that's the default for a bool or ???
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.
correct. The default value is false, so no need to mention it.
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.
root.Inode().NewChild("foo", false, node) | ||
|
||
realPath := filepath.Join(dir, "foo") | ||
cmd:=exec.Command(flock, "--nonblock", realPath, "echo", "locked") |
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.
did you run gofmt?
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.
done
} | ||
if !node.flockInvoked { | ||
t.Fatalf("flock is not invoked") | ||
} |
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.
this test makes sure the locking really goes through FUSE (which is good), but I can't see the functionality of GetLk/SetLk/SetLkw tested separately. From the signatures, it seems one can have different locks on ranges of the file, and it would be good to exercise that too. Can you think of a way to add coverage for those features? Maybe you could record the ranges of the locks and verify they are as you expect?
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.
We added additional testing to ensure SetLk and SetLkw are called but we couldn't find a way to use flock to invoke GetLk. We tried cgo in an attempt to call fcntl.c but cgo isnt allowed in test files. Maybe you have some other ideas?
Let's use @paulcwarren 's PR. #220 |
Fix #170