Revert "zfs list: Allow more fields in ZFS_ITER_SIMPLE mode"

This reverts commit f6a0dac84a.

Reviewed-by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Mark Maybee <mark.maybee@delphix.com>
Signed-off-by: Paul Dagnelie <pcd@delphix.com>
Closes #12938
This commit is contained in:
Paul Dagnelie 2022-01-06 11:12:53 -08:00 committed by GitHub
parent 0175272f64
commit 399b98198a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 93 additions and 188 deletions

View File

@ -144,20 +144,19 @@ zfs_callback(zfs_handle_t *zhp, void *data)
(cb->cb_types & (cb->cb_types &
(ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME))) && (ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME))) &&
zfs_get_type(zhp) == ZFS_TYPE_FILESYSTEM) { zfs_get_type(zhp) == ZFS_TYPE_FILESYSTEM) {
(void) zfs_iter_filesystems(zhp, cb->cb_flags, (void) zfs_iter_filesystems(zhp, zfs_callback, data);
zfs_callback, data);
} }
if (((zfs_get_type(zhp) & (ZFS_TYPE_SNAPSHOT | if (((zfs_get_type(zhp) & (ZFS_TYPE_SNAPSHOT |
ZFS_TYPE_BOOKMARK)) == 0) && include_snaps) { ZFS_TYPE_BOOKMARK)) == 0) && include_snaps) {
(void) zfs_iter_snapshots(zhp, cb->cb_flags, (void) zfs_iter_snapshots(zhp,
(cb->cb_flags & ZFS_ITER_SIMPLE) != 0,
zfs_callback, data, 0, 0); zfs_callback, data, 0, 0);
} }
if (((zfs_get_type(zhp) & (ZFS_TYPE_SNAPSHOT | if (((zfs_get_type(zhp) & (ZFS_TYPE_SNAPSHOT |
ZFS_TYPE_BOOKMARK)) == 0) && include_bmarks) { ZFS_TYPE_BOOKMARK)) == 0) && include_bmarks) {
(void) zfs_iter_bookmarks(zhp, cb->cb_flags, (void) zfs_iter_bookmarks(zhp, zfs_callback, data);
zfs_callback, data);
} }
cb->cb_depth--; cb->cb_depth--;
@ -213,58 +212,11 @@ zfs_free_sort_columns(zfs_sort_column_t *sc)
} }
} }
/* int
* Return true if all of the properties to be sorted are populated by zfs_sort_only_by_name(const zfs_sort_column_t *sc)
* dsl_dataset_fast_stat(). Note that sc == NULL (no sort) means we
* don't need any extra properties, so returns true.
*/
boolean_t
zfs_sort_only_by_fast(const zfs_sort_column_t *sc)
{ {
while (sc != NULL) { return (sc != NULL && sc->sc_next == NULL &&
switch (sc->sc_prop) { sc->sc_prop == ZFS_PROP_NAME);
case ZFS_PROP_NAME:
case ZFS_PROP_GUID:
case ZFS_PROP_CREATETXG:
case ZFS_PROP_NUMCLONES:
case ZFS_PROP_INCONSISTENT:
case ZFS_PROP_REDACTED:
case ZFS_PROP_ORIGIN:
break;
default:
return (B_FALSE);
}
sc = sc->sc_next;
}
return (B_TRUE);
}
boolean_t
zfs_list_only_by_fast(const zprop_list_t *p)
{
if (p == NULL) {
/* NULL means 'all' so we can't use simple mode */
return (B_FALSE);
}
while (p != NULL) {
switch (p->pl_prop) {
case ZFS_PROP_NAME:
case ZFS_PROP_GUID:
case ZFS_PROP_CREATETXG:
case ZFS_PROP_NUMCLONES:
case ZFS_PROP_INCONSISTENT:
case ZFS_PROP_REDACTED:
case ZFS_PROP_ORIGIN:
break;
default:
return (B_FALSE);
}
p = p->pl_next;
}
return (B_TRUE);
} }
static int static int

View File

