Skip to content

Commit

Permalink
lvutil: use wipefs not dd to clear existing signatures (xapi-project#624
Browse files Browse the repository at this point in the history
)

Signed-off-by: Yann Dirson <[email protected]>
  • Loading branch information
ydirson authored and Wescoeur committed Apr 10, 2024
1 parent eda36ca commit ded906b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
6 changes: 6 additions & 0 deletions drivers/XE_SR_ERRORCODES.xml
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,12 @@
<value>461</value>
</code>

<code>
<name>WipefsFailure</name>
<description>Failed to wipe pre-existing filesystem signature.</description>
<value>462</value>
</code>

<code>
<name>GenericException</name>
<description>SM has thrown a generic python exception</description>
Expand Down
20 changes: 4 additions & 16 deletions drivers/lvutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions drivers/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,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)
Expand Down

0 comments on commit ded906b

Please sign in to comment.