Revision f9518d38

b/lib/bdev.py
804 804

  
805 805
    if len(children) not in (0, 2):
806 806
      raise ValueError("Invalid configuration data %s" % str(children))
807
    if not isinstance(unique_id, (tuple, list)) or len(unique_id) != 5:
807
    if not isinstance(unique_id, (tuple, list)) or len(unique_id) != 6:
808 808
      raise ValueError("Invalid configuration data %s" % str(unique_id))
809 809
    (self._lhost, self._lport,
810 810
     self._rhost, self._rport,
811
     self._aminor) = unique_id
811
     self._aminor, self._secret) = unique_id
812 812
    if (self._lhost is not None and self._lhost == self._rhost and
813 813
        self._lport == self._rport):
814 814
      raise ValueError("Invalid configuration data, same local/remote %s" %
b/lib/cmdlib.py
2923 2923
  """
2924 2924
  port = cfg.AllocatePort()
2925 2925
  vgname = cfg.GetVGName()
2926
  shared_secret = cfg.GenerateDRBDSecret()
2926 2927
  dev_data = objects.Disk(dev_type=constants.LD_LV, size=size,
2927 2928
                          logical_id=(vgname, names[0]))
2928 2929
  dev_meta = objects.Disk(dev_type=constants.LD_LV, size=128,
2929 2930
                          logical_id=(vgname, names[1]))
2930 2931
  drbd_dev = objects.Disk(dev_type=constants.LD_DRBD8, size=size,
2931 2932
                          logical_id=(primary, secondary, port,
2932
                                      p_minor, s_minor),
2933
                                      p_minor, s_minor,
2934
                                      shared_secret),
2933 2935
                          children=[dev_data, dev_meta],
2934 2936
                          iv_name=iv_name)
2935 2937
  return drbd_dev
......
4050 4052
      # create new devices on new_node
4051 4053
      if pri_node == dev.logical_id[0]:
4052 4054
        new_logical_id = (pri_node, new_node,
4053
                          dev.logical_id[2], dev.logical_id[3], new_minor)
4055
                          dev.logical_id[2], dev.logical_id[3], new_minor,
4056
                          dev.logical_id[5])
4054 4057
      else:
4055 4058
        new_logical_id = (new_node, pri_node,
4056
                          dev.logical_id[2], new_minor, dev.logical_id[4])
4059
                          dev.logical_id[2], new_minor, dev.logical_id[4],
4060
                          dev.logical_id[5])
4057 4061
      iv_names[dev.iv_name] = (dev, dev.children, new_logical_id)
4058 4062
      logging.debug("Allocated new_minor: %s, new_logical_id: %s", new_minor,
4059 4063
                    new_logical_id)
......
4079 4083
    done = 0
4080 4084
    for dev in instance.disks:
4081 4085
      cfg.SetDiskID(dev, pri_node)
4082
      # set the physical (unique in bdev terms) id to None, meaning
4083
      # detach from network
4084
      dev.physical_id = (None, None, None, None, dev.physical_id[4])
4086
      # set the network part of the physical (unique in bdev terms) id
4087
      # to None, meaning detach from network
4088
      dev.physical_id = (None, None, None, None) + dev.physical_id[4:]
4085 4089
      # and 'find' the device, which will 'fix' it to match the
4086 4090
      # standalone state
4087 4091
      if rpc.call_blockdev_find(pri_node, dev):
b/lib/config.py
126 126
    all_macs = self._AllMACs()
127 127
    return mac in all_macs
128 128

  
129
  @locking.ssynchronized(_config_lock, shared=1)
130
  def GenerateDRBDSecret(self):
131
    """Generate a DRBD secret.
132

  
133
    This checks the current disks for duplicates.
134

  
135
    """
136
    self._OpenConfig()
137
    all_secrets = self._AllDRBDSecrets()
138
    retries = 64
139
    while retries > 0:
140
      secret = utils.GenerateSecret()
141
      if secret not in all_secrets:
142
        break
143
      retries -= 1
144
    else:
145
      raise errors.ConfigurationError("Can't generate unique DRBD secret")
146
    return secret
147

  
129 148
  def _ComputeAllLVs(self):
130 149
    """Compute the list of all LVs.
131 150

  
......
185 204

  
186 205
    return result
187 206

  
207
  def _AllDRBDSecrets(self):
208
    """Return all DRBD secrets present in the config.
209

  
210
    """
211
    def helper(disk, result):
212
      """Recursively gather secrets from this disk."""
213
      if disk.dev_type == constants.DT_DRBD8:
214
        result.append(disk.logical_id[5])
215
      if disk.children:
216
        for child in disk.children:
217
          helper(child, result)
218

  
219
    result = []
220
    for instance in self._config_data.instances.values():
221
      for disk in instance.disks:
222
        helper(disk, result)
223

  
224
    return result
225

  
188 226
  @locking.ssynchronized(_config_lock, shared=1)
189 227
  def VerifyConfig(self):
190 228
    """Stub verify function.
......
268 306
    if disk.logical_id is None and disk.physical_id is not None:
269 307
      return
270 308
    if disk.dev_type == constants.LD_DRBD8:
271
      pnode, snode, port, pminor, sminor = disk.logical_id
309
      pnode, snode, port, pminor, sminor, secret = disk.logical_id
272 310
      if node_name not in (pnode, snode):
273 311
        raise errors.ConfigurationError("DRBD device not knowing node %s" %
274 312
                                        node_name)
......
280 318
      p_data = (pnode_info.secondary_ip, port)
281 319
      s_data = (snode_info.secondary_ip, port)
282 320
      if pnode == node_name:
283
        disk.physical_id = p_data + s_data + (pminor,)
321
        disk.physical_id = p_data + s_data + (pminor, secret)
284 322
      else: # it must be secondary, we tested above
285
        disk.physical_id = s_data + p_data + (sminor,)
323
        disk.physical_id = s_data + p_data + (sminor, secret)
286 324
    else:
287 325
      disk.physical_id = disk.logical_id
288 326
    return
......
354 392

  
355 393
    """
356 394
    def _AppendUsedPorts(instance_name, disk, used):
357
      if disk.dev_type == constants.LD_DRBD8 and len(disk.logical_id) == 5:
358
        nodeA, nodeB, dummy, minorA, minorB = disk.logical_id
395
      if disk.dev_type == constants.LD_DRBD8 and len(disk.logical_id) >= 5:
396
        nodeA, nodeB, dummy, minorA, minorB = disk.logical_id[:5]
359 397
        for node, port in ((nodeA, minorA), (nodeB, minorB)):
360 398
          assert node in used, "Instance node not found in node list"
361 399
          if port in used[node]:
b/lib/objects.py
412 412
    if self.logical_id is None and self.physical_id is not None:
413 413
      return
414 414
    if self.dev_type in constants.LDS_DRBD:
415
      pnode, snode, port, pminor, sminor = self.logical_id
415
      pnode, snode, port, pminor, sminor, secret = self.logical_id
416 416
      if target_node not in (pnode, snode):
417 417
        raise errors.ConfigurationError("DRBD device not knowing node %s" %
418 418
                                        target_node)
......
424 424
      p_data = (pnode_ip, port)
425 425
      s_data = (snode_ip, port)
426 426
      if pnode == target_node:
427
        self.physical_id = p_data + s_data + (pminor,)
427
        self.physical_id = p_data + s_data + (pminor, secret)
428 428
      else: # it must be secondary, we tested above
429
        self.physical_id = s_data + p_data + (sminor,)
429
        self.physical_id = s_data + p_data + (sminor, secret)
430 430
    else:
431 431
      self.physical_id = self.logical_id
432 432
    return
......
458 458
      obj.logical_id = tuple(obj.logical_id)
459 459
    if obj.physical_id and isinstance(obj.physical_id, list):
460 460
      obj.physical_id = tuple(obj.physical_id)
461
    if obj.dev_type in constants.LDS_DRBD and len(obj.logical_id) == 3:
462
      # old non-minor based disk type
463
      obj.logical_id += (None, None)
461
    if obj.dev_type in constants.LDS_DRBD:
462
      # we need a tuple of length six here
463
      if len(obj.logical_id) < 6:
464
        obj.logical_id += (None,) * (6 - len(obj.logical_id))
464 465
    return obj
465 466

  
466 467
  def __str__(self):

Also available in: Unified diff