diff --git a/drivers/XE_SR_ERRORCODES.xml b/drivers/XE_SR_ERRORCODES.xml index 293ec6eb..0dac0613 100755 --- a/drivers/XE_SR_ERRORCODES.xml +++ b/drivers/XE_SR_ERRORCODES.xml @@ -888,6 +888,12 @@ 460 + + WipefsFailure + 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 e0fc0d71..f1d1c5bd 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('WipefsFailure', opterr='device %s' % dev) # from inst if not (dev == rootdev): try: diff --git a/drivers/util.py b/drivers/util.py index 07606374..364bb8c2 100755 --- a/drivers/util.py +++ b/drivers/util.py @@ -637,6 +637,11 @@ def zeroOut(path, fromByte, bytes): return True +def wipefs(blockdev): + "Wipe filesystem signatures from `blockdev`" + pread2(["/usr/sbin/wipefs", "-a", blockdev]) + + def match_rootdev(s): regex = re.compile("^PRIMARY_DISK") return regex.search(s, 0)