zfs_iter.c revision a8b6ddaf31808c845e00161dda0a3d1fe31ae281
/*
* 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
*/
/*
*/
#include <libintl.h>
#include <libuutil.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <libzfs.h>
#include "zfs_util.h"
#include "zfs_iter.h"
/*
* This is a private interface used to gather up all the datasets specified on
* the command line so that we can iterate over them in order.
*
* First, we iterate over all filesystems, gathering them together into an
* AVL tree. We report errors for any explicitly specified datasets
* that we couldn't open.
*
* When finished, we have an AVL tree of ZFS handles. We go through and execute
* the provided callback for each one, passing whatever data the user supplied.
*/
typedef struct zfs_node {
} zfs_node_t;
typedef struct callback_data {
int cb_flags;
int cb_depth_limit;
int cb_depth;
/*
* Include snaps if they were requested or if this a zfs list where types
* were not specified and the "listsnapshots" property is set on this pool.
*/
static int
{
}
/*
* Called for each dataset. If the object is of an appropriate type,
* add it to the avl tree and recurse over any children as necessary.
*/
static int
{
int dontclose = 0;
if (cb->cb_proplist) {
if ((*cb->cb_proplist) &&
cb->cb_props_table);
!= 0) {
return (-1);
}
}
dontclose = 1;
} else {
}
}
/*
* Recurse if necessary.
*/
}
if (!dontclose)
return (0);
}
int
{
return (-1);
if (prop == ZPROP_INVAL) {
}
} else {
}
return (0);
}
void
{
}
}
/* ARGSUSED */
static int
{
const char *lname = zfs_get_name(l);
const char *rname = zfs_get_name(r);
int ret;
*lat = '\0';
*rat = '\0';
if (ret == 0) {
/*
* If we're comparing a dataset to one of its snapshots, we
* always make the full dataset first.
*/
ret = -1;
ret = 1;
} else {
/*
* If we have two snapshots from the same dataset, then
* we want to sort them according to creation time. We
* use the hidden CREATETXG property to get an absolute
* ordering of snapshots.
*/
ret = -1;
ret = 1;
}
}
*lat = '@';
*rat = '@';
return (ret);
}
/*
* Sort datasets by specified columns.
*
* o Numeric types sort in ascending order.
* o String types sort in alphabetical order.
* o Types inappropriate for a row sort that row to the literal
* bottom, regardless of the specified ordering.
*
* If no sort columns are specified, or two datasets compare equally
* across all specified columns, they are sorted alphabetically by name
* with snapshots grouped under their parents.
*/
static int
{
int ret = 0;
/*
* We group the checks below the generic code. If 'lstr' and
* 'rstr' are non-NULL, then we do a string based comparison.
* Otherwise, we compare 'lnum' and 'rnum'.
*/
luser = zfs_get_user_props(l);
ruser = zfs_get_user_props(r);
if (lvalid)
ZPROP_VALUE, &lstr) == 0);
if (rvalid)
ZPROP_VALUE, &rstr) == 0);
} else {
zfs_get_type(l));
zfs_get_type(r));
if (lvalid)
if (rvalid)
}
continue;
else if (!lvalid)
return (1);
else if (!rvalid)
return (-1);
if (lstr)
ret = -1;
ret = 1;
if (ret != 0) {
return (ret);
}
}
}
int
{
callback_data_t cb = {0};
int ret = 0;
nomem();
/*
* If cb_proplist is provided then in the zfs_handles created we
* retain only those properties listed in cb_proplist and sortcol.
* The rest are pruned. So, the caller should make sure that no other
* properties other than those listed in cb_proplist/sortcol are
* accessed.
*
* If cb_proplist is NULL then we retain all the properties. We
* always retain the zoned property, which some other properties
* need (userquota & friends), and the createtxg property, which
* we need to sort snapshots.
*/
while (p) {
if (p->pl_prop >= ZFS_PROP_TYPE &&
p->pl_prop < ZFS_NUM_PROPS) {
}
p = p->pl_next;
}
while (sortcol) {
}
}
} else {
sizeof (cb.cb_props_table));
}
nomem();
if (argc == 0) {
/*
* If given no arguments, iterate over all datasets.
*/
} else {
int i;
/*
* If we're recursive, then we always allow filesystems as
* arguments. If we also are interested in snapshots, then we
* can take volumes as well.
*/
if (flags & ZFS_ITER_RECURSE) {
if (types & ZFS_TYPE_SNAPSHOT)
}
for (i = 0; i < argc; i++) {
if (flags & ZFS_ITER_ARGS_CAN_BE_PATHS) {
argtype);
} else {
}
else
ret = 1;
}
}
/*
* At this point we've got our AVL tree full of zfs handles, so iterate
* over each one and execute the real user callback.
*/
/*
* Finally, clean up the AVL tree.
*/
nomem();
}
return (ret);
}