Skip to content

Initial stable API + ClusterHQ libzfs_core extensions + various fixes #3907

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/mount_zfs/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ mount_zfs_LDADD = \
$(top_builddir)/lib/libuutil/libuutil.la \
$(top_builddir)/lib/libzpool/libzpool.la \
$(top_builddir)/lib/libzfs/libzfs.la \
$(top_builddir)/lib/libzfs_core/libzfs_core.la
$(top_builddir)/lib/libzfs_core-$(LIBZFS_CORE_VARIANT)/libzfs_core-$(LIBZFS_CORE_VARIANT).la
2 changes: 1 addition & 1 deletion cmd/zdb/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ zdb_LDADD = \
$(top_builddir)/lib/libuutil/libuutil.la \
$(top_builddir)/lib/libzpool/libzpool.la \
$(top_builddir)/lib/libzfs/libzfs.la \
$(top_builddir)/lib/libzfs_core/libzfs_core.la
$(top_builddir)/lib/libzfs_core-$(LIBZFS_CORE_VARIANT)/libzfs_core-$(LIBZFS_CORE_VARIANT).la
2 changes: 1 addition & 1 deletion cmd/zed/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ zed_LDADD = \
$(top_builddir)/lib/libspl/libspl.la \
$(top_builddir)/lib/libzpool/libzpool.la \
$(top_builddir)/lib/libzfs/libzfs.la \
$(top_builddir)/lib/libzfs_core/libzfs_core.la
$(top_builddir)/lib/libzfs_core-$(LIBZFS_CORE_VARIANT)/libzfs_core-$(LIBZFS_CORE_VARIANT).la

zedconfdir = $(sysconfdir)/zfs/zed.d

Expand Down
2 changes: 1 addition & 1 deletion cmd/zfs/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ zfs_LDADD = \
$(top_builddir)/lib/libuutil/libuutil.la \
$(top_builddir)/lib/libzpool/libzpool.la \
$(top_builddir)/lib/libzfs/libzfs.la \
$(top_builddir)/lib/libzfs_core/libzfs_core.la
$(top_builddir)/lib/libzfs_core-$(LIBZFS_CORE_VARIANT)/libzfs_core-$(LIBZFS_CORE_VARIANT).la

