reexport lock fixes v3
Subsystems (4)
cover reexport lock fixes v3
From: "J. Bruce Fields" <[email protected]>
The following fix up some problems that can cause crashes or silently broken lock guarantees in the reexport case.
Note:
- patches 1-5 are server side
- patches 6-7 are client side
- patch 8 affects both
Simplest might be for Trond or Anna to ACK 6-8, if they look OK, and then submit them all through the server. But those three sets of patches are all independent if you'd rather split them up.
Not fixed:
- Attempts to reclaim locks after a reboot of the reexport server will fail. This at least seems like an improvement over the current situation, which is that they'll succeed even in cases where they shouldn't. Complete support for reboot recovery is a bigger job.
- NFSv4.1+ lock nofications don't work. So, clients have to poll as they do with NFSv4.0, which is suboptimal, but correct (and an improvement over the current situation, which is a kernel oops).
So what we have at this point is a suboptimal lock implementation that doesn't support lock recovery.
Another alternative might be to turn off file locking entirely in the re-export case. I'd rather take the incremental improvement and fix the oopses.
Change since v2:
- keep nlmsvc_file_inode a static inline to address build failure identified by the kernel test robot
Changes since v1:
- Use ENOGRACE instead of returning NFS-specific error from vfs lock method.
- Take write opens for write locks in the NLM case (as we always have in the NFSv4 case).
- Don't block NLM threads waiting for blocking locks.
With those changes I'm passing connecthon tests for NFSv3-4.2 reexports of an NFSv4.0 filesystem.
--b.
J. Bruce Fields (8):
lockd: lockd server-side shouldn't set fl_ops
nlm: minor nlm_lookup_file argument change
nlm: minor refactoring
lockd: update nlm_lookup_file reexport comment Keep read and write fds with each nlm_file
nfs: don't atempt blocking locks on nfs reexports
lockd: don't attempt blocking locks on nfs reexports
nfs: don't allow reexport reclaims
fs/lockd/svc4proc.c | 6 +- fs/lockd/svclock.c | 80 ++++++++++++++---------- fs/lockd/svcproc.c | 6 +- fs/lockd/svcsubs.c | 117 +++++++++++++++++++++++++----------- fs/nfs/export.c | 2 +- fs/nfs/file.c | 3 + fs/nfsd/lockd.c | 8 ++- fs/nfsd/nfs4state.c | 11 +++- fs/nfsd/nfsproc.c | 1 + include/linux/errno.h | 1 + include/linux/exportfs.h | 2 + include/linux/fs.h | 1 + include/linux/lockd/bind.h | 3 +- include/linux/lockd/lockd.h | 11 +++- 14 files changed, 170 insertions(+), 82 deletions(-)
Signature · 1 line
2.31.1
PATCH 1/8 lockd: lockd server-side shouldn't set fl_ops
From: "J. Bruce Fields" <[email protected]>
Locks have two sets of op arrays, fl_lmops for the lock manager (lockd or nfsd), fl_ops for the filesystem. The server-side lockd code has been setting its own fl_ops, which leads to confusion (and crashes) in the reexport case, where the filesystem expects to be the only one setting fl_ops.
And there's no reason for it that I can see-the lm_get/put_owner ops do the same job.
--- fs/lockd/svclock.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-)
fs/lockd/svclock.c +12 -18
@@ -395,28 +395,10 @@ nlmsvc_release_lockowner(struct nlm_lock *lock)nlmsvc_put_lockowner (lock->fl.fl_owner); } -static void nlmsvc_locks_copy_lock (struct file_lock *new,struct file_lock *fl) -{ -struct nlm_lockowner *nlm_lo = (struct nlm_lockowner *)fl->fl_owner; - new->fl_owner =nlmsvc_get_lockowner (nlm_lo); -} - -static void nlmsvc_locks_release_private (struct file_lock *fl) -{ -nlmsvc_put_lockowner ((struct nlm_lockowner *)fl->fl_owner); -} - -static const struct file_lock_operations nlmsvc_lock_ops = { - .fl_copy_lock = nlmsvc_locks_copy_lock, - .fl_release_private = nlmsvc_locks_release_private, -}; -void nlmsvc_locks_init_private (struct file_lock *fl,struct nlm_host *host,pid_t pid) { fl->fl_owner =nlmsvc_find_lockowner (host, pid); -if (fl->fl_owner !=NULL ) - fl->fl_ops = &nlmsvc_lock_ops; }/*
@@ -788,9 +770,21 @@ nlmsvc_notify_blocked(struct file_lock *fl)printk (KERN_WARNING "lockd: notification for unknown block!\n" ); } +static fl_owner_t nlmsvc_get_owner (fl_owner_t owner) +{ +return nlmsvc_get_lockowner (owner); +} + +static void nlmsvc_put_owner (fl_owner_t owner) +{ +nlmsvc_put_lockowner (owner); +} +const struct lock_manager_operations nlmsvc_lock_operations = { .lm_notify = nlmsvc_notify_blocked, .lm_grant = nlmsvc_grant_deferred, + .lm_get_owner = nlmsvc_get_owner, + .lm_put_owner = nlmsvc_put_owner, };/*
Signature · 1 line
2.31.1
PATCH 2/8 nlm: minor nlm_lookup_file argument change
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
It'll come in handy to get the whole nlm_lock.
--- fs/lockd/svc4proc.c | 2 +- fs/lockd/svcproc.c | 2 +- fs/lockd/svcsubs.c | 14 +++++++------- include/linux/lockd/lockd.h | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-)
fs/lockd/svc4proc.c +1 -1
@@ -40,7 +40,7 @@ nlm4svc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp,/* Obtain file pointer. Not used by FREE_ALL call. */ if (filp !=NULL ) { -if ((error =nlm_lookup_file (rqstp, &file, &lock->fh)) !=0 ) +if ((error =nlm_lookup_file (rqstp, &file, lock)) !=0 ) goto no_locks; *filp = file;
fs/lockd/svcproc.c +1 -1
@@ -69,7 +69,7 @@ nlmsvc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp,/* Obtain file pointer. Not used by FREE_ALL call. */ if (filp !=NULL ) { - error =cast_status (nlm_lookup_file (rqstp, &file, &lock->fh)); + error =cast_status (nlm_lookup_file (rqstp, &file, lock));if (error !=0 ) goto no_locks; *filp = file;
fs/lockd/svcsubs.c +7 -7
@@ -82,31 +82,31 @@ static inline unsigned int file_hash(struct nfs_fh *f)*/ __be32 nlm_lookup_file (struct svc_rqst *rqstp,struct nlm_file **result, -struct nfs_fh *f) +struct nlm_lock *lock) {struct nlm_file *file;unsigned int hash;__be32 nfserr; -nlm_debug_print_fh ("nlm_lookup_file" , f); +nlm_debug_print_fh ("nlm_lookup_file" , &lock->fh); - hash =file_hash (f); + hash =file_hash (&lock->fh);/* Lock file table */ mutex_lock (&nlm_file_mutex);hlist_for_each_entry (file, &nlm_files[hash], f_list) -if (!nfs_compare_fh (&file->f_handle, f)) +if (!nfs_compare_fh (&file->f_handle, &lock->fh)) goto found; -nlm_debug_print_fh ("creating file for" , f); +nlm_debug_print_fh ("creating file for" , &lock->fh); nfserr = nlm_lck_denied_nolocks; file =kzalloc (sizeof (*file),GFP_KERNEL );if (!file) goto out_unlock; -memcpy (&file->f_handle, f,sizeof (struct nfs_fh )); +memcpy (&file->f_handle, &lock->fh,sizeof (struct nfs_fh ));mutex_init (&file->f_mutex);INIT_HLIST_NODE (&file->f_list);INIT_LIST_HEAD (&file->f_blocks);
@@ -117,7 +117,7 @@ nlm_lookup_file(struct svc_rqst *rqstp, struct nlm_file **result,* We have to make sure we have the right credential to open * the file. */ -if ((nfserr = nlmsvc_ops->fopen (rqstp, f, &file->f_file)) !=0 ) { +if ((nfserr = nlmsvc_ops->fopen (rqstp, &lock->fh, &file->f_file)) !=0 ) {dprintk ("lockd: open failed (error %d)\n" , nfserr); goto out_free; }
include/linux/lockd/lockd.h +1 -1
@@ -286,7 +286,7 @@ void nlmsvc_locks_init_private(struct file_lock *, struct nlm_host *, pid_t);* File handling for the server personality */ __be32 nlm_lookup_file (struct svc_rqst *,struct nlm_file **, -struct nfs_fh *); +struct nlm_lock *);void nlm_release_file (struct nlm_file *);void nlmsvc_release_lockowner (struct nlm_lock *);void nlmsvc_mark_resources (struct net *);
Signature · 1 line
2.31.1
Re: [PATCH 2/8] nlm: minor nlm_lookup_file argument change
Quoted 21 lines · J. Bruce Fields
From: "J. Bruce Fields" <[email protected]>
It'll come in handy to get the whole
nlm_lock.Signed-off-by J. Bruce Fields <[email protected]>---
fs/lockd/svc4proc.c | 2 +- fs/lockd/svcproc.c | 2 +- fs/lockd/svcsubs.c | 14 +++++++------- include/linux/lockd/lockd.h | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-)fs/lockd/svc4proc.c +0
-0
fs/lockd/svc4proc.c nlm4svc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp, · line 43
Quoted 5 lines
fs/lockd/svc4proc.c +1
-1@@ -40,7 +40,7 @@ nlm4svc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp,/* Obtain file pointer. Not used by FREE_ALL call. */ if (filp !=NULL ) { -if ((error =nlm_lookup_file (rqstp, &file, &lock->fh)) !=0 ) +if ((error =nlm_lookup_file (rqstp, &file, lock)) !=0 )
Style: Replace the "assignment in if statement" in these spots, bitte?
Since we're dealing with a __be32 result, a direct comparison with "0" is misleading. It might be better documentation to go with:
error = nlm_lookup_file(rqstp, &file, lock);
if (error)Quoted 59 lines
fs/lockd/svc4proc.c +0
-0goto no_locks; *filp = file;fs/lockd/svcproc.c +1
-1@@ -69,7 +69,7 @@ nlmsvc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp,/* Obtain file pointer. Not used by FREE_ALL call. */ if (filp !=NULL ) { - error =cast_status (nlm_lookup_file (rqstp, &file, &lock->fh)); + error =cast_status (nlm_lookup_file (rqstp, &file, lock));if (error !=0 ) goto no_locks; *filp = file;fs/lockd/svcsubs.c +0
-0@@ -82,31 +82,31 @@ static inline unsigned int file_hash(struct nfs_fh *f)*/
__be32
nlm_lookup_file(structsvc_rqst*rqstp, structnlm_file**result,fs/lockd/svcsubs.c +1
-1- struct nfs_fh *f) + struct nlm_lock *lock){ struct nlm_file *file; unsigned int hash; __be32 nfserr;fs/lockd/svcsubs.c +2
-2-nlm_debug_print_fh ("nlm_lookup_file" , f); +nlm_debug_print_fh ("nlm_lookup_file" , &lock->fh); - hash =file_hash (f); + hash =file_hash (&lock->fh);/* Lock file table */ mutex_lock(&nlm_file_mutex); hlist_for_each_entry(file, &nlm_files[hash], f_list)fs/lockd/svcsubs.c +1
-1-if (!nfs_compare_fh (&file->f_handle, f)) +if (!nfs_compare_fh (&file->f_handle, &lock->fh))goto found;fs/lockd/svcsubs.c +1
-1-nlm_debug_print_fh ("creating file for" , f); +nlm_debug_print_fh ("creating file for" , &lock->fh);nfserr = nlm_lck_denied_nolocks; file = kzalloc(sizeof(*file), GFP_KERNEL); if (!file) goto out_unlock;fs/lockd/svcsubs.c +1
-1-memcpy (&file->f_handle, f,sizeof (struct nfs_fh )); +memcpy (&file->f_handle, &lock->fh,sizeof (struct nfs_fh ));mutex_init(&file->f_mutex); INIT_HLIST_NODE(&file->f_list); INIT_LIST_HEAD(&file->f_blocks);
fs/lockd/svcsubs.c nlm_lookup_file(struct svc_rqst *rqstp, struct nlm_file **result, · line 120
Quoted 5 lines
fs/lockd/svcsubs.c +1
-1@@ -117,7 +117,7 @@ nlm_lookup_file(struct svc_rqst *rqstp, struct nlm_file **result,* We have to make sure we have the right credential to open * the file. */ -if ((nfserr = nlmsvc_ops->fopen (rqstp, f, &file->f_file)) !=0 ) { +if ((nfserr = nlmsvc_ops->fopen (rqstp, &lock->fh, &file->f_file)) !=0 ) {
Ditto.
Quoted 19 lines
fs/lockd/svcsubs.c +0
-0dprintk ("lockd: open failed (error %d)\n" , nfserr); goto out_free; }include/linux/lockd/lockd.h +1
-1@@ -286,7 +286,7 @@ void nlmsvc_locks_init_private(struct file_lock *, struct nlm_host *, pid_t);* File handling for the server personality */ __be32 nlm_lookup_file (struct svc_rqst *,struct nlm_file **, -struct nfs_fh *); +struct nlm_lock *);void nlm_release_file (struct nlm_file *);void nlmsvc_release_lockowner (struct nlm_lock *);void nlmsvc_mark_resources (struct net *);Signature · 1 line
2.31.1
--
Chuck Lever
Re: [PATCH 2/8] nlm: minor nlm_lookup_file argument change
From: "J. Bruce Fields" <[email protected]>
Subject: [PATCH] nlm: minor style issue
Make the assignment separate.
--- fs/lockd/svc4proc.c | 3 ++- fs/lockd/svcsubs.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
Quoted 2 lines
Style: Replace the "assignment in if statement" in these spots, bitte?
Feel free to fold this in if you'd prefer.--b.
fs/lockd/svc4proc.c +2 -1
@@ -40,7 +40,8 @@ nlm4svc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp,/* Obtain file pointer. Not used by FREE_ALL call. */ if (filp !=NULL ) { -if ((error =nlm_lookup_file (rqstp, &file, lock)) !=0 ) + error =nlm_lookup_file (rqstp, &file, lock); +if (error) goto no_locks; *filp = file;
fs/lockd/svcsubs.c +2 -1
@@ -117,7 +117,8 @@ nlm_lookup_file(struct svc_rqst *rqstp, struct nlm_file **result,* We have to make sure we have the right credential to open * the file. */ -if ((nfserr = nlmsvc_ops->fopen (rqstp, &lock->fh, &file->f_file)) !=0 ) { + nfserr = nlmsvc_ops->fopen (rqstp, &lock->fh, &file->f_file); +if (nfserr) {dprintk ("lockd: open failed (error %d)\n" , nfserr); goto out_free; }
Signature · 1 line
2.31.1
Re: [PATCH 2/8] nlm: minor nlm_lookup_file argument change
Quoted 13 lines · J. Bruce Fields
From: "J. Bruce Fields" <[email protected]>
Subject: [PATCH] nlm: minor style issueMake the assignment separate.
Signed-off-by J. Bruce Fields <[email protected]>---
fs/lockd/svc4proc.c| 3 ++-fs/lockd/svcsubs.c| 3 ++-
Quoted 6 lines
2 files changed, 4 insertions(+), 2 deletions(-)Quoted 2 lines
Style: Replace the "assignment in if statement" in these spots, bitte?
Feel free to fold this in if you'd prefer.--b.
Squashed. However, this change conflicts with 5/8. I've fixed that up in my tree.
There are still several outstanding inline comments for 5/8, in case you missed those.
Quoted 31 lines
fs/lockd/svc4proc.c +2
-1@@ -40,7 +40,8 @@ nlm4svc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp,/* Obtain file pointer. Not used by FREE_ALL call. */ if (filp !=NULL ) { -if ((error =nlm_lookup_file (rqstp, &file, lock)) !=0 ) + error =nlm_lookup_file (rqstp, &file, lock); +if (error) goto no_locks; *filp = file;fs/lockd/svcsubs.c +2
-1@@ -117,7 +117,8 @@ nlm_lookup_file(struct svc_rqst *rqstp, struct nlm_file **result,* We have to make sure we have the right credential to open * the file. */ -if ((nfserr = nlmsvc_ops->fopen (rqstp, &lock->fh, &file->f_file)) !=0 ) { + nfserr = nlmsvc_ops->fopen (rqstp, &lock->fh, &file->f_file); +if (nfserr) {dprintk ("lockd: open failed (error %d)\n" , nfserr); goto out_free; }Signature · 1 line
2.31.1
--
Chuck Lever
Re: [PATCH 2/8] nlm: minor nlm_lookup_file argument change
Quoted 15 lines · Chuck Lever III
Quoted 15 lines · J. Bruce Fields
From: "J. Bruce Fields" <[email protected]>
Subject: [PATCH] nlm: minor style issueMake the assignment separate.
Signed-off-by J. Bruce Fields <[email protected]>---
fs/lockd/svc4proc.c| 3 ++-fs/lockd/svcsubs.c| 3 ++-2 files changed, 4 insertions(+), 2 deletions(-)
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Style: Replace the "assignment in if statement" in these spots, bitte?
Feel free to fold this in if you'd prefer.--b.
Squashed. However, this change conflicts with 5/8. I've fixed that up in my tree.
Thanks.
Quoted 2 lines
There are still several outstanding inline comments for 5/8, in case you missed those.
Whoops, I did. Looking....--b.
Quoted 38 lines
Quoted 33 lines
fs/lockd/svc4proc.c +2
-1@@ -40,7 +40,8 @@ nlm4svc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp,/* Obtain file pointer. Not used by FREE_ALL call. */ if (filp !=NULL ) { -if ((error =nlm_lookup_file (rqstp, &file, lock)) !=0 ) + error =nlm_lookup_file (rqstp, &file, lock); +if (error) goto no_locks; *filp = file;fs/lockd/svcsubs.c +2
-1@@ -117,7 +117,8 @@ nlm_lookup_file(struct svc_rqst *rqstp, struct nlm_file **result,* We have to make sure we have the right credential to open * the file. */ -if ((nfserr = nlmsvc_ops->fopen (rqstp, &lock->fh, &file->f_file)) !=0 ) { + nfserr = nlmsvc_ops->fopen (rqstp, &lock->fh, &file->f_file); +if (nfserr) {dprintk ("lockd: open failed (error %d)\n" , nfserr); goto out_free; }Signature · 1 line
2.31.1--
Chuck Lever
PATCH 3/8 nlm: minor refactoring
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
--- fs/lockd/svclock.c | 16 ++++++++-------- fs/lockd/svcsubs.c | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-)
fs/lockd/svclock.c +8 -8
@@ -474,8 +474,8 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file,__be32 ret; dprintk("lockd: nlmsvc_lock(%s/%ld, ty=%d, pi=%d, %Ld-%Ld, bl=%d)\n", - locks_inode(file->f_file)->i_sb->s_id, - locks_inode(file->f_file)->i_ino, + nlmsvc_file_inode(file)->i_sb->s_id, + nlmsvc_file_inode(file)->i_ino, lock->fl.fl_type, lock->fl.fl_pid, (long long)lock->fl.fl_start, (long long)lock->fl.fl_end,
@@ -581,8 +581,8 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,struct nlm_lockowner *test_owner;dprintk ("lockd: nlmsvc_testlock(%s/%ld, ty=%d, %Ld-%Ld)\n" , -locks_inode (file->f_file)->i_sb->s_id, -locks_inode (file->f_file)->i_ino, +nlmsvc_file_inode (file)->i_sb->s_id, +nlmsvc_file_inode (file)->i_ino, lock->fl.fl_type, (long long )lock->fl.fl_start, (long long )lock->fl.fl_end);
@@ -644,8 +644,8 @@ nlmsvc_unlock(struct net *net, struct nlm_file *file, struct nlm_lock *lock)int error;dprintk ("lockd: nlmsvc_unlock(%s/%ld, pi=%d, %Ld-%Ld)\n" , -locks_inode (file->f_file)->i_sb->s_id, -locks_inode (file->f_file)->i_ino, +nlmsvc_file_inode (file)->i_sb->s_id, +nlmsvc_file_inode (file)->i_ino, lock->fl.fl_pid, (long long )lock->fl.fl_start, (long long )lock->fl.fl_end);
@@ -673,8 +673,8 @@ nlmsvc_cancel_blocked(struct net *net, struct nlm_file *file, struct nlm_lock *lint status =0 ;dprintk ("lockd: nlmsvc_cancel(%s/%ld, pi=%d, %Ld-%Ld)\n" , -locks_inode (file->f_file)->i_sb->s_id, -locks_inode (file->f_file)->i_ino, +nlmsvc_file_inode (file)->i_sb->s_id, +nlmsvc_file_inode (file)->i_ino, lock->fl.fl_pid, (long long )lock->fl.fl_start, (long long )lock->fl.fl_end);
fs/lockd/svcsubs.c +2 -2
@@ -45,7 +45,7 @@ static inline void nlm_debug_print_fh(char *msg, struct nfs_fh *f)static inline void nlm_debug_print_file (char *msg,struct nlm_file *file) { -struct inode *inode =locks_inode (file->f_file); +struct inode *inode =nlmsvc_file_inode (file);dprintk ("lockd: %s %s/%ld\n" , msg, inode->i_sb->s_id, inode->i_ino);
@@ -415,7 +415,7 @@ nlmsvc_match_sb(void *datap, struct nlm_file *file) {struct super_block *sb = datap; -return sb ==locks_inode (file->f_file)->i_sb; +return sb ==nlmsvc_file_inode (file)->i_sb; }/**
Signature · 1 line
2.31.1
Re: [PATCH 3/8] nlm: minor refactoring
Quoted 5 lines · J. Bruce Fields
From: "J. Bruce Fields" <[email protected]>
Missing Signed-off-by?
And add just a little text that explains why this change is needed?
Quoted 78 lines
---
fs/lockd/svclock.c| 16 ++++++++--------fs/lockd/svcsubs.c| 4 ++--2 files changed, 10 insertions(+), 10 deletions(-)fs/lockd/svclock.c +8
-8@@ -474,8 +474,8 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file,__be32 ret; dprintk("lockd: nlmsvc_lock(%s/%ld, ty=%d, pi=%d, %Ld-%Ld, bl=%d)\n", - locks_inode(file->f_file)->i_sb->s_id, - locks_inode(file->f_file)->i_ino, + nlmsvc_file_inode(file)->i_sb->s_id, + nlmsvc_file_inode(file)->i_ino, lock->fl.fl_type, lock->fl.fl_pid, (long long)lock->fl.fl_start, (long long)lock->fl.fl_end,@@ -581,8 +581,8 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,struct nlm_lockowner *test_owner;dprintk ("lockd: nlmsvc_testlock(%s/%ld, ty=%d, %Ld-%Ld)\n" , -locks_inode (file->f_file)->i_sb->s_id, -locks_inode (file->f_file)->i_ino, +nlmsvc_file_inode (file)->i_sb->s_id, +nlmsvc_file_inode (file)->i_ino, lock->fl.fl_type, (long long )lock->fl.fl_start, (long long )lock->fl.fl_end);@@ -644,8 +644,8 @@ nlmsvc_unlock(struct net *net, struct nlm_file *file, struct nlm_lock *lock)int error;dprintk ("lockd: nlmsvc_unlock(%s/%ld, pi=%d, %Ld-%Ld)\n" , -locks_inode (file->f_file)->i_sb->s_id, -locks_inode (file->f_file)->i_ino, +nlmsvc_file_inode (file)->i_sb->s_id, +nlmsvc_file_inode (file)->i_ino, lock->fl.fl_pid, (long long )lock->fl.fl_start, (long long )lock->fl.fl_end);@@ -673,8 +673,8 @@ nlmsvc_cancel_blocked(struct net *net, struct nlm_file *file, struct nlm_lock *lint status =0 ;dprintk ("lockd: nlmsvc_cancel(%s/%ld, pi=%d, %Ld-%Ld)\n" , -locks_inode (file->f_file)->i_sb->s_id, -locks_inode (file->f_file)->i_ino, +nlmsvc_file_inode (file)->i_sb->s_id, +nlmsvc_file_inode (file)->i_ino, lock->fl.fl_pid, (long long )lock->fl.fl_start, (long long )lock->fl.fl_end);fs/lockd/svcsubs.c +2
-2@@ -45,7 +45,7 @@ static inline void nlm_debug_print_fh(char *msg, struct nfs_fh *f)static inline void nlm_debug_print_file (char *msg,struct nlm_file *file) { -struct inode *inode =locks_inode (file->f_file); +struct inode *inode =nlmsvc_file_inode (file);dprintk ("lockd: %s %s/%ld\n" , msg, inode->i_sb->s_id, inode->i_ino);@@ -415,7 +415,7 @@ nlmsvc_match_sb(void *datap, struct nlm_file *file) {struct super_block *sb = datap; -return sb ==locks_inode (file->f_file)->i_sb; +return sb ==nlmsvc_file_inode (file)->i_sb; }/** Signature · 1 line
2.31.1
--
Chuck Lever
Re: [PATCH 3/8] nlm: minor refactoring
From: "J. Bruce Fields" <[email protected]>
Subject: [PATCH] nlm: minor refactoring
Make this lookup slightly more concise, and prepare for changing how we look this up in a following patch.
--- fs/lockd/svclock.c | 16 ++++++++-------- fs/lockd/svcsubs.c | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-)
Quoted 3 lines
Missing Signed-off-by?
And add just a little text that explains why this change is needed?
Whoops, thanks, how about this?--b.
fs/lockd/svclock.c +8 -8
@@ -474,8 +474,8 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file,__be32 ret; dprintk("lockd: nlmsvc_lock(%s/%ld, ty=%d, pi=%d, %Ld-%Ld, bl=%d)\n", - locks_inode(file->f_file)->i_sb->s_id, - locks_inode(file->f_file)->i_ino, + nlmsvc_file_inode(file)->i_sb->s_id, + nlmsvc_file_inode(file)->i_ino, lock->fl.fl_type, lock->fl.fl_pid, (long long)lock->fl.fl_start, (long long)lock->fl.fl_end,
@@ -581,8 +581,8 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,struct nlm_lockowner *test_owner;dprintk ("lockd: nlmsvc_testlock(%s/%ld, ty=%d, %Ld-%Ld)\n" , -locks_inode (file->f_file)->i_sb->s_id, -locks_inode (file->f_file)->i_ino, +nlmsvc_file_inode (file)->i_sb->s_id, +nlmsvc_file_inode (file)->i_ino, lock->fl.fl_type, (long long )lock->fl.fl_start, (long long )lock->fl.fl_end);
@@ -644,8 +644,8 @@ nlmsvc_unlock(struct net *net, struct nlm_file *file, struct nlm_lock *lock)int error;dprintk ("lockd: nlmsvc_unlock(%s/%ld, pi=%d, %Ld-%Ld)\n" , -locks_inode (file->f_file)->i_sb->s_id, -locks_inode (file->f_file)->i_ino, +nlmsvc_file_inode (file)->i_sb->s_id, +nlmsvc_file_inode (file)->i_ino, lock->fl.fl_pid, (long long )lock->fl.fl_start, (long long )lock->fl.fl_end);
@@ -673,8 +673,8 @@ nlmsvc_cancel_blocked(struct net *net, struct nlm_file *file, struct nlm_lock *lint status =0 ;dprintk ("lockd: nlmsvc_cancel(%s/%ld, pi=%d, %Ld-%Ld)\n" , -locks_inode (file->f_file)->i_sb->s_id, -locks_inode (file->f_file)->i_ino, +nlmsvc_file_inode (file)->i_sb->s_id, +nlmsvc_file_inode (file)->i_ino, lock->fl.fl_pid, (long long )lock->fl.fl_start, (long long )lock->fl.fl_end);
fs/lockd/svcsubs.c +2 -2
@@ -45,7 +45,7 @@ static inline void nlm_debug_print_fh(char *msg, struct nfs_fh *f)static inline void nlm_debug_print_file (char *msg,struct nlm_file *file) { -struct inode *inode =locks_inode (file->f_file); +struct inode *inode =nlmsvc_file_inode (file);dprintk ("lockd: %s %s/%ld\n" , msg, inode->i_sb->s_id, inode->i_ino);
@@ -415,7 +415,7 @@ nlmsvc_match_sb(void *datap, struct nlm_file *file) {struct super_block *sb = datap; -return sb ==locks_inode (file->f_file)->i_sb; +return sb ==nlmsvc_file_inode (file)->i_sb; }/**
Signature · 1 line
2.31.1
PATCH 4/8 lockd: update nlm_lookup_file reexport comment
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
Update comment to reflect that we *do* allow reexport, whether it's a good idea or not....
--- fs/lockd/svcsubs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/lockd/svcsubs.c +3 -2
@@ -111,8 +111,9 @@ nlm_lookup_file(struct svc_rqst *rqstp, struct nlm_file **result,INIT_HLIST_NODE (&file->f_list);INIT_LIST_HEAD (&file->f_blocks); -/* Open the file. Note that this must not sleep for too long, else -* we would lock up lockd:-) So no NFS re-exports, folks. +/* +* Open the file. Note that if we're reexporting, for example, +* this could block the lockd thread for a while. * * We have to make sure we have the right credential to open * the file.
Signature · 1 line
2.31.1
PATCH 5/8 Keep read and write fds with each nlm_file
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
We shouldn't really be using a read-only file descriptor to take a write lock.
Most filesystems will put up with it. But NFS, for example, won't.
--- fs/lockd/svc4proc.c | 4 +- fs/lockd/svclock.c | 25 ++++++--- fs/lockd/svcproc.c | 4 +- fs/lockd/svcsubs.c | 104 +++++++++++++++++++++++++----------- fs/nfsd/lockd.c | 8 ++- include/linux/lockd/bind.h | 3 +- include/linux/lockd/lockd.h | 9 +++- 7 files changed, 114 insertions(+), 43 deletions(-)
fs/lockd/svc4proc.c +3 -1
@@ -40,12 +40,14 @@ nlm4svc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp,/* Obtain file pointer. Not used by FREE_ALL call. */ if (filp !=NULL ) { +int mode =lock_to_openmode (&lock->fl); +if ((error =nlm_lookup_file (rqstp, &file, lock)) !=0 ) goto no_locks; *filp = file;/* Set up the missing parts of the file_lock structure */ - lock->fl.fl_file = file->f_file; + lock->fl.fl_file = file->f_file[mode]; lock->fl.fl_pid = current->tgid; lock->fl.fl_lmops = &nlmsvc_lock_operations;nlmsvc_locks_init_private (&lock->fl, host, (pid_t )lock->svid);
fs/lockd/svclock.c +19 -6
@@ -471,6 +471,7 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file, {struct nlm_block *block =NULL ;int error; +int mode;__be32 ret; dprintk("lockd: nlmsvc_lock(%s/%ld, ty=%d, pi=%d, %Ld-%Ld, bl=%d)\n",
@@ -524,7 +525,8 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file,if (!wait) lock->fl.fl_flags &= ~FL_SLEEP ; - error =vfs_lock_file (file->f_file,F_SETLK , &lock->fl,NULL ); + mode =lock_to_openmode (&lock->fl); + error =vfs_lock_file (file->f_file[mode],F_SETLK , &lock->fl,NULL ); lock->fl.fl_flags &= ~FL_SLEEP ;dprintk ("lockd: vfs_lock_file returned %d\n" , error);
@@ -577,6 +579,7 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file, struct nlm_lock *conflock, struct nlm_cookie *cookie) { int error; +int mode;__be32 ret;struct nlm_lockowner *test_owner;
@@ -595,7 +598,8 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,/* If there's a conflicting lock, remember to clean up the test lock */ test_owner = (struct nlm_lockowner *)lock->fl.fl_owner; - error =vfs_test_lock (file->f_file, &lock->fl); + mode =lock_to_openmode (&lock->fl); + error =vfs_test_lock (file->f_file[mode], &lock->fl);if (error) {/* We can't currently deal with deferred test requests */ if (error ==FILE_LOCK_DEFERRED )
@@ -641,7 +645,7 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,__be32 nlmsvc_unlock (struct net *net,struct nlm_file *file,struct nlm_lock *lock) { -int error; +int error =0 ; dprintk("lockd: nlmsvc_unlock(%s/%ld, pi=%d, %Ld-%Ld)\n", nlmsvc_file_inode(file)->i_sb->s_id,
@@ -654,7 +658,12 @@ nlmsvc_unlock(struct net *net, struct nlm_file *file, struct nlm_lock *lock)nlmsvc_cancel_blocked (net, file, lock); lock->fl.fl_type =F_UNLCK ; - error =vfs_lock_file (file->f_file,F_SETLK , &lock->fl,NULL ); +if (file->f_file[0 ]) + error =vfs_lock_file (file->f_file[0 ],F_SETLK , + &lock->fl,NULL ); +if (file->f_file[1 ]) + error =vfs_lock_file (file->f_file[1 ],F_SETLK , + &lock->fl,NULL );return (error <0 )? nlm_lck_denied_nolocks : nlm_granted; }
@@ -671,6 +680,7 @@ nlmsvc_cancel_blocked(struct net *net, struct nlm_file *file, struct nlm_lock *l {struct nlm_block *block;int status =0 ; +int mode; dprintk("lockd: nlmsvc_cancel(%s/%ld, pi=%d, %Ld-%Ld)\n", nlmsvc_file_inode(file)->i_sb->s_id,
@@ -686,7 +696,8 @@ nlmsvc_cancel_blocked(struct net *net, struct nlm_file *file, struct nlm_lock *l block =nlmsvc_lookup_block (file, lock);mutex_unlock (&file->f_mutex);if (block !=NULL ) { -vfs_cancel_lock (block->b_file->f_file, + mode =lock_to_openmode (&lock->fl); +vfs_cancel_lock (block->b_file->f_file[mode], &block->b_call->a_args.lock.fl); status =nlmsvc_unlink_block (block);nlmsvc_release_block (block);
@@ -803,6 +814,7 @@ nlmsvc_grant_blocked(struct nlm_block *block) {struct nlm_file *file = block->b_file;struct nlm_lock *lock = &block->b_call->a_args.lock; +int mode;int error;loff_t fl_start, fl_end;
@@ -828,7 +840,8 @@ nlmsvc_grant_blocked(struct nlm_block *block) lock->fl.fl_flags |=FL_SLEEP ; fl_start = lock->fl.fl_start; fl_end = lock->fl.fl_end; - error =vfs_lock_file (file->f_file,F_SETLK , &lock->fl,NULL ); + mode =lock_to_openmode (&lock->fl); + error =vfs_lock_file (file->f_file[mode],F_SETLK , &lock->fl,NULL ); lock->fl.fl_flags &= ~FL_SLEEP ; lock->fl.fl_start = fl_start; lock->fl.fl_end = fl_end;
fs/lockd/svcproc.c +3 -1
@@ -55,6 +55,7 @@ nlmsvc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp,struct nlm_host *host =NULL ;struct nlm_file *file =NULL ;struct nlm_lock *lock = &argp->lock; +int mode;__be32 error =0 ;/* nfsd callbacks must have been installed for this procedure */
@@ -75,7 +76,8 @@ nlmsvc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp, *filp = file;/* Set up the missing parts of the file_lock structure */ - lock->fl.fl_file = file->f_file; + mode =lock_to_openmode (&lock->fl); + lock->fl.fl_file = file->f_file[mode]; lock->fl.fl_pid = current->tgid; lock->fl.fl_lmops = &nlmsvc_lock_operations;nlmsvc_locks_init_private (&lock->fl, host, (pid_t )lock->svid);
fs/lockd/svcsubs.c +74 -30
185 lines not on this page · raw message
fs/nfsd/lockd.c +6 -2
@@ -25,9 +25,11 @@* Note: we hold the dentry use count while the file is open. */ static __be32 -nlm_fopen (struct svc_rqst *rqstp,struct nfs_fh *f,struct file **filp) +nlm_fopen (struct svc_rqst *rqstp,struct nfs_fh *f,struct file **filp, +int mode) {__be32 nfserr; +int access;struct svc_fh fh;/* must initialize before using! but maxsize doesn't matter */
@@ -36,7 +38,9 @@ nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, struct file **filp)memcpy ((char *)&fh.fh_handle.fh_base, f->data, f->size); fh.fh_export =NULL ; - nfserr =nfsd_open (rqstp, &fh,S_IFREG ,NFSD_MAY_LOCK , filp); + access = (mode ==O_WRONLY ) ?NFSD_MAY_WRITE :NFSD_MAY_READ ; + access |=NFSD_MAY_LOCK ; + nfserr =nfsd_open (rqstp, &fh,S_IFREG , access, filp);fh_put (&fh);/* We return nlm error codes as nlm doesn't know * about nfsd, but nfsd does know about nlm..
include/linux/lockd/bind.h +2 -1
@@ -27,7 +27,8 @@ struct rpc_task;struct nlmsvc_binding {__be32 (*fopen)(struct svc_rqst *,struct nfs_fh *, -struct file **); +struct file **, +int mode);void (*fclose)(struct file *); };
include/linux/lockd/lockd.h +7 -2
@@ -10,6 +10,8 @@#ifndef LINUX_LOCKD_LOCKD_H #define LINUX_LOCKD_LOCKD_H +/* XXX: a lot of this should really be under fs/lockd. */ +#include <linux/in.h> #include <linux/in6.h> #include <net/ipv6.h>
@@ -154,7 +156,8 @@ struct nlm_rqst {struct nlm_file {struct hlist_node f_list;/* linked list */ struct nfs_fh f_handle;/* NFS file handle */ -struct file * f_file;/* VFS file pointer */ +struct file * f_file[2 ];/* VFS file pointers, +indexed by O_ flags */ struct nlm_share * f_shares;/* DOS shares */ struct list_head f_blocks;/* blocked locks */ unsigned int f_locks;/* guesstimate # of locks */
@@ -267,6 +270,7 @@ typedef int (*nlm_host_match_fn_t)(void *cur, struct nlm_host *ref);/* * Server-side lock handling */ +int lock_to_openmode (struct file_lock *);__be32 nlmsvc_lock (struct svc_rqst *,struct nlm_file *,struct nlm_host *,struct nlm_lock *,int ,struct nlm_cookie *,int );
@@ -301,7 +305,8 @@ int nlmsvc_unlock_all_by_ip(struct sockaddr *server_addr);static inline struct inode *nlmsvc_file_inode (struct nlm_file *file) { -return locks_inode (file->f_file); +return locks_inode (file->f_file[0 ] ? + file->f_file[0 ] : file->f_file[1 ]); }static inline int __nlm_privileged_request4 (const struct sockaddr *sap)
Signature · 1 line
2.31.1
Re: [PATCH 5/8] Keep read and write fds with each nlm_file
Nit: short description should start with "nlm:"
Quoted 8 lines · J. Bruce Fields
From: "J. Bruce Fields" <[email protected]>
We shouldn't really be using a read-only file descriptor to take a write lock.
Most filesystems will put up with it. But NFS, for example, won't.
Two overall concerns:
1. Would it be easy/possible to split this patch further?
2. What kind of testing would provide a level of confidence that no regressions have been introduced by this change?
Quoted 81 lines
Signed-off-by J. Bruce Fields <[email protected]>---
fs/lockd/svc4proc.c | 4 +- fs/lockd/svclock.c | 25 ++++++--- fs/lockd/svcproc.c | 4 +- fs/lockd/svcsubs.c | 104 +++++++++++++++++++++++++----------- fs/nfsd/lockd.c | 8 ++- include/linux/lockd/bind.h | 3 +- include/linux/lockd/lockd.h | 9 +++- 7 files changed, 114 insertions(+), 43 deletions(-)fs/lockd/svc4proc.c +3
-1@@ -40,12 +40,14 @@ nlm4svc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp,/* Obtain file pointer. Not used by FREE_ALL call. */ if (filp !=NULL ) { +int mode =lock_to_openmode (&lock->fl); +if ((error =nlm_lookup_file (rqstp, &file, lock)) !=0 ) goto no_locks; *filp = file;/* Set up the missing parts of the file_lock structure */ - lock->fl.fl_file = file->f_file; + lock->fl.fl_file = file->f_file[mode]; lock->fl.fl_pid = current->tgid; lock->fl.fl_lmops = &nlmsvc_lock_operations;nlmsvc_locks_init_private (&lock->fl, host, (pid_t )lock->svid);fs/lockd/svclock.c +6
-2@@ -471,6 +471,7 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file, {struct nlm_block *block =NULL ;int error; +int mode;__be32 ret; dprintk("lockd: nlmsvc_lock(%s/%ld, ty=%d, pi=%d, %Ld-%Ld, bl=%d)\n",@@ -524,7 +525,8 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file,if (!wait) lock->fl.fl_flags &= ~FL_SLEEP ; - error =vfs_lock_file (file->f_file,F_SETLK , &lock->fl,NULL ); + mode =lock_to_openmode (&lock->fl); + error =vfs_lock_file (file->f_file[mode],F_SETLK , &lock->fl,NULL ); lock->fl.fl_flags &= ~FL_SLEEP ;dprintk ("lockd: vfs_lock_file returned %d\n" , error);@@ -577,6 +579,7 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file, struct nlm_lock *conflock, struct nlm_cookie *cookie) { int error; +int mode;__be32 ret;struct nlm_lockowner *test_owner;@@ -595,7 +598,8 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,/* If there's a conflicting lock, remember to clean up the test lock */ test_owner = (struct nlm_lockowner *)lock->fl.fl_owner; - error =vfs_test_lock (file->f_file, &lock->fl); + mode =lock_to_openmode (&lock->fl); + error =vfs_test_lock (file->f_file[mode], &lock->fl);if (error) {/* We can't currently deal with deferred test requests */ if (error ==FILE_LOCK_DEFERRED )@@ -641,7 +645,7 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,
__be32nlmsvc_unlock(struct net *net, struct nlm_file *file, struct nlm_lock *lock){fs/lockd/svclock.c +1
-1-int error; +int error =0 ;dprintk("lockd: nlmsvc_unlock(%s/%ld, pi=%d, %Ld-%Ld)\n", nlmsvc_file_inode(file)->i_sb->s_id,
fs/lockd/svclock.c nlmsvc_unlock(struct net *net, struct nlm_file *file, struct nlm_lock *lock) · line 666
Quoted 10 lines
fs/lockd/svclock.c +6
-1@@ -654,7 +658,12 @@ nlmsvc_unlock(struct net *net, struct nlm_file *file, struct nlm_lock *lock)nlmsvc_cancel_blocked (net, file, lock); lock->fl.fl_type =F_UNLCK ; - error =vfs_lock_file (file->f_file,F_SETLK , &lock->fl,NULL ); +if (file->f_file[0 ]) + error =vfs_lock_file (file->f_file[0 ],F_SETLK , + &lock->fl,NULL ); +if (file->f_file[1 ]) + error =vfs_lock_file (file->f_file[1 ],F_SETLK , + &lock->fl,NULL );
Eschew raw integers :-) Should the f_file array be indexed using O_ flags as the comment below suggests?
Quoted 65 lines
fs/lockd/svclock.c +6
-2return (error <0 )? nlm_lck_denied_nolocks : nlm_granted; }@@ -671,6 +680,7 @@ nlmsvc_cancel_blocked(struct net *net, struct nlm_file *file, struct nlm_lock *l {struct nlm_block *block;int status =0 ; +int mode; dprintk("lockd: nlmsvc_cancel(%s/%ld, pi=%d, %Ld-%Ld)\n", nlmsvc_file_inode(file)->i_sb->s_id,@@ -686,7 +696,8 @@ nlmsvc_cancel_blocked(struct net *net, struct nlm_file *file, struct nlm_lock *l block =nlmsvc_lookup_block (file, lock);mutex_unlock (&file->f_mutex);if (block !=NULL ) { -vfs_cancel_lock (block->b_file->f_file, + mode =lock_to_openmode (&lock->fl); +vfs_cancel_lock (block->b_file->f_file[mode], &block->b_call->a_args.lock.fl); status =nlmsvc_unlink_block (block);nlmsvc_release_block (block);@@ -803,6 +814,7 @@ nlmsvc_grant_blocked(struct nlm_block *block) {struct nlm_file *file = block->b_file;struct nlm_lock *lock = &block->b_call->a_args.lock; +int mode;int error;loff_t fl_start, fl_end;@@ -828,7 +840,8 @@ nlmsvc_grant_blocked(struct nlm_block *block) lock->fl.fl_flags |=FL_SLEEP ; fl_start = lock->fl.fl_start; fl_end = lock->fl.fl_end; - error =vfs_lock_file (file->f_file,F_SETLK , &lock->fl,NULL ); + mode =lock_to_openmode (&lock->fl); + error =vfs_lock_file (file->f_file[mode],F_SETLK , &lock->fl,NULL ); lock->fl.fl_flags &= ~FL_SLEEP ; lock->fl.fl_start = fl_start; lock->fl.fl_end = fl_end;fs/lockd/svcproc.c +3
-1@@ -55,6 +55,7 @@ nlmsvc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp,struct nlm_host *host =NULL ;struct nlm_file *file =NULL ;struct nlm_lock *lock = &argp->lock; +int mode;__be32 error =0 ;/* nfsd callbacks must have been installed for this procedure */ @@ -75,7 +76,8 @@ nlmsvc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp, *filp = file;/* Set up the missing parts of the file_lock structure */ - lock->fl.fl_file = file->f_file; + mode =lock_to_openmode (&lock->fl); + lock->fl.fl_file = file->f_file[mode]; lock->fl.fl_pid = current->tgid; lock->fl.fl_lmops = &nlmsvc_lock_operations;nlmsvc_locks_init_private (&lock->fl, host, (pid_t )lock->svid);fs/lockd/svcsubs.c +0
-0
fs/lockd/svcsubs.c static inline unsigned int file_hash(struct nfs_fh *f) · line 79
Quoted 9 lines
fs/lockd/svcsubs.c +6
-0@@ -71,14 +71,38 @@ static inline unsigned int file_hash(struct nfs_fh *f)return tmp & (FILE_NRHASH -1 ); } +int lock_to_openmode (struct file_lock *lock) +{ +if (lock->fl_type ==F_WRLCK ) +return O_WRONLY ; +else +return O_RDONLY ;
Style: a ternary would be more consistent with other areas of the code you change in this patch.
Quoted 112 lines
fs/lockd/svcsubs.c +23
-5+} + +/* +* Open the file. Note that if we're reexporting, for example, +* this could block the lockd thread for a while. +* +* We have to make sure we have the right credential to open +* the file. +*/ +static __be32 nlm_do_fopen (struct svc_rqst *rqstp, +struct nlm_file *file,int mode) +{ +struct file **fp = &file->f_file[mode]; +__be32 nfserr; + +if (*fp) +return 0 ; + nfserr = nlmsvc_ops->fopen (rqstp, &file->f_handle, fp, mode); +if (nfserr) +dprintk ("lockd: open failed (error %d)\n" , nfserr); +return nfserr; +} +/* * Lookup file info. If it doesn't exist, create a file info struct * and open a (VFS) file for the given inode. -* -* FIXME: -* Note that we open the file O_RDONLY even when creating write locks. -* This is not quite right, but for now, we assume the client performs -* the proper R/W checking. */
__be32
nlm_lookup_file(structsvc_rqst*rqstp, structnlm_file**result,fs/lockd/svcsubs.c +11
-15@@ -87,41 +111,38 @@ nlm_lookup_file(struct svc_rqst *rqstp, struct nlm_file **result,struct nlm_file *file;unsigned int hash;__be32 nfserr; +int mode;nlm_debug_print_fh ("nlm_lookup_file" , &lock->fh); hash =file_hash (&lock->fh); + mode =lock_to_openmode (&lock->fl);/* Lock file table */ mutex_lock (&nlm_file_mutex);hlist_for_each_entry (file, &nlm_files[hash], f_list) -if (!nfs_compare_fh (&file->f_handle, &lock->fh)) +if (!nfs_compare_fh (&file->f_handle, &lock->fh)) { +mutex_lock (&file->f_mutex); + nfserr =nlm_do_fopen (rqstp, file, mode); +mutex_unlock (&file->f_mutex); goto found; - + }nlm_debug_print_fh ("creating file for" , &lock->fh); nfserr = nlm_lck_denied_nolocks; file =kzalloc (sizeof (*file),GFP_KERNEL );if (!file) - goto out_unlock; + goto out_free;memcpy (&file->f_handle, &lock->fh,sizeof (struct nfs_fh ));mutex_init (&file->f_mutex);INIT_HLIST_NODE (&file->f_list);INIT_LIST_HEAD (&file->f_blocks); -/* -* Open the file. Note that if we're reexporting, for example, -* this could block the lockd thread for a while. -* -* We have to make sure we have the right credential to open -* the file. -*/ -if ((nfserr = nlmsvc_ops->fopen (rqstp, &lock->fh, &file->f_file)) !=0 ) { -dprintk ("lockd: open failed (error %d)\n" , nfserr); - goto out_free; - } + nfserr =nlm_do_fopen (rqstp, file, mode); +if (nfserr) + goto out_unlock;hlist_add_head (&file->f_list, &nlm_files[hash]);@@ -129,7 +150,6 @@ nlm_lookup_file(struct svc_rqst *rqstp, struct nlm_file **result,dprintk ("lockd: found file %p (count %d)\n" , file, file->f_count); *result = file; file->f_count++; - nfserr =0 ;
out_unlock:mutex_unlock(&nlm_file_mutex);fs/lockd/svcsubs.c +6
-1@@ -149,13 +169,34 @@ nlm_delete_file(struct nlm_file *file)nlm_debug_print_file ("closing file" , file);if (!hlist_unhashed (&file->f_list)) {hlist_del (&file->f_list); - nlmsvc_ops->fclose (file->f_file); +if (file->f_file[O_RDONLY ]) + nlmsvc_ops->fclose (file->f_file[O_RDONLY ]); +if (file->f_file[O_WRONLY ]) + nlmsvc_ops->fclose (file->f_file[O_WRONLY ]);kfree (file); }else {printk (KERN_WARNING "lockd: attempt to release unknown file!\n" ); } } +static int nlm_unlock_files (struct nlm_file *file) +{
fs/lockd/svcsubs.c nlm_delete_file(struct nlm_file *file) · line 193
Quoted 10 lines
fs/lockd/svcsubs.c +10
-0+struct file_lock lock; +struct file *f; + + lock.fl_type =F_UNLCK ; + lock.fl_start =0 ; + lock.fl_end =OFFSET_MAX ; +for (f = file->f_file[0 ]; f <= file->f_file[1 ]; f++) { +if (f &&vfs_lock_file (f,F_SETLK , &lock,NULL ) <0 ) { +printk ("lockd: unlock failure in %s:%d\n" , + __FILE__, __LINE__);
This needs a KERN_LEVEL and maybe a _once.
Quoted 94 lines
fs/lockd/svcsubs.c +18
-9+return 1 ; + } + } +return 0 ; +} +/* * Loop over all locks on the given file and perform the specified * action. @@ -183,17 +224,10 @@ nlm_traverse_locks(struct nlm_host *host, struct nlm_file *file, lockhost = ((struct nlm_lockowner *)fl->fl_owner)->host;if (match (lockhost, host)) { -struct file_lock lock = *fl;spin_unlock (&flctx->flc_lock); - lock.fl_type =F_UNLCK ; - lock.fl_start =0 ; - lock.fl_end =OFFSET_MAX ; -if (vfs_lock_file (file->f_file,F_SETLK , &lock,NULL ) <0 ) { -printk ("lockd: unlock failure in %s:%d\n" , - __FILE__, __LINE__); +if (nlm_unlock_files (file))return 1 ; - } goto again; } }@@ -247,6 +281,15 @@ nlm_file_inuse(struct nlm_file *file)return 0 ; } +static void nlm_close_files (struct nlm_file *file) +{ +struct file *f; + +for (f = file->f_file[0 ]; f <= file->f_file[1 ]; f++) +if (f) + nlmsvc_ops->fclose (f); +} +/* * Loop over all files in the file table. */ @@ -277,7 +320,7 @@ nlm_traverse_files(void *data, nlm_host_match_fn_t match,if (list_empty (&file->f_blocks) && !file->f_locks && !file->f_shares && !file->f_count) {hlist_del (&file->f_list); - nlmsvc_ops->fclose (file->f_file); +nlm_close_files (file);kfree (file); } }@@ -411,6 +454,7 @@ nlmsvc_invalidate_all(void)nlm_traverse_files (NULL , nlmsvc_is_client,NULL ); } +static int
nlmsvc_match_sb(void *datap, struct nlm_file *file){fs/nfsd/lockd.c +0
-0@@ -25,9 +25,11 @@* Note: we hold the dentry use count while the file is open. */ static
__be32fs/nfsd/lockd.c +2
-1-nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, struct file **filp) +nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, struct file **filp, + int mode){ __be32 nfserr;fs/nfsd/lockd.c +1
-0+int access;struct svc_fh fh; /* must initialize before using! but maxsize doesn't matter */fs/nfsd/lockd.c +3
-1@@ -36,7 +38,9 @@ nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, struct file **filp)memcpy ((char *)&fh.fh_handle.fh_base, f->data, f->size); fh.fh_export =NULL ; - nfserr =nfsd_open (rqstp, &fh,S_IFREG ,NFSD_MAY_LOCK , filp); + access = (mode ==O_WRONLY ) ?NFSD_MAY_WRITE :NFSD_MAY_READ ; + access |=NFSD_MAY_LOCK ; + nfserr =nfsd_open (rqstp, &fh,S_IFREG , access, filp);fh_put (&fh);/* We return nlm error codes as nlm doesn't know * about nfsd, but nfsd does know about nlm.. include/linux/lockd/bind.h +0
-0
include/linux/lockd/bind.h struct rpc_task; · line 31
Quoted 6 lines
include/linux/lockd/bind.h +2
-1@@ -27,7 +27,8 @@ struct rpc_task;struct nlmsvc_binding {__be32 (*fopen)(struct svc_rqst *,struct nfs_fh *, -struct file **); +struct file **, +int mode);
Style: "mode_t mode" might be better internal documentation.
Quoted 17 lines
include/linux/lockd/bind.h +0
-0void (*fclose)(struct file *); };include/linux/lockd/lockd.h +2
-0@@ -10,6 +10,8 @@#ifndef LINUX_LOCKD_LOCKD_H #define LINUX_LOCKD_LOCKD_H +/* XXX: a lot of this should really be under fs/lockd. */ +#include <linux/in.h> #include <linux/in6.h> #include <net/ipv6.h>
include/linux/lockd/lockd.h struct nlm_rqst { · line 160
Quoted 6 lines
include/linux/lockd/lockd.h +2
-1@@ -154,7 +156,8 @@ struct nlm_rqst {struct nlm_file {struct hlist_node f_list;/* linked list */ struct nfs_fh f_handle;/* NFS file handle */ -struct file * f_file;/* VFS file pointer */ +struct file * f_file[2 ];/* VFS file pointers, +indexed by O_ flags */
Right, except that the new code in this patch always indexes f_file with raw integers, making the comment misleading. My preference is to keep the comment and change the new code to index f_file symbolically.
Quoted 24 lines
include/linux/lockd/lockd.h +3
-1struct nlm_share * f_shares;/* DOS shares */ struct list_head f_blocks;/* blocked locks */ unsigned int f_locks;/* guesstimate # of locks */ @@ -267,6 +270,7 @@ typedef int (*nlm_host_match_fn_t)(void *cur, struct nlm_host *ref);/* * Server-side lock handling */ +int lock_to_openmode (struct file_lock *);__be32 nlmsvc_lock (struct svc_rqst *,struct nlm_file *,struct nlm_host *,struct nlm_lock *,int ,struct nlm_cookie *,int );@@ -301,7 +305,8 @@ int nlmsvc_unlock_all_by_ip(struct sockaddr *server_addr);static inline struct inode *nlmsvc_file_inode (struct nlm_file *file) { -return locks_inode (file->f_file); +return locks_inode (file->f_file[0 ] ? + file->f_file[0 ] : file->f_file[1 ]); }static inline int __nlm_privileged_request4 (const struct sockaddr *sap)Signature · 1 line
2.31.1
--
Chuck Lever
Re: [PATCH 5/8] Keep read and write fds with each nlm_file
Quoted 7 lines · Chuck Lever III
Nit: short description should start with "nlm:"
Quoted 4 lines · J. Bruce Fields
From: "J. Bruce Fields" <[email protected]>
Quoted 8 lines
Quoted 4 lines
We shouldn't really be using a read-only file descriptor to take a write lock.
Most filesystems will put up with it. But NFS, for example, won't.
Two overall concerns:
1. Would it be easy/possible to split this patch further?
I'm not sure.
Quoted 2 lines
2. What kind of testing would provide a level of confidence that no regressions have been introduced by this change?
I've just run my usual tests; the only ones relevant to this are "cthon -a" over v3 (with and without krb5), and a few tests of my own I wrote for some long-ago regressions
(http://git.linux-nfs.org/?p=bfields/lock-tests.git;a=summary).
(And I also did the same over v3 re-export of a 4.2 mount, but that's more to check for the fix than for regressions.)
--b.
Quoted 466 lines
Quoted 83 lines
Signed-off-by J. Bruce Fields <[email protected]>---
fs/lockd/svc4proc.c | 4 +- fs/lockd/svclock.c | 25 ++++++--- fs/lockd/svcproc.c | 4 +- fs/lockd/svcsubs.c | 104 +++++++++++++++++++++++++----------- fs/nfsd/lockd.c | 8 ++- include/linux/lockd/bind.h | 3 +- include/linux/lockd/lockd.h | 9 +++- 7 files changed, 114 insertions(+), 43 deletions(-)fs/lockd/svc4proc.c +3
-1@@ -40,12 +40,14 @@ nlm4svc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp,/* Obtain file pointer. Not used by FREE_ALL call. */ if (filp !=NULL ) { +int mode =lock_to_openmode (&lock->fl); +if ((error =nlm_lookup_file (rqstp, &file, lock)) !=0 ) goto no_locks; *filp = file;/* Set up the missing parts of the file_lock structure */ - lock->fl.fl_file = file->f_file; + lock->fl.fl_file = file->f_file[mode]; lock->fl.fl_pid = current->tgid; lock->fl.fl_lmops = &nlmsvc_lock_operations;nlmsvc_locks_init_private (&lock->fl, host, (pid_t )lock->svid);fs/lockd/svclock.c +6
-2@@ -471,6 +471,7 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file, {struct nlm_block *block =NULL ;int error; +int mode;__be32 ret; dprintk("lockd: nlmsvc_lock(%s/%ld, ty=%d, pi=%d, %Ld-%Ld, bl=%d)\n",@@ -524,7 +525,8 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file,if (!wait) lock->fl.fl_flags &= ~FL_SLEEP ; - error =vfs_lock_file (file->f_file,F_SETLK , &lock->fl,NULL ); + mode =lock_to_openmode (&lock->fl); + error =vfs_lock_file (file->f_file[mode],F_SETLK , &lock->fl,NULL ); lock->fl.fl_flags &= ~FL_SLEEP ;dprintk ("lockd: vfs_lock_file returned %d\n" , error);@@ -577,6 +579,7 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file, struct nlm_lock *conflock, struct nlm_cookie *cookie) { int error; +int mode;__be32 ret;struct nlm_lockowner *test_owner;@@ -595,7 +598,8 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,/* If there's a conflicting lock, remember to clean up the test lock */ test_owner = (struct nlm_lockowner *)lock->fl.fl_owner; - error =vfs_test_lock (file->f_file, &lock->fl); + mode =lock_to_openmode (&lock->fl); + error =vfs_test_lock (file->f_file[mode], &lock->fl);if (error) {/* We can't currently deal with deferred test requests */ if (error ==FILE_LOCK_DEFERRED )@@ -641,7 +645,7 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,
__be32nlmsvc_unlock(struct net *net, struct nlm_file *file, struct nlm_lock *lock){fs/lockd/svclock.c +1
-1-int error; +int error =0 ;dprintk("lockd: nlmsvc_unlock(%s/%ld, pi=%d, %Ld-%Ld)\n", nlmsvc_file_inode(file)->i_sb->s_id,fs/lockd/svclock.c nlmsvc_unlock(struct net *net, struct nlm_file *file, struct nlm_lock *lock) · line 666
Quoted 10 lines
fs/lockd/svclock.c +6
-1@@ -654,7 +658,12 @@ nlmsvc_unlock(struct net *net, struct nlm_file *file, struct nlm_lock *lock)nlmsvc_cancel_blocked (net, file, lock); lock->fl.fl_type =F_UNLCK ; - error =vfs_lock_file (file->f_file,F_SETLK , &lock->fl,NULL ); +if (file->f_file[0 ]) + error =vfs_lock_file (file->f_file[0 ],F_SETLK , + &lock->fl,NULL ); +if (file->f_file[1 ]) + error =vfs_lock_file (file->f_file[1 ],F_SETLK , + &lock->fl,NULL );Eschew raw integers :-) Should the
f_filearray be indexed using O_ flags as the comment below suggests?Quoted 65 lines
fs/lockd/svclock.c +6
-2return (error <0 )? nlm_lck_denied_nolocks : nlm_granted; }@@ -671,6 +680,7 @@ nlmsvc_cancel_blocked(struct net *net, struct nlm_file *file, struct nlm_lock *l {struct nlm_block *block;int status =0 ; +int mode; dprintk("lockd: nlmsvc_cancel(%s/%ld, pi=%d, %Ld-%Ld)\n", nlmsvc_file_inode(file)->i_sb->s_id,@@ -686,7 +696,8 @@ nlmsvc_cancel_blocked(struct net *net, struct nlm_file *file, struct nlm_lock *l block =nlmsvc_lookup_block (file, lock);mutex_unlock (&file->f_mutex);if (block !=NULL ) { -vfs_cancel_lock (block->b_file->f_file, + mode =lock_to_openmode (&lock->fl); +vfs_cancel_lock (block->b_file->f_file[mode], &block->b_call->a_args.lock.fl); status =nlmsvc_unlink_block (block);nlmsvc_release_block (block);@@ -803,6 +814,7 @@ nlmsvc_grant_blocked(struct nlm_block *block) {struct nlm_file *file = block->b_file;struct nlm_lock *lock = &block->b_call->a_args.lock; +int mode;int error;loff_t fl_start, fl_end;@@ -828,7 +840,8 @@ nlmsvc_grant_blocked(struct nlm_block *block) lock->fl.fl_flags |=FL_SLEEP ; fl_start = lock->fl.fl_start; fl_end = lock->fl.fl_end; - error =vfs_lock_file (file->f_file,F_SETLK , &lock->fl,NULL ); + mode =lock_to_openmode (&lock->fl); + error =vfs_lock_file (file->f_file[mode],F_SETLK , &lock->fl,NULL ); lock->fl.fl_flags &= ~FL_SLEEP ; lock->fl.fl_start = fl_start; lock->fl.fl_end = fl_end;fs/lockd/svcproc.c +3
-1@@ -55,6 +55,7 @@ nlmsvc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp,struct nlm_host *host =NULL ;struct nlm_file *file =NULL ;struct nlm_lock *lock = &argp->lock; +int mode;__be32 error =0 ;/* nfsd callbacks must have been installed for this procedure */ @@ -75,7 +76,8 @@ nlmsvc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp, *filp = file;/* Set up the missing parts of the file_lock structure */ - lock->fl.fl_file = file->f_file; + mode =lock_to_openmode (&lock->fl); + lock->fl.fl_file = file->f_file[mode]; lock->fl.fl_pid = current->tgid; lock->fl.fl_lmops = &nlmsvc_lock_operations;nlmsvc_locks_init_private (&lock->fl, host, (pid_t )lock->svid);fs/lockd/svcsubs.c +0
-0fs/lockd/svcsubs.c static inline unsigned int file_hash(struct nfs_fh *f) · line 79
Quoted 9 lines
fs/lockd/svcsubs.c +6
-0@@ -71,14 +71,38 @@ static inline unsigned int file_hash(struct nfs_fh *f)return tmp & (FILE_NRHASH -1 ); } +int lock_to_openmode (struct file_lock *lock) +{ +if (lock->fl_type ==F_WRLCK ) +return O_WRONLY ; +else +return O_RDONLY ;Style: a ternary would be more consistent with other areas of the code you change in this patch.
Quoted 112 lines
fs/lockd/svcsubs.c +23
-5+} + +/* +* Open the file. Note that if we're reexporting, for example, +* this could block the lockd thread for a while. +* +* We have to make sure we have the right credential to open +* the file. +*/ +static __be32 nlm_do_fopen (struct svc_rqst *rqstp, +struct nlm_file *file,int mode) +{ +struct file **fp = &file->f_file[mode]; +__be32 nfserr; + +if (*fp) +return 0 ; + nfserr = nlmsvc_ops->fopen (rqstp, &file->f_handle, fp, mode); +if (nfserr) +dprintk ("lockd: open failed (error %d)\n" , nfserr); +return nfserr; +} +/* * Lookup file info. If it doesn't exist, create a file info struct * and open a (VFS) file for the given inode. -* -* FIXME: -* Note that we open the file O_RDONLY even when creating write locks. -* This is not quite right, but for now, we assume the client performs -* the proper R/W checking. */
__be32
nlm_lookup_file(structsvc_rqst*rqstp, structnlm_file**result,fs/lockd/svcsubs.c +11
-15@@ -87,41 +111,38 @@ nlm_lookup_file(struct svc_rqst *rqstp, struct nlm_file **result,struct nlm_file *file;unsigned int hash;__be32 nfserr; +int mode;nlm_debug_print_fh ("nlm_lookup_file" , &lock->fh); hash =file_hash (&lock->fh); + mode =lock_to_openmode (&lock->fl);/* Lock file table */ mutex_lock (&nlm_file_mutex);hlist_for_each_entry (file, &nlm_files[hash], f_list) -if (!nfs_compare_fh (&file->f_handle, &lock->fh)) +if (!nfs_compare_fh (&file->f_handle, &lock->fh)) { +mutex_lock (&file->f_mutex); + nfserr =nlm_do_fopen (rqstp, file, mode); +mutex_unlock (&file->f_mutex); goto found; - + }nlm_debug_print_fh ("creating file for" , &lock->fh); nfserr = nlm_lck_denied_nolocks; file =kzalloc (sizeof (*file),GFP_KERNEL );if (!file) - goto out_unlock; + goto out_free;memcpy (&file->f_handle, &lock->fh,sizeof (struct nfs_fh ));mutex_init (&file->f_mutex);INIT_HLIST_NODE (&file->f_list);INIT_LIST_HEAD (&file->f_blocks); -/* -* Open the file. Note that if we're reexporting, for example, -* this could block the lockd thread for a while. -* -* We have to make sure we have the right credential to open -* the file. -*/ -if ((nfserr = nlmsvc_ops->fopen (rqstp, &lock->fh, &file->f_file)) !=0 ) { -dprintk ("lockd: open failed (error %d)\n" , nfserr); - goto out_free; - } + nfserr =nlm_do_fopen (rqstp, file, mode); +if (nfserr) + goto out_unlock;hlist_add_head (&file->f_list, &nlm_files[hash]);@@ -129,7 +150,6 @@ nlm_lookup_file(struct svc_rqst *rqstp, struct nlm_file **result,dprintk ("lockd: found file %p (count %d)\n" , file, file->f_count); *result = file; file->f_count++; - nfserr =0 ;
out_unlock:mutex_unlock(&nlm_file_mutex);fs/lockd/svcsubs.c +6
-1@@ -149,13 +169,34 @@ nlm_delete_file(struct nlm_file *file)nlm_debug_print_file ("closing file" , file);if (!hlist_unhashed (&file->f_list)) {hlist_del (&file->f_list); - nlmsvc_ops->fclose (file->f_file); +if (file->f_file[O_RDONLY ]) + nlmsvc_ops->fclose (file->f_file[O_RDONLY ]); +if (file->f_file[O_WRONLY ]) + nlmsvc_ops->fclose (file->f_file[O_WRONLY ]);kfree (file); }else {printk (KERN_WARNING "lockd: attempt to release unknown file!\n" ); } } +static int nlm_unlock_files (struct nlm_file *file) +{fs/lockd/svcsubs.c nlm_delete_file(struct nlm_file *file) · line 193
Quoted 10 lines
fs/lockd/svcsubs.c +10
-0+struct file_lock lock; +struct file *f; + + lock.fl_type =F_UNLCK ; + lock.fl_start =0 ; + lock.fl_end =OFFSET_MAX ; +for (f = file->f_file[0 ]; f <= file->f_file[1 ]; f++) { +if (f &&vfs_lock_file (f,F_SETLK , &lock,NULL ) <0 ) { +printk ("lockd: unlock failure in %s:%d\n" , + __FILE__, __LINE__);This needs a
KERN_LEVELand maybe a_once.Quoted 94 lines
fs/lockd/svcsubs.c +18
-9+return 1 ; + } + } +return 0 ; +} +/* * Loop over all locks on the given file and perform the specified * action. @@ -183,17 +224,10 @@ nlm_traverse_locks(struct nlm_host *host, struct nlm_file *file, lockhost = ((struct nlm_lockowner *)fl->fl_owner)->host;if (match (lockhost, host)) { -struct file_lock lock = *fl;spin_unlock (&flctx->flc_lock); - lock.fl_type =F_UNLCK ; - lock.fl_start =0 ; - lock.fl_end =OFFSET_MAX ; -if (vfs_lock_file (file->f_file,F_SETLK , &lock,NULL ) <0 ) { -printk ("lockd: unlock failure in %s:%d\n" , - __FILE__, __LINE__); +if (nlm_unlock_files (file))return 1 ; - } goto again; } }@@ -247,6 +281,15 @@ nlm_file_inuse(struct nlm_file *file)return 0 ; } +static void nlm_close_files (struct nlm_file *file) +{ +struct file *f; + +for (f = file->f_file[0 ]; f <= file->f_file[1 ]; f++) +if (f) + nlmsvc_ops->fclose (f); +} +/* * Loop over all files in the file table. */ @@ -277,7 +320,7 @@ nlm_traverse_files(void *data, nlm_host_match_fn_t match,if (list_empty (&file->f_blocks) && !file->f_locks && !file->f_shares && !file->f_count) {hlist_del (&file->f_list); - nlmsvc_ops->fclose (file->f_file); +nlm_close_files (file);kfree (file); } }@@ -411,6 +454,7 @@ nlmsvc_invalidate_all(void)nlm_traverse_files (NULL , nlmsvc_is_client,NULL ); } +static int
nlmsvc_match_sb(void *datap, struct nlm_file *file){fs/nfsd/lockd.c +0
-0@@ -25,9 +25,11 @@* Note: we hold the dentry use count while the file is open. */ static
__be32fs/nfsd/lockd.c +2
-1-nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, struct file **filp) +nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, struct file **filp, + int mode){ __be32 nfserr;fs/nfsd/lockd.c +1
-0+int access;struct svc_fh fh; /* must initialize before using! but maxsize doesn't matter */fs/nfsd/lockd.c +3
-1@@ -36,7 +38,9 @@ nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, struct file **filp)memcpy ((char *)&fh.fh_handle.fh_base, f->data, f->size); fh.fh_export =NULL ; - nfserr =nfsd_open (rqstp, &fh,S_IFREG ,NFSD_MAY_LOCK , filp); + access = (mode ==O_WRONLY ) ?NFSD_MAY_WRITE :NFSD_MAY_READ ; + access |=NFSD_MAY_LOCK ; + nfserr =nfsd_open (rqstp, &fh,S_IFREG , access, filp);fh_put (&fh);/* We return nlm error codes as nlm doesn't know * about nfsd, but nfsd does know about nlm.. include/linux/lockd/bind.h +0
-0include/linux/lockd/bind.h struct rpc_task; · line 31
Quoted 6 lines
include/linux/lockd/bind.h +2
-1@@ -27,7 +27,8 @@ struct rpc_task;struct nlmsvc_binding {__be32 (*fopen)(struct svc_rqst *,struct nfs_fh *, -struct file **); +struct file **, +int mode);Style: "
mode_tmode" might be better internal documentation.Quoted 17 lines
include/linux/lockd/bind.h +0
-0void (*fclose)(struct file *); };include/linux/lockd/lockd.h +2
-0@@ -10,6 +10,8 @@#ifndef LINUX_LOCKD_LOCKD_H #define LINUX_LOCKD_LOCKD_H +/* XXX: a lot of this should really be under fs/lockd. */ +#include <linux/in.h> #include <linux/in6.h> #include <net/ipv6.h> include/linux/lockd/lockd.h struct nlm_rqst { · line 160
Quoted 6 lines
include/linux/lockd/lockd.h +2
-1@@ -154,7 +156,8 @@ struct nlm_rqst {struct nlm_file {struct hlist_node f_list;/* linked list */ struct nfs_fh f_handle;/* NFS file handle */ -struct file * f_file;/* VFS file pointer */ +struct file * f_file[2 ];/* VFS file pointers, +indexed by O_ flags */ Right, except that the new code in this patch always indexes
f_filewith raw integers, making the comment misleading. My preference is to keep the comment and change the new code to indexf_filesymbolically.Quoted 24 lines
include/linux/lockd/lockd.h +3
-1struct nlm_share * f_shares;/* DOS shares */ struct list_head f_blocks;/* blocked locks */ unsigned int f_locks;/* guesstimate # of locks */ @@ -267,6 +270,7 @@ typedef int (*nlm_host_match_fn_t)(void *cur, struct nlm_host *ref);/* * Server-side lock handling */ +int lock_to_openmode (struct file_lock *);__be32 nlmsvc_lock (struct svc_rqst *,struct nlm_file *,struct nlm_host *,struct nlm_lock *,int ,struct nlm_cookie *,int );@@ -301,7 +305,8 @@ int nlmsvc_unlock_all_by_ip(struct sockaddr *server_addr);static inline struct inode *nlmsvc_file_inode (struct nlm_file *file) { -return locks_inode (file->f_file); +return locks_inode (file->f_file[0 ] ? + file->f_file[0 ] : file->f_file[1 ]); }static inline int __nlm_privileged_request4 (const struct sockaddr *sap)Signature · 1 line
2.31.1--
Chuck Lever
Re: [PATCH 5/8] Keep read and write fds with each nlm_file
In reply to Chuck Lever IIIQuoted 14 lines · Chuck Lever III
fs/lockd/svclock.c nlmsvc_unlock(struct net *net, struct nlm_file *file, struct nlm_lock *lock) · line 666
Quoted 11 lines
fs/lockd/svclock.c +6
-1@@ -654,7 +658,12 @@ nlmsvc_unlock(struct net *net, struct nlm_file *file, struct nlm_lock *lock)nlmsvc_cancel_blocked (net, file, lock); lock->fl.fl_type =F_UNLCK ; - error =vfs_lock_file (file->f_file,F_SETLK , &lock->fl,NULL ); +if (file->f_file[0 ]) + error =vfs_lock_file (file->f_file[0 ],F_SETLK , + &lock->fl,NULL ); +if (file->f_file[1 ]) + error =vfs_lock_file (file->f_file[1 ],F_SETLK , + &lock->fl,NULL );Eschew raw integers :-) Should the
f_filearray be indexed using O_ flags as the comment below suggests?
Sure, done.
Quoted 8 lines
Quoted 8 lines
fs/lockd/svcsubs.c +0
-0@@ -71,14 +71,38 @@ static inline unsigned int file_hash(struct nfs_fh *f)return tmp & (FILE_NRHASH -1 ); }
Quoted 9 lines
fs/lockd/svcsubs.c static inline unsigned int file_hash(struct nfs_fh *f) · line 79
Quoted 6 lines
fs/lockd/svcsubs.c +6
-0+int lock_to_openmode (struct file_lock *lock) +{ +if (lock->fl_type ==F_WRLCK ) +return O_WRONLY ; +else +return O_RDONLY ;Style: a ternary would be more consistent with other areas of the code you change in this patch.
OK.
Quoted 6 lines
Quoted 6 lines
fs/lockd/svcsubs.c +6
-0+static int nlm_unlock_files (struct nlm_file *file) +{ +struct file_lock lock; +struct file *f; + + lock.fl_type =F_UNLCK ;
Quoted 8 lines
fs/lockd/svcsubs.c nlm_delete_file(struct nlm_file *file) · line 193
Quoted 6 lines
fs/lockd/svcsubs.c +6
-0+ lock.fl_start =0 ; + lock.fl_end =OFFSET_MAX ; +for (f = file->f_file[0 ]; f <= file->f_file[1 ]; f++) { +if (f &&vfs_lock_file (f,F_SETLK , &lock,NULL ) <0 ) { +printk ("lockd: unlock failure in %s:%d\n" , + __FILE__, __LINE__);This needs a
KERN_LEVELand maybe a_once.
How about going with pr_warn for now. I don't *think* there's much danger of spamming the logs from this one. And I'm wondering there might be some causes (unresponsive server?) that could resolve themselves, and then come back, and that you'd still want to hear about the second time.
Quoted 9 lines
fs/lockd/svcsubs.c struct rpc_task; · line 31
Quoted 7 lines
fs/lockd/svcsubs.c +2
-1@@ -27,7 +27,8 @@ struct rpc_task;struct nlmsvc_binding {__be32 (*fopen)(struct svc_rqst *,struct nfs_fh *, -struct file **); +struct file **, +int mode);Style: "
mode_tmode" might be better internal documentation.
It's confusing that we use the word "mode" both for "access mode" (O_ flags) and "mode bits" (permission bits). This is the former, and I thought mode_t was the for the latter.
Quoted 4 lines
Quoted 4 lines
fs/lockd/svcsubs.c +0
-0@@ -154,7 +156,8 @@ struct nlm_rqst {struct nlm_file {struct hlist_node f_list;/* linked list */ struct nfs_fh f_handle;/* NFS file handle */
Quoted 8 lines
fs/lockd/svcsubs.c struct nlm_rqst { · line 160
Quoted 3 lines
fs/lockd/svcsubs.c +2
-1-struct file * f_file;/* VFS file pointer */ +struct file * f_file[2 ];/* VFS file pointers, +indexed by O_ flags */ Right, except that the new code in this patch always indexes
f_filewith raw integers, making the comment misleading. My preference is to keep the comment and change the new code to indexf_filesymbolically.
OK.
--b.
Re: [PATCH 5/8] Keep read and write fds with each nlm_file
Quoted 57 lines · J. Bruce Fields
Quoted 14 lines · Chuck Lever III
fs/lockd/svclock.c nlmsvc_unlock(struct net *net, struct nlm_file *file, struct nlm_lock *lock) · line 666
Quoted 11 lines
fs/lockd/svclock.c +6
-1@@ -654,7 +658,12 @@ nlmsvc_unlock(struct net *net, struct nlm_file *file, struct nlm_lock *lock)nlmsvc_cancel_blocked (net, file, lock); lock->fl.fl_type =F_UNLCK ; - error =vfs_lock_file (file->f_file,F_SETLK , &lock->fl,NULL ); +if (file->f_file[0 ]) + error =vfs_lock_file (file->f_file[0 ],F_SETLK , + &lock->fl,NULL ); +if (file->f_file[1 ]) + error =vfs_lock_file (file->f_file[1 ],F_SETLK , + &lock->fl,NULL );Eschew raw integers :-) Should the
f_filearray be indexed using O_ flags as the comment below suggests?Sure, done.
Quoted 8 lines
Quoted 8 lines
fs/lockd/svcsubs.c +0
-0@@ -71,14 +71,38 @@ static inline unsigned int file_hash(struct nfs_fh *f)return tmp & (FILE_NRHASH -1 ); }Quoted 9 lines
fs/lockd/svcsubs.c static inline unsigned int file_hash(struct nfs_fh *f) · line 79
Quoted 6 lines
fs/lockd/svcsubs.c +6
-0+int lock_to_openmode (struct file_lock *lock) +{ +if (lock->fl_type ==F_WRLCK ) +return O_WRONLY ; +else +return O_RDONLY ;Style: a ternary would be more consistent with other areas of the code you change in this patch.
OK.
Quoted 6 lines
Quoted 6 lines
fs/lockd/svcsubs.c +6
-0+static int nlm_unlock_files (struct nlm_file *file) +{ +struct file_lock lock; +struct file *f; + + lock.fl_type =F_UNLCK ;Quoted 8 lines
fs/lockd/svcsubs.c nlm_delete_file(struct nlm_file *file) · line 193
Quoted 6 lines
fs/lockd/svcsubs.c +6
-0+ lock.fl_start =0 ; + lock.fl_end =OFFSET_MAX ; +for (f = file->f_file[0 ]; f <= file->f_file[1 ]; f++) { +if (f &&vfs_lock_file (f,F_SETLK , &lock,NULL ) <0 ) { +printk ("lockd: unlock failure in %s:%d\n" , + __FILE__, __LINE__);This needs a
KERN_LEVELand maybe a_once.
Quoted 1 line
How about going with
pr_warnfor now.
Sold.
Quoted 16 lines
I don't *think* there's much
danger of spamming the logs from this one. And I'm wondering there might be some causes (unresponsive server?) that could resolve themselves, and then come back, and that you'd still want to hear about the second time.Quoted 9 lines
fs/lockd/svcsubs.c struct rpc_task; · line 31
Quoted 7 lines
fs/lockd/svcsubs.c +2
-1@@ -27,7 +27,8 @@ struct rpc_task;struct nlmsvc_binding {__be32 (*fopen)(struct svc_rqst *,struct nfs_fh *, -struct file **); +struct file **, +int mode);Style: "
mode_tmode" might be better internal documentation.
Quoted 3 lines
It's confusing that we use the word "mode" both for "access mode" (O_ flags) and "mode bits" (permission bits). This is the former, and I thought
mode_twas the for the latter.
Fair enough.
Quoted 14 lines
Quoted 13 lines
fs/lockd/svcsubs.c struct nlm_rqst { · line 160
Quoted 8 lines
fs/lockd/svcsubs.c +2
-1@@ -154,7 +156,8 @@ struct nlm_rqst {struct nlm_file {struct hlist_node f_list;/* linked list */ struct nfs_fh f_handle;/* NFS file handle */ -struct file * f_file;/* VFS file pointer */ +struct file * f_file[2 ];/* VFS file pointers, +indexed by O_ flags */ Right, except that the new code in this patch always indexes
f_filewith raw integers, making the comment misleading. My preference is to keep the comment and change the new code to indexf_filesymbolically.
Quoted 3 lines
OK.
--b.
--
Chuck Lever
Re: [PATCH 5/8] Keep read and write fds with each nlm_file
From: "J. Bruce Fields" <[email protected]>
Subject: [PATCH v4] Keep read and write fds with each nlm_file
We shouldn't really be using a read-only file descriptor to take a write lock.
Most filesystems will put up with it. But NFS, for example, won't.
--- fs/lockd/svc4proc.c | 4 +- fs/lockd/svclock.c | 25 ++++++--- fs/lockd/svcproc.c | 4 +- fs/lockd/svcsubs.c | 102 +++++++++++++++++++++++++----------- fs/nfsd/lockd.c | 8 ++- include/linux/lockd/bind.h | 3 +- include/linux/lockd/lockd.h | 9 +++- 7 files changed, 111 insertions(+), 44 deletions(-)
fs/lockd/svc4proc.c +3 -1
@@ -40,13 +40,15 @@ nlm4svc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp,/* Obtain file pointer. Not used by FREE_ALL call. */ if (filp !=NULL ) { +int mode =lock_to_openmode (&lock->fl); + error =nlm_lookup_file (rqstp, &file, lock);if (error) goto no_locks; *filp = file;/* Set up the missing parts of the file_lock structure */ - lock->fl.fl_file = file->f_file; + lock->fl.fl_file = file->f_file[mode]; lock->fl.fl_pid = current->tgid; lock->fl.fl_lmops = &nlmsvc_lock_operations;nlmsvc_locks_init_private (&lock->fl, host, (pid_t )lock->svid);
fs/lockd/svclock.c +19 -6
@@ -471,6 +471,7 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file, {struct nlm_block *block =NULL ;int error; +int mode;__be32 ret; dprintk("lockd: nlmsvc_lock(%s/%ld, ty=%d, pi=%d, %Ld-%Ld, bl=%d)\n",
@@ -524,7 +525,8 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file,if (!wait) lock->fl.fl_flags &= ~FL_SLEEP ; - error =vfs_lock_file (file->f_file,F_SETLK , &lock->fl,NULL ); + mode =lock_to_openmode (&lock->fl); + error =vfs_lock_file (file->f_file[mode],F_SETLK , &lock->fl,NULL ); lock->fl.fl_flags &= ~FL_SLEEP ;dprintk ("lockd: vfs_lock_file returned %d\n" , error);
@@ -577,6 +579,7 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file, struct nlm_lock *conflock, struct nlm_cookie *cookie) { int error; +int mode;__be32 ret;struct nlm_lockowner *test_owner;
@@ -595,7 +598,8 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,/* If there's a conflicting lock, remember to clean up the test lock */ test_owner = (struct nlm_lockowner *)lock->fl.fl_owner; - error =vfs_test_lock (file->f_file, &lock->fl); + mode =lock_to_openmode (&lock->fl); + error =vfs_test_lock (file->f_file[mode], &lock->fl);if (error) {/* We can't currently deal with deferred test requests */ if (error ==FILE_LOCK_DEFERRED )
@@ -641,7 +645,7 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,__be32 nlmsvc_unlock (struct net *net,struct nlm_file *file,struct nlm_lock *lock) { -int error; +int error =0 ; dprintk("lockd: nlmsvc_unlock(%s/%ld, pi=%d, %Ld-%Ld)\n", nlmsvc_file_inode(file)->i_sb->s_id,
@@ -654,7 +658,12 @@ nlmsvc_unlock(struct net *net, struct nlm_file *file, struct nlm_lock *lock)nlmsvc_cancel_blocked (net, file, lock); lock->fl.fl_type =F_UNLCK ; - error =vfs_lock_file (file->f_file,F_SETLK , &lock->fl,NULL ); +if (file->f_file[O_RDONLY ]) + error =vfs_lock_file (file->f_file[O_RDONLY ],F_SETLK , + &lock->fl,NULL ); +if (file->f_file[O_WRONLY ]) + error =vfs_lock_file (file->f_file[O_WRONLY ],F_SETLK , + &lock->fl,NULL );return (error <0 )? nlm_lck_denied_nolocks : nlm_granted; }
@@ -671,6 +680,7 @@ nlmsvc_cancel_blocked(struct net *net, struct nlm_file *file, struct nlm_lock *l {struct nlm_block *block;int status =0 ; +int mode; dprintk("lockd: nlmsvc_cancel(%s/%ld, pi=%d, %Ld-%Ld)\n", nlmsvc_file_inode(file)->i_sb->s_id,
@@ -686,7 +696,8 @@ nlmsvc_cancel_blocked(struct net *net, struct nlm_file *file, struct nlm_lock *l block =nlmsvc_lookup_block (file, lock);mutex_unlock (&file->f_mutex);if (block !=NULL ) { -vfs_cancel_lock (block->b_file->f_file, + mode =lock_to_openmode (&lock->fl); +vfs_cancel_lock (block->b_file->f_file[mode], &block->b_call->a_args.lock.fl); status =nlmsvc_unlink_block (block);nlmsvc_release_block (block);
@@ -803,6 +814,7 @@ nlmsvc_grant_blocked(struct nlm_block *block) {struct nlm_file *file = block->b_file;struct nlm_lock *lock = &block->b_call->a_args.lock; +int mode;int error;loff_t fl_start, fl_end;
@@ -828,7 +840,8 @@ nlmsvc_grant_blocked(struct nlm_block *block) lock->fl.fl_flags |=FL_SLEEP ; fl_start = lock->fl.fl_start; fl_end = lock->fl.fl_end; - error =vfs_lock_file (file->f_file,F_SETLK , &lock->fl,NULL ); + mode =lock_to_openmode (&lock->fl); + error =vfs_lock_file (file->f_file[mode],F_SETLK , &lock->fl,NULL ); lock->fl.fl_flags &= ~FL_SLEEP ; lock->fl.fl_start = fl_start; lock->fl.fl_end = fl_end;
fs/lockd/svcproc.c +3 -1
@@ -55,6 +55,7 @@ nlmsvc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp,struct nlm_host *host =NULL ;struct nlm_file *file =NULL ;struct nlm_lock *lock = &argp->lock; +int mode;__be32 error =0 ;/* nfsd callbacks must have been installed for this procedure */
@@ -75,7 +76,8 @@ nlmsvc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp, *filp = file;/* Set up the missing parts of the file_lock structure */ - lock->fl.fl_file = file->f_file; + mode =lock_to_openmode (&lock->fl); + lock->fl.fl_file = file->f_file[mode]; lock->fl.fl_pid = current->tgid; lock->fl.fl_lmops = &nlmsvc_lock_operations;nlmsvc_locks_init_private (&lock->fl, host, (pid_t )lock->svid);
fs/lockd/svcsubs.c +71 -31
183 lines not on this page · raw message
fs/nfsd/lockd.c +6 -2
@@ -25,9 +25,11 @@* Note: we hold the dentry use count while the file is open. */ static __be32 -nlm_fopen (struct svc_rqst *rqstp,struct nfs_fh *f,struct file **filp) +nlm_fopen (struct svc_rqst *rqstp,struct nfs_fh *f,struct file **filp, +int mode) {__be32 nfserr; +int access;struct svc_fh fh;/* must initialize before using! but maxsize doesn't matter */
@@ -36,7 +38,9 @@ nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, struct file **filp)memcpy ((char *)&fh.fh_handle.fh_base, f->data, f->size); fh.fh_export =NULL ; - nfserr =nfsd_open (rqstp, &fh,S_IFREG ,NFSD_MAY_LOCK , filp); + access = (mode ==O_WRONLY ) ?NFSD_MAY_WRITE :NFSD_MAY_READ ; + access |=NFSD_MAY_LOCK ; + nfserr =nfsd_open (rqstp, &fh,S_IFREG , access, filp);fh_put (&fh);/* We return nlm error codes as nlm doesn't know * about nfsd, but nfsd does know about nlm..
include/linux/lockd/bind.h +2 -1
@@ -27,7 +27,8 @@ struct rpc_task;struct nlmsvc_binding {__be32 (*fopen)(struct svc_rqst *,struct nfs_fh *, -struct file **); +struct file **, +int mode);void (*fclose)(struct file *); };
include/linux/lockd/lockd.h +7 -2
@@ -10,6 +10,8 @@#ifndef LINUX_LOCKD_LOCKD_H #define LINUX_LOCKD_LOCKD_H +/* XXX: a lot of this should really be under fs/lockd. */ +#include <linux/in.h> #include <linux/in6.h> #include <net/ipv6.h>
@@ -154,7 +156,8 @@ struct nlm_rqst {struct nlm_file {struct hlist_node f_list;/* linked list */ struct nfs_fh f_handle;/* NFS file handle */ -struct file * f_file;/* VFS file pointer */ +struct file * f_file[2 ];/* VFS file pointers, +indexed by O_ flags */ struct nlm_share * f_shares;/* DOS shares */ struct list_head f_blocks;/* blocked locks */ unsigned int f_locks;/* guesstimate # of locks */
@@ -267,6 +270,7 @@ typedef int (*nlm_host_match_fn_t)(void *cur, struct nlm_host *ref);/* * Server-side lock handling */ +int lock_to_openmode (struct file_lock *);__be32 nlmsvc_lock (struct svc_rqst *,struct nlm_file *,struct nlm_host *,struct nlm_lock *,int ,struct nlm_cookie *,int );
@@ -301,7 +305,8 @@ int nlmsvc_unlock_all_by_ip(struct sockaddr *server_addr);static inline struct inode *nlmsvc_file_inode (struct nlm_file *file) { -return locks_inode (file->f_file); +return locks_inode (file->f_file[0 ] ? + file->f_file[0 ] : file->f_file[1 ]); }static inline int __nlm_privileged_request4 (const struct sockaddr *sap)
Signature · 1 line
2.31.1
Re: [PATCH 5/8] Keep read and write fds with each nlm_file
Quoted 286 lines · Bruce Fields
From: "J. Bruce Fields" <[email protected]>
Subject: [PATCH v4] Keep read and write fds with eachnlm_fileWe shouldn't really be using a read-only file descriptor to take a write lock.
Most filesystems will put up with it. But NFS, for example, won't.
Signed-off-by J. Bruce Fields <[email protected]>---
fs/lockd/svc4proc.c | 4 +- fs/lockd/svclock.c | 25 ++++++--- fs/lockd/svcproc.c | 4 +- fs/lockd/svcsubs.c | 102 +++++++++++++++++++++++++----------- fs/nfsd/lockd.c | 8 ++- include/linux/lockd/bind.h | 3 +- include/linux/lockd/lockd.h | 9 +++- 7 files changed, 111 insertions(+), 44 deletions(-)fs/lockd/svc4proc.c +3
-1@@ -40,13 +40,15 @@ nlm4svc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp,/* Obtain file pointer. Not used by FREE_ALL call. */ if (filp !=NULL ) { +int mode =lock_to_openmode (&lock->fl); + error =nlm_lookup_file (rqstp, &file, lock);if (error) goto no_locks; *filp = file;/* Set up the missing parts of the file_lock structure */ - lock->fl.fl_file = file->f_file; + lock->fl.fl_file = file->f_file[mode]; lock->fl.fl_pid = current->tgid; lock->fl.fl_lmops = &nlmsvc_lock_operations;nlmsvc_locks_init_private (&lock->fl, host, (pid_t )lock->svid);fs/lockd/svclock.c +6
-2@@ -471,6 +471,7 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file, {struct nlm_block *block =NULL ;int error; +int mode;__be32 ret; dprintk("lockd: nlmsvc_lock(%s/%ld, ty=%d, pi=%d, %Ld-%Ld, bl=%d)\n",@@ -524,7 +525,8 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file,if (!wait) lock->fl.fl_flags &= ~FL_SLEEP ; - error =vfs_lock_file (file->f_file,F_SETLK , &lock->fl,NULL ); + mode =lock_to_openmode (&lock->fl); + error =vfs_lock_file (file->f_file[mode],F_SETLK , &lock->fl,NULL ); lock->fl.fl_flags &= ~FL_SLEEP ;dprintk ("lockd: vfs_lock_file returned %d\n" , error);@@ -577,6 +579,7 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file, struct nlm_lock *conflock, struct nlm_cookie *cookie) { int error; +int mode;__be32 ret;struct nlm_lockowner *test_owner;@@ -595,7 +598,8 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,/* If there's a conflicting lock, remember to clean up the test lock */ test_owner = (struct nlm_lockowner *)lock->fl.fl_owner; - error =vfs_test_lock (file->f_file, &lock->fl); + mode =lock_to_openmode (&lock->fl); + error =vfs_test_lock (file->f_file[mode], &lock->fl);if (error) {/* We can't currently deal with deferred test requests */ if (error ==FILE_LOCK_DEFERRED )@@ -641,7 +645,7 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,
__be32nlmsvc_unlock(struct net *net, struct nlm_file *file, struct nlm_lock *lock){fs/lockd/svclock.c +1
-1-int error; +int error =0 ;dprintk("lockd: nlmsvc_unlock(%s/%ld, pi=%d, %Ld-%Ld)\n", nlmsvc_file_inode(file)->i_sb->s_id,fs/lockd/svclock.c +12
-3@@ -654,7 +658,12 @@ nlmsvc_unlock(struct net *net, struct nlm_file *file, struct nlm_lock *lock)nlmsvc_cancel_blocked (net, file, lock); lock->fl.fl_type =F_UNLCK ; - error =vfs_lock_file (file->f_file,F_SETLK , &lock->fl,NULL ); +if (file->f_file[O_RDONLY ]) + error =vfs_lock_file (file->f_file[O_RDONLY ],F_SETLK , + &lock->fl,NULL ); +if (file->f_file[O_WRONLY ]) + error =vfs_lock_file (file->f_file[O_WRONLY ],F_SETLK , + &lock->fl,NULL );return (error <0 )? nlm_lck_denied_nolocks : nlm_granted; }@@ -671,6 +680,7 @@ nlmsvc_cancel_blocked(struct net *net, struct nlm_file *file, struct nlm_lock *l {struct nlm_block *block;int status =0 ; +int mode; dprintk("lockd: nlmsvc_cancel(%s/%ld, pi=%d, %Ld-%Ld)\n", nlmsvc_file_inode(file)->i_sb->s_id,@@ -686,7 +696,8 @@ nlmsvc_cancel_blocked(struct net *net, struct nlm_file *file, struct nlm_lock *l block =nlmsvc_lookup_block (file, lock);mutex_unlock (&file->f_mutex);if (block !=NULL ) { -vfs_cancel_lock (block->b_file->f_file, + mode =lock_to_openmode (&lock->fl); +vfs_cancel_lock (block->b_file->f_file[mode], &block->b_call->a_args.lock.fl); status =nlmsvc_unlink_block (block);nlmsvc_release_block (block);@@ -803,6 +814,7 @@ nlmsvc_grant_blocked(struct nlm_block *block) {struct nlm_file *file = block->b_file;struct nlm_lock *lock = &block->b_call->a_args.lock; +int mode;int error;loff_t fl_start, fl_end;@@ -828,7 +840,8 @@ nlmsvc_grant_blocked(struct nlm_block *block) lock->fl.fl_flags |=FL_SLEEP ; fl_start = lock->fl.fl_start; fl_end = lock->fl.fl_end; - error =vfs_lock_file (file->f_file,F_SETLK , &lock->fl,NULL ); + mode =lock_to_openmode (&lock->fl); + error =vfs_lock_file (file->f_file[mode],F_SETLK , &lock->fl,NULL ); lock->fl.fl_flags &= ~FL_SLEEP ; lock->fl.fl_start = fl_start; lock->fl.fl_end = fl_end;fs/lockd/svcproc.c +3
-1@@ -55,6 +55,7 @@ nlmsvc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp,struct nlm_host *host =NULL ;struct nlm_file *file =NULL ;struct nlm_lock *lock = &argp->lock; +int mode;__be32 error =0 ;/* nfsd callbacks must have been installed for this procedure */ @@ -75,7 +76,8 @@ nlmsvc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp, *filp = file;/* Set up the missing parts of the file_lock structure */ - lock->fl.fl_file = file->f_file; + mode =lock_to_openmode (&lock->fl); + lock->fl.fl_file = file->f_file[mode]; lock->fl.fl_pid = current->tgid; lock->fl.fl_lmops = &nlmsvc_lock_operations;nlmsvc_locks_init_private (&lock->fl, host, (pid_t )lock->svid);fs/lockd/svcsubs.c +26
-5@@ -71,14 +71,35 @@ static inline unsigned int file_hash(struct nfs_fh *f)return tmp & (FILE_NRHASH -1 ); } +int lock_to_openmode (struct file_lock *lock) +{ +return (lock->fl_type ==F_WRLCK ) ?O_WRONLY :O_RDONLY ; +} + +/* +* Open the file. Note that if we're reexporting, for example, +* this could block the lockd thread for a while. +* +* We have to make sure we have the right credential to open +* the file. +*/ +static __be32 nlm_do_fopen (struct svc_rqst *rqstp, +struct nlm_file *file,int mode) +{ +struct file **fp = &file->f_file[mode]; +__be32 nfserr; + +if (*fp) +return 0 ; + nfserr = nlmsvc_ops->fopen (rqstp, &file->f_handle, fp, mode); +if (nfserr) +dprintk ("lockd: open failed (error %d)\n" , nfserr); +return nfserr; +} +/* * Lookup file info. If it doesn't exist, create a file info struct * and open a (VFS) file for the given inode. -* -* FIXME: -* Note that we open the file O_RDONLY even when creating write locks. -* This is not quite right, but for now, we assume the client performs -* the proper R/W checking. */
__be32
nlm_lookup_file(structsvc_rqst*rqstp, structnlm_file**result,fs/lockd/svcsubs.c +11
-16@@ -87,42 +108,38 @@ nlm_lookup_file(struct svc_rqst *rqstp, struct nlm_file **result,struct nlm_file *file;unsigned int hash;__be32 nfserr; +int mode;nlm_debug_print_fh ("nlm_lookup_file" , &lock->fh); hash =file_hash (&lock->fh); + mode =lock_to_openmode (&lock->fl);/* Lock file table */ mutex_lock (&nlm_file_mutex);hlist_for_each_entry (file, &nlm_files[hash], f_list) -if (!nfs_compare_fh (&file->f_handle, &lock->fh)) +if (!nfs_compare_fh (&file->f_handle, &lock->fh)) { +mutex_lock (&file->f_mutex); + nfserr =nlm_do_fopen (rqstp, file, mode); +mutex_unlock (&file->f_mutex); goto found; - + }nlm_debug_print_fh ("creating file for" , &lock->fh); nfserr = nlm_lck_denied_nolocks; file =kzalloc (sizeof (*file),GFP_KERNEL );if (!file) - goto out_unlock; + goto out_free;memcpy (&file->f_handle, &lock->fh,sizeof (struct nfs_fh ));mutex_init (&file->f_mutex);INIT_HLIST_NODE (&file->f_list);INIT_LIST_HEAD (&file->f_blocks); -/* -* Open the file. Note that if we're reexporting, for example, -* this could block the lockd thread for a while. -* -* We have to make sure we have the right credential to open -* the file. -*/ - nfserr = nlmsvc_ops->fopen (rqstp, &lock->fh, &file->f_file); -if (nfserr) { -dprintk ("lockd: open failed (error %d)\n" , nfserr); - goto out_free; - } + nfserr =nlm_do_fopen (rqstp, file, mode); +if (nfserr) + goto out_unlock;hlist_add_head (&file->f_list, &nlm_files[hash]);@@ -130,7 +147,6 @@ nlm_lookup_file(struct svc_rqst *rqstp, struct nlm_file **result,dprintk ("lockd: found file %p (count %d)\n" , file, file->f_count); *result = file; file->f_count++; - nfserr =0 ;
out_unlock:mutex_unlock(&nlm_file_mutex);fs/lockd/svcsubs.c +4
-1@@ -150,13 +166,34 @@ nlm_delete_file(struct nlm_file *file)nlm_debug_print_file ("closing file" , file);if (!hlist_unhashed (&file->f_list)) {hlist_del (&file->f_list); - nlmsvc_ops->fclose (file->f_file); +if (file->f_file[O_RDONLY ]) + nlmsvc_ops->fclose (file->f_file[O_RDONLY ]); +if (file->f_file[O_WRONLY ]) + nlmsvc_ops->fclose (file->f_file[O_WRONLY ]);kfree (file); }else {printk (KERN_WARNING "lockd: attempt to release unknown file!\n" ); } }
fs/lockd/svcsubs.c nlm_delete_file(struct nlm_file *file) · line 187
Quoted 10 lines
fs/lockd/svcsubs.c +9
-0+static int nlm_unlock_files (struct nlm_file *file) +{ +struct file_lock lock; +struct file *f; + + lock.fl_type =F_UNLCK ; + lock.fl_start =0 ; + lock.fl_end =OFFSET_MAX ; +for (f = file->f_file[0 ]; f <= file->f_file[1 ]; f++) {
O_RDONLY and O_WRONLY ?
Quoted 32 lines
fs/lockd/svcsubs.c +10
-8+if (f &&vfs_lock_file (f,F_SETLK , &lock,NULL ) <0 ) { +pr_warn ("lockd: unlock failure in %s:%d\n" , + __FILE__, __LINE__); +return 1 ; + } + } +return 0 ; +} +/* * Loop over all locks on the given file and perform the specified * action. @@ -184,17 +221,10 @@ nlm_traverse_locks(struct nlm_host *host, struct nlm_file *file, lockhost = ((struct nlm_lockowner *)fl->fl_owner)->host;if (match (lockhost, host)) { -struct file_lock lock = *fl;spin_unlock (&flctx->flc_lock); - lock.fl_type =F_UNLCK ; - lock.fl_start =0 ; - lock.fl_end =OFFSET_MAX ; -if (vfs_lock_file (file->f_file,F_SETLK , &lock,NULL ) <0 ) { -printk ("lockd: unlock failure in %s:%d\n" , - __FILE__, __LINE__); +if (nlm_unlock_files (file))return 1 ; - } goto again; } }
fs/lockd/svcsubs.c nlm_file_inuse(struct nlm_file *file) · line 285
Quoted 8 lines
fs/lockd/svcsubs.c +5
-0@@ -248,6 +278,15 @@ nlm_file_inuse(struct nlm_file *file)return 0 ; } +static void nlm_close_files (struct nlm_file *file) +{ +struct file *f; + +for (f = file->f_file[0 ]; f <= file->f_file[1 ]; f++)
O_RDONLY and O_WRONLY ?
Quoted 98 lines
fs/lockd/svcsubs.c +6
-1+if (f) + nlmsvc_ops->fclose (f); +} +/* * Loop over all files in the file table. */ @@ -278,7 +317,7 @@ nlm_traverse_files(void *data, nlm_host_match_fn_t match,if (list_empty (&file->f_blocks) && !file->f_locks && !file->f_shares && !file->f_count) {hlist_del (&file->f_list); - nlmsvc_ops->fclose (file->f_file); +nlm_close_files (file);kfree (file); } }@@ -412,6 +451,7 @@ nlmsvc_invalidate_all(void)nlm_traverse_files (NULL , nlmsvc_is_client,NULL ); } +static int
nlmsvc_match_sb(void *datap, struct nlm_file *file){fs/nfsd/lockd.c +0
-0@@ -25,9 +25,11 @@* Note: we hold the dentry use count while the file is open. */ static
__be32fs/nfsd/lockd.c +2
-1-nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, struct file **filp) +nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, struct file **filp, + int mode){ __be32 nfserr;fs/nfsd/lockd.c +1
-0+int access;struct svc_fh fh; /* must initialize before using! but maxsize doesn't matter */fs/nfsd/lockd.c +3
-1@@ -36,7 +38,9 @@ nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, struct file **filp)memcpy ((char *)&fh.fh_handle.fh_base, f->data, f->size); fh.fh_export =NULL ; - nfserr =nfsd_open (rqstp, &fh,S_IFREG ,NFSD_MAY_LOCK , filp); + access = (mode ==O_WRONLY ) ?NFSD_MAY_WRITE :NFSD_MAY_READ ; + access |=NFSD_MAY_LOCK ; + nfserr =nfsd_open (rqstp, &fh,S_IFREG , access, filp);fh_put (&fh);/* We return nlm error codes as nlm doesn't know * about nfsd, but nfsd does know about nlm.. include/linux/lockd/bind.h +2
-1@@ -27,7 +27,8 @@ struct rpc_task;struct nlmsvc_binding {__be32 (*fopen)(struct svc_rqst *,struct nfs_fh *, -struct file **); +struct file **, +int mode);void (*fclose)(struct file *); };include/linux/lockd/lockd.h +5
-1@@ -10,6 +10,8 @@#ifndef LINUX_LOCKD_LOCKD_H #define LINUX_LOCKD_LOCKD_H +/* XXX: a lot of this should really be under fs/lockd. */ +#include <linux/in.h> #include <linux/in6.h> #include <net/ipv6.h> @@ -154,7 +156,8 @@ struct nlm_rqst {struct nlm_file {struct hlist_node f_list;/* linked list */ struct nfs_fh f_handle;/* NFS file handle */ -struct file * f_file;/* VFS file pointer */ +struct file * f_file[2 ];/* VFS file pointers, +indexed by O_ flags */ struct nlm_share * f_shares;/* DOS shares */ struct list_head f_blocks;/* blocked locks */ unsigned int f_locks;/* guesstimate # of locks */ @@ -267,6 +270,7 @@ typedef int (*nlm_host_match_fn_t)(void *cur, struct nlm_host *ref);/* * Server-side lock handling */ +int lock_to_openmode (struct file_lock *);__be32 nlmsvc_lock (struct svc_rqst *,struct nlm_file *,struct nlm_host *,struct nlm_lock *,int ,struct nlm_cookie *,int );
include/linux/lockd/lockd.h int nlmsvc_unlock_all_by_ip(struct sockaddr *server_addr); · line 309
Quoted 6 lines
include/linux/lockd/lockd.h +2
-1@@ -301,7 +305,8 @@ int nlmsvc_unlock_all_by_ip(struct sockaddr *server_addr);static inline struct inode *nlmsvc_file_inode (struct nlm_file *file) { -return locks_inode (file->f_file); +return locks_inode (file->f_file[0 ] ? + file->f_file[0 ] : file->f_file[1 ]);
O_RDONLY and O_WRONLY ?
Quoted 6 lines
include/linux/lockd/lockd.h +0
-0}static inline int __nlm_privileged_request4 (const struct sockaddr *sap)Signature · 1 line
2.31.1
--
Chuck Lever
Re: [PATCH 5/8] Keep read and write fds with each nlm_file
Quoted 4 lines · Chuck Lever III
Quoted 4 lines · Bruce Fields
fs/lockd/svcsubs.c +3
-0+static int nlm_unlock_files (struct nlm_file *file) +{ +struct file_lock lock;
Quoted 8 lines
fs/lockd/svcsubs.c nlm_delete_file(struct nlm_file *file) · line 187
Quoted 6 lines
fs/lockd/svcsubs.c +6
-0+struct file *f; + + lock.fl_type =F_UNLCK ; + lock.fl_start =0 ; + lock.fl_end =OFFSET_MAX ; +for (f = file->f_file[0 ]; f <= file->f_file[1 ]; f++) {
O_RDONLYandO_WRONLY?
I thought they looked weird as loop boundaries.
Quoted 9 lines
include/linux/lockd/lockd.h int nlmsvc_unlock_all_by_ip(struct sockaddr *server_addr); · line 309
Quoted 7 lines
include/linux/lockd/lockd.h +2
-1@@ -301,7 +305,8 @@ int nlmsvc_unlock_all_by_ip(struct sockaddr *server_addr);static inline struct inode *nlmsvc_file_inode (struct nlm_file *file) { -return locks_inode (file->f_file); +return locks_inode (file->f_file[0 ] ? + file->f_file[0 ] : file->f_file[1 ]);
O_RDONLYandO_WRONLY?
A little less weird.
OK, I admit, "looks weird" isn't much of an argument.
I say we leave it to whoever cares enough to make the change.
--b.
Re: [PATCH 5/8] Keep read and write fds with each nlm_file
Quoted 30 lines · Bruce Fields
Quoted 4 lines · Chuck Lever III
Quoted 4 lines · Bruce Fields
fs/lockd/svcsubs.c +3
-0+static int nlm_unlock_files (struct nlm_file *file) +{ +struct file_lock lock;Quoted 8 lines
fs/lockd/svcsubs.c nlm_delete_file(struct nlm_file *file) · line 187
Quoted 6 lines
fs/lockd/svcsubs.c +6
-0+struct file *f; + + lock.fl_type =F_UNLCK ; + lock.fl_start =0 ; + lock.fl_end =OFFSET_MAX ; +for (f = file->f_file[0 ]; f <= file->f_file[1 ]; f++) {
O_RDONLYandO_WRONLY?I thought they looked weird as loop boundaries.
Quoted 9 lines
include/linux/lockd/lockd.h int nlmsvc_unlock_all_by_ip(struct sockaddr *server_addr); · line 309
Quoted 7 lines
include/linux/lockd/lockd.h +2
-1@@ -301,7 +305,8 @@ int nlmsvc_unlock_all_by_ip(struct sockaddr *server_addr);static inline struct inode *nlmsvc_file_inode (struct nlm_file *file) { -return locks_inode (file->f_file); +return locks_inode (file->f_file[0 ] ? + file->f_file[0 ] : file->f_file[1 ]);
O_RDONLYandO_WRONLY?
Quoted 5 lines
A little less weird.
OK, I admit, "looks weird" isn't much of an argument.
I say we leave it to whoever cares enough to make the change.
I can update nlmsvc_file_inode() when I apply this version of the patch, and leave the loops alone.
--
Chuck Lever
PATCH 6/8 nfs: don't atempt blocking locks on nfs reexports
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
NFS implements blocking locks by blocking inside its lock method. In the reexport case, this blocks the nfs server thread, which could lead to deadlocks since an nfs server thread might be required to unlock the conflicting lock. It also causes a crash, since the nfs server thread assumes it can free the lock when its lm_notify lock callback is called.
Ideal would be to make the nfs lock method return without blocking in this case, but for now it works just not to attempt blocking locks. The difference is just that the original client will have to poll (as it does in the v4.0 case) instead of getting a callback when the lock's available.
--- fs/nfs/export.c | 2 +- fs/nfsd/nfs4state.c | 8 ++++++-- include/linux/exportfs.h | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-)
fs/nfs/export.c +1 -1
@@ -180,5 +180,5 @@ const struct export_operations nfs_export_ops = { .fetch_iversion = nfs_fetch_iversion, .flags =EXPORT_OP_NOWCC |EXPORT_OP_NOSUBTREECHK |EXPORT_OP_CLOSE_BEFORE_UNLINK |EXPORT_OP_REMOTE_FS | - EXPORT_OP_NOATOMIC_ATTR, + EXPORT_OP_NOATOMIC_ATTR|EXPORT_OP_SYNC_LOCKS, };
fs/nfsd/nfs4state.c +6 -2
@@ -6835,6 +6835,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,struct nfsd4_blocked_lock *nbl =NULL ;struct file_lock *file_lock =NULL ;struct file_lock *conflock =NULL ; +struct super_block *sb;__be32 status =0 ;int lkflg;int err;
@@ -6856,6 +6857,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,dprintk ("NFSD: nfsd4_lock: permission denied!\n" );return status; } + sb = cstate->current_fh.fh_dentry->d_sb;if (lock->lk_is_new) {if (nfsd4_has_session (cstate))
@@ -6904,7 +6906,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, fp = lock_stp->st_stid.sc_file;switch (lock->lk_type) {case NFS4_READW_LT : -if (nfsd4_has_session (cstate)) +if (nfsd4_has_session (cstate) && + !(sb->s_export_op->flags &EXPORT_OP_SYNC_LOCKS )) fl_flags |=FL_SLEEP ; fallthrough;case NFS4_READ_LT :
@@ -6916,7 +6919,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, fl_type =F_RDLCK ;break ;case NFS4_WRITEW_LT : -if (nfsd4_has_session (cstate)) +if (nfsd4_has_session (cstate) && + !(sb->s_export_op->flags &EXPORT_OP_SYNC_LOCKS )) fl_flags |=FL_SLEEP ; fallthrough;case NFS4_WRITE_LT :
include/linux/exportfs.h +2 -0
@@ -221,6 +221,8 @@ struct export_operations {#define EXPORT_OP_NOATOMIC_ATTR (0x10)/* Filesystem cannot supply atomic attribute updates */ +#define EXPORT_OP_SYNC_LOCKS (0x20)/* Filesystem can't do +asychronous blocking locks */ unsigned long flags; };
Signature · 1 line
2.31.1
PATCH 7/8 lockd: don't attempt blocking locks on nfs reexports
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
As in the v4 case, it doesn't work well to block waiting for a lock on an nfs filesystem.
As in the v4 case, that means we're depending on the client to poll. It's probably incorrect to depend on that, but I *think* clients do poll in practice. In any case, it's an improvement over hanging the lockd thread indefinitely as we currently are.
--- fs/lockd/svclock.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
fs/lockd/svclock.c +10 -3
@@ -31,6 +31,7 @@#include <linux/lockd/nlm.h> #include <linux/lockd/lockd.h> #include <linux/kthread.h> +#include <linux/exportfs.h> #define NLMDBG_FACILITY NLMDBG_SVCLOCK
@@ -470,18 +471,24 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file, struct nlm_cookie *cookie, int reclaim) {struct nlm_block *block =NULL ; +struct inode *inode =nlmsvc_file_inode (file);int error;int mode; +int async_block =0 ;__be32 ret;dprintk ("lockd: nlmsvc_lock(%s/%ld, ty=%d, pi=%d, %Ld-%Ld, bl=%d)\n" , -nlmsvc_file_inode (file)->i_sb->s_id, -nlmsvc_file_inode (file)->i_ino, + inode->i_sb->s_id, inode->i_ino, lock->fl.fl_type, lock->fl.fl_pid, (long long )lock->fl.fl_start, (long long )lock->fl.fl_end, wait); +if (inode->i_sb->s_export_op->flags &EXPORT_OP_SYNC_LOCKS ) { + async_block = wait; + wait =0 ; + } +/* Lock file against concurrent access */ mutex_lock (&file->f_mutex);/* Get existing block (in case client is busy-waiting)
@@ -542,7 +549,7 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file,*/ if (wait)break ; - ret = nlm_lck_denied; + ret = async_block ? nlm_lck_blocked : nlm_lck_denied; goto out;case FILE_LOCK_DEFERRED :if (wait)
Signature · 1 line
2.31.1
PATCH 8/8 nfs: don't allow reexport reclaims
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
In the reexport case, nfsd is currently passing along locks with the reclaim bit set. The client sends a new lock request, which is granted if there's currently no conflict--even if it's possible a conflicting lock could have been briefly held in the interim.
We don't currently have any way to safely grant reclaim, so for now let's just deny them all.
I'm doing this by passing the reclaim bit to nfs and letting it fail the call, with the idea that eventually the client might be able to do something more forgiving here.
--- fs/nfs/file.c | 3 +++ fs/nfsd/nfs4state.c | 3 +++ fs/nfsd/nfsproc.c | 1 + include/linux/errno.h | 1 + include/linux/fs.h | 1 + 5 files changed, 9 insertions(+)
fs/nfs/file.c +3 -0
@@ -806,6 +806,9 @@ int nfs_lock(struct file *filp, int cmd, struct file_lock *fl)nfs_inc_stats (inode,NFSIOS_VFSLOCK ); +if (fl->fl_flags &FL_RECLAIM ) +return -ENOGRACE ; +/* No mandatory locks over NFS */ if (__mandatory_lock (inode) && fl->fl_type !=F_UNLCK ) goto out_err;
fs/nfsd/nfs4state.c +3 -0
@@ -6903,6 +6903,9 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,if (!locks_in_grace (net) && lock->lk_reclaim) goto out; +if (lock->lk_reclaim) + fl_flags |=FL_RECLAIM ; + fp = lock_stp->st_stid.sc_file;switch (lock->lk_type) {case NFS4_READW_LT :
fs/nfsd/nfsproc.c +1 -0
@@ -881,6 +881,7 @@ nfserrno (int errno) { nfserr_serverfault, -ENFILE }, { nfserr_io, -EUCLEAN }, { nfserr_perm, -ENOKEY }, + { nfserr_no_grace, -ENOGRACE}, };int i;
include/linux/errno.h +1 -0
@@ -31,5 +31,6 @@#define EJUKEBOX 528/* Request initiated, but will not complete before timeout */ #define EIOCBQUEUED 529/* iocb queued, will get completion event */ #define ERECALLCONFLICT 530/* conflict with recalled state */ +#define ENOGRACE 531/* NFS file lock reclaim refused */ #endif
include/linux/fs.h +1 -0
@@ -997,6 +997,7 @@ static inline struct file *get_file(struct file *f)#define FL_UNLOCK_PENDING 512/* Lease is being broken */ #define FL_OFDLCK 1024/* lock is "owned" by struct file */ #define FL_LAYOUT 2048/* outstanding pNFS layout */ +#define FL_RECLAIM 4096/* reclaiming from a reboot server */ #define FL_CLOSE_POSIX (FL_POSIX | FL_CLOSE)
Signature · 1 line
2.31.1
Quoted 2 lines · J. Bruce Fields
With those changes I'm passing connecthon tests for NFSv3-4.2 reexports of an NFSv4.0 filesystem.
But I hadn't tested reexports of an NFSv3 filesystem. With the following server-side patch I also pass connectathon on NFSv3-4.2 reexports of an NFSv3 filesystem.--b.
[PATCH 9/8] nfsd: fix crash on LOCKT on reexported NFSv3
From: "J. Bruce Fields" <[email protected]>
Unlike other filesystems, NFSv3 tries to use fl_file in the GETLK case.
--- fs/nfsd/nfs4state.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/nfsd/nfs4state.c +3 -2
@@ -7043,8 +7043,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,/* * The NFSv4 spec allows a client to do a LOCKT without holding an OPEN, * so we do a temporary open here just to get an open file to pass to -* vfs_test_lock. (Arguably perhaps test_lock should be done with an -* inode operation.) +* vfs_test_lock. */ static __be32 nfsd_test_lock (struct svc_rqst *rqstp,struct svc_fh *fhp,struct file_lock *lock) {
@@ -7059,7 +7058,9 @@ static __be32 nfsd_test_lock(struct svc_rqst *rqstp, struct svc_fh *fhp, struct NFSD_MAY_READ));if (err) goto out; + lock->fl_file = nf->nf_file; err =nfserrno (vfs_test_lock (nf->nf_file, lock)); + lock->fl_file =NULL ; out:fh_unlock (fhp);nfsd_file_put (nf);
Signature · 1 line
2.31.1
Quoted 6 lines · J. Bruce Fields
From: "J. Bruce Fields" <[email protected]>
The following fix up some problems that can cause crashes or silently broken lock guarantees in the reexport case.
Quoted 6 lines
Note:
- patches 1-5 are server side
- patches 6-7 are client side
- patch 8 affects bothSimplest might be for Trond or Anna to ACK 6-8, if they look OK, and
They look okay to me. You can add:
to all three.
Anna
Quoted 66 lines
then submit them all through the server. But those three sets of patches are all independent if you'd rather split them up.
Not fixed:
- Attempts to reclaim locks after a reboot of the reexport server will fail. This at least seems like an improvement over the current situation, which is that they'll succeed even in cases where they shouldn't. Complete support for reboot recovery is a bigger job.- NFSv4.1+ lock nofications don't work. So, clients have to poll as they do with NFSv4.0, which is suboptimal, but correct (and an improvement over the current situation, which is a kernel oops).
So what we have at this point is a suboptimal lock implementation that doesn't support lock recovery.
Another alternative might be to turn off file locking entirely in the re-export case. I'd rather take the incremental improvement and fix the oopses.
Change since v2:
- keepnlmsvc_file_inodea static inline to address build failure identified by the kernel test robot
Changes since v1:
- Use ENOGRACE instead of returning NFS-specific error from vfs lock method.
- Take write opens for write locks in the NLM case (as we always have in the NFSv4 case).
- Don't block NLM threads waiting for blocking locks.With those changes I'm passing connecthon tests for NFSv3-4.2 reexports of an NFSv4.0 filesystem.
--b.
J. Bruce Fields (8):
lockd: lockd server-side shouldn't setfl_ops
nlm: minornlm_lookup_fileargument change
nlm: minor refactoring
lockd: updatenlm_lookup_filereexport comment Keep read and write fds with eachnlm_file
nfs: don't atempt blocking locks on nfs reexports
lockd: don't attempt blocking locks on nfs reexports
nfs: don't allow reexport reclaimsfs/lockd/svc4proc.c | 6 +- fs/lockd/svclock.c | 80 ++++++++++++++---------- fs/lockd/svcproc.c | 6 +- fs/lockd/svcsubs.c | 117 +++++++++++++++++++++++++----------- fs/nfs/export.c | 2 +- fs/nfs/file.c | 3 + fs/nfsd/lockd.c | 8 ++- fs/nfsd/nfs4state.c | 11 +++- fs/nfsd/nfsproc.c | 1 + include/linux/errno.h | 1 + include/linux/exportfs.h | 2 + include/linux/fs.h | 1 + include/linux/lockd/bind.h | 3 +- include/linux/lockd/lockd.h | 11 +++- 14 files changed, 170 insertions(+), 82 deletions(-)--
2.31.1
Quoted 16 lines · Anna Schumaker
Quoted 11 lines · J. Bruce Fields
From: "J. Bruce Fields" <[email protected]>
The following fix up some problems that can cause crashes or silently broken lock guarantees in the reexport case.
Note:
- patches 1-5 are server side
- patches 6-7 are client side
- patch 8 affects both
Quoted 7 lines
Quoted 1 line
Simplest might be for Trond or Anna to ACK 6-8, if they look OK, and
They look okay to me. You can add:
Acked-by Anna Schumaker <[email protected]>to all three.
Anna
Thanks. I've captured Anna's Acks and included 9/8 (posted a few days ago). See:
https://git.kernel.org/pub/scm/linux/kernel/git/cel/linux.git/log/?h=for-next
Quoted 63 lines
Quoted 63 lines
then submit them all through the server. But those three sets of patches are all independent if you'd rather split them up.
Not fixed:
- Attempts to reclaim locks after a reboot of the reexport server will fail. This at least seems like an improvement over the current situation, which is that they'll succeed even in cases where they shouldn't. Complete support for reboot recovery is a bigger job.- NFSv4.1+ lock nofications don't work. So, clients have to poll as they do with NFSv4.0, which is suboptimal, but correct (and an improvement over the current situation, which is a kernel oops).
So what we have at this point is a suboptimal lock implementation that doesn't support lock recovery.
Another alternative might be to turn off file locking entirely in the re-export case. I'd rather take the incremental improvement and fix the oopses.
Change since v2:
- keepnlmsvc_file_inodea static inline to address build failure identified by the kernel test robot
Changes since v1:
- Use ENOGRACE instead of returning NFS-specific error from vfs lock method.
- Take write opens for write locks in the NLM case (as we always have in the NFSv4 case).
- Don't block NLM threads waiting for blocking locks.With those changes I'm passing connecthon tests for NFSv3-4.2 reexports of an NFSv4.0 filesystem.
--b.
J. Bruce Fields (8):
lockd: lockd server-side shouldn't setfl_ops
nlm: minornlm_lookup_fileargument change
nlm: minor refactoring
lockd: updatenlm_lookup_filereexport comment Keep read and write fds with eachnlm_file
nfs: don't atempt blocking locks on nfs reexports
lockd: don't attempt blocking locks on nfs reexports
nfs: don't allow reexport reclaimsfs/lockd/svc4proc.c | 6 +- fs/lockd/svclock.c | 80 ++++++++++++++---------- fs/lockd/svcproc.c | 6 +- fs/lockd/svcsubs.c | 117 +++++++++++++++++++++++++----------- fs/nfs/export.c | 2 +- fs/nfs/file.c | 3 + fs/nfsd/lockd.c | 8 ++- fs/nfsd/nfs4state.c | 11 +++- fs/nfsd/nfsproc.c | 1 + include/linux/errno.h | 1 + include/linux/exportfs.h | 2 + include/linux/fs.h | 1 + include/linux/lockd/bind.h | 3 +- include/linux/lockd/lockd.h | 11 +++- 14 files changed, 170 insertions(+), 82 deletions(-)
Quoted 3 lines
Quoted 3 lines
--
2.31.1
--
Chuck Lever