All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/5] Implement DGRAM (connectionless) type socket listeners
       [not found] <49BA4209.1020702@ab.jp.nec.com>
@ 2009-03-13 12:06 ` Yosuke Iwamatsu
  2009-03-13 12:06 ` [PATCH 2/5] Add lock for xen-api class instances in XendAPIStore.py Yosuke Iwamatsu
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Yosuke Iwamatsu @ 2009-03-13 12:06 UTC (permalink / raw)
  To: xen-devel

Introduce SocketDgramListener and UnixDgramListener classes.
We already have STREAM (connection) type socket listener classes in the
source tree, but we need DGRAM (connectionless) type listeners to receive
udev events.

Signed-off-by: Yosuke Iwamatsu <y-iwamatsu@ab.jp.nec.com>

diff -r c30742011bb8 tools/python/xen/web/connection.py
--- a/tools/python/xen/web/connection.py	Thu Mar 12 18:48:09 2009 +0000
+++ b/tools/python/xen/web/connection.py	Fri Mar 13 16:36:19 2009 +0900
@@ -292,3 +292,40 @@
                 return True
         log.warn("Rejected connection from %s (%s).", addrport[0], fqdn)
         return False
+
+
+class SocketDgramListener:
+    """A connectionless server socket, running listen in a thread.
+    """
+
+    def __init__(self, protocol_class):
+        self.protocol = protocol_class()
+        self.sock = self.createSocket()
+        threading.Thread(target=self.main).start()
+
+
+    def close(self):
+        try:
+            self.sock.close()
+        except:
+            pass
+
+
+    def createSocket(self):
+        raise NotImplementedError()
+
+
+    def main(self):
+        try:
+            while True:
+                try:
+                    data = self.sock.recv(BUFFER_SIZE)
+                    self.protocol.dataReceived(data)
+                except socket.error, ex:
+                    if ex.args[0] not in (EWOULDBLOCK, EAGAIN, EINTR):
+                        break
+        finally:
+            try:
+                self.close()
+            except:
+                pass
diff -r c30742011bb8 tools/python/xen/web/unix.py
--- a/tools/python/xen/web/unix.py	Thu Mar 12 18:48:09 2009 +0000
+++ b/tools/python/xen/web/unix.py	Fri Mar 13 16:36:19 2009 +0900
@@ -27,16 +27,19 @@
 import connection
 
 
-def bind(path):
-    """Create a Unix socket, and bind it to the given path.  The socket is
-created such that only the current user may access it."""
+def bind(path, type = socket.SOCK_STREAM):
+    """Create a Unix socket, and bind it to the given path.
+    The socket is created such that only the current user may access it."""
 
-    parent = os.path.dirname(path)
-    mkdir.parents(parent, stat.S_IRWXU, True)
-    if os.path.exists(path):
-        os.unlink(path)
+    if path[0] == '\0': # Abstract namespace is used for the path
+        pass
+    else:
+        parent = os.path.dirname(path)
+        mkdir.parents(parent, stat.S_IRWXU, True)
+        if os.path.exists(path):
+            os.unlink(path)
 
-    sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+    sock = socket.socket(socket.AF_UNIX, type)
     sock.bind(path)
     return sock
 
@@ -48,8 +51,19 @@
 
 
     def createSocket(self):
-        return bind(self.path)
+        return bind(self.path, socket.SOCK_STREAM)
 
 
     def acceptConnection(self, sock, _):
         connection.SocketServerConnection(sock, self.protocol_class)