@ -40,13 +40,19 @@ typedef struct zfs_sort_column {
boolean_t sc_reverse; boolean_t sc_reverse;
} zfs_sort_column_t; } zfs_sort_column_t;
#define ZFS_ITER_RECURSE (1 << 0)
#define ZFS_ITER_ARGS_CAN_BE_PATHS (1 << 1)
#define ZFS_ITER_PROP_LISTSNAPS (1 << 2)
#define ZFS_ITER_DEPTH_LIMIT (1 << 3)
#define ZFS_ITER_RECVD_PROPS (1 << 4)
#define ZFS_ITER_LITERAL_PROPS (1 << 5)
#define ZFS_ITER_SIMPLE (1 << 6)
int zfs_for_each(int, char **, int options, zfs_type_t, int zfs_for_each(int, char **, int options, zfs_type_t,
zfs_sort_column_t *, zprop_list_t **, int, zfs_iter_f, void *); zfs_sort_column_t *, zprop_list_t **, int, zfs_iter_f, void *);
int zfs_add_sort_column(zfs_sort_column_t **, const char *, boolean_t); int zfs_add_sort_column(zfs_sort_column_t **, const char *, boolean_t);
void zfs_free_sort_columns(zfs_sort_column_t *); void zfs_free_sort_columns(zfs_sort_column_t *);
boolean_t zfs_sort_only_by_fast(const zfs_sort_column_t *); int zfs_sort_only_by_name(const zfs_sort_column_t *);
boolean_t zfs_list_only_by_fast(const zprop_list_t *);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -1536,7 +1536,7 @@ destroy_print_snapshots(zfs_handle_t *fs_zhp, destroy_cbdata_t *cb)
int err; int err;
assert(cb->cb_firstsnap == NULL); assert(cb->cb_firstsnap == NULL);
assert(cb->cb_prevsnap == NULL); assert(cb->cb_prevsnap == NULL);
err = zfs_iter_snapshots_sorted(fs_zhp, 0, destroy_print_cb, cb, 0, 0); err = zfs_iter_snapshots_sorted(fs_zhp, destroy_print_cb, cb, 0, 0);
if (cb->cb_firstsnap != NULL) { if (cb->cb_firstsnap != NULL) {
uint64_t used = 0; uint64_t used = 0;
if (err == 0) { if (err == 0) {
@ -1562,7 +1562,7 @@ snapshot_to_nvl_cb(zfs_handle_t *zhp, void *arg)
if (!cb->cb_doclones && !cb->cb_defer_destroy) { if (!cb->cb_doclones && !cb->cb_defer_destroy) {
cb->cb_target = zhp; cb->cb_target = zhp;
cb->cb_first = B_TRUE; cb->cb_first = B_TRUE;
err = zfs_iter_dependents(zhp, 0, B_TRUE, err = zfs_iter_dependents(zhp, B_TRUE,
destroy_check_dependent, cb); destroy_check_dependent, cb);
} }
@ -1580,8 +1580,7 @@ gather_snapshots(zfs_handle_t *zhp, void *arg)
destroy_cbdata_t *cb = arg; destroy_cbdata_t *cb = arg;
int err = 0; int err = 0;
err = zfs_iter_snapspec(zhp, 0, cb->cb_snapspec, err = zfs_iter_snapspec(zhp, cb->cb_snapspec, snapshot_to_nvl_cb, cb);
snapshot_to_nvl_cb, cb);
if (err == ENOENT) if (err == ENOENT)
err = 0; err = 0;
if (err != 0) if (err != 0)
@ -1594,7 +1593,7 @@ gather_snapshots(zfs_handle_t *zhp, void *arg)
} }
if (cb->cb_recurse) if (cb->cb_recurse)
err = zfs_iter_filesystems(zhp, 0, gather_snapshots, cb); err = zfs_iter_filesystems(zhp, gather_snapshots, cb);
out: out:
zfs_close(zhp); zfs_close(zhp);
@ -1619,7 +1618,7 @@ destroy_clones(destroy_cbdata_t *cb)
* false while destroying the clones. * false while destroying the clones.
*/ */
cb->cb_defer_destroy = B_FALSE; cb->cb_defer_destroy = B_FALSE;
err = zfs_iter_dependents(zhp, 0, B_FALSE, err = zfs_iter_dependents(zhp, B_FALSE,
destroy_callback, cb); destroy_callback, cb);
cb->cb_defer_destroy = defer; cb->cb_defer_destroy = defer;
zfs_close(zhp); zfs_close(zhp);
@ -1830,7 +1829,7 @@ zfs_do_destroy(int argc, char **argv)
*/ */
cb.cb_first = B_TRUE; cb.cb_first = B_TRUE;
if (!cb.cb_doclones && if (!cb.cb_doclones &&
zfs_iter_dependents(zhp, 0, B_TRUE, destroy_check_dependent, zfs_iter_dependents(zhp, B_TRUE, destroy_check_dependent,
&cb) != 0) { &cb) != 0) {
rv = 1; rv = 1;
goto out; goto out;
@ -1841,7 +1840,7 @@ zfs_do_destroy(int argc, char **argv)
goto out; goto out;
} }
cb.cb_batchedsnaps = fnvlist_alloc(); cb.cb_batchedsnaps = fnvlist_alloc();
if (zfs_iter_dependents(zhp, 0, B_FALSE, destroy_callback, if (zfs_iter_dependents(zhp, B_FALSE, destroy_callback,
&cb) != 0) { &cb) != 0) {
rv = 1; rv = 1;
goto out; goto out;
@ -3705,6 +3704,13 @@ zfs_do_list(int argc, char **argv)
if (fields == NULL) if (fields == NULL)
fields = default_fields; fields = default_fields;
/*
* If we are only going to list snapshot names and sort by name,
* then we can use faster version.
*/
if (strcmp(fields, "name") == 0 && zfs_sort_only_by_name(sortcol))
flags |= ZFS_ITER_SIMPLE;
/* /*
* If "-o space" and no types were specified, don't display snapshots. * If "-o space" and no types were specified, don't display snapshots.
*/ */
@ -3732,15 +3738,6 @@ zfs_do_list(int argc, char **argv)
cb.cb_first = B_TRUE; cb.cb_first = B_TRUE;
/*
* If we are only going to list and sort by properties that are "fast"
* then we can use "simple" mode and avoid populating the properties
* nvlist.
*/
if (zfs_list_only_by_fast(cb.cb_proplist) &&
zfs_sort_only_by_fast(sortcol))
flags |= ZFS_ITER_SIMPLE;
ret = zfs_for_each(argc, argv, flags, types, sortcol, &cb.cb_proplist, ret = zfs_for_each(argc, argv, flags, types, sortcol, &cb.cb_proplist,
limit, list_callback, &cb); limit, list_callback, &cb);
@ -4051,7 +4048,7 @@ rollback_check(zfs_handle_t *zhp, void *data)
} }
if (cbp->cb_recurse) { if (cbp->cb_recurse) {
if (zfs_iter_dependents(zhp, 0, B_TRUE, if (zfs_iter_dependents(zhp, B_TRUE,
rollback_check_dependent, cbp) != 0) { rollback_check_dependent, cbp) != 0) {
zfs_close(zhp); zfs_close(zhp);
return (-1); return (-1);
@ -4150,10 +4147,10 @@ zfs_do_rollback(int argc, char **argv)
if (cb.cb_create > 0) if (cb.cb_create > 0)
min_txg = cb.cb_create; min_txg = cb.cb_create;
if ((ret = zfs_iter_snapshots(zhp, 0, rollback_check, &cb, if ((ret = zfs_iter_snapshots(zhp, B_FALSE, rollback_check, &cb,
min_txg, 0)) != 0) min_txg, 0)) != 0)
goto out; goto out;
if ((ret = zfs_iter_bookmarks(zhp, 0, rollback_check, &cb)) != 0) if ((ret = zfs_iter_bookmarks(zhp, rollback_check, &cb)) != 0)
goto out; goto out;
if ((ret = cb.cb_error) != 0) if ((ret = cb.cb_error) != 0)
@ -4295,7 +4292,7 @@ zfs_snapshot_cb(zfs_handle_t *zhp, void *arg)
free(name); free(name);
if (sd->sd_recursive) if (sd->sd_recursive)
rv = zfs_iter_filesystems(zhp, 0, zfs_snapshot_cb, sd); rv = zfs_iter_filesystems(zhp, zfs_snapshot_cb, sd);
zfs_close(zhp); zfs_close(zhp);
return (rv); return (rv);
} }
@ -6281,7 +6278,7 @@ zfs_do_allow_unallow_impl(int argc, char **argv, boolean_t un)
if (un && opts.recursive) { if (un && opts.recursive) {
struct deleg_perms data = { un, update_perm_nvl }; struct deleg_perms data = { un, update_perm_nvl };
if (zfs_iter_filesystems(zhp, 0, set_deleg_perms, if (zfs_iter_filesystems(zhp, set_deleg_perms,
&data) != 0) &data) != 0)
goto cleanup0; goto cleanup0;
} }
@ -6644,7 +6641,7 @@ get_one_dataset(zfs_handle_t *zhp, void *data)
/* /*
* Iterate over any nested datasets. * Iterate over any nested datasets.
*/ */
if (zfs_iter_filesystems(zhp, 0, get_one_dataset, data) != 0) { if (zfs_iter_filesystems(zhp, get_one_dataset, data) != 0) {
zfs_close(zhp); zfs_close(zhp);
return (1); return (1);
} }

View File

@ -8807,7 +8807,7 @@ check_unsupp_fs(zfs_handle_t *zhp, void *unsupp_fs)
(*count)++; (*count)++;
} }
zfs_iter_filesystems(zhp, 0, check_unsupp_fs, unsupp_fs); zfs_iter_filesystems(zhp, check_unsupp_fs, unsupp_fs);
zfs_close(zhp); zfs_close(zhp);

View File

@ -534,7 +534,7 @@ zfs_key_config_get_dataset(zfs_key_config_t *config)
return (NULL); return (NULL);
} }
(void) zfs_iter_filesystems(zhp, 0, find_dsname_by_prop_value, (void) zfs_iter_filesystems(zhp, find_dsname_by_prop_value,
config); config);
zfs_close(zhp); zfs_close(zhp);
char *dsname = config->dsname; char *dsname = config->dsname;

