Skip to content

Commit d7a6740

Browse files
authored
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 openzfs#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 openzfs#7947 Closes openzfs#13021
1 parent 5f65d00 commit d7a6740

File tree

1 file changed

+34
-13
lines changed

1 file changed

+34
-13
lines changed

cmd/mount_zfs/mount_zfs.c

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,6 @@ main(int argc, char **argv)
246246
}
247247
}
248248

249-
if (verbose)
250-
(void) fprintf(stdout, gettext("mount.zfs:\n"
251-
" dataset: \"%s\"\n mountpoint: \"%s\"\n"
252-
" mountflags: 0x%lx\n zfsflags: 0x%lx\n"
253-
" mountopts: \"%s\"\n mtabopts: \"%s\"\n"),
254-
dataset, mntpoint, mntflags, zfsflags, mntopts, mtabopt);
255-
256249
if (mntflags & MS_REMOUNT) {
257250
nomtab = 1;
258251
remount = 1;
@@ -275,7 +268,10 @@ main(int argc, char **argv)
275268
return (MOUNT_USAGE);
276269
}
277270

278-
zfs_adjust_mount_options(zhp, mntpoint, mntopts, mtabopt);
271+
if (!zfsutil || sloppy ||
272+
libzfs_envvar_is_set("ZFS_MOUNT_HELPER")) {
273+
zfs_adjust_mount_options(zhp, mntpoint, mntopts, mtabopt);
274+
}
279275

280276
/* treat all snapshots as legacy mount points */
281277
if (zfs_get_type(zhp) == ZFS_TYPE_SNAPSHOT)
@@ -293,12 +289,11 @@ main(int argc, char **argv)
293289
if (zfs_version == 0) {
294290
fprintf(stderr, gettext("unable to fetch "
295291
"ZFS version for filesystem '%s'\n"), dataset);
292+
zfs_close(zhp);
293+
libzfs_fini(g_zfs);
296294
return (MOUNT_SYSERR);
297295
}
298296

299-
zfs_close(zhp);
300-
libzfs_fini(g_zfs);
301-
302297
/*
303298
* Legacy mount points may only be mounted using 'mount', never using
304299
* 'zfs mount'. However, since 'zfs mount' actually invokes 'mount'
@@ -316,6 +311,8 @@ main(int argc, char **argv)
316311
"Use 'zfs set mountpoint=%s' or 'mount -t zfs %s %s'.\n"
317312
"See zfs(8) for more information.\n"),
318313
dataset, mntpoint, dataset, mntpoint);
314+
zfs_close(zhp);
315+
libzfs_fini(g_zfs);
319316
return (MOUNT_USAGE);
320317
}
321318

@@ -326,14 +323,38 @@ main(int argc, char **argv)
326323
"Use 'zfs set mountpoint=%s' or 'zfs mount %s'.\n"
327324
"See zfs(8) for more information.\n"),
328325
dataset, "legacy", dataset);
326+
zfs_close(zhp);
327+
libzfs_fini(g_zfs);
329328
return (MOUNT_USAGE);
330329
}
331330

331+
if (verbose)
332+
(void) fprintf(stdout, gettext("mount.zfs:\n"
333+
" dataset: \"%s\"\n mountpoint: \"%s\"\n"
334+
" mountflags: 0x%lx\n zfsflags: 0x%lx\n"
335+
" mountopts: \"%s\"\n mtabopts: \"%s\"\n"),
336+
dataset, mntpoint, mntflags, zfsflags, mntopts, mtabopt);
337+
332338
if (!fake) {
333-
error = mount(dataset, mntpoint, MNTTYPE_ZFS,
334-
mntflags, mntopts);
339+
if (zfsutil && !sloppy &&
340+
!libzfs_envvar_is_set("ZFS_MOUNT_HELPER")) {
341+
error = zfs_mount_at(zhp, mntopts, mntflags, mntpoint);
342+
if (error) {
343+
(void) fprintf(stderr, "zfs_mount_at() failed: "
344+
"%s", libzfs_error_description(g_zfs));
345+
zfs_close(zhp);
346+
libzfs_fini(g_zfs);
347+
return (MOUNT_SYSERR);
348+
}
349+
} else {
350+
error = mount(dataset, mntpoint, MNTTYPE_ZFS,
351+
mntflags, mntopts);
352+
}
335353
}
336354

355+
zfs_close(zhp);
356+
libzfs_fini(g_zfs);
357+
337358
if (error) {
338359
switch (errno) {
339360
case ENOENT:

0 commit comments

Comments
 (0)