forked from pool/util-linux
128 lines
3.9 KiB
Diff
128 lines
3.9 KiB
Diff
On Wed, Jun 25, 2008 at 12:59:32PM +0200, Matthias Koenig wrote:
|
|
> 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.
|
|
|
|
ah, good catch. Thanks!
|
|
|
|
> We probably should ignore this error here.
|
|
|
|
I think we could be smarter. We can try to detect autoclear
|
|
loop devices. See the patch below.
|
|
|
|
[I'm going to create a stable/v2.14 branch.]
|
|
|
|
Karel
|
|
|
|
|
|
>From e84feaecfdf44a33ef9eccc5a56c8a6999466140 Mon Sep 17 00:00:00 2001
|
|
From: Karel Zak <kzak@redhat.com>
|
|
Date: Wed, 2 Jul 2008 14:26:51 +0200
|
|
Subject: [PATCH] umount: improve "-d" option for autoclear loops
|
|
|
|
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 have to check for autoclear
|
|
loop devices rather than blindly call del_loop().
|
|
|
|
Reported-by: Matthias Koenig <mkoenig@suse.de>
|
|
Signed-off-by: Karel Zak <kzak@redhat.com>
|
|
---
|
|
mount/lomount.c | 23 +++++++++++++++++++++++
|
|
mount/lomount.h | 1 +
|
|
mount/umount.c | 12 ++++++++++--
|
|
3 files changed, 34 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/mount/lomount.c b/mount/lomount.c
|
|
index c3ac68a..7937052 100644
|
|
--- a/mount/lomount.c
|
|
+++ b/mount/lomount.c
|
|
@@ -102,6 +102,29 @@ is_loop_used(int fd)
|
|
return ioctl (fd, LOOP_GET_STATUS, &li) == 0;
|
|
}
|
|
|
|
+int
|
|
+is_loop_autoclear(const char *device)
|
|
+{
|
|
+ struct loop_info lo;
|
|
+ struct loop_info64 lo64;
|
|
+ int fd, rc = 0;
|
|
+
|
|
+ if ((fd = open(device, O_RDONLY)) < 0)
|
|
+ return 0;
|
|
+
|
|
+ if (ioctl(fd, LOOP_GET_STATUS64, &lo64) == 0) {
|
|
+ if (lo64.lo_flags & LO_FLAGS_AUTOCLEAR)
|
|
+ rc = 1;
|
|
+
|
|
+ } else if (ioctl(fd, LOOP_GET_STATUS, &lo) == 0) {
|
|
+ if (lo.lo_flags & LO_FLAGS_AUTOCLEAR)
|
|
+ rc = 1;
|
|
+ }
|
|
+
|
|
+ close(fd);
|
|
+ return rc;
|
|
+}
|
|
+
|
|
static char *
|
|
looplist_mk_devname(struct looplist *ll, int num)
|
|
{
|
|
diff --git a/mount/lomount.h b/mount/lomount.h
|
|
index f332a70..59108d4 100644
|
|
--- a/mount/lomount.h
|
|
+++ b/mount/lomount.h
|
|
@@ -2,6 +2,7 @@ extern int set_loop(const char *, const char *, unsigned long long, unsigned lon
|
|
const char *, int, int *);
|
|
extern int del_loop(const char *);
|
|
extern int is_loop_device(const char *);
|
|
+extern int is_loop_autoclear(const char *device);
|
|
extern char * find_unused_loop_device(void);
|
|
|
|
extern int loopfile_used_with(char *devname, const char *filename, unsigned long long offset);
|
|
diff --git a/mount/umount.c b/mount/umount.c
|
|
index 65c8622..b2bbdae 100644
|
|
--- a/mount/umount.c
|
|
+++ b/mount/umount.c
|
|
@@ -190,6 +190,7 @@ umount_one (const char *spec, const char *node, const char *type,
|
|
int res;
|
|
int status;
|
|
const char *loopdev;
|
|
+ int myloop = 0;
|
|
|
|
/* Special case for root. As of 0.99pl10 we can (almost) unmount root;
|
|
the kernel will remount it readonly so that we can carry on running
|
|
@@ -201,7 +202,7 @@ umount_one (const char *spec, const char *node, const char *type,
|
|
|| streq (node, "rootfs"));
|
|
if (isroot)
|
|
nomtab++;
|
|
-
|
|
+
|
|
/*
|
|
* Call umount.TYPE for types that require a separate umount program.
|
|
* All such special things must occur isolated in the types string.
|
|
@@ -209,6 +210,13 @@ umount_one (const char *spec, const char *node, const char *type,
|
|
if (check_special_umountprog(spec, node, type, &status))
|
|
return status;
|
|
|
|
+ /*
|
|
+ * Ignore the option "-d" for non-loop devices and loop devices with
|
|
+ * LO_FLAGS_AUTOCLEAR flag.
|
|
+ */
|
|
+ if (delloop && is_loop_device(spec) && !is_loop_autoclear(spec))
|
|
+ myloop = 1;
|
|
+
|
|
umnt_err = umnt_err2 = 0;
|
|
if (lazy) {
|
|
res = umount2 (node, MNT_DETACH);
|
|
@@ -310,7 +318,7 @@ umount_one (const char *spec, const char *node, const char *type,
|
|
}
|
|
|
|
/* Also free loop devices when -d flag is given */
|
|
- if (delloop && is_loop_device(spec))
|
|
+ if (myloop)
|
|
loopdev = spec;
|
|
}
|
|
gotloop:
|