Skip to content

Commit 2178245

Browse files
shroffniigaw
authored andcommitted
test: extend sysfs tree dump test
In order to validate multipath link support extend the existing sysfs tree dump test. The updated tree-pcie.tar.xz archive includes a sysfs dump with two NVMe subsystems. The nvme-subsys0 simulates a single-port NVMe disk with a private namespace that does not support multipath. And another nvme-subsys1 simulates a dual-port NVMe disk with a shared namespace attached to multiple controllers. The json tree dump is also updated to include NVMe namespace path information. Since the archive content has changed, the expected output file tree-pcie.out is also updated to reflect the new structure. Reviewed-by: Hannes Reinecke <[email protected]> Signed-off-by: Nilay Shroff <[email protected]> Signed-off-by: Daniel Wagner <[email protected]>
1 parent 2722f62 commit 2178245

3 files changed

Lines changed: 124 additions & 19 deletions

File tree

src/nvme/json.c

Lines changed: 81 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -533,25 +533,97 @@ static void json_dump_ctrl(struct json_object *ctrl_array, nvme_ctrl_t c)
533533
json_object_array_add(ctrl_array, ctrl_obj);
534534
}
535535

536+
static unsigned int json_dump_subsys_multipath(nvme_subsystem_t s,
537+
struct json_object *ns_array)
538+
{
539+
nvme_ns_t n;
540+
nvme_path_t p;
541+
unsigned int i = 0;
542+
543+
nvme_subsystem_for_each_ns(s, n) {
544+
struct json_object *ns_obj;
545+
struct json_object *path_array;
546+
547+
ns_obj = json_object_new_object();
548+
json_object_object_add(ns_obj, "nsid",
549+
json_object_new_int(nvme_ns_get_nsid(n)));
550+
json_object_object_add(ns_obj, "name",
551+
json_object_new_string(nvme_ns_get_name(n)));
552+
553+
path_array = json_object_new_array();
554+
nvme_namespace_for_each_path(n, p) {
555+
struct json_object *path_obj;
556+
struct json_object *ctrl_array;
557+
nvme_ctrl_t c;
558+
559+
path_obj = json_object_new_object();
560+
json_object_object_add(path_obj, "path",
561+
json_object_new_string(nvme_path_get_name(p)));
562+
json_object_object_add(path_obj, "ANAState",
563+
json_object_new_string(nvme_path_get_ana_state(p)));
564+
json_object_object_add(path_obj, "NUMANodes",
565+
json_object_new_string(nvme_path_get_numa_nodes(p)));
566+
json_object_object_add(path_obj, "qdepth",
567+
json_object_new_int(nvme_path_get_queue_depth(p)));
568+
569+
c = nvme_path_get_ctrl(p);
570+
ctrl_array = json_object_new_array();
571+
json_dump_ctrl(ctrl_array, c);
572+
json_object_object_add(path_obj, "controller", ctrl_array);
573+
json_object_array_add(path_array, path_obj);
574+
}
575+
json_object_object_add(ns_obj, "paths", path_array);
576+
json_object_array_add(ns_array, ns_obj);
577+
i++;
578+
}
579+
return i;
580+
}
581+
582+
static void json_dump_subsys_non_multipath(nvme_subsystem_t s,
583+
struct json_object *ns_array)
584+
{
585+
nvme_ctrl_t c;
586+
nvme_ns_t n;
587+
588+
nvme_subsystem_for_each_ctrl(s, c) {
589+
nvme_ctrl_for_each_ns(c, n) {
590+
struct json_object *ctrl_array;
591+
struct json_object *ns_obj;
592+
593+
ns_obj = json_object_new_object();
594+
json_object_object_add(ns_obj, "nsid",
595+
json_object_new_int(nvme_ns_get_nsid(n)));
596+
json_object_object_add(ns_obj, "name",
597+
json_object_new_string(nvme_ns_get_name(n)));
598+
599+
ctrl_array = json_object_new_array();
600+
json_dump_ctrl(ctrl_array, c);
601+
json_object_object_add(ns_obj, "controller", ctrl_array);
602+
603+
json_object_array_add(ns_array, ns_obj);
604+
}
605+
}
606+
}
607+
536608
static void json_dump_subsys(struct json_object *subsys_array,
537609
nvme_subsystem_t s)
538610
{
539-
nvme_ctrl_t c;
540611
struct json_object *subsys_obj = json_object_new_object();
541-
struct json_object *ctrl_array;
612+
struct json_object *ns_array;
542613

543614
json_object_object_add(subsys_obj, "name",
544615
json_object_new_string(nvme_subsystem_get_name(s)));
545616
json_object_object_add(subsys_obj, "nqn",
546617
json_object_new_string(nvme_subsystem_get_nqn(s)));
547-
ctrl_array = json_object_new_array();
548-
nvme_subsystem_for_each_ctrl(s, c) {
549-
json_dump_ctrl(ctrl_array, c);
550-
}
551-
if (json_object_array_length(ctrl_array))
552-
json_object_object_add(subsys_obj, "controllers", ctrl_array);
618+
619+
ns_array = json_object_new_array();
620+
if (!json_dump_subsys_multipath(s, ns_array))
621+
json_dump_subsys_non_multipath(s, ns_array);
622+
623+
if (json_object_array_length(ns_array))
624+
json_object_object_add(subsys_obj, "namespaces", ns_array);
553625
else
554-
json_object_put(ctrl_array);
626+
json_object_put(ns_array);
555627
json_object_array_add(subsys_array, subsys_obj);
556628
}
557629

