From 70d3f58024d75be0e731420da2b82608fc075f34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Thu, 18 Aug 2016 14:02:39 +0200 Subject: [PATCH] qubes/storage: misc fixes for VM-exposed block devices handling Add 'backenddomain' element when source (not target) domain is not dom0. Fix XML elemenet name. Actually set volume.domain when listing VM-exposed devices. QubesOS/qubes-issues#2256 --- qubes/storage/__init__.py | 4 ++-- qubes/storage/domain.py | 5 +++-- qubes/storage/file.py | 1 + templates/libvirt/xen.xml | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/qubes/storage/__init__.py b/qubes/storage/__init__.py index 4d04a818..64827ad1 100644 --- a/qubes/storage/__init__.py +++ b/qubes/storage/__init__.py @@ -255,9 +255,9 @@ class Storage(object): if not rw: lxml.etree.SubElement(disk, 'readonly') - if self.vm.qid != 0: + if volume.domain is not None: lxml.etree.SubElement(disk, 'backenddomain').set( - 'name', volume.pool.split('p_')[1]) + 'name', volume.domain.name) xml_string = lxml.etree.tostring(disk, encoding='utf-8') self.vm.libvirt_domain.attachDevice(xml_string) diff --git a/qubes/storage/domain.py b/qubes/storage/domain.py index d9d6207d..dce2acde 100644 --- a/qubes/storage/domain.py +++ b/qubes/storage/domain.py @@ -86,7 +86,7 @@ class DomainPool(Pool): devices[name][atr] = value - return [DomainVolume(n, self.name, **atrs) + return [DomainVolume(n, self.vm, self.name, **atrs) for n, atrs in devices.items()] def clone(self, source, target): @@ -99,11 +99,12 @@ class DomainPool(Pool): class DomainVolume(Volume): ''' A volume provided by a block device in an domain ''' - def __init__(self, name, pool, desc, mode, **kwargs): + def __init__(self, vm, name, pool, desc, mode, **kwargs): rw = (mode == 'w') super(DomainVolume, self).__init__(desc, pool, vid=name, removable=True, rw=rw, **kwargs) + self.domain = vm @property def revisions(self): diff --git a/qubes/storage/file.py b/qubes/storage/file.py index e8864779..fd9480cc 100644 --- a/qubes/storage/file.py +++ b/qubes/storage/file.py @@ -31,6 +31,7 @@ import os.path import re import subprocess +import qubes.devices import qubes.storage BLKSIZE = 512 diff --git a/templates/libvirt/xen.xml b/templates/libvirt/xen.xml index 18147cc6..3ce2ad5e 100644 --- a/templates/libvirt/xen.xml +++ b/templates/libvirt/xen.xml @@ -81,7 +81,7 @@ {% endif %} {% if device.domain %} - + {% endif %} {% if device.script %}