diff options
author | Brian Behlendorf <behlendorf1@llnl.gov> | 2018-01-19 09:22:37 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-19 09:22:37 -0800 |
commit | 31864e3d8c9fc762d4c30324d9a061f4ed009446 (patch) | |
tree | aa46e0178efcbd829a3d83a4a9531d4495d45b5a | |
parent | 1574c73bd0680cf3141e26627191120daba3fe8d (diff) |
OpenZFS 8652 - Tautological comparisons with ZPROP_INVAL
usr/src/uts/common/sys/fs/zfs.h
Change ZPROP_INVAL and ZPROP_CONT from macros to enum values. Clang
and GCC both prefer to use unsigned ints to store enums. That was
causing tautological comparison warnings (and likely eliminating
error handling code at compile time) whenever a zfs_prop_t or
zpool_prop_t was compared to ZPROP_INVAL or ZPROP_CONT. Making the
error flags be explicity enum values forces the enum types to be
signed.
ZPROP_INVAL was also compared against two different enum types. I
had to change its name to ZPOOL_PROP_INVAL whenever its compared to
a zpool_prop_t. There are still some places where ZPROP_INVAL or
ZPROP_CONT is compared to a plain int, in code that doesn't know
whether the int is storing a zfs_prop_t or a zpool_prop_t.
usr/src/uts/common/fs/zfs/spa.c
s/ZPROP_INVAL/ZPOOL_PROP_INVAL/
Authored by: Alan Somers <asomers@gmail.com>
Approved by: Gordon Ross <gwr@nexenta.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Igor Kozhukhov <igor@dilos.org>
Reviewed by: George Melikov <mail@gmelikov.ru>
Ported-by: Brian Behlendorf <behlendorf1@llnl.gov>
OpenZFS-issue: https://www.illumos.org/issues/8652
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/c2de80dc74
Closes #7061
-rw-r--r-- | cmd/zpool/zpool_main.c | 6 | ||||
-rw-r--r-- | include/sys/fs/zfs.h | 7 | ||||
-rw-r--r-- | lib/libzfs/libzfs_pool.c | 4 | ||||
-rw-r--r-- | module/zfs/spa.c | 13 |
4 files changed, 14 insertions, 16 deletions
diff --git a/cmd/zpool/zpool_main.c b/cmd/zpool/zpool_main.c index 2293e79df..4905927fc 100644 --- a/cmd/zpool/zpool_main.c +++ b/cmd/zpool/zpool_main.c @@ -511,7 +511,7 @@ static int add_prop_list(const char *propname, char *propval, nvlist_t **props, boolean_t poolprop) { - zpool_prop_t prop = ZPROP_INVAL; + zpool_prop_t prop = ZPOOL_PROP_INVAL; zfs_prop_t fprop; nvlist_t *proplist; const char *normnm; @@ -529,7 +529,7 @@ add_prop_list(const char *propname, char *propval, nvlist_t **props, if (poolprop) { const char *vname = zpool_prop_to_name(ZPOOL_PROP_VERSION); - if ((prop = zpool_name_to_prop(propname)) == ZPROP_INVAL && + if ((prop = zpool_name_to_prop(propname)) == ZPOOL_PROP_INVAL && !zpool_prop_feature(propname)) { (void) fprintf(stderr, gettext("property '%s' is " "not a valid pool property\n"), propname); @@ -540,7 +540,7 @@ add_prop_list(const char *propname, char *propval, nvlist_t **props, * feature@ properties and version should not be specified * at the same time. */ - if ((prop == ZPROP_INVAL && zpool_prop_feature(propname) && + if ((prop == ZPOOL_PROP_INVAL && zpool_prop_feature(propname) && nvlist_exists(proplist, vname)) || (prop == ZPOOL_PROP_VERSION && prop_list_contains_feature(proplist))) { diff --git a/include/sys/fs/zfs.h b/include/sys/fs/zfs.h index 473e50082..6b1c3bb56 100644 --- a/include/sys/fs/zfs.h +++ b/include/sys/fs/zfs.h @@ -88,7 +88,8 @@ typedef enum dmu_objset_type { * the property table in module/zcommon/zfs_prop.c. */ typedef enum { - ZFS_PROP_BAD = -1, + ZPROP_CONT = -2, + ZPROP_INVAL = -1, ZFS_PROP_TYPE = 0, ZFS_PROP_CREATION, ZFS_PROP_USED, @@ -203,6 +204,7 @@ extern const char *zfs_userquota_prop_prefixes[ZFS_NUM_USERQUOTA_PROPS]; * the property table in module/zcommon/zpool_prop.c. */ typedef enum { + ZPOOL_PROP_INVAL = -1, ZPOOL_PROP_NAME, ZPOOL_PROP_SIZE, ZPOOL_PROP_CAPACITY, @@ -238,9 +240,6 @@ typedef enum { /* Small enough to not hog a whole line of printout in zpool(1M). */ #define ZPROP_MAX_COMMENT 32 -#define ZPROP_CONT -2 -#define ZPROP_INVAL -1 - #define ZPROP_VALUE "value" #define ZPROP_SOURCE "source" diff --git a/lib/libzfs/libzfs_pool.c b/lib/libzfs/libzfs_pool.c index c15f5c8a0..5f1414271 100644 --- a/lib/libzfs/libzfs_pool.c +++ b/lib/libzfs/libzfs_pool.c @@ -460,7 +460,7 @@ zpool_valid_proplist(libzfs_handle_t *hdl, const char *poolname, const char *propname = nvpair_name(elem); prop = zpool_name_to_prop(propname); - if (prop == ZPROP_INVAL && zpool_prop_feature(propname)) { + if (prop == ZPOOL_PROP_INVAL && zpool_prop_feature(propname)) { int err; char *fname = strchr(propname, '@') + 1; @@ -500,7 +500,7 @@ zpool_valid_proplist(libzfs_handle_t *hdl, const char *poolname, /* * Make sure this property is valid and applies to this type. */ - if (prop == ZPROP_INVAL) { + if (prop == ZPOOL_PROP_INVAL) { zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "invalid property '%s'"), propname); (void) zfs_error(hdl, EZFS_BADPROP, errbuf); diff --git a/module/zfs/spa.c b/module/zfs/spa.c index 75b928620..dac042464 100644 --- a/module/zfs/spa.c +++ b/module/zfs/spa.c @@ -353,7 +353,7 @@ spa_prop_get(spa_t *spa, nvlist_t **nvp) zprop_source_t src = ZPROP_SRC_DEFAULT; zpool_prop_t prop; - if ((prop = zpool_name_to_prop(za.za_name)) == ZPROP_INVAL) + if ((prop = zpool_name_to_prop(za.za_name)) == ZPOOL_PROP_INVAL) continue; switch (za.za_integer_length) { @@ -440,8 +440,8 @@ spa_prop_validate(spa_t *spa, nvlist_t *props) const char *propname = nvpair_name(elem); zpool_prop_t prop = zpool_name_to_prop(propname); - switch ((int)prop) { - case ZPROP_INVAL: + switch (prop) { + case ZPOOL_PROP_INVAL: if (!zpool_prop_feature(propname)) { error = SET_ERROR(EINVAL); break; @@ -698,7 +698,7 @@ spa_prop_set(spa_t *spa, nvlist_t *nvp) prop == ZPOOL_PROP_READONLY) continue; - if (prop == ZPOOL_PROP_VERSION || prop == ZPROP_INVAL) { + if (prop == ZPOOL_PROP_VERSION || prop == ZPOOL_PROP_INVAL) { uint64_t ver; if (prop == ZPOOL_PROP_VERSION) { @@ -6541,9 +6541,8 @@ spa_sync_props(void *arg, dmu_tx_t *tx) zprop_type_t proptype; spa_feature_t fid; - prop = zpool_name_to_prop(nvpair_name(elem)); - switch ((int)prop) { - case ZPROP_INVAL: + switch (prop = zpool_name_to_prop(nvpair_name(elem))) { + case ZPOOL_PROP_INVAL: /* * We checked this earlier in spa_prop_validate(). */ |