[PATCH] umount: ignore ENXIO in del_loop

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The new loop auto-destruct feature detaches automatically loop devices
when no longer used. This means they are detached with the umount()
call. But when we call umount with -d, del_loop is called and fails
because the ioctl() returns ENXIO.
We probably should ignore this error here.

Signed-off-by: Matthias Koenig <mkoenig@xxxxxxx>
---

 mount/lomount.c |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/mount/lomount.c b/mount/lomount.c
index c3ac68a..7ae8e81 100644
--- a/mount/lomount.c
+++ b/mount/lomount.c
@@ -769,6 +769,7 @@ set_loop(const char *device, const char *file, unsigned long long offset,
 int
 del_loop (const char *device) {
 	int fd;
+	int res = 0;
 
 	if ((fd = open (device, O_RDONLY)) < 0) {
 		int errsv = errno;
@@ -777,10 +778,22 @@ del_loop (const char *device) {
 		return 1;
 	}
 	if (ioctl (fd, LOOP_CLR_FD, 0) < 0) {
-		perror ("ioctl: LOOP_CLR_FD");
+		if (errno == ENXIO) {
+			/* ignore ENXIO, device has probably been
+			 * auto-destructed */
+			if (verbose > 1)
+				printf(_("del_loop(%s): already deleted\n"),
+				       device);
+			res = 0;
+		} else {
+			perror ("ioctl: LOOP_CLR_FD");
+			res = 1;
+		}
+
 		close(fd);
-		return 1;
+		return res;
 	}
+
 	close (fd);
 	if (verbose > 1)
 		printf(_("del_loop(%s): success\n"), device);

--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux