Revision fceb01fe

b/lib/cmdlib.py
1561 1561
    # This raises errors.OpPrereqError on its own:
1562 1562
    self.group_uuid = self.cfg.LookupNodeGroup(self.op.group_name)
1563 1563

  
1564
    all_node_info = self.cfg.GetAllNodesInfo()
1565
    all_inst_info = self.cfg.GetAllInstancesInfo()
1566

  
1567
    node_names = set(node.name
1568
                     for node in all_node_info.values()
1569
                     if node.group == self.group_uuid)
1570

  
1571
    inst_names = [inst.name
1572
                  for inst in all_inst_info.values()
1573
                  if inst.primary_node in node_names]
1574

  
1575
    # In Exec(), we warn about mirrored instances that have primary and
1576
    # secondary living in separate node groups. To fully verify that
1577
    # volumes for these instances are healthy, we will need to do an
1578
    # extra call to their secondaries. We ensure here those nodes will
1579
    # be locked.
1580
    for inst in inst_names:
1581
      if all_inst_info[inst].disk_template in constants.DTS_INT_MIRROR:
1582
        node_names.update(all_inst_info[inst].secondary_nodes)
1564
    # Get instances in node group; this is unsafe and needs verification later
1565
    inst_names = self.cfg.GetNodeGroupInstances(self.group_uuid)
1583 1566

  
1584 1567
    self.needed_locks = {
1585
      locking.LEVEL_NODEGROUP: [self.group_uuid],
1586
      locking.LEVEL_NODE: list(node_names),
1587 1568
      locking.LEVEL_INSTANCE: inst_names,
1588
    }
1569
      locking.LEVEL_NODEGROUP: [self.group_uuid],
1570
      locking.LEVEL_NODE: [],
1571
      }
1589 1572

  
1590 1573
    self.share_locks = dict.fromkeys(locking.LEVELS, 1)
1591 1574

  
1592
  def CheckPrereq(self):
1593
    self.all_node_info = self.cfg.GetAllNodesInfo()
1594
    self.all_inst_info = self.cfg.GetAllInstancesInfo()
1575
  def DeclareLocks(self, level):
1576
    if level == locking.LEVEL_NODE:
1577
      # Get members of node group; this is unsafe and needs verification later
1578
      nodes = set(self.cfg.GetNodeGroup(self.group_uuid).members)
1579

  
1580
      all_inst_info = self.cfg.GetAllInstancesInfo()
1595 1581

  
1596
    group_nodes = set(node.name
1597
                      for node in self.all_node_info.values()
1598
                      if node.group == self.group_uuid)
1582
      # In Exec(), we warn about mirrored instances that have primary and
1583
      # secondary living in separate node groups. To fully verify that
1584
      # volumes for these instances are healthy, we will need to do an
1585
      # extra call to their secondaries. We ensure here those nodes will
1586
      # be locked.
1587
      for inst in self.glm.list_owned(locking.LEVEL_INSTANCE):
1588
        # Important: access only the instances whose lock is owned
1589
        if all_inst_info[inst].disk_template in constants.DTS_INT_MIRROR:
1590
          nodes.update(all_inst_info[inst].secondary_nodes)
1599 1591

  
1600
    group_instances = set(inst.name
1601
                          for inst in self.all_inst_info.values()
1602
                          if inst.primary_node in group_nodes)
1592
      self.needed_locks[locking.LEVEL_NODE] = nodes
1593

  
1594
  def CheckPrereq(self):
1595
    group_nodes = set(self.cfg.GetNodeGroup(self.group_uuid).members)
1596
    group_instances = self.cfg.GetNodeGroupInstances(self.group_uuid)
1603 1597

  
1604 1598
    unlocked_nodes = \
1605 1599
        group_nodes.difference(self.glm.list_owned(locking.LEVEL_NODE))
......
1608 1602
        group_instances.difference(self.glm.list_owned(locking.LEVEL_INSTANCE))
1609 1603

  
1610 1604
    if unlocked_nodes:
1611
      raise errors.OpPrereqError("missing lock for nodes: %s" %
1605
      raise errors.OpPrereqError("Missing lock for nodes: %s" %
1612 1606
                                 utils.CommaJoin(unlocked_nodes))
1613 1607

  
1614 1608
    if unlocked_instances:
1615
      raise errors.OpPrereqError("missing lock for instances: %s" %
1609
      raise errors.OpPrereqError("Missing lock for instances: %s" %
1616 1610
                                 utils.CommaJoin(unlocked_instances))
1617 1611

  
1612
    self.all_node_info = self.cfg.GetAllNodesInfo()
1613
    self.all_inst_info = self.cfg.GetAllInstancesInfo()
1614

  
1618 1615
    self.my_node_names = utils.NiceSort(group_nodes)
1619 1616
    self.my_inst_names = utils.NiceSort(group_instances)
1620 1617

  
......
2567 2564
    all_nvinfo = self.rpc.call_node_verify(self.my_node_names,
2568 2565
                                           node_verify_param,
2569 2566
                                           self.cfg.GetClusterName())
2567
    nvinfo_endtime = time.time()
2568

  
2570 2569
    if self.extra_lv_nodes and vg_name is not None:
2571 2570
      extra_lv_nvinfo = \
2572 2571
          self.rpc.call_node_verify(self.extra_lv_nodes,
......
2574 2573
                                    self.cfg.GetClusterName())
2575 2574
    else:
2576 2575
      extra_lv_nvinfo = {}
2577
    nvinfo_endtime = time.time()
2578 2576

  
2579 2577
    all_drbd_map = self.cfg.ComputeDRBDMap()
2580 2578

  

Also available in: Unified diff