util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] losetup: don't skip adding a new device if it already has a device node
@ 2022-02-25 18:09 Christoph Hellwig
  2022-02-25 18:48 ` Chaitanya Kulkarni
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Christoph Hellwig @ 2022-02-25 18:09 UTC (permalink / raw)
  To: util-linux; +Cc: linux-block, Luis Chamberlain

Linux plans to deprecate the auto-creation of block devices based on
access to the devic 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 superflous 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>
---
 sys-utils/losetup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys-utils/losetup.c b/sys-utils/losetup.c
index c400cbf12..09c028b6b 100644
--- a/sys-utils/losetup.c
+++ b/sys-utils/losetup.c
@@ -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 */
-- 
2.30.2


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

* Re: [PATCH] losetup: don't skip adding a new device if it already has a device node
  2022-02-25 18:09 [PATCH] losetup: don't skip adding a new device if it already has a device node Christoph Hellwig
@ 2022-02-25 18:48 ` Chaitanya Kulkarni
  2022-02-25 21:12 ` Luis Chamberlain
  2022-02-28 10:16 ` Karel Zak
  2 siblings, 0 replies; 4+ messages in thread
From: Chaitanya Kulkarni @ 2022-02-25 18:48 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-block, util-linux, Luis Chamberlain

On 2/25/22 10:09, Christoph Hellwig wrote:
> Linux plans to deprecate the auto-creation of block devices based on
> access to the devic node starting from kernel 5.18.  Without that feature

's/devic/device/g'

> 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 superflous mknod.

's/superflous/superfluous/g'

> 
> 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>
> ---

Looks good.

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>

-ck



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

* Re: [PATCH] losetup: don't skip adding a new device if it already has a device node
  2022-02-25 18:09 [PATCH] losetup: don't skip adding a new device if it already has a device node Christoph Hellwig
  2022-02-25 18:48 ` Chaitanya Kulkarni
@ 2022-02-25 21:12 ` Luis Chamberlain
  2022-02-28 10:16 ` Karel Zak
  2 siblings, 0 replies; 4+ messages in thread
From: Luis Chamberlain @ 2022-02-25 21:12 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: util-linux, linux-block

On Fri, Feb 25, 2022 at 07:09:03PM +0100, Christoph Hellwig wrote:
> Linux plans to deprecate the auto-creation of block devices based on
> access to the devic 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 superflous 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.

I think it would help to explain what the issue is, with a simple
example on the commit log.

By default loading the loop module we'll create only 8 loopback
devices. Prior to the new CONFIG_BLOCK_LEGACY_AUTOLOAD which intends
to deprecate the whole oldschool probe functionality which used try
to load the respective block driver (loop in this case) when the
driver is not present but the nodes are created manually, the following
piece of code would work:

losetup -D
modprobe -r loop
modprobe loop

rm -f foo.img
truncate -s 10M foo.img

# Note: /dev/loop8 by default won't exist as we default to 7
# loop devices
rm -f /dev/loop8
mknod /dev/loop8 b 7 8
losetup /dev/loop8 foo.img

When deprecating this probe --> module load logic, if the
mknod is run we'd currently fail at the last step. With this
fix the last step will still work. However please note that
CONFIG_BLOCK_LEGACY_AUTOLOAD goes away the above will require
manually loading the loop module. Scripts which fail to load
the loop module prior to mknod will fail by definition of the
deprecation effort.

> Reported-by: Luis Chamberlain <mcgrof@kernel.org>
> Signed-off-by: Christoph Hellwig <hch@lst.de>

With that said:

Tested-by: Luis Chamberlain <mcgrof@kernel.org>

  Luis

> ---
>  sys-utils/losetup.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/sys-utils/losetup.c b/sys-utils/losetup.c
> index c400cbf12..09c028b6b 100644
> --- a/sys-utils/losetup.c
> +++ b/sys-utils/losetup.c
> @@ -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 */
> -- 
> 2.30.2
> 

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

* Re: [PATCH] losetup: don't skip adding a new device if it already has a device node
  2022-02-25 18:09 [PATCH] losetup: don't skip adding a new device if it already has a device node Christoph Hellwig
  2022-02-25 18:48 ` Chaitanya Kulkarni
  2022-02-25 21:12 ` Luis Chamberlain
@ 2022-02-28 10:16 ` Karel Zak
  2 siblings, 0 replies; 4+ messages in thread
From: Karel Zak @ 2022-02-28 10:16 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: util-linux, linux-block, Luis Chamberlain

On Fri, Feb 25, 2022 at 07:09:03PM +0100, Christoph Hellwig wrote:
>  sys-utils/losetup.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks.

 Karel


-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com


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

end of thread, other threads:[~2022-02-28 10:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-25 18:09 [PATCH] losetup: don't skip adding a new device if it already has a device node Christoph Hellwig
2022-02-25 18:48 ` Chaitanya Kulkarni
2022-02-25 21:12 ` Luis Chamberlain
2022-02-28 10:16 ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).