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
)
  • Loading branch information
ydirson committed Jul 5, 2023
1 parent a82ff6c commit 4a97f7b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
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
12 changes: 12 additions & 0 deletions drivers/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,18 @@ def zeroOut(path, fromByte, bytes):
return True


def wipefs(blockdev):
"Wipe filesystem signatures from `blockdev`"
cmdlist = ["wipefs", "-a", blockdev]
(rc, stdout, stderr) = doexec(cmdlist)
if rc != 0:
SMlog("FAILED in util.wipefs: (rc %d) stdout: '%s', stderr: '%s'" %
(rc, stdout, stderr))
if quiet:
SMlog("Command was: %s" % cmdlist)
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 4a97f7b

Please sign in to comment.