WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] xend: Add lock for lspci_info in pci.py

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] xend: Add lock for lspci_info in pci.py
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Tue, 17 Mar 2009 08:35:14 -0700
Delivery-date: Tue, 17 Mar 2009 08:35:35 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1237286232 0
# Node ID 95a7f97761ed317a3e26bf90a484c44fad32318c
# Parent  c05fa254405d69438826b24e9083286788025b8a
xend: Add lock for lspci_info in pci.py

Add lspci_info_lock to protect lspci_info.

Signed-off-by: Yosuke Iwamatsu <y-iwamatsu@xxxxxxxxxxxxx>
---
 tools/python/xen/util/pci.py |   57 ++++++++++++++++++++++++++++---------------
 1 files changed, 38 insertions(+), 19 deletions(-)

diff -r c05fa254405d -r 95a7f97761ed tools/python/xen/util/pci.py
--- a/tools/python/xen/util/pci.py      Tue Mar 17 10:36:51 2009 +0000
+++ b/tools/python/xen/util/pci.py      Tue Mar 17 10:37:12 2009 +0000
@@ -12,6 +12,7 @@ import types
 import types
 import struct
 import time
+import threading
 from xen.util import utils
 
 PROC_PCI_PATH = '/proc/bus/pci/devices'
@@ -97,6 +98,7 @@ MSIX_SIZE_MASK = 0x7ff
 
 # Global variable to store information from lspci
 lspci_info = None
+lspci_info_lock = threading.RLock()
 
 #Calculate PAGE_SHIFT: number of bits to shift an address to get the page 
number
 PAGE_SIZE = resource.getpagesize()
@@ -174,12 +176,16 @@ def get_all_pci_devices():
 
     return pci_devs
 
-def create_lspci_info():
+def _create_lspci_info():
+    """Execute 'lspci' command and parse the result.
+    If the command does not exist, lspci_info will be kept blank ({}).
+
+    Expects to be protected by lspci_info_lock.
+    """
     global lspci_info
+    
     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 + ' -vmm').read().split('\n\n'):
         device_name = None
         device_info = {}
@@ -194,6 +200,14 @@ def create_lspci_info():
                 pass
         if device_name is not None:
             lspci_info[device_name] = device_info
+
+def create_lspci_info():
+    global lspci_info_lock
+    lspci_info_lock.acquire()
+    try:
+        _create_lspci_info()
+    finally:
+        lspci_info_lock.release()
 
 def save_pci_conf_space(devs_string):
     pci_list = []
@@ -911,22 +925,27 @@ class PciDevice:
         Since we cannot obtain these data from sysfs, use 'lspci' command.
         """
         global lspci_info
-
-        if lspci_info is None:
-            create_lspci_info()
-
-        try:
-            device_info = lspci_info[self.name]
-            self.revision = int(device_info['Rev'], 16)
-            self.vendorname = device_info['Vendor']
-            self.devicename = device_info['Device']
-            self.classname = device_info['Class']
-            self.subvendorname = device_info['SVendor']
-            self.subdevicename = device_info['SDevice']
-        except KeyError:
-            pass
-
-        return True
+        global lspci_info_lock
+
+        lspci_info_lock.acquire()
+        try:
+            if lspci_info is None:
+                _create_lspci_info()
+
+            try:
+                device_info = lspci_info[self.name]
+                self.revision = int(device_info['Rev'], 16)
+                self.vendorname = device_info['Vendor']
+                self.devicename = device_info['Device']
+                self.classname = device_info['Class']
+                self.subvendorname = device_info['SVendor']
+                self.subdevicename = device_info['SDevice']
+            except KeyError:
+                pass
+
+            return True
+        finally:
+            lspci_info_lock.release()
 
     def __str__(self):
         str = "PCI Device %s\n" % (self.name)

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] xend: Add lock for lspci_info in pci.py, Xen patchbot-unstable <=