libshare_zfs.c revision 6185db853e024a486ff8837e6784dd290d866112
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "libfsmgt.h"
#include <libzfs.h>
#include <string.h>
#include <libshare.h>
#include "libshare_impl.h"
extern char *sa_fstype(char *);
extern void set_node_attr(void *, char *, char *);
extern int sa_is_share(void *);
/*
* File system specific code for ZFS
*/
/*
* get_zfs_dataset(path)
*
* get the name of the ZFS dataset the path is equivalent to. The
* requires a dataset to do a zfs_open().
*/
static char *
get_zfs_dataset(char *path)
{
int err;
/*
* we want the longest resource so keep trying. This
* check avoids dropping out on a partial match. ZFS
* resources are ordered when mounted in order to
* ensure inheritence of properties.
*/
}
}
}
return (dataset);
}
/*
* get_zfs_property(dataset, property)
*
* Get the file system property specified from the ZFS dataset.
*/
static char *
{
char shareopts[ZFS_MAXPROPLEN];
libhandle = libzfs_init();
FALSE) == 0) {
}
}
}
return (NULL);
}
/*
* sa_zfs_is_shared(path)
*
* Check to see if the ZFS path provided has the sharenfs option set
* or not.
*/
int
sa_zfs_is_shared(char *path)
{
int ret = 0;
char *dataset;
char shareopts[ZFS_MAXPROPLEN];
libhandle = libzfs_init();
FALSE) == 0 &&
}
}
}
return (ret);
}
/*
* find_or_create_group(groupname, proto, *err)
*
* While walking the ZFS tree, we need to add shares to a defined
* group. If the group doesn't exist, create it first, making sure it
* is marked as a ZFS group.
*
* Not that all ZFS shares are in a subgroup of the top level group
* "zfs".
*/
static sa_group_t
{
/*
* we check to see if the "zfs" group exists. Since this
* should be the top level group, we don't want the
* parent. This is to make sure the zfs group has been created
* and to created if it hasn't been.
*/
}
} else {
char **protolist;
int numprotos, i;
for (i = 0; i < numprotos; i++) {
}
}
}
}
return (group);
}
/*
* sa_get_zfs_shares(groupname)
*
* Walk the mnttab for all zfs mounts and determine which are
* the shares.
*
* All shares are in a sub-group that will hold the properties. This
* allows representing the inherited property model.
*/
int
sa_get_zfs_shares(char *groupname)
{
int legacy = 0;
int err;
char shareopts[ZFS_MAXPROPLEN];
char sourcestr[ZFS_MAXPROPLEN];
/*
* if we can't access libzfs, don't bother doing anything.
*/
libhandle = libzfs_init();
return (SA_SYSTEM_ERR);
/*
* need to walk the mounted ZFS pools and datasets to
* find shares that are possible.
*/
FALSE) == 0 &&
/* it is shared so add to list */
/*
* A zfs file system had been shared
* through tradiditional methods
* group. Now it has been added to a
* ZFS group via the zfs
* command. Remove from previous
* config and setup with current
* options.
*/
}
if (source & ZFS_SRC_INHERITED) {
&err);
} else {
&err);
char *options;
"nfs");
}
/* unmark the share's changed state */
}
}
}
}
}
}
}
}
return (legacy);
}
/*
* sa_zfs_set_sharenfs(group, path, on)
*
* Update the "sharenfs" property on the path. If on is true, then set
* to the properties on the group or "on" if no properties are
* defined. Set to "off" if on is false.
*/
int
{
int ret = SA_NOT_IMPLEMENTED;
char *command;
char *dataset;
/* for now, NFS is always available for "zfs" */
if (on) {
}
}
"%s set sharenfs=\"%s\" %s", COMMAND,
dataset);
if (ret != 0)
ret = SA_SYSTEM_ERR;
}
}
}
return (ret);
}
/*
* sa_zfs_update(group)
*
* call back to ZFS to update the share if necessary.
* Don't do it if it isn't a real change.
*/
int
{
char *command;
char *optstring;
int doupdate = 0;
if (sa_is_share(group))
else
return (SA_NO_MEMORY);
*command = '\0';
char *path;
if (sa_is_share(group)) {
}
} else {
}
/* update only when there is an optstring found */
doupdate = 0;
doupdate++;
}
if (doupdate) {
"%s set sharenfs=%s %s", COMMAND,
} else {
"%s set sharenfs=on %s", COMMAND,
dataset);
}
switch (ret) {
default:
case 1:
ret = SA_SYSTEM_ERR;
break;
case 2:
ret = SA_SYNTAX_ERR;
break;
case 0:
break;
}
}
}
}
}
}
return (ret);
}
/*
* sa_group_is_zfs(group)
*
* Given the group, determine if the zfs attribute is set.
*/
int
{
char *zfs;
int ret = 0;
ret = 1;
}
return (ret);
}
/*
* 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;
ret = 1;
}
return (ret);
}