Skip to content

Commit b9b275f

Browse files
committed
lvutil: use wipefs not dd to clear existing signatures (#624)
Signed-off-by: Yann Dirson <[email protected]>
1 parent 1b6e452 commit b9b275f

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

drivers/XE_SR_ERRORCODES.xml

+6
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,12 @@
898898
<value>460</value>
899899
</code>
900900

901+
<code>
902+
<name>WipefsFailure</name>
903+
<description>Failed to wipe pre-existing filesystem signature.</description>
904+
<value>461</value>
905+
</code>
906+
901907
<code>
902908
<name>GenericException</name>
903909
<description>SM has thrown a generic python exception</description>

drivers/lvutil.py

+4-16
Original file line numberDiff line numberDiff line change
@@ -520,24 +520,12 @@ def createVG(root, vgname):
520520

521521
f = _openExclusive(dev, True)
522522
os.close(f)
523+
524+
# Wipe any fs signature
523525
try:
524-
# Overwrite the disk header, try direct IO first
525-
cmd = [util.CMD_DD, "if=/dev/zero", "of=%s" % dev, "bs=1M",
526-
"count=10", "oflag=direct"]
527-
util.pread2(cmd)
526+
util.wipefs(dev)
528527
except util.CommandException as inst:
529-
if inst.code == errno.EPERM:
530-
try:
531-
# Overwrite the disk header, try normal IO
532-
cmd = [util.CMD_DD, "if=/dev/zero", "of=%s" % dev,
533-
"bs=1M", "count=10"]
534-
util.pread2(cmd)
535-
except util.CommandException as inst:
536-
raise xs_errors.XenError('LVMWrite', \
537-
opterr='device %s' % dev)
538-
else:
539-
raise xs_errors.XenError('LVMWrite', \
540-
opterr='device %s' % dev)
528+
raise xs_errors.XenError('WipefsFailure', opterr='device %s' % dev) # from inst
541529

542530
if not (dev == rootdev):
543531
try:

drivers/util.py

+5
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,11 @@ def zeroOut(path, fromByte, bytes):
637637
return True
638638

639639

640+
def wipefs(blockdev):
641+
"Wipe filesystem signatures from `blockdev`"
642+
pread2(["/usr/sbin/wipefs", "-a", blockdev])
643+
644+
640645
def match_rootdev(s):
641646
regex = re.compile("^PRIMARY_DISK")
642647
return regex.search(s, 0)

0 commit comments

Comments
 (0)