public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tune2fs: check whether dev is mounted or in use before setting
@ 2023-03-18  3:36 Zhiqiang Liu
  2023-03-18 16:24 ` Theodore Ts'o
  0 siblings, 1 reply; 5+ messages in thread
From: Zhiqiang Liu @ 2023-03-18  3:36 UTC (permalink / raw)
  To: Ext4 Developers List
  Cc: Theodore Y. Ts'o, adilger, Jan Kara, linfeilong, wuguanghao,
	zhanchengbin, libaokun1

From: Zhiqiang Liu <liuzhiqiang26@huawei.com>

tune2fs is used to adjust various tunable filesystem pars, which
may conflict with kernel operations. So we should check whether
device is mounted or in use at the begin similar to e2fsck and mke2fs.

Of course, we can ignore this check if -f is set.

Reported-by: Baokun Li <libaokun1@huawei.com>
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Signed-off-by: zhanchengbin <zhanchengbin1@huawei.com>
---
 misc/tune2fs.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index 458f7cf6..b667e1f4 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -3327,6 +3327,22 @@ retry_open:
 		goto closefs;
 	}

+	if (open_flag & EXT2_FLAG_RW) {
+		if (mount_flags & EXT2_MF_MOUNTED) {
+			fprintf(stderr, _("Warning! %s is mounted.\n"), device_name);
+			if (!f_flag) {
+				rc = 1;
+				goto closefs;
+			}
+		} else if (mount_flags & EXT2_MF_BUSY) {
+			fprintf(stderr, _("Warning! %s is in use by the system.\n"),
+					device_name);
+			if (!f_flag) {
+				rc = 1;
+				goto closefs;
+			}
+		}
+	}
 #ifdef NO_RECOVERY
 	/* Warn if file system needs recovery and it is opened for writing. */
 	if ((open_flag & EXT2_FLAG_RW) && !(mount_flags & EXT2_MF_MOUNTED) &&
-- 
2.33.0

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

end of thread, other threads:[~2023-03-20  2:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-18  3:36 [PATCH] tune2fs: check whether dev is mounted or in use before setting Zhiqiang Liu
2023-03-18 16:24 ` Theodore Ts'o
2023-03-19  5:44   ` Zhiqiang Liu
2023-03-19 13:02     ` Theodore Ts'o
2023-03-20  2:08       ` Zhiqiang Liu

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