aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Woodhouse <dwmw2@infradead.org>2008-02-06 04:36:27 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2008-02-06 13:41:01 -0500
commit96c5865559cee0f9cbc5173f3c949f6ce3525581 (patch)
treebbcfa89faeae5e5b1334a8f537b6bdb7caa992d8
parenta3b81113fb6658629f4ebaabf8dd3067cd341020 (diff)
Allow auto-destruction of loop devices
This allows a flag to be set on loop devices so that when they are closed for the last time, they'll self-destruct. In general, so that we can automatically allocate loop devices (as with losetup -f) and have them disappear when we're done with them. In particular, right now, so that we can stop relying on the hackish special-case in umount(8) which kills off loop devices which were set up by 'mount -oloop'. That means we can stop putting crap in /etc/mtab which doesn't belong there, which means it can be a symlink to /proc/mounts, which means yet another writable file on the root filesystem is eliminated and the 'stateless' folks get happier... and OLPC trac #356 can be closed. The mount(8) side of that is at http://marc.info/?l=util-linux-ng&m=119362955431694&w=2 [akpm@linux-foundation.org: coding-style fixes] Signed-off-by: David Woodhouse <dwmw2@infradead.org> Cc: Bernardo Innocenti <bernie@codewiz.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--drivers/block/loop.c8
-rw-r--r--include/linux/loop.h1
2 files changed, 9 insertions, 0 deletions
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index b8af22e610df..91ebb007416c 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -973,6 +973,10 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info)
973 lo->transfer = xfer->transfer; 973 lo->transfer = xfer->transfer;
974 lo->ioctl = xfer->ioctl; 974 lo->ioctl = xfer->ioctl;
975 975
976 if ((lo->lo_flags & LO_FLAGS_AUTOCLEAR) !=
977 (info->lo_flags & LO_FLAGS_AUTOCLEAR))
978 lo->lo_flags ^= LO_FLAGS_AUTOCLEAR;
979
976 lo->lo_encrypt_key_size = info->lo_encrypt_key_size; 980 lo->lo_encrypt_key_size = info->lo_encrypt_key_size;
977 lo->lo_init[0] = info->lo_init[0]; 981 lo->lo_init[0] = info->lo_init[0];
978 lo->lo_init[1] = info->lo_init[1]; 982 lo->lo_init[1] = info->lo_init[1];
@@ -1331,6 +1335,10 @@ static int lo_release(struct inode *inode, struct file *file)
1331 1335
1332 mutex_lock(&lo->lo_ctl_mutex); 1336 mutex_lock(&lo->lo_ctl_mutex);
1333 --lo->lo_refcnt; 1337 --lo->lo_refcnt;
1338
1339 if ((lo->lo_flags & LO_FLAGS_AUTOCLEAR) && !lo->lo_refcnt)
1340 loop_clr_fd(lo, inode->i_bdev);
1341
1334 mutex_unlock(&lo->lo_ctl_mutex); 1342 mutex_unlock(&lo->lo_ctl_mutex);
1335 1343
1336 return 0; 1344 return 0;
diff --git a/include/linux/loop.h b/include/linux/loop.h
index 26a0a103898f..46169a7b559b 100644
--- a/include/linux/loop.h
+++ b/include/linux/loop.h
@@ -76,6 +76,7 @@ struct loop_device {
76enum { 76enum {
77 LO_FLAGS_READ_ONLY = 1, 77 LO_FLAGS_READ_ONLY = 1,
78 LO_FLAGS_USE_AOPS = 2, 78 LO_FLAGS_USE_AOPS = 2,
79 LO_FLAGS_AUTOCLEAR = 4,
79}; 80};
80 81
81#include <asm/posix_types.h> /* for __kernel_old_dev_t */ 82#include <asm/posix_types.h> /* for __kernel_old_dev_t */