Skip to content

Commit c06fcce

Browse files
committed
json: remove wrapper definitions
Switch to JSON-C API. Signed-off-by: Hannes Reinecke <[email protected]>
1 parent 7d81256 commit c06fcce

1 file changed

Lines changed: 38 additions & 32 deletions

File tree

src/nvme/json.c

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,6 @@
1818
#include "log.h"
1919
#include "private.h"
2020

21-
#define json_object_add_value_string(o, k, v) \
22-
json_object_object_add(o, k, json_object_new_string(v))
23-
#define json_object_add_value_int(o, k, v) \
24-
json_object_object_add(o, k, json_object_new_int(v))
25-
#define json_object_add_value_bool(o, k, v) \
26-
json_object_object_add(o, k, json_object_new_boolean(v))
27-
#define json_object_add_value_string(o, k, v) \
28-
json_object_object_add(o, k, json_object_new_string(v))
29-
3021
#define JSON_UPDATE_INT_OPTION(c, k, a, o) \
3122
if (!strcmp(# a, k ) && !c->a) c->a = json_object_get_int(o);
3223
#define JSON_UPDATE_BOOL_OPTION(c, k, a, o) \
@@ -194,13 +185,18 @@ int json_read_config(nvme_root_t r, const char *config_file)
194185
return 0;
195186
}
196187

197-
#define JSON_STRING_OPTION(c, p, o) \
198-
if ((c)->o && strcmp((c)->o, "none")) \
199-
json_object_add_value_string((p), # o , (c)->o)
188+
#define JSON_STRING_OPTION(c, p, o) \
189+
if ((c)->o && strcmp((c)->o, "none")) \
190+
json_object_object_add((p), # o , \
191+
json_object_new_string((c)->o))
200192
#define JSON_INT_OPTION(c, p, o, d) \
201-
if ((c)->o != d) json_object_add_value_int((p), # o , (c)->o)
193+
if ((c)->o != d) \
194+
json_object_object_add((p), # o , \
195+
json_object_new_int((c)->o))
202196
#define JSON_BOOL_OPTION(c, p, o) \
203-
if ((c)->o) json_object_add_value_bool((p), # o , (c)->o)
197+
if ((c)->o) \
198+
json_object_object_add((p), # o , \
199+
json_object_new_boolean((c)->o))
204200

205201
static void json_update_port(struct json_object *ctrl_array, nvme_ctrl_t c)
206202
{
@@ -209,23 +205,28 @@ static void json_update_port(struct json_object *ctrl_array, nvme_ctrl_t c)
209205
const char *transport, *value;
210206

211207
transport = nvme_ctrl_get_transport(c);
212-
json_object_add_value_string(port_obj, "transport", transport);
208+
json_object_object_add(port_obj, "transport",
209+
json_object_new_string(transport));
213210
value = nvme_ctrl_get_traddr(c);
214211
if (value)
215-
json_object_add_value_string(port_obj, "traddr", value);
212+
json_object_object_add(port_obj, "traddr",
213+
json_object_new_string(value));
216214
value = nvme_ctrl_get_host_traddr(c);
217215
if (value)
218-
json_object_add_value_string(port_obj, "host_traddr", value);
216+
json_object_object_add(port_obj, "host_traddr",
217+
json_object_new_string(value));
219218
value = nvme_ctrl_get_host_iface(c);
220219
if (value)
221-
json_object_add_value_string(port_obj, "host_iface", value);
220+
json_object_object_add(port_obj, "host_iface",
221+
json_object_new_string(value));
222222
value = nvme_ctrl_get_trsvcid(c);
223223
if (value)
224-
json_object_add_value_string(port_obj, "trsvcid", value);
224+
json_object_object_add(port_obj, "trsvcid",
225+
json_object_new_string(value));
225226
value = nvme_ctrl_get_dhchap_key(c);
226227
if (value)
227-
json_object_add_value_string(port_obj, "dhchap_key",
228-
value);
228+
json_object_object_add(port_obj, "dhchap_key",
229+
json_object_new_string(value));
229230
JSON_INT_OPTION(cfg, port_obj, nr_io_queues, 0);
230231
JSON_INT_OPTION(cfg, port_obj, nr_write_queues, 0);
231232
JSON_INT_OPTION(cfg, port_obj, nr_poll_queues, 0);
@@ -244,9 +245,11 @@ static void json_update_port(struct json_object *ctrl_array, nvme_ctrl_t c)
244245
JSON_BOOL_OPTION(cfg, port_obj, data_digest);
245246
JSON_BOOL_OPTION(cfg, port_obj, tls);
246247
if (nvme_ctrl_is_persistent(c))
247-
json_object_add_value_bool(port_obj, "persistent", true);
248+
json_object_object_add(port_obj, "persistent",
249+
json_object_new_boolean(true));
248250
if (nvme_ctrl_is_discovery_ctrl(c))
249-
json_object_add_value_bool(port_obj, "discovery", true);
251+
json_object_object_add(port_obj, "discovery",
252+
json_object_new_boolean(true));
250253
json_object_array_add(ctrl_array, port_obj);
251254
}
252255

@@ -262,8 +265,8 @@ static void json_update_subsys(struct json_object *subsys_array,
262265
if (!strcmp(subsysnqn, NVME_DISC_SUBSYS_NAME))
263266
return;
264267

265-
json_object_add_value_string(subsys_obj, "nqn",
266-
nvme_subsystem_get_nqn(s));
268+
json_object_object_add(subsys_obj, "nqn",
269+
json_object_new_string(subsysnqn));
267270
port_array = json_object_new_array();
268271
nvme_subsystem_for_each_ctrl(s, c) {
269272
json_update_port(port_array, c);
@@ -285,19 +288,22 @@ int json_update_config(nvme_root_t r, const char *config_file)
285288
json_root = json_object_new_array();
286289
nvme_for_each_host(r, h) {
287290
nvme_subsystem_t s;
288-
const char *hostid, *dhchap_key;
291+
const char *hostnqn, *hostid, *dhchap_key;
289292

290293
host_obj = json_object_new_object();
291-
json_object_add_value_string(host_obj, "hostnqn",
292-
nvme_host_get_hostnqn(h));
294+
if (!host_obj)
295+
continue;
296+
hostnqn = nvme_host_get_hostnqn(h);
297+
json_object_object_add(host_obj, "hostnqn",
298+
json_object_new_string(hostnqn));
293299
hostid = nvme_host_get_hostid(h);
294300
if (hostid)
295-
json_object_add_value_string(host_obj, "hostid",
296-
hostid);
301+
json_object_object_add(host_obj, "hostid",
302+
json_object_new_string(hostid));
297303
dhchap_key = nvme_host_get_dhchap_key(h);
298304
if (dhchap_key)
299-
json_object_add_value_string(host_obj, "dhchap_key",
300-
dhchap_key);
305+
json_object_object_add(host_obj, "dhchap_key",
306+
json_object_new_string(dhchap_key));
301307
subsys_array = json_object_new_array();
302308
nvme_for_each_subsystem(h, s) {
303309
json_update_subsys(subsys_array, s);

0 commit comments

Comments
 (0)