Exemplo n.º 1
0
    def _ComputeDiskBarrierArgs(cls, disabled_barriers, disable_meta_flush):
        """Compute the DRBD command line parameters for disk barriers

    """
        disabled_barriers_set = frozenset(disabled_barriers)
        if not disabled_barriers_set in constants.DRBD_VALID_BARRIER_OPT:
            raise errors.BlockDeviceError(
                "%s is not a valid option set for DRBD"
                " barriers" % disabled_barriers)

        args = []

        # meta flushes
        if disable_meta_flush:
            args.append(cls._DISABLE_META_FLUSH_OPTION)

        # disk flushes
        if constants.DRBD_B_DISK_FLUSH in disabled_barriers_set:
            args.append(cls._DISABLE_FLUSH_OPTION)

        # disk drain
        if constants.DRBD_B_DISK_DRAIN in disabled_barriers_set:
            args.append(cls._DISABLE_DRAIN_OPTION)

        # disk barriers
        if constants.DRBD_B_DISK_BARRIERS in disabled_barriers_set:
            args.append(cls._DISABLE_DISK_OPTION)

        return args
Exemplo n.º 2
0
 def _AppendOrRaise(option, min_version):
   """Helper for DRBD options"""
   if min_version is not None and vrel >= min_version:
     args.append(option)
   else:
     raise errors.BlockDeviceError("Could not use the option %s as the"
                                   " DRBD version %d.%d.%d does not support"
                                   " it." % (option, vmaj, vmin, vrel))
Exemplo n.º 3
0
    def __init__(self, procline):
        u = self.UNCONF_RE.match(procline)
        if u:
            self.cstatus = self.CS_UNCONFIGURED
            self.lrole = self.rrole = self.ldisk = self.rdisk = None
        else:
            m = self.LINE_RE.match(procline)
            if not m:
                raise errors.BlockDeviceError("Can't parse input data '%s'" %
                                              procline)
            self.cstatus = m.group(1)
            self.lrole = m.group(2)
            self.rrole = m.group(3)
            self.ldisk = m.group(4)
            self.rdisk = m.group(5)

        # end reading of data from the LINE_RE or UNCONF_RE

        self.is_standalone = self.cstatus == self.CS_STANDALONE
        self.is_wfconn = self.cstatus == self.CS_WFCONNECTION
        self.is_connected = self.cstatus == self.CS_CONNECTED
        self.is_unconfigured = self.cstatus == self.CS_UNCONFIGURED
        self.is_primary = self.lrole == self.RO_PRIMARY
        self.is_secondary = self.lrole == self.RO_SECONDARY
        self.peer_primary = self.rrole == self.RO_PRIMARY
        self.peer_secondary = self.rrole == self.RO_SECONDARY
        self.both_primary = self.is_primary and self.peer_primary
        self.both_secondary = self.is_secondary and self.peer_secondary

        self.is_diskless = self.ldisk == self.DS_DISKLESS
        self.is_disk_uptodate = self.ldisk == self.DS_UPTODATE
        self.peer_disk_uptodate = self.rdisk == self.DS_UPTODATE

        self.is_in_resync = self.cstatus in self.CSET_SYNC
        self.is_in_use = self.cstatus != self.CS_UNCONFIGURED

        m = self.SYNC_RE.match(procline)
        if m:
            self.sync_percent = float(m.group(1))
            hours = int(m.group(2))
            minutes = int(m.group(3))
            seconds = int(m.group(4))
            self.est_time = hours * 3600 + minutes * 60 + seconds
        else:
            # we have (in this if branch) no percent information, but if
            # we're resyncing we need to 'fake' a sync percent information,
            # as this is how cmdlib determines if it makes sense to wait for
            # resyncing or not
            if self.is_in_resync:
                self.sync_percent = 0
            else:
                self.sync_percent = None
            self.est_time = None
Exemplo n.º 4
0
def ThrowError(msg, *args):
    """Log an error to the node daemon and the raise an exception.

  @type msg: string
  @param msg: the text of the exception
  @raise errors.BlockDeviceError

  """
    if args:
        msg = msg % args
    logging.error(msg)
    raise errors.BlockDeviceError(msg)
