Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lvutil: use wipefs not dd to clear existing signatures #626

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions drivers/XE_SR_ERRORCODES.xml
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,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 @@ -520,24 +520,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