Revision b00b95dd

b/lib/bdev.py
1628 1628
                                    " requested ganeti usage: kernel is"
1629 1629
                                    " %s.%s, ganeti wants 8.x" % (kmaj, kmin))
1630 1630

  
1631
    if len(children) != 2:
1631
    if len(children) not in (0, 2):
1632 1632
      raise ValueError("Invalid configuration data %s" % str(children))
1633 1633
    if not isinstance(unique_id, (tuple, list)) or len(unique_id) != 4:
1634 1634
      raise ValueError("Invalid configuration data %s" % str(unique_id))
......
1794 1794
    device.
1795 1795

  
1796 1796
    """
1797
    backend = self._children[0]
1797
    if self._children:
1798
      backend, meta = self._children
1799
    else:
1800
      backend = meta = None
1801

  
1798 1802
    if backend is not None:
1799
      retval = (info["local_dev"] == backend.dev_path)
1803
      retval = ("local_dev" in info and info["local_dev"] == backend.dev_path)
1800 1804
    else:
1801 1805
      retval = ("local_dev" not in info)
1802
    meta = self._children[1]
1806

  
1803 1807
    if meta is not None:
1804
      retval = retval and (info["meta_dev"] == meta.dev_path)
1805
      retval = retval and (info["meta_index"] == 0)
1808
      retval = retval and ("meta_dev" in info and
1809
                           info["meta_dev"] == meta.dev_path)
1810
      retval = retval and ("meta_index" in info and
1811
                           info["meta_index"] == 0)
1806 1812
    else:
1807 1813
      retval = retval and ("meta_dev" not in info and
1808 1814
                           "meta_index" not in info)
......
1890 1896
      return False
1891 1897
    return True
1892 1898

  
1899
  def AddChildren(self, devices):
1900
    """Add a disk to the DRBD device.
1901

  
1902
    """
1903
    if self.minor is None:
1904
      raise errors.BlockDeviceError("Can't attach to dbrd8 during AddChildren")
1905

  
1906
    if len(devices) != 2:
1907
      raise errors.BlockDeviceError("Need two devices for AddChildren")
1908
    if self._children:
1909
      raise errors.BlockDeviceError("DRBD8 already attached to a local disk")
1910
    backend, meta = devices
1911
    if backend.dev_path is None or meta.dev_path is None:
1912
      raise errors.BlockDeviceError("Children not ready during AddChildren")
1913
    backend.Open()
1914
    meta.Open()
1915
    if not self._CheckMetaSize(meta.dev_path):
1916
      raise errors.BlockDeviceError("Invalid meta device size")
1917
    self._InitMeta(self._FindUnusedMinor(), meta.dev_path)
1918
    if not self._IsValidMeta(meta.dev_path):
1919
      raise errors.BlockDeviceError("Cannot initalize meta device")
1920

  
1921
    if not self._AssembleLocal(self.minor, backend.dev_path, meta.dev_path):
1922
      raise errors.BlockDeviceError("Can't attach to local storage")
1923
    self._children = devices
1924

  
1925
  def RemoveChildren(self, devices):
1926
    """Detach the drbd device from local storage.
1927

  
1928
    """
1929
    if self.minor is None:
1930
      raise errors.BlockDeviceError("Can't attach to drbd8 during"
1931
                                    " RemoveChildren")
1932
    if len(self._children) != 2:
1933
      raise errors.BlockDeviceError("We don't have two children: %s" %
1934
                                    self._children)
1935

  
1936
    if len(devices) != 2:
1937
      raise errors.BlockDeviceError("We need two children in RemoveChildren")
1938
    for idx, dev in enumerate(devices):
1939
      if dev.dev_path != self._children[idx].dev_path:
1940
        raise errors.BlockDeviceError("Mismatch in local storage (%d) in"
1941
                                      " RemoveChildren" % idx)
1942

  
1943
    if not self._ShutdownLocal(self.minor):
1944
      raise errors.BlockDeviceError("Can't detach from local storage")
1945
    self._children = []
1946

  
1893 1947
  def SetSyncSpeed(self, kbytes):
1894 1948
    """Set the speed of the DRBD syncer.
1895 1949

  
......
2082 2136
    return True
2083 2137

  
2084 2138
  @classmethod
2139
  def _ShutdownLocal(cls, minor):
2140
    """Detach from the local device.
2141

  
2142
    I/Os will continue to be served from the remote device. If we
2143
    don't have a remote device, this operation will fail.
2144

  
2145
    """
2146
    result = utils.RunCmd(["drbdsetup", cls._DevPath(minor), "detach"])
2147
    if result.failed:
2148
      logger.Error("Can't detach local device: %s" % result.output)
2149
    return not result.failed
2150

  
2151
  @classmethod
2085 2152
  def _ShutdownNet(cls, minor):
2086 2153
    """Disconnect from the remote peer.
2087 2154

  

Also available in: Unified diff