mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 02:30:03 +01:00
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@xensource.com>
This commit is contained in:
1 parent
2bf2793e18
commit
5840748740
1 file changed
+46
-28
@@ -79,9 +79,36 @@ class DevController:
|
||||
if devid is None:
|
||||
return 0
|
||||
|
||||
self.writeDetails(config, devid, back, front)
|
||||
(backpath, frontpath) = self.addStoreEntries(config, devid, back,
|
||||
front)
|
||||
|
||||
return devid
|
||||
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 @@ class DevController:
|
||||
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 @@ class DevController:
|
||||
'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):
|
||||
|
||||