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

Resolve issue #1222: Cannot attach existing (but empty) logical volume to VM #1258

Merged
merged 1 commit into from
Apr 19, 2019
Merged
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
23 changes: 16 additions & 7 deletions model/storagevolumes.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,23 @@ def lookup(self, pool, name):
# raw files), so it's necessary check the 'content' of them
isvalid = True
if fmt == 'raw':
try:
ms = magic.open(magic.NONE)
ms.load()
if ms.file(path).lower() not in VALID_RAW_CONTENT:
if not os.path.islink(path): # Check if file is a symlink to a real block device, if so, don't check it's contents for validity
try:
ms = magic.open(magic.NONE)
ms.load()
if ms.file(path).lower() not in VALID_RAW_CONTENT:
isvalid = False
ms.close()
except UnicodeDecodeError:
isvalid = False
ms.close()
except UnicodeDecodeError:
isvalid = False
else: # We are a symlink
if "/dev/dm-" in os.path.realpath(path):
# This is most likely a real blockdevice
isvalid = True
wok_log.error("symlink detected, validated the disk")
else:
# Doesn't point to a known blockdevice
isvalid = False

used_by = get_disk_used_by(self.conn, path)
if (self.libvirt_user is None):
Expand Down