Revision a57e502a lib/config.py

b/lib/config.py
553 553

  
554 554
    return result
555 555

  
556
  def _CheckDiskIDs(self, disk, l_ids, p_ids):
556
  def _CheckDiskIDs(self, disk, l_ids):
557 557
    """Compute duplicate disk IDs
558 558

  
559 559
    @type disk: L{objects.Disk}
560 560
    @param disk: the disk at which to start searching
561 561
    @type l_ids: list
562 562
    @param l_ids: list of current logical ids
563
    @type p_ids: list
564
    @param p_ids: list of current physical ids
565 563
    @rtype: list
566 564
    @return: a list of error messages
567 565

  
......
572 570
        result.append("duplicate logical id %s" % str(disk.logical_id))
573 571
      else:
574 572
        l_ids.append(disk.logical_id)
575
    if disk.physical_id is not None:
576
      if disk.physical_id in p_ids:
577
        result.append("duplicate physical id %s" % str(disk.physical_id))
578
      else:
579
        p_ids.append(disk.physical_id)
580 573

  
581 574
    if disk.children:
582 575
      for child in disk.children:
583
        result.extend(self._CheckDiskIDs(child, l_ids, p_ids))
576
        result.extend(self._CheckDiskIDs(child, l_ids))
584 577
    return result
585 578

  
586 579
  def _UnlockedVerifyConfig(self):
......
598 591
    data = self._config_data
599 592
    cluster = data.cluster
600 593
    seen_lids = []
601
    seen_pids = []
602 594

  
603 595
    # global cluster checks
604 596
    if not cluster.enabled_hypervisors:
......
729 721
      for idx, disk in enumerate(instance.disks):
730 722
        result.extend(["instance '%s' disk %d error: %s" %
731 723
                       (instance.name, idx, msg) for msg in disk.Verify()])
732
        result.extend(self._CheckDiskIDs(disk, seen_lids, seen_pids))
724
        result.extend(self._CheckDiskIDs(disk, seen_lids))
733 725

  
734 726
      wrong_names = _CheckInstanceDiskIvNames(instance.disks)
735 727
      if wrong_names:
......
873 865
    """
874 866
    return self._UnlockedVerifyConfig()
875 867

  
876
  def _UnlockedSetDiskID(self, disk, node_uuid):
877
    """Convert the unique ID to the ID needed on the target nodes.
878

  
879
    This is used only for drbd, which needs ip/port configuration.
880

  
881
    The routine descends down and updates its children also, because
882
    this helps when the only the top device is passed to the remote
883
    node.
884

  
885
    This function is for internal use, when the config lock is already held.
886

  
887
    """
888
    if disk.children:
889
      for child in disk.children:
890
        self._UnlockedSetDiskID(child, node_uuid)
891

  
892
    if disk.logical_id is None and disk.physical_id is not None:
893
      return
894
    if disk.dev_type == constants.DT_DRBD8:
895
      pnode, snode, port, pminor, sminor, secret = disk.logical_id
896
      if node_uuid not in (pnode, snode):
897
        raise errors.ConfigurationError("DRBD device not knowing node %s" %
898
                                        node_uuid)
899
      pnode_info = self._UnlockedGetNodeInfo(pnode)
900
      snode_info = self._UnlockedGetNodeInfo(snode)
901
      if pnode_info is None or snode_info is None:
902
        raise errors.ConfigurationError("Can't find primary or secondary node"
903
                                        " for %s" % str(disk))
904
      p_data = (pnode_info.secondary_ip, port)
905
      s_data = (snode_info.secondary_ip, port)
906
      if pnode == node_uuid:
907
        disk.physical_id = p_data + s_data + (pminor, secret)
908
      else: # it must be secondary, we tested above
909
        disk.physical_id = s_data + p_data + (sminor, secret)
910
    else:
911
      disk.physical_id = disk.logical_id
912
    return
913

  
914
  @locking.ssynchronized(_config_lock)
915
  def SetDiskID(self, disk, node_uuid):
916
    """Convert the unique ID to the ID needed on the target nodes.
917

  
918
    This is used only for drbd, which needs ip/port configuration.
919

  
920
    The routine descends down and updates its children also, because
921
    this helps when the only the top device is passed to the remote
922
    node.
923

  
924
    """
925
    return self._UnlockedSetDiskID(disk, node_uuid)
926

  
927 868
  @locking.ssynchronized(_config_lock)
928 869
  def AddTcpUdpPort(self, port):
929 870
    """Adds a new port to the available port pool.
......
1586 1527
        disk.logical_id = (disk.logical_id[0],
1587 1528
                           utils.PathJoin(file_storage_dir, inst.name,
1588 1529
                                          "disk%s" % idx))
1589
        disk.physical_id = disk.logical_id
1590 1530

  
1591 1531
    # Force update of ssconf files
1592 1532
    self._config_data.cluster.serial_no += 1

Also available in: Unified diff