* Add API functions mnt_context_enable_exclusive() and mnt_context_is_exclusive()
* Use the new flag when creating the superblock
Signed-off-by: Karel Zak <kzak@redhat.com>
mnt_context_disable_helpers
mnt_context_disable_mtab
mnt_context_disable_swapmatch
+mnt_context_enable_exclusive
mnt_context_enable_fake
mnt_context_enable_force
mnt_context_enable_fork
mnt_context_helper_setopt
mnt_context_init_helper
mnt_context_is_child
+mnt_context_is_exclusive
mnt_context_is_fake
mnt_context_is_force
mnt_context_is_fork
* @cxt: mount context
* @enable: TRUE or FALSE
*
- * Enable/disable only-once mount (check if FS is not already mounted).
+ * Enable/disable only-once mount (check if source + target is not already mounted).
*
* Returns: 0 on success, negative number in case of error.
*/
return cxt->flags & MNT_FL_ONLYONCE ? 1 : 0;
}
+/**
+ * mnt_context_enable_exclusive
+ * @cxt: mount context
+ * @enable: TRUE or FALSE
+ *
+ * Enable/disable exclusive mount (only one FS instance is allowed).
+ *
+ * Returns: 0 on success, negative number in case of error.
+ */
+int mnt_context_enable_exclusive(struct libmnt_context *cxt, int enable)
+{
+ return set_flag(cxt, MNT_FL_EXCL, enable);
+}
+
+/**
+ * mnt_context_is_exclusive:
+ * @cxt: mount context
+ *
+ * Returns: 1 if exclisive mount is enabled or 0
+ */
+int mnt_context_is_exclusive(struct libmnt_context *cxt)
+{
+ return cxt->flags & MNT_FL_EXCL ? 1 : 0;
+}
+
/**
* mnt_context_enable_fork:
* @cxt: mount context
return rc != 0 && errno ? -errno : rc;
}
+static int create_superblock(struct libmnt_context *cxt,
+ const struct libmnt_hookset *hs, int fd)
+{
+ int rc = 0;
+
+ DBG(HOOK, ul_debugobj(hs, " create FS %s",
+ mnt_context_is_exclusive(cxt) ? "excl" : ""));
+ errno = 0;
+
+ if (mnt_context_is_exclusive(cxt))
+ rc = fsconfig(fd, FSCONFIG_CMD_CREATE_EXCL, NULL, NULL, 0);
+ else
+ rc = fsconfig(fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0);
+
+ hookset_set_syscall_status(cxt, "fsconfig", rc == 0);
+
+ DBG(HOOK, ul_debugobj(hs, " create done [rc=%d]", rc));
+ return rc != 0 && errno ? -errno : rc;;
+}
+
static int open_fs_configuration_context(struct libmnt_context *cxt,
struct libmnt_sysapi *api,
const char *type)
if (!rc)
rc = configure_superblock(cxt, hs, api->fd_fs, 0);
- if (!rc) {
- DBG(HOOK, ul_debugobj(hs, "create FS"));
- rc = fsconfig(api->fd_fs, FSCONFIG_CMD_CREATE, NULL, NULL, 0);
- hookset_set_syscall_status(cxt, "fsconfig", rc == 0);
- }
+ if (!rc)
+ rc = create_superblock(cxt, hs, api->fd_fs);
if (!rc) {
int fd = fsmount(api->fd_fs, FSMOUNT_CLOEXEC, 0);
extern int mnt_context_set_optsmode(struct libmnt_context *cxt, int mode);
extern int mnt_context_disable_canonicalize(struct libmnt_context *cxt, int disable);
extern int mnt_context_enable_onlyonce(struct libmnt_context *cxt, int enable);
+extern int mnt_context_enable_exclusive(struct libmnt_context *cxt, int enable);
extern int mnt_context_enable_lazy(struct libmnt_context *cxt, int enable);
extern int mnt_context_enable_rdonly_umount(struct libmnt_context *cxt, int enable);
extern int mnt_context_enable_rwonly_mount(struct libmnt_context *cxt, int enable);
extern int mnt_context_is_onlyonce(struct libmnt_context *cxt)
__ul_attribute__((nonnull));
+extern int mnt_context_is_exclusive(struct libmnt_context *cxt)
+ __ul_attribute__((nonnull));
extern int mnt_context_is_lazy(struct libmnt_context *cxt)
__ul_attribute__((nonnull));
extern int mnt_context_is_rdonly_umount(struct libmnt_context *cxt)
mnt_table_refer_statmnt;
mnt_unref_statmnt;
} MOUNT_2_40;
+
+MOUNT_2_42 {
+ mnt_context_enable_exclusive;
+ mnt_context_is_exclusive;
+} MOUNT_2_41;
#define MNT_FL_NOSWAPMATCH (1 << 13)
#define MNT_FL_RWONLY_MOUNT (1 << 14) /* explicit mount -w; never try read-only */
#define MNT_FL_ONLYONCE (1 << 15)
+#define MNT_FL_EXCL (1 << 16)
#define MNT_FL_MOUNTDATA (1 << 20)
#define MNT_FL_TAB_APPLIED (1 << 21) /* fstab merged to cxt->fs */