From: Martin Mares Date: Sun, 12 Aug 2018 09:24:06 +0000 (+0200) Subject: Topology now works in combination with filters X-Git-Tag: v3.6.2~3 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=ce22dfec13cda94039f6ce4cdaf2af0bf764f4e2;p=pciutils.git Topology now works in combination with filters If bus topology is needed, we scan all devices regardless of filters, and apply the filters later when showing devices. Also, we forbid several impossible combinations of options: tree mode with filters, bus mapping mode with anything requiring topology. --- diff --git a/ls-tree.c b/ls-tree.c index 8ce9b4f..8d60ea2 100644 --- a/ls-tree.c +++ b/ls-tree.c @@ -237,7 +237,5 @@ void show_forest(void) { char line[256]; - - grow_tree(); show_tree_bridge(&host_bridge, line, line); } diff --git a/lspci.c b/lspci.c index 4631059..3dabbde 100644 --- a/lspci.c +++ b/lspci.c @@ -18,6 +18,7 @@ int verbose; /* Show detailed information */ static int opt_hex; /* Show contents of config space as hexadecimal numbers */ struct pci_filter filter; /* Device filter */ +static int opt_filter; /* Any filter was given */ static int opt_tree; /* Show bus tree */ static int opt_path; /* Show bridge path */ static int opt_machine; /* Generate machine-readable output */ @@ -81,6 +82,7 @@ GENERIC_HELP struct pci_access *pacc; struct device *first_dev; static int seen_errors; +static int need_topology; int config_fetch(struct device *d, unsigned int pos, unsigned int len) @@ -117,7 +119,7 @@ scan_device(struct pci_dev *p) if (p->domain && !opt_domains) opt_domains = 1; - if (!pci_filter_match(&filter, p)) + if (!pci_filter_match(&filter, p) && !need_topology) return NULL; d = xmalloc(sizeof(struct device)); memset(d, 0, sizeof(*d)); @@ -977,10 +979,9 @@ show(void) { struct device *d; - if (opt_path) - grow_tree(); for (d=first_dev; d; d=d->next) - show_device(d); + if (pci_filter_match(&filter, d->dev)) + show_device(d); } /* Main */ @@ -1016,19 +1017,23 @@ main(int argc, char **argv) case 's': if (msg = pci_filter_parse_slot(&filter, optarg)) die("-s: %s", msg); + opt_filter = 1; break; case 'd': if (msg = pci_filter_parse_id(&filter, optarg)) die("-d: %s", msg); + opt_filter = 1; break; case 'x': opt_hex++; break; case 'P': opt_path++; + need_topology = 1; break; case 't': opt_tree++; + need_topology = 1; break; case 'i': pci_set_name_list_path(pacc, optarg, 0); @@ -1072,6 +1077,9 @@ main(int argc, char **argv) if (optind < argc) goto bad; + if (opt_tree && opt_filter) + die("Tree mode does not support filtering"); + if (opt_query_dns) { pacc->id_lookup_mode |= PCI_LOOKUP_NETWORK; @@ -1084,14 +1092,16 @@ main(int argc, char **argv) pci_init(pacc); if (opt_map_mode) { - if (opt_path) - die("Bus paths cannot be shown in bus mapping mode"); + if (need_topology) + die("Bus mapping mode does not recognize bus topology"); map_the_bus(); } else { scan_devices(); sort_them(); + if (need_topology) + grow_tree(); if (opt_tree) show_forest(); else