summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamian Szuberski <[email protected]>2022-02-08 19:53:23 +0100
committerTony Hutter <[email protected]>2022-02-16 17:58:55 -0800
commitbb271d67e85ad90cda640e382daf3a15f6e82d9e (patch)
tree760bf1f52dd15f4025a35de0dbc3555de7008d52
parenta61915e08687b70654290df7088928f42f829aea (diff)
`mount.zfs -o zfsutil` leverages `zfs_mount_at()`
Using `zfs_mount_at()` gives opportunity to properly propagate mountopts from what's stored in a pool to the `mount(2)` syscall invocation. It fixes cases when mount options are set to incorrect values and rectification is impossible (e. g. Linux initrd boot sequence in #7947). Moved debug information printing after all variables are initialized - printed text reflects what is passed to `mount(2)`. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: szubersk <[email protected]> Issue #7947 Closes #13021
-rw-r--r--cmd/mount_zfs/mount_zfs.c47
1 files changed, 34 insertions, 13 deletions
diff --git a/cmd/mount_zfs/mount_zfs.c b/cmd/mount_zfs/mount_zfs.c
index de3833698..55968ac88 100644
--- a/cmd/mount_zfs/mount_zfs.c
+++ b/cmd/mount_zfs/mount_zfs.c
@@ -246,13 +246,6 @@ main(int argc, char **argv)
}
}
- if (verbose)
- (void) fprintf(stdout, gettext("mount.zfs:\n"
- " dataset: \"%s\"\n mountpoint: \"%s\"\n"
- " mountflags: 0x%lx\n zfsflags: 0x%lx\n"
- " mountopts: \"%s\"\n mtabopts: \"%s\"\n"),
- dataset, mntpoint, mntflags, zfsflags, mntopts, mtabopt);
-
if (mntflags & MS_REMOUNT) {
nomtab = 1;
remount = 1;
@@ -275,7 +268,10 @@ main(int argc, char **argv)
return (MOUNT_USAGE);
}
- zfs_adjust_mount_options(zhp, mntpoint, mntopts, mtabopt);
+ if (!zfsutil || sloppy ||
+ libzfs_envvar_is_set("ZFS_MOUNT_HELPER")) {
+ zfs_adjust_mount_options(zhp, mntpoint, mntopts, mtabopt);
+ }
/* treat all snapshots as legacy mount points */
if (zfs_get_type(zhp) == ZFS_TYPE_SNAPSHOT)
@@ -293,12 +289,11 @@ main(int argc, char **argv)
if (zfs_version == 0) {
fprintf(stderr, gettext("unable to fetch "
"ZFS version for filesystem '%s'\n"), dataset);
+ zfs_close(zhp);
+ libzfs_fini(g_zfs);
return (MOUNT_SYSERR);
}
- zfs_close(zhp);
- libzfs_fini(g_zfs);
-
/*
* Legacy mount points may only be mounted using 'mount', never using
* 'zfs mount'. However, since 'zfs mount' actually invokes 'mount'
@@ -316,6 +311,8 @@ main(int argc, char **argv)
"Use 'zfs set mountpoint=%s' or 'mount -t zfs %s %s'.\n"
"See zfs(8) for more information.\n"),
dataset, mntpoint, dataset, mntpoint);
+ zfs_close(zhp);
+ libzfs_fini(g_zfs);
return (MOUNT_USAGE);
}
@@ -326,14 +323,38 @@ main(int argc, char **argv)
"Use 'zfs set mountpoint=%s' or 'zfs mount %s'.\n"
"See zfs(8) for more information.\n"),
dataset, "legacy", dataset);
+ zfs_close(zhp);
+ libzfs_fini(g_zfs);
return (MOUNT_USAGE);
}
+ if (verbose)
+ (void) fprintf(stdout, gettext("mount.zfs:\n"
+ " dataset: \"%s\"\n mountpoint: \"%s\"\n"
+ " mountflags: 0x%lx\n zfsflags: 0x%lx\n"
+ " mountopts: \"%s\"\n mtabopts: \"%s\"\n"),
+ dataset, mntpoint, mntflags, zfsflags, mntopts, mtabopt);
+
if (!fake) {
- error = mount(dataset, mntpoint, MNTTYPE_ZFS,
- mntflags, mntopts);
+ if (zfsutil && !sloppy &&
+ !libzfs_envvar_is_set("ZFS_MOUNT_HELPER")) {
+ error = zfs_mount_at(zhp, mntopts, mntflags, mntpoint);
+ if (error) {
+ (void) fprintf(stderr, "zfs_mount_at() failed: "
+ "%s", libzfs_error_description(g_zfs));
+ zfs_close(zhp);
+ libzfs_fini(g_zfs);
+ return (MOUNT_SYSERR);
+ }
+ } else {
+ error = mount(dataset, mntpoint, MNTTYPE_ZFS,
+ mntflags, mntopts);
+ }
}
+ zfs_close(zhp);
+ libzfs_fini(g_zfs);
+
if (error) {
switch (errno) {
case ENOENT: