mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] gfs2: restart rename when a signal interrupts the glock wait
@ 2026-11-25 17:50 Hengyu Liang
  2026-11-25 18:53 ` Andreas Gruenbacher
  0 siblings, 1 reply; 2+ messages in thread
From: Hengyu Liang @ 2026-11-25 17:50 UTC (permalink / raw)
  To: Andreas Gruenbacher; +Cc: gfs2, linux-kernel, stable

Commit 11d763f0b0af ("gfs2: Retries missing in gfs2_{rename,exchange}")
made gfs2_glock_async_wait() interruptible. It returns -EINTR when a
signal is pending.

However, -EINTR goes back to user space as it is, and the system call
is not restarted. As of now, rename() and renameat2() on gfs2 fail
with EINTR when a signal arrives while they wait for a glock, also
when the signal only stops and continues the process.

The issue can be reproduced with:

    mkfs.gfs2 -O -p lock_nolock -j 1 /dev/vda
    mount /dev/vda /mnt
    mkdir /mnt/a /mnt/b
    for i in $(seq 12000); do echo > /mnt/a/$i; done
    umount /mnt; mount /dev/vda /mnt
    mv /mnt/a/* /mnt/b/ &
    while kill -STOP $!; do kill -CONT $!; sleep 0.005; done

Before commit 11d763f0b0af ("gfs2: Retries missing in
gfs2_{rename,exchange}"), mv moves all 12000 files.

After that commit, the result for 783 of the files is:

    mv: cannot move '/mnt/a/10' to '/mnt/b/10': Interrupted system call

With this patch, mv moves all 12000 files again.

This patch will return -ERESTARTSYS instead, as gfs2_statfs_slow()
does for its glock wait, so that the system call is restarted.

Fixes: 11d763f0b0af ("gfs2: Retries missing in gfs2_{rename,exchange}")
Cc: stable@vger.kernel.org
Signed-off-by: Hengyu Liang <hengyul@cs.unc.edu>
---
I found this while comparing the behavior of different kernel versions.
I used an LLM to analyze the problem and to draft the patch and this
message, and I analyzed the result myself.

Since commit a098f26d3b80 ("gfs2: Get rid of sd_async_glock_wait"),
signals are only checked while a glock is still pending, so fewer
renames fail: 60 of the 12000 files on gfs2 for-next. The stable trees
that have commit 11d763f0b0af do not have that one, so the change is a
single line there.

Application impact (Ubuntu 26.04 user space): rsync 3.4.1 updates
12000 small files on gfs2 while its processes are stopped and
continued every 5 ms (kill -TSTP / -CONT). On v6.19, rsync exits with
0. On v7.0, it exits with 23 after 267 "rename ... Interrupted system
call" errors, and those files keep their old content.

Tested on gfs2 for-next (9aa0082cf969) with lock_nolock, KASAN and
lockdep: rename, RENAME_EXCHANGE and directory renames no longer fail
under a SA_RESTART handler or under stop / continue. A handler without
SA_RESTART still gets EINTR.

 fs/gfs2/glock.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index aa11168255e9..05e6b0f6ccc7 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -1318,7 +1318,7 @@ int gfs2_glock_async_wait(unsigned int num_gh, struct gfs2_holder *ghs,
 		if (!glocks_pending(num_gh, ghs))
 			break;
 		if (signal_pending(current)) {
-			ret = -EINTR;
+			ret = -ERESTARTSYS;
 			break;
 		}
 		ret = schedule_timeout(ret);
@@ -1329,7 +1329,7 @@ int gfs2_glock_async_wait(unsigned int num_gh, struct gfs2_holder *ghs,
 			break;
 		}
 		if (signal_pending(current)) {
-			ret = -EINTR;
+			ret = -ERESTARTSYS;
 			break;
 		}
 	}
@@ -1363,7 +1363,7 @@ int gfs2_glock_async_wait(unsigned int num_gh, struct gfs2_holder *ghs,
 	return ret;
 
 interrupted:
-	ret = -EINTR;
+	ret = -ERESTARTSYS;
 	goto out;
 }
 

base-commit: 9aa0082cf969a9973ec6554586753c53211ab799
-- 
2.53.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] gfs2: restart rename when a signal interrupts the glock wait
  2026-11-25 17:50 [PATCH] gfs2: restart rename when a signal interrupts the glock wait Hengyu Liang
@ 2026-11-25 18:53 ` Andreas Gruenbacher
  0 siblings, 0 replies; 2+ messages in thread
