diff options
author | Karel Zak | 2008-07-02 14:26:51 +0200 |
---|---|---|
committer | Karel Zak | 2008-07-02 15:01:28 +0200 |
commit | e84feaecfdf44a33ef9eccc5a56c8a6999466140 (patch) | |
tree | 29d8c5744a3dbd7129c8f5518b08cd43409b2214 /mount/lomount.c | |
parent | selinux: is_selinux_enabled() returns 0, 1 and -1 (diff) | |
download | kernel-qcow2-util-linux-e84feaecfdf44a33ef9eccc5a56c8a6999466140.tar.gz kernel-qcow2-util-linux-e84feaecfdf44a33ef9eccc5a56c8a6999466140.tar.xz kernel-qcow2-util-linux-e84feaecfdf44a33ef9eccc5a56c8a6999466140.zip |
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>
Diffstat (limited to 'mount/lomount.c')
-rw-r--r-- | mount/lomount.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/mount/lomount.c b/mount/lomount.c index c3ac68a70..793705249 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) { |