libzfs_changelist.c revision 94de1d4cf6ec0a3bf040dcc4b8df107c4ed36b51
/*
* 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 <libintl.h>
#include <libuutil.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <zone.h>
#include <libzfs.h>
#include "libzfs_impl.h"
/*
* Structure to keep track of dataset state. Before changing the 'sharenfs' or
* 'mountpoint' property, we record whether the filesystem was previously
* dataset after the property has been changed.
*
* The interface consists of the following sequence of functions:
*
* changelist_gather()
* changelist_prefix()
* < change property >
* changelist_postfix()
* changelist_free()
*
* Other interfaces:
*
* changelist_remove() - remove a node from a gathered list
* changelist_rename() - renames all datasets appropriately when doing a rename
* changelist_unshare() - unshares all the nodes in a given changelist
* changelist_haszonedchild() - check if there is any child exported to
* a local zone
*/
typedef struct prop_changenode {
int cn_shared;
int cn_mounted;
int cn_zoned;
struct prop_changelist {
int cl_flags;
};
/*
* If the property is 'mountpoint', go through and unmount filesystems as
* necessary. We don't do the same for 'sharenfs', because we can just re-share
* with different options without interrupting service.
*/
int
{
int ret = 0;
return (0);
/*
* if we are in a global zone, but this dataset is exported to
* a local zone, do nothing.
*/
continue;
/*
* If we have a volume and this was a rename, remove the
*/
ret = -1;
ret = -1;
}
return (ret);
}
/*
* reshare the filesystems as necessary. In changelist_gather() we recorded
* whether the filesystem was previously shared or mounted. The action we take
* depends on the previous state, and whether the value was previously 'legacy'.
* filesystem.
*/
int
{
int ret = 0;
/*
* If we're changing the mountpoint, attempt to destroy the underlying
* mountpoint. All other datasets will have inherited from this dataset
* (in which case their mountpoints exist in the filesystem in the new
* location), or have explicit mountpoints set (in which case they won't
* be in the changelist).
*/
return (0);
/*
* We walk the datasets in reverse, because we want to mount any parent
* datasets before mounting the children.
*/
/*
* if we are in a global zone, but this dataset is exported to
* a local zone, do nothing.
*/
continue;
/*
* If this is a volume and we're doing a rename, recreate the
*/
ret = -1;
continue;
}
ret = -1;
/*
* We always re-share even if the filesystem is currently
* shared, so that we can adopt any new options.
*/
char shareopts[ZFS_MAXPROPLEN];
else
}
}
return (ret);
}
/*
* Is this "dataset" a child of "parent"?
*/
static boolean_t
{
int len;
/* snapshot does not have a child */
return (B_FALSE);
return (B_TRUE);
else
return (B_FALSE);
}
/*
* If we rename a filesystem, and child filesystem handles are no longer valid,
* since we identify datasets by their name in the ZFS namespace. So, we have
* to go through and fix up all the names appropriately. We could do this
* automatically if libzfs kept track of all open handles, but this is a lot
* less work.
*/
void
{
char newname[ZFS_MAXNAMELEN];
/*
* Do not rename a clone that's not in the source hierarchy.
*/
continue;
/*
* Destroy the previous mountpoint if needed.
*/
}
}
/*
* Given a gathered changelist for the "sharenfs" property,
* unshare all the nodes in the list.
*/
int
{
int ret = 0;
return (0);
ret = -1;
}
return (ret);
}
/*
* Check if there is any child exported to a local zone in a
* given changelist. This information has already been recorded
* while gathering the changelist via changelist_gather().
*/
int
{
return (clp->cl_haszonedchild);
}
/*
* Remove a node from a gathered list.
*/
void
{
return;
}
}
}
/*
* Release any memory associated with a changelist.
*/
void
{
UU_WALK_ROBUST)) != NULL);
}
}
}
static int
{
char property[ZFS_MAXPROPLEN];
char where[64];
/*
* inherit from the target filesystem. If we find any filesystem
* with a locally set mountpoint, we ignore any children since changing
* the property will not affect them. If this is a rename, we iterate
* over all children regardless, since we need them unmounted in order
* to do the rename. Also, if this is a volume and we're doing a
* rename, then always add it to the changelist.
*/
B_FALSE) != 0) {
return (0);
}
sizeof (prop_changenode_t))) == NULL) {
return (-1);
}
/* indicate if any child is exported to a local zone */
if (clp->cl_alldependents) {
return (0);
} else {
}
} else {
}
return (0);
}
/*
* Given a ZFS handle and a property, construct a complete list of datasets that
* need to be modified as part of this process. For anything but the
* 'mountpoint' and 'sharenfs' properties, this just returns an empty list.
* Otherwise, we iterate over all children and look for any datasets which
* inherit this property. For each such dataset, we add it to the list and mark
* whether it was shared beforehand.
*/
{
char property[ZFS_MAXPROPLEN];
return (NULL);
sizeof (prop_changenode_t),
NULL, 0);
return (NULL);
}
return (NULL);
}
/*
* If this is a rename or the 'zoned' property, we pretend we're
* changing the mountpoint and flag it so we can catch all children in
* change_one().
*
* Flag cl_alldependents to catch all children plus the
* dependents (clones) that are not in the hierarchy.
*/
if (prop == ZFS_PROP_NAME) {
} else if (prop == ZFS_PROP_ZONED) {
} else {
}
return (clp);
if (clp->cl_alldependents) {
return (NULL);
}
return (NULL);
}
/*
* We have to re-open ourselves because we auto-close all the handles
* and can't tell the difference.
*/
ZFS_TYPE_ANY)) == NULL) {
return (NULL);
}
/*
* Always add ourself to the list. We add ourselves to the end so that
* we're the last to be unmounted.
*/
sizeof (prop_changenode_t))) == NULL) {
return (NULL);
}
/*
* If the property was previously 'legacy' or 'none', record this fact,
* as the behavior of changelist_postfix() will be different.
*/
return (clp);
}