Linux EXT4 FS development
 help / color / mirror / Atom feed
From: Baokun Li <libaokun@linux.alibaba.com>
To: linux-ext4@vger.kernel.org
Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz,
	yi.zhang@huawei.com, ojaswin@linux.ibm.com,
	ritesh.list@gmail.com, djwong@kernel.org
Subject: [PATCH e2fsprogs] tune2fs: touch the device node after setting the label via ioctl
Date: Wed, 23 Sep 2026 21:22:23 +0800	[thread overview]
Message-ID: <20260923132223.3355764-1-libaokun@linux.alibaba.com> (raw)

When the file system is mounted, tune2fs sets the label through
FS_IOC_SETFSLABEL, which updates the label without touching the
mtime of the device node.  Consumers such as blkid use that mtime
to validate their cached superblock information, so the old label
can still be returned right after the change:

  blkid -s LABEL /dev/sdb    # gets "old" and caches it
  tune2fs -L new /dev/sdb    # online path, node mtime unchanged
  blkid -s LABEL /dev/sdb    # still gets "old" within 2s

The offline path is unaffected because writing the superblock
through the device node updates its mtime as a side effect.  The
ioctl path has no such side effect, so add an explicit utime() on
the device after a successful FS_IOC_SETFSLABEL.

The return value is ignored; if the touch fails, the behavior is
no worse than before.

Suggested-by: Theodore Ts'o <tytso@mit.edu>
Link: https://patch.msgid.link/arKZu30pMe0ZavVA@mit.edu
Signed-off-by: Baokun Li <libaokun@linux.alibaba.com>
---
 misc/tune2fs.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index 2d85fb704e15..87b8e6830bb9 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -48,6 +48,7 @@ extern int optind;
 #endif
 #include <string.h>
 #include <time.h>
+#include <utime.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <libgen.h>
@@ -3167,6 +3168,14 @@ static int handle_fslabel(int setlabel)
 		return 1;
 	}
 	close(fd);
+
+	/*
+	 * FS_IOC_SETFSLABEL does not touch the device mtime that
+	 * blkid uses to validate its cache; touch the device so
+	 * mtime-based consumers see the change.
+	 */
+	utime(device_name, NULL);
+
 	return 0;
 #else
 	return -1;
-- 
2.43.7


             reply	other threads:[~2026-09-23 13:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-23 13:22 Baokun Li [this message]
2026-09-23 17:13 ` [PATCH e2fsprogs] tune2fs: touch the device node after setting the label via ioctl Darrick J. Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260923132223.3355764-1-libaokun@linux.alibaba.com \
    --to=libaokun@linux.alibaba.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=djwong@kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=ojaswin@linux.ibm.com \
    --cc=ritesh.list@gmail.com \
    --cc=tytso@mit.edu \
    --cc=yi.zhang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox