summaryrefslogtreecommitdiffstats
path: root/libmount/src
diff options
context:
space:
mode:
authorKarel Zak2012-07-17 21:57:22 +0200
committerKarel Zak2012-07-17 21:57:22 +0200
commite39cbb76033e689093da42453839afa9c8d4c8e5 (patch)
treebaaddf234aae42639032f2437a3732aa78bbdad3 /libmount/src
parentdocs: update TODO file (diff)
downloadkernel-qcow2-util-linux-e39cbb76033e689093da42453839afa9c8d4c8e5.tar.gz
kernel-qcow2-util-linux-e39cbb76033e689093da42453839afa9c8d4c8e5.tar.xz
kernel-qcow2-util-linux-e39cbb76033e689093da42453839afa9c8d4c8e5.zip
libmount: allow to disable swap between source and target
In some cases (for example if only one mount argument is given) may be mount request ambivalent: # mount /foo and fstab: /dev/sda5 /foo rw 0 0 /foo /bar bind 0 0 The libmount allows to swap between source and target (if source is not LABEL or UUID) by default. The new function mnt_context_disable_swapmatch() allows to disable this feature. Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src')
-rw-r--r--libmount/src/context.c30
-rw-r--r--libmount/src/context_umount.c2
-rw-r--r--libmount/src/libmount.h.in2
-rw-r--r--libmount/src/libmount.sym2
-rw-r--r--libmount/src/mountP.h1
5 files changed, 34 insertions, 3 deletions
diff --git a/libmount/src/context.c b/libmount/src/context.c
index e0b6a35f4..bfc418cd8 100644
--- a/libmount/src/context.c
+++ b/libmount/src/context.c
@@ -502,7 +502,7 @@ int mnt_context_disable_mtab(struct libmnt_context *cxt, int disable)
}
/**
- * mnt_context_is_nomtab
+ * mnt_context_is_nomtab:
* @cxt: mount context
*
* Returns: 1 if no-mtab is enabled or 0
@@ -513,6 +513,32 @@ int mnt_context_is_nomtab(struct libmnt_context *cxt)
}
/**
+ * mnt_context_disable_swapmatch:
+ * @cxt: mount context
+ * @disable: TRUE or FALSE
+ *
+ * Disable/enable swap between source and target for mount(8) if only one path
+ * is specified.
+ *
+ * Returns: 0 on success, negative number in case of error.
+ */
+int mnt_context_disable_swapmatch(struct libmnt_context *cxt, int disable)
+{
+ return set_flag(cxt, MNT_FL_NOSWAPMATCH, disable);
+}
+
+/**
+ * mnt_context_is_swapmatch:
+ * @cxt: mount context
+ *
+ * Returns: 1 if swap between source and target is allowed (default is 1) or 0.
+ */
+int mnt_context_is_swapmatch(struct libmnt_context *cxt)
+{
+ return cxt && (cxt->flags & MNT_FL_NOSWAPMATCH) ? 0 : 1;
+}
+
+/**
* mnt_context_enable_force:
* @cxt: mount context
* @enable: TRUE or FALSE
@@ -1617,7 +1643,7 @@ static int apply_table(struct libmnt_context *cxt, struct libmnt_table *tb,
else if (tgt)
fs = mnt_table_find_target(tb, tgt, direction);
- if (!fs) {
+ if (!fs && mnt_context_is_swapmatch(cxt)) {
/* swap source and target (if @src is not LABEL/UUID),
* for example in
*
diff --git a/libmount/src/context_umount.c b/libmount/src/context_umount.c
index 39d940f6c..2c2975e7e 100644
--- a/libmount/src/context_umount.c
+++ b/libmount/src/context_umount.c
@@ -64,7 +64,7 @@ static int lookup_umount_fs(struct libmnt_context *cxt)
try_loopdev:
fs = mnt_table_find_target(mtab, tgt, MNT_ITER_BACKWARD);
- if (!fs) {
+ if (!fs && mnt_context_is_swapmatch(cxt)) {
/* maybe the option is source rather than target (mountpoint) */
fs = mnt_table_find_source(mtab, tgt, MNT_ITER_BACKWARD);
diff --git a/libmount/src/libmount.h.in b/libmount/src/libmount.h.in
index 2c66871b7..326588fec 100644
--- a/libmount/src/libmount.h.in
+++ b/libmount/src/libmount.h.in
@@ -428,6 +428,7 @@ extern int mnt_context_enable_force(struct libmnt_context *cxt, int enable);
extern int mnt_context_enable_verbose(struct libmnt_context *cxt, int enable);
extern int mnt_context_enable_loopdel(struct libmnt_context *cxt, int enable);
extern int mnt_context_enable_fork(struct libmnt_context *cxt, int enable);
+extern int mnt_context_disable_swapmatch(struct libmnt_context *cxt, int disable);
extern int mnt_context_get_optsmode(struct libmnt_context *cxt);
extern int mnt_context_is_lazy(struct libmnt_context *cxt);
@@ -440,6 +441,7 @@ 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_swapmatch(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 39f81d665..260642d4d 100644
--- a/libmount/src/libmount.sym
+++ b/libmount/src/libmount.sym
@@ -244,4 +244,6 @@ global:
mnt_fs_get_swaptype;
mnt_fs_get_tid;
mnt_fs_get_usedsize;
+ mnt_context_is_swapmatch;
+ mnt_context_disable_swapmatch;
} MOUNT_2.21;
diff --git a/libmount/src/mountP.h b/libmount/src/mountP.h
index a2922c2b3..0ef073a69 100644
--- a/libmount/src/mountP.h
+++ b/libmount/src/mountP.h
@@ -335,6 +335,7 @@ struct libmnt_context
#define MNT_FL_NOCANONICALIZE (1 << 9)
#define MNT_FL_RDONLY_UMOUNT (1 << 11) /* remount,ro after EBUSY umount(2) */
#define MNT_FL_FORK (1 << 12)
+#define MNT_FL_NOSWAPMATCH (1 << 13)
#define MNT_FL_EXTERN_FS (1 << 15) /* cxt->fs is not private */
#define MNT_FL_EXTERN_FSTAB (1 << 16) /* cxt->fstab is not private */