zfs_LDFLAGS = -pthread
153 changes: 64 additions & 89 deletions cmd/zfs/zfs_iter.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,82 +68,37 @@ typedef struct callback_data {

uu_avl_pool_t *avl_pool;

/*
* 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 boolean_t
zfs_include_snapshots(zfs_handle_t *zhp, callback_data_t *cb)
{
zpool_handle_t *zph;

if ((cb->cb_flags & ZFS_ITER_PROP_LISTSNAPS) == 0)
return (cb->cb_types & ZFS_TYPE_SNAPSHOT);

zph = zfs_get_pool_handle(zhp);
return (zpool_get_prop_int(zph, ZPOOL_PROP_LISTSNAPS, NULL));
}

/*
* 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.
*/
/* Called for each dataset. */
static int
zfs_callback(zfs_handle_t *zhp, void *data)
{
callback_data_t *cb = data;
boolean_t dontclose = B_FALSE;
boolean_t include_snaps = zfs_include_snapshots(zhp, cb);
boolean_t include_bmarks = (cb->cb_types & ZFS_TYPE_BOOKMARK);

if ((zfs_get_type(zhp) & cb->cb_types) ||
((zfs_get_type(zhp) == ZFS_TYPE_SNAPSHOT) && include_snaps)) {
uu_avl_index_t idx;
zfs_node_t *node = safe_malloc(sizeof (zfs_node_t));

node->zn_handle = zhp;
uu_avl_node_init(node, &node->zn_avlnode, avl_pool);
if (uu_avl_find(cb->cb_avl, node, cb->cb_sortcol,
&idx) == NULL) {
if (cb->cb_proplist) {
if ((*cb->cb_proplist) &&
!(*cb->cb_proplist)->pl_all)
zfs_prune_proplist(zhp,
cb->cb_props_table);

if (zfs_expand_proplist(zhp, cb->cb_proplist,
(cb->cb_flags & ZFS_ITER_RECVD_PROPS),
(cb->cb_flags & ZFS_ITER_LITERAL_PROPS))
!= 0) {
free(node);
return (-1);
}
uu_avl_index_t idx;
zfs_node_t *node = safe_malloc(sizeof (zfs_node_t));

node->zn_handle = zhp;
uu_avl_node_init(node, &node->zn_avlnode, avl_pool);
if (uu_avl_find(cb->cb_avl, node, cb->cb_sortcol,
&idx) == NULL) {
if (cb->cb_proplist) {
if ((*cb->cb_proplist) &&
!(*cb->cb_proplist)->pl_all)
zfs_prune_proplist(zhp,
cb->cb_props_table);

if (zfs_expand_proplist(zhp, cb->cb_proplist,
(cb->cb_flags & ZFS_ITER_RECVD_PROPS),
(cb->cb_flags & ZFS_ITER_LITERAL_PROPS))
!= 0) {
free(node);
return (-1);
}
uu_avl_insert(cb->cb_avl, node, idx);
dontclose = B_TRUE;
} else {
free(node);
}
}

/*
* Recurse if necessary.
*/
if (cb->cb_flags & ZFS_ITER_RECURSE &&
((cb->cb_flags & ZFS_ITER_DEPTH_LIMIT) == 0 ||
cb->cb_depth < cb->cb_depth_limit)) {
cb->cb_depth++;
if (zfs_get_type(zhp) == ZFS_TYPE_FILESYSTEM)
(void) zfs_iter_filesystems(zhp, zfs_callback, data);
if (((zfs_get_type(zhp) & (ZFS_TYPE_SNAPSHOT |
ZFS_TYPE_BOOKMARK)) == 0) && include_snaps)
(void) zfs_iter_snapshots(zhp,
(cb->cb_flags & ZFS_ITER_SIMPLE) != 0, zfs_callback,
data);
if (((zfs_get_type(zhp) & (ZFS_TYPE_SNAPSHOT |
ZFS_TYPE_BOOKMARK)) == 0) && include_bmarks)
(void) zfs_iter_bookmarks(zhp, zfs_callback, data);
cb->cb_depth--;
uu_avl_insert(cb->cb_avl, node, idx);
dontclose = B_TRUE;
} else {
free(node);
}

if (!dontclose)
Expand Down Expand Up @@ -378,6 +333,9 @@ zfs_for_each(int argc, char **argv, int flags, zfs_type_t types,
int ret = 0;
zfs_node_t *node;
uu_avl_walk_t *walk;
zfs_type_t argtype;
zfs_type_t opentype;
boolean_t limit_specified = !!(flags & ZFS_ITER_DEPTH_LIMIT);

avl_pool = uu_avl_pool_create("zfs_pool", sizeof (zfs_node_t),
offsetof(zfs_node_t, zn_avlnode), zfs_sort, UU_DEFAULT);
Expand All @@ -386,6 +344,10 @@ zfs_for_each(int argc, char **argv, int flags, zfs_type_t types,
nomem();

cb.cb_sortcol = sortcol;
/*
* XXX: We are phasing out the legacy recursive interface in
* favor of the new stable list API.
*/
cb.cb_flags = flags;
cb.cb_proplist = proplist;
cb.cb_types = types;
Expand Down Expand Up @@ -431,39 +393,52 @@ zfs_for_each(int argc, char **argv, int flags, zfs_type_t types,
if ((cb.cb_avl = uu_avl_create(avl_pool, NULL, UU_DEFAULT)) == NULL)
nomem();

/*
* zfs_iter_generic() lets the kernel worry about default types.
*/
argtype = types * !!(flags & ZFS_ITER_TYPES_SPECIFIED);
opentype = argtype;
if ((flags & ZFS_ITER_RECURSE) != 0 || limit_specified)
opentype |= ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME;
if (argc == 0) {
/*
* If given no arguments, iterate over all datasets.
*/
cb.cb_flags |= ZFS_ITER_RECURSE;
ret = zfs_iter_root(g_zfs, zfs_callback, &cb);
ret = zfs_iter_generic(g_zfs, NULL, argtype, 0,
(limit_specified) ? limit : -1, limit_specified,
zfs_callback, &cb);
} else {
int i;
zfs_handle_t *zhp;
zfs_type_t argtype;

/*
* 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.
*/
argtype = types;
if (flags & ZFS_ITER_RECURSE) {
argtype |= ZFS_TYPE_FILESYSTEM;
if (types & ZFS_TYPE_SNAPSHOT)
argtype |= ZFS_TYPE_VOLUME;
}

for (i = 0; i < argc; i++) {
/*
* Special case for bookmarks
*/
if (argv[i][0] != '/' &&
strncmp(argv[i], "./", strlen("./")) != 0 &&
strchr(argv[i], '#') != NULL) {
ret = zfs_iter_generic(g_zfs, argv[i], argtype,
0, 0, B_FALSE, zfs_callback, &cb);
continue;
}

if (flags & ZFS_ITER_ARGS_CAN_BE_PATHS) {
zhp = zfs_path_to_zhandle(g_zfs, argv[i],
argtype);
opentype);
} else {
zhp = zfs_open(g_zfs, argv[i], argtype);
zhp = zfs_open(g_zfs, argv[i],
opentype);
}
if (zhp != NULL)
ret |= zfs_callback(zhp, &cb);
else
if (zhp != NULL) {
ret |= zfs_iter_generic(zfs_get_handle(zhp),
zfs_get_name(zhp), argtype, 0,
(limit_specified) ? limit : (flags &
ZFS_ITER_RECURSE) ? -1 : 0,
!(flags & ZFS_ITER_RECURSE), zfs_callback,
&cb);
zfs_close(zhp);
} else
ret = 1;
}
}
Expand Down
1 change: 1 addition & 0 deletions cmd/zfs/zfs_iter.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ typedef struct zfs_sort_column {
#define ZFS_ITER_RECVD_PROPS (1 << 4)
#define ZFS_ITER_LITERAL_PROPS (1 << 5)
#define ZFS_ITER_SIMPLE (1 << 6)
#define ZFS_ITER_TYPES_SPECIFIED (1 << 7)

int zfs_for_each(int, char **, int options, zfs_type_t,
zfs_sort_column_t *, zprop_list_t **, int, zfs_iter_f, void *);
Expand Down
Loading