summaryrefslogtreecommitdiffstats
path: root/libmount/src/context.c
diff options
context:
space:
mode:
authorKarel Zak2014-06-17 15:38:14 +0200
committerKarel Zak2014-06-17 15:38:14 +0200
commit150e696dacafb2a2583e9c5dae736480b84d6673 (patch)
tree8890391f877566548b9648ca71cd8e2b4058da42 /libmount/src/context.c
parenttests: remove test_wholedisk (diff)
downloadkernel-qcow2-util-linux-150e696dacafb2a2583e9c5dae736480b84d6673.tar.gz
kernel-qcow2-util-linux-150e696dacafb2a2583e9c5dae736480b84d6673.tar.xz
kernel-qcow2-util-linux-150e696dacafb2a2583e9c5dae736480b84d6673.zip
libmount: don't touch mtab when mount -n specified
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1109367 Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/context.c')
-rw-r--r--libmount/src/context.c74
1 files changed, 63 insertions, 11 deletions
diff --git a/libmount/src/context.c b/libmount/src/context.c
index 1a04c1a29..65171eceb 100644
--- a/libmount/src/context.c
+++ b/libmount/src/context.c
@@ -65,11 +65,6 @@ struct libmnt_context *mnt_new_context(void)
DBG(CXT, ul_debugobj(cxt, "----> allocate %s",
cxt->restricted ? "[RESTRICTED]" : ""));
- mnt_has_regular_mtab(&cxt->mtab_path, &cxt->mtab_writable);
-
- if (!cxt->mtab_writable)
- /* use /run/mount/utab if /etc/mtab is useless */
- mnt_has_regular_utab(&cxt->utab_path, &cxt->utab_writable);
return cxt;
}
@@ -178,6 +173,7 @@ int mnt_reset_context(struct libmnt_context *cxt)
cxt->flags |= (fl & MNT_FL_NOCANONICALIZE);
cxt->flags |= (fl & MNT_FL_RDONLY_UMOUNT);
cxt->flags |= (fl & MNT_FL_NOSWAPMATCH);
+ cxt->flags |= (fl & MNT_FL_TABPATHS_CHECKED);
return 0;
}
@@ -205,6 +201,59 @@ int mnt_context_reset_status(struct libmnt_context *cxt)
return 0;
}
+static int context_init_paths(struct libmnt_context *cxt, int writable)
+{
+ assert(cxt);
+
+ if (!cxt->mtab_path)
+ cxt->mtab_path = mnt_get_mtab_path();
+ if (!cxt->utab_path)
+ cxt->utab_path = mnt_get_utab_path();
+
+ if (!writable)
+ return 0; /* only paths wanted */
+ if (mnt_context_is_nomtab(cxt))
+ return 0; /* write mode overrided by mount -n */
+ if (cxt->flags & MNT_FL_TABPATHS_CHECKED)
+ return 0;
+
+ DBG(CXT, ul_debugobj(cxt, "checking for writable tab files"));
+
+ mnt_has_regular_mtab(&cxt->mtab_path, &cxt->mtab_writable);
+
+ if (!cxt->mtab_writable)
+ /* use /run/mount/utab if /etc/mtab is useless */
+ mnt_has_regular_utab(&cxt->utab_path, &cxt->utab_writable);
+
+ cxt->flags |= MNT_FL_TABPATHS_CHECKED;
+ return 0;
+}
+
+int mnt_context_mtab_writable(struct libmnt_context *cxt)
+{
+ assert(cxt);
+
+ context_init_paths(cxt, 1);
+ return cxt->mtab_writable == 1;
+}
+
+int mnt_context_utab_writable(struct libmnt_context *cxt)
+{
+ assert(cxt);
+
+ context_init_paths(cxt, 1);
+ return cxt->utab_writable == 1;
+}
+
+const char *mnt_context_get_writable_tabpath(struct libmnt_context *cxt)
+{
+ assert(cxt);
+
+ context_init_paths(cxt, 1);
+ return cxt->mtab_writable ? cxt->mtab_path : cxt->utab_path;
+}
+
+
static int set_flag(struct libmnt_context *cxt, int flag, int enable)
{
assert(cxt);
@@ -978,6 +1027,8 @@ int mnt_context_get_mtab(struct libmnt_context *cxt, struct libmnt_table **tb)
if (!cxt->mtab) {
int rc;
+ context_init_paths(cxt, 0);
+
cxt->mtab = mnt_new_table();
if (!cxt->mtab)
return -ENOMEM;
@@ -1220,8 +1271,8 @@ struct libmnt_lock *mnt_context_get_lock(struct libmnt_context *cxt)
return NULL;
if (!cxt->lock) {
- cxt->lock = mnt_new_lock(cxt->mtab_writable ?
- cxt->mtab_path : cxt->utab_path, 0);
+ cxt->lock = mnt_new_lock(
+ mnt_context_get_writable_tabpath(cxt), 0);
if (cxt->lock)
mnt_lock_block_signals(cxt->lock, TRUE);
}
@@ -1740,7 +1791,7 @@ int mnt_context_prepare_update(struct libmnt_context *cxt)
DBG(CXT, ul_debugobj(cxt, "skip update: NOMTAB flag"));
return 0;
}
- if (!cxt->mtab_writable && !cxt->utab_writable) {
+ if (!mnt_context_get_writable_tabpath(cxt)) {
DBG(CXT, ul_debugobj(cxt, "skip update: no writable destination"));
return 0;
}
@@ -1753,7 +1804,7 @@ int mnt_context_prepare_update(struct libmnt_context *cxt)
}
if (!cxt->update) {
- const char *name = cxt->mtab_writable ? cxt->mtab_path : cxt->utab_path;
+ const char *name = mnt_context_get_writable_tabpath(cxt);
if (cxt->action == MNT_ACT_UMOUNT && is_file_empty(name)) {
DBG(CXT, ul_debugobj(cxt,
@@ -1765,7 +1816,8 @@ int mnt_context_prepare_update(struct libmnt_context *cxt)
if (!cxt->update)
return -ENOMEM;
- mnt_update_set_filename(cxt->update, name, !cxt->mtab_writable);
+ mnt_update_set_filename(cxt->update, name,
+ !mnt_context_mtab_writable(cxt));
}
if (cxt->action == MNT_ACT_UMOUNT)
@@ -1796,7 +1848,7 @@ int mnt_context_update_tabs(struct libmnt_context *cxt)
/* check utab update when external helper executed */
if (mnt_context_helper_executed(cxt)
&& mnt_context_get_helper_status(cxt) == 0
- && cxt->utab_writable) {
+ && mnt_context_utab_writable(cxt)) {
if (mnt_update_already_done(cxt->update, cxt->lock)) {
DBG(CXT, ul_debugobj(cxt, "don't update: error evaluate or already updated"));