X-Git-Url: https://code.grnet.gr/git/ganeti-local/blobdiff_plain/f2165b8aff2d8331625b9930af591383d8db3d05..3b01286e6de5b54648bbb96dafd6deb67babc01a:/lib/backend.py diff --git a/lib/backend.py b/lib/backend.py index 8abe5a6..4bf94fb 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -491,8 +491,9 @@ def VerifyNode(what, cluster_name): result = {} my_name = netutils.Hostname.GetSysName() port = netutils.GetDaemonPort(constants.NODED) + vm_capable = my_name not in what.get(constants.NV_VMNODES, []) - if constants.NV_HYPERVISOR in what: + if constants.NV_HYPERVISOR in what and vm_capable: result[constants.NV_HYPERVISOR] = tmp = {} for hv_name in what[constants.NV_HYPERVISOR]: try: @@ -547,14 +548,14 @@ def VerifyNode(what, cluster_name): result[constants.NV_MASTERIP] = netutils.TcpPing(master_ip, port, source=source) - if constants.NV_LVLIST in what: + if constants.NV_LVLIST in what and vm_capable: try: val = GetVolumeList(what[constants.NV_LVLIST]) except RPCFail, err: val = str(err) result[constants.NV_LVLIST] = val - if constants.NV_INSTANCELIST in what: + if constants.NV_INSTANCELIST in what and vm_capable: # GetInstanceList can fail try: val = GetInstanceList(what[constants.NV_INSTANCELIST]) @@ -562,10 +563,10 @@ def VerifyNode(what, cluster_name): val = str(err) result[constants.NV_INSTANCELIST] = val - if constants.NV_VGLIST in what: + if constants.NV_VGLIST in what and vm_capable: result[constants.NV_VGLIST] = utils.ListVolumeGroups() - if constants.NV_PVLIST in what: + if constants.NV_PVLIST in what and vm_capable: result[constants.NV_PVLIST] = \ bdev.LogicalVolume.GetPVInfo(what[constants.NV_PVLIST], filter_allocatable=False) @@ -574,11 +575,11 @@ def VerifyNode(what, cluster_name): result[constants.NV_VERSION] = (constants.PROTOCOL_VERSION, constants.RELEASE_VERSION) - if constants.NV_HVINFO in what: + if constants.NV_HVINFO in what and vm_capable: hyper = hypervisor.GetHypervisor(what[constants.NV_HVINFO]) result[constants.NV_HVINFO] = hyper.GetNodeInfo() - if constants.NV_DRBDLIST in what: + if constants.NV_DRBDLIST in what and vm_capable: try: used_minors = bdev.DRBD8.GetUsedDevs().keys() except errors.BlockDeviceError, err: @@ -586,7 +587,7 @@ def VerifyNode(what, cluster_name): used_minors = str(err) result[constants.NV_DRBDLIST] = used_minors - if constants.NV_DRBDHELPER in what: + if constants.NV_DRBDHELPER in what and vm_capable: status = True try: payload = bdev.BaseDRBD.GetUsermodeHelper() @@ -611,7 +612,7 @@ def VerifyNode(what, cluster_name): if constants.NV_TIME in what: result[constants.NV_TIME] = utils.SplitTime(time.time()) - if constants.NV_OSLIST in what: + if constants.NV_OSLIST in what and vm_capable: result[constants.NV_OSLIST] = DiagnoseOS() return result @@ -1287,32 +1288,50 @@ def BlockdevCreate(disk, size, owner, on_primary, info): return device.unique_id -def _WipeDevice(path): +def _WipeDevice(path, offset, size): """This function actually wipes the device. @param path: The path to the device to wipe + @param offset: The offset in MiB in the file + @param size: The size in MiB to write """ - result = utils.RunCmd("%s%s" % (constants.WIPE_CMD, utils.ShellQuote(path))) + cmd = [constants.DD_CMD, "if=/dev/zero", "seek=%d" % offset, + "bs=%d" % constants.WIPE_BLOCK_SIZE, "oflag=direct", "of=%s" % path, + "count=%d" % size] + result = utils.RunCmd(cmd) if result.failed: _Fail("Wipe command '%s' exited with error: %s; output: %s", result.cmd, result.fail_reason, result.output) -def BlockdevWipe(disk): +def BlockdevWipe(disk, offset, size): """Wipes a block device. @type disk: L{objects.Disk} @param disk: the disk object we want to wipe + @type offset: int + @param offset: The offset in MiB in the file + @type size: int + @param size: The size in MiB to write """ try: rdev = _RecursiveFindBD(disk) - except errors.BlockDeviceError, err: - _Fail("Cannot execute wipe for device %s: device not found", err) + except errors.BlockDeviceError: + rdev = None + + if not rdev: + _Fail("Cannot execute wipe for device %s: device not found", disk.iv_name) + + # Do cross verify some of the parameters + if offset > rdev.size: + _Fail("Offset is bigger than device size") + if (offset + size) > rdev.size: + _Fail("The provided offset and size to wipe is bigger than device size") - _WipeDevice(rdev.dev_path) + _WipeDevice(rdev.dev_path, offset, size) def BlockdevRemove(disk):