storage: make DirectoryThinPool helper less verbose, add sudo

Don't print scary messages when given pool cannot be found. Also, add
sudo to make it work from non-root user (tests)
This commit is contained in:
Marek Marczykowski-Górecki 2018-03-20 15:54:23 +01:00
parent 1bc640f3e0
commit 825de49767
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -932,9 +932,12 @@ class DirectoryThinPool:
fs_major = (fs_stat.st_dev & 0xff00) >> 8
fs_minor = fs_stat.st_dev & 0xff
root_table = subprocess.check_output(["dmsetup",
sudo = []
if os.getuid():
sudo = ['sudo']
root_table = subprocess.check_output(sudo + ["dmsetup",
"-j", str(fs_major), "-m", str(fs_minor),
"table"])
"table"], stderr=subprocess.DEVNULL)
_start, _sectors, target_type, target_args = \
root_table.decode().split(" ", 3)