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 Feb 22, 2024
1 parent ded093d commit 03b2c03
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 @@ -888,6 +888,12 @@
<value>460</value>
</code>

<code>
<name>WipefsFailure</name>
<description>Failed to wipe pre-existing filesystem signature.</description>
<value>461</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 @@ -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)
Expand Down

0 comments on commit 03b2c03

Please sign in to comment.