zfs_iter.c revision fa9e4066f08beec538e775443c5be79dd423fcab
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2005 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 <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <libzfs.h>
#include "zfs_util.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 sorted by name. For snapshots, we order them according to
* creation time. 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_recurse;
/*
* Called for each dataset. If the object the object is of an appropriate type,
* add it to the avl tree and recurse over any children as necessary.
*/
int
{
int dontclose = 0;
/*
* If this object is of the appropriate type, add it to the AVL tree.
*/
dontclose = 1;
} else {
}
}
/*
* If 'recurse' is set, and the datasets can have datasets of the
* appropriate type, then recurse over its children.
*/
if (!dontclose)
return (0);
}
/* 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);
}
int
{
int ret = 0;
gettext("internal error: out of memory\n"));
exit(1);
}
gettext("internal error: out of memory\n"));
exit(1);
}
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 (recurse) {
if (types & ZFS_TYPE_SNAPSHOT)
}
for (i = 0; i < argc; i++) {
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.
*/
gettext("internal error: out of memory"));
exit(1);
}
}
return (ret);
}