direct-io.hg

changeset 8019:4d1d9f7ebcfc

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>
author emellor@leeni.uk.xensource.com
date Thu Nov 24 15:57:36 2005 +0000 (2005-11-24)
parents 1cf273e133c8
children 64d919032001
files tools/python/xen/xend/server/DevController.py
line diff
     1.1 --- a/tools/python/xen/xend/server/DevController.py	Thu Nov 24 15:55:49 2005 +0000
     1.2 +++ b/tools/python/xen/xend/server/DevController.py	Thu Nov 24 15:57:36 2005 +0000
     1.3 @@ -79,9 +79,36 @@ class DevController:
     1.4          if devid is None:
     1.5              return 0
     1.6  
     1.7 -        self.writeDetails(config, devid, back, front)
     1.8 +        (backpath, frontpath) = self.addStoreEntries(config, devid, back,
     1.9 +                                                     front)
    1.10 +
    1.11 +        while True:
    1.12 +            t = xstransact()
    1.13 +            try:
    1.14 +                if devid in self.deviceIDs(t):
    1.15 +                    if 'dev' in back:
    1.16 +                        dev_str = '%s (%d, %s)' % (back['dev'], devid,
    1.17 +                                                   self.deviceClass)
    1.18 +                    else:
    1.19 +                        dev_str = '%s (%s)' % (devid, self.deviceClass)
    1.20 +                    
    1.21 +                    raise VmError("Device %s is already connected." % dev_str)
    1.22  
    1.23 -        return devid
    1.24 +                log.debug('DevController: writing %s to %s.', str(front),
    1.25 +                          frontpath)
    1.26 +                log.debug('DevController: writing %s to %s.', str(back),
    1.27 +                          backpath)
    1.28 +
    1.29 +                t.remove2(backpath, HOTPLUG_STATUS_NODE)
    1.30 +
    1.31 +                t.write2(frontpath, front)
    1.32 +                t.write2(backpath,  back)
    1.33 +
    1.34 +                if t.commit():
    1.35 +                    return devid
    1.36 +            except:
    1.37 +                t.abort()
    1.38 +                raise
    1.39  
    1.40  
    1.41      def waitForDevices(self):
    1.42 @@ -245,21 +272,29 @@ class DevController:
    1.43              raise VmError("Device %s not connected" % devid)
    1.44  
    1.45  
    1.46 -    def deviceIDs(self):
    1.47 +    def deviceIDs(self, transaction = None):
    1.48          """@return The IDs of each of the devices currently configured for
    1.49          this instance's deviceClass.
    1.50          """
    1.51 -        return map(int, xstransact.List(self.frontendRoot()))
    1.52 +        fe = self.frontendRoot()
    1.53 +        if transaction:
    1.54 +            return map(lambda x: int(x.split('/')[-1]), transaction.list(fe))
    1.55 +        else:
    1.56 +            return map(int, xstransact.List(fe))
    1.57  
    1.58  
    1.59  ## private:
    1.60  
    1.61 -    def writeDetails(self, config, devid, backDetails, frontDetails):
    1.62 -        """Write the details in the store to trigger creation of a device.
    1.63 -        The backend domain ID is taken from the given config, paths for
    1.64 -        frontend and backend are computed, and these are written to the store
    1.65 -        appropriately, including references from frontend to backend and vice
    1.66 -        versa.
    1.67 +    def addStoreEntries(self, config, devid, backDetails, frontDetails):
    1.68 +        """Add to backDetails and frontDetails the entries to be written in
    1.69 +        the store to trigger creation of a device.  The backend domain ID is
    1.70 +        taken from the given config, paths for frontend and backend are
    1.71 +        computed, and these are added to the backDetails and frontDetails
    1.72 +        dictionaries for writing to the store, including references from
    1.73 +        frontend to backend and vice versa.
    1.74 +
    1.75 +        @return A pair of (backpath, frontpath).  backDetails and frontDetails
    1.76 +        will have been updated appropriately, also.
    1.77  
    1.78          @param config The configuration of the device, as given to
    1.79          {@link #createDevice}.
    1.80 @@ -298,24 +333,7 @@ class DevController:
    1.81              'state' : str(xenbusState['Initialising'])
    1.82              })
    1.83  
    1.84 -        log.debug('DevController: writing %s to %s.', str(frontDetails),
    1.85 -                  frontpath)
    1.86 -        log.debug('DevController: writing %s to %s.', str(backDetails),
    1.87 -                  backpath)
    1.88 -
    1.89 -        while True:
    1.90 -            t = xstransact()
    1.91 -            try:
    1.92 -                t.remove2(backpath, HOTPLUG_STATUS_NODE)
    1.93 -
    1.94 -                t.write2(frontpath, frontDetails)
    1.95 -                t.write2(backpath,  backDetails)
    1.96 -
    1.97 -                if t.commit():
    1.98 -                    return
    1.99 -            except:
   1.100 -                t.abort()
   1.101 -                raise
   1.102 +        return (backpath, frontpath)
   1.103  
   1.104  
   1.105      def waitForBackend(self, devid):