Skip to content

Commit 10b8668

Browse files
committed
ndctl, list: add the remaining set of 'filter_by' helpers
We already support filtering region and bus listings by dimm, lets extend that to the other object types. I.e. permit buses to be filtered by regions, dimms, and namespaces; allow regions to be filtered by dimms, and namespaces etc... For example, to list all the DIMMs that comprise a given namespace: # ndctl list --dimms --namespace=7.0 [ { "dev":"nmem1", "id":"cdab-0a-07e0-ffffffff", "handle":0, "phys_id":0 }, { "dev":"nmem3", "id":"cdab-0a-07e0-fffeffff", "handle":256, "phys_id":2 }, { "dev":"nmem2", "id":"cdab-0a-07e0-feffffff", "handle":1, "phys_id":1 }, { "dev":"nmem4", "id":"cdab-0a-07e0-fefeffff", "handle":257, "phys_id":3 } ] Reported-by: Keith Hazelet <[email protected]> Signed-off-by: Dan Williams <[email protected]>
1 parent b05f821 commit 10b8668

File tree

3 files changed

+111
-3
lines changed

3 files changed

+111
-3
lines changed

ndctl/list.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,9 @@ int cmd_list(int argc, const char **argv, void *ctx)
344344
struct ndctl_dimm *dimm;
345345

346346
if (!util_bus_filter(bus, param.bus)
347-
|| !util_bus_filter_by_dimm(bus, param.dimm))
347+
|| !util_bus_filter_by_dimm(bus, param.dimm)
348+
|| !util_bus_filter_by_region(bus, param.region)
349+
|| !util_bus_filter_by_namespace(bus, param.namespace))
348350
continue;
349351

350352
if (list.buses) {
@@ -371,7 +373,11 @@ int cmd_list(int argc, const char **argv, void *ctx)
371373
if (!list.dimms)
372374
break;
373375

374-
if (!util_dimm_filter(dimm, param.dimm))
376+
if (!util_dimm_filter(dimm, param.dimm)
377+
|| !util_dimm_filter_by_region(dimm,
378+
param.region)
379+
|| !util_dimm_filter_by_namespace(dimm,
380+
param.namespace))
375381
continue;
376382

377383
if (!list.idle && !ndctl_dimm_is_enabled(dimm))
@@ -425,7 +431,9 @@ int cmd_list(int argc, const char **argv, void *ctx)
425431

426432
if (!util_region_filter(region, param.region)
427433
|| !util_region_filter_by_dimm(region,
428-
param.dimm))
434+
param.dimm)
435+
|| !util_region_filter_by_namespace(region,
436+
param.namespace))
429437
continue;
430438

431439
if (type && ndctl_region_get_type(region) != type)

util/filter.c

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,37 @@ struct ndctl_bus *util_bus_filter_by_dimm(struct ndctl_bus *bus,
130130
return NULL;
131131
}
132132

133+
struct ndctl_bus *util_bus_filter_by_region(struct ndctl_bus *bus,
134+
const char *ident)
135+
{
136+
struct ndctl_region *region;
137+
138+
if (!ident || strcmp(ident, "all") == 0)
139+
return bus;
140+
141+
ndctl_region_foreach(bus, region)
142+
if (util_region_filter(region, ident))
143+
return bus;
144+
return NULL;
145+
}
146+
147+
148+
struct ndctl_bus *util_bus_filter_by_namespace(struct ndctl_bus *bus,
149+
const char *ident)
150+
{
151+
struct ndctl_region *region;
152+
struct ndctl_namespace *ndns;
153+
154+
if (!ident || strcmp(ident, "all") == 0)
155+
return bus;
156+
157+
ndctl_region_foreach(bus, region)
158+
ndctl_namespace_foreach(region, ndns)
159+
if (util_namespace_filter(ndns, ident))
160+
return bus;
161+
return NULL;
162+
}
163+
133164
struct ndctl_region *util_region_filter_by_dimm(struct ndctl_region *region,
134165
const char *ident)
135166
{
@@ -145,6 +176,65 @@ struct ndctl_region *util_region_filter_by_dimm(struct ndctl_region *region,
145176
return NULL;
146177
}
147178

179+
struct ndctl_dimm *util_dimm_filter_by_region(struct ndctl_dimm *dimm,
180+
const char *ident)
181+
{
182+
struct ndctl_bus *bus = ndctl_dimm_get_bus(dimm);
183+
struct ndctl_region *region;
184+
struct ndctl_dimm *check;
185+
186+
if (!ident || strcmp(ident, "all") == 0)
187+
return dimm;
188+
189+
ndctl_region_foreach(bus, region) {
190+
if (!util_region_filter(region, ident))
191+
continue;
192+
ndctl_dimm_foreach_in_region(region, check)
193+
if (check == dimm)
194+
return dimm;
195+
}
196+
197+
return NULL;
198+
}
199+
200+
struct ndctl_dimm *util_dimm_filter_by_namespace(struct ndctl_dimm *dimm,
201+
const char *ident)
202+
{
203+
struct ndctl_bus *bus = ndctl_dimm_get_bus(dimm);
204+
struct ndctl_namespace *ndns;
205+
struct ndctl_region *region;
206+
struct ndctl_dimm *check;
207+
208+
if (!ident || strcmp(ident, "all") == 0)
209+
return dimm;
210+
211+
ndctl_region_foreach(bus, region) {
212+
ndctl_namespace_foreach(region, ndns) {
213+
if (!util_namespace_filter(ndns, ident))
214+
continue;
215+
ndctl_dimm_foreach_in_region(region, check)
216+
if (check == dimm)
217+
return dimm;
218+
}
219+
}
220+
221+
return NULL;
222+
}
223+
224+
struct ndctl_region *util_region_filter_by_namespace(struct ndctl_region *region,
225+
const char *ident)
226+
{
227+
struct ndctl_namespace *ndns;
228+
229+
if (!ident || strcmp(ident, "all") == 0)
230+
return region;
231+
232+
ndctl_namespace_foreach(region, ndns)
233+
if (util_namespace_filter(ndns, ident))
234+
return region;
235+
return NULL;
236+
}
237+
148238
struct daxctl_dev *util_daxctl_dev_filter(struct daxctl_dev *dev,
149239
const char *ident)
150240
{

util/filter.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,18 @@ struct ndctl_namespace *util_namespace_filter(struct ndctl_namespace *ndns,
2020
struct ndctl_dimm *util_dimm_filter(struct ndctl_dimm *dimm, const char *ident);
2121
struct ndctl_bus *util_bus_filter_by_dimm(struct ndctl_bus *bus,
2222
const char *ident);
23+
struct ndctl_bus *util_bus_filter_by_region(struct ndctl_bus *bus,
24+
const char *ident);
25+
struct ndctl_bus *util_bus_filter_by_namespace(struct ndctl_bus *bus,
26+
const char *ident);
2327
struct ndctl_region *util_region_filter_by_dimm(struct ndctl_region *region,
2428
const char *ident);
29+
struct ndctl_dimm *util_dimm_filter_by_region(struct ndctl_dimm *dimm,
30+
const char *ident);
31+
struct ndctl_dimm *util_dimm_filter_by_namespace(struct ndctl_dimm *dimm,
32+
const char *ident);
33+
struct ndctl_region *util_region_filter_by_namespace(struct ndctl_region *region,
34+
const char *ident);
2535
struct daxctl_dev *util_daxctl_dev_filter(struct daxctl_dev *dev,
2636
const char *ident);
2737
#endif

0 commit comments

Comments
 (0)