diff options
author | Brian Behlendorf <[email protected]> | 2015-08-31 16:46:01 -0700 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2015-09-03 14:14:55 -0700 |
commit | 0282c4137e7409e6d85289f4955adf07fac834f5 (patch) | |
tree | faabc832933de17480f434489a98be3dc477648c /cmd/mount_zfs/mount_zfs.c | |
parent | 69de34219af4a4d100cc5ed155a68ab03393fca4 (diff) |
Add temporary mount options
Add the required kernel side infrastructure to parse arbitrary
mount options. This enables us to support temporary mount
options in largely the same way it is handled on other platforms.
See the 'Temporary Mount Point Properties' section of zfs(8)
for complete details.
Signed-off-by: Brian Behlendorf <[email protected]>
Closes #985
Closes #3351
Diffstat (limited to 'cmd/mount_zfs/mount_zfs.c')
-rw-r--r-- | cmd/mount_zfs/mount_zfs.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/cmd/mount_zfs/mount_zfs.c b/cmd/mount_zfs/mount_zfs.c index 0f4995943..e3e8cfc22 100644 --- a/cmd/mount_zfs/mount_zfs.c +++ b/cmd/mount_zfs/mount_zfs.c @@ -28,10 +28,14 @@ #include <unistd.h> #include <sys/file.h> #include <sys/mount.h> +#include <sys/mntent.h> #include <sys/stat.h> #include <libzfs.h> #include <locale.h> +#define ZS_COMMENT 0x00000000 /* comment */ +#define ZS_ZFSUTIL 0x00000001 /* caller is zfs(8) */ + libzfs_handle_t *g_zfs; typedef struct option_map { @@ -335,14 +339,18 @@ mtab_update(char *dataset, char *mntpoint, char *type, char *mntopts) } static void -__zfs_selinux_setcontext(const char *name, const char *context, char *mntopts, - char *mtabopt) +append_mntopt(const char *name, const char *val, char *mntopts, + char *mtabopt, boolean_t quote) { char tmp[MNT_LINE_MAX]; - snprintf(tmp, MNT_LINE_MAX, ",%s=\"%s\"", name, context); - strlcat(mntopts, tmp, MNT_LINE_MAX); - strlcat(mtabopt, tmp, MNT_LINE_MAX); + snprintf(tmp, MNT_LINE_MAX, quote ? ",%s=\"%s\"" : ",%s=%s", name, val); + + if (mntopts) + strlcat(mntopts, tmp, MNT_LINE_MAX); + + if (mtabopt) + strlcat(mtabopt, tmp, MNT_LINE_MAX); } static void @@ -354,7 +362,7 @@ zfs_selinux_setcontext(zfs_handle_t *zhp, zfs_prop_t zpt, const char *name, if (zfs_prop_get(zhp, zpt, context, sizeof (context), NULL, NULL, 0, B_FALSE) == 0) { if (strcmp(context, "none") != 0) - __zfs_selinux_setcontext(name, context, mntopts, mtabopt); + append_mntopt(name, context, mntopts, mtabopt, B_TRUE); } } @@ -506,11 +514,14 @@ main(int argc, char **argv) ZFS_PROP_SELINUX_ROOTCONTEXT, MNTOPT_ROOTCONTEXT, mntopts, mtabopt); } else { - __zfs_selinux_setcontext(MNTOPT_CONTEXT, - prop, mntopts, mtabopt); + append_mntopt(MNTOPT_CONTEXT, prop, + mntopts, mtabopt, B_TRUE); } } + /* A hint used to determine an auto-mounted snapshot mount point */ + append_mntopt(MNTOPT_MNTPOINT, mntpoint, mntopts, NULL, B_FALSE); + /* treat all snapshots as legacy mount points */ if (zfs_get_type(zhp) == ZFS_TYPE_SNAPSHOT) (void) strlcpy(prop, ZFS_MOUNTPOINT_LEGACY, ZFS_MAXPROPLEN); |