Skip to contentSkip to conversation

pvSCSI: add new device assignment mode

PATCH New Jun Kamada 1 participant 1 message Feb 16, 2009

lore
Share & tools
lore

Jun Kamada

author
#0 lore raw

PATCH 2/2 pvSCSI: add new device assignment mode

Attached is patch for xend.

You can use "host" mode by specifying keyword "host" as virtual scsi device. Following is usage example.

    xm scsi-attach 1 2:0:3:4 host

In this case, all LUNs under host=2 are attached to guest domain 1. The channel=0, target=3 and lun=4 are ignored.

-----
Jun Kamada

tools/python/xen/xend/XendConfig.py +26 -8
diff -r 09a6fa059b37 tools/python/xen/xend/XendConfig.py
@@ -1272,6 +1272,7 @@ class XendConfig(dict):
                                                   uuid.createString())
                 vscsi_dict = self.vscsi_convert_sxp_to_dict(config)
                 vscsi_devs = vscsi_dict['devs']
+                vscsi_mode = vscsi_dict['feature-host']
 
                 # create XenAPI DSCSI objects.
                 for vscsi_dev in vscsi_devs:
@@ -1286,9 +1287,14 @@ class XendConfig(dict):
                     }
                     XendDSCSI(dscsi_uuid, dscsi_record)
 
-                target['devices'][vscsi_devs_uuid] = \
-                    (dev_type, {'devs': vscsi_devs, 'uuid': vscsi_devs_uuid} )
-                log.debug("XendConfig: reading device: %s" % vscsi_devs)
+                vscsi_info = {
+                    'devs': vscsi_devs,
+                    'feature-host': vscsi_mode,
+                    'uuid': vscsi_devs_uuid
+                }
+                target['devices'][vscsi_devs_uuid] = (dev_type, vscsi_info)
+                log.debug("XendConfig: reading device: %s,%s" % \
+                          (vscsi_devs, vscsi_mode))
                 return vscsi_devs_uuid
 
             for opt_val in config[1:]:
@@ -1612,6 +1618,7 @@ class XendConfig(dict):
         #
         # [device,
         #   [vscsi,
+        #     [feature-host, 0],
         #     [dev,
         #       [devid, 0], [p-devname, sdb], [p-dev, 1:0:0:1],
         #       [v-dev, 0:0:0:0], [state, 1]
@@ -1622,6 +1629,7 @@ class XendConfig(dict):
         #     ]
         #   ],
         #   [vscsi,
+        #     [feature-host, 1],
         #     [dev,
         #       [devid, 1], [p-devname, sdg], [p-dev, 2:0:0:0],
         #       [v-dev, 1:0:0:0], [state, 1]
@@ -1642,6 +1650,7 @@ class XendConfig(dict):
         #
         # [device,
         #   [vscsi,
+        #     [feature-host, 0],
         #     [dev,
         #       [devid, 0], [p-devname, sdd], [p-dev, 1:0:0:3],
         #       [v-dev, 0:0:0:2], [state, 1]
@@ -1656,7 +1665,8 @@ class XendConfig(dict):
         # The Dict looks like this:
         #
         # { devs: [ {devid: 0, p-devname: sdd, p-dev: 1:0:0:3,
-        #            v-dev: 0:0:0:2, state: 1} ] }
+        #            v-dev: 0:0:0:2, state: 1} ],
+        #   feature-host: 1 }
 
         dev_config = {}
 
@@ -1675,6 +1685,9 @@ class XendConfig(dict):
             vscsi_devs.append(vscsi_dev_info)
         dev_config['devs'] = vscsi_devs 
 
+        vscsi_mode = sxp.children(dev_sxp, 'feature-host')[0]
+        dev_config['feature-host'] = vscsi_mode[1]
+
         return dev_config
 
     def console_add(self, protocol, location, other_config = {}):
@@ -1787,6 +1800,7 @@ class XendConfig(dict):
             if dev_type == 'vscsi': # Special case for vscsi
                 vscsi_dict = self.vscsi_convert_sxp_to_dict(config)
                 vscsi_devs = vscsi_dict['devs']
+                vscsi_mode = vscsi_dict['feature-host']
 
                 # destroy existing XenAPI DSCSI objects
                 for dscsi_uuid in XendDSCSI.get_by_VM(self['uuid']):
@@ -1805,8 +1819,12 @@ class XendConfig(dict):
                     }
                     XendDSCSI(dscsi_uuid, dscsi_record)
 
-                self['devices'][dev_uuid] = \
-                    (dev_type, {'devs': vscsi_devs, 'uuid': dev_uuid} )
+                vscsi_info = { 
+                    'devs': vscsi_devs,
+                    'feature-host': vscsi_mode,
+                    'uuid': dev_uuid
+                }
+                self['devices'][dev_uuid] = (dev_type, vscsi_info)
                 return True
                 
             for opt_val in config[1:]:
@@ -1883,7 +1901,6 @@ class XendConfig(dict):
     def all_devices_sxpr(self, target = None):
         """Returns the SXPR for all devices in the current configuration."""
         sxprs = []
-        pci_devs = []
 
         if target == None:
             target = self
