Blame SOURCES/0090-json-Add-support-for-json_object_new_uint64.patch

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