From: Zhiqiang Liu <liuzhiqiang26@huawei.com>
To: Ext4 Developers List <linux-ext4@vger.kernel.org>
Cc: "Theodore Y. Ts'o" <tytso@mit.edu>, <adilger@whamcloud.com>,
Jan Kara <jack@suse.cz>, linfeilong <linfeilong@huawei.com>,
wuguanghao <wuguanghao3@huawei.com>,
zhanchengbin <zhanchengbin1@huawei.com>, <libaokun1@huawei.com>
Subject: [PATCH] tune2fs: check whether dev is mounted or in use before setting
Date: Sat, 18 Mar 2023 11:36:03 +0800 [thread overview]
Message-ID: <8babc8eb-1713-91c9-1efa-496909340a6f@huawei.com> (raw)
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
next reply other threads:[~2023-03-18 3:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-18 3:36 Zhiqiang Liu [this message]
2023-03-18 16:24 ` [PATCH] tune2fs: check whether dev is mounted or in use before setting 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
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=8babc8eb-1713-91c9-1efa-496909340a6f@huawei.com \
--to=liuzhiqiang26@huawei.com \
--cc=adilger@whamcloud.com \
--cc=jack@suse.cz \
--cc=libaokun1@huawei.com \
--cc=linfeilong@huawei.com \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
--cc=wuguanghao3@huawei.com \
--cc=zhanchengbin1@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