+
+
+class UnixDgramListener(connection.SocketDgramListener):
+    def __init__(self, path, protocol_class):
+        self.path = path
+        connection.SocketDgramListener.__init__(self, protocol_class)
+
+
+    def createSocket(self):
+        return bind(self.path, socket.SOCK_DGRAM)
+

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/5] Add lock for xen-api class instances in XendAPIStore.py
       [not found] <49BA4209.1020702@ab.jp.nec.com>
  2009-03-13 12:06 ` [PATCH 1/5] Implement DGRAM (connectionless) type socket listeners Yosuke Iwamatsu
@ 2009-03-13 12:06 ` Yosuke Iwamatsu
  2009-03-13 12:06 ` [PATCH 3/5] Add lock for lspci_info in pci.py Yosuke Iwamatsu
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Yosuke Iwamatsu @ 2009-03-13 12:06 UTC (permalink / raw)
  To: xen-devel

Add __classes_lock to protect __classes, since it can be modified by the udev
listener thread.

Signed-off-by: Yosuke Iwamatsu <y-iwamatsu@ab.jp.nec.com>

diff -r c30742011bb8 tools/python/xen/xend/XendAPIStore.py
--- a/tools/python/xen/xend/XendAPIStore.py	Thu Mar 12 18:48:09 2009 +0000
+++ b/tools/python/xen/xend/XendAPIStore.py	Fri Mar 13 16:36:52 2009 +0900
@@ -25,36 +25,59 @@
 by type, to ensure safety
 """
 
+import threading
+
 __classes = {}
+__classes_lock = threading.RLock()
 
 def register(uuid, type, inst):
-    __classes[(uuid, type)] = inst
-    return inst
+    __classes_lock.acquire()
+    try:
+        __classes[(uuid, type)] = inst
+        return inst
+    finally:
+        __classes_lock.release()
 
 def deregister(uuid, type):
-    old = get(uuid, type)
-    if old is not None:
-        del __classes[(uuid, type)]
-    return old
+    __classes_lock.acquire()
+    try:
+        old = get(uuid, type)
+        if old is not None:
+            del __classes[(uuid, type)]
+        return old
+    finally:
+        __classes_lock.release()
 
 def get(uuid, type):
     """
     Get the instances by uuid and type
     """
-    return __classes.get((uuid, type), None)
+    __classes_lock.acquire()
+    try:
+        return __classes.get((uuid, type), None)
+    finally:
+        __classes_lock.release()
 
 def get_all(all_type):
     """
     Get all instances by type
     """
-    return [inst
-            for ((uuid, t), inst) in __classes.items()
-            if t == all_type]        
+    __classes_lock.acquire()
+    try:
+        return [inst
+                for ((uuid, t), inst) in __classes.items()
+                if t == all_type]        
+    finally:
+        __classes_lock.release()
 
 def get_all_uuid(all_type):
     """
     Get all uuids by type
     """
-    return [uuid
-            for (uuid, t) in __classes.keys()
-            if t == all_type]
+    __classes_lock.acquire()
+    try:
+        return [uuid
+                for (uuid, t) in __classes.keys()
+                if t == all_type]
+    finally:
+        __classes_lock.release()

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 3/5] Add lock for lspci_info in pci.py
       [not found] <49BA4209.1020702@ab.jp.nec.com>
  2009-03-13 12:06 ` [PATCH 1/5] Implement DGRAM (connectionless) type socket listeners Yosuke Iwamatsu
  2009-03-13 12:06 ` [PATCH 2/5] Add lock for xen-api class instances in XendAPIStore.py Yosuke Iwamatsu
@ 2009-03-13 12:06 ` Yosuke Iwamatsu
  2009-03-13 12:06 ` [PATCH 4/5] Accept udev events and update physical resource information Yosuke Iwamatsu
  2009-03-13 12:06 ` [PATCH 5/5] Add udev rules to deliver hw events to xend Yosuke Iwamatsu
  4 siblings, 0 replies; 8+ messages in thread
From: Yosuke Iwamatsu @ 2009-03-13 12:06 UTC (permalink / raw)
  To: xen-devel

Add lspci_info_lock to protect lspci_info.

Signed-off-by: Yosuke Iwamatsu <y-iwamatsu@ab.jp.nec.com>

------

diff -r c30742011bb8 tools/python/xen/util/pci.py
--- a/tools/python/xen/util/pci.py	Thu Mar 12 18:48:09 2009 +0000
+++ b/tools/python/xen/util/pci.py	Fri Mar 13 16:37:17 2009 +0900
@@ -12,6 +12,7 @@
 import types
 import struct
 import time
+import threading
 from xen.util import utils
 
 PROC_PCI_PATH = '/proc/bus/pci/devices'
