From c56b06db90607ac17cd46e030d4c07a742106ac0 Mon Sep 17 00:00:00 2001 From: a-a Date: Mon, 15 Oct 2018 18:16:19 +0100 Subject: [PATCH] stop testing symlinks/blockdevices against VALID_RAW_CONTENT as they are real devices on the system(usually disks!) let's not try and test them to see if they are a valid content just trust the kernel, it probably knows best. --- model/storagevolumes.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/model/storagevolumes.py b/model/storagevolumes.py index aea2760b7..0bdbe998c 100644 --- a/model/storagevolumes.py +++ b/model/storagevolumes.py @@ -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):