Revision 2d0c8319 lib/bdev.py

b/lib/bdev.py
1321 1321
                             "C", dual_pri=multimaster)
1322 1322

  
1323 1323
  def Attach(self):
1324
    """Find a DRBD device which matches our config and attach to it.
1324
    """Check if our minor is configured.
1325

  
1326
    This doesn't do any device configurations - it only checks if the
1327
    minor is in a state different from Unconfigured.
1328

  
1329
    Note that this function will not change the state of the system in
1330
    any way (except in case of side-effects caused by reading from
1331
    /proc).
1332

  
1333
    """
1334
    used_devs = self._GetUsedDevs()
1335
    if self._aminor in used_devs:
1336
      minor = self._aminor
1337
    else:
1338
      minor = None
1339

  
1340
    self._SetFromMinor(minor)
1341
    return minor is not None
1342

  
1343
  def Assemble(self):
1344
    """Assemble the drbd.
1345

  
1346
    Method:
1347
      - if we have a configured device, we try to ensure that it matches
1348
        our config
1349
      - if not, we create it from zero
1350

  
1351
    """
1352
    result = super(DRBD8, self).Assemble()
1353
    if not result:
1354
      return result
1355

  
1356
    self.Attach()
1357
    if self.minor is None:
1358
      # local device completely unconfigured
1359
      return self._FastAssemble()
1360
    else:
1361
      # we have to recheck the local and network status and try to fix
1362
      # the device
1363
      return self._SlowAssemble()
1364

  
1365
  def _SlowAssemble(self):
1366
    """Assembles the DRBD device from a (partially) configured device.
1325 1367

  
1326 1368
    In case of partially attached (local device matches but no network
1327 1369
    setup), we perform the network attach. If successful, we re-test
......
1382 1424
    self._SetFromMinor(minor)
1383 1425
    return minor is not None
1384 1426

  
1385
  def Assemble(self):
1386
    """Assemble the drbd.
1427
  def _FastAssemble(self):
1428
    """Assemble the drbd device from zero.
1387 1429

  
1388
    Method:
1389
      - if we have a local backing device, we bind to it by:
1390
        - checking the list of used drbd devices
1391
        - check if the local minor use of any of them is our own device
1392
        - if yes, abort?
1393
        - if not, bind
1394
      - if we have a local/remote net info:
1395
        - redo the local backing device step for the remote device
1396
        - check if any drbd device is using the local port,
1397
          if yes abort
1398
        - check if any remote drbd device is using the remote
1399
          port, if yes abort (for now)
1400
        - bind our net port
1401
        - bind the remote net port
1430
    This is run when in Assemble we detect our minor is unused.
1402 1431

  
1403 1432
    """
1404
    self.Attach()
1405
    if self.minor is not None:
1406
      logging.info("Already assembled")
1407
      return True
1408

  
1409
    result = super(DRBD8, self).Assemble()
1410
    if not result:
1411
      return result
1412

  
1413 1433
    # TODO: maybe completely tear-down the minor (drbdsetup ... down)
1414 1434
    # before attaching our own?
1415 1435
    minor = self._aminor

Also available in: Unified diff