@@ -97,6 +98,7 @@
 
 # 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 @@
 
     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 @@
                 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 @@
         Since we cannot obtain these data from sysfs, use 'lspci' command.
         """
         global lspci_info
+        global lspci_info_lock
 
-        if lspci_info is None:
-            create_lspci_info()
+        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
+            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
+            return True
+        finally:
+            lspci_info_lock.release()
 
     def __str__(self):
         str = "PCI Device %s\n" % (self.name)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 4/5] Accept udev events and update physical resource information
       [not found] <49BA4209.1020702@ab.jp.nec.com>
                   ` (2 preceding siblings ...)
  2009-03-13 12:06 ` [PATCH 3/5] Add lock for lspci_info in pci.py Yosuke Iwamatsu
@ 2009-03-13 12:06 ` Yosuke Iwamatsu
  2009-03-23  7:05   ` [PATCH 4/5] Accept udev events and update physicalresource information Masaki Kanno
  2009-03-13 12:06 ` [PATCH 5/5] Add udev rules to deliver hw events to xend Yosuke Iwamatsu
  4 siblings, 1 reply; 8+ messages in thread
From: Yosuke Iwamatsu @ 2009-03-13 12:06 UTC (permalink / raw)
  To: xen-devel

This is the main part of the patch series.
When a udev event is received, udevevent.py parses the udev data and tells
XendNode.py to update the physical resource information.
This patch also add a boolean parameter 'xend-udev-event-server', to let users
indicate whether we should enable this function or not. 

Signed-off-by: Yosuke Iwamatsu <y-iwamatsu@ab.jp.nec.com>

------

diff -r c30742011bb8 tools/examples/xend-config.sxp
--- a/tools/examples/xend-config.sxp	Thu Mar 12 18:48:09 2009 +0000
+++ b/tools/examples/xend-config.sxp	Fri Mar 13 16:38:17 2009 +0900
@@ -64,6 +64,7 @@
 #(xend-relocation-server no)
 (xend-relocation-server yes)
 #(xend-relocation-ssl-server no)
+#(xend-udev-event-server no)
 
 #(xend-unix-path /var/lib/xend/xend-socket)
 
diff -r c30742011bb8 tools/python/xen/xend/XendNode.py
--- a/tools/python/xen/xend/XendNode.py	Thu Mar 12 18:48:09 2009 +0000
+++ b/tools/python/xen/xend/XendNode.py	Fri Mar 13 16:38:17 2009 +0900
@@ -146,6 +146,18 @@
 
         self.srs = {}
 
+        self._init_networks()
+        self._init_PIFs()
+
+        self._init_SRs()
+        self._init_PBDs()
+       
+        self._init_PPCIs()
+
+        self._init_PSCSIs()
+
+
+    def _init_networks(self):
         # Initialise networks
         # First configure ones off disk
         saved_networks = self.state_store.load_state('network')
@@ -179,6 +191,7 @@
             if unconfigured_bridge != 'tmpbridge':
                 XendNetwork.create_phy(unconfigured_bridge)
 
+    def _init_PIFs(self):
         # Initialise PIFs
         # First configure ones off disk
         saved_pifs = self.state_store.load_state('pif')
@@ -221,7 +234,8 @@
                     log.debug("Cannot find network for bridge %s "
                               "when configuring PIF %s",
                               (bridge_name, name))     
-        
+
+    def _init_SRs(self):
         # initialise storage
         saved_srs = self.state_store.load_state('sr')
         if saved_srs:
@@ -240,6 +254,7 @@
             qcow_sr_uuid = uuid.createString()
             self.srs[qcow_sr_uuid] = XendQCoWStorageRepo(qcow_sr_uuid)
 
+    def _init_PBDs(self):
         saved_pbds = self.state_store.load_state('pbd')
         if saved_pbds:
             for pbd_uuid, pbd_cfg in saved_pbds.items():
@@ -247,8 +262,8 @@
                     XendPBD.recreate(pbd_uuid, pbd_cfg)
                 except CreateUnspecifiedAttributeError:
                     log.warn("Error recreating PBD %s", pbd_uuid) 
-
-
+ 
+    def _init_PPCIs(self):
         # Initialise PPCIs
         saved_ppcis = self.state_store.load_state('ppci')
         saved_ppci_table = {}
@@ -282,7 +297,7 @@
             ppci_uuid = saved_ppci_table.get(pci_dev.name, uuid.createString())
             XendPPCI(ppci_uuid, ppci_record)
 
-
+    def _init_PSCSIs(self):
         # Initialise PSCSIs
         saved_pscsis = self.state_store.load_state('pscsi')
         saved_pscsi_table = {}
@@ -299,6 +314,75 @@
                 pscsi_uuid = saved_pscsi_table.get(pscsi_record['scsi_id'],
                                                    uuid.createString())
                 XendPSCSI(pscsi_uuid, pscsi_record)
+
+
+    def add_network(self, interface):
+        # TODO
+        log.debug("add_network(): Not implemented.")
+
+
+    def remove_network(self, interface):
+        # TODO
+        log.debug("remove_network(): Not implemented.")
+
+
+    def add_PPCI(self, pci_name):
+        # Update lspci info
+        PciUtil.create_lspci_info()
+
+        # Initialise the PPCI
+        saved_ppcis = self.state_store.load_state('ppci')
+        saved_ppci_table = {}
+        if saved_ppcis:
+            for ppci_uuid, ppci_record in saved_ppcis.items():
+                try:
+                    saved_ppci_table[ppci_record['name']] = ppci_uuid
+                except KeyError:
+                    pass
+
+        (domain, bus, slot, func) = PciUtil.parse_pci_name(pci_name)
+        pci_dev = PciUtil.PciDevice(domain, bus, slot, func)
+        ppci_record = {
+            'domain':                   pci_dev.domain,
+            'bus':                      pci_dev.bus,
+            'slot':                     pci_dev.slot,
+            'func':                     pci_dev.func,
+            'vendor_id':                pci_dev.vendor,
+            'vendor_name':              pci_dev.vendorname,
+            'device_id':                pci_dev.device,
+            'device_name':              pci_dev.devicename,
+            'revision_id':              pci_dev.revision,
+            'class_code':               pci_dev.classcode,
+            'class_name':               pci_dev.classname,
+            'subsystem_vendor_id':      pci_dev.subvendor,
+            'subsystem_vendor_name':    pci_dev.subvendorname,
+            'subsystem_id':             pci_dev.subdevice,
+            'subsystem_name':           pci_dev.subdevicename,
+            'driver':                   pci_dev.driver
+            }
+        # If saved uuid exists, use it. Otherwise create one.
+        ppci_uuid = saved_ppci_table.get(pci_dev.name, uuid.createString())
+        XendPPCI(ppci_uuid, ppci_record)
+
+
+    def remove_PPCI(self, pci_name):
+        # Update lspci info
+        PciUtil.create_lspci_info()
+
+        # Remove the PPCI
+        (domain, bus, slot, func) = PciUtil.parse_pci_name(pci_name)
+        ppci_ref = XendPPCI.get_by_sbdf(domain, bus, slot, func)
+        XendAPIStore.get(ppci_ref, "PPCI").destroy()
+
+
+    def add_PSCSI(self):
+        # TODO
+        log.debug("add_network(): Not implemented.")
+
+
+    def remove_PSCSI(self):
+        # TODO
+        log.debug("add_network(): Not implemented.")
 
 
 ##    def network_destroy(self, net_uuid):
diff -r c30742011bb8 tools/python/xen/xend/XendOptions.py
--- a/tools/python/xen/xend/XendOptions.py	Thu Mar 12 18:48:09 2009 +0000
+++ b/tools/python/xen/xend/XendOptions.py	Fri Mar 13 16:38:17 2009 +0900
@@ -75,6 +75,9 @@
     """Default for the flag indicating whether xend should run a ssl relocation server."""
     xend_relocation_ssl_server_default = 'no'
 
+    """Default for the flag indicating whether xend should run a udev event server."""
+    xend_udev_event_server_default = 'no'
+
     """Default interface address the xend relocation server listens at. """
     xend_relocation_address_default = ''
 
@@ -215,6 +218,10 @@
 
     def get_xend_relocation_server_ssl_cert_file(self):
         return self.get_config_string("xend-relocation-server-ssl-cert-file")
+
+    def get_xend_udev_event_server(self):
+        return self.get_config_bool("xend-udev-event-server",
+                                    self.xend_udev_event_server_default)
 
     def get_xend_port(self):
         """Get the port xend listens at for its HTTP interface.
