Skip to contentSkip to conversation

locks: add locks_move_blocks in posix_lock_inode

PATCH In review yangerkun 3 participants 6 messages Jun 1, 2020 – Jun 3, 2020

Subsystems (2)
lore
Share & tools
lore

yangerkun

author
#0 lore raw

PATCH 1/1 locks: add locks_move_blocks in posix_lock_inode

We forget to call locks_move_blocks in posix_lock_inode when try to process same owner and different types.

---
 fs/locks.c | 1 +
 1 file changed, 1 insertion(+)
fs/locks.c +1 -0
index b8a31c1c4fff..36bd2c221786 100644
@@ -1282,6 +1282,7 @@ static int posix_lock_inode(struct inode *inode, struct file_lock *request,
 				if (!new_fl)
 					goto out;
 				locks_copy_lock(new_fl, request);
+				locks_move_blocks(new_fl, request);
 				request = new_fl;
 				new_fl = NULL;
 				locks_insert_lock_ctx(request, &fl->fl_list);
Signature · 1 line
2.21.3
#1 lore raw
Quoted 3 lines · yangerkun

We forget to call locks_move_blocks in posix_lock_inode when try to process same owner and different types.

This patch is not necessary.
The caller of posix_lock_inode() must calls locks_delete_block() on 'request', and that will remove all blocked request and retry them.

So calling locks_move_blocks() here is at most an optimization. Maybe it is a useful one.

What led you to suggesting this patch? Were you just examining the code, or was there some problem that you were trying to solve?

Thanks,
NeilBrown

Quoted 19 lines
---
 fs/locks.c | 1 +
 1 file changed, 1 insertion(+)
fs/locks.c +1 -0
index b8a31c1c4fff..36bd2c221786 100644
@@ -1282,6 +1282,7 @@ static int posix_lock_inode(struct inode *inode, struct file_lock *request,
 				if (!new_fl)
 					goto out;
 				locks_copy_lock(new_fl, request);
+				locks_move_blocks(new_fl, request);
 				request = new_fl;
 				new_fl = NULL;
 				locks_insert_lock_ctx(request, &fl->fl_list);
Signature · 1 line
2.21.3
author
#2 lore raw
Quoted 10 lines · NeilBrown
Quoted 3 lines · yangerkun

We forget to call locks_move_blocks in posix_lock_inode when try to process same owner and different types.

This patch is not necessary.
The caller of posix_lock_inode() must calls locks_delete_block() on 'request', and that will remove all blocked request and retry them.

Quoted 5 lines

So calling locks_move_blocks() here is at most an optimization. Maybe it is a useful one.

What led you to suggesting this patch? Were you just examining the code, or was there some problem that you were trying to solve?

Actually, case of this means just replace a exists file_lock. And once we forget to call locks_move_blocks, the function call of posix_lock_inode will also call locks_delete_block, and will wakeup all blocked requests and retry them. But we should do this until we UNLOCK the file_lock! So, it's really a bug here.

Thanks,
Kun.

Quoted 24 lines

Thanks,
NeilBrown

Quoted 19 lines
---
  fs/locks.c | 1 +
  1 file changed, 1 insertion(+)
fs/locks.c +1 -0
index b8a31c1c4fff..36bd2c221786 100644
@@ -1282,6 +1282,7 @@ static int posix_lock_inode(struct inode *inode, struct file_lock *request,
  				if (!new_fl)
  					goto out;
  				locks_copy_lock(new_fl, request);
+				locks_move_blocks(new_fl, request);
  				request = new_fl;
  				new_fl = NULL;
  				locks_insert_lock_ctx(request, &fl->fl_list);
Signature · 1 line
2.21.3
maintainer
#3 lore raw
Quoted 19 lines · yangerkun
Quoted 10 lines · NeilBrown
Quoted 3 lines · yangerkun

We forget to call locks_move_blocks in posix_lock_inode when try to process same owner and different types.

This patch is not necessary.
The caller of posix_lock_inode() must calls locks_delete_block() on 'request', and that will remove all blocked request and retry them.

Quoted 5 lines

So calling locks_move_blocks() here is at most an optimization. Maybe it is a useful one.

What led you to suggesting this patch? Were you just examining the code, or was there some problem that you were trying to solve?

Quoted 6 lines

Actually, case of this means just replace a exists file_lock. And once we forget to call locks_move_blocks, the function call of posix_lock_inode will also call locks_delete_block, and will wakeup all blocked requests and retry them. But we should do this until we UNLOCK the file_lock! So, it's really a bug here.

Waking up waiters to re-poll a lock that's still blocked seems wrong. I agree with Neil that this is mainly an optimization, but it does look useful.

Unfortunately this is the type of thing that's quite difficult to test for in a userland testcase. Is this something you noticed due to the extra wakeups or did you find it by inspection? It'd be great to have a better way to test for this in xfstests or something.

I'll plan to add this to linux-next. It should make v5.9, but let me know if this is causing real-world problems and maybe we can make a case for v5.8.

Thanks,
Jeff

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
---
  fs/locks.c | 1 +
  1 file changed, 1 insertion(+)
fs/locks.c +1 -0
index b8a31c1c4fff..36bd2c221786 100644
@@ -1282,6 +1282,7 @@ static int posix_lock_inode(struct inode *inode, struct file_lock *request,
  				if (!new_fl)
  					goto out;
  				locks_copy_lock(new_fl, request);
+				locks_move_blocks(new_fl, request);
  				request = new_fl;
  				new_fl = NULL;
  				locks_insert_lock_ctx(request, &fl->fl_list);
Signature · 1 line
2.21.3
Signature · 1 line
Jeff Layton <[email protected]>
author
#4 lore raw
Quoted 27 lines · Jeff Layton
Quoted 19 lines · yangerkun
Quoted 10 lines · NeilBrown
Quoted 3 lines · yangerkun

We forget to call locks_move_blocks in posix_lock_inode when try to process same owner and different types.

This patch is not necessary.
The caller of posix_lock_inode() must calls locks_delete_block() on 'request', and that will remove all blocked request and retry them.

Quoted 5 lines

So calling locks_move_blocks() here is at most an optimization. Maybe it is a useful one.

What led you to suggesting this patch? Were you just examining the code, or was there some problem that you were trying to solve?

Quoted 6 lines

Actually, case of this means just replace a exists file_lock. And once we forget to call locks_move_blocks, the function call of posix_lock_inode will also call locks_delete_block, and will wakeup all blocked requests and retry them. But we should do this until we UNLOCK the file_lock! So, it's really a bug here.

Quoted 3 lines

Waking up waiters to re-poll a lock that's still blocked seems wrong. I agree with Neil that this is mainly an optimization, but it does look useful.

Agree. Logic of this seems wrong, but it won't trigger any problem since the waiters will conflict and try wait again.

Quoted 5 lines

Unfortunately this is the type of thing that's quite difficult to test for in a userland testcase. Is this something you noticed due to the extra wakeups or did you find it by inspection? It'd be great to have a better way to test for this in xfstests or something.

Notice this after reading the patch 5946c4319ebb ("fs/locks: allow a lock request to block other requests."), and find that we have do the same thing exist in flock_lock_inode and another place exists in posix_lock_inode.

Quoted 4 lines

I'll plan to add this to linux-next. It should make v5.9, but let me know if this is causing real-world problems and maybe we can make a case for v5.8.

Actually, I have not try to find will this lead to some real-world problems... Sorry for this.:(

Thanks,
Kun.

Quoted 25 lines

Thanks,
Jeff

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
---
   fs/locks.c | 1 +
   1 file changed, 1 insertion(+)
fs/locks.c +1 -0
index b8a31c1c4fff..36bd2c221786 100644
@@ -1282,6 +1282,7 @@ static int posix_lock_inode(struct inode *inode, struct file_lock *request,
   				if (!new_fl)
   					goto out;
   				locks_copy_lock(new_fl, request);
+				locks_move_blocks(new_fl, request);
   				request = new_fl;
   				new_fl = NULL;
   				locks_insert_lock_ctx(request, &fl->fl_list);
Signature · 1 line
2.21.3
maintainer
#5 lore raw
Quoted 48 lines · yangerkun
Quoted 25 lines · Jeff Layton
Quoted 14 lines · yangerkun
Quoted 13 lines · NeilBrown
Quoted 3 lines · yangerkun

We forget to call locks_move_blocks in posix_lock_inode when try to process same owner and different types.

This patch is not necessary.
The caller of posix_lock_inode() must calls locks_delete_block() on 'request', and that will remove all blocked request and retry them.

So calling locks_move_blocks() here is at most an optimization. Maybe it is a useful one.

Quoted 9 lines
Quoted 2 lines

What led you to suggesting this patch? Were you just examining the code, or was there some problem that you were trying to solve?

Actually, case of this means just replace a exists file_lock. And once we forget to call locks_move_blocks, the function call of posix_lock_inode will also call locks_delete_block, and will wakeup all blocked requests and retry them. But we should do this until we UNLOCK the file_lock! So, it's really a bug here.

Quoted 3 lines

Waking up waiters to re-poll a lock that's still blocked seems wrong. I agree with Neil that this is mainly an optimization, but it does look useful.

Agree. Logic of this seems wrong, but it won't trigger any problem since the waiters will conflict and try wait again.

Quoted 4 lines

Unfortunately this is the type of thing that's quite difficult to test for in a userland testcase. Is this something you noticed due to the extra wakeups or did you find it by inspection? It'd be great to have a better way to test for this in xfstests or something.

Notice this after reading the patch 5946c4319ebb ("fs/locks: allow a lock request to block other requests."), and find that we have do the same thing exist in flock_lock_inode and another place exists in posix_lock_inode.

Quoted 3 lines

I'll plan to add this to linux-next. It should make v5.9, but let me know if this is causing real-world problems and maybe we can make a case for v5.8.

Quoted 7 lines

Actually, I have not try to find will this lead to some real-world problems... Sorry for this.:(

Thanks,
Kun.

No problem. I doubt this would be easily noticeable in testing. Given that it's not causing immediate issues, we'll let it sit in linux-next for a cycle and plan to merge this for v5.9.

Thanks!

Signature · 1 line
Jeff Layton <[email protected]>