diff options
author | Dan Williams <dan.j.williams@intel.com> | 2022-01-23 16:52:10 -0800 |
---|---|---|
committer | Vishal Verma <vishal.l.verma@intel.com> | 2022-01-26 14:37:53 -0700 |
commit | 691cd249750b505753680d2a766280698ce25b75 (patch) | |
tree | 822862c378257b54c1513ad7f9c1274f333973d5 | |
parent | 6dafb0baf8fda14f25e0a764fe8f89d8a4727b0c (diff) |
json: Add support for json_object_new_uint64()
Recent versions of json-c add a proper u64 type. However since ndctl still
needs to build against older json-c add build infrastructure to fallback to
s64.
Link: https://lore.kernel.org/r/164298553057.3021641.17232869374733997747.stgit@dwillia2-desk3.amr.corp.intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
-rw-r--r-- | config.h.meson | 3 | ||||
-rw-r--r-- | cxl/json.c | 6 | ||||
-rw-r--r-- | daxctl/json.c | 2 | ||||
-rw-r--r-- | meson.build | 6 | ||||
-rw-r--r-- | ndctl/dimm.c | 2 | ||||
-rw-r--r-- | ndctl/json.c | 10 | ||||
-rw-r--r-- | util/json.c | 2 | ||||
-rw-r--r-- | util/json.h | 13 |
8 files changed, 32 insertions, 12 deletions
diff --git a/config.h.meson b/config.h.meson index 98102251..2852f1e9 100644 --- a/config.h.meson +++ b/config.h.meson @@ -88,6 +88,9 @@ /* Define to 1 if you have the `__secure_getenv' function. */ #mesondefine HAVE___SECURE_GETENV +/* Define to 1 if you have json_object_new_uint64 in json-c */ +#mesondefine HAVE_JSON_U64 + /* Define to the sub-directory where libtool stores uninstalled libraries. */ #mesondefine LT_OBJDIR @@ -159,17 +159,17 @@ static struct json_object *util_cxl_memdev_health_to_json( } field = cxl_cmd_health_info_get_dirty_shutdowns(cmd); - jobj = json_object_new_int64(field); + jobj = util_json_new_u64(field); if (jobj) json_object_object_add(jhealth, "dirty_shutdowns", jobj); field = cxl_cmd_health_info_get_volatile_errors(cmd); - jobj = json_object_new_int64(field); + jobj = util_json_new_u64(field); if (jobj) json_object_object_add(jhealth, "volatile_errors", jobj); field = cxl_cmd_health_info_get_pmem_errors(cmd); - jobj = json_object_new_int64(field); + jobj = util_json_new_u64(field); if (jobj) json_object_object_add(jhealth, "pmem_errors", jobj); diff --git a/daxctl/json.c b/daxctl/json.c index 66a795e2..3cbce9dc 100644 --- a/daxctl/json.c +++ b/daxctl/json.c @@ -190,7 +190,7 @@ struct json_object *util_daxctl_region_to_json(struct daxctl_region *region, align = daxctl_region_get_align(region); if (align < ULONG_MAX) { - jobj = json_object_new_int64(align); + jobj = util_json_new_u64(align); if (!jobj) goto err; json_object_object_add(jregion, "align", jobj); diff --git a/meson.build b/meson.build index 68f3d0ce..f25ec6c4 100644 --- a/meson.build +++ b/meson.build @@ -241,6 +241,12 @@ foreach ident : ['secure_getenv', '__secure_getenv'] conf.set10('HAVE_' + ident.to_upper(), cc.has_function(ident)) endforeach +conf.set10('HAVE_JSON_U64', + cc.has_function('json_object_new_uint64', + prefix : '''#include <json-c/json.h>''', + dependencies : json, + ) +) ndctlconf_dir = sysconfdir / 'ndctl.conf.d' ndctlconf = ndctlconf_dir / 'monitor.conf' diff --git a/ndctl/dimm.c b/ndctl/dimm.c index 0f052644..d9718a33 100644 --- a/ndctl/dimm.c +++ b/ndctl/dimm.c @@ -168,7 +168,7 @@ static struct json_object *dump_label_json(struct ndctl_dimm *dimm, break; json_object_object_add(jlabel, "isetcookie", jobj); - jobj = json_object_new_int64(le64_to_cpu(nslabel.lbasize)); + jobj = util_json_new_u64(le64_to_cpu(nslabel.lbasize)); if (!jobj) break; json_object_object_add(jlabel, "lbasize", jobj); diff --git a/ndctl/json.c b/ndctl/json.c index c62e6cae..23bad7fd 100644 --- a/ndctl/json.c +++ b/ndctl/json.c @@ -357,7 +357,7 @@ static struct json_object *util_##type##_build_size_array(struct ndctl_##type *a int64_t align; \ \ align = get_elem(arg, i); \ - jobj = json_object_new_int64(align); \ + jobj = util_json_new_u64(align); \ if (!jobj) \ goto err; \ json_object_array_add(arr, jobj); \ @@ -550,7 +550,7 @@ struct json_object *util_region_badblocks_to_json(struct ndctl_region *region, if (!jbb) goto err_array; - jobj = json_object_new_int64(bb->offset); + jobj = util_json_new_u64(bb->offset); if (!jobj) goto err; json_object_object_add(jbb, "offset", jobj); @@ -604,7 +604,7 @@ static struct json_object *util_namespace_badblocks_to_json( if (!jbb) goto err_array; - jobj = json_object_new_int64(bb->offset); + jobj = util_json_new_u64(bb->offset); if (!jobj) goto err; json_object_object_add(jbb, "offset", jobj); @@ -682,7 +682,7 @@ static struct json_object *dev_badblocks_to_json(struct ndctl_region *region, if (!jbb) goto err_array; - jobj = json_object_new_int64(offset); + jobj = util_json_new_u64(offset); if (!jobj) goto err; json_object_object_add(jbb, "offset", jobj); @@ -972,7 +972,7 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns, } if (align) { - jobj = json_object_new_int64(align); + jobj = util_json_new_u64(align); if (!jobj) goto err; json_object_object_add(jndns, "align", jobj); diff --git a/util/json.c b/util/json.c index 9f0a8e13..bd5f8fc4 100644 --- a/util/json.c +++ b/util/json.c @@ -82,7 +82,7 @@ struct json_object *util_json_object_size(unsigned long long size, struct json_object *util_json_object_hex(unsigned long long val, unsigned long flags) { - struct json_object *jobj = json_object_new_int64(val); + struct json_object *jobj = util_json_new_u64(val); if (jobj && (flags & UTIL_JSON_HUMAN)) json_object_set_serializer(jobj, display_hex, NULL, NULL); diff --git a/util/json.h b/util/json.h index 4ca2c890..061f0d42 100644 --- a/util/json.h +++ b/util/json.h @@ -4,6 +4,7 @@ #define __UTIL_JSON_H__ #include <stdio.h> #include <stdbool.h> +#include <json-c/json.h> enum util_json_flags { UTIL_JSON_IDLE = (1 << 0), @@ -19,11 +20,21 @@ enum util_json_flags { UTIL_JSON_HEALTH = (1 << 10), }; -struct json_object; void util_display_json_array(FILE *f_out, struct json_object *jarray, unsigned long flags); struct json_object *util_json_object_size(unsigned long long size, unsigned long flags); struct json_object *util_json_object_hex(unsigned long long val, unsigned long flags); +#if HAVE_JSON_U64 +static inline struct json_object *util_json_new_u64(unsigned long long val) +{ + return json_object_new_uint64(val); +} +#else /* fallback to signed */ +static inline struct json_object *util_json_new_u64(unsigned long long val) +{ + return json_object_new_int64(val); +} +#endif /* HAVE_JSON_U64 */ #endif /* __UTIL_JSON_H__ */ |