Skip to content

Commit

Permalink
Replace ZPROP_INVAL with ZPROP_USERPROP where it means a user property
Browse files Browse the repository at this point in the history
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Allan Jude <allan@klarasystems.com>
Sponsored-by: Klara Inc.
Closes openzfs#12676
  • Loading branch information
allanjude authored and andrewc12 committed Sep 23, 2022
1 parent 7c7f5c2 commit f7b4364
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 46 deletions.
6 changes: 3 additions & 3 deletions cmd/zfs/zfs_iter.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ zfs_add_sort_column(zfs_sort_column_t **sc, const char *name,
zfs_sort_column_t *col;
zfs_prop_t prop;

if ((prop = zfs_name_to_prop(name)) == ZPROP_INVAL &&
if ((prop = zfs_name_to_prop(name)) == ZPROP_USERPROP &&
!zfs_prop_user(name))
return (-1);

col = safe_malloc(sizeof (zfs_sort_column_t));

col->sc_prop = prop;
col->sc_reverse = reverse;
if (prop == ZPROP_INVAL) {
if (prop == ZPROP_USERPROP) {
col->sc_user_prop = safe_malloc(strlen(name) + 1);
(void) strcpy(col->sc_user_prop, name);
}
Expand Down Expand Up @@ -311,7 +311,7 @@ zfs_sort(const void *larg, const void *rarg, void *data)
* Otherwise, we compare 'lnum' and 'rnum'.
*/
lstr = rstr = NULL;
if (psc->sc_prop == ZPROP_INVAL) {
if (psc->sc_prop == ZPROP_USERPROP) {
nvlist_t *luser, *ruser;
nvlist_t *lval, *rval;

Expand Down
8 changes: 4 additions & 4 deletions cmd/zfs/zfs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1917,7 +1917,7 @@ get_callback(zfs_handle_t *zhp, void *data)
pl == cbp->cb_proplist)
continue;

if (pl->pl_prop != ZPROP_INVAL) {
if (pl->pl_prop != ZPROP_USERPROP) {
if (zfs_prop_get(zhp, pl->pl_prop, buf,
sizeof (buf), &sourcetype, source,
sizeof (source),
Expand Down Expand Up @@ -2307,7 +2307,7 @@ zfs_do_inherit(int argc, char **argv)
argc--;
argv++;

if ((prop = zfs_name_to_prop(propname)) != ZPROP_INVAL) {
if ((prop = zfs_name_to_prop(propname)) != ZPROP_USERPROP) {
if (zfs_prop_readonly(prop)) {
(void) fprintf(stderr, gettext(
"%s property is read-only\n"),
Expand Down Expand Up @@ -3443,7 +3443,7 @@ print_header(list_cbdata_t *cb)
}

right_justify = B_FALSE;
if (pl->pl_prop != ZPROP_INVAL) {
if (pl->pl_prop != ZPROP_USERPROP) {
header = zfs_prop_column_name(pl->pl_prop);
right_justify = zfs_prop_align_right(pl->pl_prop);
} else {
Expand Down Expand Up @@ -3494,7 +3494,7 @@ print_dataset(zfs_handle_t *zhp, list_cbdata_t *cb)
sizeof (property));
propstr = property;
right_justify = zfs_prop_align_right(pl->pl_prop);
} else if (pl->pl_prop != ZPROP_INVAL) {
} else if (pl->pl_prop != ZPROP_USERPROP) {
if (zfs_prop_get(zhp, pl->pl_prop, property,
sizeof (property), NULL, NULL, 0,
cb->cb_literal) != 0)
Expand Down
4 changes: 2 additions & 2 deletions cmd/zpool/zpool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5948,7 +5948,7 @@ print_header(list_cbdata_t *cb)
first = B_FALSE;

right_justify = B_FALSE;
if (pl->pl_prop != ZPROP_INVAL) {
if (pl->pl_prop != ZPROP_USERPROP) {
header = zpool_prop_column_name(pl->pl_prop);
right_justify = zpool_prop_align_right(pl->pl_prop);
} else {
Expand Down Expand Up @@ -6006,7 +6006,7 @@ print_pool(zpool_handle_t *zhp, list_cbdata_t *cb)
}

right_justify = B_FALSE;
if (pl->pl_prop != ZPROP_INVAL) {
if (pl->pl_prop != ZPROP_USERPROP) {
if (zpool_get_prop(zhp, pl->pl_prop, property,
sizeof (property), NULL, cb->cb_literal) != 0)
propstr = "-";
Expand Down
3 changes: 2 additions & 1 deletion include/sys/fs/zfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ typedef enum dmu_objset_type {
typedef enum {
ZPROP_CONT = -2,
ZPROP_INVAL = -1,
ZPROP_USERPROP = ZPROP_INVAL,
ZFS_PROP_TYPE = 0,
ZFS_PROP_CREATION,
ZFS_PROP_USED,
Expand Down Expand Up @@ -312,7 +313,7 @@ typedef int (*zprop_func)(int, void *);
*/
typedef enum {
VDEV_PROP_INVAL = -1,
#define VDEV_PROP_USER VDEV_PROP_INVAL
VDEV_PROP_USERPROP = VDEV_PROP_INVAL,
VDEV_PROP_NAME,
VDEV_PROP_CAPACITY,
VDEV_PROP_STATE,
Expand Down
22 changes: 12 additions & 10 deletions lib/libzfs/libzfs_dataset.c
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ zfs_valid_proplist(libzfs_handle_t *hdl, zfs_type_t type, nvlist_t *nvl,
const char *propname = nvpair_name(elem);

prop = zfs_name_to_prop(propname);
if (prop == ZPROP_INVAL && zfs_prop_user(propname)) {
if (prop == ZPROP_USERPROP && zfs_prop_user(propname)) {
/*
* This is a user property: make sure it's a
* string, and that it's less than ZAP_MAXNAMELEN.
Expand Down Expand Up @@ -1064,7 +1064,7 @@ zfs_valid_proplist(libzfs_handle_t *hdl, zfs_type_t type, nvlist_t *nvl,
goto error;
}

if (prop == ZPROP_INVAL && zfs_prop_userquota(propname)) {
if (prop == ZPROP_USERPROP && zfs_prop_userquota(propname)) {
zfs_userquota_prop_t uqtype;
char *newpropname = NULL;
char domain[128];
Expand Down Expand Up @@ -1146,7 +1146,8 @@ zfs_valid_proplist(libzfs_handle_t *hdl, zfs_type_t type, nvlist_t *nvl,
}
free(newpropname);
continue;
} else if (prop == ZPROP_INVAL && zfs_prop_written(propname)) {
} else if (prop == ZPROP_USERPROP &&
zfs_prop_written(propname)) {
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
"'%s' is readonly"),
propname);
Expand Down Expand Up @@ -1940,7 +1941,7 @@ zfs_prop_inherit(zfs_handle_t *zhp, const char *propname, boolean_t received)
"cannot inherit %s for '%s'"), propname, zhp->zfs_name);

zc.zc_cookie = received;
if ((prop = zfs_name_to_prop(propname)) == ZPROP_INVAL) {
if ((prop = zfs_name_to_prop(propname)) == ZPROP_USERPROP) {
/*
* For user properties, the amount of work we have to do is very
* small, so just do it here.
Expand Down Expand Up @@ -2359,7 +2360,7 @@ zfs_prop_get_recvd(zfs_handle_t *zhp, const char *propname, char *propbuf,

prop = zfs_name_to_prop(propname);

if (prop != ZPROP_INVAL) {
if (prop != ZPROP_USERPROP) {
uint64_t cookie;
if (!nvlist_exists(zhp->zfs_recvd_props, propname))
return (-1);
Expand Down Expand Up @@ -4643,7 +4644,7 @@ zfs_expand_proplist(zfs_handle_t *zhp, zprop_list_t **plp, boolean_t received,
*/
start = plp;
while (*start != NULL) {
if ((*start)->pl_prop == ZPROP_INVAL)
if ((*start)->pl_prop == ZPROP_USERPROP)
break;
start = &(*start)->pl_next;
}
Expand All @@ -4664,7 +4665,7 @@ zfs_expand_proplist(zfs_handle_t *zhp, zprop_list_t **plp, boolean_t received,
entry = zfs_alloc(hdl, sizeof (zprop_list_t));
entry->pl_user_prop =
zfs_strdup(hdl, nvpair_name(elem));
entry->pl_prop = ZPROP_INVAL;
entry->pl_prop = ZPROP_USERPROP;
entry->pl_width = strlen(nvpair_name(elem));
entry->pl_all = B_TRUE;
*last = entry;
Expand All @@ -4679,7 +4680,7 @@ zfs_expand_proplist(zfs_handle_t *zhp, zprop_list_t **plp, boolean_t received,
if (entry->pl_fixed && !literal)
continue;

if (entry->pl_prop != ZPROP_INVAL) {
if (entry->pl_prop != ZPROP_USERPROP) {
if (zfs_prop_get(zhp, entry->pl_prop,
buf, sizeof (buf), NULL, NULL, 0, literal) == 0) {
if (strlen(buf) > entry->pl_width)
Expand Down Expand Up @@ -4728,13 +4729,14 @@ zfs_prune_proplist(zfs_handle_t *zhp, uint8_t *props)
next = nvlist_next_nvpair(zhp->zfs_props, curr);

/*
* User properties will result in ZPROP_INVAL, and since we
* User properties will result in ZPROP_USERPROP (an alias
* for ZPROP_INVAL), and since we
* only know how to prune standard ZFS properties, we always
* leave these in the list. This can also happen if we
* encounter an unknown DSL property (when running older
* software, for example).
*/
if (zfs_prop != ZPROP_INVAL && props[zfs_prop] == B_FALSE)
if (zfs_prop != ZPROP_USERPROP && props[zfs_prop] == B_FALSE)
(void) nvlist_remove(zhp->zfs_props,
nvpair_name(curr), nvpair_type(curr));
curr = next;
Expand Down
12 changes: 6 additions & 6 deletions lib/libzfs/libzfs_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ zpool_expand_proplist(zpool_handle_t *zhp, zprop_list_t **plp,
for (i = 0; i < SPA_FEATURES; i++) {
zprop_list_t *entry = zfs_alloc(hdl,
sizeof (zprop_list_t));
entry->pl_prop = ZPROP_INVAL;
entry->pl_prop = ZPROP_USERPROP;
entry->pl_user_prop = zfs_asprintf(hdl, "feature@%s",
spa_feature_table[i].fi_uname);
entry->pl_width = strlen(entry->pl_user_prop);
Expand Down Expand Up @@ -897,7 +897,7 @@ zpool_expand_proplist(zpool_handle_t *zhp, zprop_list_t **plp,
}

entry = zfs_alloc(hdl, sizeof (zprop_list_t));
entry->pl_prop = ZPROP_INVAL;
entry->pl_prop = ZPROP_USERPROP;
entry->pl_user_prop = propname;
entry->pl_width = strlen(entry->pl_user_prop);
entry->pl_all = B_TRUE;
Expand All @@ -910,7 +910,7 @@ zpool_expand_proplist(zpool_handle_t *zhp, zprop_list_t **plp,
if (entry->pl_fixed && !literal)
continue;

if (entry->pl_prop != ZPROP_INVAL &&
if (entry->pl_prop != ZPROP_USERPROP &&
zpool_get_prop(zhp, entry->pl_prop, buf, sizeof (buf),
NULL, literal) == 0) {
if (strlen(buf) > entry->pl_width)
Expand Down Expand Up @@ -966,7 +966,7 @@ vdev_expand_proplist(zpool_handle_t *zhp, const char *vdevname,

/* Skip properties that are not user defined */
if ((prop = vdev_name_to_prop(propname)) !=
VDEV_PROP_USER)
VDEV_PROP_USERPROP)
continue;

if (nvpair_value_nvlist(elem, &propval) != 0)
Expand Down Expand Up @@ -5032,7 +5032,7 @@ zpool_get_vdev_prop_value(nvlist_t *nvprop, vdev_prop_t prop, char *prop_name,
uint64_t intval;
zprop_source_t src = ZPROP_SRC_NONE;

if (prop == VDEV_PROP_USER) {
if (prop == VDEV_PROP_USERPROP) {
/* user property, prop_name must contain the property name */
assert(prop_name != NULL);
if (nvlist_lookup_nvlist(nvprop, prop_name, &nv) == 0) {
Expand Down Expand Up @@ -5194,7 +5194,7 @@ zpool_get_vdev_prop(zpool_handle_t *zhp, const char *vdevname, vdev_prop_t prop,

fnvlist_add_uint64(reqnvl, ZPOOL_VDEV_PROPS_GET_VDEV, vdev_guid);

if (prop != VDEV_PROP_USER) {
if (prop != VDEV_PROP_USERPROP) {
/* prop_name overrides prop value */
if (prop_name != NULL)
prop = vdev_name_to_prop(prop_name);
Expand Down
2 changes: 1 addition & 1 deletion lib/libzfs/libzfs_sendrecv.c
Original file line number Diff line number Diff line change
Expand Up @@ -5107,7 +5107,7 @@ zfs_receive_checkprops(libzfs_handle_t *hdl, nvlist_t *props,
name = nvpair_name(nvp);
prop = zfs_name_to_prop(name);

if (prop == ZPROP_INVAL) {
if (prop == ZPROP_USERPROP) {
if (!zfs_prop_user(name)) {
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
"%s: invalid property '%s'"), errbuf, name);
Expand Down
6 changes: 3 additions & 3 deletions lib/libzfs/libzfs_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ zprop_print_headers(zprop_get_cbdata_t *cbp, zfs_type_t type)
/*
* 'PROPERTY' column
*/
if (pl->pl_prop != ZPROP_INVAL) {
if (pl->pl_prop != ZPROP_USERPROP) {
const char *propname = (type == ZFS_TYPE_POOL) ?
zpool_prop_to_name(pl->pl_prop) :
((type == ZFS_TYPE_VDEV) ?
Expand Down Expand Up @@ -1756,7 +1756,7 @@ addlist(libzfs_handle_t *hdl, const char *propname, zprop_list_t **listp,
* Return failure if no property table entry was found and this isn't
* a user-defined property.
*/
if (prop == ZPROP_INVAL && ((type == ZFS_TYPE_POOL &&
if (prop == ZPROP_USERPROP && ((type == ZFS_TYPE_POOL &&
!zpool_prop_feature(propname) &&
!zpool_prop_unsupported(propname)) ||
((type == ZFS_TYPE_DATASET) && !zfs_prop_user(propname) &&
Expand All @@ -1771,7 +1771,7 @@ addlist(libzfs_handle_t *hdl, const char *propname, zprop_list_t **listp,
zprop_list_t *entry = zfs_alloc(hdl, sizeof (*entry));

entry->pl_prop = prop;
if (prop == ZPROP_INVAL) {
if (prop == ZPROP_USERPROP) {
entry->pl_user_prop = zfs_strdup(hdl, propname);
entry->pl_width = strlen(propname);
} else {
Expand Down
10 changes: 5 additions & 5 deletions module/zfs/dsl_prop.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ dsl_prop_get_dd(dsl_dir_t *dd, const char *propname,
setpoint[0] = '\0';

prop = zfs_name_to_prop(propname);
inheritable = (prop == ZPROP_INVAL || zfs_prop_inheritable(prop));
inheritable = (prop == ZPROP_USERPROP || zfs_prop_inheritable(prop));
inheritstr = kmem_asprintf("%s%s", propname, ZPROP_INHERIT_SUFFIX);
recvdstr = kmem_asprintf("%s%s", propname, ZPROP_RECVD_SUFFIX);

Expand Down Expand Up @@ -168,7 +168,7 @@ dsl_prop_get_ds(dsl_dataset_t *ds, const char *propname,
uint64_t zapobj;

ASSERT(dsl_pool_config_held(ds->ds_dir->dd_pool));
inheritable = (prop == ZPROP_INVAL || zfs_prop_inheritable(prop));
inheritable = (prop == ZPROP_USERPROP || zfs_prop_inheritable(prop));
zapobj = dsl_dataset_phys(ds)->ds_props_obj;

if (zapobj != 0) {
Expand Down Expand Up @@ -1055,12 +1055,12 @@ dsl_prop_get_all_impl(objset_t *mos, uint64_t propobj,
prop = zfs_name_to_prop(propname);

/* Skip non-inheritable properties. */
if ((flags & DSL_PROP_GET_INHERITING) && prop != ZPROP_INVAL &&
!zfs_prop_inheritable(prop))
if ((flags & DSL_PROP_GET_INHERITING) &&
prop != ZPROP_USERPROP && !zfs_prop_inheritable(prop))
continue;

/* Skip properties not valid for this type. */
if ((flags & DSL_PROP_GET_SNAPSHOT) && prop != ZPROP_INVAL &&
if ((flags & DSL_PROP_GET_SNAPSHOT) && prop != ZPROP_USERPROP &&
!zfs_prop_valid_for_type(prop, ZFS_TYPE_SNAPSHOT, B_FALSE))
continue;

Expand Down
6 changes: 3 additions & 3 deletions module/zfs/vdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -5514,7 +5514,7 @@ vdev_props_set_sync(void *arg, dmu_tx_t *tx)
}

switch (prop = vdev_name_to_prop(propname)) {
case VDEV_PROP_USER:
case VDEV_PROP_USERPROP:
if (vdev_prop_user(propname)) {
strval = fnvpair_value_string(elem);
if (strlen(strval) == 0) {
Expand Down Expand Up @@ -5598,7 +5598,7 @@ vdev_prop_set(vdev_t *vd, nvlist_t *innvl, nvlist_t *outnvl)
uint64_t intval = 0;
char *strval = NULL;

if (prop == VDEV_PROP_USER && !vdev_prop_user(propname)) {
if (prop == VDEV_PROP_USERPROP && !vdev_prop_user(propname)) {
error = EINVAL;
goto end;
}
Expand Down Expand Up @@ -5955,7 +5955,7 @@ vdev_prop_get(vdev_t *vd, nvlist_t *innvl, nvlist_t *outnvl)
case VDEV_PROP_COMMENT:
/* Exists in the ZAP below */
/* FALLTHRU */
case VDEV_PROP_USER:
case VDEV_PROP_USERPROP:
/* User Properites */
src = ZPROP_SRC_LOCAL;

Expand Down
2 changes: 1 addition & 1 deletion module/zfs/zcp_synctask.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ zcp_synctask_inherit_prop_check(void *arg, dmu_tx_t *tx)
zcp_inherit_prop_arg_t *args = arg;
zfs_prop_t prop = zfs_name_to_prop(args->zipa_prop);

if (prop == ZPROP_INVAL) {
if (prop == ZPROP_USERPROP) {
if (zfs_prop_user(args->zipa_prop))
return (0);

Expand Down
Loading

0 comments on commit f7b4364

Please sign in to comment.