Skip to content

Commit

Permalink
Revert "zfs list: Allow more fields in ZFS_ITER_SIMPLE mode"
Browse files Browse the repository at this point in the history
This reverts commit f6a0dac.

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
  • Loading branch information
pcd1193182 authored Jan 6, 2022
1 parent 0175272 commit 399b981
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 188 deletions.
64 changes: 8 additions & 56 deletions cmd/zfs/zfs_iter.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,19 @@ zfs_callback(zfs_handle_t *zhp, void *data)
(cb->cb_types &
(ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME))) &&
zfs_get_type(zhp) == ZFS_TYPE_FILESYSTEM) {
(void) zfs_iter_filesystems(zhp, cb->cb_flags,
zfs_callback, data);
(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,
(void) zfs_iter_snapshots(zhp,
(cb->cb_flags & ZFS_ITER_SIMPLE) != 0,
zfs_callback, data, 0, 0);
}

if (((zfs_get_type(zhp) & (ZFS_TYPE_SNAPSHOT |
ZFS_TYPE_BOOKMARK)) == 0) && include_bmarks) {
(void) zfs_iter_bookmarks(zhp, cb->cb_flags,
zfs_callback, data);
(void) zfs_iter_bookmarks(zhp, zfs_callback, data);
}

cb->cb_depth--;
Expand Down Expand Up @@ -213,58 +212,11 @@ zfs_free_sort_columns(zfs_sort_column_t *sc)
}
}

/*
* Return true if all of the properties to be sorted are populated by
* 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) {
switch (sc->sc_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);
}
sc = sc->sc_next;
}

return (B_TRUE);
}

boolean_t
zfs_list_only_by_fast(const zprop_list_t *p)
int
zfs_sort_only_by_name(const zfs_sort_column_t *sc)
{
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);
return (sc != NULL && sc->sc_next == NULL &&
sc->sc_prop == ZFS_PROP_NAME);
}

static int
Expand Down
12 changes: 9 additions & 3 deletions cmd/zfs/zfs_iter.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,19 @@ typedef struct zfs_sort_column {
boolean_t sc_reverse;
} 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,
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);
void zfs_free_sort_columns(zfs_sort_column_t *);
boolean_t zfs_sort_only_by_fast(const zfs_sort_column_t *);
boolean_t zfs_list_only_by_fast(const zprop_list_t *);

int zfs_sort_only_by_name(const zfs_sort_column_t *);

#ifdef __cplusplus
}
Expand Down
43 changes: 20 additions & 23 deletions cmd/zfs/zfs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1536,7 +1536,7 @@ destroy_print_snapshots(zfs_handle_t *fs_zhp, destroy_cbdata_t *cb)
int err;
assert(cb->cb_firstsnap == 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) {
uint64_t used = 0;
if (err == 0) {
Expand All @@ -1562,7 +1562,7 @@ snapshot_to_nvl_cb(zfs_handle_t *zhp, void *arg)
if (!cb->cb_doclones && !cb->cb_defer_destroy) {
cb->cb_target = zhp;
cb->cb_first = B_TRUE;
err = zfs_iter_dependents(zhp, 0, B_TRUE,
err = zfs_iter_dependents(zhp, B_TRUE,
destroy_check_dependent, cb);
}

Expand All @@ -1580,8 +1580,7 @@ gather_snapshots(zfs_handle_t *zhp, void *arg)
destroy_cbdata_t *cb = arg;
int err = 0;

err = zfs_iter_snapspec(zhp, 0, cb->cb_snapspec,
snapshot_to_nvl_cb, cb);
err = zfs_iter_snapspec(zhp, cb->cb_snapspec, snapshot_to_nvl_cb, cb);
if (err == ENOENT)
err = 0;
if (err != 0)
Expand All @@ -1594,7 +1593,7 @@ gather_snapshots(zfs_handle_t *zhp, void *arg)
}

if (cb->cb_recurse)
err = zfs_iter_filesystems(zhp, 0, gather_snapshots, cb);
err = zfs_iter_filesystems(zhp, gather_snapshots, cb);

out:
zfs_close(zhp);
Expand All @@ -1619,7 +1618,7 @@ destroy_clones(destroy_cbdata_t *cb)
* false while destroying the clones.
*/
cb->cb_defer_destroy = B_FALSE;
err = zfs_iter_dependents(zhp, 0, B_FALSE,
err = zfs_iter_dependents(zhp, B_FALSE,
destroy_callback, cb);
cb->cb_defer_destroy = defer;
zfs_close(zhp);
Expand Down Expand Up @@ -1830,7 +1829,7 @@ zfs_do_destroy(int argc, char **argv)
*/
cb.cb_first = B_TRUE;
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) {
rv = 1;
goto out;
Expand All @@ -1841,7 +1840,7 @@ zfs_do_destroy(int argc, char **argv)
goto out;
}
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) {
rv = 1;
goto out;
Expand Down Expand Up @@ -3705,6 +3704,13 @@ zfs_do_list(int argc, char **argv)
if (fields == NULL)
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.
*/
Expand Down Expand Up @@ -3732,15 +3738,6 @@ zfs_do_list(int argc, char **argv)

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,
limit, list_callback, &cb);

Expand Down Expand Up @@ -4051,7 +4048,7 @@ rollback_check(zfs_handle_t *zhp, void *data)
}