diff -r c30742011bb8 tools/python/xen/xend/server/SrvDaemon.py
--- a/tools/python/xen/xend/server/SrvDaemon.py	Thu Mar 12 18:48:09 2009 +0000
+++ b/tools/python/xen/xend/server/SrvDaemon.py	Fri Mar 13 16:38:17 2009 +0900
@@ -24,6 +24,7 @@
 from xen.util import mkdir
 
 import relocate
+import udevevent
 import SrvServer
 from params import *
 
@@ -336,6 +337,7 @@
             del xc
 
             relocate.listenRelocation()
+            udevevent.listenUdevEvent()
             servers = SrvServer.create()
             servers.start(status)
             del servers
diff -r c30742011bb8 tools/python/xen/xend/server/udevevent.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/python/xen/xend/server/udevevent.py	Fri Mar 13 16:38:17 2009 +0900
@@ -0,0 +1,68 @@
+import socket
+
+from xen.web import protocol, unix
+
+from xen.xend.XendLogging import log
+from xen.xend import XendNode
+from xen.xend import XendOptions
+
+UDEV_EVENT_PATH = '\0/org/xen/xend/udev_event'
+
+class UdevEventProtocol(protocol.Protocol):
+
+    def __init__(self):
+        protocol.Protocol.__init__(self)
+
+    def dataReceived(self, data):
+        udev_event = {}
+        for entry in data.split('\0'):
+            try:
+                opt, val = entry.split("=")
+                udev_event[opt] = val
+            except (TypeError, ValueError):
+                pass
+        if udev_event.get('ACTION', None) is None:
+            log.warn("Invalid udev event received")
+            return
+
+        log.debug("udev event received: %s", udev_event)
+
+        self._process_event(udev_event)
+
+    def _process_event(self, udev_event):
+        try:
+            if (udev_event.get('SUBSYSTEM', None) == 'pci'):
+                pci_name = udev_event.get('PCI_SLOT_NAME', None)
+                if (udev_event['ACTION'] == 'add'):
+                    log.info("Adding pci device %s", pci_name)
+                    XendNode.instance().add_PPCI(pci_name)
+                elif (udev_event['ACTION'] == 'remove'):
+                    log.info("Removing pci device %s", pci_name)
+                    XendNode.instance().remove_PPCI(pci_name)
+
+            elif (udev_event.get('SUBSYSTEMS', None) == 'scsi'):
+                if (udev_event['ACTION'] == 'add'):
+                    log.info("Adding scsi device")
+                    XendNode.instance().add_PSCSI()
+                elif (udev_event['ACTION'] == 'remove'):
+                    log.info("Removing scci device")
+                    XendNode.instance().remove_PSCSI()
+
+            elif (udev_event.get('SUBSYSTEM', None) == 'net'):
+                interface = udev_event.get('INTERFACE', None)
+                if (udev_event['ACTION'] == 'add'):
+                    log.info("Adding net device %s", interface)
+                    XendNode.instance().add_network(interface)
+                elif (udev_event['ACTION'] == 'remove'):
+                    log.info("Removing net device %s", interface)
+                    XendNode.instance().remove_network(interface)
+            
+        except Exception, e:
+            log.warn("error while processing udev event(): %s" % str(e))
+
+
+def listenUdevEvent():
+    xoptions = XendOptions.instance()
+    if xoptions.get_xend_udev_event_server():
+        unix.UnixDgramListener(UDEV_EVENT_PATH, UdevEventProtocol)
+

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 5/5] Add udev rules to deliver hw events to xend
       [not found] <49BA4209.1020702@ab.jp.nec.com>
                   ` (3 preceding siblings ...)
  2009-03-13 12:06 ` [PATCH 4/5] Accept udev events and update physical resource information Yosuke Iwamatsu
