summaryrefslogtreecommitdiffstats
path: root/libmount/src/context_umount.c
diff options
context:
space:
mode:
authorKarel Zak2012-01-16 13:15:01 +0100
committerKarel Zak2012-01-16 13:15:01 +0100
commit98b1302ecf8a901dcd3ffa0fe3e4c86f868ff729 (patch)
tree688df65c6227c6e449e8f9a70a0fc8b85dfd2fcf /libmount/src/context_umount.c
parentlibmount: fix MS_BIND|MS_REC usage, improve some bitwise operations (diff)
downloadkernel-qcow2-util-linux-98b1302ecf8a901dcd3ffa0fe3e4c86f868ff729.tar.gz
kernel-qcow2-util-linux-98b1302ecf8a901dcd3ffa0fe3e4c86f868ff729.tar.xz
kernel-qcow2-util-linux-98b1302ecf8a901dcd3ffa0fe3e4c86f868ff729.zip
libmount: cleanup post-umount operations
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/context_umount.c')
-rw-r--r--libmount/src/context_umount.c62
1 files changed, 30 insertions, 32 deletions
diff --git a/libmount/src/context_umount.c b/libmount/src/context_umount.c
index 939f66e7f..ee1a648bc 100644
--- a/libmount/src/context_umount.c
+++ b/libmount/src/context_umount.c
@@ -536,8 +536,10 @@ static int do_umount(struct libmnt_context *cxt)
if (rc < 0 && cxt->syscall_status == -EBUSY &&
(cxt->flags & MNT_FL_RDONLY_UMOUNT) && src) {
- cxt->mountflags |= MS_REMOUNT | MS_RDONLY;
+ mnt_context_set_mflags(cxt, (cxt->mountflags |
+ MS_REMOUNT | MS_RDONLY));
cxt->flags &= ~MNT_FL_LOOPDEL;
+
DBG(CXT, mnt_debug_h(cxt,
"umount(2) failed [errno=%d] -- trying to remount read-only",
-cxt->syscall_status));
@@ -615,11 +617,13 @@ int mnt_context_prepare_umount(struct libmnt_context *cxt)
rc = mnt_context_prepare_helper(cxt, "umount", NULL);
}
-/* TODO
- if ((cxt->flags & MNT_FL_LOOPDEL) &&
- (!mnt_is_loopdev(src) || mnt_loopdev_is_autoclear(src)))
- cxt->flags &= ~MNT_FL_LOOPDEL;
-*/
+ if (!rc && (cxt->flags & MNT_FL_LOOPDEL) && cxt->fs) {
+ const char *src = mnt_fs_get_srcpath(cxt->fs);
+
+ if (src && (!is_loopdev(src) || loopdev_is_autoclear(src)))
+ cxt->flags &= ~MNT_FL_LOOPDEL;
+ }
+
if (rc) {
DBG(CXT, mnt_debug_h(cxt, "umount: preparing failed"));
return rc;
@@ -661,36 +665,30 @@ int mnt_context_do_umount(struct libmnt_context *cxt)
rc = do_umount(cxt);
if (rc)
return rc;
-/* TODO
- if (cxt->flags & MNT_FL_LOOPDEL)
- rc = mnt_loopdev_clean(mnt_fs_get_source(cxt->fs));
-*/
- if (cxt->flags & MNT_FL_NOMTAB)
- return rc;
- if ((cxt->flags & MNT_FL_RDONLY_UMOUNT) &&
- (cxt->mountflags & (MS_RDONLY | MS_REMOUNT))
- == (MS_RDONLY | MS_REMOUNT)) {
+ if (mnt_context_get_status(cxt) && !(cxt->flags & MNT_FL_FAKE)) {
/*
- * fix options, remount --> read-only mount
+ * Umounted, do some post-umount operations
+ * - remove loopdev
+ * - refresh in-memory mtab stuff if remount rather than
+ * umount has been performed
*/
- const char *o = mnt_fs_get_options(cxt->fs);
- char *n = o ? strdup(o) : NULL;
-
- DBG(CXT, mnt_debug_h(cxt, "fix remount-on-umount update"));
-
- if (n)
- mnt_optstr_remove_option(&n, "rw");
- rc = mnt_optstr_prepend_option(&n, "ro", NULL);
- if (!rc)
- rc = mnt_fs_set_options(cxt->fs, n);
-
- /* use "remount" instead of "umount" in /etc/mtab */
- if (!rc && cxt->update && cxt->mtab_writable)
- rc = mnt_update_set_fs(cxt->update,
- cxt->mountflags, NULL, cxt->fs);
+ if ((cxt->flags & MNT_FL_LOOPDEL)
+ && !(cxt->mountflags & MS_REMOUNT))
+ rc = mnt_context_delete_loopdev(cxt);
+
+ if (!(cxt->flags & MNT_FL_NOMTAB)
+ && mnt_context_get_status(cxt)
+ && !cxt->helper
+ && (cxt->flags & MNT_FL_RDONLY_UMOUNT)
+ && (cxt->mountflags & MS_REMOUNT)) {
+
+ /* use "remount" instead of "umount" in /etc/mtab */
+ if (!rc && cxt->update && cxt->mtab_writable)
+ rc = mnt_update_set_fs(cxt->update,
+ cxt->mountflags, NULL, cxt->fs);
+ }
}
-
return rc;
}