summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2012-03-07 10:45:48 +0100
committerKarel Zak2012-03-07 10:45:48 +0100
commit379e84390af9a352611228f166f63521558040bd (patch)
tree5c31583cd774bdb85d05b8dfa4b0454781a2bf92
parentlslocks: add TYPE column (diff)
downloadkernel-qcow2-util-linux-379e84390af9a352611228f166f63521558040bd.tar.gz
kernel-qcow2-util-linux-379e84390af9a352611228f166f63521558040bd.tar.xz
kernel-qcow2-util-linux-379e84390af9a352611228f166f63521558040bd.zip
libmount: cleanup flags usage
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--libmount/docs/libmount-sections.txt3
-rw-r--r--libmount/src/context.c113
-rw-r--r--libmount/src/context_mount.c10
-rw-r--r--libmount/src/context_umount.c42
-rw-r--r--libmount/src/libmount.h.in3
-rw-r--r--libmount/src/libmount.sym3
6 files changed, 120 insertions, 54 deletions
diff --git a/libmount/docs/libmount-sections.txt b/libmount/docs/libmount-sections.txt
index d99f6dcd2..d1318acde 100644
--- a/libmount/docs/libmount-sections.txt
+++ b/libmount/docs/libmount-sections.txt
@@ -56,6 +56,9 @@ mnt_context_is_force
mnt_context_is_fork
mnt_context_is_fs_mounted
mnt_context_is_lazy
+mnt_context_is_loopdel
+mnt_context_is_nocanonicalize
+mnt_context_is_nohelpers
mnt_context_is_nomtab
mnt_context_is_parent
mnt_context_is_rdonly_umount
diff --git a/libmount/src/context.c b/libmount/src/context.c
index f97dd36a6..a9ff91091 100644
--- a/libmount/src/context.c
+++ b/libmount/src/context.c
@@ -286,9 +286,10 @@ int mnt_context_get_optsmode(struct libmnt_context *cxt)
* canonicalies paths when search in fstab and when prepare source and target paths
* for mount(2) syscall.
*
- * This fuction has effect to the private fstab instance only (see
- * mnt_context_set_fstab()). If you want to use an external fstab then you need
- * manage your private struct libmnt_cache (see mnt_table_set_cache(fstab, NULL).
+ * This fuction has effect to the private (within context) fstab instance only
+ * (see mnt_context_set_fstab()). If you want to use an external fstab then you
+ * need manage your private struct libmnt_cache (see mnt_table_set_cache(fstab,
+ * NULL).
*
* Returns: 0 on success, negative number in case of error.
*/
@@ -298,6 +299,17 @@ int mnt_context_disable_canonicalize(struct libmnt_context *cxt, int disable)
}
/**
+ * mnt_context_is_nocanonicalize:
+ * @cxt: mount context
+ *
+ * Returns: 1 if no-canonicalize mode enabled or 0.
+ */
+int mnt_context_is_nocanonicalize(struct libmnt_context *cxt)
+{
+ return cxt && (cxt->flags & MNT_FL_NOCANONICALIZE) ? 1 : 0;
+}
+
+/**
* mnt_context_enable_lazy:
* @cxt: mount context
* @enable: TRUE or FALSE
@@ -312,6 +324,17 @@ int mnt_context_enable_lazy(struct libmnt_context *cxt, int enable)
}
/**
+ * mnt_context_is_lazy:
+ * @cxt: mount context
+ *
+ * Returns: 1 if lazy umount is enabled or 0
+ */
+int mnt_context_is_lazy(struct libmnt_context *cxt)
+{
+ return cxt && (cxt->flags & MNT_FL_LAZY) ? 1 : 0;
+}
+
+/**
* mnt_context_enable_fork:
* @cxt: mount context
* @enable: TRUE or FALSE
@@ -327,16 +350,37 @@ int mnt_context_enable_fork(struct libmnt_context *cxt, int enable)
}
/**
- * mnt_context_is_lazy:
+ * mnt_context_is_fork:
* @cxt: mount context
*
- * Returns: 1 if lazy umount is enabled or 0
+ * Returns: 1 if fork (mount -F) is enabled or 0
*/
-int mnt_context_is_lazy(struct libmnt_context *cxt)
+int mnt_context_is_fork(struct libmnt_context *cxt)
{
- return cxt && (cxt->flags & MNT_FL_LAZY) ? 1 : 0;
+ return cxt && (cxt->flags & MNT_FL_FORK) ? 1 : 0;
}
+/**
+ * mnt_context_is_parent:
+ * @cxt: mount context
+ *
+ * Return: 1 if mount -F enabled and the current context is parent, or 0
+ */
+int mnt_context_is_parent(struct libmnt_context *cxt)
+{
+ return mnt_context_is_fork(cxt) && cxt->pid == 0;
+}
+
+/**
+ * mnt_context_is_child:
+ * @cxt: mount context
+ *
+ * Return: 1 if mount -F enabled and the current context is child, or 0
+ */
+int mnt_context_is_child(struct libmnt_context *cxt)
+{
+ return !mnt_context_is_fork(cxt) && cxt->pid;
+}
/**
* mnt_context_enable_rdonly_umount:
@@ -382,6 +426,18 @@ int mnt_context_disable_helpers(struct libmnt_context *cxt, int disable)
}
/**
+ * mnt_context_is_nohelpers
+ * @cxt: mount context
+ *
+ * Returns: 1 if helpers are disabled (mount -i) or 0
+ */
+int mnt_context_is_nohelpers(struct libmnt_context *cxt)
+{
+ return cxt && (cxt->flags & MNT_FL_NOHELPERS) ? 1 : 0;
+}
+
+
+/**
* mnt_context_enable_sloppy:
* @cxt: mount context
* @enable: TRUE or FALSE
@@ -521,6 +577,17 @@ int mnt_context_enable_loopdel(struct libmnt_context *cxt, int enable)
}
/**
+ * mnt_context_is_loopdel:
+ * @cxt: mount context
+ *
+ * Returns: 1 if loop device should be deleted after umount (umount -d) or 0.
+ */
+int mnt_context_is_loopdel(struct libmnt_context *cxt)
+{
+ return cxt && (cxt->flags & MNT_FL_LOOPDEL) ? 1 : 0;
+}
+
+/**
* mnt_context_set_fs:
* @cxt: mount context
* @fs: filesystem description
@@ -934,7 +1001,7 @@ int mnt_context_set_cache(struct libmnt_context *cxt, struct libmnt_cache *cache
*/
struct libmnt_cache *mnt_context_get_cache(struct libmnt_context *cxt)
{
- if (!cxt || (cxt->flags & MNT_FL_NOCANONICALIZE))
+ if (!cxt || mnt_context_is_nocanonicalize(cxt))
return NULL;
if (!cxt->cache) {
@@ -995,7 +1062,7 @@ struct libmnt_lock *mnt_context_get_lock(struct libmnt_context *cxt)
* the lock. The mnt_update_* functions are able to allocate the lock
* only when mtab/utab update is really necessary.
*/
- if (!cxt || (cxt->flags & MNT_FL_NOMTAB))
+ if (!cxt || mnt_context_is_nomtab(cxt))
return NULL;
if (!cxt->lock) {
@@ -1340,8 +1407,10 @@ int mnt_context_prepare_helper(struct libmnt_context *cxt, const char *name,
if (!type)
type = mnt_fs_get_fstype(cxt->fs);
- if ((cxt->flags & MNT_FL_NOHELPERS) || !type ||
- !strcmp(type, "none") || mnt_fs_is_swaparea(cxt->fs))
+ if (mnt_context_is_nohelpers(cxt)
+ || !type
+ || !strcmp(type, "none")
+ || mnt_fs_is_swaparea(cxt->fs))
return 0;
path = strtok_r(search_path, ":", &p);
@@ -1432,9 +1501,9 @@ int mnt_context_prepare_update(struct libmnt_context *cxt)
if (cxt->action == MNT_ACT_UMOUNT && target && !strcmp(target, "/"))
/* Don't try to touch mtab if umounting root FS */
- cxt->flags |= MNT_FL_NOMTAB;
+ mnt_context_disable_mtab(cxt, TRUE);
- if (cxt->flags & MNT_FL_NOMTAB) {
+ if (mnt_context_is_nomtab(cxt)) {
DBG(CXT, mnt_debug_h(cxt, "skip update: NOMTAB flag"));
return 0;
}
@@ -1479,7 +1548,7 @@ int mnt_context_update_tabs(struct libmnt_context *cxt)
assert(cxt);
- if (cxt->flags & MNT_FL_NOMTAB) {
+ if (mnt_context_is_nomtab(cxt)) {
DBG(CXT, mnt_debug_h(cxt, "don't update: NOMTAB flag"));
return 0;
}
@@ -1898,7 +1967,7 @@ int mnt_fork_context(struct libmnt_context *cxt)
case 0: /* child */
cxt->pid = getpid();
- cxt->flags &= ~MNT_FL_FORK;
+ mnt_context_enable_fork(cxt, FALSE);
DBG(CXT, mnt_debug_h(cxt, "child created"));
break;
@@ -1953,22 +2022,8 @@ int mnt_context_wait_for_children(struct libmnt_context *cxt,
return 0;
}
-int mnt_context_is_fork(struct libmnt_context *cxt)
-{
- return cxt && (cxt->flags & MNT_FL_FORK);
-}
-int mnt_context_is_parent(struct libmnt_context *cxt)
-{
- return mnt_context_is_fork(cxt) && cxt->pid == 0;
-}
-
-int mnt_context_is_child(struct libmnt_context *cxt)
-{
- return !mnt_context_is_fork(cxt) && cxt->pid;
-}
-
#ifdef TEST_PROGRAM
struct libmnt_lock *lock;
diff --git a/libmount/src/context_mount.c b/libmount/src/context_mount.c
index c56ffd4c1..4174f84cb 100644
--- a/libmount/src/context_mount.c
+++ b/libmount/src/context_mount.c
@@ -467,11 +467,11 @@ static int do_mount(struct libmnt_context *cxt, const char *try_type)
DBG(CXT, mnt_debug_h(cxt, "%smount(2) "
"[source=%s, target=%s, type=%s, "
" mountflags=0x%08lx, mountdata=%s]",
- (cxt->flags & MNT_FL_FAKE) ? "(FAKE) " : "",
+ mnt_context_is_fake(cxt) ? "(FAKE) " : "",
src, target, type,
flags, cxt->mountdata ? "yes" : "<none>"));
- if (cxt->flags & MNT_FL_FAKE)
+ if (mnt_context_is_fake(cxt))
cxt->syscall_status = 0;
else {
if (mount(src, target, type, flags, cxt->mountdata)) {
@@ -607,11 +607,11 @@ int mnt_context_prepare_mount(struct libmnt_context *cxt)
* another source or target than you have to call mnt_reset_context().
*
* If you want to call mount(2) for the same source and target with a diffrent
- * mount flags or fstype then you call mnt_context_reset_status() and then try
+ * mount flags or fstype then call mnt_context_reset_status() and then try
* again mnt_context_do_mount().
*
* WARNING: non-zero return code does not mean that mount(2) syscall or
- * umount.type helper wasn't sucessfully called.
+ * mount.type helper wasn't sucessfully called.
*
* Check mnt_context_get_status() after error!
*
@@ -644,7 +644,7 @@ int mnt_context_do_mount(struct libmnt_context *cxt)
res = do_mount_by_pattern(cxt, cxt->fstype_pattern);
if (mnt_context_get_status(cxt)
- && !(cxt->flags & MNT_FL_FAKE)
+ && !mnt_context_is_fake(cxt)
&& !cxt->helper) {
/*
* Mounted by mount(2), do some post-mount checks
diff --git a/libmount/src/context_umount.c b/libmount/src/context_umount.c
index 5a2ad9ec7..7daa913fc 100644
--- a/libmount/src/context_umount.c
+++ b/libmount/src/context_umount.c
@@ -178,7 +178,7 @@ static int prepare_helper_from_options(struct libmnt_context *cxt,
const char *opts;
size_t valsz;
- if (cxt->flags & MNT_FL_NOHELPERS)
+ if (mnt_context_is_nohelpers(cxt))
return 0;
opts = mnt_fs_get_user_options(cxt->fs);
@@ -369,15 +369,15 @@ static int exec_helper(struct libmnt_context *cxt)
args[i++] = cxt->helper; /* 1 */
args[i++] = mnt_fs_get_target(cxt->fs); /* 2 */
- if (cxt->flags & MNT_FL_NOMTAB)
+ if (mnt_context_is_nomtab(cxt))
args[i++] = "-n"; /* 3 */
- if (cxt->flags & MNT_FL_LAZY)
+ if (mnt_context_is_lazy(cxt))
args[i++] = "-l"; /* 4 */
- if (cxt->flags & MNT_FL_FORCE)
+ if (mnt_context_is_force(cxt))
args[i++] = "-f"; /* 5 */
- if (cxt->flags & MNT_FL_VERBOSE)
+ if (mnt_context_is_verbose(cxt))
args[i++] = "-v"; /* 6 */
- if (cxt->flags & MNT_FL_RDONLY_UMOUNT)
+ if (mnt_context_is_rdonly_umount(cxt))
args[i++] = "-r"; /* 7 */
if (type && !endswith(cxt->helper, type)) {
args[i++] = "-t"; /* 8 */
@@ -495,7 +495,7 @@ static int do_umount(struct libmnt_context *cxt)
DBG(CXT, mnt_debug_h(cxt, "do umount"));
- if (cxt->restricted && !(cxt->flags & MNT_FL_FAKE)) {
+ if (cxt->restricted && !mnt_context_is_fake(cxt)) {
/*
* extra paranoa for non-root users
* -- chdir to the parent of the mountpoint and use NOFOLLOW
@@ -510,17 +510,17 @@ static int do_umount(struct libmnt_context *cxt)
target = tgtbuf;
}
- if (cxt->flags & MNT_FL_LAZY)
+ if (mnt_context_is_lazy(cxt))
flags |= MNT_DETACH;
- else if (cxt->flags & MNT_FL_FORCE)
+ else if (mnt_context_is_force(cxt))
flags |= MNT_FORCE;
DBG(CXT, mnt_debug_h(cxt, "umount(2) [target='%s', flags=0x%08x]%s",
target, flags,
- cxt->flags & MNT_FL_FAKE ? " (FAKE)" : ""));
+ mnt_context_is_fake(cxt) ? " (FAKE)" : ""));
- if (cxt->flags & MNT_FL_FAKE)
+ if (mnt_context_is_fake(cxt))
rc = 0;
else {
rc = flags ? umount2(target, flags) : umount(target);
@@ -532,12 +532,14 @@ static int do_umount(struct libmnt_context *cxt)
/*
* try remount read-only
*/
- if (rc < 0 && cxt->syscall_status == -EBUSY &&
- (cxt->flags & MNT_FL_RDONLY_UMOUNT) && src) {
+ if (rc < 0
+ && cxt->syscall_status == -EBUSY
+ && mnt_context_is_rdonly_umount(cxt)
+ && src) {
mnt_context_set_mflags(cxt, (cxt->mountflags |
MS_REMOUNT | MS_RDONLY));
- cxt->flags &= ~MNT_FL_LOOPDEL;
+ mnt_context_enable_loopdel(cxt, FALSE);
DBG(CXT, mnt_debug_h(cxt,
"umount(2) failed [errno=%d] -- trying to remount read-only",
@@ -616,11 +618,11 @@ int mnt_context_prepare_umount(struct libmnt_context *cxt)
rc = mnt_context_prepare_helper(cxt, "umount", NULL);
}
- if (!rc && (cxt->flags & MNT_FL_LOOPDEL) && cxt->fs) {
+ if (!rc && mnt_context_is_loopdel(cxt) && 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;
+ mnt_context_enable_loopdel(cxt, FALSE);
}
if (rc) {
@@ -665,21 +667,21 @@ int mnt_context_do_umount(struct libmnt_context *cxt)
if (rc)
return rc;
- if (mnt_context_get_status(cxt) && !(cxt->flags & MNT_FL_FAKE)) {
+ if (mnt_context_get_status(cxt) && !mnt_context_is_fake(cxt)) {
/*
* Umounted, do some post-umount operations
* - remove loopdev
* - refresh in-memory mtab stuff if remount rather than
* umount has been performed
*/
- if ((cxt->flags & MNT_FL_LOOPDEL)
+ if (mnt_context_is_loopdel(cxt)
&& !(cxt->mountflags & MS_REMOUNT))
rc = mnt_context_delete_loopdev(cxt);
- if (!(cxt->flags & MNT_FL_NOMTAB)
+ if (!mnt_context_is_nomtab(cxt)
&& mnt_context_get_status(cxt)
&& !cxt->helper
- && (cxt->flags & MNT_FL_RDONLY_UMOUNT)
+ && mnt_context_is_rdonly_umount(cxt)
&& (cxt->mountflags & MS_REMOUNT)) {
/* use "remount" instead of "umount" in /etc/mtab */
diff --git a/libmount/src/libmount.h.in b/libmount/src/libmount.h.in
index 771952924..fbabec5c8 100644
--- a/libmount/src/libmount.h.in
+++ b/libmount/src/libmount.h.in
@@ -412,6 +412,9 @@ extern int mnt_context_is_fake(struct libmnt_context *cxt);
extern int mnt_context_is_nomtab(struct libmnt_context *cxt);
extern int mnt_context_is_force(struct libmnt_context *cxt);
extern int mnt_context_is_verbose(struct libmnt_context *cxt);
+extern int mnt_context_is_loopdel(struct libmnt_context *cxt);
+extern int mnt_context_is_nohelpers(struct libmnt_context *cxt);
+extern int mnt_context_is_nocanonicalize(struct libmnt_context *cxt);
extern int mnt_context_is_fork(struct libmnt_context *cxt);
extern int mnt_context_is_parent(struct libmnt_context *cxt);
diff --git a/libmount/src/libmount.sym b/libmount/src/libmount.sym
index 1d174bcb6..48860e870 100644
--- a/libmount/src/libmount.sym
+++ b/libmount/src/libmount.sym
@@ -230,4 +230,7 @@ MOUNT_2.22 {
global:
mnt_fs_streq_target;
mnt_fs_streq_srcpath;
+ mnt_context_is_loopdel;
+ mnt_context_is_nocanonicalize;
+ mnt_context_is_nohelpers;
} MOUNT_2.21;