@ 2009-03-13 12:06 ` Yosuke Iwamatsu
  4 siblings, 0 replies; 8+ messages in thread
From: Yosuke Iwamatsu @ 2009-03-13 12:06 UTC (permalink / raw)
  To: xen-devel

Signed-off-by: Yosuke Iwamatsu <y-iwamatsu@ab.jp.nec.com>

------

diff -r c30742011bb8 Makefile
--- a/Makefile	Thu Mar 12 18:48:09 2009 +0000
+++ b/Makefile	Fri Mar 13 16:38:34 2009 +0900
@@ -203,6 +203,8 @@
 	rm -rf $(D)/etc/hotplug/xen-backend.agent
 	rm -f  $(D)/etc/udev/rules.d/xen-backend.rules
 	rm -f  $(D)/etc/udev/xen-backend.rules
+	rm -f  $(D)/etc/udev/rules.d/xend.rules
+	rm -f  $(D)/etc/udev/xend.rules
 	rm -f  $(D)/etc/sysconfig/xendomains
 	rm -rf $(D)/var/run/xen* $(D)/var/lib/xen*
 	rm -rf $(D)/boot/*xen*
diff -r c30742011bb8 tools/hotplug/Linux/Makefile
--- a/tools/hotplug/Linux/Makefile	Thu Mar 12 18:48:09 2009 +0000
+++ b/tools/hotplug/Linux/Makefile	Fri Mar 13 16:38:34 2009 +0900
@@ -29,7 +29,7 @@
 XEN_HOTPLUG_SCRIPTS = xen-backend.agent
 
 UDEV_RULES_DIR = /etc/udev
-UDEV_RULES = xen-backend.rules
+UDEV_RULES = xen-backend.rules xend.rules
 
 DI = $(if $(DISTDIR),$(shell readlink -f $(DISTDIR)),)
 DE = $(if $(DESTDIR),$(shell readlink -f $(DESTDIR)),)
diff -r c30742011bb8 tools/hotplug/Linux/xend.rules
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/hotplug/Linux/xend.rules	Fri Mar 13 16:38:34 2009 +0900
@@ -0,0 +1,3 @@
+SUBSYSTEM=="pci", RUN+="socket:/org/xen/xend/udev_event"
+#SUBSYSTEM=="scsi", RUN+="socket:/org/xen/xend/udev_event"
+#SUBSYSTEM=="net", KERNEL!="vif[0-9]*.[0-9]*|tap[0-9]*.[0-9]*", RUN+="socket:/org/xen/xend/udev_event"

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 4/5] Accept udev events and update physicalresource information
  2009-03-13 12:06 ` [PATCH 4/5] Accept udev events and update physical resource information Yosuke Iwamatsu
@ 2009-03-23  7:05   ` Masaki Kanno
  2009-03-24  8:12     ` [PATCH] xend: save the state of PPCIs after hot-plug ([PATCH 4/5] Accept udev events and update physical resource information) Yosuke Iwamatsu
  0 siblings, 1 reply; 8+ messages in thread
From: Masaki Kanno @ 2009-03-23  7:05 UTC (permalink / raw)
  To: Yosuke Iwamatsu, xen-devel

Hi Yosuke,

I have a question.

Need the patch call save_PPCIs at the end of add_PPCI and the end 
of remove_PPCI?

Best regards,
 Kan

Fri, 13 Mar 2009 21:06:37 +0900, Yosuke Iwamatsu wrote:

