Skip to content

Commit 2bb2eb0

Browse files
dwsuseigaw
authored andcommitted
tree: preserve parsing order of a config file
The order of the elements matters for array types for JSON. Appending any element to a list keeps the order. With this change dumping a tree will produce an exact copy of a input config JSON file. Signed-off-by: Daniel Wagner <[email protected]>
1 parent bad8dda commit 2bb2eb0

2 files changed

Lines changed: 17 additions & 17 deletions

File tree

src/nvme/tree.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ struct nvme_subsystem *nvme_alloc_subsystem(struct nvme_host *h,
557557
list_head_init(&s->ctrls);
558558
list_head_init(&s->namespaces);
559559
list_node_init(&s->entry);
560-
list_add(&h->subsystems, &s->entry);
560+
list_add_tail(&h->subsystems, &s->entry);
561561
h->r->modified = true;
562562
return s;
563563
}
@@ -641,7 +641,7 @@ struct nvme_host *nvme_lookup_host(nvme_root_t r, const char *hostnqn,
641641
list_head_init(&h->subsystems);
642642
list_node_init(&h->entry);
643643
h->r = r;
644-
list_add(&r->hosts, &h->entry);
644+
list_add_tail(&r->hosts, &h->entry);
645645
r->modified = true;
646646

647647
return h;
@@ -831,7 +831,7 @@ static void nvme_subsystem_set_path_ns(nvme_subsystem_t s, nvme_path_t p)
831831
sprintf(n_name, "nvme%dn%d", i, nsid);
832832
nvme_subsystem_for_each_ns(s, n) {
833833
if (!strcmp(n_name, nvme_ns_get_name(n))) {
834-
list_add(&n->paths, &p->nentry);
834+
list_add_tail(&n->paths, &p->nentry);
835835
p->n = n;
836836
}
837837
}
@@ -877,7 +877,7 @@ static int nvme_ctrl_scan_path(nvme_root_t r, struct nvme_ctrl *c, char *name)
877877
list_node_init(&p->nentry);
878878
nvme_subsystem_set_path_ns(c->s, p);
879879
list_node_init(&p->entry);
880-
list_add(&c->paths, &p->entry);
880+
list_add_tail(&c->paths, &p->entry);
881881
return 0;
882882
}
883883

@@ -1680,7 +1680,7 @@ nvme_ctrl_t nvme_lookup_ctrl(nvme_subsystem_t s, const char *transport,
16801680
host_traddr, host_iface, trsvcid);
16811681
if (c) {
16821682
c->s = s;
1683-
list_add(&s->ctrls, &c->entry);
1683+
list_add_tail(&s->ctrls, &c->entry);
16841684
s->h->r->modified = true;
16851685
}
16861686
return c;
@@ -1896,7 +1896,7 @@ int nvme_init_ctrl(nvme_host_t h, nvme_ctrl_t c, int instance)
18961896
if (s->subsystype && !strcmp(s->subsystype, "discovery"))
18971897
c->discovery_ctrl = true;
18981898
c->s = s;
1899-
list_add(&s->ctrls, &c->entry);
1899+
list_add_tail(&s->ctrls, &c->entry);
19001900
return ret;
19011901
}
19021902

@@ -2670,7 +2670,7 @@ static int nvme_ctrl_scan_namespace(nvme_root_t r, struct nvme_ctrl *c,
26702670
}
26712671
n->s = c->s;
26722672
n->c = c;
2673-
list_add(&c->namespaces, &n->entry);
2673+
list_add_tail(&c->namespaces, &n->entry);
26742674
return 0;
26752675
}
26762676

@@ -2693,7 +2693,7 @@ static void nvme_subsystem_set_ns_path(nvme_subsystem_t s, nvme_ns_t n)
26932693
if (ret != 3)
26942694
continue;
26952695
if (ns_ctrl == p_subsys && ns_nsid == p_nsid) {
2696-
list_add(&n->paths, &p->nentry);
2696+
list_add_tail(&n->paths, &p->nentry);
26972697
p->n = n;
26982698
}
26992699
}
@@ -2731,7 +2731,7 @@ static int nvme_subsystem_scan_namespace(nvme_root_t r, nvme_subsystem_t s,
27312731
__nvme_free_ns(_n);
27322732
}
27332733
n->s = s;
2734-
list_add(&s->namespaces, &n->entry);
2734+
list_add_tail(&s->namespaces, &n->entry);
27352735
nvme_subsystem_set_ns_path(s, n);
27362736
return 0;
27372737
}

test/sysfs/data/nvme-sysfs-tw-carbon-6.8.0-rc1+.out

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@
55
"hostid":"ce4fee3e-c02c-11ee-8442-830d068a36c6",
66
"subsystems":[
77
{
8-
"name":"nvme-subsys1",
9-
"nqn":"nqn.2019-08.org.qemu:nvme-0",
8+
"name":"nvme-subsys0",
9+
"nqn":"nqn.2019-08.org.qemu:subsys1",
1010
"controllers":[
1111
{
12-
"name":"nvme1",
12+
"name":"nvme0",
1313
"transport":"pcie",
14-
"traddr":"0000:00:05.0"
14+
"traddr":"0000:0f:00.0"
1515
}
1616
]
1717
},
1818
{
19-
"name":"nvme-subsys0",
20-
"nqn":"nqn.2019-08.org.qemu:subsys1",
19+
"name":"nvme-subsys1",
20+
"nqn":"nqn.2019-08.org.qemu:nvme-0",
2121
"controllers":[
2222
{
23-
"name":"nvme0",
23+
"name":"nvme1",
2424
"transport":"pcie",
25-
"traddr":"0000:0f:00.0"
25+
"traddr":"0000:00:05.0"
2626
}
2727
]
2828
}

0 commit comments

Comments
 (0)