Skip to content

Commit

Permalink
LX-1396 umount failed (part deux)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryant G. Ly committed Nov 7, 2019
1 parent f14ae90 commit 6f4219b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
14 changes: 14 additions & 0 deletions cmd/zfs/zfs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,20 @@ parseprop(nvlist_t *props, char *propname)
"specified multiple times\n"), propname);
return (B_FALSE);
}

/*
* If we are setting the sharenfs property, lock the sharetab to
* ensure concurrent writers don't update the file simultaneously.
* The sharetab will remain locked until the process exits.
*/
if (strcmp(propname, zfs_prop_to_name(ZFS_PROP_SHARENFS)) == 0) {
if (sharetab_lock() != 0) {
(void) fprintf(stderr, gettext("unable to set "
"property: %s\n"), strerror(errno));
exit(1);
}
}

if (nvlist_add_string(props, propname, propval) != 0)
nomem();
return (B_TRUE);
Expand Down
13 changes: 12 additions & 1 deletion cmd/zpool/zpool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@

#include <libzfs.h>
#include <libzutil.h>
#include <libshare.h>

#include "zpool_util.h"
#include "zfs_comutil.h"
Expand Down Expand Up @@ -1614,12 +1615,15 @@ zpool_do_destroy(int argc, char **argv)
return (1);
}

verify(sharetab_lock() == 0);
if (zpool_disable_datasets(zhp, force) != 0) {
(void) fprintf(stderr, gettext("could not destroy '%s': "
"could not unmount datasets\n"), zpool_get_name(zhp));
zpool_close(zhp);
verify(sharetab_unlock() == 0);
return (1);
}
verify(sharetab_unlock() == 0);

/* The history must be logged as part of the export */
log_history = B_FALSE;
Expand All @@ -1644,8 +1648,12 @@ zpool_export_one(zpool_handle_t *zhp, void *data)
{
export_cbdata_t *cb = data;

if (zpool_disable_datasets(zhp, cb->force || cb->hardforce) != 0)
verify(sharetab_lock() == 0);
if (zpool_disable_datasets(zhp, cb->force || cb->hardforce) != 0) {
verify(sharetab_unlock() == 0);
return (1);
}
verify(sharetab_unlock() == 0);

/* The history must be logged as part of the export */
log_history = B_FALSE;
Expand Down Expand Up @@ -2827,12 +2835,15 @@ do_import(nvlist_t *config, const char *newname, const char *mntopts,
ret = 1;
}

verify(sharetab_lock() == 0);
if (zpool_get_state(zhp) != POOL_STATE_UNAVAIL &&
!(flags & ZFS_IMPORT_ONLY) &&
zpool_enable_datasets(zhp, mntopts, 0) != 0) {
zpool_close(zhp);
verify(sharetab_unlock() == 0);
return (1);
}
verify(sharetab_unlock() == 0);

zpool_close(zhp);
return (ret);
Expand Down
10 changes: 4 additions & 6 deletions lib/libshare/libshare.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,18 @@ sharetab_lock(void)
{
struct flock lock;

assert(sharetab_fd == -1);
verify(sharetab_fd == -1);

if (mkdir("/etc/dfs", 0755) < 0 && errno != EEXIST) {
perror("sharetab_lock: failed to create /etc/dfs");
return (-1);
return (errno);
}

sharetab_fd = open(ZFS_SHARETAB_LOCK, (O_RDWR | O_CREAT), 0600);

if (sharetab_fd < 0) {
perror("sharetab_lock: failed to open");
return (-1);
return (errno);
}

lock.l_type = F_WRLCK;
Expand All @@ -193,7 +193,7 @@ sharetab_lock(void)
lock.l_len = 0;
if (fcntl(sharetab_fd, F_SETLKW, &lock) < 0) {
perror("sharetab_lock: failed to lock");
return (-1);
return (errno);
}
return (0);
}
Expand All @@ -217,7 +217,6 @@ sharetab_unlock(void)
return (retval);
}


static void
update_sharetab(sa_handle_impl_t impl_handle)
{
Expand All @@ -228,7 +227,6 @@ update_sharetab(sa_handle_impl_t impl_handle)
sa_fstype_t *fstype;
const char *resource;


temp_fd = mkstemp(tempfile);

if (temp_fd < 0)
Expand Down
6 changes: 0 additions & 6 deletions lib/libzfs/libzfs_mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,6 @@ zfs_share_proto(zfs_handle_t *zhp, zfs_share_proto_t *proto)
if (!zfs_is_mountable(zhp, mountpoint, sizeof (mountpoint), NULL))
return (0);

verify(sharetab_lock() == 0);
for (curr_proto = proto; *curr_proto != PROTO_END; curr_proto++) {
/*
* Return success if there are no share options.
Expand All @@ -887,7 +886,6 @@ zfs_share_proto(zfs_handle_t *zhp, zfs_share_proto_t *proto)
(void) zfs_error_fmt(hdl, EZFS_SHARENFSFAILED,
dgettext(TEXT_DOMAIN, "cannot share '%s': %s"),
zfs_get_name(zhp), sa_errorstr(ret));
verify(sharetab_unlock() == 0);
return (-1);
}

Expand Down Expand Up @@ -919,7 +917,6 @@ zfs_share_proto(zfs_handle_t *zhp, zfs_share_proto_t *proto)
proto_table[*curr_proto].p_share_err,
dgettext(TEXT_DOMAIN, "cannot share '%s'"),
zfs_get_name(zhp));
verify(sharetab_unlock() == 0);
return (-1);
}
hdl->libzfs_shareflags |= ZFSSHARE_MISS;
Expand All @@ -935,20 +932,17 @@ zfs_share_proto(zfs_handle_t *zhp, zfs_share_proto_t *proto)
proto_table[*curr_proto].p_share_err,
dgettext(TEXT_DOMAIN, "cannot share '%s'"),
zfs_get_name(zhp));
verify(sharetab_unlock() == 0);
return (-1);
}
} else {
(void) zfs_error_fmt(hdl,
proto_table[*curr_proto].p_share_err,
dgettext(TEXT_DOMAIN, "cannot share '%s'"),
zfs_get_name(zhp));
verify(sharetab_unlock() == 0);
return (-1);
}

}
verify(sharetab_unlock() == 0);
return (0);
}

Expand Down

0 comments on commit 6f4219b

Please sign in to comment.