View File

@ -644,27 +644,19 @@ _LIBZFS_H void zprop_print_one_property(const char *, zprop_get_cbdata_t *,
/* /*
* Iterator functions. * Iterator functions.
*/ */
#define ZFS_ITER_RECURSE (1 << 0)
#define ZFS_ITER_ARGS_CAN_BE_PATHS (1 << 1)
#define ZFS_ITER_PROP_LISTSNAPS (1 << 2)
#define ZFS_ITER_DEPTH_LIMIT (1 << 3)
#define ZFS_ITER_RECVD_PROPS (1 << 4)
#define ZFS_ITER_LITERAL_PROPS (1 << 5)
#define ZFS_ITER_SIMPLE (1 << 6)
typedef int (*zfs_iter_f)(zfs_handle_t *, void *); typedef int (*zfs_iter_f)(zfs_handle_t *, void *);
_LIBZFS_H int zfs_iter_root(libzfs_handle_t *, zfs_iter_f, void *); _LIBZFS_H int zfs_iter_root(libzfs_handle_t *, zfs_iter_f, void *);
_LIBZFS_H int zfs_iter_children(zfs_handle_t *, int, zfs_iter_f, void *); _LIBZFS_H int zfs_iter_children(zfs_handle_t *, zfs_iter_f, void *);
_LIBZFS_H int zfs_iter_dependents(zfs_handle_t *, int, boolean_t, zfs_iter_f, _LIBZFS_H int zfs_iter_dependents(zfs_handle_t *, boolean_t, zfs_iter_f,
void *); void *);
_LIBZFS_H int zfs_iter_filesystems(zfs_handle_t *, int, zfs_iter_f, void *); _LIBZFS_H int zfs_iter_filesystems(zfs_handle_t *, zfs_iter_f, void *);
_LIBZFS_H int zfs_iter_snapshots(zfs_handle_t *, int, zfs_iter_f, void *, _LIBZFS_H int zfs_iter_snapshots(zfs_handle_t *, boolean_t, zfs_iter_f, void *,
uint64_t, uint64_t); uint64_t, uint64_t);
_LIBZFS_H int zfs_iter_snapshots_sorted(zfs_handle_t *, int, zfs_iter_f, void *, _LIBZFS_H int zfs_iter_snapshots_sorted(zfs_handle_t *, zfs_iter_f, void *,
uint64_t, uint64_t); uint64_t, uint64_t);
_LIBZFS_H int zfs_iter_snapspec(zfs_handle_t *, int, const char *, zfs_iter_f, _LIBZFS_H int zfs_iter_snapspec(zfs_handle_t *, const char *, zfs_iter_f,
void *); void *);
_LIBZFS_H int zfs_iter_bookmarks(zfs_handle_t *, int, zfs_iter_f, void *); _LIBZFS_H int zfs_iter_bookmarks(zfs_handle_t *, zfs_iter_f, void *);
_LIBZFS_H int zfs_iter_mounted(zfs_handle_t *, zfs_iter_f, void *); _LIBZFS_H int zfs_iter_mounted(zfs_handle_t *, zfs_iter_f, void *);
typedef struct get_all_cb { typedef struct get_all_cb {

View File

@ -4025,14 +4025,13 @@
<abi-instr address-size='64' path='libzfs_iter.c' language='LANG_C99'> <abi-instr address-size='64' path='libzfs_iter.c' language='LANG_C99'>
<function-decl name='zfs_iter_filesystems' mangled-name='zfs_iter_filesystems' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zfs_iter_filesystems'> <function-decl name='zfs_iter_filesystems' mangled-name='zfs_iter_filesystems' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zfs_iter_filesystems'>
<parameter type-id='9200a744' name='zhp'/> <parameter type-id='9200a744' name='zhp'/>
<parameter type-id='95e97e5e' name='flags'/>
<parameter type-id='d8e49ab9' name='func'/> <parameter type-id='d8e49ab9' name='func'/>
<parameter type-id='eaa32e2f' name='data'/> <parameter type-id='eaa32e2f' name='data'/>
<return type-id='95e97e5e'/> <return type-id='95e97e5e'/>
</function-decl> </function-decl>
<function-decl name='zfs_iter_snapshots' mangled-name='zfs_iter_snapshots' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zfs_iter_snapshots'> <function-decl name='zfs_iter_snapshots' mangled-name='zfs_iter_snapshots' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zfs_iter_snapshots'>
<parameter type-id='9200a744' name='zhp'/> <parameter type-id='9200a744' name='zhp'/>
<parameter type-id='95e97e5e' name='flags'/> <parameter type-id='c19b74c3' name='simple'/>
<parameter type-id='d8e49ab9' name='func'/> <parameter type-id='d8e49ab9' name='func'/>
<parameter type-id='eaa32e2f' name='data'/> <parameter type-id='eaa32e2f' name='data'/>
<parameter type-id='9c313c2d' name='min_txg'/> <parameter type-id='9c313c2d' name='min_txg'/>
@ -4041,14 +4040,12 @@
</function-decl> </function-decl>
<function-decl name='zfs_iter_bookmarks' mangled-name='zfs_iter_bookmarks' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zfs_iter_bookmarks'> <function-decl name='zfs_iter_bookmarks' mangled-name='zfs_iter_bookmarks' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zfs_iter_bookmarks'>
<parameter type-id='9200a744' name='zhp'/> <parameter type-id='9200a744' name='zhp'/>
<parameter type-id='95e97e5e' name='flags'/>
<parameter type-id='d8e49ab9' name='func'/> <parameter type-id='d8e49ab9' name='func'/>
<parameter type-id='eaa32e2f' name='data'/> <parameter type-id='eaa32e2f' name='data'/>
<return type-id='95e97e5e'/> <return type-id='95e97e5e'/>
</function-decl> </function-decl>
<function-decl name='zfs_iter_snapshots_sorted' mangled-name='zfs_iter_snapshots_sorted' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zfs_iter_snapshots_sorted'> <function-decl name='zfs_iter_snapshots_sorted' mangled-name='zfs_iter_snapshots_sorted' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zfs_iter_snapshots_sorted'>
<parameter type-id='9200a744' name='zhp'/> <parameter type-id='9200a744' name='zhp'/>
<parameter type-id='95e97e5e' name='flags'/>
<parameter type-id='d8e49ab9' name='callback'/> <parameter type-id='d8e49ab9' name='callback'/>
<parameter type-id='eaa32e2f' name='data'/> <parameter type-id='eaa32e2f' name='data'/>
<parameter type-id='9c313c2d' name='min_txg'/> <parameter type-id='9c313c2d' name='min_txg'/>
@ -4057,7 +4054,6 @@
</function-decl> </function-decl>
<function-decl name='zfs_iter_snapspec' mangled-name='zfs_iter_snapspec' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zfs_iter_snapspec'> <function-decl name='zfs_iter_snapspec' mangled-name='zfs_iter_snapspec' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zfs_iter_snapspec'>
<parameter type-id='9200a744' name='fs_zhp'/> <parameter type-id='9200a744' name='fs_zhp'/>
<parameter type-id='95e97e5e' name='flags'/>
<parameter type-id='80f4b756' name='spec_orig'/> <parameter type-id='80f4b756' name='spec_orig'/>
<parameter type-id='d8e49ab9' name='func'/> <parameter type-id='d8e49ab9' name='func'/>
<parameter type-id='eaa32e2f' name='arg'/> <parameter type-id='eaa32e2f' name='arg'/>
@ -4065,14 +4061,12 @@
</function-decl> </function-decl>
<function-decl name='zfs_iter_children' mangled-name='zfs_iter_children' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zfs_iter_children'> <function-decl name='zfs_iter_children' mangled-name='zfs_iter_children' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zfs_iter_children'>
<parameter type-id='9200a744' name='zhp'/> <parameter type-id='9200a744' name='zhp'/>
<parameter type-id='95e97e5e' name='flags'/>
<parameter type-id='d8e49ab9' name='func'/> <parameter type-id='d8e49ab9' name='func'/>
<parameter type-id='eaa32e2f' name='data'/> <parameter type-id='eaa32e2f' name='data'/>
<return type-id='95e97e5e'/> <return type-id='95e97e5e'/>
</function-decl> </function-decl>
<function-decl name='zfs_iter_dependents' mangled-name='zfs_iter_dependents' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zfs_iter_dependents'> <function-decl name='zfs_iter_dependents' mangled-name='zfs_iter_dependents' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zfs_iter_dependents'>
<parameter type-id='9200a744' name='zhp'/> <parameter type-id='9200a744' name='zhp'/>
<parameter type-id='95e97e5e' name='flags'/>
<parameter type-id='c19b74c3' name='allowrecursion'/> <parameter type-id='c19b74c3' name='allowrecursion'/>
<parameter type-id='d8e49ab9' name='func'/> <parameter type-id='d8e49ab9' name='func'/>
<parameter type-id='eaa32e2f' name='data'/> <parameter type-id='eaa32e2f' name='data'/>

View File

@ -551,7 +551,7 @@ change_one(zfs_handle_t *zhp, void *data)
} }
if (!clp->cl_alldependents) if (!clp->cl_alldependents)
ret = zfs_iter_children(zhp, 0, change_one, data); ret = zfs_iter_children(zhp, change_one, data);
/* /*
* If we added the handle to the changelist, we will re-use it * If we added the handle to the changelist, we will re-use it
@ -721,11 +721,11 @@ changelist_gather(zfs_handle_t *zhp, zfs_prop_t prop, int gather_flags,
return (NULL); return (NULL);
} }
} else if (clp->cl_alldependents) { } else if (clp->cl_alldependents) {
if (zfs_iter_dependents(zhp, 0, B_TRUE, change_one, clp) != 0) { if (zfs_iter_dependents(zhp, B_TRUE, change_one, clp) != 0) {
changelist_free(clp); changelist_free(clp);
return (NULL); return (NULL);
} }
} else if (zfs_iter_children(zhp, 0, change_one, clp) != 0) { } else if (zfs_iter_children(zhp, change_one, clp) != 0) {
changelist_free(clp); changelist_free(clp);
return (NULL); return (NULL);
} }

View File

@ -1228,7 +1228,7 @@ load_keys_cb(zfs_handle_t *zhp, void *arg)
cb->cb_numfailed++; cb->cb_numfailed++;
out: out:
(void) zfs_iter_filesystems(zhp, 0, load_keys_cb, cb); (void) zfs_iter_filesystems(zhp, load_keys_cb, cb);
zfs_close(zhp); zfs_close(zhp);
/* always return 0, since this function is best effort */ /* always return 0, since this function is best effort */

View File

@ -529,17 +529,9 @@ make_dataset_simple_handle_zc(zfs_handle_t *pzhp, zfs_cmd_t *zc)
zhp->zfs_hdl = pzhp->zfs_hdl; zhp->zfs_hdl = pzhp->zfs_hdl;
(void) strlcpy(zhp->zfs_name, zc->zc_name, sizeof (zhp->zfs_name)); (void) strlcpy(zhp->zfs_name, zc->zc_name, sizeof (zhp->zfs_name));
zhp->zpool_hdl = zpool_handle(zhp);
zhp->zfs_dmustats = zc->zc_objset_stats; /* structure assignment */
zhp->zfs_head_type = pzhp->zfs_type; zhp->zfs_head_type = pzhp->zfs_type;
if (zhp->zfs_dmustats.dds_is_snapshot) zhp->zfs_type = ZFS_TYPE_SNAPSHOT;
zhp->zfs_type = ZFS_TYPE_SNAPSHOT; zhp->zpool_hdl = zpool_handle(zhp);
else if (zhp->zfs_dmustats.dds_type == DMU_OST_ZVOL)
zhp->zfs_type = ZFS_TYPE_VOLUME;
else if (zhp->zfs_dmustats.dds_type == DMU_OST_ZFS)
zhp->zfs_type = ZFS_TYPE_FILESYSTEM;
else
abort(); /* we should never see any other types */
return (zhp); return (zhp);
} }
@ -745,7 +737,7 @@ zfs_open(libzfs_handle_t *hdl, const char *path, int types)
* Iterate bookmarks to find the right one. * Iterate bookmarks to find the right one.
*/ */
errno = 0; errno = 0;
if ((zfs_iter_bookmarks(pzhp, 0, zfs_open_bookmarks_cb, if ((zfs_iter_bookmarks(pzhp, zfs_open_bookmarks_cb,
&cb_data) == 0) && (cb_data.zhp == NULL)) { &cb_data) == 0) && (cb_data.zhp == NULL)) {
(void) zfs_error(hdl, EZFS_NOENT, errbuf); (void) zfs_error(hdl, EZFS_NOENT, errbuf);
zfs_close(pzhp); zfs_close(pzhp);
@ -2095,8 +2087,7 @@ getprop_string(zfs_handle_t *zhp, zfs_prop_t prop, char **source)
static boolean_t static boolean_t
zfs_is_recvd_props_mode(zfs_handle_t *zhp) zfs_is_recvd_props_mode(zfs_handle_t *zhp)
{ {
return (zhp->zfs_props != NULL && return (zhp->zfs_props == zhp->zfs_recvd_props);
zhp->zfs_props == zhp->zfs_recvd_props);
} }
static void static void
@ -2301,20 +2292,6 @@ get_numeric_property(zfs_handle_t *zhp, zfs_prop_t prop, zprop_source_t *src,
*val = zhp->zfs_dmustats.dds_redacted; *val = zhp->zfs_dmustats.dds_redacted;
break; break;
case ZFS_PROP_GUID:
if (zhp->zfs_dmustats.dds_guid != 0)
*val = zhp->zfs_dmustats.dds_guid;
else
*val = getprop_uint64(zhp, prop, source);
break;
case ZFS_PROP_CREATETXG:
if (zhp->zfs_dmustats.dds_creation_txg != 0)
*val = zhp->zfs_dmustats.dds_creation_txg;
else
*val = getprop_uint64(zhp, prop, source);
break;
default: default:
switch (zfs_prop_get_type(prop)) { switch (zfs_prop_get_type(prop)) {
case PROP_TYPE_NUMBER: case PROP_TYPE_NUMBER:
@ -2458,7 +2435,7 @@ get_clones_cb(zfs_handle_t *zhp, void *arg)
} }
out: out:
(void) zfs_iter_children(zhp, 0, get_clones_cb, gca); (void) zfs_iter_children(zhp, get_clones_cb, gca);
zfs_close(zhp); zfs_close(zhp);
return (0); return (0);
} }
@ -2745,9 +2722,7 @@ zfs_prop_get(zfs_handle_t *zhp, zfs_prop_t prop, char *propbuf, size_t proplen,
break; break;
case ZFS_PROP_ORIGIN: case ZFS_PROP_ORIGIN:
str = (char *)&zhp->zfs_dmustats.dds_origin; str = getprop_string(zhp, prop, &source);
if (*str == '\0')
str = zfs_prop_default_string(prop);
if (str == NULL) if (str == NULL)
return (-1); return (-1);
(void) strlcpy(propbuf, str, proplen); (void) strlcpy(propbuf, str, proplen);
@ -3883,7 +3858,7 @@ zfs_check_snap_cb(zfs_handle_t *zhp, void *arg)
if (lzc_exists(name)) if (lzc_exists(name))
verify(nvlist_add_boolean(dd->nvl, name) == 0); verify(nvlist_add_boolean(dd->nvl, name) == 0);
rv = zfs_iter_filesystems(zhp, 0, zfs_check_snap_cb, dd); rv = zfs_iter_filesystems(zhp, zfs_check_snap_cb, dd);
zfs_close(zhp); zfs_close(zhp);
return (rv); return (rv);
} }
@ -4124,7 +4099,7 @@ zfs_snapshot_cb(zfs_handle_t *zhp, void *arg)
fnvlist_add_boolean(sd->sd_nvl, name); fnvlist_add_boolean(sd->sd_nvl, name);
rv = zfs_iter_filesystems(zhp, 0, zfs_snapshot_cb, sd); rv = zfs_iter_filesystems(zhp, zfs_snapshot_cb, sd);
} }
zfs_close(zhp); zfs_close(zhp);
@ -4299,7 +4274,7 @@ rollback_destroy(zfs_handle_t *zhp, void *data)
rollback_data_t *cbp = data; rollback_data_t *cbp = data;
if (zfs_prop_get_int(zhp, ZFS_PROP_CREATETXG) > cbp->cb_create) { if (zfs_prop_get_int(zhp, ZFS_PROP_CREATETXG) > cbp->cb_create) {
cbp->cb_error |= zfs_iter_dependents(zhp, 0, B_FALSE, cbp->cb_error |= zfs_iter_dependents(zhp, B_FALSE,
rollback_destroy_dependent, cbp); rollback_destroy_dependent, cbp);
cbp->cb_error |= zfs_destroy(zhp, B_FALSE); cbp->cb_error |= zfs_destroy(zhp, B_FALSE);
@ -4339,10 +4314,10 @@ zfs_rollback(zfs_handle_t *zhp, zfs_handle_t *snap, boolean_t force)
if (cb.cb_create > 0) if (cb.cb_create > 0)
min_txg = cb.cb_create; min_txg = cb.cb_create;
(void) zfs_iter_snapshots(zhp, 0, rollback_destroy, &cb, (void) zfs_iter_snapshots(zhp, B_FALSE, rollback_destroy, &cb,
min_txg, 0); min_txg, 0);
(void) zfs_iter_bookmarks(zhp, 0, rollback_destroy, &cb); (void) zfs_iter_bookmarks(zhp, rollback_destroy, &cb);
if (cb.cb_error) if (cb.cb_error)
return (-1); return (-1);
@ -4934,7 +4909,7 @@ zfs_hold_one(zfs_handle_t *zhp, void *arg)
fnvlist_add_string(ha->nvl, name, ha->tag); fnvlist_add_string(ha->nvl, name, ha->tag);
if (ha->recursive) if (ha->recursive)
rv = zfs_iter_filesystems(zhp, 0, zfs_hold_one, ha); rv = zfs_iter_filesystems(zhp, zfs_hold_one, ha);
zfs_close(zhp); zfs_close(zhp);
return (rv); return (rv);
} }
@ -5065,7 +5040,7 @@ zfs_release_one(zfs_handle_t *zhp, void *arg)
} }
if (ha->recursive) if (ha->recursive)
rv = zfs_iter_filesystems(zhp, 0, zfs_release_one, ha); rv = zfs_iter_filesystems(zhp, zfs_release_one, ha);
zfs_close(zhp); zfs_close(zhp);
return (rv); return (rv);
} }

