zfs list: Allow more fields in ZFS_ITER_SIMPLE mode

If the fields to be listed and sorted by are constrained
to those populated by dsl_dataset_fast_stat(), then
zfs list is much faster, as it does not need to open each
objset and reads its properties.

A previous optimization by Pawel Dawidek
(0cee24064a) took advantage
of this to make listing snapshot names sorted only by name
much faster.

However, it was limited to `-o name -s name`, this work
extends this optimization to work with:
  - name
  - guid
  - createtxg
  - numclones
  - inconsistent
  - redacted
  - origin
and could be further extended to any other properties
supported by dsl_dataset_fast_stat() or similar, that do
not require extra locking or reading from disk.

Reviewed-by: Mark Maybee <mark.maybee@delphix.com>
Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Pawel Jakub Dawidek <pawel@dawidek.net>
Signed-off-by: Allan Jude <allan@klarasystems.com>
Closes #11080
This commit is contained in:
Allan Jude
2021-12-16 14:56:22 -05:00
committed by GitHub
parent 2300621dc7
commit f6a0dac84a
14 changed files with 189 additions and 95 deletions
+38 -13
View File
@@ -529,9 +529,17 @@ make_dataset_simple_handle_zc(zfs_handle_t *pzhp, zfs_cmd_t *zc)
zhp->zfs_hdl = pzhp->zfs_hdl;
(void) strlcpy(zhp->zfs_name, zc->zc_name, sizeof (zhp->zfs_name));
zhp->zfs_head_type = pzhp->zfs_type;
zhp->zfs_type = ZFS_TYPE_SNAPSHOT;
zhp->zpool_hdl = zpool_handle(zhp);
zhp->zfs_dmustats = zc->zc_objset_stats; /* structure assignment */
zhp->zfs_head_type = pzhp->zfs_type;
if (zhp->zfs_dmustats.dds_is_snapshot)
zhp->zfs_type = ZFS_TYPE_SNAPSHOT;
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);
}
@@ -737,7 +745,7 @@ zfs_open(libzfs_handle_t *hdl, const char *path, int types)
* Iterate bookmarks to find the right one.
*/
errno = 0;
if ((zfs_iter_bookmarks(pzhp, zfs_open_bookmarks_cb,
if ((zfs_iter_bookmarks(pzhp, 0, zfs_open_bookmarks_cb,
&cb_data) == 0) && (cb_data.zhp == NULL)) {
(void) zfs_error(hdl, EZFS_NOENT, errbuf);
zfs_close(pzhp);
@@ -2087,7 +2095,8 @@ getprop_string(zfs_handle_t *zhp, zfs_prop_t prop, char **source)
static boolean_t
zfs_is_recvd_props_mode(zfs_handle_t *zhp)
{
return (zhp->zfs_props == zhp->zfs_recvd_props);
return (zhp->zfs_props != NULL &&
zhp->zfs_props == zhp->zfs_recvd_props);
}
static void
@@ -2292,6 +2301,20 @@ get_numeric_property(zfs_handle_t *zhp, zfs_prop_t prop, zprop_source_t *src,
*val = zhp->zfs_dmustats.dds_redacted;
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:
switch (zfs_prop_get_type(prop)) {
case PROP_TYPE_NUMBER:
@@ -2435,7 +2458,7 @@ get_clones_cb(zfs_handle_t *zhp, void *arg)
}
out:
(void) zfs_iter_children(zhp, get_clones_cb, gca);
(void) zfs_iter_children(zhp, 0, get_clones_cb, gca);
zfs_close(zhp);
return (0);
}
@@ -2722,7 +2745,9 @@ zfs_prop_get(zfs_handle_t *zhp, zfs_prop_t prop, char *propbuf, size_t proplen,
break;
case ZFS_PROP_ORIGIN:
str = getprop_string(zhp, prop, &source);
str = (char *)&zhp->zfs_dmustats.dds_origin;
if (*str == '\0')
str = zfs_prop_default_string(prop);
if (str == NULL)
return (-1);
(void) strlcpy(propbuf, str, proplen);
@@ -3857,7 +3882,7 @@ zfs_check_snap_cb(zfs_handle_t *zhp, void *arg)
if (lzc_exists(name))
verify(nvlist_add_boolean(dd->nvl, name) == 0);
rv = zfs_iter_filesystems(zhp, zfs_check_snap_cb, dd);
rv = zfs_iter_filesystems(zhp, 0, zfs_check_snap_cb, dd);
zfs_close(zhp);
return (rv);
}
@@ -4098,7 +4123,7 @@ zfs_snapshot_cb(zfs_handle_t *zhp, void *arg)
fnvlist_add_boolean(sd->sd_nvl, name);
rv = zfs_iter_filesystems(zhp, zfs_snapshot_cb, sd);
rv = zfs_iter_filesystems(zhp, 0, zfs_snapshot_cb, sd);
}
zfs_close(zhp);
@@ -4273,7 +4298,7 @@ rollback_destroy(zfs_handle_t *zhp, void *data)
rollback_data_t *cbp = data;
if (zfs_prop_get_int(zhp, ZFS_PROP_CREATETXG) > cbp->cb_create) {
cbp->cb_error |= zfs_iter_dependents(zhp, B_FALSE,
cbp->cb_error |= zfs_iter_dependents(zhp, 0, B_FALSE,
rollback_destroy_dependent, cbp);
cbp->cb_error |= zfs_destroy(zhp, B_FALSE);
@@ -4313,10 +4338,10 @@ zfs_rollback(zfs_handle_t *zhp, zfs_handle_t *snap, boolean_t force)
if (cb.cb_create > 0)
min_txg = cb.cb_create;
(void) zfs_iter_snapshots(zhp, B_FALSE, rollback_destroy, &cb,
(void) zfs_iter_snapshots(zhp, 0, rollback_destroy, &cb,
min_txg, 0);
(void) zfs_iter_bookmarks(zhp, rollback_destroy, &cb);
(void) zfs_iter_bookmarks(zhp, 0, rollback_destroy, &cb);
if (cb.cb_error)
return (-1);
@@ -4908,7 +4933,7 @@ zfs_hold_one(zfs_handle_t *zhp, void *arg)
fnvlist_add_string(ha->nvl, name, ha->tag);
if (ha->recursive)
rv = zfs_iter_filesystems(zhp, zfs_hold_one, ha);
rv = zfs_iter_filesystems(zhp, 0, zfs_hold_one, ha);
zfs_close(zhp);
return (rv);
}
@@ -5039,7 +5064,7 @@ zfs_release_one(zfs_handle_t *zhp, void *arg)
}
if (ha->recursive)
rv = zfs_iter_filesystems(zhp, zfs_release_one, ha);
rv = zfs_iter_filesystems(zhp, 0, zfs_release_one, ha);
zfs_close(zhp);
return (rv);
}