From: Richard Yao Date: Mon, 23 Jun 2014 18:12:53 +0000 (-0400) Subject: Add add_prop_list_default helper X-Git-Tag: zfs-0.6.4~149 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2f3ec9006146844af6763d1fa4e823fd9047fd54;p=zfs Add add_prop_list_default helper Adding to a property list only if there is no existing value is used twice. Once by zpool create -R and again by zpool import -R. Now that zpool create -t and zpool import -t also need it, lets refactor it into a helper function to make the code more readable. Signed-off-by: Richard Yao Signed-off-by: Brian Behlendorf Issue #2417 --- diff --git a/cmd/zpool/zpool_main.c b/cmd/zpool/zpool_main.c index d197e3d64..d6fa8a829 100644 --- a/cmd/zpool/zpool_main.c +++ b/cmd/zpool/zpool_main.c @@ -485,6 +485,21 @@ add_prop_list(const char *propname, char *propval, nvlist_t **props, return (0); } +/* + * Set a default property pair (name, string-value) in a property nvlist + */ +static int +add_prop_list_default(const char *propname, char *propval, nvlist_t **props, + boolean_t poolprop) +{ + char *pval; + + if (nvlist_lookup_string(*props, propname, &pval) == 0) + return (0); + + return (add_prop_list(propname, propval, props, B_TRUE)); +} + /* * zpool add [-fn] [-o property=value] ... * @@ -823,11 +838,7 @@ zpool_do_create(int argc, char **argv) if (add_prop_list(zpool_prop_to_name( ZPOOL_PROP_ALTROOT), optarg, &props, B_TRUE)) goto errout; - if (nvlist_lookup_string(props, - zpool_prop_to_name(ZPOOL_PROP_CACHEFILE), - &propval) == 0) - break; - if (add_prop_list(zpool_prop_to_name( + if (add_prop_list_default(zpool_prop_to_name( ZPOOL_PROP_CACHEFILE), "none", &props, B_TRUE)) goto errout; break; @@ -2068,11 +2079,7 @@ zpool_do_import(int argc, char **argv) if (add_prop_list(zpool_prop_to_name( ZPOOL_PROP_ALTROOT), optarg, &props, B_TRUE)) goto error; - if (nvlist_lookup_string(props, - zpool_prop_to_name(ZPOOL_PROP_CACHEFILE), - &propval) == 0) - break; - if (add_prop_list(zpool_prop_to_name( + if (add_prop_list_default(zpool_prop_to_name( ZPOOL_PROP_CACHEFILE), "none", &props, B_TRUE)) goto error; break;