Skip to content

Commit

Permalink
Ignore errors from zfs_share when updating properties
Browse files Browse the repository at this point in the history
On TrueNAS SCALE, for every dataset middleware calls do_update()
from ZFSDatasetService. This eventually calls into
update_properties from py-libzfs which calls zfs_prop_set_list.

When zfs_prop_set_list is called, it tries to update all the
properties. On this path, libzfs upon checking for sharesmb and
sharenfs properties, it tries to share that particular filesystem
and reports error in updating the properties. Due to this, the
pool import is un-successful from the UI when middleware tries to
run ZFSDatasetService.

This commit checks for share status specifically from
zfs_prop_set_list and ignores the share errors if any.

Once the pool is imported, zfs_share service tries to enable the
zfs shares from zfs-share.service. This service is disabled by
default from now on.

Signed-off-by: Umer Saleem <[email protected]>
  • Loading branch information
usaleem-ix committed Aug 24, 2023
1 parent bbaf65a commit b33f8eb
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion contrib/debian/rules.in
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ override_dh_installinit:
dh_installinit -r --no-restart-after-upgrade --name zfs-import
dh_installinit -r --no-restart-after-upgrade --name zfs-mount
dh_installinit -r --no-restart-after-upgrade --name zfs-load-key
dh_installinit -R --name zfs-share
dh_installinit --no-start --no-enable --name zfs-share
dh_installinit -R --name zfs-zed

override_dh_installsystemd:
Expand Down
17 changes: 13 additions & 4 deletions lib/libzfs/libzfs_changelist.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ changelist_prefix(prop_changelist_t *clp)
uu_avl_walk_end(walk);

if (ret == -1)
(void) changelist_postfix(clp);
(void) changelist_postfix(clp, NULL);

