From 2f14adacaa8211f4d628f905986005246602b2ac Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Fri, 4 Feb 2022 20:52:10 +0100 Subject: [PATCH] zfs_set_prop_nvlist: make it easier to spot the call to dsl_props_set Reviewed-by: Brian Behlendorf Signed-off-by: Christian Schwarz Closes #12963 --- module/zfs/zfs_ioctl.c | 79 +++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 36 deletions(-) diff --git a/module/zfs/zfs_ioctl.c b/module/zfs/zfs_ioctl.c index e004410ea5..17eb7d497d 100644 --- a/module/zfs/zfs_ioctl.c +++ b/module/zfs/zfs_ioctl.c @@ -2558,6 +2558,7 @@ zfs_set_prop_nvlist(const char *dsname, zprop_source_t source, nvlist_t *nvl, nvpair_t *pair; nvpair_t *propval; int rv = 0; + int err; uint64_t intval; const char *strval; boolean_t should_update_mount_cache = B_FALSE; @@ -2569,7 +2570,7 @@ retry: while ((pair = nvlist_next_nvpair(nvl, pair)) != NULL) { const char *propname = nvpair_name(pair); zfs_prop_t prop = zfs_name_to_prop(propname); - int err = 0; + err = 0; /* decode the property value */ propval = pair; @@ -2668,47 +2669,53 @@ retry: goto retry; } - if (!nvlist_empty(genericnvl) && - dsl_props_set(dsname, source, genericnvl) != 0) { - /* - * If this fails, we still want to set as many properties as we - * can, so try setting them individually. - */ - pair = NULL; - while ((pair = nvlist_next_nvpair(genericnvl, pair)) != NULL) { - const char *propname = nvpair_name(pair); - int err = 0; + if (nvlist_empty(genericnvl)) + goto out; - propval = pair; - if (nvpair_type(pair) == DATA_TYPE_NVLIST) { - nvlist_t *attrs; - attrs = fnvpair_value_nvlist(pair); - propval = fnvlist_lookup_nvpair(attrs, - ZPROP_VALUE); - } + /* + * Try to set them all in one batch. + */ + err = dsl_props_set(dsname, source, genericnvl); + if (err == 0) + goto out; - if (nvpair_type(propval) == DATA_TYPE_STRING) { - strval = fnvpair_value_string(propval); - err = dsl_prop_set_string(dsname, propname, - source, strval); - } else if (nvpair_type(propval) == DATA_TYPE_BOOLEAN) { - err = dsl_prop_inherit(dsname, propname, - source); - } else { - intval = fnvpair_value_uint64(propval); - err = dsl_prop_set_int(dsname, propname, source, - intval); - } + /* + * If batching fails, we still want to set as many properties as we + * can, so try setting them individually. + */ + pair = NULL; + while ((pair = nvlist_next_nvpair(genericnvl, pair)) != NULL) { + const char *propname = nvpair_name(pair); + err = 0; - if (err != 0) { - if (errlist != NULL) { - fnvlist_add_int32(errlist, propname, - err); - } - rv = err; + propval = pair; + if (nvpair_type(pair) == DATA_TYPE_NVLIST) { + nvlist_t *attrs; + attrs = fnvpair_value_nvlist(pair); + propval = fnvlist_lookup_nvpair(attrs, ZPROP_VALUE); + } + + if (nvpair_type(propval) == DATA_TYPE_STRING) { + strval = fnvpair_value_string(propval); + err = dsl_prop_set_string(dsname, propname, + source, strval); + } else if (nvpair_type(propval) == DATA_TYPE_BOOLEAN) { + err = dsl_prop_inherit(dsname, propname, source); + } else { + intval = fnvpair_value_uint64(propval); + err = dsl_prop_set_int(dsname, propname, source, + intval); + } + + if (err != 0) { + if (errlist != NULL) { + fnvlist_add_int32(errlist, propname, err); } + rv = err; } } + +out: if (should_update_mount_cache) zfs_ioctl_update_mount_cache(dsname);