@@ -1898,7 +1915,8 @@ class XendConfig(dict):
                 if dev_type == 'pci':
                     sxpr = ['pci', ['uuid', dev_info['uuid']]]
                 elif dev_type == 'vscsi':
-                    sxpr = ['vscsi', ['uuid', dev_info['uuid']]]
+                    sxpr = ['vscsi', ['uuid', dev_info['uuid']],
+                                     ['feature-host', dev_info['feature-host']]]
                 for pci_dev_info in dev_info['devs']:
                     pci_dev_sxpr = ['dev']
                     for opt, val in pci_dev_info.items():
tools/python/xen/xend/XendDomainInfo.py +9 -2
diff -r 09a6fa059b37 tools/python/xen/xend/XendDomainInfo.py
@@ -898,15 +898,21 @@ class XendDomainInfo:
         else:
             cur_dev_sxp = self._getDeviceInfo_vscsi(req_devid, None)
             new_dev_sxp = ['vscsi']
+            cur_mode = sxp.children(cur_dev_sxp, 'feature-host')[0]
+            new_dev_sxp.append(cur_mode)
+
             for cur_dev in sxp.children(cur_dev_sxp, 'dev'):
                 if state == xenbusState['Closing']:
+                    if int(cur_mode[1]) == 1:
+                        continue
                     cur_dev_vdev = sxp.child_value(cur_dev, 'v-dev')
                     if cur_dev_vdev == dev['v-dev']:
                         continue
                 new_dev_sxp.append(cur_dev)
 
             if state == xenbusState['Initialising']:
-                new_dev_sxp.append(sxp.child0(dev_sxp, 'dev'))
+                for new_dev in sxp.children(dev_sxp, 'dev'):
+                    new_dev_sxp.append(new_dev)
 
             dev_uuid = sxp.child_value(cur_dev_sxp, 'uuid')
             self.info.device_update(dev_uuid, new_dev_sxp)
@@ -1112,7 +1118,8 @@ class XendDomainInfo:
                         vscsi_dev.append(['frontstate', None])
                         vscsi_devs[1].append(vscsi_dev)
                         dev_num = int(sxp.child_value(vscsi_dev, 'devid'))
-                    sxprs.append([dev_num, [vscsi_devs]])
+                    vscsi_mode = sxp.children(dev_info, 'feature-host')[0]
+                    sxprs.append([dev_num, [vscsi_devs, vscsi_mode]])
                 elif deviceClass == 'vbd':
                     dev = sxp.child_value(dev_info, 'dev')
                     if 'ioemu:' in dev:
tools/python/xen/xend/server/vscsiif.py +14 -1
diff -r 09a6fa059b37 tools/python/xen/xend/server/vscsiif.py
@@ -68,6 +68,8 @@ class VSCSIController(DevController):
             vscsi_config.append(['devs', devs])
             state = self.readFrontend(devid, 'state')
             vscsi_config.append(['state', state])
+            hostmode = self.readBackend(devid, 'feature-host')
+            vscsi_config.append(['feature-host', hostmode])
             backid = self.readFrontend(devid, 'backend-id')
             vscsi_config.append(['backend-id', backid])
             backpath = self.readFrontend(devid, 'backend')
@@ -98,6 +100,8 @@ class VSCSIController(DevController):
             devid = vscsi_config.get('devid', '')
             back[devpath + '/devid'] = str(devid)
 
+        host_mode = config.get('feature-host','')
+        back['feature-host'] = str(host_mode)
         back['uuid'] = config.get('uuid','')
         devid = int(devid)
         return (devid, back, {})
@@ -133,6 +137,7 @@ class VSCSIController(DevController):
             vscsi_devs.append(dev_dict)
 
         config['devs'] = vscsi_devs
+        config['feature-host'] = self.readBackend(devid, 'feature-host')
         config['uuid'] = self.readBackend(devid, 'uuid')
         return config
 
@@ -171,6 +176,7 @@ class VSCSIController(DevController):
         vscsi_config = config['devs'][0]
         state = vscsi_config.get('state', xenbusState['Unknown'])
         driver_state = self.readBackend(devid, 'state')
+
         if str(xenbusState['Connected']) != driver_state:
             raise VmError("Driver status is not connected")
 
@@ -182,13 +188,20 @@ class VSCSIController(DevController):
         elif state == xenbusState['Closing']:
             found = False
             devs = self.readBackendList(devid, "vscsi-devs")
+            hostmode = int(self.readBackend(devid, 'feature-host'))
             vscsipath = "vscsi-devs/"
             vdev = vscsi_config.get('v-dev', '')
 
             for dev in devs:
                 devpath = vscsipath + dev
                 old_vdev = self.readBackend(devid, devpath + '/v-dev')
-                if vdev == old_vdev:
+
+                if hostmode == 1:
+                    #At hostmode, all v-dev that belongs to devid is deleted.
+                    found = True
+                    self.writeBackend(devid, devpath + '/state', \
+                                    str(xenbusState['Closing']))
+                elif vdev == old_vdev:
                     found = True
                     self.writeBackend(devid, devpath + '/state', \
                                     str(xenbusState['Closing']))
tools/python/xen/xm/create.py +29 -16

80 lines not on this page · raw message

tools/python/xen/xm/main.py +41 -20

88 lines not on this page · raw message

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel