Browse Source

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)
Marek Marczykowski-Górecki 6 years ago
parent
commit
825de49767
1 changed files with 5 additions and 2 deletions
  1. 5 2
      qubes/storage/__init__.py

+ 5 - 2
qubes/storage/__init__.py

@@ -932,9 +932,12 @@ class DirectoryThinPool:
                 fs_major = (fs_stat.st_dev & 0xff00) >> 8
                 fs_major = (fs_stat.st_dev & 0xff00) >> 8
                 fs_minor = fs_stat.st_dev & 0xff
                 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),
                     "-j", str(fs_major), "-m", str(fs_minor),
-                    "table"])
+                    "table"], stderr=subprocess.DEVNULL)
 
 
                 _start, _sectors, target_type, target_args = \
                 _start, _sectors, target_type, target_args = \
                     root_table.decode().split(" ", 3)
                     root_table.decode().split(" ", 3)