# HG changeset patch
# User emellor@xxxxxxxxxxxxxxxxxxxxxx
# Node ID 4d1d9f7ebcfc79f96631382ea812ca986c7156dd
# Parent 1cf273e133c8bb89fb61f49f655ede4eb84ae824
Check whether a device is already configured before trying to configure it
again. Closes bug #397.
To perform this check in the same transaction as the writing of the device
entries has required a little bit of rejigging.
Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>
diff -r 1cf273e133c8 -r 4d1d9f7ebcfc
tools/python/xen/xend/server/DevController.py
--- a/tools/python/xen/xend/server/DevController.py Thu Nov 24 15:55:49 2005
+++ b/tools/python/xen/xend/server/DevController.py Thu Nov 24 15:57:36 2005
@@ -79,9 +79,36 @@
if devid is None:
return 0
- self.writeDetails(config, devid, back, front)
-
- return devid
+ (backpath, frontpath) = self.addStoreEntries(config, devid, back,
+ front)
+
+ while True:
+ t = xstransact()
+ try:
+ if devid in self.deviceIDs(t):
+ if 'dev' in back:
+ dev_str = '%s (%d, %s)' % (back['dev'], devid,
+ self.deviceClass)
+ else:
+ dev_str = '%s (%s)' % (devid, self.deviceClass)
+
+ raise VmError("Device %s is already connected." % dev_str)
+
+ log.debug('DevController: writing %s to %s.', str(front),
+ frontpath)
+ log.debug('DevController: writing %s to %s.', str(back),
+ backpath)
+
+ t.remove2(backpath, HOTPLUG_STATUS_NODE)
+
+ t.write2(frontpath, front)
+ t.write2(backpath, back)
+
+ if t.commit():
+ return devid
+ except:
+ t.abort()
+ raise
def waitForDevices(self):
@@ -245,21 +272,29 @@
raise VmError("Device %s not connected" % devid)
- def deviceIDs(self):
+ def deviceIDs(self, transaction = None):
"""@return The IDs of each of the devices currently configured for
this instance's deviceClass.
"""
- return map(int, xstransact.List(self.frontendRoot()))
+ fe = self.frontendRoot()
+ if transaction:
+ return map(lambda x: int(x.split('/')[-1]), transaction.list(fe))
+ else:
+ return map(int, xstransact.List(fe))
## private:
- def writeDetails(self, config, devid, backDetails, frontDetails):
- """Write the details in the store to trigger creation of a device.
- The backend domain ID is taken from the given config, paths for
- frontend and backend are computed, and these are written to the store
- appropriately, including references from frontend to backend and vice
- versa.
+ def addStoreEntries(self, config, devid, backDetails, frontDetails):
+ """Add to backDetails and frontDetails the entries to be written in
+ the store to trigger creation of a device. The backend domain ID is
+ taken from the given config, paths for frontend and backend are
+ computed, and these are added to the backDetails and frontDetails
+ dictionaries for writing to the store, including references from
+ frontend to backend and vice versa.
+
+ @return A pair of (backpath, frontpath). backDetails and frontDetails
+ will have been updated appropriately, also.
@param config The configuration of the device, as given to
{@link #createDevice}.
@@ -298,24 +333,7 @@
'state' : str(xenbusState['Initialising'])
})
- log.debug('DevController: writing %s to %s.', str(frontDetails),
- frontpath)
- log.debug('DevController: writing %s to %s.', str(backDetails),
- backpath)
-
- while True:
- t = xstransact()
- try:
- t.remove2(backpath, HOTPLUG_STATUS_NODE)
-
- t.write2(frontpath, frontDetails)
- t.write2(backpath, backDetails)
-
- if t.commit():
- return
- except:
- t.abort()
- raise
+ return (backpath, frontpath)
def waitForBackend(self, devid):
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|