Skip to content

Commit

Permalink
Merge branch 'QubesOS:master' into shrink_volume
Browse files Browse the repository at this point in the history
  • Loading branch information
a-barinov authored Jun 12, 2022
2 parents f6fbce2 + bcdf577 commit 1daff6b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ ADMIN_API_METHODS_SIMPLE = \
admin.vm.device.block.Detach \
admin.vm.device.block.List \
admin.vm.device.block.Set.persistent \
admin.vm.device.usb.Attach \
admin.vm.device.usb.Available \
admin.vm.device.usb.Detach \
admin.vm.device.usb.List \
admin.vm.device.usb.Set.persistent \
admin.vm.device.mic.Attach \
admin.vm.device.mic.Available \
admin.vm.device.mic.Detach \
Expand Down
19 changes: 13 additions & 6 deletions qubes/storage/lvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import qubes
import qubes.storage
import qubes.utils
import json

_sudo, _dd, _lvm = 'sudo', 'dd', 'lvm'

Expand Down Expand Up @@ -206,19 +207,25 @@ def usage_details(self):

_init_cache_cmd = [_lvm, 'lvs', '--noheadings', '-o',
'vg_name,pool_lv,name,lv_size,data_percent,lv_attr,origin,lv_metadata_size,'
'metadata_percent', '--units', 'b', '--separator', ';']
'metadata_percent', '--units', 'b', '--reportformat=json']
if os.getuid() != 0:
_init_cache_cmd.insert(0, _sudo)

def _parse_lvm_cache(lvm_output):
# Assume that LVM produces correct JSON.
out_list = json.loads(lvm_output)["report"][0]["lv"]
result = {}

for line in lvm_output.splitlines():
line = line.decode().strip()
pool_name, pool_lv, name, size, usage_percent, attr, \
origin, metadata_size, metadata_percent = line.split(';', 8)
for row in out_list:
try:
pool_name, name = row['vg_name'], row['lv_name']
size, usage_percent = row['lv_size'], row['data_percent']
except KeyError:
continue
if '' in [pool_name, name, size, usage_percent]:
continue
pool_lv, attr, origin = row['pool_lv'], row['lv_attr'], row['origin']
metadata_size = row['lv_metadata_size']
metadata_percent = row['metadata_percent']
name = pool_name + "/" + name
size = int(size[:-1]) # Remove 'B' suffix
usage = int(size / 100 * float(usage_percent))
Expand Down
13 changes: 6 additions & 7 deletions qubes/vm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,7 @@ def __set__(self, instance, value):
if self.allow_none:
super().__set__(instance, value)
return
raise ValueError(
'Property {!r} does not allow setting to {!r}'.format(
self.__name__, value))
raise qubes.exc.QubesPropertyValueError(instance, self, value)

app = instance if isinstance(instance, qubes.Qubes) else instance.app

Expand All @@ -487,10 +485,11 @@ def __set__(self, instance, value):
raise qubes.exc.QubesVMNotFoundError(value)

if not isinstance(vm, self.vmclass):
raise TypeError('wrong VM class: domains[{!r}] is of type {!s} '
'and not {!s}'.format(value,
vm.__class__.__name__,
self.vmclass.__name__))
raise qubes.exc.QubesPropertyValueError(instance, self, value,
'wrong VM class: domains[{!r}] is of type {!s} '
'and not {!s}'.format(value,
vm.__class__.__name__,
self.vmclass.__name__))

super().__set__(instance, vm)

Expand Down

0 comments on commit 1daff6b

Please sign in to comment.