Skip to content

Commit 4a3b069

Browse files
authored
Merge pull request #223 from hreinecke/json-mandatory
Make JSON-C mandatory
2 parents 3f0b379 + c139cec commit 4a3b069

3 files changed

Lines changed: 49 additions & 47 deletions

File tree

meson.build

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ libuuid_dep = dependency('uuid', required: true)
4040
conf.set('CONFIG_LIBUUID', libuuid_dep.found(), description: 'Is libuuid required?')
4141

4242
# Check for json-c availability
43-
json_c_dep = dependency('json-c', version: '>=0.13', fallback : ['json-c', 'json_c_dep'])
43+
json_c_dep = dependency('json-c',
44+
version: '>=0.13',
45+
required: true,
46+
fallback : ['json-c', 'json_c_dep'])
4447
conf.set('CONFIG_JSONC', json_c_dep.found(), description: 'Is json-c required?')
4548

4649
# Check for OpenSSL availability

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);

src/nvme/tree.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,12 +1258,10 @@ static nvme_ctrl_t nvme_ctrl_alloc(nvme_root_t r, nvme_subsystem_t s,
12581258
break;
12591259
if (!strcmp(c->name, name)) {
12601260
nvme_msg(r, LOG_DEBUG,
1261-
"%s: found existing ctrl %s\n",
1262-
__func__, c->name);
1261+
"found existing ctrl %s\n", c->name);
12631262
break;
12641263
}
1265-
nvme_msg(r, LOG_DEBUG, "%s: skipping ctrl %s\n",
1266-
__func__, c->name);
1264+
nvme_msg(r, LOG_DEBUG, "skipping ctrl %s\n", c->name);
12671265
p = c;
12681266
}
12691267
} while (c);
@@ -1274,8 +1272,7 @@ static nvme_ctrl_t nvme_ctrl_alloc(nvme_root_t r, nvme_subsystem_t s,
12741272
free(address);
12751273
if (!c) {
12761274
if (!p) {
1277-
nvme_msg(r, LOG_ERR, "%s: failed to lookup ctrl\n",
1278-
__func__);
1275+
nvme_msg(r, LOG_ERR, "failed to lookup ctrl\n");
12791276
errno = ENODEV;
12801277
} else
12811278
errno = ENOMEM;
@@ -1796,15 +1793,13 @@ static int nvme_ctrl_scan_namespace(nvme_root_t r, struct nvme_ctrl *c,
17961793
struct nvme_ns *n;
17971794

17981795
if (!c->s) {
1799-
nvme_msg(r, LOG_DEBUG, "%s: no subsystem for %s\n",
1800-
__func__, name);
1796+
nvme_msg(r, LOG_DEBUG, "no subsystem for %s\n", name);
18011797
errno = EINVAL;
18021798
return -1;
18031799
}
18041800
n = __nvme_scan_namespace(c->sysfs_dir, name);
18051801
if (!n) {
1806-
nvme_msg(r, LOG_DEBUG, "%s: failed to scan namespace %s\n",
1807-
__func__, name);
1802+
nvme_msg(r, LOG_DEBUG, "failed to scan namespace %s\n", name);
18081803
return -1;
18091804
}
18101805

@@ -1821,8 +1816,7 @@ static int nvme_subsystem_scan_namespace(nvme_root_t r, nvme_subsystem_t s,
18211816

18221817
n = __nvme_scan_namespace(s->sysfs_dir, name);
18231818
if (!n) {
1824-
nvme_msg(r, LOG_DEBUG, "%s: failed to scan namespace %s\n",
1825-
__func__, name);
1819+
nvme_msg(r, LOG_DEBUG, "failed to scan namespace %s\n", name);
18261820
return -1;
18271821
}
18281822

@@ -1844,8 +1838,7 @@ struct nvme_ns *nvme_subsystem_lookup_namespace(struct nvme_subsystem *s,
18441838
return NULL;
18451839
n = __nvme_scan_namespace(s->sysfs_dir, name);
18461840
if (!n) {
1847-
nvme_msg(r, LOG_DEBUG, "%s: failed to scan namespace %d\n",
1848-
__func__, nsid);
1841+
nvme_msg(r, LOG_DEBUG, "failed to scan namespace %d\n", nsid);
18491842
free(name);
18501843
return NULL;
18511844
}

0 commit comments

Comments
 (0)