From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yosuke Iwamatsu Subject: Re: A small portability issue introduced by changeset 17951 Date: Thu, 31 Jul 2008 20:36:19 +0900 Message-ID: <4891A3B3.7040808@ab.jp.nec.com> References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------090106050509010408040007" Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "Cui, Dexuan" Cc: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org This is a multi-part message in MIME format. --------------090106050509010408040007 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi, Cui, Dexuan wrote: > changeset 17951: e65fe28b5288 uses a shell command "lspci -vmmD". > But the "-D" parameter is not supported in relatively-old version of > pciutils, like pciutils-2.1.99.test8-3.4 (for instance, this vresion can > be found in RHEL4u6). > It'd be nice to have it fixed. The attached patch uses 'lspci -vmm' instead of '-vmmD'. The pci domain number may be omitted from the output of lspci, but pci_parse_name() will set it default to 0 if it doesn't exist. Thanks, -- Yosuke --------------090106050509010408040007 Content-Type: all/allfiles; name="lspci_parse.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="lspci_parse.patch" xend: Fix portability issue of lspci option. Signed-off-by: Yosuke Iwamatsu diff -r 21dd1fdb73d8 tools/python/xen/util/pci.py --- a/tools/python/xen/util/pci.py Wed Jul 30 16:22:45 2008 +0100 +++ b/tools/python/xen/util/pci.py Thu Jul 31 20:17:26 2008 +0900 @@ -111,15 +111,22 @@ def parse_hex(val): return None def parse_pci_name(pci_name_string): - # Format: xxxx:xx:xx.x - s = pci_name_string - s = s.split(':') - dom = parse_hex(s[0]) - bus = parse_hex(s[1]) - s = s[2].split('.') - dev = parse_hex(s[0]) - func = parse_hex(s[1]) - return (dom, bus, dev, func) + pci_match = re.match(r"((?P[0-9a-fA-F]{1,4})[:,])?" + \ + r"(?P[0-9a-fA-F]{1,2})[:,]" + \ + r"(?P[0-9a-fA-F]{1,2})[.,]" + \ + r"(?P[0-7])$", pci_name_string) + if pci_match is None: + raise PciDeviceParseError(('Failed to parse pci device name: %s' % + pci_name_string)) + pci_dev_info = pci_match.groupdict('0') + + domain = parse_hex(pci_dev_info['domain']) + bus = parse_hex(pci_dev_info['bus']) + slot = parse_hex(pci_dev_info['slot']) + func = parse_hex(pci_dev_info['func']) + + return (domain, bus, slot, func) + def find_sysfs_mnt(): global sysfs_mnt_point @@ -175,14 +182,14 @@ def create_lspci_info(): # Execute 'lspci' command and parse the result. # If the command does not exist, lspci_info will be kept blank ({}). - for paragraph in os.popen(LSPCI_CMD + ' -vmmD').read().split('\n\n'): + for paragraph in os.popen(LSPCI_CMD + ' -vmm').read().split('\n\n'): device_name = None device_info = {} for line in paragraph.split('\n'): try: (opt, value) = line.split(':\t') if opt == 'Slot': - device_name = value + device_name = PCI_DEV_FORMAT_STR % parse_pci_name(value) else: device_info[opt] = value except: --------------090106050509010408040007 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --------------090106050509010408040007--