Re: `losetup --remove` is confusing, and misuse silently fails

Karel Zak <[email protected]> Tue, 21 Oct 2025 12:00:23 +0200
Newsgroups org.kernel.vger.util-linux
Message-ID <ymw6pydao6vwwvav346losfnhvynbxapxxoiv77eoendsgnqa4@dcimzsl3szvn>
On Fri, Oct 17, 2025 at 10:55:17AM +0200, Benno Schulenberg wrote:
> 
> Op 16-10-2025 om 12:28 schreef Karel Zak:
> > https://github.com/util-linux/util-linux/pull/3803
> 
> Misusing the tool now gives a surprising a result:
> 
>   # ./losetup --remove --detach
>   losetup: /dev/--detach: remove failed: Success
> 
>   # ./losetup --remove --detach loop0
>   losetup: /dev/--detach: remove failed: Success
>   losetup: /dev/loop0: remove failed: Device or resource busy

Ah, this is unpleasant. Thank you for reporting it. 

> Ideally, `losetup` would first interpret all options, and complain
> that --remove and --detach cannot be combined.  (The code for that
> seems to be there, but it doesn't appear to have any effect.)
> 
> But at least it shouldn't print "Success" when something failed.

Both issues should be fixed in the branch. I have changed how it uses
--detach, --remove, and --set-capacity to assume the device name
follows the options rather than requiring it as an option's argument.

It returns the mutually exclusive check to the game and avoids
interpreting an option as a device name.

 # ./losetup --remove --detach loop0
 losetup: mutually exclusive arguments: --detach-all --all --set-capacity --detach --find --associated --remove

 Karel

-- 
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com