|
|
e0018b |
From 691cd249750b505753680d2a766280698ce25b75 Mon Sep 17 00:00:00 2001
|
|
|
e0018b |
From: Dan Williams <dan.j.williams@intel.com>
|
|
|
e0018b |
Date: Sun, 23 Jan 2022 16:52:10 -0800
|
|
|
e0018b |
Subject: [PATCH 090/217] json: Add support for json_object_new_uint64()
|
|
|
e0018b |
|
|
|
e0018b |
Recent versions of json-c add a proper u64 type. However since ndctl still
|
|
|
e0018b |
needs to build against older json-c add build infrastructure to fallback to
|
|
|
e0018b |
s64.
|
|
|
e0018b |
|
|
|
e0018b |
Link: https://lore.kernel.org/r/164298553057.3021641.17232869374733997747.stgit@dwillia2-desk3.amr.corp.intel.com
|
|
|
e0018b |
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
|
|
|
e0018b |
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
|
|
|
e0018b |
---
|
|
|
e0018b |
config.h.meson | 3 +++
|
|
|
e0018b |
cxl/json.c | 6 +++---
|
|
|
e0018b |
daxctl/json.c | 2 +-
|
|
|
e0018b |
meson.build | 6 ++++++
|
|
|
e0018b |
ndctl/dimm.c | 2 +-
|
|
|
e0018b |
ndctl/json.c | 10 +++++-----
|
|
|
e0018b |
util/json.c | 2 +-
|
|
|
e0018b |
util/json.h | 13 ++++++++++++-
|
|
|
e0018b |
8 files changed, 32 insertions(+), 12 deletions(-)
|
|
|
e0018b |
|
|
|
e0018b |
diff -up ndctl-71.1/config.h.meson.orig ndctl-71.1/config.h.meson
|
|
|
e0018b |
--- ndctl-71.1/config.h.meson.orig 2022-10-07 17:40:36.698914113 -0400
|
|
|
e0018b |
+++ ndctl-71.1/config.h.meson 2022-10-07 17:41:24.043075305 -0400
|
|
|
e0018b |
@@ -88,6 +88,9 @@
|
|
|
e0018b |
/* Define to 1 if you have the `__secure_getenv' function. */
|
|
|
e0018b |
#mesondefine HAVE___SECURE_GETENV
|
|
|
e0018b |
|
|
|
e0018b |
+/* Define to 1 if you have json_object_new_uint64 in json-c */
|
|
|
e0018b |
+#mesondefine HAVE_JSON_U64
|
|
|
e0018b |
+
|
|
|
e0018b |
/* Define to the sub-directory where libtool stores uninstalled libraries. */
|
|
|
e0018b |
#mesondefine LT_OBJDIR
|
|
|
e0018b |
|
|
|
e0018b |
diff -up ndctl-71.1/cxl/json.c.orig ndctl-71.1/cxl/json.c
|
|
|
e0018b |
--- ndctl-71.1/cxl/json.c.orig 2022-10-07 17:40:36.668914011 -0400
|
|
|
e0018b |
+++ ndctl-71.1/cxl/json.c 2022-10-07 17:41:24.043075305 -0400
|
|
|
e0018b |
@@ -159,17 +159,17 @@ static struct json_object *util_cxl_memd
|
|
|
e0018b |
}
|
|
|
e0018b |
|
|
|
e0018b |
field = cxl_cmd_health_info_get_dirty_shutdowns(cmd);
|
|
|
e0018b |
- jobj = json_object_new_int64(field);
|
|
|
e0018b |
+ jobj = util_json_new_u64(field);
|
|
|
e0018b |
if (jobj)
|
|
|
e0018b |
json_object_object_add(jhealth, "dirty_shutdowns", jobj);
|
|
|
e0018b |
|
|
|
e0018b |
field = cxl_cmd_health_info_get_volatile_errors(cmd);
|
|
|
e0018b |
- jobj = json_object_new_int64(field);
|
|
|
e0018b |
+ jobj = util_json_new_u64(field);
|
|
|
e0018b |
if (jobj)
|
|
|
e0018b |
json_object_object_add(jhealth, "volatile_errors", jobj);
|
|
|
e0018b |
|
|
|
e0018b |
field = cxl_cmd_health_info_get_pmem_errors(cmd);
|
|
|
e0018b |
- jobj = json_object_new_int64(field);
|
|
|
e0018b |
+ jobj = util_json_new_u64(field);
|
|
|
e0018b |
if (jobj)
|
|
|
e0018b |
json_object_object_add(jhealth, "pmem_errors", jobj);
|
|
|
e0018b |
|
|
|
e0018b |
diff -up ndctl-71.1/daxctl/json.c.orig ndctl-71.1/daxctl/json.c
|
|
|
e0018b |
--- ndctl-71.1/daxctl/json.c.orig 2022-10-07 17:40:36.671914021 -0400
|
|
|
e0018b |
+++ ndctl-71.1/daxctl/json.c 2022-10-07 17:41:24.043075305 -0400
|
|
|
e0018b |
@@ -190,7 +190,7 @@ struct json_object *util_daxctl_region_t
|
|
|
e0018b |
|
|
|
e0018b |
align = daxctl_region_get_align(region);
|
|
|
e0018b |
if (align < ULONG_MAX) {
|
|
|
e0018b |
- jobj = json_object_new_int64(align);
|
|
|
e0018b |
+ jobj = util_json_new_u64(align);
|
|
|
e0018b |
if (!jobj)
|
|
|
e0018b |
goto err;
|
|
|
e0018b |
json_object_object_add(jregion, "align", jobj);
|
|
|
e0018b |
diff -up ndctl-71.1/meson.build.orig ndctl-71.1/meson.build
|
|
|
e0018b |
--- ndctl-71.1/meson.build.orig 2022-10-07 17:40:36.720914188 -0400
|
|
|
e0018b |
+++ ndctl-71.1/meson.build 2022-10-07 17:41:24.044075308 -0400
|
|
|
e0018b |
@@ -240,6 +240,12 @@ foreach ident : ['secure_getenv', '__sec
|
|
|
e0018b |
conf.set10('HAVE_' + ident.to_upper(), cc.has_function(ident))
|
|
|
e0018b |
endforeach
|
|
|
e0018b |
|
|
|
e0018b |
+conf.set10('HAVE_JSON_U64',
|
|
|
e0018b |
+ cc.has_function('json_object_new_uint64',
|
|
|
e0018b |
+ prefix : '''#include <json-c/json.h>''',
|
|
|
e0018b |
+ dependencies : json,
|
|
|
e0018b |
+ )
|
|
|
e0018b |
+)
|
|
|
e0018b |
|
|
|
e0018b |
ndctlconf_dir = sysconfdir / 'ndctl'
|
|
|
e0018b |
ndctlconf = ndctlconf_dir / 'monitor.conf'
|
|
|
e0018b |
diff -up ndctl-71.1/ndctl/dimm.c.orig ndctl-71.1/ndctl/dimm.c
|
|
|
e0018b |
--- ndctl-71.1/ndctl/dimm.c.orig 2022-10-07 17:40:36.673914028 -0400
|
|
|
e0018b |
+++ ndctl-71.1/ndctl/dimm.c 2022-10-07 17:41:24.044075308 -0400
|
|
|
e0018b |
@@ -168,7 +168,7 @@ static struct json_object *dump_label_js
|
|
|
e0018b |
break;
|
|
|
e0018b |
json_object_object_add(jlabel, "isetcookie", jobj);
|
|
|
e0018b |
|
|
|
e0018b |
- jobj = json_object_new_int64(le64_to_cpu(nslabel.lbasize));
|
|
|
e0018b |
+ jobj = util_json_new_u64(le64_to_cpu(nslabel.lbasize));
|
|
|
e0018b |
if (!jobj)
|
|
|
e0018b |
break;
|
|
|
e0018b |
json_object_object_add(jlabel, "lbasize", jobj);
|
|
|
e0018b |
diff -up ndctl-71.1/ndctl/json.c.orig ndctl-71.1/ndctl/json.c
|
|
|
e0018b |
--- ndctl-71.1/ndctl/json.c.orig 2022-10-07 17:40:36.675914034 -0400
|
|
|
e0018b |
+++ ndctl-71.1/ndctl/json.c 2022-10-07 17:41:24.044075308 -0400
|
|
|
e0018b |
@@ -357,7 +357,7 @@ static struct json_object *util_##type##
|
|
|
e0018b |
int64_t align; \
|
|
|
e0018b |
\
|
|
|
e0018b |
align = get_elem(arg, i); \
|
|
|
e0018b |
- jobj = json_object_new_int64(align); \
|
|
|
e0018b |
+ jobj = util_json_new_u64(align); \
|
|
|
e0018b |
if (!jobj) \
|
|
|
e0018b |
goto err; \
|
|
|
e0018b |
json_object_array_add(arr, jobj); \
|
|
|
e0018b |
@@ -550,7 +550,7 @@ struct json_object *util_region_badblock
|
|
|
e0018b |
if (!jbb)
|
|
|
e0018b |
goto err_array;
|
|
|
e0018b |
|
|
|
e0018b |
- jobj = json_object_new_int64(bb->offset);
|
|
|
e0018b |
+ jobj = util_json_new_u64(bb->offset);
|
|
|
e0018b |
if (!jobj)
|
|
|
e0018b |
goto err;
|
|
|
e0018b |
json_object_object_add(jbb, "offset", jobj);
|
|
|
e0018b |
@@ -604,7 +604,7 @@ static struct json_object *util_namespac
|
|
|
e0018b |
if (!jbb)
|
|
|
e0018b |
goto err_array;
|
|
|
e0018b |
|
|
|
e0018b |
- jobj = json_object_new_int64(bb->offset);
|
|
|
e0018b |
+ jobj = util_json_new_u64(bb->offset);
|
|
|
e0018b |
if (!jobj)
|
|
|
e0018b |
goto err;
|
|
|
e0018b |
json_object_object_add(jbb, "offset", jobj);
|
|
|
e0018b |
@@ -682,7 +682,7 @@ static struct json_object *dev_badblocks
|
|
|
e0018b |
if (!jbb)
|
|
|
e0018b |
goto err_array;
|
|
|
e0018b |
|
|
|
e0018b |
- jobj = json_object_new_int64(offset);
|
|
|
e0018b |
+ jobj = util_json_new_u64(offset);
|
|
|
e0018b |
if (!jobj)
|
|
|
e0018b |
goto err;
|
|
|
e0018b |
json_object_object_add(jbb, "offset", jobj);
|
|
|
e0018b |
@@ -972,7 +972,7 @@ struct json_object *util_namespace_to_js
|
|
|
e0018b |
}
|
|
|
e0018b |
|
|
|
e0018b |
if (align) {
|
|
|
e0018b |
- jobj = json_object_new_int64(align);
|
|
|
e0018b |
+ jobj = util_json_new_u64(align);
|
|
|
e0018b |
if (!jobj)
|
|
|
e0018b |
goto err;
|
|
|
e0018b |
json_object_object_add(jndns, "align", jobj);
|
|
|
e0018b |
diff -up ndctl-71.1/util/json.c.orig ndctl-71.1/util/json.c
|
|
|
e0018b |
--- ndctl-71.1/util/json.c.orig 2022-10-07 17:40:36.682914058 -0400
|
|
|
e0018b |
+++ ndctl-71.1/util/json.c 2022-10-07 17:41:24.045075312 -0400
|
|
|
e0018b |
@@ -82,7 +82,7 @@ struct json_object *util_json_object_siz
|
|
|
e0018b |
struct json_object *util_json_object_hex(unsigned long long val,
|
|
|
e0018b |
unsigned long flags)
|
|
|
e0018b |
{
|
|
|
e0018b |
- struct json_object *jobj = json_object_new_int64(val);
|
|
|
e0018b |
+ struct json_object *jobj = util_json_new_u64(val);
|
|
|
e0018b |
|
|
|
e0018b |
if (jobj && (flags & UTIL_JSON_HUMAN))
|
|
|
e0018b |
json_object_set_serializer(jobj, display_hex, NULL, NULL);
|
|
|
e0018b |
diff -up ndctl-71.1/util/json.h.orig ndctl-71.1/util/json.h
|
|
|
e0018b |
--- ndctl-71.1/util/json.h.orig 2022-10-07 17:40:36.683914062 -0400
|
|
|
e0018b |
+++ ndctl-71.1/util/json.h 2022-10-07 17:41:24.046075315 -0400
|
|
|
e0018b |
@@ -4,6 +4,7 @@
|
|
|
e0018b |
#define __UTIL_JSON_H__
|
|
|
e0018b |
#include <stdio.h>
|
|
|
e0018b |
#include <stdbool.h>
|
|
|
e0018b |
+#include <json-c/json.h>
|
|
|
e0018b |
|
|
|
e0018b |
enum util_json_flags {
|
|
|
e0018b |
UTIL_JSON_IDLE = (1 << 0),
|
|
|
e0018b |
@@ -19,11 +20,21 @@ enum util_json_flags {
|
|
|
e0018b |
UTIL_JSON_HEALTH = (1 << 10),
|
|
|
e0018b |
};
|
|
|
e0018b |
|
|
|
e0018b |
-struct json_object;
|
|
|
e0018b |
void util_display_json_array(FILE *f_out, struct json_object *jarray,
|
|
|
e0018b |
unsigned long flags);
|
|
|
e0018b |
struct json_object *util_json_object_size(unsigned long long size,
|
|
|
e0018b |
unsigned long flags);
|
|
|
e0018b |
struct json_object *util_json_object_hex(unsigned long long val,
|
|
|
e0018b |
unsigned long flags);
|
|
|
e0018b |
+#if HAVE_JSON_U64
|
|
|
e0018b |
+static inline struct json_object *util_json_new_u64(unsigned long long val)
|
|
|
e0018b |
+{
|
|
|
e0018b |
+ return json_object_new_uint64(val);
|
|
|
e0018b |
+}
|
|
|
e0018b |
+#else /* fallback to signed */
|
|
|
e0018b |
+static inline struct json_object *util_json_new_u64(unsigned long long val)
|
|
|
e0018b |
+{
|
|
|
e0018b |
+ return json_object_new_int64(val);
|
|
|
e0018b |
+}
|
|
|
e0018b |
+#endif /* HAVE_JSON_U64 */
|
|
|
e0018b |
#endif /* __UTIL_JSON_H__ */
|