View File

@ -104,7 +104,7 @@ top:
* Iterate over all child filesystems * Iterate over all child filesystems
*/ */
int int
zfs_iter_filesystems(zfs_handle_t *zhp, int flags, zfs_iter_f func, void *data) zfs_iter_filesystems(zfs_handle_t *zhp, zfs_iter_f func, void *data)
{ {
zfs_cmd_t zc = {"\0"}; zfs_cmd_t zc = {"\0"};
zfs_handle_t *nzhp; zfs_handle_t *nzhp;
@ -113,24 +113,19 @@ zfs_iter_filesystems(zfs_handle_t *zhp, int flags, zfs_iter_f func, void *data)
if (zhp->zfs_type != ZFS_TYPE_FILESYSTEM) if (zhp->zfs_type != ZFS_TYPE_FILESYSTEM)
return (0); return (0);
if ((flags & ZFS_ITER_SIMPLE) == ZFS_ITER_SIMPLE)
zc.zc_simple = B_TRUE;
if (zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0) != 0) if (zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0) != 0)
return (-1); return (-1);
while ((ret = zfs_do_list_ioctl(zhp, ZFS_IOC_DATASET_LIST_NEXT, while ((ret = zfs_do_list_ioctl(zhp, ZFS_IOC_DATASET_LIST_NEXT,
&zc)) == 0) { &zc)) == 0) {
if (zc.zc_simple)
nzhp = make_dataset_simple_handle_zc(zhp, &zc);
else
nzhp = make_dataset_handle_zc(zhp->zfs_hdl, &zc);
/* /*
* Silently ignore errors, as the only plausible explanation is * Silently ignore errors, as the only plausible explanation is
* that the pool has since been removed. * that the pool has since been removed.
*/ */
if (nzhp == NULL) if ((nzhp = make_dataset_handle_zc(zhp->zfs_hdl,
&zc)) == NULL) {
continue; continue;
}
if ((ret = func(nzhp, data)) != 0) { if ((ret = func(nzhp, data)) != 0) {
zcmd_free_nvlists(&zc); zcmd_free_nvlists(&zc);
@ -145,7 +140,7 @@ zfs_iter_filesystems(zfs_handle_t *zhp, int flags, zfs_iter_f func, void *data)
* Iterate over all snapshots * Iterate over all snapshots
*/ */
int int
zfs_iter_snapshots(zfs_handle_t *zhp, int flags, zfs_iter_f func, zfs_iter_snapshots(zfs_handle_t *zhp, boolean_t simple, zfs_iter_f func,
void *data, uint64_t min_txg, uint64_t max_txg) void *data, uint64_t min_txg, uint64_t max_txg)
{ {
zfs_cmd_t zc = {"\0"}; zfs_cmd_t zc = {"\0"};
@ -157,7 +152,7 @@ zfs_iter_snapshots(zfs_handle_t *zhp, int flags, zfs_iter_f func,
zhp->zfs_type == ZFS_TYPE_BOOKMARK) zhp->zfs_type == ZFS_TYPE_BOOKMARK)
return (0); return (0);
zc.zc_simple = (flags & ZFS_ITER_SIMPLE) != 0; zc.zc_simple = simple;
if (zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0) != 0) if (zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0) != 0)
return (-1); return (-1);
@ -182,7 +177,7 @@ zfs_iter_snapshots(zfs_handle_t *zhp, int flags, zfs_iter_f func,
while ((ret = zfs_do_list_ioctl(zhp, ZFS_IOC_SNAPSHOT_LIST_NEXT, while ((ret = zfs_do_list_ioctl(zhp, ZFS_IOC_SNAPSHOT_LIST_NEXT,
&zc)) == 0) { &zc)) == 0) {
if (zc.zc_simple) if (simple)
nzhp = make_dataset_simple_handle_zc(zhp, &zc); nzhp = make_dataset_simple_handle_zc(zhp, &zc);
else else
nzhp = make_dataset_handle_zc(zhp->zfs_hdl, &zc); nzhp = make_dataset_handle_zc(zhp->zfs_hdl, &zc);
@ -204,9 +199,8 @@ zfs_iter_snapshots(zfs_handle_t *zhp, int flags, zfs_iter_f func,
* Iterate over all bookmarks * Iterate over all bookmarks
*/ */
int int
zfs_iter_bookmarks(zfs_handle_t *zhp, int flags, zfs_iter_f func, void *data) zfs_iter_bookmarks(zfs_handle_t *zhp, zfs_iter_f func, void *data)
{ {
(void) flags;
zfs_handle_t *nzhp; zfs_handle_t *nzhp;
nvlist_t *props = NULL; nvlist_t *props = NULL;
nvlist_t *bmarks = NULL; nvlist_t *bmarks = NULL;
@ -312,8 +306,8 @@ zfs_snapshot_compare(const void *larg, const void *rarg)
} }
int int
zfs_iter_snapshots_sorted(zfs_handle_t *zhp, int flags, zfs_iter_f callback, zfs_iter_snapshots_sorted(zfs_handle_t *zhp, zfs_iter_f callback, void *data,
void *data, uint64_t min_txg, uint64_t max_txg) uint64_t min_txg, uint64_t max_txg)
{ {
int ret = 0; int ret = 0;
zfs_node_t *node; zfs_node_t *node;
@ -323,7 +317,7 @@ zfs_iter_snapshots_sorted(zfs_handle_t *zhp, int flags, zfs_iter_f callback,
avl_create(&avl, zfs_snapshot_compare, avl_create(&avl, zfs_snapshot_compare,
sizeof (zfs_node_t), offsetof(zfs_node_t, zn_avlnode)); sizeof (zfs_node_t), offsetof(zfs_node_t, zn_avlnode));
ret = zfs_iter_snapshots(zhp, flags, zfs_sort_snaps, &avl, min_txg, ret = zfs_iter_snapshots(zhp, B_FALSE, zfs_sort_snaps, &avl, min_txg,
max_txg); max_txg);
for (node = avl_first(&avl); node != NULL; node = AVL_NEXT(&avl, node)) for (node = avl_first(&avl); node != NULL; node = AVL_NEXT(&avl, node))
@ -386,7 +380,7 @@ snapspec_cb(zfs_handle_t *zhp, void *arg)
* return ENOENT at the end. * return ENOENT at the end.
*/ */
int int
zfs_iter_snapspec(zfs_handle_t *fs_zhp, int flags, const char *spec_orig, zfs_iter_snapspec(zfs_handle_t *fs_zhp, const char *spec_orig,
zfs_iter_f func, void *arg) zfs_iter_f func, void *arg)
{ {
char *buf, *comma_separated, *cp; char *buf, *comma_separated, *cp;
@ -426,7 +420,7 @@ zfs_iter_snapspec(zfs_handle_t *fs_zhp, int flags, const char *spec_orig,
} }
} }
err = zfs_iter_snapshots_sorted(fs_zhp, flags, err = zfs_iter_snapshots_sorted(fs_zhp,
snapspec_cb, &ssa, 0, 0); snapspec_cb, &ssa, 0, 0);
if (ret == 0) if (ret == 0)
ret = err; ret = err;
@ -463,14 +457,14 @@ zfs_iter_snapspec(zfs_handle_t *fs_zhp, int flags, const char *spec_orig,
* and as close as possible. * and as close as possible.
*/ */
int int
zfs_iter_children(zfs_handle_t *zhp, int flags, zfs_iter_f func, void *data) zfs_iter_children(zfs_handle_t *zhp, zfs_iter_f func, void *data)
{ {
int ret; int ret;
if ((ret = zfs_iter_snapshots(zhp, flags, func, data, 0, 0)) != 0) if ((ret = zfs_iter_snapshots(zhp, B_FALSE, func, data, 0, 0)) != 0)
return (ret); return (ret);
return (zfs_iter_filesystems(zhp, flags, func, data)); return (zfs_iter_filesystems(zhp, func, data));
} }
@ -481,7 +475,6 @@ typedef struct iter_stack_frame {
typedef struct iter_dependents_arg { typedef struct iter_dependents_arg {
boolean_t first; boolean_t first;
int flags;
boolean_t allowrecursion; boolean_t allowrecursion;
iter_stack_frame_t *stack; iter_stack_frame_t *stack;
zfs_iter_f func; zfs_iter_f func;
@ -531,10 +524,9 @@ iter_dependents_cb(zfs_handle_t *zhp, void *arg)
isf.zhp = zhp; isf.zhp = zhp;
isf.next = ida->stack; isf.next = ida->stack;
ida->stack = &isf; ida->stack = &isf;
err = zfs_iter_filesystems(zhp, ida->flags, err = zfs_iter_filesystems(zhp, iter_dependents_cb, ida);
iter_dependents_cb, ida);
if (err == 0) if (err == 0)
err = zfs_iter_snapshots(zhp, ida->flags, err = zfs_iter_snapshots(zhp, B_FALSE,
iter_dependents_cb, ida, 0, 0); iter_dependents_cb, ida, 0, 0);
ida->stack = isf.next; ida->stack = isf.next;
} }
@ -548,11 +540,10 @@ iter_dependents_cb(zfs_handle_t *zhp, void *arg)
} }
int int
zfs_iter_dependents(zfs_handle_t *zhp, int flags, boolean_t allowrecursion, zfs_iter_dependents(zfs_handle_t *zhp, boolean_t allowrecursion,
zfs_iter_f func, void *data) zfs_iter_f func, void *data)
{ {
iter_dependents_arg_t ida; iter_dependents_arg_t ida;
ida.flags = flags;
ida.allowrecursion = allowrecursion; ida.allowrecursion = allowrecursion;
ida.stack = NULL; ida.stack = NULL;
ida.func = func; ida.func = func;

View File

@ -1127,7 +1127,7 @@ zfs_iter_cb(zfs_handle_t *zhp, void *data)
} }
libzfs_add_handle(cbp, zhp); libzfs_add_handle(cbp, zhp);
if (zfs_iter_filesystems(zhp, 0, zfs_iter_cb, cbp) != 0) { if (zfs_iter_filesystems(zhp, zfs_iter_cb, cbp) != 0) {
zfs_close(zhp); zfs_close(zhp);
return (-1); return (-1);
} }
@ -1474,7 +1474,7 @@ zpool_enable_datasets(zpool_handle_t *zhp, const char *mntopts, int flags)
* over all child filesystems. * over all child filesystems.
*/ */
libzfs_add_handle(&cb, zfsp); libzfs_add_handle(&cb, zfsp);
if (zfs_iter_filesystems(zfsp, 0, zfs_iter_cb, &cb) != 0) if (zfs_iter_filesystems(zfsp, zfs_iter_cb, &cb) != 0)
goto out; goto out;
/* /*

View File

@ -597,7 +597,7 @@ send_iterate_fs(zfs_handle_t *zhp, void *arg)
min_txg = fromsnap_txg; min_txg = fromsnap_txg;
if (!sd->replicate && tosnap_txg != 0) if (!sd->replicate && tosnap_txg != 0)
max_txg = tosnap_txg; max_txg = tosnap_txg;
(void) zfs_iter_snapshots_sorted(zhp, 0, send_iterate_snap, sd, (void) zfs_iter_snapshots_sorted(zhp, send_iterate_snap, sd,
min_txg, max_txg); min_txg, max_txg);
} else { } else {
char snapname[MAXPATHLEN] = { 0 }; char snapname[MAXPATHLEN] = { 0 };
@ -640,7 +640,7 @@ send_iterate_fs(zfs_handle_t *zhp, void *arg)
/* iterate over children */ /* iterate over children */
if (sd->recursive) if (sd->recursive)
rv = zfs_iter_filesystems(zhp, 0, send_iterate_fs, sd); rv = zfs_iter_filesystems(zhp, send_iterate_fs, sd);
out: out:
sd->parent_fromsnap_guid = parent_fromsnap_guid_save; sd->parent_fromsnap_guid = parent_fromsnap_guid_save;
@ -1212,7 +1212,7 @@ dump_filesystem(zfs_handle_t *zhp, void *arg)
if (!sdd->replicate && sdd->tosnap != NULL) if (!sdd->replicate && sdd->tosnap != NULL)
max_txg = get_snap_txg(zhp->zfs_hdl, zhp->zfs_name, max_txg = get_snap_txg(zhp->zfs_hdl, zhp->zfs_name,
sdd->tosnap); sdd->tosnap);
rv = zfs_iter_snapshots_sorted(zhp, 0, dump_snapshot, arg, rv = zfs_iter_snapshots_sorted(zhp, dump_snapshot, arg,
min_txg, max_txg); min_txg, max_txg);
} else { } else {
char snapname[MAXPATHLEN] = { 0 }; char snapname[MAXPATHLEN] = { 0 };
@ -2959,9 +2959,9 @@ guid_to_name_cb(zfs_handle_t *zhp, void *arg)
return (EEXIST); return (EEXIST);
} }
err = zfs_iter_children(zhp, 0, guid_to_name_cb, gtnd); err = zfs_iter_children(zhp, guid_to_name_cb, gtnd);
if (err != EEXIST && gtnd->bookmark_ok) if (err != EEXIST && gtnd->bookmark_ok)
err = zfs_iter_bookmarks(zhp, 0, guid_to_name_cb, gtnd); err = zfs_iter_bookmarks(zhp, guid_to_name_cb, gtnd);
zfs_close(zhp); zfs_close(zhp);
return (err); return (err);
} }
@ -3015,10 +3015,9 @@ guid_to_name_redact_snaps(libzfs_handle_t *hdl, const char *parent,
continue; continue;
int err = guid_to_name_cb(zfs_handle_dup(zhp), &gtnd); int err = guid_to_name_cb(zfs_handle_dup(zhp), &gtnd);
if (err != EEXIST) if (err != EEXIST)
err = zfs_iter_children(zhp, 0, guid_to_name_cb, &gtnd); err = zfs_iter_children(zhp, guid_to_name_cb, &gtnd);
if (err != EEXIST && bookmark_ok) if (err != EEXIST && bookmark_ok)
err = zfs_iter_bookmarks(zhp, 0, guid_to_name_cb, err = zfs_iter_bookmarks(zhp, guid_to_name_cb, &gtnd);
&gtnd);
zfs_close(zhp); zfs_close(zhp);
if (err == EEXIST) if (err == EEXIST)
return (0); return (0);

View File

@ -2044,7 +2044,7 @@ zfs_ioc_objset_stats_impl(zfs_cmd_t *zc, objset_t *os)
dmu_objset_fast_stat(os, &zc->zc_objset_stats); dmu_objset_fast_stat(os, &zc->zc_objset_stats);
if (!zc->zc_simple && zc->zc_nvlist_dst != 0 && if (zc->zc_nvlist_dst != 0 &&
(error = dsl_prop_get_all(os, &nv)) == 0) { (error = dsl_prop_get_all(os, &nv)) == 0) {
dmu_objset_stats(os, nv); dmu_objset_stats(os, nv);
/* /*
@ -2331,7 +2331,6 @@ zfs_ioc_snapshot_list_next(zfs_cmd_t *zc)
} }
if (zc->zc_simple) { if (zc->zc_simple) {
dsl_dataset_fast_stat(ds, &zc->zc_objset_stats);
dsl_dataset_rele(ds, FTAG); dsl_dataset_rele(ds, FTAG);
break; break;
} }