if (cbp->cb_recurse) {
if (zfs_iter_dependents(zhp, 0, B_TRUE,
if (zfs_iter_dependents(zhp, B_TRUE,
rollback_check_dependent, cbp) != 0) {
zfs_close(zhp);
return (-1);
Expand Down Expand Up @@ -4150,10 +4147,10 @@ zfs_do_rollback(int argc, char **argv)
if (cb.cb_create > 0)
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)
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;

if ((ret = cb.cb_error) != 0)
Expand Down Expand Up @@ -4295,7 +4292,7 @@ zfs_snapshot_cb(zfs_handle_t *zhp, void *arg)
free(name);

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);
return (rv);
}
Expand Down Expand Up @@ -6281,7 +6278,7 @@ zfs_do_allow_unallow_impl(int argc, char **argv, boolean_t un)

if (un && opts.recursive) {
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)
goto cleanup0;
}
Expand Down Expand Up @@ -6644,7 +6641,7 @@ get_one_dataset(zfs_handle_t *zhp, void *data)
/*
* 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);
return (1);
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/zpool/zpool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8807,7 +8807,7 @@ check_unsupp_fs(zfs_handle_t *zhp, void *unsupp_fs)
(*count)++;
}

zfs_iter_filesystems(zhp, 0, check_unsupp_fs, unsupp_fs);
zfs_iter_filesystems(zhp, check_unsupp_fs, unsupp_fs);

zfs_close(zhp);

Expand Down
2 changes: 1 addition & 1 deletion contrib/pam_zfs_key/pam_zfs_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ zfs_key_config_get_dataset(zfs_key_config_t *config)
return (NULL);
}

(void) zfs_iter_filesystems(zhp, 0, find_dsname_by_prop_value,
(void) zfs_iter_filesystems(zhp, find_dsname_by_prop_value,
config);
zfs_close(zhp);
char *dsname = config->dsname;
Expand Down
22 changes: 7 additions & 15 deletions include/libzfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -644,27 +644,19 @@ _LIBZFS_H void zprop_print_one_property(const char *, zprop_get_cbdata_t *,
/*
* 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 *);
_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_dependents(zfs_handle_t *, int, boolean_t, zfs_iter_f,
_LIBZFS_H int zfs_iter_children(zfs_handle_t *, zfs_iter_f, void *);
_LIBZFS_H int zfs_iter_dependents(zfs_handle_t *, boolean_t, zfs_iter_f,
void *);
_LIBZFS_H int zfs_iter_filesystems(zfs_handle_t *, int, zfs_iter_f, void *);
_LIBZFS_H int zfs_iter_snapshots(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 *, boolean_t, zfs_iter_f, void *,
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);
_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 *);
_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 *);

typedef struct get_all_cb {
Expand Down
8 changes: 1 addition & 7 deletions lib/libzfs/libzfs.abi
Original file line number Diff line number Diff line change
Expand Up @@ -4025,14 +4025,13 @@
<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'>
<parameter type-id='9200a744' name='zhp'/>
<parameter type-id='95e97e5e' name='flags'/>
<parameter type-id='d8e49ab9' name='func'/>
<parameter type-id='eaa32e2f' name='data'/>
<return type-id='95e97e5e'/>
</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'>
<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='eaa32e2f' name='data'/>
<parameter type-id='9c313c2d' name='min_txg'/>
Expand All @@ -4041,14 +4040,12 @@
</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'>
<parameter type-id='9200a744' name='zhp'/>
<parameter type-id='95e97e5e' name='flags'/>
<parameter type-id='d8e49ab9' name='func'/>
<parameter type-id='eaa32e2f' name='data'/>
<return type-id='95e97e5e'/>
</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'>
<parameter type-id='9200a744' name='zhp'/>
<parameter type-id='95e97e5e' name='flags'/>
<parameter type-id='d8e49ab9' name='callback'/>
<parameter type-id='eaa32e2f' name='data'/>
<parameter type-id='9c313c2d' name='min_txg'/>
Expand All @@ -4057,22 +4054,19 @@
</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'>
<parameter type-id='9200a744' name='fs_zhp'/>
<parameter type-id='95e97e5e' name='flags'/>
<parameter type-id='80f4b756' name='spec_orig'/>
<parameter type-id='d8e49ab9' name='func'/>
<parameter type-id='eaa32e2f' name='arg'/>
<return type-id='95e97e5e'/>
</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'>
<parameter type-id='9200a744' name='zhp'/>
<parameter type-id='95e97e5e' name='flags'/>
<parameter type-id='d8e49ab9' name='func'/>
<parameter type-id='eaa32e2f' name='data'/>
<return type-id='95e97e5e'/>
</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'>
<parameter type-id='9200a744' name='zhp'/>
<parameter type-id='95e97e5e' name='flags'/>
<parameter type-id='c19b74c3' name='allowrecursion'/>
<parameter type-id='d8e49ab9' name='func'/>
<parameter type-id='eaa32e2f' name='data'/>
Expand Down
6 changes: 3 additions & 3 deletions lib/libzfs/libzfs_changelist.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ change_one(zfs_handle_t *zhp, void *data)
}

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
Expand Down Expand Up @@ -721,11 +721,11 @@ changelist_gather(zfs_handle_t *zhp, zfs_prop_t prop, int gather_flags,
return (NULL);
}
} 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);
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);
return (NULL);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/libzfs/libzfs_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ load_keys_cb(zfs_handle_t *zhp, void *arg)
cb->cb_numfailed++;

out:
(void) zfs_iter_filesystems(zhp, 0, load_keys_cb, cb);
(void) zfs_iter_filesystems(zhp, load_keys_cb, cb);
zfs_close(zhp);

/* always return 0, since this function is best effort */
Expand Down
Loading

0 comments on commit 399b981

Please sign in to comment.