]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
losetup: don't skip adding a new device if it already has a device node
authorChristoph Hellwig <hch@lst.de>
Fri, 25 Feb 2022 18:09:03 +0000 (19:09 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 28 Feb 2022 10:14:35 +0000 (11:14 +0100)
Linux plans to deprecate the auto-creation of block devices based on
access to the device node starting from kernel 5.18.  Without that feature
losetup will fail to create the loop device if a device node already
exists, but the loop device to back it in the kernel does not exist yet.
This is a scenario that should not happen in modern udev based
distributions, but apparently there still are various scripts around that
manually call the superfluous mknod.

Change losetup to unconditionally call loopcxt_add_device when a specific
device node is specified on the command line.  If the loop device
already exists the LOOP_CTL_ADD ioctl will fail, but given that losetup
ignores the return value from loopcxt_add_device that failure has no
further effect.

Reported-by: Luis Chamberlain <mcgrof@kernel.org>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/losetup.c

index c400cbf12863a2c6035da31db30d15124b57bf2a..09c028b6b4e620fba1a2f7fcdfebb57c34f4cf62 100644 (file)
@@ -522,7 +522,7 @@ static int create_loop(struct loopdev_cxt *lc,
                }
        }
 
-       if (hasdev && !is_loopdev(loopcxt_get_device(lc)))
+       if (hasdev)
                loopcxt_add_device(lc);
 
        /* losetup --noverlap /dev/loopN file.img */