summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Yao <[email protected]>2014-06-23 14:12:53 -0400
committerBrian Behlendorf <[email protected]>2014-09-30 10:46:58 -0700
commit2f3ec9006146844af6763d1fa4e823fd9047fd54 (patch)
treea522e90e82a26bce9d15565c7acff143ba26e778
parentaa0ac7caa438bf3981456c559d4224be104ccc7d (diff)
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 <[email protected]> Signed-off-by: Brian Behlendorf <[email protected]> Issue #2417
-rw-r--r--cmd/zpool/zpool_main.c27
1 files changed, 17 insertions, 10 deletions
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
@@ -486,6 +486,21 @@ add_prop_list(const char *propname, char *propval, nvlist_t **props,
}
/*
+ * 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] <pool> <vdev> ...
*
* -f Force addition of devices, even if they appear in use
@@ -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;