>This is the main part of the patch series.
>When a udev event is received, udevevent.py parses the udev data and tells
>XendNode.py to update the physical resource information.
>This patch also add a boolean parameter 'xend-udev-event-server', to let 
>users
>indicate whether we should enable this function or not. 
>
>Signed-off-by: Yosuke Iwamatsu <y-iwamatsu@ab.jp.nec.com>
>
>------
>
>diff -r c30742011bb8 tools/examples/xend-config.sxp
>--- a/tools/examples/xend-config.sxp	Thu Mar 12 18:48:09 2009 +0000
>+++ b/tools/examples/xend-config.sxp	Fri Mar 13 16:38:17 2009 +0900
>@@ -64,6 +64,7 @@
> #(xend-relocation-server no)
> (xend-relocation-server yes)
> #(xend-relocation-ssl-server no)
>+#(xend-udev-event-server no)
> 
> #(xend-unix-path /var/lib/xend/xend-socket)
> 
>diff -r c30742011bb8 tools/python/xen/xend/XendNode.py
>--- a/tools/python/xen/xend/XendNode.py	Thu Mar 12 18:48:09 2009 +0000
>+++ b/tools/python/xen/xend/XendNode.py	Fri Mar 13 16:38:17 2009 +0900
>@@ -146,6 +146,18 @@
> 
>         self.srs = {}
> 
>+        self._init_networks()
>+        self._init_PIFs()
>+
>+        self._init_SRs()
>+        self._init_PBDs()
>+       
>+        self._init_PPCIs()
>+
>+        self._init_PSCSIs()
>+
>+
>+    def _init_networks(self):
>         # Initialise networks
>         # First configure ones off disk
>         saved_networks = self.state_store.load_state('network')
>@@ -179,6 +191,7 @@
>             if unconfigured_bridge != 'tmpbridge':
>                 XendNetwork.create_phy(unconfigured_bridge)
> 
>+    def _init_PIFs(self):
>         # Initialise PIFs
>         # First configure ones off disk
>         saved_pifs = self.state_store.load_state('pif')
>@@ -221,7 +234,8 @@
>                     log.debug("Cannot find network for bridge %s "
>                               "when configuring PIF %s",
>                               (bridge_name, name))     
>-        
>+
>+    def _init_SRs(self):
>         # initialise storage
>         saved_srs = self.state_store.load_state('sr')
>         if saved_srs:
>@@ -240,6 +254,7 @@
>             qcow_sr_uuid = uuid.createString()
>             self.srs[qcow_sr_uuid] = XendQCoWStorageRepo(qcow_sr_uuid)
> 
>+    def _init_PBDs(self):
>         saved_pbds = self.state_store.load_state('pbd')
>         if saved_pbds:
>             for pbd_uuid, pbd_cfg in saved_pbds.items():
>@@ -247,8 +262,8 @@
>                     XendPBD.recreate(pbd_uuid, pbd_cfg)
>                 except CreateUnspecifiedAttributeError:
>                     log.warn("Error recreating PBD %s", pbd_uuid) 
>-
>-
>+ 
>+    def _init_PPCIs(self):
>         # Initialise PPCIs
>         saved_ppcis = self.state_store.load_state('ppci')
>         saved_ppci_table = {}
>@@ -282,7 +297,7 @@
>             ppci_uuid = saved_ppci_table.get(pci_dev.name, uuid.
>createString())
>             XendPPCI(ppci_uuid, ppci_record)
> 
>-
>+    def _init_PSCSIs(self):
>         # Initialise PSCSIs
>         saved_pscsis = self.state_store.load_state('pscsi')
>         saved_pscsi_table = {}
>@@ -299,6 +314,75 @@
>                 pscsi_uuid = saved_pscsi_table.get(pscsi_record['scsi_id'],
>                                                    uuid.createString())
>                 XendPSCSI(pscsi_uuid, pscsi_record)
>+
>+
>+    def add_network(self, interface):
>+        # TODO
>+        log.debug("add_network(): Not implemented.")
>+
>+
>+    def remove_network(self, interface):
>+        # TODO
>+        log.debug("remove_network(): Not implemented.")
>+
>+
>+    def add_PPCI(self, pci_name):
>+        # Update lspci info
>+        PciUtil.create_lspci_info()
>+
>+        # Initialise the PPCI
>+        saved_ppcis = self.state_store.load_state('ppci')
>+        saved_ppci_table = {}
>+        if saved_ppcis:
>+            for ppci_uuid, ppci_record in saved_ppcis.items():
>+                try:
>+                    saved_ppci_table[ppci_record['name']] = ppci_uuid
>+                except KeyError:
>+                    pass
>+
>+        (domain, bus, slot, func) = PciUtil.parse_pci_name(pci_name)
>+        pci_dev = PciUtil.PciDevice(domain, bus, slot, func)
>+        ppci_record = {
>+            'domain':                   pci_dev.domain,
>+            'bus':                      pci_dev.bus,
>+            'slot':                     pci_dev.slot,
>+            'func':                     pci_dev.func,
>+            'vendor_id':                pci_dev.vendor,
>+            'vendor_name':              pci_dev.vendorname,
>+            'device_id':                pci_dev.device,
>+            'device_name':              pci_dev.devicename,
>+            'revision_id':              pci_dev.revision,
>+            'class_code':               pci_dev.classcode,
>+            'class_name':               pci_dev.classname,
>+            'subsystem_vendor_id':      pci_dev.subvendor,
>+            'subsystem_vendor_name':    pci_dev.subvendorname,
>+            'subsystem_id':             pci_dev.subdevice,
>+            'subsystem_name':           pci_dev.subdevicename,
>+            'driver':                   pci_dev.driver
>+            }
>+        # If saved uuid exists, use it. Otherwise create one.
>+        ppci_uuid = saved_ppci_table.get(pci_dev.name, uuid.createString())
>+        XendPPCI(ppci_uuid, ppci_record)
>+
>+
>+    def remove_PPCI(self, pci_name):
>+        # Update lspci info
>+        PciUtil.create_lspci_info()
>+
>+        # Remove the PPCI
>+        (domain, bus, slot, func) = PciUtil.parse_pci_name(pci_name)
>+        ppci_ref = XendPPCI.get_by_sbdf(domain, bus, slot, func)
>+        XendAPIStore.get(ppci_ref, "PPCI").destroy()
>+
>+
>+    def add_PSCSI(self):
>+        # TODO
>+        log.debug("add_network(): Not implemented.")
>+
>+
>+    def remove_PSCSI(self):
>+        # TODO
>+        log.debug("add_network(): Not implemented.")
> 
> 
> ##    def network_destroy(self, net_uuid):
>diff -r c30742011bb8 tools/python/xen/xend/XendOptions.py
>--- a/tools/python/xen/xend/XendOptions.py	Thu Mar 12 18:48:09 2009 +0000
>+++ b/tools/python/xen/xend/XendOptions.py	Fri Mar 13 16:38:17 2009 +0900
>@@ -75,6 +75,9 @@
>     """Default for the flag indicating whether xend should run a ssl 
>relocation server."""
>     xend_relocation_ssl_server_default = 'no'
> 
>+    """Default for the flag indicating whether xend should run a udev 
>event server."""
>+    xend_udev_event_server_default = 'no'
>+
>     """Default interface address the xend relocation server listens at. """
>     xend_relocation_address_default = ''
> 
>@@ -215,6 +218,10 @@
> 
>     def get_xend_relocation_server_ssl_cert_file(self):
>         return self.get_config_string("xend-relocation-server-ssl-cert-
>file")
>+
>+    def get_xend_udev_event_server(self):
>+        return self.get_config_bool("xend-udev-event-server",
>+                                    self.xend_udev_event_server_default)
> 
>     def get_xend_port(self):
>         """Get the port xend listens at for its HTTP interface.
>diff -r c30742011bb8 tools/python/xen/xend/server/SrvDaemon.py
>--- a/tools/python/xen/xend/server/SrvDaemon.py	Thu Mar 12 18:48:09 
2009 +
>0000
>+++ b/tools/python/xen/xend/server/SrvDaemon.py	Fri Mar 13 16:38:17 
2009 +
>0900
>@@ -24,6 +24,7 @@
> from xen.util import mkdir
> 
> import relocate
>+import udevevent
> import SrvServer
> from params import *
> 
>@@ -336,6 +337,7 @@
>             del xc
> 
>             relocate.listenRelocation()
>+            udevevent.listenUdevEvent()
>             servers = SrvServer.create()
>             servers.start(status)
>             del servers
>diff -r c30742011bb8 tools/python/xen/xend/server/udevevent.py
>--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
>+++ b/tools/python/xen/xend/server/udevevent.py	Fri Mar 13 16:38:17 
2009 +
>0900
>@@ -0,0 +1,68 @@
>+import socket
>+
>+from xen.web import protocol, unix
>+
>+from xen.xend.XendLogging import log
>+from xen.xend import XendNode
>+from xen.xend import XendOptions
>+
>+UDEV_EVENT_PATH = '\0/org/xen/xend/udev_event'
>+
>+class UdevEventProtocol(protocol.Protocol):
>+
>+    def __init__(self):
>+        protocol.Protocol.__init__(self)
>+
>+    def dataReceived(self, data):
>+        udev_event = {}
>+        for entry in data.split('\0'):
>+            try:
>+                opt, val = entry.split("=")
>+                udev_event[opt] = val
>+            except (TypeError, ValueError):
>+                pass
>+        if udev_event.get('ACTION', None) is None:
>+            log.warn("Invalid udev event received")
>+            return
>+
>+        log.debug("udev event received: %s", udev_event)
>+
>+        self._process_event(udev_event)
>+
>+    def _process_event(self, udev_event):
>+        try:
>+            if (udev_event.get('SUBSYSTEM', None) == 'pci'):
>+                pci_name = udev_event.get('PCI_SLOT_NAME', None)
>+                if (udev_event['ACTION'] == 'add'):
>+                    log.info("Adding pci device %s", pci_name)
>+                    XendNode.instance().add_PPCI(pci_name)
>+                elif (udev_event['ACTION'] == 'remove'):
>+                    log.info("Removing pci device %s", pci_name)
>+                    XendNode.instance().remove_PPCI(pci_name)
>+
>+            elif (udev_event.get('SUBSYSTEMS', None) == 'scsi'):
>+                if (udev_event['ACTION'] == 'add'):
>+                    log.info("Adding scsi device")
>+                    XendNode.instance().add_PSCSI()
>+                elif (udev_event['ACTION'] == 'remove'):
>+                    log.info("Removing scci device")
>+                    XendNode.instance().remove_PSCSI()
>+
>+            elif (udev_event.get('SUBSYSTEM', None) == 'net'):
>+                interface = udev_event.get('INTERFACE', None)
>+                if (udev_event['ACTION'] == 'add'):
>+                    log.info("Adding net device %s", interface)
>+                    XendNode.instance().add_network(interface)
>+                elif (udev_event['ACTION'] == 'remove'):
>+                    log.info("Removing net device %s", interface)
>+                    XendNode.instance().remove_network(interface)
>+            
>+        except Exception, e:
>+            log.warn("error while processing udev event(): %s" % str(e))
>+
>+
>+def listenUdevEvent():
>+    xoptions = XendOptions.instance()
>+    if xoptions.get_xend_udev_event_server():
>+        unix.UnixDgramListener(UDEV_EVENT_PATH, UdevEventProtocol)
>+
>
>
>
>
>_______________________________________________
>Xen-devel mailing list
>Xen-devel@lists.xensource.com
>http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH] xend: save the state of PPCIs after hot-plug ([PATCH 4/5] Accept udev events and update physical resource information)
  2009-03-23  7:05   ` [PATCH 4/5] Accept udev events and update physicalresource information Masaki Kanno
@ 2009-03-24  8:12     ` Yosuke Iwamatsu
  2009-03-25  9:24       ` Masaki Kanno
  0 siblings, 1 reply; 8+ messages in thread
From: Yosuke Iwamatsu @ 2009-03-24  8:12 UTC (permalink / raw)
  To: Masaki Kanno; +Cc: xen-devel

Masaki Kanno wrote:
> Hi Yosuke,
> 
> I have a question.
> 
> Need the patch call save_PPCIs at the end of add_PPCI and the end 
> of remove_PPCI?
> 

It seems you are right. I generated a patch to do that.
Thank you.

-- Yosuke

--------

xend: Save the state of PPCIs after hot-plug events.

Signed-off-by: Yosuke Iwamatsu <y-iwamatsu@ab.jp.nec.com>

diff -r 0477f9061c8a tools/python/xen/xend/XendNode.py
--- a/tools/python/xen/xend/XendNode.py	Fri Mar 20 17:42:46 2009 +0000
+++ b/tools/python/xen/xend/XendNode.py	Tue Mar 24 15:32:00 2009 +0900
@@ -363,6 +363,8 @@
        ppci_uuid = saved_ppci_table.get(pci_dev.name, uuid.createString())
        XendPPCI(ppci_uuid, ppci_record)

+        self.save_PPCIs()
+

    def remove_PPCI(self, pci_name):
        # Update lspci info
@@ -372,6 +374,8 @@
        (domain, bus, slot, func) = PciUtil.parse_pci_name(pci_name)
        ppci_ref = XendPPCI.get_by_sbdf(domain, bus, slot, func)
        XendAPIStore.get(ppci_ref, "PPCI").destroy()
+
+        self.save_PPCIs()


    def add_PSCSI(self):

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] xend: save the state of PPCIs after hot-plug ([PATCH 4/5] Accept udev events and update physical resource information)
  2009-03-24  8:12     ` [PATCH] xend: save the state of PPCIs after hot-plug ([PATCH 4/5] Accept udev events and update physical resource information) Yosuke Iwamatsu
@ 2009-03-25  9:24       ` Masaki Kanno
  0 siblings, 0 replies; 8+ messages in thread
From: Masaki Kanno @ 2009-03-25  9:24 UTC (permalink / raw)
  To: Yosuke Iwamatsu; +Cc: xen-devel

Hi Yosuke,

Thanks for your reply.
I have felt sure of my thought by your reply.
I have written a patch for SCSI devices.  The patch accepts udev 
events about SCSI devices, then it updates physical SCSI information.
I'm going to send the patch to xen-devel.

Best regards,
 Kan

Tue, 24 Mar 2009 17:12:58 +0900, Yosuke Iwamatsu wrote:

>Masaki Kanno wrote:
>> Hi Yosuke,
>> 
>> I have a question.
>> 
>> Need the patch call save_PPCIs at the end of add_PPCI and the end 
>> of remove_PPCI?
>> 
>
>It seems you are right. I generated a patch to do that.
>Thank you.
>
>-- Yosuke
>
>--------
>
>xend: Save the state of PPCIs after hot-plug events.
>
>Signed-off-by: Yosuke Iwamatsu <y-iwamatsu@ab.jp.nec.com>
>
>diff -r 0477f9061c8a tools/python/xen/xend/XendNode.py
>--- a/tools/python/xen/xend/XendNode.py	Fri Mar 20 17:42:46 2009 +0000
>+++ b/tools/python/xen/xend/XendNode.py	Tue Mar 24 15:32:00 2009 +0900
>@@ -363,6 +363,8 @@
>        ppci_uuid = saved_ppci_table.get(pci_dev.name, uuid.createString())
>        XendPPCI(ppci_uuid, ppci_record)
>
>+        self.save_PPCIs()
>+
>
>    def remove_PPCI(self, pci_name):
>        # Update lspci info
>@@ -372,6 +374,8 @@
>        (domain, bus, slot, func) = PciUtil.parse_pci_name(pci_name)
>        ppci_ref = XendPPCI.get_by_sbdf(domain, bus, slot, func)
>        XendAPIStore.get(ppci_ref, "PPCI").destroy()
>+
>+        self.save_PPCIs()
>
>
>    def add_PSCSI(self):
>
>
>
>_______________________________________________
>Xen-devel mailing list
>Xen-devel@lists.xensource.com
>http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-03-25  9:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <49BA4209.1020702@ab.jp.nec.com>
2009-03-13 12:06 ` [PATCH 1/5] Implement DGRAM (connectionless) type socket listeners Yosuke Iwamatsu
2009-03-13 12:06 ` [PATCH 2/5] Add lock for xen-api class instances in XendAPIStore.py Yosuke Iwamatsu
2009-03-13 12:06 ` [PATCH 3/5] Add lock for lspci_info in pci.py Yosuke Iwamatsu
2009-03-13 12:06 ` [PATCH 4/5] Accept udev events and update physical resource information Yosuke Iwamatsu
2009-03-23  7:05   ` [PATCH 4/5] Accept udev events and update physicalresource information Masaki Kanno
2009-03-24  8:12     ` [PATCH] xend: save the state of PPCIs after hot-plug ([PATCH 4/5] Accept udev events and update physical resource information) Yosuke Iwamatsu
2009-03-25  9:24       ` Masaki Kanno
2009-03-13 12:06 ` [PATCH 5/5] Add udev rules to deliver hw events to xend Yosuke Iwamatsu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.