Revision a1578d63

b/lib/bdev.py
1243 1243
    the attach if can return success.
1244 1244

  
1245 1245
    """
1246
    for minor in self._GetUsedDevs():
1246
    for minor in (self._aminor,):
1247 1247
      info = self._GetDevInfo(self._GetShowData(minor))
1248 1248
      match_l = self._MatchesLocal(info)
1249 1249
      match_r = self._MatchesNet(info)
......
1319 1319
    if not result:
1320 1320
      return result
1321 1321

  
1322
    minor = self._FindUnusedMinor()
1322
    # TODO: maybe completely tear-down the minor (drbdsetup ... down)
1323
    # before attaching our own?
1324
    minor = self._aminor
1323 1325
    need_localdev_teardown = False
1324 1326
    if self._children and self._children[0] and self._children[1]:
1325 1327
      result = self._AssembleLocal(minor, self._children[0].dev_path,
b/lib/cmdlib.py
2958 2958
      raise errors.ProgrammerError("Wrong template configuration")
2959 2959
    remote_node = secondary_nodes[0]
2960 2960
    (minor_pa, minor_pb,
2961
     minor_sa, minor_sb) = [None, None, None, None]
2961
     minor_sa, minor_sb) = cfg.AllocateDRBDMinor(
2962
      [primary_node, primary_node, remote_node, remote_node], instance_name)
2962 2963

  
2963 2964
    names = _GenerateUniqueNames(cfg, [".sda_data", ".sda_meta",
2964 2965
                                       ".sdb_data", ".sdb_meta"])
......
3517 3518
    feedback_fn("* creating instance disks...")
3518 3519
    if not _CreateDisks(self.cfg, iobj):
3519 3520
      _RemoveDisks(iobj, self.cfg)
3521
      self.cfg.ReleaseDRBDMinors(instance)
3520 3522
      raise errors.OpExecError("Device creation failed, reverting...")
3521 3523

  
3522 3524
    feedback_fn("adding instance %s to cluster config" % instance)
......
3525 3527
    # Declare that we don't want to remove the instance lock anymore, as we've
3526 3528
    # added the instance to the config
3527 3529
    del self.remove_locks[locking.LEVEL_INSTANCE]
3530
    # Remove the temp. assignements for the instance's drbds
3531
    self.cfg.ReleaseDRBDMinors(instance)
3528 3532

  
3529 3533
    if self.op.wait_for_sync:
3530 3534
      disk_abort = not _WaitForSync(self.cfg, iobj, self.proc)
......
4027 4031

  
4028 4032

  
4029 4033
    # Step 4: dbrd minors and drbd setups changes
4030
    minors = [None for dev in instance.disks]
4034
    # after this, we must manually remove the drbd minors on both the
4035
    # error and the success paths
4036
    minors = cfg.AllocateDRBDMinor([new_node for dev in instance.disks],
4037
                                   instance.name)
4031 4038
    logging.debug("Allocated minors %s" % (minors,))
4032 4039
    self.proc.LogStep(4, steps_total, "changing drbd configuration")
4033 4040
    for dev, new_minor in zip(instance.disks, minors):
......
4041 4048
        new_logical_id = (new_node, pri_node,
4042 4049
                          dev.logical_id[2], new_minor, dev.logical_id[4])
4043 4050
      iv_names[dev.iv_name] = (dev, dev.children, new_logical_id)
4051
      logging.debug("Allocated new_minor: %s, new_logical_id: %s", new_minor,
4052
                    new_logical_id)
4044 4053
      new_drbd = objects.Disk(dev_type=constants.LD_DRBD8,
4045 4054
                              logical_id=new_logical_id,
4046 4055
                              children=dev.children)
4047 4056
      if not _CreateBlockDevOnSecondary(cfg, new_node, instance,
4048 4057
                                        new_drbd, False,
4049 4058
                                      _GetInstanceInfoText(instance)):
4059
        self.cfg.ReleaseDRBDMinors(instance.name)
4050 4060
        raise errors.OpExecError("Failed to create new DRBD on"
4051 4061
                                 " node '%s'" % new_node)
4052 4062

  
......
4075 4085

  
4076 4086
    if not done:
4077 4087
      # no detaches succeeded (very unlikely)
4088
      self.cfg.ReleaseDRBDMinors(instance.name)
4078 4089
      raise errors.OpExecError("Can't detach at least one DRBD from old node")
4079 4090

  
4080 4091
    # if we managed to detach at least one, we update all the disks of
......
4084 4095
      dev.logical_id = new_logical_id
4085 4096
      cfg.SetDiskID(dev, pri_node)
4086 4097
    cfg.Update(instance)
4098
    # we can remove now the temp minors as now the new values are
4099
    # written to the config file (and therefore stable)
4100
    self.cfg.ReleaseDRBDMinors(instance.name)
4087 4101

  
4088 4102
    # and now perform the drbd attach
4089 4103
    info("attaching primary drbds to new secondary (standalone => connected)")

Also available in: Unified diff