Skip to contentSkip to conversation

lockd: fix hang on shutdown when there are active locks

PATCH In review Jeff Layton 2 participants 5 messages Jul 11, 2022

Subsystems (2)
lore
Share & tools
lore

Jeff Layton

author maintainer
#0 lore raw

cover lockd: fix hang on shutdown when there are active locks

We had a report that shutting down nfsd would hang when there were active NFSv3 locks. The first patch fixes that. While testing that I hit a crash in nlm_close_files. The second patch fixes that one.

Jeff Layton (2):
lockd: set fl_owner when unlocking files
lockd: fix nlm_close_files

 fs/lockd/svcsubs.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
Signature · 1 line
2.36.1
author maintainer
#1 lore raw

PATCH 1/2 lockd: set fl_owner when unlocking files

Unlocking a POSIX inode with vfs_lock_file only works if the owner matches. Ensure we set it in the request.

Cc J. Bruce Fields <[email protected]>
Fixes 7f024fcd5c97 ("Keep read and write fds with each nlm_file")
---
 fs/lockd/svcsubs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/lockd/svcsubs.c +3 -2
index 0a22a2faf552..b2f277727469 100644
@@ -176,7 +176,7 @@ nlm_delete_file(struct nlm_file *file)
 	}
 }
 
-static int nlm_unlock_files(struct nlm_file *file)
+static int nlm_unlock_files(struct nlm_file *file, fl_owner_t owner)
 {
 	struct file_lock lock;
 
@@ -184,6 +184,7 @@ static int nlm_unlock_files(struct nlm_file *file)
 	lock.fl_type  = F_UNLCK;
 	lock.fl_start = 0;
 	lock.fl_end   = OFFSET_MAX;
+	lock.fl_owner = owner;
 	if (file->f_file[O_RDONLY] &&
 	    vfs_lock_file(file->f_file[O_RDONLY], F_SETLK, &lock, NULL))
 		goto out_err;
@@ -225,7 +226,7 @@ nlm_traverse_locks(struct nlm_host *host, struct nlm_file *file,
 		if (match(lockhost, host)) {
 
 			spin_unlock(&flctx->flc_lock);
-			if (nlm_unlock_files(file))
+			if (nlm_unlock_files(file, fl->fl_owner))
 				return 1;
 			goto again;
 		}
Signature · 1 line
2.36.1
author maintainer
#2 lore raw

Re: [PATCH 1/2] lockd: set fl_owner when unlocking files

Quoted 3 lines · Jeff Layton

Unlocking a POSIX inode with vfs_lock_file only works if the owner matches. Ensure we set it in the request.

Oof, that description makes no sense. How about:

"Unlocking a POSIX lock on an inode with vfs_lock_file..."

Quoted 37 lines
Cc J. Bruce Fields <[email protected]>
Fixes 7f024fcd5c97 ("Keep read and write fds with each nlm_file")
---
 fs/lockd/svcsubs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/lockd/svcsubs.c +3 -2
index 0a22a2faf552..b2f277727469 100644
@@ -176,7 +176,7 @@ nlm_delete_file(struct nlm_file *file)
 	}
 }
 
-static int nlm_unlock_files(struct nlm_file *file)
+static int nlm_unlock_files(struct nlm_file *file, fl_owner_t owner)
 {
 	struct file_lock lock;
 
@@ -184,6 +184,7 @@ static int nlm_unlock_files(struct nlm_file *file)
 	lock.fl_type  = F_UNLCK;
 	lock.fl_start = 0;
 	lock.fl_end   = OFFSET_MAX;
+	lock.fl_owner = owner;
 	if (file->f_file[O_RDONLY] &&
 	    vfs_lock_file(file->f_file[O_RDONLY], F_SETLK, &lock, NULL))
 		goto out_err;
@@ -225,7 +226,7 @@ nlm_traverse_locks(struct nlm_host *host, struct nlm_file *file,
 		if (match(lockhost, host)) {
 
 			spin_unlock(&flctx->flc_lock);
-			if (nlm_unlock_files(file))
+			if (nlm_unlock_files(file, fl->fl_owner))
 				return 1;
 			goto again;
 		}
Signature · 1 line
Jeff Layton <[email protected]>
author maintainer
#3 lore raw

PATCH 2/2 lockd: fix nlm_close_files

In reply to Jeff Layton

This loop condition tries a bit too hard to be clever. Just test for the two indices we care about explicitly.

Cc J. Bruce Fields <[email protected]>
Fixes 7f024fcd5c97 ("Keep read and write fds with each nlm_file")
---
 fs/lockd/svcsubs.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
fs/lockd/svcsubs.c +4 -5
index b2f277727469..e1c4617de771 100644
@@ -283,11 +283,10 @@ nlm_file_inuse(struct nlm_file *file)
 
 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);
+	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]);
 }
 
 /*
Signature · 1 line
2.36.1
#4 lore raw
In reply to Jeff Layton
Quoted 8 lines · Jeff Layton

We had a report that shutting down nfsd would hang when there were active NFSv3 locks. The first patch fixes that. While testing that I hit a crash in nlm_close_files. The second patch fixes that one.

Quoted 6 lines

Jeff Layton (2):
lockd: set fl_owner when unlocking files
lockd: fix nlm_close_files

fs/lockd/svcsubs.c | 14 +++++++-------

1 file changed, 7 insertions(+), 7 deletions(-)

Grabbed both for the next 5.18-rc PR.

--
Chuck Lever