Skip to contentSkip to conversation

losetup: report lost loop devices for finding free loop

PATCH Applied Junxiao Bi 2 participants 2 messages Nov 7, 2023 – Nov 27, 2023 Util-Linux package

lore
Share & tools
lore

Junxiao Bi

author
#0 lore raw

PATCH 1/1 losetup: report lost loop devices for finding free loop

commit a6ca0456cc6d("loopdev: report lost loop devices") forgot to report lost loop device for finding free loop case. With this path, it will show the following if next free loop device is lost.

 # ./losetup -f
 /dev/loop1 (lost)
 # ./losetup -f /tmp/test.img
 lt-losetup: /tmp/test.img: failed to set up loop device: No such file or directory
 lt-losetup: device node /dev/loop1 (7:1) is lost. You may use mknod(1) to recover it.
---
 sys-utils/losetup.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
sys-utils/losetup.c +3 -1
index b218ce14d582..afeb5babbd8b 100644
@@ -950,7 +950,8 @@ int main(int argc, char **argv)
 	case A_FIND_FREE:
 		res = find_unused(&lc);
 		if (!res)
-			printf("%s\n", loopcxt_get_device(&lc));
+			printf("%s%s\n", loopcxt_get_device(&lc),
+				loopcxt_is_lost(&lc) ? " (lost)" : "");
 		break;
 	case A_SHOW:
 		if (list)
@@ -991,6 +992,7 @@ int main(int argc, char **argv)
 	}
 
 	if (res && (act == A_SET_CAPACITY
+		    || act == A_CREATE
 		    || act == A_SET_DIRECT_IO
 		    || act == A_SET_BLOCKSIZE)
 	    && loopcxt_is_lost(&lc))
Signature · 1 line
2.39.3
maintainer Applied
#1 lore raw
Quoted 2 lines · Junxiao Bi
 sys-utils/losetup.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Applied, thanks.

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com