From: zhanchengbin <zhanchengbin1@huawei.com>
To: Theodore Ts'o <tytso@mit.edu>
Cc: <linux-ext4@vger.kernel.org>, <liuzhiqiang26@huawei.com>,
<linux-ext4@vger.kernel.org>
Subject: [PATCH v2] resize2fs: resize2fs disk hardlinks will be error
Date: Tue, 4 Jan 2022 22:23:52 +0800 [thread overview]
Message-ID: <9dcadf7a-b12a-c977-2de2-222e20f0cebe@huawei.com> (raw)
Resize2fs disk hardlinks which mounting after the same name as tmpfs
filesystem it will be error. The items in /proc/mounts are traversed,
when you get to tmpfs,file!=mnt->mnt_fsname, therefore, the
stat(mnt->mnt_fsname, &st_buf) branch is used, however, the values of
file_rdev and st_buf.st_rdev are the same. As a result, the system
mistakenly considers that disk is mounted to /root/tmp. As a result
, resize2fs fails.
example:
dev_name="/dev/sdc" (ps: a disk in you self)
mkdir /root/tmp
mkdir /root/mnt
mkfs.ext4 -F -b 1024 -E "resize=10000000" "${dev_name}" 32768
mount -t tmpfs "${dev_name}" /root/tmp
mount "${dev_name}" /root/mnt
ln "${dev_name}" "${dev_name}"-ln
resize2fs "${dev_name}"-ln 6G
Signed-off-by: zhanchengbin <zhanchengbin1@huawei.com>
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
---
lib/ext2fs/ismounted.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/lib/ext2fs/ismounted.c b/lib/ext2fs/ismounted.c
index aee7d726..463a82a6 100644
--- a/lib/ext2fs/ismounted.c
+++ b/lib/ext2fs/ismounted.c
@@ -98,6 +98,7 @@ static errcode_t check_mntent_file(const char
*mtab_file, const char *file,
{
struct mntent *mnt;
struct stat st_buf;
+ struct stat dir_st_buf;
errcode_t retval = 0;
dev_t file_dev=0, file_rdev=0;
ino_t file_ino=0;
@@ -144,8 +145,12 @@ static errcode_t check_mntent_file(const char
*mtab_file, const char *file,
if (stat(mnt->mnt_fsname, &st_buf) == 0) {
if (ext2fsP_is_disk_device(st_buf.st_mode)) {
#ifndef __GNU__
- if (file_rdev && (file_rdev == st_buf.st_rdev))
- break;
+ if (file_rdev && (file_rdev == st_buf.st_rdev)) {
+ if (stat(mnt->mnt_dir, &dir_st_buf) != 0)
+ continue;
+ if (file_rdev == dir_st_buf.st_dev)
+ break;
+ }
if (check_loop_mounted(mnt->mnt_fsname,
st_buf.st_rdev, file_dev,
file_ino) == 1)
--
2.27.0
next reply other threads:[~2022-01-04 14:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-04 14:23 zhanchengbin [this message]
2022-02-24 8:28 ` [PATCH v2] resize2fs: resize2fs disk hardlinks will be error zhanchengbin
2023-01-18 5:05 ` Theodore Ts'o
2023-01-18 22:30 ` Andreas Dilger
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=9dcadf7a-b12a-c977-2de2-222e20f0cebe@huawei.com \
--to=zhanchengbin1@huawei.com \
--cc=linux-ext4@vger.kernel.org \
--cc=liuzhiqiang26@huawei.com \
--cc=tytso@mit.edu \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.