mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-12-25 18:59:33 +03:00
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 <ryao@gentoo.org> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Issue #2417
This commit is contained in:
parent
aa0ac7caa4
commit
2f3ec90061
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user