X-Git-Url: https://code.grnet.gr/git/ganeti-local/blobdiff_plain/9c793cfbdc4956a23121a93baaa6e80ff07ee12c..da961187f97344fde390140ebb2f10d10d334d51:/lib/bdev.py diff --git a/lib/bdev.py b/lib/bdev.py index 49fd3e3..9d3f08b 100644 --- a/lib/bdev.py +++ b/lib/bdev.py @@ -563,7 +563,7 @@ class DRBD8Status(object): """ UNCONF_RE = re.compile(r"\s*[0-9]+:\s*cs:Unconfigured$") - LINE_RE = re.compile(r"\s*[0-9]+:\s*cs:(\S+)\s+st:([^/]+)/(\S+)" + LINE_RE = re.compile(r"\s*[0-9]+:\s*cs:(\S+)\s+(?:st|ro):([^/]+)/(\S+)" "\s+ds:([^/]+)/(\S+)\s+.*$") SYNC_RE = re.compile(r"^.*\ssync'ed:\s*([0-9.]+)%.*" "\sfinish: ([0-9]+):([0-9]+):([0-9]+)\s.*$") @@ -639,11 +639,18 @@ class BaseDRBD(BlockDev): """Return data from /proc/drbd. """ - stat = open(filename, "r") try: - data = stat.read().splitlines() - finally: - stat.close() + stat = open(filename, "r") + try: + data = stat.read().splitlines() + finally: + stat.close() + except EnvironmentError, err: + if err.errno == errno.ENOENT: + _ThrowError("The file %s cannot be opened, check if the module" + " is loaded (%s)", filename, str(err)) + else: + _ThrowError("Can't read the DRBD proc file %s: %s", filename, str(err)) if not data: _ThrowError("Can't read any data from %s", filename) return data @@ -889,15 +896,20 @@ class DRBD8(BaseDRBD): # value types value = pyp.Word(pyp.alphanums + '_-/.:') quoted = dbl_quote + pyp.CharsNotIn('"') + dbl_quote - addr_port = (pyp.Word(pyp.nums + '.') + pyp.Literal(':').suppress() + - number) + addr_type = (pyp.Optional(pyp.Literal("ipv4")).suppress() + + pyp.Optional(pyp.Literal("ipv6")).suppress()) + addr_port = (addr_type + pyp.Word(pyp.nums + '.') + + pyp.Literal(':').suppress() + number) # meta device, extended syntax meta_value = ((value ^ quoted) + pyp.Literal('[').suppress() + number + pyp.Word(']').suppress()) + # device name, extended syntax + device_value = pyp.Literal("minor").suppress() + number # a statement stmt = (~rbrace + keyword + ~lbrace + - pyp.Optional(addr_port ^ value ^ quoted ^ meta_value) + + pyp.Optional(addr_port ^ value ^ quoted ^ meta_value ^ + device_value) + pyp.Optional(defa) + semi + pyp.Optional(pyp.restOfLine).suppress()) @@ -1404,9 +1416,9 @@ class DRBD8(BaseDRBD): try: self._ShutdownNet(minor) except errors.BlockDeviceError, err: - _ThrowError("Device has correct local storage, wrong remote peer" - " and is unable to disconnect in order to attach to" - " the correct peer: %s", str(err)) + _ThrowError("drbd%d: device has correct local storage, wrong" + " remote peer and is unable to disconnect in order" + " to attach to the correct peer: %s", minor, str(err)) # note: _AssembleNet also handles the case when we don't want # local storage (i.e. one or more of the _[lr](host|port) is # None) @@ -1475,7 +1487,8 @@ class DRBD8(BaseDRBD): """ result = utils.RunCmd(["drbdsetup", cls._DevPath(minor), "down"]) if result.failed: - _ThrowError("Can't shutdown drbd device: %s", result.output) + _ThrowError("drbd%d: can't shutdown drbd device: %s", + minor, result.output) def Shutdown(self): """Shutdown the DRBD device. @@ -1514,11 +1527,12 @@ class DRBD8(BaseDRBD): else: in_use = False if in_use: - _ThrowError("DRBD minor %d already in use at Create() time", aminor) + _ThrowError("drbd%d: minor is already in use at Create() time", aminor) meta = children[1] meta.Assemble() if not meta.Attach(): - raise errors.BlockDeviceError("Can't attach to meta device") + _ThrowError("drbd%d: can't attach to meta device '%s'", + aminor, meta) cls._CheckMetaSize(meta.dev_path) cls._InitMeta(aminor, meta.dev_path) return cls(unique_id, children) @@ -1627,11 +1641,11 @@ class FileStorage(BlockDev): @return: an instance of FileStorage """ - # TODO: decide whether we should check for existing files and - # abort or not if not isinstance(unique_id, (tuple, list)) or len(unique_id) != 2: raise ValueError("Invalid configuration data %s" % str(unique_id)) dev_path = unique_id[1] + if os.path.exists(dev_path): + _ThrowError("File already existing: %s", dev_path) try: f = open(dev_path, 'w') f.truncate(size * 1024 * 1024)