diff --git a/drivers/XE_SR_ERRORCODES.xml b/drivers/XE_SR_ERRORCODES.xml index 97236fe08..0d0353692 100755 --- a/drivers/XE_SR_ERRORCODES.xml +++ b/drivers/XE_SR_ERRORCODES.xml @@ -881,6 +881,12 @@ 460 + + WipeFS + Failed to wipe pre-existing filesystem signature. + 461 + + GenericException SM has thrown a generic python exception diff --git a/drivers/lvutil.py b/drivers/lvutil.py index 40bde905c..0f8bd4c6e 100755 --- a/drivers/lvutil.py +++ b/drivers/lvutil.py @@ -503,24 +503,12 @@ def createVG(root, vgname): f = _openExclusive(dev, True) os.close(f) + + # Wipe any fs signature try: - # Overwrite the disk header, try direct IO first - cmd = [util.CMD_DD, "if=/dev/zero", "of=%s" % dev, "bs=1M", - "count=10", "oflag=direct"] - util.pread2(cmd) + util.wipefs(dev) except util.CommandException as inst: - if inst.code == errno.EPERM: - try: - # Overwrite the disk header, try normal IO - cmd = [util.CMD_DD, "if=/dev/zero", "of=%s" % dev, - "bs=1M", "count=10"] - util.pread2(cmd) - except util.CommandException as inst: - raise xs_errors.XenError('LVMWrite', \ - opterr='device %s' % dev) - else: - raise xs_errors.XenError('LVMWrite', \ - opterr='device %s' % dev) + raise xs_errors.XenError('WipeFS', opterr='device %s' % dev) # from inst if not (dev == rootdev): try: diff --git a/drivers/util.py b/drivers/util.py index 50c9a5a86..00ec7259f 100755 --- a/drivers/util.py +++ b/drivers/util.py @@ -637,6 +637,17 @@ def zeroOut(path, fromByte, bytes): return True +def wipefs(blockdev): + "Wipe filesystem signatures from `blockdev`" + cmdlist = ["wipefs", "-a", blockdev] + SMlog("Running command: %s" % cmdlist) + (rc, stdout, stderr) = doexec(cmdlist) + if rc != 0: + SMlog("FAILED in util.wipefs: (rc %d) stdout: '%s', stderr: '%s'" % + (rc, stdout, stderr)) + raise CommandException(rc, str(cmdlist), stderr.strip()) + + def match_rootdev(s): regex = re.compile("^PRIMARY_DISK") return regex.search(s, 0)