libshare_zfs.c revision 93a6f655de601ef9f8e8bfeca1b816fbfca6bc17
/*
* 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.
*
* Note that all ZFS shares are in a subgroup of the top level group
* called "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.
*/
/* make sure this is flagged as a ZFS group */
}
} else {
char **protolist;
int numprotos, i;
for (i = 0; i < numprotos; i++) {
}
}
}
}
return (group);
}
/*
* find_or_create_zfs_subgroup(groupname, optstring, *err)
*
* ZFS shares will be in a subgroup of the "zfs" master group. This
* function looks to see if the groupname exists and returns it if it
* does or else creates a new one with the specified name and returns
* that. The "zfs" group will exist before we get here, but we make
* sure just in case.
*
* err must be a valid pointer.
*/
static sa_group_t
{
char *name;
char *options;
/* start with the top-level "zfs" group */
/* have the group so break out of here */
break;
}
}
/* need to create the sub-group since it doesn't exist */
}
optstring = "rw";
} else {
*err = SA_NO_MEMORY;
}
}
}
}
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];
char *options;
/*
* 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) {
int doshopt = 0;
/*
* Need to find the "real" parent
* sub-group. It may not be mounted,
* but it was identified in the
* "sourcestr" variable. The real
* parent not mounted can occur if
* "canmount=off and sharenfs=on".
*/
&doshopt);
&err);
/*
* some options may only be on
* shares. If the opt string
* contains one of those, we
* put it just on the share.
*/
doshopt == SA_PROP_SHARE_ONLY) {
options, "nfs");
}
}
} else {
err = SA_NO_MEMORY;
}
} else {
/*
* this is a sub-group that actually
* contains the sharenfs property as
* opposed to a share that inherited.
*/
&err);
"nfs");
}
if (err == SA_PROP_SHARE_ONLY) {
/*
* Same as above, some
* properties may only be on
* shares, but due to the ZFS
* sub-groups being
* artificial, we sometimes
* get this and have to deal
* with it. We do it by
* attempting to put it on the
* share.
*/
"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);
}