test/sysfs/data/tree-pcie.out

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,56 @@
66
"subsystems":[
77
{
88
"name":"nvme-subsys0",
9-
"nqn":"nqn.2019-08.org.qemu:subsys1",
10-
"controllers":[
9+
"nqn":"nqn.1994-11.com.samsung:nvme:PM1743:2.5-inch:S7DFNG0W700063",
10+
"namespaces":[
1111
{
12-
"name":"nvme0",
13-
"transport":"pcie",
14-
"traddr":"0000:0f:00.0"
12+
"nsid":1,
13+
"name":"nvme0n1",
14+
"controller":[
15+
{
16+
"name":"nvme0",
17+
"transport":"pcie",
18+
"traddr":"0214:90:00.0"
19+
}
20+
]
1521
}
1622
]
1723
},
1824
{
1925
"name":"nvme-subsys1",
20-
"nqn":"nqn.2019-08.org.qemu:nvme-0",
21-
"controllers":[
26+
"nqn":"nqn.1994-11.com.samsung:nvme:PM1735a:2.5-inch:S6RTNE0R900057",
27+
"namespaces":[
2228
{
23-
"name":"nvme1",
24-
"transport":"pcie",
25-
"traddr":"0000:00:05.0"
29+
"nsid":1,
30+
"name":"nvme1n1",
31+
"paths":[
32+
{
33+
"path":"nvme1c1n1",
34+
"ANAState":"optimized",
35+
"NUMANodes":"0-1",
36+
"qdepth":0,
37+
"controller":[
38+
{
39+
"name":"nvme1",
40+
"transport":"pcie",
41+
"traddr":"052e:78:00.0"
42+
}
43+
]
44+
},
45+
{
46+
"path":"nvme1c2n1",
47+
"ANAState":"optimized",
48+
"NUMANodes":"2-3",
49+
"qdepth":0,
50+
"controller":[
51+
{
52+
"name":"nvme2",
53+
"transport":"pcie",
54+
"traddr":"058e:78:00.0"
55+
}
56+
]
57+
}
58+
]
2659
}
2760
]
2861
}

test/sysfs/data/tree-pcie.tar.xz

-6.89 KB
Binary file not shown.

0 commit comments

Comments
 (0)