7857 zfs/zpool commands print scary errors after 7741
[unleashed.git] / usr / src / lib / libshare / common / libshare_zfs.c
blob08b5a00e9d2f7fdaf732c1339ff9bcbf3affa32c
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
26 * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
27 * Copyright (c) 2012, 2016 by Delphix. All rights reserved.
28 * Copyright 2017 RackTop Systems.
31 #include <stdio.h>
32 #include <libzfs.h>
33 #include <string.h>
34 #include <strings.h>
35 #include <errno.h>
36 #include <libshare.h>
37 #include "libshare_impl.h"
38 #include <libintl.h>
39 #include <sys/mnttab.h>
40 #include <sys/mntent.h>
41 #include <assert.h>
43 extern sa_share_t _sa_add_share(sa_group_t, char *, int, int *, uint64_t);
44 extern sa_group_t _sa_create_zfs_group(sa_group_t, char *);
45 extern char *sa_fstype(char *);
46 extern void set_node_attr(void *, char *, char *);
47 extern int sa_is_share(void *);
48 extern void sa_update_sharetab_ts(sa_handle_t);
51 * File system specific code for ZFS. The original code was stolen
52 * from the "zfs" command and modified to better suit this library's
53 * usage.
56 typedef struct get_all_cbdata {
57 zfs_handle_t **cb_handles;
58 size_t cb_alloc;
59 size_t cb_used;
60 uint_t cb_types;
61 } get_all_cbdata_t;
64 * sa_zfs_init(impl_handle)
66 * Initialize an access handle into libzfs. The handle needs to stay
67 * around until sa_zfs_fini() in order to maintain the cache of
68 * mounts.
71 int
72 sa_zfs_init(sa_handle_impl_t impl_handle)
74 impl_handle->zfs_libhandle = libzfs_init();
75 if (impl_handle->zfs_libhandle != NULL) {
76 libzfs_print_on_error(impl_handle->zfs_libhandle, B_TRUE);
77 return (B_TRUE);
79 return (B_FALSE);
83 * sa_zfs_fini(impl_handle)
85 * cleanup data structures and the libzfs handle used for accessing
86 * zfs file share info.
89 void
90 sa_zfs_fini(sa_handle_impl_t impl_handle)
92 if (impl_handle->zfs_libhandle != NULL) {
93 if (impl_handle->zfs_list != NULL) {
94 zfs_handle_t **zhp = impl_handle->zfs_list;
95 size_t i;
98 * Contents of zfs_list need to be freed so we
99 * don't lose ZFS handles.
101 for (i = 0; i < impl_handle->zfs_list_count; i++) {
102 zfs_close(zhp[i]);
104 free(impl_handle->zfs_list);
105 impl_handle->zfs_list = NULL;
106 impl_handle->zfs_list_count = 0;
109 libzfs_fini(impl_handle->zfs_libhandle);
110 impl_handle->zfs_libhandle = NULL;
115 * get_one_filesystem(zfs_handle_t, data)
117 * an iterator function called while iterating through the ZFS
118 * root. It accumulates into an array of file system handles that can
119 * be used to derive info about those file systems.
121 * Note that as this function is called, we close all zhp handles that
122 * are not going to be places into the cp_handles list. We don't want
123 * to close the ones we are keeping, but all others would be leaked if
124 * not closed here.
127 static int
128 get_one_filesystem(zfs_handle_t *zhp, void *data)
130 get_all_cbdata_t *cbp = data;
131 zfs_type_t type = zfs_get_type(zhp);
134 * Interate over any nested datasets.
136 if (type == ZFS_TYPE_FILESYSTEM &&
137 zfs_iter_filesystems(zhp, get_one_filesystem, data) != 0) {
138 zfs_close(zhp);
139 return (1);
143 * Skip any datasets whose type does not match.
145 if ((type & cbp->cb_types) == 0) {
146 zfs_close(zhp);
147 return (0);
150 if (cbp->cb_alloc == cbp->cb_used) {
151 zfs_handle_t **handles;
153 if (cbp->cb_alloc == 0)
154 cbp->cb_alloc = 64;
155 else
156 cbp->cb_alloc *= 2;
158 handles = (zfs_handle_t **)calloc(1,
159 cbp->cb_alloc * sizeof (void *));
161 if (handles == NULL) {
162 zfs_close(zhp);
163 return (0);
165 if (cbp->cb_handles) {
166 bcopy(cbp->cb_handles, handles,
167 cbp->cb_used * sizeof (void *));
168 free(cbp->cb_handles);
171 cbp->cb_handles = handles;
174 cbp->cb_handles[cbp->cb_used++] = zhp;
176 return (0);
180 * get_all_filesystems(zfs_handle_t ***fslist, size_t *count)
182 * iterate through all ZFS file systems starting at the root. Returns
183 * a count and an array of handle pointers. Allocating is only done
184 * once. The caller does not need to free since it will be done at
185 * sa_zfs_fini() time.
188 static void
189 get_all_filesystems(sa_handle_impl_t impl_handle,
190 zfs_handle_t ***fslist, size_t *count)
192 get_all_cbdata_t cb = { 0 };
193 cb.cb_types = ZFS_TYPE_FILESYSTEM;
195 if (impl_handle->zfs_list != NULL) {
196 *fslist = impl_handle->zfs_list;
197 *count = impl_handle->zfs_list_count;
198 return;
201 (void) zfs_iter_root(impl_handle->zfs_libhandle,
202 get_one_filesystem, &cb);
204 impl_handle->zfs_list = *fslist = cb.cb_handles;
205 impl_handle->zfs_list_count = *count = cb.cb_used;
209 * mountpoint_compare(a, b)
211 * compares the mountpoint on two zfs file systems handles.
212 * returns values following strcmp() model.
215 static int
216 mountpoint_compare(const void *a, const void *b)
218 zfs_handle_t **za = (zfs_handle_t **)a;
219 zfs_handle_t **zb = (zfs_handle_t **)b;
220 char mounta[MAXPATHLEN];
221 char mountb[MAXPATHLEN];
223 verify(zfs_prop_get(*za, ZFS_PROP_MOUNTPOINT, mounta,
224 sizeof (mounta), NULL, NULL, 0, B_FALSE) == 0);
225 verify(zfs_prop_get(*zb, ZFS_PROP_MOUNTPOINT, mountb,
226 sizeof (mountb), NULL, NULL, 0, B_FALSE) == 0);
228 return (strcmp(mounta, mountb));
232 * return legacy mountpoint. Caller provides space for mountpoint and
233 * dataset.
236 get_legacy_mountpoint(const char *path, char *dataset, size_t dlen,
237 char *mountpoint, size_t mlen)
239 FILE *fp;
240 struct mnttab entry;
242 if ((fp = fopen(MNTTAB, "r")) == NULL) {
243 return (1);
246 while (getmntent(fp, &entry) == 0) {
248 if (entry.mnt_fstype == NULL ||
249 strcmp(entry.mnt_fstype, MNTTYPE_ZFS) != 0)
250 continue;
252 if (strcmp(entry.mnt_mountp, path) == 0) {
253 if (mlen > 0)
254 (void) strlcpy(mountpoint, entry.mnt_mountp,
255 mlen);
256 if (dlen > 0)
257 (void) strlcpy(dataset, entry.mnt_special,
258 dlen);
259 break;
262 (void) fclose(fp);
263 return (1);
267 static char *
268 verify_zfs_handle(zfs_handle_t *hdl, const char *path, boolean_t search_mnttab)
270 char mountpoint[ZFS_MAXPROPLEN];
271 char canmount[ZFS_MAXPROPLEN] = { 0 };
272 /* must have a mountpoint */
273 if (zfs_prop_get(hdl, ZFS_PROP_MOUNTPOINT, mountpoint,
274 sizeof (mountpoint), NULL, NULL, 0, B_FALSE) != 0) {
275 /* no mountpoint */
276 return (NULL);
279 /* mountpoint must be a path */
280 if (strcmp(mountpoint, ZFS_MOUNTPOINT_NONE) == 0 ||
281 strcmp(mountpoint, ZFS_MOUNTPOINT_LEGACY) == 0) {
283 * Search mmttab for mountpoint and get dataset.
286 if (search_mnttab == B_TRUE &&
287 get_legacy_mountpoint(path, mountpoint,
288 sizeof (mountpoint), NULL, 0) == 0) {
289 return (strdup(mountpoint));
291 return (NULL);
294 /* canmount must be set */
295 if (zfs_prop_get(hdl, ZFS_PROP_CANMOUNT, canmount,
296 sizeof (canmount), NULL, NULL, 0, B_FALSE) != 0 ||
297 strcmp(canmount, "off") == 0)
298 return (NULL);
301 * have a mountable handle but want to skip those marked none
302 * and legacy
304 if (strcmp(mountpoint, path) == 0) {
305 return (strdup((char *)zfs_get_name(hdl)));
308 return (NULL);
312 * get_zfs_dataset(impl_handle, path)
314 * get the name of the ZFS dataset the path is equivalent to. The
315 * dataset name is used for get/set of ZFS properties since libzfs
316 * requires a dataset to do a zfs_open().
319 static char *
320 get_zfs_dataset(sa_handle_impl_t impl_handle, char *path,
321 boolean_t search_mnttab)
323 size_t i, count = 0;
324 zfs_handle_t **zlist;
325 char *cutpath;
326 zfs_handle_t *handle_from_path;
327 char *ret = NULL;
330 * First we optimistically assume that the mount path for the filesystem
331 * is the same as the name of the filesystem (minus some number of
332 * leading slashes). If this is true, then zfs_open should properly open
333 * the filesystem. We duplicate the error checking done later in the
334 * function for consistency. If anything fails, we resort to the
335 * (extremely slow) search of all the filesystems.
337 cutpath = path + strspn(path, "/");
339 assert(impl_handle->zfs_libhandle != NULL);
340 libzfs_print_on_error(impl_handle->zfs_libhandle, B_FALSE);
341 if ((handle_from_path = zfs_open(impl_handle->zfs_libhandle, cutpath,
342 ZFS_TYPE_FILESYSTEM)) != NULL) {
343 if ((ret = verify_zfs_handle(handle_from_path, path,
344 search_mnttab)) != NULL) {
345 zfs_close(handle_from_path);
346 libzfs_print_on_error(impl_handle->zfs_libhandle,
347 B_TRUE);
348 return (ret);
350 zfs_close(handle_from_path);
352 libzfs_print_on_error(impl_handle->zfs_libhandle, B_TRUE);
355 * Couldn't find a filesystem optimistically, check all the handles we
356 * can.
358 get_all_filesystems(impl_handle, &zlist, &count);
359 for (i = 0; i < count; i++) {
360 assert(zlist[i]);
361 if ((ret = verify_zfs_handle(zlist[i], path,
362 search_mnttab)) != NULL)
363 return (ret);
366 /* Couldn't find a matching dataset */
367 return (NULL);
371 * get_zfs_property(dataset, property)
373 * Get the file system property specified from the ZFS dataset.
376 static char *
377 get_zfs_property(char *dataset, zfs_prop_t property)
379 zfs_handle_t *handle = NULL;
380 char shareopts[ZFS_MAXPROPLEN];
381 libzfs_handle_t *libhandle;
383 libhandle = libzfs_init();
384 if (libhandle != NULL) {
385 handle = zfs_open(libhandle, dataset, ZFS_TYPE_FILESYSTEM);
386 if (handle != NULL) {
387 if (zfs_prop_get(handle, property, shareopts,
388 sizeof (shareopts), NULL, NULL, 0,
389 B_FALSE) == 0) {
390 zfs_close(handle);
391 libzfs_fini(libhandle);
392 return (strdup(shareopts));
394 zfs_close(handle);
396 libzfs_fini(libhandle);
398 return (NULL);
402 * sa_zfs_is_shared(handle, path)
404 * Check to see if the ZFS path provided has the sharenfs option set
405 * or not.
409 sa_zfs_is_shared(sa_handle_t sahandle, char *path)
411 int ret = 0;
412 char *dataset;
413 zfs_handle_t *handle = NULL;
414 char shareopts[ZFS_MAXPROPLEN];
415 libzfs_handle_t *libhandle;
417 dataset = get_zfs_dataset((sa_handle_t)sahandle, path, B_FALSE);
418 if (dataset != NULL) {
419 libhandle = libzfs_init();
420 if (libhandle != NULL) {
421 handle = zfs_open(libhandle, dataset,
422 ZFS_TYPE_FILESYSTEM);
423 if (handle != NULL) {
424 if (zfs_prop_get(handle, ZFS_PROP_SHARENFS,
425 shareopts, sizeof (shareopts), NULL, NULL,
426 0, B_FALSE) == 0 &&
427 strcmp(shareopts, "off") != 0) {
428 ret = 1; /* it is shared */
430 zfs_close(handle);
432 libzfs_fini(libhandle);
434 free(dataset);
436 return (ret);
440 * find_or_create_group(handle, groupname, proto, *err)
442 * While walking the ZFS tree, we need to add shares to a defined
443 * group. If the group doesn't exist, create it first, making sure it
444 * is marked as a ZFS group.
446 * Note that all ZFS shares are in a subgroup of the top level group
447 * called "zfs".
450 static sa_group_t
451 find_or_create_group(sa_handle_t handle, char *groupname, char *proto, int *err)
453 sa_group_t group;
454 sa_optionset_t optionset;
455 int ret = SA_OK;
458 * we check to see if the "zfs" group exists. Since this
459 * should be the top level group, we don't want the
460 * parent. This is to make sure the zfs group has been created
461 * and to created if it hasn't been.
463 group = sa_get_group(handle, groupname);
464 if (group == NULL) {
465 group = sa_create_group(handle, groupname, &ret);
467 /* make sure this is flagged as a ZFS group */
468 if (group != NULL)
469 ret = sa_set_group_attr(group, "zfs", "true");
471 if (group != NULL) {
472 if (proto != NULL) {
473 optionset = sa_get_optionset(group, proto);
474 if (optionset == NULL)
475 optionset = sa_create_optionset(group, proto);
478 if (err != NULL)
479 *err = ret;
480 return (group);
484 * find_or_create_zfs_subgroup(groupname, optstring, *err)
486 * ZFS shares will be in a subgroup of the "zfs" master group. This
487 * function looks to see if the groupname exists and returns it if it
488 * does or else creates a new one with the specified name and returns
489 * that. The "zfs" group will exist before we get here, but we make
490 * sure just in case.
492 * err must be a valid pointer.
495 static sa_group_t
496 find_or_create_zfs_subgroup(sa_handle_t handle, char *groupname, char *proto,
497 char *optstring, int *err)
499 sa_group_t group = NULL;
500 sa_group_t zfs;
501 char *name;
502 char *options;
504 /* start with the top-level "zfs" group */
505 zfs = sa_get_group(handle, "zfs");
506 *err = SA_OK;
507 if (zfs != NULL) {
508 for (group = sa_get_sub_group(zfs); group != NULL;
509 group = sa_get_next_group(group)) {
510 name = sa_get_group_attr(group, "name");
511 if (name != NULL && strcmp(name, groupname) == 0) {
512 /* have the group so break out of here */
513 sa_free_attr_string(name);
514 break;
516 if (name != NULL)
517 sa_free_attr_string(name);
520 if (group == NULL) {
522 * Need to create the sub-group since it doesn't exist
524 group = _sa_create_zfs_group(zfs, groupname);
525 if (group == NULL) {
526 *err = SA_NO_MEMORY;
527 return (NULL);
529 set_node_attr(group, "zfs", "true");
531 if (strcmp(optstring, "on") == 0)
532 optstring = "rw";
533 options = strdup(optstring);
534 if (options != NULL) {
535 *err = sa_parse_legacy_options(group, options,
536 proto);
537 /* If no optionset, add one. */
538 if (sa_get_optionset(group, proto) == NULL)
539 (void) sa_create_optionset(group, proto);
542 * Do not forget to update an optionset of
543 * the parent group so that it contains
544 * all protocols its subgroups have.
546 if (sa_get_optionset(zfs, proto) == NULL)
547 (void) sa_create_optionset(zfs, proto);
549 free(options);
550 } else {
551 *err = SA_NO_MEMORY;
554 return (group);
558 * zfs_construct_resource(share, name, base, dataset)
560 * Add a resource to the share using name as a template. If name ==
561 * NULL, then construct a name based on the dataset value.
562 * name.
564 static void
565 zfs_construct_resource(sa_share_t share, char *dataset)
567 char buff[SA_MAX_RESOURCE_NAME + 1];
568 int ret = SA_OK;
570 (void) snprintf(buff, SA_MAX_RESOURCE_NAME, "%s", dataset);
571 sa_fix_resource_name(buff);
572 (void) sa_add_resource(share, buff, SA_SHARE_TRANSIENT, &ret);
576 * zfs_inherited(handle, source, sourcestr)
578 * handle case of inherited share{nfs,smb}. Pulled out of sa_get_zfs_shares
579 * for readability.
581 static int
582 zfs_inherited(sa_handle_t handle, sa_share_t share, char *sourcestr,
583 char *shareopts, char *mountpoint, char *proto, char *dataset)
585 int doshopt = 0;
586 int err = SA_OK;
587 sa_group_t group;
588 sa_resource_t resource;
589 uint64_t features;
592 * Need to find the "real" parent sub-group. It may not be
593 * mounted, but it was identified in the "sourcestr"
594 * variable. The real parent not mounted can occur if
595 * "canmount=off and sharenfs=on".
597 group = find_or_create_zfs_subgroup(handle, sourcestr, proto,
598 shareopts, &doshopt);
599 if (group != NULL) {
601 * We may need the first share for resource
602 * prototype. We only care about it if it has a
603 * resource that sets a prefix value.
605 if (share == NULL)
606 share = _sa_add_share(group, mountpoint,
607 SA_SHARE_TRANSIENT, &err,
608 (uint64_t)SA_FEATURE_NONE);
610 * some options may only be on shares. If the opt
611 * string contains one of those, we put it just on the
612 * share.
614 if (share != NULL && doshopt == SA_PROP_SHARE_ONLY) {
615 char *options;
616 options = strdup(shareopts);
617 if (options != NULL) {
618 set_node_attr(share, "dataset", dataset);
619 err = sa_parse_legacy_options(share, options,
620 proto);
621 set_node_attr(share, "dataset", NULL);
622 free(options);
624 if (sa_get_optionset(group, proto) == NULL)
625 (void) sa_create_optionset(group, proto);
627 features = sa_proto_get_featureset(proto);
628 if (share != NULL && features & SA_FEATURE_RESOURCE) {
630 * We have a share and the protocol requires
631 * that at least one resource exist (probably
632 * SMB). We need to make sure that there is at
633 * least one.
635 resource = sa_get_share_resource(share, NULL);
636 if (resource == NULL) {
637 zfs_construct_resource(share, dataset);
640 } else {
641 err = SA_NO_MEMORY;
643 return (err);
647 * zfs_notinherited(group, share, mountpoint, shareopts, proto, dataset,
648 * grouperr)
650 * handle case where this is the top of a sub-group in ZFS. Pulled out
651 * of sa_get_zfs_shares for readability. We need the grouperr from the
652 * creation of the subgroup to know whether to add the public
653 * property, etc. to the specific share.
655 static int
656 zfs_notinherited(sa_group_t group, sa_share_t share, char *mountpoint,
657 char *shareopts, char *proto, char *dataset, int grouperr)
659 int err = SA_OK;
660 sa_resource_t resource;
661 uint64_t features;
663 set_node_attr(group, "zfs", "true");
664 if (share == NULL)
665 share = _sa_add_share(group, mountpoint, SA_SHARE_TRANSIENT,
666 &err, (uint64_t)SA_FEATURE_NONE);
668 if (err != SA_OK)
669 return (err);
671 if (strcmp(shareopts, "on") == 0)
672 shareopts = "";
673 if (shareopts != NULL) {
674 char *options;
675 if (grouperr == SA_PROP_SHARE_ONLY) {
677 * Some properties may only be on shares, but
678 * due to the ZFS sub-groups being artificial,
679 * we sometimes get this and have to deal with
680 * it. We do it by attempting to put it on the
681 * share.
683 options = strdup(shareopts);
684 if (options != NULL) {
685 err = sa_parse_legacy_options(share,
686 options, proto);
687 free(options);
690 /* Unmark the share's changed state */
691 set_node_attr(share, "changed", NULL);
693 features = sa_proto_get_featureset(proto);
694 if (share != NULL && features & SA_FEATURE_RESOURCE) {
696 * We have a share and the protocol requires that at
697 * least one resource exist (probably SMB). We need to
698 * make sure that there is at least one.
700 resource = sa_get_share_resource(share, NULL);
701 if (resource == NULL) {
702 zfs_construct_resource(share, dataset);
705 return (err);
709 * zfs_grp_error(err)
711 * Print group create error, but only once. If err is 0 do the
712 * print else don't.
715 static void
716 zfs_grp_error(int err)
718 if (err == 0) {
719 /* only print error once */
720 (void) fprintf(stderr, dgettext(TEXT_DOMAIN,
721 "Cannot create ZFS subgroup during initialization:"
722 " %s\n"), sa_errorstr(SA_SYSTEM_ERR));
727 * zfs_process_share(handle, share, mountpoint, proto, source,
728 * shareopts, sourcestr)
730 * Creates the subgroup, if necessary and adds shares, resources
731 * and properties.
734 sa_zfs_process_share(sa_handle_t handle, sa_group_t group, sa_share_t share,
735 char *mountpoint, char *proto, zprop_source_t source, char *shareopts,
736 char *sourcestr, char *dataset)
738 int err = SA_OK;
740 if (source & ZPROP_SRC_INHERITED) {
741 err = zfs_inherited(handle, share, sourcestr, shareopts,
742 mountpoint, proto, dataset);
743 } else {
744 group = find_or_create_zfs_subgroup(handle, dataset, proto,
745 shareopts, &err);
746 if (group == NULL) {
747 static boolean_t reported_error = B_FALSE;
749 * There is a problem, but we can't do
750 * anything about it at this point so we issue
751 * a warning and move on.
753 zfs_grp_error(reported_error);
754 reported_error = B_TRUE;
756 set_node_attr(group, "zfs", "true");
758 * Add share with local opts via zfs_notinherited.
760 err = zfs_notinherited(group, share, mountpoint, shareopts,
761 proto, dataset, err);
763 return (err);
767 * sa_get_zfs_shares(handle, groupname)
769 * Walk the mnttab for all zfs mounts and determine which are
770 * shared. Find or create the appropriate group/sub-group to contain
771 * the shares.
773 * All shares are in a sub-group that will hold the properties. This
774 * allows representing the inherited property model.
776 * One area of complication is if "sharenfs" is set at one level of
777 * the directory tree and "sharesmb" is set at a different level, the
778 * a sub-group must be formed at the lower level for both
779 * protocols. That is the nature of the problem in CR 6667349.
783 sa_get_zfs_shares(sa_handle_t handle, char *groupname)
785 sa_group_t zfsgroup;
786 boolean_t nfs;
787 boolean_t nfs_inherited;
788 boolean_t smb;
789 boolean_t smb_inherited;
790 zfs_handle_t **zlist;
791 char nfsshareopts[ZFS_MAXPROPLEN];
792 char smbshareopts[ZFS_MAXPROPLEN];
793 sa_share_t share;
794 zprop_source_t source;
795 char nfssourcestr[ZFS_MAXPROPLEN];
796 char smbsourcestr[ZFS_MAXPROPLEN];
797 char mountpoint[ZFS_MAXPROPLEN];
798 size_t count = 0, i;
799 libzfs_handle_t *zfs_libhandle;
800 int err = SA_OK;
803 * If we can't access libzfs, don't bother doing anything.
805 zfs_libhandle = ((sa_handle_impl_t)handle)->zfs_libhandle;
806 if (zfs_libhandle == NULL)
807 return (SA_SYSTEM_ERR);
809 zfsgroup = find_or_create_group(handle, groupname, NULL, &err);
810 /* Not an error, this could be a legacy condition */
811 if (zfsgroup == NULL)
812 return (SA_OK);
815 * need to walk the mounted ZFS pools and datasets to
816 * find shares that are possible.
818 get_all_filesystems((sa_handle_impl_t)handle, &zlist, &count);
819 qsort(zlist, count, sizeof (void *), mountpoint_compare);
821 for (i = 0; i < count; i++) {
822 char *dataset;
824 source = ZPROP_SRC_ALL;
825 /* If no mountpoint, skip. */
826 if (zfs_prop_get(zlist[i], ZFS_PROP_MOUNTPOINT,
827 mountpoint, sizeof (mountpoint), NULL, NULL, 0,
828 B_FALSE) != 0)
829 continue;
832 * zfs_get_name value must not be freed. It is just a
833 * pointer to a value in the handle.
835 if ((dataset = (char *)zfs_get_name(zlist[i])) == NULL)
836 continue;
839 * only deal with "mounted" file systems since
840 * unmounted file systems can't actually be shared.
843 if (!zfs_is_mounted(zlist[i], NULL))
844 continue;
846 nfs = nfs_inherited = B_FALSE;
848 if (zfs_prop_get(zlist[i], ZFS_PROP_SHARENFS, nfsshareopts,
849 sizeof (nfsshareopts), &source, nfssourcestr,
850 ZFS_MAXPROPLEN, B_FALSE) == 0 &&
851 strcmp(nfsshareopts, "off") != 0) {
852 if (source & ZPROP_SRC_INHERITED)
853 nfs_inherited = B_TRUE;
854 else
855 nfs = B_TRUE;
858 smb = smb_inherited = B_FALSE;
859 if (zfs_prop_get(zlist[i], ZFS_PROP_SHARESMB, smbshareopts,
860 sizeof (smbshareopts), &source, smbsourcestr,
861 ZFS_MAXPROPLEN, B_FALSE) == 0 &&
862 strcmp(smbshareopts, "off") != 0) {
863 if (source & ZPROP_SRC_INHERITED)
864 smb_inherited = B_TRUE;
865 else
866 smb = B_TRUE;
870 * If the mountpoint is already shared, it must be a
871 * non-ZFS share. We want to remove the share from its
872 * parent group and reshare it under ZFS.
874 share = sa_find_share(handle, mountpoint);
875 if (share != NULL &&
876 (nfs || smb || nfs_inherited || smb_inherited)) {
877 err = sa_remove_share(share);
878 share = NULL;
882 * At this point, we have the information needed to
883 * determine what to do with the share.
885 * If smb or nfs is set, we have a new sub-group.
886 * If smb_inherit and/or nfs_inherit is set, then
887 * place on an existing sub-group. If both are set,
888 * the existing sub-group is the closest up the tree.
890 if (nfs || smb) {
892 * Non-inherited is the straightforward
893 * case. sa_zfs_process_share handles it
894 * directly. Make sure that if the "other"
895 * protocol is inherited, that we treat it as
896 * non-inherited as well.
898 if (nfs || nfs_inherited) {
899 err = sa_zfs_process_share(handle, zfsgroup,
900 share, mountpoint, "nfs",
901 0, nfsshareopts,
902 nfssourcestr, dataset);
903 share = sa_find_share(handle, mountpoint);
905 if (smb || smb_inherited) {
906 err = sa_zfs_process_share(handle, zfsgroup,
907 share, mountpoint, "smb",
908 0, smbshareopts,
909 smbsourcestr, dataset);
911 } else if (nfs_inherited || smb_inherited) {
912 char *grpdataset;
914 * If we only have inherited groups, it is
915 * important to find the closer of the two if
916 * the protocols are set at different
917 * levels. The closest sub-group is the one we
918 * want to work with.
920 if (nfs_inherited && smb_inherited) {
921 if (strcmp(nfssourcestr, smbsourcestr) <= 0)
922 grpdataset = nfssourcestr;
923 else
924 grpdataset = smbsourcestr;
925 } else if (nfs_inherited) {
926 grpdataset = nfssourcestr;
927 } else if (smb_inherited) {
928 grpdataset = smbsourcestr;
930 if (nfs_inherited) {
931 err = sa_zfs_process_share(handle, zfsgroup,
932 share, mountpoint, "nfs",
933 ZPROP_SRC_INHERITED, nfsshareopts,
934 grpdataset, dataset);
935 share = sa_find_share(handle, mountpoint);
937 if (smb_inherited) {
938 err = sa_zfs_process_share(handle, zfsgroup,
939 share, mountpoint, "smb",
940 ZPROP_SRC_INHERITED, smbshareopts,
941 grpdataset, dataset);
946 * Don't need to free the "zlist" variable since it is only a
947 * pointer to a cached value that will be freed when
948 * sa_fini() is called.
950 return (err);
953 #define COMMAND "/usr/sbin/zfs"
956 * sa_zfs_set_sharenfs(group, path, on)
958 * Update the "sharenfs" property on the path. If on is true, then set
959 * to the properties on the group or "on" if no properties are
960 * defined. Set to "off" if on is false.
964 sa_zfs_set_sharenfs(sa_group_t group, char *path, int on)
966 int ret = SA_NOT_IMPLEMENTED;
967 char *command;
969 command = malloc(ZFS_MAXPROPLEN * 2);
970 if (command != NULL) {
971 char *opts = NULL;
972 char *dataset = NULL;
973 FILE *pfile;
974 sa_handle_impl_t impl_handle;
975 /* for now, NFS is always available for "zfs" */
976 if (on) {
977 opts = sa_proto_legacy_format("nfs", group, 1);
978 if (opts != NULL && strlen(opts) == 0) {
979 free(opts);
980 opts = strdup("on");
984 impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
985 assert(impl_handle != NULL);
986 if (impl_handle != NULL)
987 dataset = get_zfs_dataset(impl_handle, path, B_FALSE);
988 else
989 ret = SA_SYSTEM_ERR;
991 if (dataset != NULL) {
992 (void) snprintf(command, ZFS_MAXPROPLEN * 2,
993 "%s set sharenfs=\"%s\" %s", COMMAND,
994 opts != NULL ? opts : "off", dataset);
995 pfile = popen(command, "r");
996 if (pfile != NULL) {
997 ret = pclose(pfile);
998 if (ret != 0)
999 ret = SA_SYSTEM_ERR;
1002 if (opts != NULL)
1003 free(opts);
1004 if (dataset != NULL)
1005 free(dataset);
1006 free(command);
1008 return (ret);
1012 * add_resources(share, opt)
1014 * Add resource properties to those in "opt". Resources are prefixed
1015 * with name=resourcename.
1017 static char *
1018 add_resources(sa_share_t share, char *opt)
1020 char *newopt = NULL;
1021 char *propstr;
1022 sa_resource_t resource;
1024 newopt = strdup(opt);
1025 if (newopt == NULL)
1026 return (newopt);
1028 for (resource = sa_get_share_resource(share, NULL);
1029 resource != NULL;
1030 resource = sa_get_next_resource(resource)) {
1031 char *name;
1032 size_t size;
1034 name = sa_get_resource_attr(resource, "name");
1035 if (name == NULL) {
1036 free(newopt);
1037 return (NULL);
1039 size = strlen(name) + strlen(opt) + sizeof ("name=") + 1;
1040 newopt = calloc(1, size);
1041 if (newopt != NULL)
1042 (void) snprintf(newopt, size, "%s,name=%s", opt, name);
1043 sa_free_attr_string(name);
1044 free(opt);
1045 opt = newopt;
1046 propstr = sa_proto_legacy_format("smb", resource, 0);
1047 if (propstr == NULL) {
1048 free(opt);
1049 return (NULL);
1051 size = strlen(propstr) + strlen(opt) + 2;
1052 newopt = calloc(1, size);
1053 if (newopt != NULL)
1054 (void) snprintf(newopt, size, "%s,%s", opt, propstr);
1055 free(opt);
1056 opt = newopt;
1058 return (opt);
1062 * sa_zfs_set_sharesmb(group, path, on)
1064 * Update the "sharesmb" property on the path. If on is true, then set
1065 * to the properties on the group or "on" if no properties are
1066 * defined. Set to "off" if on is false.
1070 sa_zfs_set_sharesmb(sa_group_t group, char *path, int on)
1072 int ret = SA_NOT_IMPLEMENTED;
1073 char *command;
1074 sa_share_t share;
1076 /* In case SMB not enabled */
1077 if (sa_get_optionset(group, "smb") == NULL)
1078 return (SA_NOT_SUPPORTED);
1080 command = malloc(ZFS_MAXPROPLEN * 2);
1081 if (command != NULL) {
1082 char *opts = NULL;
1083 char *dataset = NULL;
1084 FILE *pfile;
1085 sa_handle_impl_t impl_handle;
1087 if (on) {
1088 char *newopt;
1090 share = sa_get_share(group, NULL);
1091 opts = sa_proto_legacy_format("smb", share, 1);
1092 if (opts != NULL && strlen(opts) == 0) {
1093 free(opts);
1094 opts = strdup("on");
1096 newopt = add_resources(opts, share);
1097 free(opts);
1098 opts = newopt;
1101 impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
1102 assert(impl_handle != NULL);
1103 if (impl_handle != NULL)
1104 dataset = get_zfs_dataset(impl_handle, path, B_FALSE);
1105 else
1106 ret = SA_SYSTEM_ERR;
1108 if (dataset != NULL) {
1109 (void) snprintf(command, ZFS_MAXPROPLEN * 2,
1110 "echo %s set sharesmb=\"%s\" %s", COMMAND,
1111 opts != NULL ? opts : "off", dataset);
1112 pfile = popen(command, "r");
1113 if (pfile != NULL) {
1114 ret = pclose(pfile);
1115 if (ret != 0)
1116 ret = SA_SYSTEM_ERR;
1119 if (opts != NULL)
1120 free(opts);
1121 if (dataset != NULL)
1122 free(dataset);
1123 free(command);
1125 return (ret);
1129 * sa_zfs_update(group)
1131 * call back to ZFS to update the share if necessary.
1132 * Don't do it if it isn't a real change.
1135 sa_zfs_update(sa_group_t group)
1137 sa_optionset_t protopt;
1138 sa_group_t parent;
1139 char *command;
1140 char *optstring;
1141 int ret = SA_OK;
1142 int doupdate = 0;
1143 FILE *pfile;
1145 if (sa_is_share(group))
1146 parent = sa_get_parent_group(group);
1147 else
1148 parent = group;
1150 if (parent != NULL) {
1151 command = malloc(ZFS_MAXPROPLEN * 2);
1152 if (command == NULL)
1153 return (SA_NO_MEMORY);
1155 *command = '\0';
1156 for (protopt = sa_get_optionset(parent, NULL); protopt != NULL;
1157 protopt = sa_get_next_optionset(protopt)) {
1159 char *proto = sa_get_optionset_attr(protopt, "type");
1160 char *path;
1161 char *dataset = NULL;
1162 char *zfsopts = NULL;
1164 if (sa_is_share(group)) {
1165 path = sa_get_share_attr((sa_share_t)group,
1166 "path");
1167 if (path != NULL) {
1168 sa_handle_impl_t impl_handle;
1170 impl_handle = sa_find_group_handle(
1171 group);
1172 if (impl_handle != NULL)
1173 dataset = get_zfs_dataset(
1174 impl_handle, path, B_FALSE);
1175 else
1176 ret = SA_SYSTEM_ERR;
1178 sa_free_attr_string(path);
1180 } else {
1181 dataset = sa_get_group_attr(group, "name");
1183 /* update only when there is an optstring found */
1184 doupdate = 0;
1185 if (proto != NULL && dataset != NULL) {
1186 optstring = sa_proto_legacy_format(proto,
1187 group, 1);
1188 zfsopts = get_zfs_property(dataset,
1189 ZFS_PROP_SHARENFS);
1191 if (optstring != NULL && zfsopts != NULL) {
1192 if (strcmp(optstring, zfsopts) != 0)
1193 doupdate++;
1195 if (doupdate) {
1196 if (optstring != NULL &&
1197 strlen(optstring) > 0) {
1198 (void) snprintf(command,
1199 ZFS_MAXPROPLEN * 2,
1200 "%s set share%s=%s %s",
1201 COMMAND, proto,
1202 optstring, dataset);
1203 } else {
1204 (void) snprintf(command,
1205 ZFS_MAXPROPLEN * 2,
1206 "%s set share%s=on %s",
1207 COMMAND, proto,
1208 dataset);
1210 pfile = popen(command, "r");
1211 if (pfile != NULL)
1212 ret = pclose(pfile);
1213 switch (ret) {
1214 default:
1215 case 1:
1216 ret = SA_SYSTEM_ERR;
1217 break;
1218 case 2:
1219 ret = SA_SYNTAX_ERR;
1220 break;
1221 case 0:
1222 break;
1225 if (optstring != NULL)
1226 free(optstring);
1227 if (zfsopts != NULL)
1228 free(zfsopts);
1230 if (proto != NULL)
1231 sa_free_attr_string(proto);
1232 if (dataset != NULL)
1233 free(dataset);
1235 free(command);
1237 return (ret);
1241 * sa_group_is_zfs(group)
1243 * Given the group, determine if the zfs attribute is set.
1247 sa_group_is_zfs(sa_group_t group)
1249 char *zfs;
1250 int ret = 0;
1252 zfs = sa_get_group_attr(group, "zfs");
1253 if (zfs != NULL) {
1254 ret = 1;
1255 sa_free_attr_string(zfs);
1257 return (ret);
1261 * sa_path_is_zfs(path)
1263 * Check to see if the file system path represents is of type "zfs".
1267 sa_path_is_zfs(char *path)
1269 char *fstype;
1270 int ret = 0;
1272 fstype = sa_fstype(path);
1273 if (fstype != NULL && strcmp(fstype, "zfs") == 0)
1274 ret = 1;
1275 if (fstype != NULL)
1276 sa_free_fstype(fstype);
1277 return (ret);
1281 sa_sharetab_fill_zfs(sa_share_t share, share_t *sh, char *proto)
1283 char *path;
1285 /* Make sure path is valid */
1287 path = sa_get_share_attr(share, "path");
1288 if (path != NULL) {
1289 (void) memset(sh, 0, sizeof (sh));
1290 (void) sa_fillshare(share, proto, sh);
1291 sa_free_attr_string(path);
1292 return (0);
1293 } else
1294 return (1);
1297 #define SMAX(i, j) \
1298 if ((j) > (i)) { \
1299 (i) = (j); \
1303 sa_share_zfs(sa_share_t share, sa_resource_t resource, char *path, share_t *sh,
1304 void *exportdata, zfs_share_op_t operation)
1306 libzfs_handle_t *libhandle;
1307 sa_group_t group;
1308 sa_handle_t sahandle;
1309 char *dataset;
1310 int err = EINVAL;
1311 int i, j;
1312 char newpath[MAXPATHLEN];
1313 char *pathp;
1316 * First find the dataset name
1318 if ((group = sa_get_parent_group(share)) == NULL) {
1319 return (EINVAL);
1321 if ((sahandle = sa_find_group_handle(group)) == NULL) {
1322 return (EINVAL);
1326 * If get_zfs_dataset fails, see if it is a subdirectory
1329 pathp = path;
1330 while ((dataset = get_zfs_dataset(sahandle, pathp, B_TRUE)) == NULL) {
1331 char *p;
1333 if (pathp == path) {
1334 (void) strlcpy(newpath, path, sizeof (newpath));
1335 pathp = newpath;
1339 * Make sure only one leading '/' This condition came
1340 * about when using HAStoragePlus which insisted on
1341 * putting an extra leading '/' in the ZFS path
1342 * name. The problem is fixed in other areas, but this
1343 * will catch any other ways that a double slash might
1344 * get introduced.
1346 while (*pathp == '/' && *(pathp + 1) == '/')
1347 pathp++;
1350 * chop off part of path, but if we are at root then
1351 * make sure path is a /
1353 if ((strlen(pathp) > 1) && (p = strrchr(pathp, '/'))) {
1354 if (pathp == p) {
1355 *(p + 1) = '\0'; /* skip over /, root case */
1356 } else {
1357 *p = '\0';
1359 } else {
1360 return (EINVAL);
1364 libhandle = libzfs_init();
1365 if (libhandle != NULL) {
1366 char *resource_name;
1368 i = (sh->sh_path ? strlen(sh->sh_path) : 0);
1369 sh->sh_size = i;
1371 j = (sh->sh_res ? strlen(sh->sh_res) : 0);
1372 sh->sh_size += j;
1373 SMAX(i, j);
1375 j = (sh->sh_fstype ? strlen(sh->sh_fstype) : 0);
1376 sh->sh_size += j;
1377 SMAX(i, j);
1379 j = (sh->sh_opts ? strlen(sh->sh_opts) : 0);
1380 sh->sh_size += j;
1381 SMAX(i, j);
1383 j = (sh->sh_descr ? strlen(sh->sh_descr) : 0);
1384 sh->sh_size += j;
1385 SMAX(i, j);
1387 resource_name = sa_get_resource_attr(resource, "name");
1389 err = zfs_deleg_share_nfs(libhandle, dataset, path,
1390 resource_name, exportdata, sh, i, operation);
1391 if (err == SA_OK)
1392 sa_update_sharetab_ts(sahandle);
1393 else
1394 err = errno;
1395 if (resource_name)
1396 sa_free_attr_string(resource_name);
1398 libzfs_fini(libhandle);
1400 free(dataset);
1401 return (err);
1405 * sa_get_zfs_handle(handle)
1407 * Given an sa_handle_t, return the libzfs_handle_t *. This is only
1408 * used internally by libzfs. Needed in order to avoid including
1409 * libshare_impl.h in libzfs.
1412 libzfs_handle_t *
1413 sa_get_zfs_handle(sa_handle_t handle)
1415 sa_handle_impl_t implhandle = (sa_handle_impl_t)handle;
1417 return (implhandle->zfs_libhandle);
1421 * sa_get_zfs_info(libzfs, path, mountpoint, dataset)
1423 * Find the ZFS dataset and mountpoint for a given path
1426 sa_zfs_get_info(libzfs_handle_t *libzfs, char *path, char *mountpointp,
1427 char *datasetp)
1429 get_all_cbdata_t cb = { 0 };
1430 int i;
1431 char mountpoint[ZFS_MAXPROPLEN];
1432 char dataset[ZFS_MAXPROPLEN];
1433 char canmount[ZFS_MAXPROPLEN];
1434 char *dp;
1435 int count;
1436 int ret = 0;
1438 cb.cb_types = ZFS_TYPE_FILESYSTEM;
1440 if (libzfs == NULL)
1441 return (0);
1443 (void) zfs_iter_root(libzfs, get_one_filesystem, &cb);
1444 count = cb.cb_used;
1446 qsort(cb.cb_handles, count, sizeof (void *), mountpoint_compare);
1447 for (i = 0; i < count; i++) {
1448 /* must have a mountpoint */
1449 if (zfs_prop_get(cb.cb_handles[i], ZFS_PROP_MOUNTPOINT,
1450 mountpoint, sizeof (mountpoint),
1451 NULL, NULL, 0, B_FALSE) != 0) {
1452 /* no mountpoint */
1453 continue;
1456 /* mountpoint must be a path */
1457 if (strcmp(mountpoint, ZFS_MOUNTPOINT_NONE) == 0 ||
1458 strcmp(mountpoint, ZFS_MOUNTPOINT_LEGACY) == 0) {
1460 * Search mmttab for mountpoint
1463 if (get_legacy_mountpoint(path, dataset,
1464 ZFS_MAXPROPLEN, mountpoint,
1465 ZFS_MAXPROPLEN) == 0) {
1466 ret = 1;
1467 break;
1469 continue;
1472 /* canmount must be set */
1473 canmount[0] = '\0';
1474 if (zfs_prop_get(cb.cb_handles[i], ZFS_PROP_CANMOUNT, canmount,
1475 sizeof (canmount), NULL, NULL, 0, B_FALSE) != 0 ||
1476 strcmp(canmount, "off") == 0)
1477 continue;
1480 * have a mountable handle but want to skip those marked none
1481 * and legacy
1483 if (strcmp(mountpoint, path) == 0) {
1484 dp = (char *)zfs_get_name(cb.cb_handles[i]);
1485 if (dp != NULL) {
1486 if (datasetp != NULL)
1487 (void) strcpy(datasetp, dp);
1488 if (mountpointp != NULL)
1489 (void) strcpy(mountpointp, mountpoint);
1490 ret = 1;
1492 break;
1497 return (ret);
1501 * This method builds values for "sharesmb" property from the
1502 * nvlist argument. The values are returned in sharesmb_val variable.
1504 static int
1505 sa_zfs_sprintf_new_prop(nvlist_t *nvl, char *sharesmb_val)
1507 char cur_val[MAXPATHLEN];
1508 char *name, *val;
1509 nvpair_t *cur;
1510 int err = 0;
1512 cur = nvlist_next_nvpair(nvl, NULL);
1513 while (cur != NULL) {
1514 name = nvpair_name(cur);
1515 err = nvpair_value_string(cur, &val);
1516 if ((err != 0) || (name == NULL) || (val == NULL))
1517 return (-1);
1519 (void) snprintf(cur_val, MAXPATHLEN, "%s=%s,", name, val);
1520 (void) strlcat(sharesmb_val, cur_val, MAXPATHLEN);
1522 cur = nvlist_next_nvpair(nvl, cur);
1525 return (0);
1529 * This method builds values for "sharesmb" property from values
1530 * already existing on the share. The properties set via sa_zfs_sprint_new_prop
1531 * method are passed in sharesmb_val. If a existing property is already
1532 * set via sa_zfs_sprint_new_prop method, then they are not appended
1533 * to the sharesmb_val string. The returned sharesmb_val string is a combination
1534 * of new and existing values for 'sharesmb' property.
1536 static int
1537 sa_zfs_sprintf_existing_prop(zfs_handle_t *handle, char *sharesmb_val)
1539 char shareopts[ZFS_MAXPROPLEN], cur_val[MAXPATHLEN];
1540 char *token, *last, *value;
1542 if (zfs_prop_get(handle, ZFS_PROP_SHARESMB, shareopts,
1543 sizeof (shareopts), NULL, NULL, 0, B_FALSE) != 0)
1544 return (-1);
1546 if (strstr(shareopts, "=") == NULL)
1547 return (0);
1549 for (token = strtok_r(shareopts, ",", &last); token != NULL;
1550 token = strtok_r(NULL, ",", &last)) {
1551 value = strchr(token, '=');
1552 if (value == NULL)
1553 return (-1);
1554 *value++ = '\0';
1556 (void) snprintf(cur_val, MAXPATHLEN, "%s=", token);
1557 if (strstr(sharesmb_val, cur_val) == NULL) {
1558 (void) strlcat(cur_val, value, MAXPATHLEN);
1559 (void) strlcat(cur_val, ",", MAXPATHLEN);
1560 (void) strlcat(sharesmb_val, cur_val, MAXPATHLEN);
1564 return (0);
1568 * Sets the share properties on a ZFS share. For now, this method sets only
1569 * the "sharesmb" property.
1571 * This method includes building a comma seperated name-value string to be
1572 * set on the "sharesmb" property of a ZFS share. This name-value string is
1573 * build in 2 steps:
1574 * - New property values given as name-value pair are set first.
1575 * - Existing optionset properties, which are not part of the new properties
1576 * passed in step 1, are appended to the newly set properties.
1579 sa_zfs_setprop(sa_handle_t handle, char *path, nvlist_t *nvl)
1581 zfs_handle_t *z_fs;
1582 libzfs_handle_t *z_lib;
1583 char sharesmb_val[MAXPATHLEN];
1584 char *dataset, *lastcomma;
1586 if (nvlist_empty(nvl))
1587 return (0);
1589 if ((handle == NULL) || (path == NULL))
1590 return (-1);
1592 if ((dataset = get_zfs_dataset(handle, path, B_FALSE)) == NULL)
1593 return (-1);
1595 if ((z_lib = libzfs_init()) == NULL) {
1596 free(dataset);
1597 return (-1);
1600 z_fs = zfs_open(z_lib, dataset, ZFS_TYPE_DATASET);
1601 if (z_fs == NULL) {
1602 free(dataset);
1603 libzfs_fini(z_lib);
1604 return (-1);
1607 bzero(sharesmb_val, MAXPATHLEN);
1608 if (sa_zfs_sprintf_new_prop(nvl, sharesmb_val) != 0) {
1609 free(dataset);
1610 zfs_close(z_fs);
1611 libzfs_fini(z_lib);
1612 return (-1);
1615 if (sa_zfs_sprintf_existing_prop(z_fs, sharesmb_val) != 0) {
1616 free(dataset);
1617 zfs_close(z_fs);
1618 libzfs_fini(z_lib);
1619 return (-1);
1622 lastcomma = strrchr(sharesmb_val, ',');
1623 if ((lastcomma != NULL) && (lastcomma[1] == '\0'))
1624 *lastcomma = '\0';
1626 (void) zfs_prop_set(z_fs, zfs_prop_to_name(ZFS_PROP_SHARESMB),
1627 sharesmb_val);
1628 free(dataset);
1629 zfs_close(z_fs);
1630 libzfs_fini(z_lib);
1632 return (0);