All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] resize2fs: open device read-only when -P is passed
@ 2022-05-26  1:08 Michael Hudson-Doyle
  2022-08-13  1:11 ` Theodore Ts'o
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Hudson-Doyle @ 2022-05-26  1:08 UTC (permalink / raw)
  To: linux-ext4; +Cc: Michael Hudson-Doyle

We ran into this because we noticed that resize2fs -P $device was
triggering udev events.

I added a very simple test that just checks resize2fs -P on a file
lacking the w bit succeeds.

Signed-off-by: Michael Hudson-Doyle <michael.hudson@ubuntu.com>
---
 resize/main.c             | 8 ++++++--
 tests/scripts/resize_test | 8 ++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/resize/main.c b/resize/main.c
index bceaa1677..073c0bc7c 100644
--- a/resize/main.c
+++ b/resize/main.c
@@ -256,6 +256,7 @@ int main (int argc, char ** argv)
 	int		force_min_size = 0;
 	int		print_min_size = 0;
 	int		fd, ret;
+	int		open_flags = O_RDWR;
 	blk64_t		new_size = 0;
 	blk64_t		max_size = 0;
 	blk64_t		min_size = 0;
@@ -363,7 +364,10 @@ int main (int argc, char ** argv)
 		len = 2 * len;
 	}
 
-	fd = ext2fs_open_file(device_name, O_RDWR, 0);
+	if (print_min_size)
+		open_flags = O_RDONLY;
+
+	fd = ext2fs_open_file(device_name, open_flags, 0);
 	if (fd < 0) {
 		com_err("open", errno, _("while opening %s"),
 			device_name);
@@ -401,7 +405,7 @@ int main (int argc, char ** argv)
 #endif
 		io_ptr = unix_io_manager;
 
-	if (!(mount_flags & EXT2_MF_MOUNTED))
+	if (!(mount_flags & EXT2_MF_MOUNTED) && !print_min_size)
 		io_flags = EXT2_FLAG_RW | EXT2_FLAG_EXCLUSIVE;
 
 	io_flags |= EXT2_FLAG_64BITS | EXT2_FLAG_THREADS;
diff --git a/tests/scripts/resize_test b/tests/scripts/resize_test
index fc9d1c246..a000c85e5 100755
--- a/tests/scripts/resize_test
+++ b/tests/scripts/resize_test
@@ -60,6 +60,14 @@ rm -f $OUT_TMP
 echo $FSCK -fy $TMPFILE >> $LOG 2>&1 
 $FSCK -fy $TMPFILE >> $LOG 2>&1 
 
+chmod u-w $TMPFILE
+echo $RESIZE2FS -P $TMPFILE >> $LOG 2>&1
+if ! $RESIZE2FS -P $TMPFILE >> $LOG 2>&1
+then
+	return 1
+fi
+chmod u+w $TMPFILE
+
 echo $RESIZE2FS $RESIZE2FS_OPTS -d $DBG_FLAGS $TMPFILE $SIZE_2 >> $LOG 2>&1
 if ! $RESIZE2FS $RESIZE2FS_OPTS -d $DBG_FLAGS $TMPFILE $SIZE_2 >> $LOG 2>&1
 then
-- 
2.34.1


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

* Re: [PATCH] resize2fs: open device read-only when -P is passed
  2022-05-26  1:08 [PATCH] resize2fs: open device read-only when -P is passed Michael Hudson-Doyle
@ 2022-08-13  1:11 ` Theodore Ts'o
  0 siblings, 0 replies; 3+ messages in thread
From: Theodore Ts'o @ 2022-08-13  1:11 UTC (permalink / raw)
  To: Michael Hudson-Doyle; +Cc: linux-ext4

On Thu, May 26, 2022 at 01:08:28PM +1200, Michael Hudson-Doyle wrote:
> We ran into this because we noticed that resize2fs -P $device was
> triggering udev events.
> 
> I added a very simple test that just checks resize2fs -P on a file
> lacking the w bit succeeds.
> 
> Signed-off-by: Michael Hudson-Doyle <michael.hudson@ubuntu.com>

Applied, thanks!

						- Ted

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

* [PATCH] resize2fs: open device read-only when -P is passed
@ 2022-05-26  0:33 Michael Hudson-Doyle
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Hudson-Doyle @ 2022-05-26  0:33 UTC (permalink / raw)
  To: linux-ext4; +Cc: Michael Hudson-Doyle

We ran into this because we noticed that resize2fs -P $device was
triggering udev events.

I added a very simple test that just checks resize2fs -P on a file
lacking the w bit succeeds.

Signed-off-by: Michael Hudson-Doyle <michael.hudson@canonical.com>
---
 resize/main.c             | 8 ++++++--
 tests/scripts/resize_test | 8 ++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/resize/main.c b/resize/main.c
index bceaa1677..073c0bc7c 100644
--- a/resize/main.c
+++ b/resize/main.c
@@ -256,6 +256,7 @@ int main (int argc, char ** argv)
 	int		force_min_size = 0;
 	int		print_min_size = 0;
 	int		fd, ret;
+	int		open_flags = O_RDWR;
 	blk64_t		new_size = 0;
 	blk64_t		max_size = 0;
 	blk64_t		min_size = 0;
@@ -363,7 +364,10 @@ int main (int argc, char ** argv)
 		len = 2 * len;
 	}
 
-	fd = ext2fs_open_file(device_name, O_RDWR, 0);
+	if (print_min_size)
+		open_flags = O_RDONLY;
+
+	fd = ext2fs_open_file(device_name, open_flags, 0);
 	if (fd < 0) {
 		com_err("open", errno, _("while opening %s"),
 			device_name);
@@ -401,7 +405,7 @@ int main (int argc, char ** argv)
 #endif
 		io_ptr = unix_io_manager;
 
-	if (!(mount_flags & EXT2_MF_MOUNTED))
+	if (!(mount_flags & EXT2_MF_MOUNTED) && !print_min_size)
 		io_flags = EXT2_FLAG_RW | EXT2_FLAG_EXCLUSIVE;
 
 	io_flags |= EXT2_FLAG_64BITS | EXT2_FLAG_THREADS;
diff --git a/tests/scripts/resize_test b/tests/scripts/resize_test
index fc9d1c246..a000c85e5 100755
--- a/tests/scripts/resize_test
+++ b/tests/scripts/resize_test
@@ -60,6 +60,14 @@ rm -f $OUT_TMP
 echo $FSCK -fy $TMPFILE >> $LOG 2>&1 
 $FSCK -fy $TMPFILE >> $LOG 2>&1 
 
+chmod u-w $TMPFILE
+echo $RESIZE2FS -P $TMPFILE >> $LOG 2>&1
+if ! $RESIZE2FS -P $TMPFILE >> $LOG 2>&1
+then
+	return 1
+fi
+chmod u+w $TMPFILE
+
 echo $RESIZE2FS $RESIZE2FS_OPTS -d $DBG_FLAGS $TMPFILE $SIZE_2 >> $LOG 2>&1
 if ! $RESIZE2FS $RESIZE2FS_OPTS -d $DBG_FLAGS $TMPFILE $SIZE_2 >> $LOG 2>&1
 then
-- 
2.34.1


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

end of thread, other threads:[~2022-08-13  1:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-26  1:08 [PATCH] resize2fs: open device read-only when -P is passed Michael Hudson-Doyle
2022-08-13  1:11 ` Theodore Ts'o
  -- strict thread matches above, loose matches on Subject: below --
2022-05-26  0:33 Michael Hudson-Doyle

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.