Exemplo n.º 5
0
  def __init__(self, unique_id, children, size, params, dyn_params, *args):
    """Initalizes a file device backend.

    """
    if children:
      raise errors.BlockDeviceError("Invalid setup for file device")
    super(FileStorage, self).__init__(unique_id, children, size, params,
                                      dyn_params, *args)
    if not isinstance(unique_id, (tuple, list)) or len(unique_id) != 2:
      raise ValueError("Invalid configuration data %s" % str(unique_id))
    self.driver = unique_id[0]
    self.dev_path = unique_id[1]
    self.file = FileDeviceHelper(self.dev_path)
    self.Attach()
Exemplo n.º 6
0
    def _ParseVersion(self, lines):
        first_line = lines[0].strip()
        version = self._VERSION_RE.match(first_line)
        if not version:
            raise errors.BlockDeviceError(
                "Can't parse DRBD version from '%s'" % first_line)

        values = version.groups()
        retval = {
            "k_major": int(values[0]),
            "k_minor": int(values[1]),
            "k_point": int(values[2]),
            "api": int(values[4]),
            "proto": int(values[5]),
        }
        if values[3] is not None:
            retval["k_fix"] = values[3]
        if values[6] is not None:
            retval["proto2"] = values[6]

        return retval
Exemplo n.º 7
0
    def FindUnusedMinor():
        """Find an unused DRBD device.

    This is specific to 8.x as the minors are allocated dynamically,
    so non-existing numbers up to a max minor count are actually free.

    @rtype: int

    """
        highest = -1
        info = DRBD8.GetProcInfo()
        for minor in info.GetMinors():
            status = info.GetMinorStatus(minor)
            if not status.is_in_use:
                return minor
            highest = max(highest, minor)

        if highest >= DRBD8._MAX_MINORS:
            logging.error("Error: no free drbd minors!")
            raise errors.BlockDeviceError("Can't find a free DRBD minor")

        return highest + 1
Exemplo n.º 8
0
    def _ComputeDiskBarrierArgs(cls, vmaj, vmin, vrel, disabled_barriers,
                                disable_meta_flush):
        """Compute the DRBD command line parameters for disk barriers

    Returns a list of the disk barrier parameters as requested via the
    disabled_barriers and disable_meta_flush arguments, and according to the
    supported ones in the DRBD version vmaj.vmin.vrel

    If the desired option is unsupported, raises errors.BlockDeviceError.

    """
        disabled_barriers_set = frozenset(disabled_barriers)
        if not disabled_barriers_set in constants.DRBD_VALID_BARRIER_OPT:
            raise errors.BlockDeviceError(
                "%s is not a valid option set for DRBD"
                " barriers" % disabled_barriers)

        args = []

        # The following code assumes DRBD 8.x, with x < 4 and x != 1 (DRBD 8.1.x
        # does not exist)
        if not vmaj == 8 and vmin in (0, 2, 3):
            raise errors.BlockDeviceError(
                "Unsupported DRBD version: %d.%d.%d" % (vmaj, vmin, vrel))

        def _AppendOrRaise(option, min_version):
            """Helper for DRBD options"""
            if min_version is not None and vrel >= min_version:
                args.append(option)
            else:
                raise errors.BlockDeviceError(
                    "Could not use the option %s as the"
                    " DRBD version %d.%d.%d does not support"
                    " it." % (option, vmaj, vmin, vrel))

        # the minimum version for each feature is encoded via pairs of (minor
        # version -> x) where x is version in which support for the option was
        # introduced.
        meta_flush_supported = disk_flush_supported = {
            0: 12,
            2: 7,
            3: 0,
        }

        disk_drain_supported = {
            2: 7,
            3: 0,
        }

        disk_barriers_supported = {
            3: 0,
        }

        # meta flushes
        if disable_meta_flush:
            _AppendOrRaise(cls._DISABLE_META_FLUSH_OPTION,
                           meta_flush_supported.get(vmin, None))

        # disk flushes
        if constants.DRBD_B_DISK_FLUSH in disabled_barriers_set:
            _AppendOrRaise(cls._DISABLE_FLUSH_OPTION,
                           disk_flush_supported.get(vmin, None))

        # disk drain
        if constants.DRBD_B_DISK_DRAIN in disabled_barriers_set:
            _AppendOrRaise(cls._DISABLE_DRAIN_OPTION,
                           disk_drain_supported.get(vmin, None))

        # disk barriers
        if constants.DRBD_B_DISK_BARRIERS in disabled_barriers_set:
            _AppendOrRaise(cls._DISABLE_DISK_OPTION,
                           disk_barriers_supported.get(vmin, None))

        return args