From 47ed406f8594fcbcfe12727c6ade4579658a485e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20Wei=C3=9Fschuh?= Date: Wed, 16 Apr 2025 11:55:31 +0200 Subject: [PATCH] lib/loopdev: open loop control device read-only if possible MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Opening the control device read-write to trigger udev events is a hack. It works around a kernel bug which fails to send uevents directly from the kernel by triggering a full udev reprobe. While it works to trigger the events, it is problematic. The udev reprobe will asynchronously recreate all partition devices which requires an ungly locking and synchronization scheme after losetup has completed to guarantee the usability of the partition devices. The kernel has been fixed to properly emit these uevents in commit 7ed2a771b5fb ("loop: properly send KOBJ_CHANGED uevent for disk device"). Drop the workaround. This is a partial revert of commit ced1142d6f25 ("losetup: cleanup device node modes"). Signed-off-by: Thomas Weißschuh --- lib/loopdev.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/loopdev.c b/lib/loopdev.c index f2931552c..65efeb9ea 100644 --- a/lib/loopdev.c +++ b/lib/loopdev.c @@ -1418,11 +1418,7 @@ int loopcxt_setup_device(struct loopdev_cxt *lc) do { errno = 0; - /* For the ioctls, it's enough to use O_RDONLY for a read-only - * loop device, but udevd monitor devices by inotify, and udevd - * needs IN_CLOSE_WRITE event to trigger probing of the new device. - */ - dev_fd = __loopcxt_get_fd(lc, O_RDWR); + dev_fd = __loopcxt_get_fd(lc, mode); if (dev_fd >= 0 || lc->control_ok == 0) break; if (errno != EACCES && errno != ENOENT) -- 2.47.3