From: Andreas Gruenbacher @ 2026-11-25 18:53 UTC (permalink / raw)
  To: Hengyu Liang; +Cc: Andreas Gruenbacher, gfs2, linux-kernel, stable

On Wed, 25 Nov 2026 at 18:50, Hengyu Liang <hengyul@cs.unc.edu> wrote:
> Commit 11d763f0b0af ("gfs2: Retries missing in gfs2_{rename,exchange}")
> made gfs2_glock_async_wait() interruptible. It returns -EINTR when a
> signal is pending.
>
> However, -EINTR goes back to user space as it is, and the system call
> is not restarted. As of now, rename() and renameat2() on gfs2 fail
> with EINTR when a signal arrives while they wait for a glock, also
> when the signal only stops and continues the process.

This is indeed undesirable.

> The issue can be reproduced with:
>
>     mkfs.gfs2 -O -p lock_nolock -j 1 /dev/vda
>     mount /dev/vda /mnt
>     mkdir /mnt/a /mnt/b
>     for i in $(seq 12000); do echo > /mnt/a/$i; done
>     umount /mnt; mount /dev/vda /mnt
>     mv /mnt/a/* /mnt/b/ &
>     while kill -STOP $!; do kill -CONT $!; sleep 0.005; done
>
> Before commit 11d763f0b0af ("gfs2: Retries missing in
> gfs2_{rename,exchange}"), mv moves all 12000 files.
>
> After that commit, the result for 783 of the files is:
>
>     mv: cannot move '/mnt/a/10' to '/mnt/b/10': Interrupted system call
>
> With this patch, mv moves all 12000 files again.
>
> This patch will return -ERESTARTSYS instead, as gfs2_statfs_slow()
> does for its glock wait, so that the system call is restarted.

Why not make gfs2_glock_async_wait() non-interruptible instead?
Something like the below should work.

Thanks,
Andreas

---
 fs/gfs2/glock.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index d22a088c66cd..3a49699ba9cb 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -1284,9 +1284,9 @@ int gfs2_glock_async_wait(unsigned int num_gh, struct gfs2_holder *ghs,
 		max_shift = BITS_PER_LONG - 2 - __fls(GL_GLOCK_HOLD_INCR);
 		incr = min(GL_GLOCK_HOLD_INCR << min(retries - 1, max_shift),
 			   10 * HZ - GL_GLOCK_MIN_HOLD);
-		schedule_timeout_interruptible(get_random_long() % (incr / 3));
-		if (signal_pending(current))
-			goto interrupted;
+		schedule_timeout_killable(get_random_long() % (incr / 3));
+		if (fatal_signal_pending(current))
+			return -EINTR;
 		timeout += (incr / 3) + get_random_long() % (incr / 3);
 	}
 
@@ -1300,21 +1300,17 @@ int gfs2_glock_async_wait(unsigned int num_gh, struct gfs2_holder *ghs,
 			prepare_to_wait(waitq[i], wait + i, TASK_INTERRUPTIBLE);
 		if (!glocks_pending(num_gh, ghs))
 			break;
-		if (signal_pending(current)) {
+		ret = schedule_timeout_killable(ret);
+		if (fatal_signal_pending(current)) {
 			ret = -EINTR;
 			break;
 		}
-		ret = schedule_timeout(ret);
 		if (!glocks_pending(num_gh, ghs))
 			break;
 		if (!ret) {
 			ret = -ESTALE; /* request timed out. */
 			break;
 		}
-		if (signal_pending(current)) {
-			ret = -EINTR;
-			break;
-		}
 	}
 	for (i = 0; i < num_gh; i++)
 		finish_wait(waitq[i], wait + i);
@@ -1344,10 +1340,6 @@ int gfs2_glock_async_wait(unsigned int num_gh, struct gfs2_holder *ghs,
 		}
 	}
 	return ret;
-
-interrupted:
-	ret = -EINTR;
-	goto out;
 }
 
 /**

base-commit: 4dce97c6c265544342e716e62fd24bbb232590c5
-- 
2.56.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-25 18:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 17:50 [PATCH] gfs2: restart rename when a signal interrupts the glock wait Hengyu Liang
2026-11-25 18:53 ` Andreas Gruenbacher

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®