]> granicus.if.org Git - zfs/commitdiff
Add add_prop_list_default helper
authorRichard Yao <ryao@gentoo.org>
Mon, 23 Jun 2014 18:12:53 +0000 (14:12 -0400)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Tue, 30 Sep 2014 17:46:58 +0000 (10:46 -0700)
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 <ryao@gentoo.org>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue #2417

cmd/zpool/zpool_main.c

index d197e3d6420fdfd3c49956983f58438bad9ce164..d6fa8a82905f922a1baaa99645ea19eedb227301 100644 (file)
@@ -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] <pool> <vdev> ...
  *
@@ -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;