return (ret);
}
Expand All @@ -169,12 +169,13 @@ changelist_prefix(prop_changelist_t *clp)
* filesystem.
*/
int
changelist_postfix(prop_changelist_t *clp)
changelist_postfix(prop_changelist_t *clp, int *s_status)
{
prop_changenode_t *cn;
uu_avl_walk_t *walk;
char shareopts[ZFS_MAXPROPLEN];
int errors = 0;
int ret = 0;
boolean_t commit_smb_shares = B_FALSE;
boolean_t commit_nfs_shares = B_FALSE;

Expand Down Expand Up @@ -262,7 +263,11 @@ changelist_postfix(prop_changelist_t *clp)
const enum sa_protocol nfs[] =
{SA_PROTOCOL_NFS, SA_NO_PROTOCOL};
if (sharenfs && mounted) {
errors += zfs_share(cn->cn_handle, nfs);
ret = zfs_share(cn->cn_handle, nfs);
if (ret != 0 && s_status != NULL) {
*s_status = EZFS_SHARENFSFAILED;
errors += ret;
}
commit_nfs_shares = B_TRUE;
} else if (cn->cn_shared || clp->cl_waslegacy) {
errors += zfs_unshare(cn->cn_handle, NULL, nfs);
Expand All @@ -271,7 +276,11 @@ changelist_postfix(prop_changelist_t *clp)
const enum sa_protocol smb[] =
{SA_PROTOCOL_SMB, SA_NO_PROTOCOL};
if (sharesmb && mounted) {
errors += zfs_share(cn->cn_handle, smb);
ret = zfs_share(cn->cn_handle, smb);
if (ret != 0 && s_status != NULL) {
*s_status = EZFS_SHARESMBFAILED;
errors += ret;
}
commit_smb_shares = B_TRUE;
} else if (cn->cn_shared || clp->cl_waslegacy) {
errors += zfs_unshare(cn->cn_handle, NULL, smb);
Expand Down
14 changes: 8 additions & 6 deletions lib/libzfs/libzfs_dataset.c
Original file line number Diff line number Diff line change
Expand Up @@ -1789,6 +1789,7 @@ zfs_prop_set_list(zfs_handle_t *zhp, nvlist_t *props)
nvlist_t *nvl;
int nvl_len = 0;
int added_resv = 0;
int s_status = 0;
zfs_prop_t prop;
boolean_t nsprop = B_FALSE;
nvpair_t *elem;
Expand Down Expand Up @@ -1918,8 +1919,9 @@ zfs_prop_set_list(zfs_handle_t *zhp, nvlist_t *props)
} else {
for (cl_idx = 0; cl_idx < nvl_len; cl_idx++) {
if (cls[cl_idx] != NULL) {
int clp_err = changelist_postfix(cls[cl_idx]);
if (clp_err != 0)
int clp_err = changelist_postfix(cls[cl_idx],
&s_status);
if (clp_err != 0 && s_status == 0)
ret = clp_err;
}
}
Expand Down Expand Up @@ -2044,7 +2046,7 @@ zfs_prop_inherit(zfs_handle_t *zhp, const char *propname, boolean_t received)
return (zfs_standard_error(hdl, errno, errbuf));
} else {

if ((ret = changelist_postfix(cl)) != 0)
if ((ret = changelist_postfix(cl, NULL)) != 0)
goto error;

/*
Expand Down Expand Up @@ -4334,7 +4336,7 @@ rollback_destroy_dependent(zfs_handle_t *zhp, void *data)
cbp->cb_error = B_TRUE;
else
changelist_remove(clp, zhp->zfs_name);
(void) changelist_postfix(clp);
(void) changelist_postfix(clp, NULL);
changelist_free(clp);

zfs_close(zhp);
Expand Down Expand Up @@ -4647,11 +4649,11 @@ zfs_rename(zfs_handle_t *zhp, const char *target, renameflags_t flags)
* were previously mounted, so we don't alter the system state.
*/
if (cl != NULL)
(void) changelist_postfix(cl);
(void) changelist_postfix(cl, NULL);
} else {
if (cl != NULL) {
changelist_rename(cl, zfs_get_name(zhp), target);
ret = changelist_postfix(cl);
ret = changelist_postfix(cl, NULL);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/libzfs/libzfs_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ extern int zcmd_read_dst_nvlist(libzfs_handle_t *, zfs_cmd_t *, nvlist_t **);
extern void zcmd_free_nvlists(zfs_cmd_t *);

extern int changelist_prefix(prop_changelist_t *);
extern int changelist_postfix(prop_changelist_t *);
extern int changelist_postfix(prop_changelist_t *, int *);
extern void changelist_rename(prop_changelist_t *, const char *, const char *);
extern void changelist_remove(prop_changelist_t *, const char *);
extern void changelist_free(prop_changelist_t *);
Expand Down
8 changes: 4 additions & 4 deletions lib/libzfs/libzfs_sendrecv.c
Original file line number Diff line number Diff line change
Expand Up @@ -2984,7 +2984,7 @@ recv_rename(libzfs_handle_t *hdl, const char *name, const char *tryname,
(void) printf("failed (%u)\n", errno);
}

(void) changelist_postfix(clp);
(void) changelist_postfix(clp, NULL);

out:
if (clp != NULL)
Expand Down Expand Up @@ -3089,7 +3089,7 @@ recv_destroy(libzfs_handle_t *hdl, const char *name, int baselen,
changelist_remove(clp, name);
}

(void) changelist_postfix(clp);
(void) changelist_postfix(clp, NULL);
changelist_free(clp);

/*
Expand Down Expand Up @@ -5238,7 +5238,7 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap,
*/
if (clp) {
if (!flags->nomount)
err |= changelist_postfix(clp);
err |= changelist_postfix(clp, NULL);
changelist_free(clp);
}

Expand Down Expand Up @@ -5549,7 +5549,7 @@ zfs_receive(libzfs_handle_t *hdl, const char *tosnap, nvlist_t *props,
}

/* mount and share received datasets */
err = changelist_postfix(clp);
err = changelist_postfix(clp, NULL);
changelist_free(clp);
if (err != 0)
err = -1;
Expand Down

0 comments on commit b33f8eb

Please sign in to comment.