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 committed Jan 11, 2024
1 parent 4d048f8 commit 09aa30e
Show file tree
Hide file tree
Showing 3 changed files with 21 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 @@ -881,6 +881,12 @@
<value>460</value>
</code>

<code>
<name>WipeFS</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('WipeFS', opterr='device %s' % dev) # from inst

if not (dev == rootdev):
try:
Expand Down
11 changes: 11 additions & 0 deletions drivers/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,17 @@ def zeroOut(path, fromByte, bytes):
return True


def wipefs(blockdev):
"Wipe filesystem signatures from `blockdev`"
cmdlist = ["/usr/sbin/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)
Expand Down

0 comments on commit 09aa30e

Please sign in to comment.