Print this page
4095 minor cleanup up libshare
*** 19,31 ****
* CDDL HEADER END
*/
/*
* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
- */
- /*
* Copyright 2012 Nexenta Systems, Inc. All rights reserved.
*/
#include <stdio.h>
#include <libzfs.h>
#include <string.h>
--- 19,30 ----
* CDDL HEADER END
*/
/*
* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2012 Nexenta Systems, Inc. All rights reserved.
+ * Copyright (c) 2013 RackTop Systems.
*/
#include <stdio.h>
#include <libzfs.h>
#include <string.h>
*** 39,49 ****
extern sa_share_t _sa_add_share(sa_group_t, char *, int, int *, uint64_t);
extern sa_group_t _sa_create_zfs_group(sa_group_t, char *);
extern char *sa_fstype(char *);
extern void set_node_attr(void *, char *, char *);
! extern int sa_is_share(void *);
extern void sa_update_sharetab_ts(sa_handle_t);
/*
* File system specific code for ZFS. The original code was stolen
* from the "zfs" command and modified to better suit this library's
--- 38,48 ----
extern sa_share_t _sa_add_share(sa_group_t, char *, int, int *, uint64_t);
extern sa_group_t _sa_create_zfs_group(sa_group_t, char *);
extern char *sa_fstype(char *);
extern void set_node_attr(void *, char *, char *);
! extern boolean_t sa_is_share(void *);
extern void sa_update_sharetab_ts(sa_handle_t);
/*
* File system specific code for ZFS. The original code was stolen
* from the "zfs" command and modified to better suit this library's
*** 56,112 ****
size_t cb_used;
uint_t cb_types;
} get_all_cbdata_t;
/*
! * sa_zfs_init(impl_handle)
*
* Initialize an access handle into libzfs. The handle needs to stay
* around until sa_zfs_fini() in order to maintain the cache of
* mounts.
*/
int
! sa_zfs_init(sa_handle_impl_t impl_handle)
{
! impl_handle->zfs_libhandle = libzfs_init();
! if (impl_handle->zfs_libhandle != NULL) {
! libzfs_print_on_error(impl_handle->zfs_libhandle, B_TRUE);
return (B_TRUE);
}
return (B_FALSE);
}
/*
! * sa_zfs_fini(impl_handle)
*
* cleanup data structures and the libzfs handle used for accessing
* zfs file share info.
*/
void
! sa_zfs_fini(sa_handle_impl_t impl_handle)
{
! if (impl_handle->zfs_libhandle != NULL) {
! if (impl_handle->zfs_list != NULL) {
! zfs_handle_t **zhp = impl_handle->zfs_list;
size_t i;
/*
* Contents of zfs_list need to be freed so we
* don't lose ZFS handles.
*/
! for (i = 0; i < impl_handle->zfs_list_count; i++) {
zfs_close(zhp[i]);
}
! free(impl_handle->zfs_list);
! impl_handle->zfs_list = NULL;
! impl_handle->zfs_list_count = 0;
}
! libzfs_fini(impl_handle->zfs_libhandle);
! impl_handle->zfs_libhandle = NULL;
}
}
/*
* get_one_filesystem(zfs_handle_t, data)
--- 55,111 ----
size_t cb_used;
uint_t cb_types;
} get_all_cbdata_t;
/*
! * sa_zfs_init(handle)
*
* Initialize an access handle into libzfs. The handle needs to stay
* around until sa_zfs_fini() in order to maintain the cache of
* mounts.
*/
int
! sa_zfs_init(sa_handle_t handle)
{
! handle->zfs_libhandle = libzfs_init();
! if (handle->zfs_libhandle != NULL) {
! libzfs_print_on_error(handle->zfs_libhandle, B_TRUE);
return (B_TRUE);
}
return (B_FALSE);
}
/*
! * sa_zfs_fini(handle)
*
* cleanup data structures and the libzfs handle used for accessing
* zfs file share info.
*/
void
! sa_zfs_fini(sa_handle_t handle)
{
! if (handle->zfs_libhandle != NULL) {
! if (handle->zfs_list != NULL) {
! zfs_handle_t **zhp = handle->zfs_list;
size_t i;
/*
* Contents of zfs_list need to be freed so we
* don't lose ZFS handles.
*/
! for (i = 0; i < handle->zfs_list_count; i++) {
zfs_close(zhp[i]);
}
! free(handle->zfs_list);
! handle->zfs_list = NULL;
! handle->zfs_list_count = 0;
}
! libzfs_fini(handle->zfs_libhandle);
! handle->zfs_libhandle = NULL;
}
}
/*
* get_one_filesystem(zfs_handle_t, data)
*** 181,207 ****
* once. The caller does not need to free since it will be done at
* sa_zfs_fini() time.
*/
static void
! get_all_filesystems(sa_handle_impl_t impl_handle,
zfs_handle_t ***fslist, size_t *count)
{
get_all_cbdata_t cb = { 0 };
cb.cb_types = ZFS_TYPE_FILESYSTEM;
! if (impl_handle->zfs_list != NULL) {
! *fslist = impl_handle->zfs_list;
! *count = impl_handle->zfs_list_count;
return;
}
! (void) zfs_iter_root(impl_handle->zfs_libhandle,
get_one_filesystem, &cb);
! impl_handle->zfs_list = *fslist = cb.cb_handles;
! impl_handle->zfs_list_count = *count = cb.cb_used;
}
/*
* mountpoint_compare(a, b)
*
--- 180,206 ----
* once. The caller does not need to free since it will be done at
* sa_zfs_fini() time.
*/
static void
! get_all_filesystems(sa_handle_t handle,
zfs_handle_t ***fslist, size_t *count)
{
get_all_cbdata_t cb = { 0 };
cb.cb_types = ZFS_TYPE_FILESYSTEM;
! if (handle->zfs_list != NULL) {
! *fslist = handle->zfs_list;
! *count = handle->zfs_list_count;
return;
}
! (void) zfs_iter_root(handle->zfs_libhandle,
get_one_filesystem, &cb);
! handle->zfs_list = *fslist = cb.cb_handles;
! handle->zfs_list_count = *count = cb.cb_used;
}
/*
* mountpoint_compare(a, b)
*
*** 259,286 ****
(void) fclose(fp);
return (1);
}
/*
! * get_zfs_dataset(impl_handle, path)
*
* get the name of the ZFS dataset the path is equivalent to. The
* dataset name is used for get/set of ZFS properties since libzfs
* requires a dataset to do a zfs_open().
*/
static char *
! get_zfs_dataset(sa_handle_impl_t impl_handle, char *path,
boolean_t search_mnttab)
{
size_t i, count = 0;
char *dataset = NULL;
zfs_handle_t **zlist;
char mountpoint[ZFS_MAXPROPLEN];
char canmount[ZFS_MAXPROPLEN];
! get_all_filesystems(impl_handle, &zlist, &count);
qsort(zlist, count, sizeof (void *), mountpoint_compare);
for (i = 0; i < count; i++) {
/* must have a mountpoint */
if (zfs_prop_get(zlist[i], ZFS_PROP_MOUNTPOINT, mountpoint,
sizeof (mountpoint), NULL, NULL, 0, B_FALSE) != 0) {
--- 258,285 ----
(void) fclose(fp);
return (1);
}
/*
! * get_zfs_dataset(handle, path)
*
* get the name of the ZFS dataset the path is equivalent to. The
* dataset name is used for get/set of ZFS properties since libzfs
* requires a dataset to do a zfs_open().
*/
static char *
! get_zfs_dataset(sa_handle_t handle, char *path,
boolean_t search_mnttab)
{
size_t i, count = 0;
char *dataset = NULL;
zfs_handle_t **zlist;
char mountpoint[ZFS_MAXPROPLEN];
char canmount[ZFS_MAXPROPLEN];
! get_all_filesystems(handle, &zlist, &count);
qsort(zlist, count, sizeof (void *), mountpoint_compare);
for (i = 0; i < count; i++) {
/* must have a mountpoint */
if (zfs_prop_get(zlist[i], ZFS_PROP_MOUNTPOINT, mountpoint,
sizeof (mountpoint), NULL, NULL, 0, B_FALSE) != 0) {
*** 333,362 ****
*
* Get the file system property specified from the ZFS dataset.
*/
static char *
! get_zfs_property(char *dataset, zfs_prop_t property)
{
! zfs_handle_t *handle = NULL;
char shareopts[ZFS_MAXPROPLEN];
- libzfs_handle_t *libhandle;
! libhandle = libzfs_init();
! if (libhandle != NULL) {
! handle = zfs_open(libhandle, dataset, ZFS_TYPE_FILESYSTEM);
! if (handle != NULL) {
! if (zfs_prop_get(handle, property, shareopts,
sizeof (shareopts), NULL, NULL, 0,
B_FALSE) == 0) {
! zfs_close(handle);
! libzfs_fini(libhandle);
return (strdup(shareopts));
}
! zfs_close(handle);
! }
! libzfs_fini(libhandle);
}
return (NULL);
}
/*
--- 332,355 ----
*
* Get the file system property specified from the ZFS dataset.
*/
static char *
! get_zfs_property(sa_handle_t handle, char *dataset, zfs_prop_t property)
{
! zfs_handle_t *z_fs;
char shareopts[ZFS_MAXPROPLEN];
! z_fs = zfs_open(handle->zfs_libhandle, dataset, ZFS_TYPE_FILESYSTEM);
! if (z_fs != NULL) {
! if (zfs_prop_get(z_fs, property, shareopts,
sizeof (shareopts), NULL, NULL, 0,
B_FALSE) == 0) {
! zfs_close(z_fs);
return (strdup(shareopts));
}
! zfs_close(z_fs);
}
return (NULL);
}
/*
*** 364,398 ****
*
* Check to see if the ZFS path provided has the sharenfs option set
* or not.
*/
! int
! sa_zfs_is_shared(sa_handle_t sahandle, char *path)
{
! int ret = 0;
char *dataset;
! zfs_handle_t *handle = NULL;
char shareopts[ZFS_MAXPROPLEN];
- libzfs_handle_t *libhandle;
! dataset = get_zfs_dataset((sa_handle_t)sahandle, path, B_FALSE);
if (dataset != NULL) {
! libhandle = libzfs_init();
! if (libhandle != NULL) {
! handle = zfs_open(libhandle, dataset,
ZFS_TYPE_FILESYSTEM);
! if (handle != NULL) {
! if (zfs_prop_get(handle, ZFS_PROP_SHARENFS,
shareopts, sizeof (shareopts), NULL, NULL,
0, B_FALSE) == 0 &&
strcmp(shareopts, "off") != 0) {
! ret = 1; /* it is shared */
}
! zfs_close(handle);
! }
! libzfs_fini(libhandle);
}
free(dataset);
}
return (ret);
}
--- 357,386 ----
*
* Check to see if the ZFS path provided has the sharenfs option set
* or not.
*/
! boolean_t
! sa_zfs_is_shared(sa_handle_t handle, char *path)
{
! int ret = B_FALSE;
char *dataset;
! zfs_handle_t *z_fs = NULL;
char shareopts[ZFS_MAXPROPLEN];
! dataset = get_zfs_dataset(handle, path, B_FALSE);
if (dataset != NULL) {
! z_fs = zfs_open(handle->zfs_libhandle, dataset,
ZFS_TYPE_FILESYSTEM);
! if (z_fs != NULL) {
! if (zfs_prop_get(z_fs, ZFS_PROP_SHARENFS,
shareopts, sizeof (shareopts), NULL, NULL,
0, B_FALSE) == 0 &&
strcmp(shareopts, "off") != 0) {
! ret = B_TRUE; /* it is shared */
}
! zfs_close(z_fs);
}
free(dataset);
}
return (ret);
}
*** 761,771 ****
int err = SA_OK;
/*
* If we can't access libzfs, don't bother doing anything.
*/
! zfs_libhandle = ((sa_handle_impl_t)handle)->zfs_libhandle;
if (zfs_libhandle == NULL)
return (SA_SYSTEM_ERR);
zfsgroup = find_or_create_group(handle, groupname, NULL, &err);
/* Not an error, this could be a legacy condition */
--- 749,759 ----
int err = SA_OK;
/*
* If we can't access libzfs, don't bother doing anything.
*/
! zfs_libhandle = handle->zfs_libhandle;
if (zfs_libhandle == NULL)
return (SA_SYSTEM_ERR);
zfsgroup = find_or_create_group(handle, groupname, NULL, &err);
/* Not an error, this could be a legacy condition */
*** 774,784 ****
/*
* need to walk the mounted ZFS pools and datasets to
* find shares that are possible.
*/
! get_all_filesystems((sa_handle_impl_t)handle, &zlist, &count);
qsort(zlist, count, sizeof (void *), mountpoint_compare);
for (i = 0; i < count; i++) {
char *dataset;
--- 762,772 ----
/*
* need to walk the mounted ZFS pools and datasets to
* find shares that are possible.
*/
! get_all_filesystems(handle, &zlist, &count);
qsort(zlist, count, sizeof (void *), mountpoint_compare);
for (i = 0; i < count; i++) {
char *dataset;
*** 930,953 ****
command = malloc(ZFS_MAXPROPLEN * 2);
if (command != NULL) {
char *opts = NULL;
char *dataset = NULL;
FILE *pfile;
! sa_handle_impl_t impl_handle;
/* for now, NFS is always available for "zfs" */
if (on) {
opts = sa_proto_legacy_format("nfs", group, 1);
if (opts != NULL && strlen(opts) == 0) {
free(opts);
opts = strdup("on");
}
}
! impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
! assert(impl_handle != NULL);
! if (impl_handle != NULL)
! dataset = get_zfs_dataset(impl_handle, path, B_FALSE);
else
ret = SA_SYSTEM_ERR;
if (dataset != NULL) {
(void) snprintf(command, ZFS_MAXPROPLEN * 2,
--- 918,941 ----
command = malloc(ZFS_MAXPROPLEN * 2);
if (command != NULL) {
char *opts = NULL;
char *dataset = NULL;
FILE *pfile;
! sa_handle_t handle;
/* for now, NFS is always available for "zfs" */
if (on) {
opts = sa_proto_legacy_format("nfs", group, 1);
if (opts != NULL && strlen(opts) == 0) {
free(opts);
opts = strdup("on");
}
}
! handle = sa_find_group_handle(group);
! assert(handle != NULL);
! if (handle != NULL)
! dataset = get_zfs_dataset(handle, path, B_FALSE);
else
ret = SA_SYSTEM_ERR;
if (dataset != NULL) {
(void) snprintf(command, ZFS_MAXPROPLEN * 2,
*** 1041,1051 ****
command = malloc(ZFS_MAXPROPLEN * 2);
if (command != NULL) {
char *opts = NULL;
char *dataset = NULL;
FILE *pfile;
! sa_handle_impl_t impl_handle;
if (on) {
char *newopt;
share = sa_get_share(group, NULL);
--- 1029,1039 ----
command = malloc(ZFS_MAXPROPLEN * 2);
if (command != NULL) {
char *opts = NULL;
char *dataset = NULL;
FILE *pfile;
! sa_handle_t handle;
if (on) {
char *newopt;
share = sa_get_share(group, NULL);
*** 1057,1070 ****
newopt = add_resources(opts, share);
free(opts);
opts = newopt;
}
! impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
! assert(impl_handle != NULL);
! if (impl_handle != NULL)
! dataset = get_zfs_dataset(impl_handle, path, B_FALSE);
else
ret = SA_SYSTEM_ERR;
if (dataset != NULL) {
(void) snprintf(command, ZFS_MAXPROPLEN * 2,
--- 1045,1058 ----
newopt = add_resources(opts, share);
free(opts);
opts = newopt;
}
! handle = sa_find_group_handle(group);
! assert(handle != NULL);
! if (handle != NULL)
! dataset = get_zfs_dataset(handle, path, B_FALSE);
else
ret = SA_SYSTEM_ERR;
if (dataset != NULL) {
(void) snprintf(command, ZFS_MAXPROPLEN * 2,
*** 1124,1140 ****
if (sa_is_share(group)) {
path = sa_get_share_attr((sa_share_t)group,
"path");
if (path != NULL) {
! sa_handle_impl_t impl_handle;
! impl_handle = sa_find_group_handle(
group);
! if (impl_handle != NULL)
dataset = get_zfs_dataset(
! impl_handle, path, B_FALSE);
else
ret = SA_SYSTEM_ERR;
sa_free_attr_string(path);
}
--- 1112,1128 ----
if (sa_is_share(group)) {
path = sa_get_share_attr((sa_share_t)group,
"path");
if (path != NULL) {
! sa_handle_t handle;
! handle = sa_find_group_handle(
group);
! if (handle != NULL)
dataset = get_zfs_dataset(
! handle, path, B_FALSE);
else
ret = SA_SYSTEM_ERR;
sa_free_attr_string(path);
}
*** 1142,1154 ****
dataset = sa_get_group_attr(group, "name");
}
/* update only when there is an optstring found */
doupdate = 0;
if (proto != NULL && dataset != NULL) {
optstring = sa_proto_legacy_format(proto,
group, 1);
! zfsopts = get_zfs_property(dataset,
ZFS_PROP_SHARENFS);
if (optstring != NULL && zfsopts != NULL) {
if (strcmp(optstring, zfsopts) != 0)
doupdate++;
--- 1130,1145 ----
dataset = sa_get_group_attr(group, "name");
}
/* update only when there is an optstring found */
doupdate = 0;
if (proto != NULL && dataset != NULL) {
+ sa_handle_t handle;
+
optstring = sa_proto_legacy_format(proto,
group, 1);
! handle = sa_find_group_handle(group);
! zfsopts = get_zfs_property(handle, dataset,
ZFS_PROP_SHARENFS);
if (optstring != NULL && zfsopts != NULL) {
if (strcmp(optstring, zfsopts) != 0)
doupdate++;
*** 1202,1220 ****
* sa_group_is_zfs(group)
*
* Given the group, determine if the zfs attribute is set.
*/
! int
sa_group_is_zfs(sa_group_t group)
{
char *zfs;
! int ret = 0;
zfs = sa_get_group_attr(group, "zfs");
if (zfs != NULL) {
! ret = 1;
sa_free_attr_string(zfs);
}
return (ret);
}
--- 1193,1211 ----
* sa_group_is_zfs(group)
*
* Given the group, determine if the zfs attribute is set.
*/
! boolean_t
sa_group_is_zfs(sa_group_t group)
{
char *zfs;
! int ret = B_FALSE;
zfs = sa_get_group_attr(group, "zfs");
if (zfs != NULL) {
! ret = B_TRUE;
sa_free_attr_string(zfs);
}
return (ret);
}
*** 1222,1240 ****
* sa_path_is_zfs(path)
*
* Check to see if the file system path represents is of type "zfs".
*/
! int
sa_path_is_zfs(char *path)
{
char *fstype;
! int ret = 0;
fstype = sa_fstype(path);
if (fstype != NULL && strcmp(fstype, "zfs") == 0)
! ret = 1;
if (fstype != NULL)
sa_free_fstype(fstype);
return (ret);
}
--- 1213,1231 ----
* sa_path_is_zfs(path)
*
* Check to see if the file system path represents is of type "zfs".
*/
! boolean_t
sa_path_is_zfs(char *path)
{
char *fstype;
! int ret = B_FALSE;
fstype = sa_fstype(path);
if (fstype != NULL && strcmp(fstype, "zfs") == 0)
! ret = B_TRUE;
if (fstype != NULL)
sa_free_fstype(fstype);
return (ret);
}
*** 1262,1296 ****
int
sa_share_zfs(sa_share_t share, sa_resource_t resource, char *path, share_t *sh,
void *exportdata, zfs_share_op_t operation)
{
- libzfs_handle_t *libhandle;
sa_group_t group;
! sa_handle_t sahandle;
char *dataset;
int err = EINVAL;
int i, j;
char newpath[MAXPATHLEN];
char *pathp;
/*
* First find the dataset name
*/
if ((group = sa_get_parent_group(share)) == NULL) {
return (EINVAL);
}
! if ((sahandle = sa_find_group_handle(group)) == NULL) {
return (EINVAL);
}
/*
* If get_zfs_dataset fails, see if it is a subdirectory
*/
pathp = path;
! while ((dataset = get_zfs_dataset(sahandle, pathp, B_TRUE)) == NULL) {
char *p;
if (pathp == path) {
(void) strlcpy(newpath, path, sizeof (newpath));
pathp = newpath;
--- 1253,1287 ----
int
sa_share_zfs(sa_share_t share, sa_resource_t resource, char *path, share_t *sh,
void *exportdata, zfs_share_op_t operation)
{
sa_group_t group;
! sa_handle_t handle;
char *dataset;
int err = EINVAL;
int i, j;
char newpath[MAXPATHLEN];
char *pathp;
+ char *resource_name;
/*
* First find the dataset name
*/
if ((group = sa_get_parent_group(share)) == NULL) {
return (EINVAL);
}
! if ((handle = sa_find_group_handle(group)) == NULL) {
return (EINVAL);
}
/*
* If get_zfs_dataset fails, see if it is a subdirectory
*/
pathp = path;
! while ((dataset = get_zfs_dataset(handle, pathp, B_TRUE)) == NULL) {
char *p;
if (pathp == path) {
(void) strlcpy(newpath, path, sizeof (newpath));
pathp = newpath;
*** 1320,1333 ****
} else {
return (EINVAL);
}
}
- libhandle = libzfs_init();
- if (libhandle != NULL) {
- char *resource_name;
-
i = (sh->sh_path ? strlen(sh->sh_path) : 0);
sh->sh_size = i;
j = (sh->sh_res ? strlen(sh->sh_res) : 0);
sh->sh_size += j;
--- 1311,1320 ----
*** 1345,1365 ****
sh->sh_size += j;
SMAX(i, j);
resource_name = sa_get_resource_attr(resource, "name");
! err = zfs_deleg_share_nfs(libhandle, dataset, path,
resource_name, exportdata, sh, i, operation);
if (err == SA_OK)
! sa_update_sharetab_ts(sahandle);
else
err = errno;
! if (resource_name)
sa_free_attr_string(resource_name);
- libzfs_fini(libhandle);
- }
free(dataset);
return (err);
}
/*
--- 1332,1350 ----
sh->sh_size += j;
SMAX(i, j);
resource_name = sa_get_resource_attr(resource, "name");
! err = zfs_deleg_share_nfs(handle->zfs_libhandle, dataset, path,
resource_name, exportdata, sh, i, operation);
if (err == SA_OK)
! sa_update_sharetab_ts(handle);
else
err = errno;
! if (resource_name != NULL)
sa_free_attr_string(resource_name);
free(dataset);
return (err);
}
/*
*** 1371,1473 ****
*/
libzfs_handle_t *
sa_get_zfs_handle(sa_handle_t handle)
{
! sa_handle_impl_t implhandle = (sa_handle_impl_t)handle;
!
! return (implhandle->zfs_libhandle);
! }
!
! /*
! * sa_get_zfs_info(libzfs, path, mountpoint, dataset)
! *
! * Find the ZFS dataset and mountpoint for a given path
! */
! int
! sa_zfs_get_info(libzfs_handle_t *libzfs, char *path, char *mountpointp,
! char *datasetp)
! {
! get_all_cbdata_t cb = { 0 };
! int i;
! char mountpoint[ZFS_MAXPROPLEN];
! char dataset[ZFS_MAXPROPLEN];
! char canmount[ZFS_MAXPROPLEN];
! char *dp;
! int count;
! int ret = 0;
!
! cb.cb_types = ZFS_TYPE_FILESYSTEM;
!
! if (libzfs == NULL)
! return (0);
!
! (void) zfs_iter_root(libzfs, get_one_filesystem, &cb);
! count = cb.cb_used;
!
! qsort(cb.cb_handles, count, sizeof (void *), mountpoint_compare);
! for (i = 0; i < count; i++) {
! /* must have a mountpoint */
! if (zfs_prop_get(cb.cb_handles[i], ZFS_PROP_MOUNTPOINT,
! mountpoint, sizeof (mountpoint),
! NULL, NULL, 0, B_FALSE) != 0) {
! /* no mountpoint */
! continue;
! }
!
! /* mountpoint must be a path */
! if (strcmp(mountpoint, ZFS_MOUNTPOINT_NONE) == 0 ||
! strcmp(mountpoint, ZFS_MOUNTPOINT_LEGACY) == 0) {
! /*
! * Search mmttab for mountpoint
! */
!
! if (get_legacy_mountpoint(path, dataset,
! ZFS_MAXPROPLEN, mountpoint,
! ZFS_MAXPROPLEN) == 0) {
! ret = 1;
! break;
! }
! continue;
! }
!
! /* canmount must be set */
! canmount[0] = '\0';
! if (zfs_prop_get(cb.cb_handles[i], ZFS_PROP_CANMOUNT, canmount,
! sizeof (canmount), NULL, NULL, 0, B_FALSE) != 0 ||
! strcmp(canmount, "off") == 0)
! continue;
!
! /*
! * have a mountable handle but want to skip those marked none
! * and legacy
! */
! if (strcmp(mountpoint, path) == 0) {
! dp = (char *)zfs_get_name(cb.cb_handles[i]);
! if (dp != NULL) {
! if (datasetp != NULL)
! (void) strcpy(datasetp, dp);
! if (mountpointp != NULL)
! (void) strcpy(mountpointp, mountpoint);
! ret = 1;
! }
! break;
! }
!
! }
!
! return (ret);
}
/*
* This method builds values for "sharesmb" property from the
* nvlist argument. The values are returned in sharesmb_val variable.
*/
static int
sa_zfs_sprintf_new_prop(nvlist_t *nvl, char *sharesmb_val)
{
! char cur_val[MAXPATHLEN];
char *name, *val;
nvpair_t *cur;
int err = 0;
cur = nvlist_next_nvpair(nvl, NULL);
--- 1356,1376 ----
*/
libzfs_handle_t *
sa_get_zfs_handle(sa_handle_t handle)
{
! return (handle->zfs_libhandle);
}
/*
* This method builds values for "sharesmb" property from the
* nvlist argument. The values are returned in sharesmb_val variable.
*/
static int
sa_zfs_sprintf_new_prop(nvlist_t *nvl, char *sharesmb_val)
{
! char cur_val[ZFS_MAXPROPLEN];
char *name, *val;
nvpair_t *cur;
int err = 0;
cur = nvlist_next_nvpair(nvl, NULL);
*** 1475,1486 ****
name = nvpair_name(cur);
err = nvpair_value_string(cur, &val);
if ((err != 0) || (name == NULL) || (val == NULL))
return (-1);
! (void) snprintf(cur_val, MAXPATHLEN, "%s=%s,", name, val);
! (void) strlcat(sharesmb_val, cur_val, MAXPATHLEN);
cur = nvlist_next_nvpair(nvl, cur);
}
return (0);
--- 1378,1389 ----
name = nvpair_name(cur);
err = nvpair_value_string(cur, &val);
if ((err != 0) || (name == NULL) || (val == NULL))
return (-1);
! (void) snprintf(cur_val, ZFS_MAXPROPLEN, "%s=%s,", name, val);
! (void) strlcat(sharesmb_val, cur_val, ZFS_MAXPROPLEN);
cur = nvlist_next_nvpair(nvl, cur);
}
return (0);
*** 1495,1505 ****
* of new and existing values for 'sharesmb' property.
*/
static int
sa_zfs_sprintf_existing_prop(zfs_handle_t *handle, char *sharesmb_val)
{
! char shareopts[ZFS_MAXPROPLEN], cur_val[MAXPATHLEN];
char *token, *last, *value;
if (zfs_prop_get(handle, ZFS_PROP_SHARESMB, shareopts,
sizeof (shareopts), NULL, NULL, 0, B_FALSE) != 0)
return (-1);
--- 1398,1408 ----
* of new and existing values for 'sharesmb' property.
*/
static int
sa_zfs_sprintf_existing_prop(zfs_handle_t *handle, char *sharesmb_val)
{
! char shareopts[ZFS_MAXPROPLEN], cur_val[ZFS_MAXPROPLEN];
char *token, *last, *value;
if (zfs_prop_get(handle, ZFS_PROP_SHARESMB, shareopts,
sizeof (shareopts), NULL, NULL, 0, B_FALSE) != 0)
return (-1);
*** 1512,1526 ****
value = strchr(token, '=');
if (value == NULL)
return (-1);
*value++ = '\0';
! (void) snprintf(cur_val, MAXPATHLEN, "%s=", token);
if (strstr(sharesmb_val, cur_val) == NULL) {
! (void) strlcat(cur_val, value, MAXPATHLEN);
! (void) strlcat(cur_val, ",", MAXPATHLEN);
! (void) strlcat(sharesmb_val, cur_val, MAXPATHLEN);
}
}
return (0);
}
--- 1415,1429 ----
value = strchr(token, '=');
if (value == NULL)
return (-1);
*value++ = '\0';
! (void) snprintf(cur_val, ZFS_MAXPROPLEN, "%s=", token);
if (strstr(sharesmb_val, cur_val) == NULL) {
! (void) strlcat(cur_val, value, ZFS_MAXPROPLEN);
! (void) strlcat(cur_val, ",", ZFS_MAXPROPLEN);
! (void) strlcat(sharesmb_val, cur_val, ZFS_MAXPROPLEN);
}
}
return (0);
}
*** 1538,1549 ****
*/
int
sa_zfs_setprop(sa_handle_t handle, char *path, nvlist_t *nvl)
{
zfs_handle_t *z_fs;
! libzfs_handle_t *z_lib;
! char sharesmb_val[MAXPATHLEN];
char *dataset, *lastcomma;
if (nvlist_empty(nvl))
return (0);
--- 1441,1451 ----
*/
int
sa_zfs_setprop(sa_handle_t handle, char *path, nvlist_t *nvl)
{
zfs_handle_t *z_fs;
! char sharesmb_val[ZFS_MAXPROPLEN];
char *dataset, *lastcomma;
if (nvlist_empty(nvl))
return (0);
*** 1551,1584 ****
return (-1);
if ((dataset = get_zfs_dataset(handle, path, B_FALSE)) == NULL)
return (-1);
! if ((z_lib = libzfs_init()) == NULL) {
! free(dataset);
! return (-1);
! }
!
! z_fs = zfs_open(z_lib, dataset, ZFS_TYPE_DATASET);
if (z_fs == NULL) {
free(dataset);
- libzfs_fini(z_lib);
return (-1);
}
! bzero(sharesmb_val, MAXPATHLEN);
if (sa_zfs_sprintf_new_prop(nvl, sharesmb_val) != 0) {
free(dataset);
zfs_close(z_fs);
- libzfs_fini(z_lib);
return (-1);
}
if (sa_zfs_sprintf_existing_prop(z_fs, sharesmb_val) != 0) {
free(dataset);
zfs_close(z_fs);
- libzfs_fini(z_lib);
return (-1);
}
lastcomma = strrchr(sharesmb_val, ',');
if ((lastcomma != NULL) && (lastcomma[1] == '\0'))
--- 1453,1478 ----
return (-1);
if ((dataset = get_zfs_dataset(handle, path, B_FALSE)) == NULL)
return (-1);
! z_fs = zfs_open(handle->zfs_libhandle, dataset, ZFS_TYPE_DATASET);
if (z_fs == NULL) {
free(dataset);
return (-1);
}
! bzero(sharesmb_val, ZFS_MAXPROPLEN);
if (sa_zfs_sprintf_new_prop(nvl, sharesmb_val) != 0) {
free(dataset);
zfs_close(z_fs);
return (-1);
}
if (sa_zfs_sprintf_existing_prop(z_fs, sharesmb_val) != 0) {
free(dataset);
zfs_close(z_fs);
return (-1);
}
lastcomma = strrchr(sharesmb_val, ',');
if ((lastcomma != NULL) && (lastcomma[1] == '\0'))
*** 1586,1594 ****
(void) zfs_prop_set(z_fs, zfs_prop_to_name(ZFS_PROP_SHARESMB),
sharesmb_val);
free(dataset);
zfs_close(z_fs);
- libzfs_fini(z_lib);
return (0);
}
--- 1480,1487 ----