Revision 8b9887c5

b/lib/cmdlib/instance.py
559 559
    self.needed_locks[locking.LEVEL_NODE_RES] = \
560 560
      CopyLockList(self.needed_locks[locking.LEVEL_NODE])
561 561

  
562
    # Optimistically acquire shared group locks (we're reading the
563
    # configuration).  We can't just call GetInstanceNodeGroups, because the
564
    # instance doesn't exist yet. Therefore we lock all node groups of all
565
    # nodes we have.
566
    if self.needed_locks[locking.LEVEL_NODE] == locking.ALL_SET:
567
      # In the case we lock all nodes for opportunistic allocation, we have no
568
      # choice than to lock all groups, because they're allocated before nodes.
569
      # This is sad, but true. At least we release all those we don't need in
570
      # CheckPrereq later.
571
      self.needed_locks[locking.LEVEL_NODEGROUP] = locking.ALL_SET
572
    else:
573
      self.needed_locks[locking.LEVEL_NODEGROUP] = \
574
        list(self.cfg.GetNodeGroupsFromNodes(
575
          self.needed_locks[locking.LEVEL_NODE]))
576
    self.share_locks[locking.LEVEL_NODEGROUP] = 1
577

  
562 578
  def DeclareLocks(self, level):
563 579
    if level == locking.LEVEL_NODE_RES and \
564 580
      self.opportunistic_locks[locking.LEVEL_NODE]:
......
846 862
    """Check prerequisites.
847 863

  
848 864
    """
865
    # Check that the optimistically acquired groups are correct wrt the
866
    # acquired nodes
867
    owned_groups = frozenset(self.owned_locks(locking.LEVEL_NODEGROUP))
868
    owned_nodes = frozenset(self.owned_locks(locking.LEVEL_NODE))
869
    cur_groups = list(self.cfg.GetNodeGroupsFromNodes(owned_nodes))
870
    if not owned_groups.issuperset(cur_groups):
871
      raise errors.OpPrereqError("New instance %s's node groups changed since"
872
                                 " locks were acquired, current groups are"
873
                                 " are '%s', owning groups '%s'; retry the"
874
                                 " operation" %
875
                                 (self.op.instance_name,
876
                                  utils.CommaJoin(cur_groups),
877
                                  utils.CommaJoin(owned_groups)),
878
                                 errors.ECODE_STATE)
879

  
849 880
    self._CalculateFileStorageDir()
850 881

  
851 882
    if self.op.mode == constants.INSTANCE_IMPORT:
......
957 988
    ReleaseLocks(self, locking.LEVEL_NODE, keep=keep_locks)
958 989
    ReleaseLocks(self, locking.LEVEL_NODE_RES, keep=keep_locks)
959 990
    ReleaseLocks(self, locking.LEVEL_NODE_ALLOC)
991
    # Release all unneeded group locks
992
    ReleaseLocks(self, locking.LEVEL_NODEGROUP,
993
                 keep=self.cfg.GetNodeGroupsFromNodes(keep_locks))
960 994

  
961 995
    assert (self.owned_locks(locking.LEVEL_NODE) ==
962 996
            self.owned_locks(locking.LEVEL_NODE_RES)), \

Also available in: Unified diff