Skip to content

Commit

Permalink
Let zfs mount all tolerate in-progress mounts
Browse files Browse the repository at this point in the history
The zfs-mount service can unexpectedly fail to start when zfs 
encounters a mount that is in progress. This service uses 
zfs mount -a, which has a window between the time it checks if 
the dataset was mounted and when the actual mount (via mount.zfs 
binary) occurs.

The reason for the racing mounts is that both zfs-mount.target 
and zfs-share.target are allowed to execute concurrently after 
the import.  This is more of an issue with the relatively recent 
addition of parallel mounting, and we should consider serializing
the mount and share targets.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed by: John Kennedy <john.kennedy@delphix.com>
Reviewed-by: Allan Jude <allanjude@freebsd.org>
Signed-off-by: Don Brady <don.brady@delphix.com>
Closes #8881
  • Loading branch information
Don Brady authored and behlendorf committed Jun 22, 2019
1 parent fb6e6f1 commit a9cd8bf
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion cmd/zfs/zfs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6580,8 +6580,25 @@ share_mount_one(zfs_handle_t *zhp, int op, int flags, char *protocol,
return (1);
}

if (zfs_mount(zhp, options, flags) != 0)
if (zfs_mount(zhp, options, flags) != 0) {
/*
* Check if a mount sneaked in after we checked
*/
if (!explicit &&
libzfs_errno(g_zfs) == EZFS_MOUNTFAILED) {
usleep(10 * MILLISEC);
libzfs_mnttab_cache(g_zfs, B_FALSE);

if (zfs_is_mounted(zhp, NULL)) {
(void) fprintf(stderr, gettext(
"Ignoring previous 'already "
"mounted' error for '%s'\n"),
zfs_get_name(zhp));
return (0);
}
}
return (1);
}
break;
}

Expand Down

0 comments on commit a9cd8bf

Please sign in to comment.