[libvirt] [PATCH 10/16] hostdev: Maintain a driver list of active mediated devices

2017-02-06 Thread Erik Skultety
Keep track of the assigned mediated devices the same way we do it for
the rest of hostdevs.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/libvirt_private.syms |   1 +
 src/qemu/qemu_hostdev.c  |  22 +
 src/qemu/qemu_hostdev.h  |   4 ++
 src/util/virhostdev.c| 126 ++-
 src/util/virhostdev.h|   9 
 5 files changed, 161 insertions(+), 1 deletion(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 4047945..8921a53 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1707,6 +1707,7 @@ virHostdevPCINodeDeviceDetach;
 virHostdevPCINodeDeviceReAttach;
 virHostdevPCINodeDeviceReset;
 virHostdevPrepareDomainDevices;
+virHostdevPrepareMediatedDevices;
 virHostdevPreparePCIDevices;
 virHostdevPrepareSCSIDevices;
 virHostdevPrepareSCSIVHostDevices;
diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index 7cd49e4..45b731c 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -305,6 +305,24 @@ qemuHostdevPrepareSCSIVHostDevices(virQEMUDriverPtr driver,
 }
 
 int
+qemuHostdevPrepareMediatedDevices(virQEMUDriverPtr driver,
+  const char *name,
+  virDomainHostdevDefPtr *hostdevs,
+  int nhostdevs)
+{
+virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
+
+if (!qemuHostdevHostSupportsPassthroughVFIO()) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("host doesn't support VFIO PCI interface"));
+return -1;
+}
+
+return virHostdevPrepareMediatedDevices(hostdev_mgr, QEMU_DRIVER_NAME,
+name, hostdevs, nhostdevs);
+}
+
+int
 qemuHostdevPrepareDomainDevices(virQEMUDriverPtr driver,
 virDomainDefPtr def,
 virQEMUCapsPtr qemuCaps,
@@ -330,6 +348,10 @@ qemuHostdevPrepareDomainDevices(virQEMUDriverPtr driver,
def->hostdevs, def->nhostdevs) < 0)
 return -1;
 
+if (qemuHostdevPrepareMediatedDevices(driver, def->name,
+  def->hostdevs, def->nhostdevs) < 0)
+return -1;
+
 return 0;
 }
 
diff --git a/src/qemu/qemu_hostdev.h b/src/qemu/qemu_hostdev.h
index 74a7d4f..9399241 100644
--- a/src/qemu/qemu_hostdev.h
+++ b/src/qemu/qemu_hostdev.h
@@ -59,6 +59,10 @@ int qemuHostdevPrepareSCSIVHostDevices(virQEMUDriverPtr 
driver,
const char *name,
virDomainHostdevDefPtr *hostdevs,
int nhostdevs);
+int qemuHostdevPrepareMediatedDevices(virQEMUDriverPtr driver,
+  const char *name,
+  virDomainHostdevDefPtr *hostdevs,
+  int nhostdevs);
 int qemuHostdevPrepareDomainDevices(virQEMUDriverPtr driver,
 virDomainDefPtr def,
 virQEMUCapsPtr qemuCaps,
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index 86ca8e0..7691eaa 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -1,6 +1,6 @@
 /* virhostdev.c: hostdev management
  *
- * Copyright (C) 2006-2007, 2009-2016 Red Hat, Inc.
+ * Copyright (C) 2006-2007, 2009-2017 Red Hat, Inc.
  * Copyright (C) 2006 Daniel P. Berrange
  * Copyright (C) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
  *
@@ -147,6 +147,7 @@ virHostdevManagerDispose(void *obj)
 virObjectUnref(hostdevMgr->activeUSBHostdevs);
 virObjectUnref(hostdevMgr->activeSCSIHostdevs);
 virObjectUnref(hostdevMgr->activeSCSIVHostHostdevs);
+virObjectUnref(hostdevMgr->activeMediatedHostdevs);
 VIR_FREE(hostdevMgr->stateDir);
 }
 
@@ -174,6 +175,9 @@ virHostdevManagerNew(void)
 if (!(hostdevMgr->activeSCSIVHostHostdevs = virSCSIVHostDeviceListNew()))
 goto error;
 
+if (!(hostdevMgr->activeMediatedHostdevs = virMediatedDeviceListNew()))
+goto error;
+
 if (privileged) {
 if (VIR_STRDUP(hostdevMgr->stateDir, HOSTDEV_STATE_DIR) < 0)
 goto error;
@@ -1595,6 +1599,126 @@ virHostdevPrepareSCSIVHostDevices(virHostdevManagerPtr 
mgr,
 return -1;
 }
 
+static int
+virHostdevMarkMediatedDevices(virHostdevManagerPtr mgr,
+  const char *drvname,
+  const char *domname,
+  virMediatedDeviceListPtr list)
+{
+size_t i, j;
+unsigned int count;
+virMediatedDevicePtr tmp;
+
+virObjectLock(mgr->activeMediatedHostdevs);
+count = virMediatedDeviceListCount(list);
+
+for (i = 0; i < count; i++) {
+virMediatedDevicePtr mdev = virMediatedDeviceListGet(

[libvirt] [PATCH 06/16] security: dac: Enable labeling of vfio mediated devices

2017-02-06 Thread Erik Skultety
Label the VFIO IOMMU devices under /dev/vfio/ referenced by the symlinks
in the sysfs (e.g. /sys/class/mdev_bus//iommu_group) which what
qemu actually gets formatted on the command line.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/security/security_dac.c | 58 +++--
 1 file changed, 56 insertions(+), 2 deletions(-)

diff --git a/src/security/security_dac.c b/src/security/security_dac.c
index ecce1d3..93cb66f 100644
--- a/src/security/security_dac.c
+++ b/src/security/security_dac.c
@@ -33,6 +33,7 @@
 #include "virfile.h"
 #include "viralloc.h"
 #include "virlog.h"
+#include "virmdev.h"
 #include "virpci.h"
 #include "virusb.h"
 #include "virscsi.h"
@@ -856,6 +857,15 @@ virSecurityDACSetHostLabel(virSCSIVHostDevicePtr dev 
ATTRIBUTE_UNUSED,
 
 
 static int
+virSecurityDACSetMediatedDevLabel(virMediatedDevicePtr dev ATTRIBUTE_UNUSED,
+  const char *file,
+  void *opaque)
+{
+return virSecurityDACSetHostdevLabelHelper(file, opaque);
+}
+
+
+static int
 virSecurityDACSetHostdevLabel(virSecurityManagerPtr mgr,
   virDomainDefPtr def,
   virDomainHostdevDefPtr dev,
@@ -867,7 +877,9 @@ virSecurityDACSetHostdevLabel(virSecurityManagerPtr mgr,
 virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
 virDomainHostdevSubsysSCSIVHostPtr hostsrc = 
>source.subsys.u.scsi_host;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 int ret = -1;
+virMediatedDevicePtr mdev = NULL;
 
 if (!priv->dynamicOwnership)
 return 0;
@@ -964,13 +976,26 @@ virSecurityDACSetHostdevLabel(virSecurityManagerPtr mgr,
 break;
 }
 
-case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
+char *vfio_dev = NULL;
+if (!(mdev = virMediatedDeviceNew(>addr, mdevsrc->uuidstr)))
+goto done;
+
+if (!(vfio_dev = virMediatedDeviceGetIOMMUGroupDev(mdev)))
+goto done;
+
+ret = virSecurityDACSetMediatedDevLabel(mdev, vfio_dev, );
+VIR_FREE(vfio_dev);
+break;
+}
+
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 ret = 0;
 break;
 }
 
  done:
+virMediatedDeviceFree(mdev);
 return ret;
 }
 
@@ -1018,6 +1043,15 @@ virSecurityDACRestoreHostLabel(virSCSIVHostDevicePtr dev 
ATTRIBUTE_UNUSED,
 return virSecurityDACRestoreFileLabel(priv, file);
 }
 
+static int
+virSecurityDACRestoreMediatedDevLabel(virMediatedDevicePtr dev 
ATTRIBUTE_UNUSED,
+  const char *file,
+  void *opaque)
+{
+virSecurityManagerPtr mgr = opaque;
+virSecurityDACDataPtr priv = virSecurityManagerGetPrivateData(mgr);
+return virSecurityDACRestoreFileLabel(priv, file);
+}
 
 static int
 virSecurityDACRestoreHostdevLabel(virSecurityManagerPtr mgr,
@@ -1032,6 +1066,7 @@ virSecurityDACRestoreHostdevLabel(virSecurityManagerPtr 
mgr,
 virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
 virDomainHostdevSubsysSCSIVHostPtr hostsrc = 
>source.subsys.u.scsi_host;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 int ret = -1;
 
 secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_DAC_NAME);
@@ -1120,7 +1155,26 @@ virSecurityDACRestoreHostdevLabel(virSecurityManagerPtr 
mgr,
 break;
 }
 
-case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
+char *vfiodev = NULL;
+virMediatedDevicePtr mdev = virMediatedDeviceNew(>addr,
+ mdevsrc->uuidstr);
+
+if (!mdev)
+goto done;
+
+if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdev))) {
+virMediatedDeviceFree(mdev);
+goto done;
+}
+
+ret = virSecurityDACRestoreMediatedDevLabel(mdev, vfiodev, mgr);
+
+VIR_FREE(vfiodev);
+virMediatedDeviceFree(mdev);
+break;
+}
+
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 ret = 0;
 break;
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 15/16] test: Add some test cases for our test suite regarding the mdevs

2017-02-06 Thread Erik Skultety
For now, focus only on unmanaged devices, thus also testing whether the
uuid element is present or not, since in case of unmanaged mediated
devices it must be present.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 ...qemuxml2argv-hostdev-mdev-unmanaged-no-uuid.xml | 37 +++
 .../qemuxml2argv-hostdev-mdev-unmanaged.args   | 25 +
 .../qemuxml2argv-hostdev-mdev-unmanaged.xml| 38 
 tests/qemuxml2argvtest.c   |  6 
 .../qemuxml2xmlout-hostdev-mdev-unmanaged.xml  | 41 ++
 tests/qemuxml2xmltest.c|  1 +
 6 files changed, 148 insertions(+)
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged-no-uuid.xml
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.args
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.xml
 create mode 100644 
tests/qemuxml2xmloutdata/qemuxml2xmlout-hostdev-mdev-unmanaged.xml

diff --git 
a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged-no-uuid.xml 
b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged-no-uuid.xml
new file mode 100644
index 000..0fda187
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged-no-uuid.xml
@@ -0,0 +1,37 @@
+
+  QEMUGuest2
+  c7a5fdbd-edaf-9455-926a-d65c16db1809
+  219136
+  219136
+  1
+  
+hvm
+
+  
+  
+  destroy
+  restart
+  destroy
+  
+/usr/bin/qemu
+
+  
+  
+  
+  
+
+
+
+
+
+
+
+
+
+  
+
+  
+
+
+  
+
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.args 
b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.args
new file mode 100644
index 000..be0017e
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.args
@@ -0,0 +1,25 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/home/test \
+USER=test \
+LOGNAME=test \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu \
+-name QEMUGuest2 \
+-S \
+-M pc \
+-m 214 \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
+-nographic \
+-nodefconfig \
+-nodefaults \
+-monitor unix:/tmp/lib/domain--1-QEMUGuest2/monitor.sock,server,nowait \
+-no-acpi \
+-boot c \
+-usb \
+-drive file=/dev/HostVG/QEMUGuest2,format=raw,if=none,id=drive-ide0-0-0 \
+-device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \
+-device vfio-pci,\
+sysfsdev=/sys/class/mdev_bus/:00:03.0/53764d0e-85a0-42b4-af5c-2046b460b1dc,\
+bus=pci.0,addr=0x3
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.xml 
b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.xml
new file mode 100644
index 000..025429d
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.xml
@@ -0,0 +1,38 @@
+
+  QEMUGuest2
+  c7a5fdbd-edaf-9455-926a-d65c16db1809
+  219136
+  219136
+  1
+  
+hvm
+
+  
+  
+  destroy
+  restart
+  destroy
+  
+/usr/bin/qemu
+
+  
+  
+  
+  
+
+
+
+
+
+
+
+
+
+  
+
+53764d0e-85a0-42b4-af5c-2046b460b1dc
+  
+
+
+  
+
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 3532cb5..12ed800 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1469,6 +1469,12 @@ mymain(void)
 DO_TEST("hostdev-vfio-multidomain",
 QEMU_CAPS_NODEFCONFIG,
 QEMU_CAPS_DEVICE_VFIO_PCI, QEMU_CAPS_HOST_PCI_MULTIDOMAIN);
+DO_TEST("hostdev-mdev-unmanaged",
+QEMU_CAPS_NODEFCONFIG,
+QEMU_CAPS_DEVICE_VFIO_PCI);
+DO_TEST_PARSE_ERROR("hostdev-mdev-unmanaged-no-uuid",
+QEMU_CAPS_NODEFCONFIG,
+QEMU_CAPS_DEVICE_VFIO_PCI);
 DO_TEST_FAILURE("hostdev-vfio-multidomain",
 QEMU_CAPS_NODEFCONFIG, QEMU_CAPS_DEVICE_VFIO_PCI);
 DO_TEST("pci-rom",
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-hostdev-mdev-unmanaged.xml 
b/tests/qemuxml2xmloutdata/qemuxml2xmlout-hostdev-mdev-unmanaged.xml
new file mode 100644
index 000..baa8b78
--- /dev/null
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-hostdev-mdev-unmanaged.xml
@@ -0,0 +1,41 @@
+
+  QEMUGuest2
+  c7a5fdbd-edaf-9455-926a-d65c16db1809
+  219136
+  219136
+  1
+  
+hvm
+
+  
+  
+  destroy
+  restart
+  destroy
+  
+/usr/bin/qemu
+
+  
+  
+  
+  
+
+
+  
+
+
+
+  
+
+
+
+
+  
+
+53764d0e-85a0-42b4-af5c-2046b460b1dc
+  
+  
+
+
+  
+
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 4f3b09a..740025d 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -550,6 +550,7 @@ mymain(void)
 DO_TEST("hostdev-usb-address", NONE);
 DO_TEST("hostdev-pci-address&

[libvirt] [PATCH 13/16] qemu: namespace: Hook up the discovery of mdevs into the namespace code

2017-02-06 Thread Erik Skultety
Again, as for all the other hostdev device types, make sure that the
/dev/vfio/ device will be added to the qemu namespace.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/qemu/qemu_domain.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 3006d78..afc7d07 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -6824,10 +6824,12 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev,
 virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
 virDomainHostdevSubsysSCSIVHostPtr hostsrc = 
>source.subsys.u.scsi_host;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 virPCIDevicePtr pci = NULL;
 virUSBDevicePtr usb = NULL;
 virSCSIDevicePtr scsi = NULL;
 virSCSIVHostDevicePtr host = NULL;
+virMediatedDevicePtr mdev = NULL;
 char *tmpPath = NULL;
 bool freeTmpPath = false;
 
@@ -6902,6 +6904,15 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev,
 }
 
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+if (!(mdev = virMediatedDeviceNew(>addr,
+  mdevsrc->uuidstr)))
+goto cleanup;
+
+if (!(tmpPath = virMediatedDeviceGetIOMMUGroupDev(mdev)))
+goto cleanup;
+
+freeTmpPath = true;
+break;
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 break;
 }
@@ -6922,6 +6933,7 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev,
 virUSBDeviceFree(usb);
 virSCSIDeviceFree(scsi);
 virSCSIVHostDeviceFree(host);
+virMediatedDeviceFree(mdev);
 if (freeTmpPath)
 VIR_FREE(tmpPath);
 return ret;
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 12/16] qemu: cgroup: Adjust cgroups' logic to allow mediated devices

2017-02-06 Thread Erik Skultety
As goes for all the other hostdev device types, grant the qemu process
access to /dev/vfio/.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/qemu/qemu_cgroup.c | 30 ++
 1 file changed, 30 insertions(+)

diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 0902624..405d6c1 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -318,6 +318,23 @@ qemuSetupHostSCSIVHostDeviceCgroup(virSCSIVHostDevicePtr 
dev ATTRIBUTE_UNUSED,
 return ret;
 }
 
+static int
+qemuSetupHostMediatedDeviceCgroup(virMediatedDevicePtr dev ATTRIBUTE_UNUSED,
+  const char *path,
+  void *opaque)
+{
+virDomainObjPtr vm = opaque;
+qemuDomainObjPrivatePtr priv = vm->privateData;
+int ret = -1;
+
+VIR_DEBUG("Process path '%s' for mediated device", path);
+ret = virCgroupAllowDevicePath(priv->cgroup, path,
+   VIR_CGROUP_DEVICE_RW, false);
+virDomainAuditCgroupPath(vm, priv->cgroup, "allow", path, "rw", ret == 0);
+
+return ret;
+}
+
 int
 qemuSetupHostdevCgroup(virDomainObjPtr vm,
virDomainHostdevDefPtr dev)
@@ -328,10 +345,12 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm,
 virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
 virDomainHostdevSubsysSCSIVHostPtr hostsrc = 
>source.subsys.u.scsi_host;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 virPCIDevicePtr pci = NULL;
 virUSBDevicePtr usb = NULL;
 virSCSIDevicePtr scsi = NULL;
 virSCSIVHostDevicePtr host = NULL;
+virMediatedDevicePtr mdev = NULL;
 char *path = NULL;
 
 /* currently this only does something for PCI devices using vfio
@@ -434,6 +453,16 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm,
 }
 
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+if (!(mdev = virMediatedDeviceNew(>addr,
+  mdevsrc->uuidstr)))
+goto cleanup;
+
+if (!(path = virMediatedDeviceGetIOMMUGroupDev(mdev)))
+goto cleanup;
+
+if (qemuSetupHostMediatedDeviceCgroup(mdev, path, vm) < 0)
+goto cleanup;
+
 break;
 
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
@@ -447,6 +476,7 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm,
 virUSBDeviceFree(usb);
 virSCSIDeviceFree(scsi);
 virSCSIVHostDeviceFree(host);
+virMediatedDeviceFree(mdev);
 VIR_FREE(path);
 return ret;
 }
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 07/16] security: selinux: Enable labeling of vfio mediated devices

2017-02-06 Thread Erik Skultety
Label the VFIO IOMMU devices under /dev/vfio/ referenced by the symlinks
in the sysfs (e.g. /sys/class/mdev_bus//iommu_group) which what
qemu actually gets formatted on the command line.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/security/security_selinux.c | 57 +++--
 1 file changed, 55 insertions(+), 2 deletions(-)

diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index e152c72..4f6b098 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -36,6 +36,7 @@
 #include "virerror.h"
 #include "viralloc.h"
 #include "virlog.h"
+#include "virmdev.h"
 #include "virpci.h"
 #include "virusb.h"
 #include "virscsi.h"
@@ -1686,6 +1687,13 @@ virSecuritySELinuxSetHostLabel(virSCSIVHostDevicePtr dev 
ATTRIBUTE_UNUSED,
 }
 
 static int
+virSecuritySELinuxSetMediatedDevLabel(virMediatedDevicePtr dev 
ATTRIBUTE_UNUSED,
+  const char *file, void *opaque)
+{
+return virSecuritySELinuxSetHostdevLabelHelper(file, opaque);
+}
+
+static int
 virSecuritySELinuxSetHostdevSubsysLabel(virSecurityManagerPtr mgr,
 virDomainDefPtr def,
 virDomainHostdevDefPtr dev,
@@ -1696,7 +1704,9 @@ 
virSecuritySELinuxSetHostdevSubsysLabel(virSecurityManagerPtr mgr,
 virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
 virDomainHostdevSubsysSCSIVHostPtr hostsrc = 
>source.subsys.u.scsi_host;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 virSecuritySELinuxCallbackData data = {.mgr = mgr, .def = def};
+virMediatedDevicePtr mdev = NULL;
 
 int ret = -1;
 
@@ -1782,13 +1792,26 @@ 
virSecuritySELinuxSetHostdevSubsysLabel(virSecurityManagerPtr mgr,
 break;
 }
 
-case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
+char *vfio_dev = NULL;
+if (!(mdev = virMediatedDeviceNew(>addr, mdevsrc->uuidstr)))
+goto done;
+
+if (!(vfio_dev = virMediatedDeviceGetIOMMUGroupDev(mdev)))
+goto done;
+
+ret = virSecuritySELinuxSetMediatedDevLabel(mdev, vfio_dev, );
+VIR_FREE(vfio_dev);
+break;
+}
+
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 ret = 0;
 break;
 }
 
  done:
+virMediatedDeviceFree(mdev);
 return ret;
 }
 
@@ -1918,6 +1941,16 @@ virSecuritySELinuxRestoreHostLabel(virSCSIVHostDevicePtr 
dev ATTRIBUTE_UNUSED,
 }
 
 static int
+virSecuritySELinuxRestoreMediatedDevLabel(virMediatedDevicePtr dev 
ATTRIBUTE_UNUSED,
+   const char *file,
+   void *opaque)
+{
+virSecurityManagerPtr mgr = opaque;
+
+return virSecuritySELinuxRestoreFileLabel(mgr, file);
+}
+
+static int
 virSecuritySELinuxRestoreHostdevSubsysLabel(virSecurityManagerPtr mgr,
 virDomainHostdevDefPtr dev,
 const char *vroot)
@@ -1927,6 +1960,7 @@ 
virSecuritySELinuxRestoreHostdevSubsysLabel(virSecurityManagerPtr mgr,
 virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
 virDomainHostdevSubsysSCSIVHostPtr hostsrc = 
>source.subsys.u.scsi_host;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 int ret = -1;
 
 /* Like virSecuritySELinuxRestoreImageLabelInt() for a networked
@@ -2010,7 +2044,26 @@ 
virSecuritySELinuxRestoreHostdevSubsysLabel(virSecurityManagerPtr mgr,
 break;
 }
 
-case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
+char *vfiodev = NULL;
+virMediatedDevicePtr mdev = virMediatedDeviceNew(>addr,
+ mdevsrc->uuidstr);
+
+if (!mdev)
+goto done;
+
+if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdev))) {
+virMediatedDeviceFree(mdev);
+goto done;
+}
+
+ret = virSecuritySELinuxRestoreMediatedDevLabel(mdev, vfiodev, mgr);
+
+VIR_FREE(vfiodev);
+virMediatedDeviceFree(mdev);
+break;
+}
+
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 ret = 0;
 break;
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 01/16] util: Introduce new module virmdev

2017-02-06 Thread Erik Skultety
Beside creation, disposal, getter, and setter methods the module exports
methods to work with lists of mediated devices.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 po/POTFILES.in   |   1 +
 src/Makefile.am  |   1 +
 src/libvirt_private.syms |  17 +++
 src/util/virmdev.c   | 375 +++
 src/util/virmdev.h   |  85 +++
 5 files changed, 479 insertions(+)
 create mode 100644 src/util/virmdev.c
 create mode 100644 src/util/virmdev.h

diff --git a/po/POTFILES.in b/po/POTFILES.in
index 365ea66..53c674e 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -218,6 +218,7 @@ src/util/virlease.c
 src/util/virlockspace.c
 src/util/virlog.c
 src/util/virmacmap.c
+src/util/virmdev.c
 src/util/virnetdev.c
 src/util/virnetdevbandwidth.c
 src/util/virnetdevbridge.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 2f32d41..6510e1d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -186,6 +186,7 @@ UTIL_SOURCES =  
\
util/viruuid.c util/viruuid.h   \
util/virxdrdefs.h   \
util/virxml.c util/virxml.h \
+   util/virmdev.c util/virmdev.h   \
$(NULL)
 
 EXTRA_DIST += $(srcdir)/util/keymaps.csv $(srcdir)/util/virkeycode-mapgen.py
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 8e994c7..4047945 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1960,6 +1960,23 @@ virMacMapNew;
 virMacMapRemove;
 virMacMapWriteFile;
 
+# util/virmdev.h
+virMediatedDeviceFree;
+virMediatedDeviceGetIOMMUGroupDev;
+virMediatedDeviceGetPath;
+virMediatedDeviceGetUsedBy;
+virMediatedDeviceListAdd;
+virMediatedDeviceListCount;
+virMediatedDeviceListDel;
+virMediatedDeviceListFind;
+virMediatedDeviceListGet;
+virMediatedDeviceListNew;
+virMediatedDeviceListSteal;
+virMediatedDeviceListStealIndex;
+virMediatedDeviceNew;
+virMediatedDeviceSetUsedBy;
+
+
 
 # util/virnetdev.h
 virNetDevAddMulti;
diff --git a/src/util/virmdev.c b/src/util/virmdev.c
new file mode 100644
index 000..0b70798
--- /dev/null
+++ b/src/util/virmdev.c
@@ -0,0 +1,375 @@
+/*
+ * virmdev.c: helper APIs for managing host MDEV devices
+ *
+ * Copyright (C) 2017-2018 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Erik Skultety <eskul...@redhat.com>
+ */
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "virmdev.h"
+#include "dirname.h"
+#include "virlog.h"
+#include "viralloc.h"
+#include "vircommand.h"
+#include "virerror.h"
+#include "virfile.h"
+#include "virkmod.h"
+#include "virstring.h"
+#include "virutil.h"
+#include "viruuid.h"
+#include "virhostdev.h"
+
+VIR_LOG_INIT("util.mdev");
+
+struct _virMediatedDevice {
+char *path; /* sysfs path */
+bool managed;
+
+char *used_by_drvname;
+char *used_by_domname;
+};
+
+struct _virMediatedDeviceList {
+virObjectLockable parent;
+
+size_t count;
+virMediatedDevicePtr *devs;
+};
+
+
+/* For virReportOOMError()  and virReportSystemError() */
+#define VIR_FROM_THIS VIR_FROM_NONE
+
+static virClassPtr virMediatedDeviceListClass;
+
+static void virMediatedDeviceListDispose(void *obj);
+
+static int virMediatedOnceInit(void)
+{
+if (!(virMediatedDeviceListClass = virClassNew(virClassForObjectLockable(),
+   "virMediatedDeviceList",
+   
sizeof(virMediatedDeviceList),
+   
virMediatedDeviceListDispose)))
+return -1;
+
+return 0;
+}
+
+VIR_ONCE_GLOBAL_INIT(virMediated)
+
+#ifdef __linux__
+# define MDEV_SYSFS "/sys/class/mdev_bus/"
+
+virMediatedDevicePtr
+virMediatedDeviceNew(virPCIDeviceAddressPtr pciaddr, const char *uuidstr)
+{
+virMediatedDevicePtr dev = NULL, ret = NULL;
+char *pcistr = NULL;
+
+if (virAsprintf(, "%.4x:%.2x:%.2x.%.1x", pciaddr->domain,
+   

[libvirt] [PATCH 03/16] docs: Update RNG schema to reflect the new hostdev type mdev

2017-02-06 Thread Erik Skultety
To keep the domain XML as much platform agnostic as possible, do not
expose an element/attribute which would contain path directly to the
syfs filesystem which the mediated devices are build upon. Instead,
identify each mediated device by the parent physical device and a UUID
which is an optional element, but only if managed='yes' which is not
implemented yet.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 docs/schemas/domaincommon.rng | 17 +
 1 file changed, 17 insertions(+)

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index cc6e0d0..087ca82 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -3984,6 +3984,7 @@
   
   
   
+  
 
   
 
@@ -4134,6 +4135,22 @@
 
   
 
+  
+
+  mdev
+
+
+  
+
+  
+  
+
+  
+
+  
+
+  
+
   
 
   storage
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 11/16] hostdev: Introduce a reattach method for mediated devices

2017-02-06 Thread Erik Skultety
The name "reattach" does not really reflect the truth behind mediated
devices, since these are purely software devices that do not need to be
plugged back into the host in any way, however this patch pushes for
naming consistency for methods where the logic behind the underlying
operation stays the same except that in case of mdevs the operation
itself is effectively a NO-OP.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/libvirt_private.syms |  1 +
 src/qemu/qemu_hostdev.c  | 15 ++
 src/qemu/qemu_hostdev.h  |  4 
 src/util/virhostdev.c| 53 
 src/util/virhostdev.h|  7 +++
 5 files changed, 80 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 8921a53..00fb2c2 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1713,6 +1713,7 @@ virHostdevPrepareSCSIDevices;
 virHostdevPrepareSCSIVHostDevices;
 virHostdevPrepareUSBDevices;
 virHostdevReAttachDomainDevices;
+virHostdevReAttachMediatedDevices;
 virHostdevReAttachPCIDevices;
 virHostdevReAttachSCSIDevices;
 virHostdevReAttachSCSIVHostDevices;
diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index 45b731c..6a7232f 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -419,6 +419,18 @@ qemuHostdevReAttachSCSIVHostDevices(virQEMUDriverPtr 
driver,
 }
 
 void
+qemuHostdevReAttachMediatedDevices(virQEMUDriverPtr driver,
+   const char *name,
+   virDomainHostdevDefPtr *hostdevs,
+   int nhostdevs)
+{
+virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
+
+virHostdevReAttachMediatedDevices(hostdev_mgr, QEMU_DRIVER_NAME,
+  name, hostdevs, nhostdevs);
+}
+
+void
 qemuHostdevReAttachDomainDevices(virQEMUDriverPtr driver,
  virDomainDefPtr def)
 {
@@ -436,4 +448,7 @@ qemuHostdevReAttachDomainDevices(virQEMUDriverPtr driver,
 
 qemuHostdevReAttachSCSIVHostDevices(driver, def->name, def->hostdevs,
 def->nhostdevs);
+
+qemuHostdevReAttachMediatedDevices(driver, def->name, def->hostdevs,
+   def->nhostdevs);
 }
diff --git a/src/qemu/qemu_hostdev.h b/src/qemu/qemu_hostdev.h
index 9399241..0096497 100644
--- a/src/qemu/qemu_hostdev.h
+++ b/src/qemu/qemu_hostdev.h
@@ -84,6 +84,10 @@ void qemuHostdevReAttachSCSIVHostDevices(virQEMUDriverPtr 
driver,
  const char *name,
  virDomainHostdevDefPtr *hostdevs,
  int nhostdevs);
+void qemuHostdevReAttachMediatedDevices(virQEMUDriverPtr driver,
+const char *name,
+virDomainHostdevDefPtr *hostdevs,
+int nhostdevs);
 void qemuHostdevReAttachDomainDevices(virQEMUDriverPtr driver,
   virDomainDefPtr def);
 
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index 7691eaa..520b711 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -1913,6 +1913,59 @@ virHostdevReAttachSCSIVHostDevices(virHostdevManagerPtr 
mgr,
 virObjectUnlock(mgr->activeSCSIVHostHostdevs);
 }
 
+void
+virHostdevReAttachMediatedDevices(virHostdevManagerPtr mgr,
+  const char *drv_name,
+  const char *dom_name,
+  virDomainHostdevDefPtr *hostdevs,
+  int nhostdevs)
+{
+char *used_by_drvname = NULL;
+char *used_by_domname = NULL;
+virDomainHostdevDefPtr hostdev = NULL;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = NULL;
+size_t i;
+
+if (nhostdevs == 0)
+return;
+
+virObjectLock(mgr->activeMediatedHostdevs);
+for (i = 0; i < nhostdevs; i++) {
+virMediatedDevicePtr mdev, tmp;
+
+hostdev = hostdevs[i];
+mdevsrc = >source.subsys.u.mdev;
+
+if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
+hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV)
+continue;
+
+if (!(mdev = virMediatedDeviceNew(>addr, mdevsrc->uuidstr))) {
+VIR_WARN("Failed to reattach mediated device %s attached to "
+ "domain %s", mdevsrc->uuidstr, dom_name);
+continue;
+}
+
+/* Remove from the list only mdevs assigned to @drv_name/@dom_name */
+
+tmp = virMediatedDeviceListFind(mgr->activeMediatedHostdevs, mdev);
+virMediatedDeviceFree(mdev);
+
+/* skip inactive devices */
+if (!tmp)
+continue;
+
+virMediatedDeviceGetUsedB

[libvirt] [PATCH 09/16] qemu: Assign PCI addresses for mediated devices as well

2017-02-06 Thread Erik Skultety
So far, the official support is for x86_64 arch guests so unless a
different device API than vfio-pci is available let's assume PCI address
assignment. Once a different device API is introduced, we'll actually
have to start checking for the device API in the sysfs in order to
assign a correct type of address.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/qemu/qemu_domain_address.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 70482f2..71a2e5c 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -618,9 +618,11 @@ 
qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
 virPCIDeviceAddressPtr hostAddr = >source.subsys.u.pci.addr;
 
 if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
-hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) 
{
+(hostdev->source.subsys.type !=
+ VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
+ hostdev->source.subsys.type !=
+ VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV))
 return 0;
-}
 
 if (pciFlags == pcieFlags) {
 /* This arch/qemu only supports legacy PCI, so there
@@ -642,6 +644,9 @@ 
qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
 return pcieFlags;
 }
 
+if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV)
+return pcieFlags;
+
 if (!(pciDev = virPCIDeviceNew(hostAddr->domain,
hostAddr->bus,
hostAddr->slot,
@@ -1730,7 +1735,8 @@ qemuDomainAssignDevicePCISlots(virDomainDefPtr def,
 if (def->hostdevs[i]->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
 continue;
 if (def->hostdevs[i]->source.subsys.type != 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
-def->hostdevs[i]->source.subsys.type != 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST)
+def->hostdevs[i]->source.subsys.type != 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST &&
+def->hostdevs[i]->source.subsys.type != 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV)
 continue;
 
 if (qemuDomainPCIAddressReserveNextAddr(addrs,
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 0/3] storage: Fix FS pool destroy not unmounting its source

2017-02-07 Thread Erik Skultety
The issue lies in how we check whether a FS is already mounted or not, we
compare the pool's source/target with source/target in the mount's binary
output both of which can actually be just symlinks to the same location yet
failing our check on the FS being mounted, thus reporting a strange error that
the pool's source is already mounted.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1417203

Erik Skultety (3):
  storage: Fix reporting an error on an already mounted filesystem
  util: Introduce virFileComparePaths
  storage: Fix checking whether source filesystem is mounted

 src/libvirt_private.syms |  1 +
 src/storage/storage_backend_fs.c | 25 ++
 src/util/virfile.c   | 45 
 src/util/virfile.h   |  2 ++
 4 files changed, 64 insertions(+), 9 deletions(-)

-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 1/3] storage: Fix reporting an error on an already mounted filesystem

2017-02-07 Thread Erik Skultety
When FS pool's source is already mounted on the target location instead
of just simply marking the pool as active, thus starting it we fail with
an error stating that the source is indeed already mounted on the target.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/storage/storage_backend_fs.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index 54bcc57..fe4705b 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -358,14 +358,13 @@ virStorageBackendFileSystemMount(virStoragePoolObjPtr 
pool)
 if (virStorageBackendFileSystemIsValid(pool) < 0)
 return -1;
 
+if ((rc = virStorageBackendFileSystemIsMounted(pool)) < 0)
+return -1;
+
 /* Short-circuit if already mounted */
-if ((rc = virStorageBackendFileSystemIsMounted(pool)) != 0) {
-if (rc == 1) {
-virReportError(VIR_ERR_OPERATION_INVALID,
-   _("Target '%s' is already mounted"),
-   pool->def->target.path);
-}
-return -1;
+if (rc == 1) {
+VIR_INFO("Target '%s' is already mounted", pool->def->target.path);
+return 0;
 }
 
 if (!(src = virStorageBackendFileSystemGetPoolSource(pool)))
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 2/3] util: Introduce virFileComparePaths

2017-02-07 Thread Erik Skultety
So rather than comparing 2 paths (strings) as they are, which can very
easily lead to unnecessary errors (e.g. in storage driver) that the paths
are not the same when in fact they'd be e.g. just symlinks to the same
location, we should put our best effort into resolving any symlinks and
canonicalizing the path and only then compare the 2 paths.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/libvirt_private.syms |  1 +
 src/util/virfile.c   | 45 +
 src/util/virfile.h   |  2 ++
 3 files changed, 48 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 8e994c7..06f3737 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1575,6 +1575,7 @@ virFileActivateDirOverride;
 virFileBindMountDevice;
 virFileBuildPath;
 virFileClose;
+virFileComparePaths;
 virFileCopyACLs;
 virFileDeleteTree;
 virFileDirectFdFlag;
diff --git a/src/util/virfile.c b/src/util/virfile.c
index bf8099e..b261632 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -3737,3 +3737,48 @@ virFileCopyACLs(const char *src,
 virFileFreeACLs();
 return ret;
 }
+
+/*
+ * virFileComparePaths:
+ * @p1: source path 1
+ * @p2: source path 2
+ *
+ * Compares two paths for equality. To do so, it first canonicalizes both paths
+ * to resolve all symlinks and discard relative path components. If symlinks
+ * resolution or path canonicalization fails, plain string equality of @p1
+ * and @p2 is performed.
+ *
+ * Returns 0 if the paths are equal, 1 if they're not or -1 in case of an
+ * error.
+ */
+int
+virFileComparePaths(const char *p1, const char *p2)
+{
+int ret = -1;
+char *res1, *res2;
+
+res1 = res2 = NULL;
+
+/* Assume p1 and p2 are symlinks, so try to resolve and canonicalize them.
+ * Canonicalization fails for example on file systems names like 'proc' or
+ * 'sysfs', since they're no real paths so fallback to plain string
+ * comparison.
+ */
+ignore_value(virFileResolveLink(p1, ));
+if (!res1 && VIR_STRDUP(res1, p1) < 0)
+goto cleanup;
+
+ignore_value(virFileResolveLink(p2, ));
+if (!res2 && VIR_STRDUP(res2, p2) < 0)
+goto cleanup;
+
+if (STREQ_NULLABLE(res1, res2))
+ret = 0;
+else
+ret = 1;
+
+ cleanup:
+VIR_FREE(res1);
+VIR_FREE(res2);
+return ret;
+}
diff --git a/src/util/virfile.h b/src/util/virfile.h
index 0343acd..5822b29 100644
--- a/src/util/virfile.h
+++ b/src/util/virfile.h
@@ -331,4 +331,6 @@ void virFileFreeACLs(void **acl);
 
 int virFileCopyACLs(const char *src,
 const char *dst);
+
+int virFileComparePaths(const char *p1, const char *p2);
 #endif /* __VIR_FILE_H */
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 3/3] storage: Fix checking whether source filesystem is mounted

2017-02-07 Thread Erik Skultety
Right now, we use simple string comparison both on the source paths
(mount's output vs pool's source) and the target (mount's mnt_dir vs
pool's target). The problem are symlinks and mount indeed returns
symlinks in its output, e.g. /dev/mappper/lvm_symlink. The same goes for
the pool's source/target, so in order to successfully compare these two
replace plain string comparison with virFileComparePaths which will
resolve all symlinks and canonicalize the paths prior to comparison.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1417203

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/storage/storage_backend_fs.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index fe4705b..fae1c03 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -301,6 +301,7 @@ virStorageBackendFileSystemIsMounted(virStoragePoolObjPtr 
pool)
 FILE *mtab;
 struct mntent ent;
 char buf[1024];
+int rc1, rc2;
 
 if ((mtab = fopen(_PATH_MOUNTED, "r")) == NULL) {
 virReportSystemError(errno,
@@ -313,8 +314,15 @@ virStorageBackendFileSystemIsMounted(virStoragePoolObjPtr 
pool)
 if (!(src = virStorageBackendFileSystemGetPoolSource(pool)))
 goto cleanup;
 
-if (STREQ(ent.mnt_dir, pool->def->target.path) &&
-STREQ(ent.mnt_fsname, src)) {
+/* compare both mount destinations and sources to be sure the mounted
+ * FS pool is really the one we're looking for
+ */
+if ((rc1 = virFileComparePaths(ent.mnt_dir,
+   pool->def->target.path)) < 0 ||
+(rc2 = virFileComparePaths(ent.mnt_fsname, src)) < 0)
+goto cleanup;
+
+if (rc1 == 0 && rc2 == 0) {
 ret = 1;
 goto cleanup;
 }
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [RFC PATCH 00/16] Introduce vGPU mdev framework to libvirt

2017-02-07 Thread Erik Skultety
On Mon, Feb 06, 2017 at 09:33:14AM -0700, Alex Williamson wrote:
> On Mon,  6 Feb 2017 13:19:42 +0100
> Erik Skultety <eskul...@redhat.com> wrote:
> 
> > Finally. It's here. This is the initial suggestion on how libvirt might
> > interract with the mdev framework, currently only focussing on the 
> > non-managed
> > devices, i.e. those pre-created by the user, since that will be revisited 
> > once
> > we all settled on how the XML should look like, given we might not want to 
> > use
> > the sysfs path directly as an attribute in the domain XML. My proposal on 
> > the
> > XML is the following:
> > 
> >   
> > 
> > 
> > 
> > vGPU_UUID
> > 
> > 
> > 
> > 
> > So the mediated device is identified by the physical parent device visible 
> > on
> > the host and a UUID which allows us to construct the sysfs path by 
> > ourselves,
> > which we then put on the QEMU's command line.
> 
> Based on your test code, I think you're creating something like this:
> 
> -device 
> vfio-pci,sysfsdev=/sys/class/mdev_bus/:00:03.0/53764d0e-85a0-42b4-af5c-2046b460b1dc
> 
> That would explain the need for the parent device address, but that's
> an entirely self inflicted requirement.  For a managed="no" scenarios,
> we shouldn't need the parent, we can get to the mdev device
> via /sys/bus/mdev/devices/53764d0e-85a0-42b4-af5c-2046b460b1dc.  So it

True, for managed="no" would this path be a nice optimization.

> seems that the UUID should be the only required source element for
> managed="no".
> 
> For managed="yes", it seems like the parent device is still an optional

The reason I went with the parent address element (and purposely neglecting the
sample mtty driver) was that I assumed any modern mdev capable HW would be
accessible through the PCI bus on the host. Also I wanted to explicitly hint
libvirt as much as possible which parent device a vGPU device instance should
be created on in case there are more than one of them, rather then scanning
sysfs for a suitable parent which actually supports the given vGPU type.

> field.  The most important thing that libvirt needs to know when
> creating a mdev device for a VM is the mdev type name.  The parent
> device should be an optional field to help higher level management
> tools deal with placement of the device for locality or load balancing.
> Also, we can't assume that the parent device is a PCI device, the
> sample mtty driver already breaks this assumption.

Since we need to assume non-PCI devices and we still need to enable management
to hint libvirt about the parent to utilize load balancing and stuff, I've come
up with the following adjustments/ideas on how to reflect that in the XML:
- still use the address element but use it with the 'type' attribute [1] (still
  breaks the sample mtty driver though) while making the element truly optional
  if I'm going to be outvoted in favor of scanning the directory for a suitable
  parent device on our own, rather than requiring the user to provide that

- providing either an attribute or a standalone element for the parent device
  name, like a string version of the PCI address or whatever form the parent
  device comes in (doesn't break the mtty driver but I don't quite like this)

- providing a path element/attribute to sysfs pointing to the parent device
  which I'm afraid is what Daniel is not in favor of libvirt doing

So, this is what I've so far come up with in terms of hinting libvirt about the
parent device, do you have any input on this, maybe some more ideas on how we
should identify the parent device?

> 
> Also, grep'ing through the patches, I don't see that the "device_api"

Yep, this was also on purpose since as you write below, right now the only
functioning mdev devices we have to work with are vfio-pci capable only, so
with this RFC I wanted to gather some feedback on whether I'm moving the right
direction in the first place. So yeah, I thought this could be added at any 
point
later.

[1] http://libvirt.org/formatdomain.html#elementsAddress

Erik

> file is being used to test that the mdev device actually exports the
> vfio-pci API before making use of it with the QEMU vfio-pci driver.  We
> don't yet have any examples to the contrary, but non vfio-pci mdev
> devices are in development.  Just like we can't assume the parent
> device type, we can't assume the API of an mdev device to the user.
> Thanks,
> 
> Alex
> 
> > A few remarks if you actually happen to have a machine to test this on:
> > - right now the mediated devices are one-time use only, i.e. they have to be
> > recreated before every machine boot
> > - I wouldn't recommend assigning

Re: [libvirt] [RFC PATCH 00/16] Introduce vGPU mdev framework to libvirt

2017-02-07 Thread Erik Skultety
On Mon, Feb 06, 2017 at 04:44:37PM +, Daniel P. Berrange wrote:
> On Mon, Feb 06, 2017 at 01:19:42PM +0100, Erik Skultety wrote:
> > Finally. It's here. This is the initial suggestion on how libvirt might
> > interract with the mdev framework, currently only focussing on the 
> > non-managed
> > devices, i.e. those pre-created by the user, since that will be revisited 
> > once
> > we all settled on how the XML should look like, given we might not want to 
> > use
> > the sysfs path directly as an attribute in the domain XML. My proposal on 
> > the
> > XML is the following:
> > 
> >   
> > 
> > 
> > 
> > vGPU_UUID
> > 
> > 
> > 
> > 
> > So the mediated device is identified by the physical parent device visible 
> > on
> > the host and a UUID which allows us to construct the sysfs path by 
> > ourselves,
> > which we then put on the QEMU's command line.
> > 
> > A few remarks if you actually happen to have a machine to test this on:
> > - right now the mediated devices are one-time use only, i.e. they have to be
> > recreated before every machine boot
> > - I wouldn't recommend assigning multiple vGPUs to a single domain
> > 
> > Once this series is sorted out, we can then continue with 'managed=yes' 
> > where
> > as Laine pointed out [1], we need to figure out how exactly should the
> > management layer hint libvirt which vGPU type should be used for device
> > instantiation.
> 
> You seem to be suggesting that managed=yes with mdev devices would
> cause create / delete of a mdev device from a specified parent.
> 
> This is rather different semantics from what managed=yes does with
> PCI device assignment today.  There the managed=yes flag is just
> about controlling host device driver attachment. ie whether libvirt
> will manually bind to vfio.ko, or expect the admin to have bound
> it to vfio.ko before hand. I think it is important to keep that
> concept as is for mdev too.

If the managed attribute was used with other devices beside PCI, then sure, we
should keep the concept, however, since only PCI devices support it and now we
have another device type that potentially might have a use for such an
attribute I think it's perfectly reasonable to alter the logic behind that
attribute in favor of the new possibilities to device management which mdev
framework is providing us with which in this case is dynamic creation and
removal of a mediated device.

> 
> While we're thinking of mdev purely in terms of KVM + vfio usage,
> it wouldn't suprise me if there ended up being non-KVM based
> use cases for mdev.
> 
> It isn't clear to me that auto-creation of mdev devices as a concept
> even belongs in the domain XML neccessarily.
> 
> Looking at two similar areas. For SRIOV NICs, in the domain XML
> you either specify an explicit VF to use, or you reference a
> libvirt virtual network. The latter takes care of dynamically
> providing VFs to VMs.  For NPIV, IIRC, the domain XML works
> similarly either taking an explicit vHBA, or referencing a
> storage pool to get one more dynamically.
> 
> Before we even consider auto-creation though, I think we need
> to have manual creation designed & integrated in the node device
> APIs.
> 

Yes, integrating mdev into the nodedev driver this way ^^ is definitely planned.

> So in terms of the domain XML, I think the only think we need
> to provide is the address of the pre-existing mdev device
> to be used. In this case "address" means the UUID. We should
> not need anything about the parent device AFAICT.
> 
> Regards,
> Daniel
> -- 
> |: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
> |: http://libvirt.org  -o- http://virt-manager.org :|
> |: http://entangle-photo.org   -o-http://search.cpan.org/~danberr/ :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] qemuBuildChrChardevStr: Don't leak @charAlias

2017-01-30 Thread Erik Skultety
On Mon, Jan 30, 2017 at 10:28:53AM +0100, Michal Privoznik wrote:
> ==12618== 110 bytes in 10 blocks are definitely lost in loss record 269 of 295
> ==12618==at 0x4C2AE5F: malloc (vg_replace_malloc.c:297)
> ==12618==by 0x1CFC6DD7: vasprintf (vasprintf.c:73)
> ==12618==by 0x1912B2FC: virVasprintfInternal (virstring.c:551)
> ==12618==by 0x1912B411: virAsprintfInternal (virstring.c:572)
> ==12618==by 0x50B1FF: qemuAliasChardevFromDevAlias (qemu_alias.c:638)
> ==12618==by 0x518CCE: qemuBuildChrChardevStr (qemu_command.c:4973)
> ==12618==by 0x522DA0: qemuBuildShmemBackendChrStr (qemu_command.c:8674)
> ==12618==by 0x523209: qemuBuildShmemCommandLine (qemu_command.c:8789)
> ==12618==by 0x526135: qemuBuildCommandLine (qemu_command.c:9843)
> ==12618==by 0x48B4BA: qemuProcessCreatePretendCmd (qemu_process.c:5897)
> ==12618==by 0x4378C9: testCompareXMLToArgv (qemuxml2argvtest.c:498)
> ==12618==by 0x44D5A6: virTestRun (testutils.c:180)
> 
> Signed-off-by: Michal Privoznik 
> ---

ACK

Erik

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [RFC PATCH v2 REBASE 17/18] docs: Document the new hostdev and address type 'mdev'

2017-02-22 Thread Erik Skultety
On Wed, Feb 22, 2017 at 08:20:06PM +0530, Kirti Wankhede wrote:
> 
> 
> On 2/20/2017 7:58 PM, Erik Skultety wrote:
> > Signed-off-by: Erik Skultety <eskul...@redhat.com>
> > ---
> >  docs/formatdomain.html.in | 48 
> > +++
> >  1 file changed, 44 insertions(+), 4 deletions(-)
> > 
> > diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
> > index b69bd4c..13cb767 100644
> > --- a/docs/formatdomain.html.in
> > +++ b/docs/formatdomain.html.in
> > @@ -3277,8 +3277,20 @@
> >  attributes: iobase and irq.
> >  Since 1.2.1
> >
> > +  mdev
> > +  Mediated devices' addresses have so far only one mandatory 
> > attribute
> > +uuid (since 3.1.0) which
> > +uniquely identifies a mediated device under the syfs file system.
> > +  
> >  
> >  
> > +
> > +Note: Due to nature of mediated devices, being only software 
> > devices
> > +defining an allocation of resources on the physical parent device, 
> > the
> > +address type mdev is supposed to be used to identify a
> > +device on the host only, rather than identifying it in the guest.
> > +
> > +
> >  Controllers
> >  
> >  
> > @@ -3774,6 +3786,19 @@
> >/devices
> >...
> >  
> > +or:
> > +
> > +
> > +  ...
> > +  devices
> > +hostdev mode='subsystem' type='mdev' model='vfio-pci'
> > +source
> > +  address type='mdev' 
> > uuid='c2177883-f1bb-47f0-914d-32a22e3a8804'
> > +/source
> > +/hostdev
> > +  /devices
> > +  ...
> > +
> 
> Hi Erik,
> 
> Changes looks good so far. I did some basic testing with these patches.
> I used above example snippet of hostdev element and it throws below
> error. Add a '/' before '' and after uuid in address line.
> 
> error: (domain_definition):74: Opening and ending tag mismatch: address
> line 73 and source
>   
> ---^
> Failed. Try again? [y,n,i,f,?]:
> 
> Thanks,
> Kirti
> 

Oh, right, good catch.

Thanks,
Erik

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 REBASE 11/18] hostdev: Maintain a driver list of active mediated devices

2017-02-20 Thread Erik Skultety
Keep track of the assigned mediated devices the same way we do it for
the rest of hostdevs.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/libvirt_private.syms |   1 +
 src/qemu/qemu_hostdev.c  |  22 ++
 src/qemu/qemu_hostdev.h  |   4 ++
 src/util/virhostdev.c| 176 ++-
 src/util/virhostdev.h|   9 +++
 5 files changed, 211 insertions(+), 1 deletion(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 8af65a1..e6d1282 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1706,6 +1706,7 @@ virHostdevPCINodeDeviceDetach;
 virHostdevPCINodeDeviceReAttach;
 virHostdevPCINodeDeviceReset;
 virHostdevPrepareDomainDevices;
+virHostdevPrepareMediatedDevices;
 virHostdevPreparePCIDevices;
 virHostdevPrepareSCSIDevices;
 virHostdevPrepareSCSIVHostDevices;
diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index 7cd49e4..45b731c 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -305,6 +305,24 @@ qemuHostdevPrepareSCSIVHostDevices(virQEMUDriverPtr driver,
 }
 
 int
+qemuHostdevPrepareMediatedDevices(virQEMUDriverPtr driver,
+  const char *name,
+  virDomainHostdevDefPtr *hostdevs,
+  int nhostdevs)
+{
+virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
+
+if (!qemuHostdevHostSupportsPassthroughVFIO()) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("host doesn't support VFIO PCI interface"));
+return -1;
+}
+
+return virHostdevPrepareMediatedDevices(hostdev_mgr, QEMU_DRIVER_NAME,
+name, hostdevs, nhostdevs);
+}
+
+int
 qemuHostdevPrepareDomainDevices(virQEMUDriverPtr driver,
 virDomainDefPtr def,
 virQEMUCapsPtr qemuCaps,
@@ -330,6 +348,10 @@ qemuHostdevPrepareDomainDevices(virQEMUDriverPtr driver,
def->hostdevs, def->nhostdevs) < 0)
 return -1;
 
+if (qemuHostdevPrepareMediatedDevices(driver, def->name,
+  def->hostdevs, def->nhostdevs) < 0)
+return -1;
+
 return 0;
 }
 
diff --git a/src/qemu/qemu_hostdev.h b/src/qemu/qemu_hostdev.h
index 74a7d4f..9399241 100644
--- a/src/qemu/qemu_hostdev.h
+++ b/src/qemu/qemu_hostdev.h
@@ -59,6 +59,10 @@ int qemuHostdevPrepareSCSIVHostDevices(virQEMUDriverPtr 
driver,
const char *name,
virDomainHostdevDefPtr *hostdevs,
int nhostdevs);
+int qemuHostdevPrepareMediatedDevices(virQEMUDriverPtr driver,
+  const char *name,
+  virDomainHostdevDefPtr *hostdevs,
+  int nhostdevs);
 int qemuHostdevPrepareDomainDevices(virQEMUDriverPtr driver,
 virDomainDefPtr def,
 virQEMUCapsPtr qemuCaps,
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index 86ca8e0..681f720 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -1,6 +1,6 @@
 /* virhostdev.c: hostdev management
  *
- * Copyright (C) 2006-2007, 2009-2016 Red Hat, Inc.
+ * Copyright (C) 2006-2007, 2009-2017 Red Hat, Inc.
  * Copyright (C) 2006 Daniel P. Berrange
  * Copyright (C) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
  *
@@ -147,6 +147,7 @@ virHostdevManagerDispose(void *obj)
 virObjectUnref(hostdevMgr->activeUSBHostdevs);
 virObjectUnref(hostdevMgr->activeSCSIHostdevs);
 virObjectUnref(hostdevMgr->activeSCSIVHostHostdevs);
+virObjectUnref(hostdevMgr->activeMediatedHostdevs);
 VIR_FREE(hostdevMgr->stateDir);
 }
 
@@ -174,6 +175,9 @@ virHostdevManagerNew(void)
 if (!(hostdevMgr->activeSCSIVHostHostdevs = virSCSIVHostDeviceListNew()))
 goto error;
 
+if (!(hostdevMgr->activeMediatedHostdevs = virMediatedDeviceListNew()))
+goto error;
+
 if (privileged) {
 if (VIR_STRDUP(hostdevMgr->stateDir, HOSTDEV_STATE_DIR) < 0)
 goto error;
@@ -1595,6 +1599,176 @@ virHostdevPrepareSCSIVHostDevices(virHostdevManagerPtr 
mgr,
 return -1;
 }
 
+
+static bool
+virHostdevMediatedDeviceIsUsed(virMediatedDevicePtr dev,
+   virMediatedDeviceListPtr list)
+{
+const char *drvname, *domname;
+virMediatedDevicePtr tmp = NULL;
+
+virObjectLock(list);
+
+if ((tmp = virMediatedDeviceListFind(list, dev))) {
+virMediatedDeviceGetUsedBy(tmp, , );
+virReportError(VIR_ERR_OPERATION_INVALID,
+   _("Mediated device %s is in use by "
+ "driver %s, domain %s")

[libvirt] [RFC PATCH v2 REBASE 18/18] news: Update the NEWS.xml about the new mdev feature

2017-02-20 Thread Erik Skultety
Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 docs/news.xml | 9 +
 1 file changed, 9 insertions(+)

diff --git a/docs/news.xml b/docs/news.xml
index 8d53e07..5523f29 100644
--- a/docs/news.xml
+++ b/docs/news.xml
@@ -62,6 +62,15 @@
   strong encryption and doesn't require any extra network connection
   other than what's required for remote access of libvirtd.
 
+
+  qemu: add mediated devices framework support
+
+
+  With the upcomming kernel changes which introduce the new mediated
+  device framework, provide an initial support of this framework into
+  libvirt, mainly introduce new device type as well as an address type
+  in the XML.
+
   
   
 
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 REBASE 01/18] util: Introduce new module virmdev

2017-02-20 Thread Erik Skultety
Beside creation, disposal, getter, and setter methods the module exports
methods to work with lists of mediated devices.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 po/POTFILES.in   |   1 +
 src/Makefile.am  |   1 +
 src/libvirt_private.syms |  18 +++
 src/util/virmdev.c   | 358 +++
 src/util/virmdev.h   |  93 
 5 files changed, 471 insertions(+)
 create mode 100644 src/util/virmdev.c
 create mode 100644 src/util/virmdev.h

diff --git a/po/POTFILES.in b/po/POTFILES.in
index 9f66697..c857211 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -218,6 +218,7 @@ src/util/virlease.c
 src/util/virlockspace.c
 src/util/virlog.c
 src/util/virmacmap.c
+src/util/virmdev.c
 src/util/virnetdev.c
 src/util/virnetdevbandwidth.c
 src/util/virnetdevbridge.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 46ca272..7bc2d3b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -188,6 +188,7 @@ UTIL_SOURCES =  
\
util/virvhba.c util/virvhba.h   \
util/virxdrdefs.h   \
util/virxml.c util/virxml.h \
+   util/virmdev.c util/virmdev.h   \
$(NULL)
 
 EXTRA_DIST += $(srcdir)/util/keymaps.csv $(srcdir)/util/virkeycode-mapgen.py
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index e6ccd69..8af65a1 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1959,6 +1959,24 @@ virMacMapNew;
 virMacMapRemove;
 virMacMapWriteFile;
 
+# util/virmdev.h
+virMediatedDeviceFree;
+virMediatedDeviceGetDeviceAPI;
+virMediatedDeviceGetIOMMUGroupDev;
+virMediatedDeviceGetPath;
+virMediatedDeviceGetUsedBy;
+virMediatedDeviceListAdd;
+virMediatedDeviceListCount;
+virMediatedDeviceListDel;
+virMediatedDeviceListFind;
+virMediatedDeviceListGet;
+virMediatedDeviceListNew;
+virMediatedDeviceListSteal;
+virMediatedDeviceListStealIndex;
+virMediatedDeviceNew;
+virMediatedDeviceSetUsedBy;
+
+
 
 # util/virnetdev.h
 virNetDevAddMulti;
diff --git a/src/util/virmdev.c b/src/util/virmdev.c
new file mode 100644
index 000..9c80647
--- /dev/null
+++ b/src/util/virmdev.c
@@ -0,0 +1,358 @@
+/*
+ * virmdev.c: helper APIs for managing host MDEV devices
+ *
+ * Copyright (C) 2017-2018 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "virmdev.h"
+#include "dirname.h"
+#include "virlog.h"
+#include "viralloc.h"
+#include "vircommand.h"
+#include "virerror.h"
+#include "virfile.h"
+#include "virkmod.h"
+#include "virstring.h"
+#include "virutil.h"
+#include "viruuid.h"
+#include "virhostdev.h"
+
+VIR_LOG_INIT("util.mdev");
+
+struct _virMediatedDevice {
+char *path; /* sysfs path */
+
+char *used_by_drvname;
+char *used_by_domname;
+};
+
+struct _virMediatedDeviceList {
+virObjectLockable parent;
+
+size_t count;
+virMediatedDevicePtr *devs;
+};
+
+
+/* For virReportOOMError()  and virReportSystemError() */
+#define VIR_FROM_THIS VIR_FROM_NONE
+
+static virClassPtr virMediatedDeviceListClass;
+
+static void virMediatedDeviceListDispose(void *obj);
+
+static int virMediatedOnceInit(void)
+{
+if (!(virMediatedDeviceListClass = virClassNew(virClassForObjectLockable(),
+   "virMediatedDeviceList",
+   
sizeof(virMediatedDeviceList),
+   
virMediatedDeviceListDispose)))
+return -1;
+
+return 0;
+}
+
+VIR_ONCE_GLOBAL_INIT(virMediated)
+
+#ifdef __linux__
+# define MDEV_SYSFS_DEVICES "/sys/bus/mdev/devices/"
+
+virMediatedDevicePtr
+virMediatedDeviceNew(const char *uuidstr)
+{
+virMediatedDevicePtr dev = NULL, ret = NULL;
+
+if (VIR_ALLOC(dev) < 0)
+return NULL;
+
+if (virAsprintf(>path, MDEV_SYSFS_DEVICES "%s", uuidstr) < 0)
+   goto cleanup;
+
+  

[libvirt] [RFC PATCH v2 REBASE 03/18] conf: Introduce new address type mdev

2017-02-20 Thread Erik Skultety
Since the address element is much easier extendible by attributes adding
more and more elements, starting with , to the  element
once we find out we need more data to identify a mediated device. By
introducing a new address type rather than using plain elements, we also
remain consistent with all other devices that can make use of the
address element.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/conf/device_conf.h |  1 +
 src/conf/domain_conf.c | 11 +--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h
index f435fb5..8b67208 100644
--- a/src/conf/device_conf.h
+++ b/src/conf/device_conf.h
@@ -47,6 +47,7 @@ typedef enum {
 VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO,
 VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA,
 VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM,
+VIR_DOMAIN_DEVICE_ADDRESS_TYPE_MDEV,
 
 VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST
 } virDomainDeviceAddressType;
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 83aa15f..947a902 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -259,7 +259,8 @@ VIR_ENUM_IMPL(virDomainDeviceAddress, 
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST,
   "ccw",
   "virtio-mmio",
   "isa",
-  "dimm")
+  "dimm",
+  "mdev")
 
 VIR_ENUM_IMPL(virDomainDiskDevice, VIR_DOMAIN_DISK_DEVICE_LAST,
   "disk",
@@ -3290,6 +3291,7 @@ int virDomainDeviceAddressIsValid(virDomainDeviceInfoPtr 
info,
 return virDomainDeviceCCWAddressIsValid(>addr.ccw);
 
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB:
+case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_MDEV:
 return 1;
 }
 
@@ -3382,6 +3384,7 @@ virDomainDeviceInfoAddressIsEqual(const 
virDomainDeviceInfo *a,
 /* address types below don't have any specific data */
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO:
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390:
+case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_MDEV:
 break;
 
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
@@ -5130,7 +5133,8 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
 }
 
 if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE ||
-info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390)
+info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390 ||
+info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_MDEV)
 return 0;
 
 /* We'll be in domain/devices/[device type]/ so 3 level indent */
@@ -5213,6 +5217,7 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
 break;
 
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390:
+case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_MDEV:
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
 break;
@@ -5774,6 +5779,7 @@ virDomainDeviceInfoParseXML(xmlNodePtr node,
 goto cleanup;
 break;
 
+case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_MDEV:
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
 break;
@@ -18546,6 +18552,7 @@ 
virDomainDeviceInfoCheckABIStability(virDomainDeviceInfoPtr src,
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390:
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW:
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO:
+case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_MDEV:
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
 break;
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 REBASE 10/18] qemu: Assign PCI addresses for mediated devices as well

2017-02-20 Thread Erik Skultety
So far, the official support is for x86_64 arch guests so unless a
different device API than vfio-pci is available let's only turn on
support for PCI address assignment. Once a different device API is
introduced, we can enable another address type easily.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/qemu/qemu_domain.h |  1 +
 src/qemu/qemu_domain_address.c | 16 
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 8ba807c..8d51bb8 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -34,6 +34,7 @@
 # include "qemu_agent.h"
 # include "qemu_conf.h"
 # include "qemu_capabilities.h"
+# include "virmdev.h"
 # include "virchrdev.h"
 # include "virobject.h"
 # include "logging/log_manager.h"
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 5b75044..cacd131 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -618,9 +618,11 @@ 
qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
 virPCIDeviceAddressPtr hostAddr = >source.subsys.u.pci.addr;
 
 if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
-hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) 
{
+(hostdev->source.subsys.type !=
+ VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
+ hostdev->source.subsys.type !=
+ VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV))
 return 0;
-}
 
 if (pciFlags == pcieFlags) {
 /* This arch/qemu only supports legacy PCI, so there
@@ -642,6 +644,9 @@ 
qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
 return pcieFlags;
 }
 
+if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV)
+return pcieFlags;
+
 if (!(pciDev = virPCIDeviceNew(hostAddr->domain,
hostAddr->bus,
hostAddr->slot,
@@ -1725,12 +1730,15 @@ qemuDomainAssignDevicePCISlots(virDomainDefPtr def,
 
 /* Host PCI devices */
 for (i = 0; i < def->nhostdevs; i++) {
+virDomainHostdevSubsysPtr subsys = >hostdevs[i]->source.subsys;
 if (!virDeviceInfoPCIAddressWanted(def->hostdevs[i]->info))
 continue;
 if (def->hostdevs[i]->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
 continue;
-if (def->hostdevs[i]->source.subsys.type != 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
-def->hostdevs[i]->source.subsys.type != 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST)
+if (subsys->type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
+subsys->type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST &&
+!(subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV &&
+  subsys->u.mdev.model == VIR_MDEV_MODEL_TYPE_VFIO_PCI))
 continue;
 
 if (qemuDomainPCIAddressReserveNextAddr(addrs,
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 REBASE 17/18] docs: Document the new hostdev and address type 'mdev'

2017-02-20 Thread Erik Skultety
Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 docs/formatdomain.html.in | 48 +++
 1 file changed, 44 insertions(+), 4 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index b69bd4c..13cb767 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -3277,8 +3277,20 @@
 attributes: iobase and irq.
 Since 1.2.1
   
+  mdev
+  Mediated devices' addresses have so far only one mandatory attribute
+uuid (since 3.1.0) which
+uniquely identifies a mediated device under the syfs file system.
+  
 
 
+
+Note: Due to nature of mediated devices, being only software devices
+defining an allocation of resources on the physical parent device, the
+address type mdev is supposed to be used to identify a
+device on the host only, rather than identifying it in the guest.
+
+
 Controllers
 
 
@@ -3774,6 +3786,19 @@
   /devices
   ...
 
+or:
+
+
+  ...
+  devices
+hostdev mode='subsystem' type='mdev' model='vfio-pci'
+source
+  address type='mdev' uuid='c2177883-f1bb-47f0-914d-32a22e3a8804'
+/source
+/hostdev
+  /devices
+  ...
+
 
   hostdev
   The hostdev element is the main container for describing
@@ -3818,12 +3843,23 @@
 type passes all LUNs presented by a single HBA to
 the guest.
   
+  mdev
+  For mediated devices (Since 3.1.0)
+  the model attribute specifies the device API which
+  determines how the host's vfio driver will expose the device to the
+  guest. Currently, only vfio-pci model is supported.
+  The model also has implications on the guest's address type, i.e.
+  for vfio-pci device API any address type other than PCI
+  will result in an error.
+  
 
 
-  Note: The managed attribute is only used with PCI 
devices
-  and is ignored by all the other device types, thus setting
-  managed explicitly with other than PCI device has the 
same
-  effect as omitting it.
+  Note: The managed attribute is only used with PCI and is
+  ignored by all the other device types, thus setting
+  managed explicitly with other than a PCI device has the
+  same effect as omitting it. Similarly, model attribute 
is
+  only supported by mediated devices and ignored by all other device
+  types.
 
   
   source
@@ -3888,6 +3924,10 @@
 is the vhost_scsi wwpn (16 hexadecimal digits with a prefix of
 "naa.") established in the host configfs.
   
+  mdev
+  Mediated devices (Since 3.1.0) are
+  described by the address element.
+  
 
   
   vendor, product
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 REBASE 05/18] conf: Introduce virDomainHostdevDefPostParse

2017-02-20 Thread Erik Skultety
Just to make the code a bit cleaner, move hostdev specific post parse
code to its own function just in case it grows in the future.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/conf/domain_conf.c | 76 +++---
 1 file changed, 48 insertions(+), 28 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 3aee8b6..522553c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -4208,6 +4208,51 @@ virDomainHostdevAssignAddress(virDomainXMLOptionPtr 
xmlopt,
 
 
 static int
+virDomainHostdevDefPostParse(virDomainHostdevDefPtr dev,
+ const virDomainDef *def,
+ virDomainXMLOptionPtr xmlopt)
+{
+if (dev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
+return 0;
+
+switch (dev->source.subsys.type) {
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI:
+if (dev->info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
+virDomainHostdevAssignAddress(xmlopt, def, dev) < 0) {
+virReportError(VIR_ERR_XML_ERROR, "%s",
+   _("Cannot assign SCSI host device address"));
+return -1;
+} else {
+/* Ensure provided address doesn't conflict with existing
+ * scsi disk drive address
+ */
+virDomainDeviceDriveAddressPtr addr = >info->addr.drive;
+if (virDomainDriveAddressIsUsedByDisk(def,
+  VIR_DOMAIN_DISK_BUS_SCSI,
+  addr)) {
+virReportError(VIR_ERR_XML_ERROR,
+   _("SCSI host address controller='%u' "
+ "bus='%u' target='%u' unit='%u' in "
+ "use by a SCSI disk"),
+   addr->controller, addr->bus,
+   addr->target, addr->unit);
+return -1;
+}
+}
+break;
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST:
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
+break;
+}
+
+return 0;
+}
+
+
+static int
 virDomainDeviceDefPostParseInternal(virDomainDeviceDefPtr dev,
 const virDomainDef *def,
 virCapsPtr caps ATTRIBUTE_UNUSED,
@@ -4288,34 +4333,9 @@ 
virDomainDeviceDefPostParseInternal(virDomainDeviceDefPtr dev,
 video->vram = VIR_ROUND_UP_POWER_OF_TWO(video->vram);
 }
 
-if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
-virDomainHostdevDefPtr hdev = dev->data.hostdev;
-
-if (virHostdevIsSCSIDevice(hdev)) {
-if (hdev->info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
-virDomainHostdevAssignAddress(xmlopt, def, hdev) < 0) {
-virReportError(VIR_ERR_XML_ERROR, "%s",
-   _("Cannot assign SCSI host device address"));
-return -1;
-} else {
-/* Ensure provided address doesn't conflict with existing
- * scsi disk drive address
- */
-virDomainDeviceDriveAddressPtr addr = >info->addr.drive;
-if (virDomainDriveAddressIsUsedByDisk(def,
-  VIR_DOMAIN_DISK_BUS_SCSI,
-  addr)) {
-virReportError(VIR_ERR_XML_ERROR,
-   _("SCSI host address controller='%u' "
- "bus='%u' target='%u' unit='%u' in "
- "use by a SCSI disk"),
-   addr->controller, addr->bus,
-   addr->target, addr->unit);
-return -1;
-}
-}
-}
-}
+if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV &&
+virDomainHostdevDefPostParse(dev->data.hostdev, def, xmlopt) < 0)
+return -1;
 
 if (dev->type == VIR_DOMAIN_DEVICE_CONTROLLER) {
 virDomainControllerDefPtr cdev = dev->data.controller;
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 REBASE 09/18] conf: Enable cold-plug of a mediated device

2017-02-20 Thread Erik Skultety
This merely introduces virDomainHostdevMatchSubsysMediatedDev method that
is supposed to check whether device being cold-plugged does not already
exist in the domain configuration.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/conf/domain_conf.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 1fdab6a..3df7576 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -14273,6 +14273,19 @@ 
virDomainHostdevMatchSubsysSCSIiSCSI(virDomainHostdevDefPtr first,
 }
 
 static int
+virDomainHostdevMatchSubsysMediatedDev(virDomainHostdevDefPtr a,
+   virDomainHostdevDefPtr b)
+{
+virDomainHostdevSubsysMediatedDevPtr src_a = >source.subsys.u.mdev;
+virDomainHostdevSubsysMediatedDevPtr src_b = >source.subsys.u.mdev;
+
+if (STREQ(src_a->uuidstr, src_b->uuidstr))
+return 1;
+
+return 0;
+}
+
+static int
 virDomainHostdevMatchSubsys(virDomainHostdevDefPtr a,
 virDomainHostdevDefPtr b)
 {
@@ -14303,6 +14316,7 @@ virDomainHostdevMatchSubsys(virDomainHostdevDefPtr a,
 else
 return 0;
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+return virDomainHostdevMatchSubsysMediatedDev(a, b);
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 return 0;
 }
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 REBASE 16/18] test: Add some test cases for our test suite regarding the mdevs

2017-02-20 Thread Erik Skultety
For now, these only cover the unmanaged, i.e. user pre-created devices.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 .../qemuxml2argv-hostdev-mdev-unmanaged.args   | 25 ++
 .../qemuxml2argv-hostdev-mdev-unmanaged.xml| 37 
 tests/qemuxml2argvtest.c   |  6 
 .../qemuxml2xmlout-hostdev-mdev-unmanaged.xml  | 40 ++
 tests/qemuxml2xmltest.c|  1 +
 5 files changed, 109 insertions(+)
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.args
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.xml
 create mode 100644 
tests/qemuxml2xmloutdata/qemuxml2xmlout-hostdev-mdev-unmanaged.xml

diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.args 
b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.args
new file mode 100644
index 000..fdefeb6
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.args
@@ -0,0 +1,25 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/home/test \
+USER=test \
+LOGNAME=test \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu \
+-name QEMUGuest2 \
+-S \
+-M pc \
+-m 214 \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
+-nographic \
+-nodefconfig \
+-nodefaults \
+-monitor unix:/tmp/lib/domain--1-QEMUGuest2/monitor.sock,server,nowait \
+-no-acpi \
+-boot c \
+-usb \
+-drive file=/dev/HostVG/QEMUGuest2,format=raw,if=none,id=drive-ide0-0-0 \
+-device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \
+-device vfio-pci,\
+sysfsdev=/sys/bus/mdev/devices/53764d0e-85a0-42b4-af5c-2046b460b1dc,bus=pci.0,\
+addr=0x3
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.xml 
b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.xml
new file mode 100644
index 000..144b769
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.xml
@@ -0,0 +1,37 @@
+
+  QEMUGuest2
+  c7a5fdbd-edaf-9455-926a-d65c16db1809
+  219136
+  219136
+  1
+  
+hvm
+
+  
+  
+  destroy
+  restart
+  destroy
+  
+/usr/bin/qemu
+
+  
+  
+  
+  
+
+
+
+
+
+
+
+
+
+  
+
+  
+
+
+  
+
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index f55b04b..0740ba3 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1475,6 +1475,12 @@ mymain(void)
 DO_TEST("hostdev-vfio-multidomain",
 QEMU_CAPS_NODEFCONFIG,
 QEMU_CAPS_DEVICE_VFIO_PCI, QEMU_CAPS_HOST_PCI_MULTIDOMAIN);
+DO_TEST("hostdev-mdev-unmanaged",
+QEMU_CAPS_NODEFCONFIG,
+QEMU_CAPS_DEVICE_VFIO_PCI);
+DO_TEST_PARSE_ERROR("hostdev-mdev-unmanaged-no-uuid",
+QEMU_CAPS_NODEFCONFIG,
+QEMU_CAPS_DEVICE_VFIO_PCI);
 DO_TEST_FAILURE("hostdev-vfio-multidomain",
 QEMU_CAPS_NODEFCONFIG, QEMU_CAPS_DEVICE_VFIO_PCI);
 DO_TEST("pci-rom",
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-hostdev-mdev-unmanaged.xml 
b/tests/qemuxml2xmloutdata/qemuxml2xmlout-hostdev-mdev-unmanaged.xml
new file mode 100644
index 000..55f19c4
--- /dev/null
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-hostdev-mdev-unmanaged.xml
@@ -0,0 +1,40 @@
+
+  QEMUGuest2
+  c7a5fdbd-edaf-9455-926a-d65c16db1809
+  219136
+  219136
+  1
+  
+hvm
+
+  
+  
+  destroy
+  restart
+  destroy
+  
+/usr/bin/qemu
+
+  
+  
+  
+  
+
+
+  
+
+
+
+  
+
+
+
+
+  
+
+  
+  
+
+
+  
+
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 0702f58..fbb5192 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -550,6 +550,7 @@ mymain(void)
 DO_TEST("hostdev-usb-address", NONE);
 DO_TEST("hostdev-pci-address", NONE);
 DO_TEST("hostdev-vfio", NONE);
+DO_TEST("hostdev-mdev-unmanaged", NONE);
 DO_TEST("pci-rom", NONE);
 DO_TEST("pci-serial-dev-chardev", NONE);
 
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 REBASE 12/18] hostdev: Introduce a reattach method for mediated devices

2017-02-20 Thread Erik Skultety
The name "reattach" does not really reflect the truth behind mediated
devices, since these are purely software devices that do not need to be
plugged back into the host in any way, however this patch pushes for
naming consistency for methods where the logic behind the underlying
operation stays the same except that in case of mdevs the operation
itself is effectively a NO-OP.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/libvirt_private.syms |  1 +
 src/qemu/qemu_hostdev.c  | 15 ++
 src/qemu/qemu_hostdev.h  |  4 
 src/util/virhostdev.c| 53 
 src/util/virhostdev.h|  7 +++
 5 files changed, 80 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index e6d1282..f2e1a74 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1712,6 +1712,7 @@ virHostdevPrepareSCSIDevices;
 virHostdevPrepareSCSIVHostDevices;
 virHostdevPrepareUSBDevices;
 virHostdevReAttachDomainDevices;
+virHostdevReAttachMediatedDevices;
 virHostdevReAttachPCIDevices;
 virHostdevReAttachSCSIDevices;
 virHostdevReAttachSCSIVHostDevices;
diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index 45b731c..6a7232f 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -419,6 +419,18 @@ qemuHostdevReAttachSCSIVHostDevices(virQEMUDriverPtr 
driver,
 }
 
 void
+qemuHostdevReAttachMediatedDevices(virQEMUDriverPtr driver,
+   const char *name,
+   virDomainHostdevDefPtr *hostdevs,
+   int nhostdevs)
+{
+virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
+
+virHostdevReAttachMediatedDevices(hostdev_mgr, QEMU_DRIVER_NAME,
+  name, hostdevs, nhostdevs);
+}
+
+void
 qemuHostdevReAttachDomainDevices(virQEMUDriverPtr driver,
  virDomainDefPtr def)
 {
@@ -436,4 +448,7 @@ qemuHostdevReAttachDomainDevices(virQEMUDriverPtr driver,
 
 qemuHostdevReAttachSCSIVHostDevices(driver, def->name, def->hostdevs,
 def->nhostdevs);
+
+qemuHostdevReAttachMediatedDevices(driver, def->name, def->hostdevs,
+   def->nhostdevs);
 }
diff --git a/src/qemu/qemu_hostdev.h b/src/qemu/qemu_hostdev.h
index 9399241..0096497 100644
--- a/src/qemu/qemu_hostdev.h
+++ b/src/qemu/qemu_hostdev.h
@@ -84,6 +84,10 @@ void qemuHostdevReAttachSCSIVHostDevices(virQEMUDriverPtr 
driver,
  const char *name,
  virDomainHostdevDefPtr *hostdevs,
  int nhostdevs);
+void qemuHostdevReAttachMediatedDevices(virQEMUDriverPtr driver,
+const char *name,
+virDomainHostdevDefPtr *hostdevs,
+int nhostdevs);
 void qemuHostdevReAttachDomainDevices(virQEMUDriverPtr driver,
   virDomainDefPtr def);
 
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index 681f720..2a43b4d 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -1963,6 +1963,59 @@ virHostdevReAttachSCSIVHostDevices(virHostdevManagerPtr 
mgr,
 virObjectUnlock(mgr->activeSCSIVHostHostdevs);
 }
 
+void
+virHostdevReAttachMediatedDevices(virHostdevManagerPtr mgr,
+  const char *drv_name,
+  const char *dom_name,
+  virDomainHostdevDefPtr *hostdevs,
+  int nhostdevs)
+{
+const char *used_by_drvname = NULL;
+const char *used_by_domname = NULL;
+virDomainHostdevDefPtr hostdev = NULL;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = NULL;
+size_t i;
+
+if (nhostdevs == 0)
+return;
+
+virObjectLock(mgr->activeMediatedHostdevs);
+for (i = 0; i < nhostdevs; i++) {
+virMediatedDevicePtr mdev, tmp;
+
+hostdev = hostdevs[i];
+mdevsrc = >source.subsys.u.mdev;
+
+if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
+hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV)
+continue;
+
+if (!(mdev = virMediatedDeviceNew(mdevsrc->uuidstr))) {
+VIR_WARN("Failed to reattach mediated device %s attached to "
+ "domain %s", mdevsrc->uuidstr, dom_name);
+continue;
+}
+
+/* Remove from the list only mdevs assigned to @drv_name/@dom_name */
+
+tmp = virMediatedDeviceListFind(mgr->activeMediatedHostdevs, mdev);
+virMediatedDeviceFree(mdev);
+
+/* skip inactive devices */
+if (!tmp)
+continue;
+
+virMediatedDeviceGetUsedBy(t

[libvirt] [RFC PATCH v2 REBASE 15/18] qemu: Format mdevs on qemu command line

2017-02-20 Thread Erik Skultety
Format the mediated devices on the qemu command line as
-device vfio-pci,sysfsdev='/path/to/device/in/syfs'.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/qemu/qemu_command.c | 49 +
 src/qemu/qemu_command.h |  5 +
 2 files changed, 54 insertions(+)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index f4bcfd4..0532156 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -57,6 +57,7 @@
 #include "virscsi.h"
 #include "virnuma.h"
 #include "virgic.h"
+#include "virmdev.h"
 #if defined(__linux__)
 # include 
 #endif
@@ -5161,6 +5162,35 @@ qemuBuildChrChardevStr(virLogManagerPtr logManager,
 return ret;
 }
 
+char *
+qemuBuildHostdevMediatedDevStr(const virDomainDef *def,
+   virDomainHostdevDefPtr dev,
+   virQEMUCapsPtr qemuCaps)
+{
+virBuffer buf = VIR_BUFFER_INITIALIZER;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
+virMediatedDevicePtr mdev = NULL;
+char *ret = NULL;
+
+if (!(mdev = virMediatedDeviceNew(mdevsrc->uuidstr)))
+goto cleanup;
+
+virBufferAddLit(, "vfio-pci");
+virBufferAsprintf(, ",sysfsdev=%s", virMediatedDeviceGetPath(mdev));
+
+if (qemuBuildDeviceAddressStr(, def, dev->info, qemuCaps) < 0)
+goto cleanup;
+
+if (virBufferCheckError() < 0)
+goto cleanup;
+
+ret = virBufferContentAndReset();
+
+ cleanup:
+virBufferFreeAndReset();
+virMediatedDeviceFree(mdev);
+return ret;
+}
 
 static int
 qemuBuildHostdevCommandLine(virCommandPtr cmd,
@@ -5349,6 +5379,25 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd,
 VIR_FREE(devstr);
 }
 }
+
+/* MDEV */
+if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
+subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV) {
+
+if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("VFIO PCI device assignment is not "
+ "supported by this version of qemu"));
+return -1;
+}
+
+virCommandAddArg(cmd, "-device");
+if (!(devstr =
+  qemuBuildHostdevMediatedDevStr(def, hostdev, qemuCaps)))
+return -1;
+virCommandAddArg(cmd, devstr);
+VIR_FREE(devstr);
+}
 }
 
 return 0;
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index 69fe846..b263b87 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -171,6 +171,11 @@ qemuBuildSCSIVHostHostdevDevStr(const virDomainDef *def,
 virQEMUCapsPtr qemuCaps,
 char *vhostfdName);
 
+char *
+qemuBuildHostdevMediatedDevStr(const virDomainDef *def,
+   virDomainHostdevDefPtr dev,
+   virQEMUCapsPtr qemuCaps);
+
 char *qemuBuildRedirdevDevStr(const virDomainDef *def,
   virDomainRedirdevDefPtr dev,
   virQEMUCapsPtr qemuCaps);
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 REBASE 02/18] conf: Introduce new hostdev device type mdev

2017-02-20 Thread Erik Skultety
A mediated device will be identified by a UUID of the user pre-created
mediated device. The data necessary to identify a mediated device can
be easily extended in the future, e.g. when auto-creation of mediated
devices should be enabled.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/conf/domain_conf.c  | 36 +++-
 src/conf/domain_conf.h  |  9 +
 src/qemu/qemu_domain.c  |  1 +
 src/qemu/qemu_hotplug.c |  2 ++
 src/security/security_apparmor.c|  3 +++
 src/security/security_dac.c |  2 ++
 src/security/security_selinux.c |  2 ++
 tests/domaincapsschemadata/full.xml |  1 +
 8 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a56ea82..83aa15f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -56,6 +56,7 @@
 #include "virstring.h"
 #include "virnetdev.h"
 #include "virhostdev.h"
+#include "virmdev.h"
 
 #define VIR_FROM_THIS VIR_FROM_DOMAIN
 
@@ -649,7 +650,8 @@ VIR_ENUM_IMPL(virDomainHostdevSubsys, 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST,
   "usb",
   "pci",
   "scsi",
-  "scsi_host")
+  "scsi_host",
+  "mdev")
 
 VIR_ENUM_IMPL(virDomainHostdevSubsysPCIBackend,
   VIR_DOMAIN_HOSTDEV_PCI_BACKEND_TYPE_LAST,
@@ -668,6 +670,11 @@ VIR_ENUM_IMPL(virDomainHostdevSubsysSCSIHostProtocol,
   "none",
   "vhost")
 
+VIR_ENUM_IMPL(virMediatedDeviceModel,
+  VIR_MDEV_MODEL_TYPE_LAST,
+  "default",
+  "vfio-pci")
+
 VIR_ENUM_IMPL(virDomainHostdevCaps, VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST,
   "storage",
   "misc",
@@ -6349,10 +6356,12 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
 char *sgio = NULL;
 char *rawio = NULL;
 char *backendStr = NULL;
+char *model = NULL;
 int backend;
 int ret = -1;
 virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 
 /* @managed can be read from the xml document - it is always an
  * attribute of the toplevel element, no matter what type of
@@ -6432,6 +6441,21 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
 }
 }
 
+if (model) {
+if (def->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV) {
+virReportError(VIR_ERR_XML_ERROR, "%s",
+   _("model is only supported with mediated devices"));
+goto error;
+}
+
+if ((mdevsrc->model = virMediatedDeviceModelTypeFromString(model)) <= 
0) {
+virReportError(VIR_ERR_XML_ERROR,
+   _("unknown hostdev model '%s'"),
+   model);
+goto error;
+}
+}
+
 switch (def->source.subsys.type) {
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
 if (virDomainHostdevSubsysPCIDefParseXML(sourcenode, def, flags) < 0)
@@ -6464,6 +6488,8 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
 if (virDomainHostdevSubsysSCSIVHostDefParseXML(sourcenode, def) < 0)
 goto error;
 break;
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+break;
 
 default:
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -13297,6 +13323,7 @@ virDomainHostdevDefParseXML(virDomainXMLOptionPtr 
xmlopt,
 }
 break;
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 break;
 }
@@ -14188,6 +14215,7 @@ virDomainHostdevMatchSubsys(virDomainHostdevDefPtr a,
 return 1;
 else
 return 0;
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 return 0;
 }
@@ -23121,6 +23149,7 @@ virDomainHostdevDefFormat(virBufferPtr buf,
 {
 const char *mode = virDomainHostdevModeTypeToString(def->mode);
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 const char *type;
 
 if (!mode) {
@@ -23170,6 +23199,11 @@ virDomainHostdevDefFormat(virBufferPtr buf,
 virBufferAsprintf(buf, " rawio='%s'",
   virTristateBoolTypeToString(scsisrc->rawio));
 }
+
+if (def->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV &&
+mdevsrc->model)
+virBufferAsprintf(buf, " model='%s'"

[libvirt] [RFC PATCH v2 REBASE 13/18] qemu: cgroup: Adjust cgroups' logic to allow mediated devices

2017-02-20 Thread Erik Skultety
As goes for all the other hostdev device types, grant the qemu process
access to /dev/vfio/.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/qemu/qemu_domain.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index b905f9a..86db8b7 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -6875,10 +6875,12 @@ qemuDomainGetHostdevPath(virDomainDefPtr def,
 virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
 virDomainHostdevSubsysSCSIVHostPtr hostsrc = 
>source.subsys.u.scsi_host;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 virPCIDevicePtr pci = NULL;
 virUSBDevicePtr usb = NULL;
 virSCSIDevicePtr scsi = NULL;
 virSCSIVHostDevicePtr host = NULL;
+virMediatedDevicePtr mdev = NULL;
 char *tmpPath = NULL;
 bool freeTmpPath = false;
 bool includeVFIO = false;
@@ -6979,6 +6981,16 @@ qemuDomainGetHostdevPath(virDomainDefPtr def,
 }
 
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+if (!(mdev = virMediatedDeviceNew(mdevsrc->uuidstr)))
+goto cleanup;
+
+if (!(tmpPath = virMediatedDeviceGetIOMMUGroupDev(mdev)))
+goto cleanup;
+
+freeTmpPath = true;
+includeVFIO = true;
+perm = VIR_CGROUP_DEVICE_RW;
+break;
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 break;
 }
@@ -7028,6 +7040,7 @@ qemuDomainGetHostdevPath(virDomainDefPtr def,
 virUSBDeviceFree(usb);
 virSCSIDeviceFree(scsi);
 virSCSIVHostDeviceFree(host);
+virMediatedDeviceFree(mdev);
 if (freeTmpPath)
 VIR_FREE(tmpPath);
 return ret;
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 REBASE 08/18] security: selinux: Enable labeling of vfio mediated devices

2017-02-20 Thread Erik Skultety
Label the VFIO IOMMU devices under /dev/vfio/ referenced by the symlinks
in the sysfs (e.g. /sys/class/mdev_bus//iommu_group) which what
qemu actually gets formatted on the command line.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/security/security_selinux.c | 56 +++--
 1 file changed, 54 insertions(+), 2 deletions(-)

diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index e152c72..60bdb1c 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -36,6 +36,7 @@
 #include "virerror.h"
 #include "viralloc.h"
 #include "virlog.h"
+#include "virmdev.h"
 #include "virpci.h"
 #include "virusb.h"
 #include "virscsi.h"
@@ -1686,6 +1687,13 @@ virSecuritySELinuxSetHostLabel(virSCSIVHostDevicePtr dev 
ATTRIBUTE_UNUSED,
 }
 
 static int
+virSecuritySELinuxSetMediatedDevLabel(virMediatedDevicePtr dev 
ATTRIBUTE_UNUSED,
+  const char *file, void *opaque)
+{
+return virSecuritySELinuxSetHostdevLabelHelper(file, opaque);
+}
+
+static int
 virSecuritySELinuxSetHostdevSubsysLabel(virSecurityManagerPtr mgr,
 virDomainDefPtr def,
 virDomainHostdevDefPtr dev,
@@ -1696,7 +1704,9 @@ 
virSecuritySELinuxSetHostdevSubsysLabel(virSecurityManagerPtr mgr,
 virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
 virDomainHostdevSubsysSCSIVHostPtr hostsrc = 
>source.subsys.u.scsi_host;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 virSecuritySELinuxCallbackData data = {.mgr = mgr, .def = def};
+virMediatedDevicePtr mdev = NULL;
 
 int ret = -1;
 
@@ -1782,13 +1792,26 @@ 
virSecuritySELinuxSetHostdevSubsysLabel(virSecurityManagerPtr mgr,
 break;
 }
 
-case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
+char *vfio_dev = NULL;
+if (!(mdev = virMediatedDeviceNew(mdevsrc->uuidstr)))
+goto done;
+
+if (!(vfio_dev = virMediatedDeviceGetIOMMUGroupDev(mdev)))
+goto done;
+
+ret = virSecuritySELinuxSetMediatedDevLabel(mdev, vfio_dev, );
+VIR_FREE(vfio_dev);
+break;
+}
+
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 ret = 0;
 break;
 }
 
  done:
+virMediatedDeviceFree(mdev);
 return ret;
 }
 
@@ -1918,6 +1941,16 @@ virSecuritySELinuxRestoreHostLabel(virSCSIVHostDevicePtr 
dev ATTRIBUTE_UNUSED,
 }
 
 static int
+virSecuritySELinuxRestoreMediatedDevLabel(virMediatedDevicePtr dev 
ATTRIBUTE_UNUSED,
+   const char *file,
+   void *opaque)
+{
+virSecurityManagerPtr mgr = opaque;
+
+return virSecuritySELinuxRestoreFileLabel(mgr, file);
+}
+
+static int
 virSecuritySELinuxRestoreHostdevSubsysLabel(virSecurityManagerPtr mgr,
 virDomainHostdevDefPtr dev,
 const char *vroot)
@@ -1927,6 +1960,7 @@ 
virSecuritySELinuxRestoreHostdevSubsysLabel(virSecurityManagerPtr mgr,
 virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
 virDomainHostdevSubsysSCSIVHostPtr hostsrc = 
>source.subsys.u.scsi_host;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 int ret = -1;
 
 /* Like virSecuritySELinuxRestoreImageLabelInt() for a networked
@@ -2010,7 +2044,25 @@ 
virSecuritySELinuxRestoreHostdevSubsysLabel(virSecurityManagerPtr mgr,
 break;
 }
 
-case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
+char *vfiodev = NULL;
+virMediatedDevicePtr mdev = virMediatedDeviceNew(mdevsrc->uuidstr);
+
+if (!mdev)
+goto done;
+
+if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdev))) {
+virMediatedDeviceFree(mdev);
+goto done;
+}
+
+ret = virSecuritySELinuxRestoreMediatedDevLabel(mdev, vfiodev, mgr);
+
+VIR_FREE(vfiodev);
+virMediatedDeviceFree(mdev);
+break;
+}
+
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 ret = 0;
 break;
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 REBASE 06/18] conf: Add post parse code for mdevs to virDomainHostdevDefPostParse

2017-02-20 Thread Erik Skultety
We need to make sure that if user explicitly provides a guest address
for a mdev device, the address type will be matching the device API
supported on that specific mediated device and error out with an
incorrect XML message.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/conf/domain_conf.c | 18 +-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 522553c..1fdab6a 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -4240,10 +4240,26 @@ virDomainHostdevDefPostParse(virDomainHostdevDefPtr dev,
 }
 }
 break;
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
+int model = dev->source.subsys.u.mdev.model;
+
+if (dev->info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE)
+return 0;
+
+if (model == VIR_MDEV_MODEL_TYPE_VFIO_PCI &&
+dev->info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
+virReportError(VIR_ERR_XML_ERROR,
+   _("Unsupported address type '%s' with mediated "
+ "device model '%s'"),
+   virDomainDeviceAddressTypeToString(dev->info->type),
+   virMediatedDeviceModelTypeToString(model));
+return -1;
+}
+}
+
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST:
-case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 break;
 }
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 REBASE 07/18] security: dac: Enable labeling of vfio mediated devices

2017-02-20 Thread Erik Skultety
Label the VFIO IOMMU devices under /dev/vfio/ referenced by the symlinks
in the sysfs (e.g. /sys/class/mdev_bus//iommu_group) which what
qemu actually gets formatted on the command line.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/security/security_dac.c | 57 +++--
 1 file changed, 55 insertions(+), 2 deletions(-)

diff --git a/src/security/security_dac.c b/src/security/security_dac.c
index ecce1d3..45bd24e 100644
--- a/src/security/security_dac.c
+++ b/src/security/security_dac.c
@@ -33,6 +33,7 @@
 #include "virfile.h"
 #include "viralloc.h"
 #include "virlog.h"
+#include "virmdev.h"
 #include "virpci.h"
 #include "virusb.h"
 #include "virscsi.h"
@@ -856,6 +857,15 @@ virSecurityDACSetHostLabel(virSCSIVHostDevicePtr dev 
ATTRIBUTE_UNUSED,
 
 
 static int
+virSecurityDACSetMediatedDevLabel(virMediatedDevicePtr dev ATTRIBUTE_UNUSED,
+  const char *file,
+  void *opaque)
+{
+return virSecurityDACSetHostdevLabelHelper(file, opaque);
+}
+
+
+static int
 virSecurityDACSetHostdevLabel(virSecurityManagerPtr mgr,
   virDomainDefPtr def,
   virDomainHostdevDefPtr dev,
@@ -867,7 +877,9 @@ virSecurityDACSetHostdevLabel(virSecurityManagerPtr mgr,
 virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
 virDomainHostdevSubsysSCSIVHostPtr hostsrc = 
>source.subsys.u.scsi_host;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 int ret = -1;
+virMediatedDevicePtr mdev = NULL;
 
 if (!priv->dynamicOwnership)
 return 0;
@@ -964,13 +976,26 @@ virSecurityDACSetHostdevLabel(virSecurityManagerPtr mgr,
 break;
 }
 
-case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
+char *vfio_dev = NULL;
+if (!(mdev = virMediatedDeviceNew(mdevsrc->uuidstr)))
+goto done;
+
+if (!(vfio_dev = virMediatedDeviceGetIOMMUGroupDev(mdev)))
+goto done;
+
+ret = virSecurityDACSetMediatedDevLabel(mdev, vfio_dev, );
+VIR_FREE(vfio_dev);
+break;
+}
+
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 ret = 0;
 break;
 }
 
  done:
+virMediatedDeviceFree(mdev);
 return ret;
 }
 
@@ -1018,6 +1043,15 @@ virSecurityDACRestoreHostLabel(virSCSIVHostDevicePtr dev 
ATTRIBUTE_UNUSED,
 return virSecurityDACRestoreFileLabel(priv, file);
 }
 
+static int
+virSecurityDACRestoreMediatedDevLabel(virMediatedDevicePtr dev 
ATTRIBUTE_UNUSED,
+  const char *file,
+  void *opaque)
+{
+virSecurityManagerPtr mgr = opaque;
+virSecurityDACDataPtr priv = virSecurityManagerGetPrivateData(mgr);
+return virSecurityDACRestoreFileLabel(priv, file);
+}
 
 static int
 virSecurityDACRestoreHostdevLabel(virSecurityManagerPtr mgr,
@@ -1032,6 +1066,7 @@ virSecurityDACRestoreHostdevLabel(virSecurityManagerPtr 
mgr,
 virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
 virDomainHostdevSubsysSCSIVHostPtr hostsrc = 
>source.subsys.u.scsi_host;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 int ret = -1;
 
 secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_DAC_NAME);
@@ -1120,7 +1155,25 @@ virSecurityDACRestoreHostdevLabel(virSecurityManagerPtr 
mgr,
 break;
 }
 
-case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
+char *vfiodev = NULL;
+virMediatedDevicePtr mdev = virMediatedDeviceNew(mdevsrc->uuidstr);
+
+if (!mdev)
+goto done;
+
+if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdev))) {
+virMediatedDeviceFree(mdev);
+goto done;
+}
+
+ret = virSecurityDACRestoreMediatedDevLabel(mdev, vfiodev, mgr);
+
+VIR_FREE(vfiodev);
+virMediatedDeviceFree(mdev);
+break;
+}
+
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 ret = 0;
 break;
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 REBASE 00/18] Introduce vGPU mdev framework to libvirt

2017-02-20 Thread Erik Skultety
since the original v2 [1]:
- resolved a few merge conflicts caused by @9d92f533 which refactored out some
duplicate code which eventually lead to dropping patch 14/18 from the original
series due to being unnecessary
- rebased onto fresh HEAD

[1] https://www.redhat.com/archives/libvir-list/2017-February/msg00739.html

Erik Skultety (18):
  util: Introduce new module virmdev
  conf: Introduce new hostdev device type mdev
  conf: Introduce new address type mdev
  conf: Update XML parser, formatter, and RNG schema to support mdev
  conf: Introduce virDomainHostdevDefPostParse
  conf: Add post parse code for mdevs to virDomainHostdevDefPostParse
  security: dac: Enable labeling of vfio mediated devices
  security: selinux: Enable labeling of vfio mediated devices
  conf: Enable cold-plug of a mediated device
  qemu: Assign PCI addresses for mediated devices as well
  hostdev: Maintain a driver list of active mediated devices
  hostdev: Introduce a reattach method for mediated devices
  qemu: cgroup: Adjust cgroups' logic to allow mediated devices
  qemu: Bump the memory locking limit for mdevs as well
  qemu: Format mdevs on qemu command line
  test: Add some test cases for our test suite regarding the mdevs
  docs: Document the new hostdev and address type 'mdev'
  news: Update the NEWS.xml about the new mdev feature

 docs/formatdomain.html.in  |  48 ++-
 docs/news.xml  |   9 +
 docs/schemas/domaincommon.rng  |  26 ++
 po/POTFILES.in |   1 +
 src/Makefile.am|   1 +
 src/conf/device_conf.h |   1 +
 src/conf/domain_conf.c | 203 ++--
 src/conf/domain_conf.h |   9 +
 src/libvirt_private.syms   |  20 ++
 src/qemu/qemu_command.c|  49 +++
 src/qemu/qemu_command.h|   5 +
 src/qemu/qemu_domain.c |  23 +-
 src/qemu/qemu_domain.h |   1 +
 src/qemu/qemu_domain_address.c |  16 +-
 src/qemu/qemu_hostdev.c|  37 +++
 src/qemu/qemu_hostdev.h|   8 +
 src/qemu/qemu_hotplug.c|   2 +
 src/security/security_apparmor.c   |   3 +
 src/security/security_dac.c|  55 
 src/security/security_selinux.c|  54 
 src/util/virhostdev.c  | 229 -
 src/util/virhostdev.h  |  16 +
 src/util/virmdev.c | 358 +
 src/util/virmdev.h |  93 ++
 tests/domaincapsschemadata/full.xml|   1 +
 .../qemuxml2argv-hostdev-mdev-unmanaged.args   |  25 ++
 .../qemuxml2argv-hostdev-mdev-unmanaged.xml|  37 +++
 tests/qemuxml2argvtest.c   |   6 +
 .../qemuxml2xmlout-hostdev-mdev-unmanaged.xml  |  40 +++
 tests/qemuxml2xmltest.c|   1 +
 30 files changed, 1333 insertions(+), 44 deletions(-)
 create mode 100644 src/util/virmdev.c
 create mode 100644 src/util/virmdev.h
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.args
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.xml
 create mode 100644 
tests/qemuxml2xmloutdata/qemuxml2xmlout-hostdev-mdev-unmanaged.xml

-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 REBASE 04/18] conf: Update XML parser, formatter, and RNG schema to support mdev

2017-02-20 Thread Erik Skultety
To keep the domain XML as much platform agnostic as possible, do not
expose an element/attribute which would contain path directly to the
syfs filesystem which the mediated devices are build upon. Instead,
identify each mediated device by a UUID attribute as well as specifying
the device API (e.g. vfio-pci) through the 'model' attribute.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 docs/schemas/domaincommon.rng | 26 ++
 src/conf/domain_conf.c| 50 +++
 2 files changed, 76 insertions(+)

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index c5f1013..7b17a17 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -4019,6 +4019,7 @@
   
   
   
+  
 
   
 
@@ -4169,6 +4170,20 @@
 
   
 
+  
+
+  mdev
+
+
+  
+vfio-pci
+  
+
+
+  
+
+  
+
   
 
   storage
@@ -4327,6 +4342,11 @@
   
 
   
+  
+
+  
+
+  
   
 
   
@@ -4708,6 +4728,12 @@
   
   
 
+
+  
+mdev
+  
+  
+
   
 
   
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 947a902..3aee8b6 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6349,6 +6349,47 @@ virDomainHostdevSubsysSCSIVHostDefParseXML(xmlNodePtr 
sourcenode,
 return ret;
 }
 
+static int
+virDomainHostdevSubsysMediatedDevDefParseXML(virDomainHostdevDefPtr def,
+ xmlXPathContextPtr ctxt)
+{
+int ret = -1;
+unsigned char uuid[VIR_UUID_BUFLEN] = {0};
+char *uuidxml = NULL;
+xmlNodePtr node = NULL;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
+
+if (mdevsrc->model == 0) {
+virReportError(VIR_ERR_XML_ERROR, "%s",
+   _("Missing 'model' attribute for element "));
+goto cleanup;
+}
+
+if (!(node = virXPathNode("./source/address", ctxt))) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("Missing  element"));
+goto cleanup;
+}
+
+if (!(uuidxml = virXMLPropString(node, "uuid"))) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("Missing 'uuid' attribute for element "));
+goto cleanup;
+}
+
+if (virUUIDParse(uuidxml, uuid) < 0) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   "%s",
+   _("Cannot parse uuid attribute of element "));
+goto cleanup;
+}
+
+virUUIDFormat(uuid, mdevsrc->uuidstr);
+ret = 0;
+ cleanup:
+VIR_FREE(uuidxml);
+return ret;
+}
 
 static int
 virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
@@ -6381,6 +6422,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
 
 sgio = virXMLPropString(node, "sgio");
 rawio = virXMLPropString(node, "rawio");
+model = virXMLPropString(node, "model");
 
 /* @type is passed in from the caller rather than read from the
  * xml document, because it is specified in different places for
@@ -6495,6 +6537,8 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
 goto error;
 break;
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+if (virDomainHostdevSubsysMediatedDevDefParseXML(def, ctxt) < 0)
+goto error;
 break;
 
 default:
@@ -6510,6 +6554,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
 VIR_FREE(sgio);
 VIR_FREE(rawio);
 VIR_FREE(backendStr);
+VIR_FREE(model);
 return ret;
 }
 
@@ -21186,6 +21231,7 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf,
 virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
 virDomainHostdevSubsysSCSIVHostPtr hostsrc = 
>source.subsys.u.scsi_host;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 virDomainHostdevSubsysSCSIHostPtr scsihostsrc = >u.host;
 virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc = >u.iscsi;
 
@@ -21290,6 +21336,10 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf,
 break;
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST:
 break;
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+virBufferAsprintf(buf, "\n",
+  mdevsrc->uuidstr);
+break;
 default:
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected hostdev type %d"),
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 REBASE 14/18] qemu: Bump the memory locking limit for mdevs as well

2017-02-20 Thread Erik Skultety
Since mdevs are just another type of VFIO devices, we should increase
the memory locking limit the same way we do for VFIO PCI devices.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/qemu/qemu_domain.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 86db8b7..27f6f17 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -6223,11 +6223,12 @@ qemuDomainRequiresMemLock(virDomainDefPtr def)
 return true;
 
 for (i = 0; i < def->nhostdevs; i++) {
-virDomainHostdevDefPtr dev = def->hostdevs[i];
+virDomainHostdevSubsysPtr subsys = >hostdevs[i]->source.subsys;
 
-if (dev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
-dev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
-dev->source.subsys.u.pci.backend == 
VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO)
+if (def->hostdevs[i]->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
+(subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV ||
+ (subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
+  subsys->u.pci.backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO)))
 return true;
 }
 
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] libvirt-override: fix flags mutually exclusize

2017-02-17 Thread Erik Skultety
On Fri, Feb 17, 2017 at 07:19:25PM +0800, Jie Wang wrote:

Just a nit that we tend to prefix the patch with [libvirt-python] instead of
just [libvirt] so it's absolutely clear which repository you're sending the
patch against and in this case it's a python bindings fix.

> As virDomainGetBlkioParameters is called in 
> libvirt_virDomainSetBlkioParameters,
> it will result in the two flags 'VIR_DOMAIN_AFFECT_LIVE' and 
> 'VIR_DOMAIN_AFFECT_CONFIG'
> are mutually exclusive in libvirt_virDomainSetBlkioParameters, it's 
> unreasonable,
> So ues this patch to fix it.
> 
> Signed-off-by: Jie Wang 
> ---
>  libvirt-override.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/libvirt-override.c b/libvirt-override.c
> index 9e40f00..7bdc09c 100644
> --- a/libvirt-override.c
> +++ b/libvirt-override.c
> @@ -727,7 +727,7 @@ libvirt_virDomainSetBlkioParameters(PyObject *self 
> ATTRIBUTE_UNUSED,
>  }
>  
>  LIBVIRT_BEGIN_ALLOW_THREADS;
> -i_retval = virDomainGetBlkioParameters(domain, NULL, , flags);
> +i_retval = virDomainGetBlkioParameters(domain, NULL, , 0);
>  LIBVIRT_END_ALLOW_THREADS;
>  
>  if (i_retval < 0)
> @@ -743,7 +743,7 @@ libvirt_virDomainSetBlkioParameters(PyObject *self 
> ATTRIBUTE_UNUSED,
>  return PyErr_NoMemory();
>  
>  LIBVIRT_BEGIN_ALLOW_THREADS;
> -i_retval = virDomainGetBlkioParameters(domain, params, , flags);
> +i_retval = virDomainGetBlkioParameters(domain, params, , 0);
>  LIBVIRT_END_ALLOW_THREADS;
>  

IMHO the correct fix would be to get rid of the getters completely as that is
something the python API adds as an 'extra' compared to the plain C API - it
never performed such a check and it never will since it's been done on the
server side for quite some time. So, if someone used the old C API with a new
client and an old server using some unsupported typed params, the old server
would happily interpret all the ones it knew and fail at the first unknown one,
however, there was no rollback involved. Similarly, the python API should behave
exactly the same, irregardless of the correctness of the old server's behaviour.

CC'ing Dan what he thinks about the python API doing some extra checking to
compensate for the old server's behaviour.

Regards,
Erik

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] libvirt-override: fix flags mutually exclusize

2017-02-17 Thread Erik Skultety
On Fri, Feb 17, 2017 at 02:26:21PM +, Daniel P. Berrange wrote:
> On Fri, Feb 17, 2017 at 03:22:12PM +0100, Erik Skultety wrote:
> > On Fri, Feb 17, 2017 at 07:19:25PM +0800, Jie Wang wrote:
> > 
> > Just a nit that we tend to prefix the patch with [libvirt-python] instead of
> > just [libvirt] so it's absolutely clear which repository you're sending the
> > patch against and in this case it's a python bindings fix.
> > 
> > > As virDomainGetBlkioParameters is called in 
> > > libvirt_virDomainSetBlkioParameters,
> > > it will result in the two flags 'VIR_DOMAIN_AFFECT_LIVE' and 
> > > 'VIR_DOMAIN_AFFECT_CONFIG'
> > > are mutually exclusive in libvirt_virDomainSetBlkioParameters, it's 
> > > unreasonable,
> > > So ues this patch to fix it.
> > > 
> > > Signed-off-by: Jie Wang <wangji...@huawei.com>
> > > ---
> > >  libvirt-override.c | 4 ++--
> > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/libvirt-override.c b/libvirt-override.c
> > > index 9e40f00..7bdc09c 100644
> > > --- a/libvirt-override.c
> > > +++ b/libvirt-override.c
> > > @@ -727,7 +727,7 @@ libvirt_virDomainSetBlkioParameters(PyObject *self 
> > > ATTRIBUTE_UNUSED,
> > >  }
> > >  
> > >  LIBVIRT_BEGIN_ALLOW_THREADS;
> > > -i_retval = virDomainGetBlkioParameters(domain, NULL, , 
> > > flags);
> > > +i_retval = virDomainGetBlkioParameters(domain, NULL, , 0);
> > >  LIBVIRT_END_ALLOW_THREADS;
> > >  
> > >  if (i_retval < 0)
> > > @@ -743,7 +743,7 @@ libvirt_virDomainSetBlkioParameters(PyObject *self 
> > > ATTRIBUTE_UNUSED,
> > >  return PyErr_NoMemory();
> > >  
> > >  LIBVIRT_BEGIN_ALLOW_THREADS;
> > > -i_retval = virDomainGetBlkioParameters(domain, params, , 
> > > flags);
> > > +i_retval = virDomainGetBlkioParameters(domain, params, , 0);
> > >  LIBVIRT_END_ALLOW_THREADS;
> > >  
> > 
> > IMHO the correct fix would be to get rid of the getters completely as that 
> > is
> > something the python API adds as an 'extra' compared to the plain C API - it
> > never performed such a check and it never will since it's been done on the
> > server side for quite some time. So, if someone used the old C API with a 
> > new
> > client and an old server using some unsupported typed params, the old server
> > would happily interpret all the ones it knew and fail at the first unknown 
> > one,
> > however, there was no rollback involved. Similarly, the python API should 
> > behave
> > exactly the same, irregardless of the correctness of the old server's 
> > behaviour.
> 
> It isn't that simple - this isn't a mere matter of checking data. The use
> of the getters during the setter method is a fundamental requirement. At
> the C layer we have many distinct data types - eg int, unsigned int,
> long long, unsigned long long, which all map to the same python data
> type.
> 
> When we set the parameters, we have no idea which data VIR_TYPED_PARAM_
> data type to use. You need to thus call the getter to fetch the list of all
> known types parameters & their data types. You now know what C data type to
> convert the python type into.

Noted, thanks for clarification, in that case, there are a few identical
issues with SetNumaParameters, SetMemoryParameters, SetInterfaceParameters,
SetSchedulerParametersFlags, so it would be awesome if we could fix them at the
same time, since we would hit the very same issue you're trying to fix with all
of those. Could you send a v2 fixing all the above-mentioned occurrences?

Erik

> 
> Anyway, the patch above is correct - when calling the getters from a setter,
> the flags parameter should always be zero.
> 
> Regards,
> Daniel
> -- 
> |: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
> |: http://libvirt.org  -o- http://virt-manager.org :|
> |: http://entangle-photo.org   -o-http://search.cpan.org/~danberr/ :|
> 
> --
> libvir-list mailing list
> libvir-list@redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] virfile: Fix virFileExists commentary

2017-02-24 Thread Erik Skultety
Arguably though, function returning only on success is a very
interesting, although quite impractical concept. Also, the errno isn't
and shouldn't be preserved in this case, since the errno can be directly
fed to the virReportSystemError.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
Pushed as trivial.

 src/util/virfile.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/util/virfile.c b/src/util/virfile.c
index 6ba67bf..41cdca9 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -1820,7 +1820,8 @@ virFileIsDir(const char *path)
  * virFileExists: Check for presence of file
  * @path: Path of file to check
  *
- * Returns if the file exists. Preserves errno in case it does not exist.
+ * Returns true if the file exists, false if it doesn't, setting errno
+ * appropriately.
  */
 bool
 virFileExists(const char *path)
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] news: add entries for recent nodedev driver improvements

2017-02-20 Thread Erik Skultety
On Fri, Feb 17, 2017 at 04:53:37PM +0100, Michal Privoznik wrote:
> Signed-off-by: Michal Privoznik 
> ---
>  docs/news.xml | 17 +
>  1 file changed, 17 insertions(+)
> 
> diff --git a/docs/news.xml b/docs/news.xml
> index 54337f782..8d53e0797 100644
> --- a/docs/news.xml
> +++ b/docs/news.xml
> @@ -63,6 +63,23 @@
>other than what's required for remote access of libvirtd.
>  
>
> +  
> +
> +  qemu: add rendernode argument
> +
> +
> +  Add a new attribute 'rendernode' to gl spice element.
> +
> +  
> +  
> +
> +  nodedev: add drm capability
> +
> +
> +  Add a new 'drm' capability for Direct Rendering Manager (DRM)
> +  devices, providing device type information.
> +
> +  
>  
>  
>
> -- 

ACK

Erik

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] Introduce vGPU mdev framework to libvirt

2017-02-15 Thread Erik Skultety
On Wed, Feb 15, 2017 at 09:50:03AM +0100, Martin Polednik wrote:
> On 14/02/17 09:58 -0700, Alex Williamson wrote:
> > On Tue, 14 Feb 2017 16:50:14 +0100
> > Martin Polednik <mpoled...@redhat.com> wrote:
> > 
> > > On 07/02/17 12:29 -0700, Alex Williamson wrote:
> > > >On Tue, 7 Feb 2017 17:26:51 +0100
> > > >Erik Skultety <eskul...@redhat.com> wrote:
> > > >
> > > >> On Mon, Feb 06, 2017 at 09:33:14AM -0700, Alex Williamson wrote:
> > > >> > On Mon,  6 Feb 2017 13:19:42 +0100
> > > >> > Erik Skultety <eskul...@redhat.com> wrote:
> > > >> >
> > > >> > > Finally. It's here. This is the initial suggestion on how libvirt 
> > > >> > > might
> > > >> > > interract with the mdev framework, currently only focussing on the 
> > > >> > > non-managed
> > > >> > > devices, i.e. those pre-created by the user, since that will be 
> > > >> > > revisited once
> > > >> > > we all settled on how the XML should look like, given we might not 
> > > >> > > want to use
> > > >> > > the sysfs path directly as an attribute in the domain XML. My 
> > > >> > > proposal on the
> > > >> > > XML is the following:
> > > >> > >
> > > >> > > 
> > > >> > > 
> > > >> > > 
> > > >> > >  > > >> > > function='0x00'>
> > > >> > > vGPU_UUID
> > > >> > > 
> > > >> > > 
> > > >> > > 
> > > >> > >
> > > >> > > So the mediated device is identified by the physical parent device 
> > > >> > > visible on
> > > >> > > the host and a UUID which allows us to construct the sysfs path by 
> > > >> > > ourselves,
> > > >> > > which we then put on the QEMU's command line.
> > > >> >
> > > >> > Based on your test code, I think you're creating something like this:
> > > >> >
> > > >> > -device 
> > > >> > vfio-pci,sysfsdev=/sys/class/mdev_bus/:00:03.0/53764d0e-85a0-42b4-af5c-2046b460b1dc
> > > >> >
> > > >> > That would explain the need for the parent device address, but that's
> > > >> > an entirely self inflicted requirement.  For a managed="no" 
> > > >> > scenarios,
> > > >> > we shouldn't need the parent, we can get to the mdev device
> > > >> > via /sys/bus/mdev/devices/53764d0e-85a0-42b4-af5c-2046b460b1dc.  So 
> > > >> > it
> > > >>
> > > >> True, for managed="no" would this path be a nice optimization.
> > > >>
> > > >> > seems that the UUID should be the only required source element for
> > > >> > managed="no".
> > > >> >
> > > >> > For managed="yes", it seems like the parent device is still an 
> > > >> > optional
> > > >>
> > > >> The reason I went with the parent address element (and purposely 
> > > >> neglecting the
> > > >> sample mtty driver) was that I assumed any modern mdev capable HW 
> > > >> would be
> > > >> accessible through the PCI bus on the host. Also I wanted to 
> > > >> explicitly hint
> > > >> libvirt as much as possible which parent device a vGPU device instance 
> > > >> should
> > > >> be created on in case there are more than one of them, rather then 
> > > >> scanning
> > > >> sysfs for a suitable parent which actually supports the given vGPU 
> > > >> type.
> > > >>
> > > >> > field.  The most important thing that libvirt needs to know when
> > > >> > creating a mdev device for a VM is the mdev type name.  The parent
> > > >> > device should be an optional field to help higher level management
> > > >> > tools deal with placement of the device for locality or load 
> > > >> > balancing.
> > > >> > Also, we can't assume that the parent device is a PCI device, the
> > > >> > sample mtty driver already breaks this assumption.
> > > >>
> >

Re: [libvirt] [PATCH] docs: document bhyve e1000 support

2017-02-13 Thread Erik Skultety
On Sun, Feb 12, 2017 at 08:44:59PM +0400, Roman Bogorodskiy wrote:
>   Roman Bogorodskiy wrote:
> 
> >  * Add bhyve e1000 support entry to release nodes
>   ^
> Oops, should be 'notes'.
> 
> >  * Update the bhyve driver page with usage sample
> > ---
> >  docs/drvbhyve.html.in | 15 +++
> >  docs/news.xml |  9 +
> >  2 files changed, 24 insertions(+)
> 
> Roman Bogorodskiy

ACK to the patch.

Erik

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 2/3] util: Introduce virFileComparePaths

2017-02-10 Thread Erik Skultety
> > + * Returns 0 if the paths are equal, 1 if they're not or -1 in case of an
> > + * error.
> > + */
> > +int
> > +virFileComparePaths(const char *p1, const char *p2)
> 
> I think this be "virFileCompareResolvedPaths" - change all the places...
>  Better representation than just ComparePaths
> 

Well, having the substring "Resolved" in the name IMHO implies that the paths
to be compared should already by resolved in which case the whole point of the
function doesn't make sense, since you'd simply use STREQ. So for this reason I
prefer just ComparePaths. I really wanted it to be called *Equal but sort of
implies the return type boolean which is inapplicable because of the VIR_STRDUP
:(.

> > +{
> > +int ret = -1;
> > +char *res1, *res2;
> > +
> > +res1 = res2 = NULL;
> > +
> > +/* Assume p1 and p2 are symlinks, so try to resolve and canonicalize 
> > them.
> > + * Canonicalization fails for example on file systems names like 
> > 'proc' or
> > + * 'sysfs', since they're no real paths so fallback to plain string
> > + * comparison.
> > + */
> > +ignore_value(virFileResolveLink(p1, ));
> > +if (!res1 && VIR_STRDUP(res1, p1) < 0)
> > +goto cleanup;
> > +
> > +ignore_value(virFileResolveLink(p2, ));
> > +if (!res2 && VIR_STRDUP(res2, p2) < 0)
> > +goto cleanup;
> > +
> > +if (STREQ_NULLABLE(res1, res2))
> > +ret = 0;
> > +else
> > +ret = 1;
> 
> WHy not return 1 on match, 0 on non match, and -1 on failure that way
> all you have to do is "ret = STREQ_NULLABLE(res1, res2);"... If so
> adjust the returns comments above too.
>

Well, that was my initial thought, the code would look cleaner, I also liked it
more, but then I thought, most of our compare functions use strcmp for
comparison at some point, so I wanted to follow the convention of returning 0
when equal. However, it wasn't until you suggested it that I grep'ed our code 
and found virReadCompareWWN that works exactly the way I'd favour. So, yeah, I
should have gone with my initial gut feeling, I'll adjust this appropriately,
thanks.

Erik

> 
> ACK w/ adjustments.
> 
> > +
> > + cleanup:
> > +VIR_FREE(res1);
> > +VIR_FREE(res2);
> > +return ret;
> > +}
> > diff --git a/src/util/virfile.h b/src/util/virfile.h
> > index 0343acd..5822b29 100644
> > --- a/src/util/virfile.h
> > +++ b/src/util/virfile.h
> > @@ -331,4 +331,6 @@ void virFileFreeACLs(void **acl);
> >  
> >  int virFileCopyACLs(const char *src,
> >  const char *dst);
> > +
> > +int virFileComparePaths(const char *p1, const char *p2);
> >  #endif /* __VIR_FILE_H */
> > 
> 
> --
> libvir-list mailing list
> libvir-list@redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 3/3] storage: Fix checking whether source filesystem is mounted

2017-02-10 Thread Erik Skultety
On Thu, Feb 09, 2017 at 06:05:41PM -0500, John Ferlan wrote:
> 
> 
> On 02/07/2017 09:16 AM, Erik Skultety wrote:
> > Right now, we use simple string comparison both on the source paths
> > (mount's output vs pool's source) and the target (mount's mnt_dir vs
> > pool's target). The problem are symlinks and mount indeed returns
> > symlinks in its output, e.g. /dev/mappper/lvm_symlink. The same goes for
> > the pool's source/target, so in order to successfully compare these two
> > replace plain string comparison with virFileComparePaths which will
> > resolve all symlinks and canonicalize the paths prior to comparison.
> > 
> > Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1417203
> > 
> > Signed-off-by: Erik Skultety <eskul...@redhat.com>
> > ---
> >  src/storage/storage_backend_fs.c | 12 ++--
> >  1 file changed, 10 insertions(+), 2 deletions(-)
> > 
> > diff --git a/src/storage/storage_backend_fs.c 
> > b/src/storage/storage_backend_fs.c
> > index fe4705b..fae1c03 100644
> > --- a/src/storage/storage_backend_fs.c
> > +++ b/src/storage/storage_backend_fs.c
> > @@ -301,6 +301,7 @@ 
> > virStorageBackendFileSystemIsMounted(virStoragePoolObjPtr pool)
> >  FILE *mtab;
> >  struct mntent ent;
> >  char buf[1024];
> > +int rc1, rc2;
> >  
> >  if ((mtab = fopen(_PATH_MOUNTED, "r")) == NULL) {
> >  virReportSystemError(errno,
> > @@ -313,8 +314,15 @@ 
> > virStorageBackendFileSystemIsMounted(virStoragePoolObjPtr pool)
> >  if (!(src = virStorageBackendFileSystemGetPoolSource(pool)))
> >  goto cleanup;
> >  
> > -if (STREQ(ent.mnt_dir, pool->def->target.path) &&
> > -STREQ(ent.mnt_fsname, src)) {
> > +/* compare both mount destinations and sources to be sure the 
> > mounted
> > + * FS pool is really the one we're looking for
> > + */
> > +if ((rc1 = virFileComparePaths(ent.mnt_dir,
> > +   pool->def->target.path)) < 0 ||
> > +(rc2 = virFileComparePaths(ent.mnt_fsname, src)) < 0)
> > +goto cleanup;
> > +
> > +if (rc1 == 0 && rc2 == 0) {
> 
> With changes to previous to return 1 on match, then this gets adjusted
> too...
> 
> ACK - I think you can alter this appropriately

Sure, thanks.

Erik

> 
> John
> >  ret = 1;
> >  goto cleanup;
> >  }
> > 
> 
> --
> libvir-list mailing list
> libvir-list@redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] news: add entries for libxl driver improvements and bug fixes

2017-02-16 Thread Erik Skultety
On Wed, Feb 15, 2017 at 09:31:57PM -0700, Jim Fehlig wrote:
> Signed-off-by: Jim Fehlig 
> ---
> 
> Since news changes are not candidates for backport I assume it is fine
> to include recent libxl improvements and bug fixes in a single commit.
> I can break this up if that assumption is wrong.

Your assumption is absolutely correct, it's preferable to have them in a single
commit in this case.

ACK

Erik

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] Revert "news: fix spelling of tunneled"

2017-02-16 Thread Erik Skultety
On Wed, Feb 15, 2017 at 07:53:40PM -0700, Jim Fehlig wrote:
> Use of 'tunnelled' is over 100x that of 'tunneled' throughout the
> code. Also, the commit providing this news item used 'tunnelled'.
> 

I don't think it matters at all, both should be grammatically correct, it's just
a matter of convention, the former is BrE and while the latter is AmE.

So, you've got an ACK since it's correct, but it's your call whether you
really want to pollute the logs with fixing different correct spellings of a
word in the news file. :)

Erik

> This reverts commit b5ac475f506cd13adab773cebd125a45d3f2ba8d.
> 
> Signed-off-by: Jim Fehlig 
> ---
> 
> Heh, so much for the trivial rule. I'll wait for an ACK on this one.
> 
> Sorry for the chatter...
> 
>  docs/news.xml | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/docs/news.xml b/docs/news.xml
> index 5bca75ea1..b0629b523 100644
> --- a/docs/news.xml
> +++ b/docs/news.xml
> @@ -55,10 +55,10 @@
>
>
>  
> -  libxl: add tunneled migration support
> +  libxl: add tunnelled migration support
>  
>  
> -  Add tunneled migration to libxl driver, which is always capable of
> +  Add tunnelled migration to libxl driver, which is always capable of
>strong encryption and doesn't require any extra network connection
>other than what's required for remote access of libvirtd.
>  
> -- 
> 2.11.0
> 
> --
> libvir-list mailing list
> libvir-list@redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 14.5/18] qemu: Bump the memory locking limit for mdevs as well

2017-02-16 Thread Erik Skultety
Since mdevs are just another type of VFIO devices, we should increase
the memory locking limit the same way we do for VFIO PCI devices.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/qemu/qemu_domain.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index eb86385..bdd687f 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -6222,11 +6222,12 @@ qemuDomainRequiresMemLock(virDomainDefPtr def)
 return true;
 
 for (i = 0; i < def->nhostdevs; i++) {
-virDomainHostdevDefPtr dev = def->hostdevs[i];
+virDomainHostdevSubsysPtr subsys = >hostdevs[i]->source.subsys;
 
-if (dev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
-dev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
-dev->source.subsys.u.pci.backend == 
VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO)
+if (def->hostdevs[i]->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
+(subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV ||
+ (subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
+  subsys->u.pci.backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO)))
 return true;
 }
 
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 03/18] conf: Introduce new address type mdev

2017-02-15 Thread Erik Skultety
Since the address element is much easier extendible by attributes adding
more and more elements, starting with , to the  element
once we find out we need more data to identify a mediated device. By
introducing a new address type rather than using plain elements, we also
remain consistent with all other devices that can make use of the
address element.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/conf/device_conf.h |  1 +
 src/conf/domain_conf.c | 11 +--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h
index f435fb5..8b67208 100644
--- a/src/conf/device_conf.h
+++ b/src/conf/device_conf.h
@@ -47,6 +47,7 @@ typedef enum {
 VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO,
 VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA,
 VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM,
+VIR_DOMAIN_DEVICE_ADDRESS_TYPE_MDEV,
 
 VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST
 } virDomainDeviceAddressType;
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 4911b0b..053f3cb 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -259,7 +259,8 @@ VIR_ENUM_IMPL(virDomainDeviceAddress, 
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST,
   "ccw",
   "virtio-mmio",
   "isa",
-  "dimm")
+  "dimm",
+  "mdev")
 
 VIR_ENUM_IMPL(virDomainDiskDevice, VIR_DOMAIN_DISK_DEVICE_LAST,
   "disk",
@@ -3289,6 +3290,7 @@ int virDomainDeviceAddressIsValid(virDomainDeviceInfoPtr 
info,
 return virDomainDeviceCCWAddressIsValid(>addr.ccw);
 
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB:
+case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_MDEV:
 return 1;
 }
 
@@ -3381,6 +3383,7 @@ virDomainDeviceInfoAddressIsEqual(const 
virDomainDeviceInfo *a,
 /* address types below don't have any specific data */
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO:
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390:
+case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_MDEV:
 break;
 
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
@@ -5129,7 +5132,8 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
 }
 
 if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE ||
-info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390)
+info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390 ||
+info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_MDEV)
 return 0;
 
 /* We'll be in domain/devices/[device type]/ so 3 level indent */
@@ -5212,6 +5216,7 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
 break;
 
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390:
+case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_MDEV:
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
 break;
@@ -5773,6 +5778,7 @@ virDomainDeviceInfoParseXML(xmlNodePtr node,
 goto cleanup;
 break;
 
+case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_MDEV:
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
 break;
@@ -18540,6 +18546,7 @@ 
virDomainDeviceInfoCheckABIStability(virDomainDeviceInfoPtr src,
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390:
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW:
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO:
+case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_MDEV:
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
 break;
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 05/18] conf: Introduce virDomainHostdevDefPostParse

2017-02-15 Thread Erik Skultety
Just to make the code a bit cleaner, move hostdev specific post parse
code to its own function just in case it grows in the future.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/conf/domain_conf.c | 76 +++---
 1 file changed, 48 insertions(+), 28 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 870aec6..151a308 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -4207,6 +4207,51 @@ virDomainHostdevAssignAddress(virDomainXMLOptionPtr 
xmlopt,
 
 
 static int
+virDomainHostdevDefPostParse(virDomainHostdevDefPtr dev,
+ const virDomainDef *def,
+ virDomainXMLOptionPtr xmlopt)
+{
+if (dev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
+return 0;
+
+switch (dev->source.subsys.type) {
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI:
+if (dev->info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
+virDomainHostdevAssignAddress(xmlopt, def, dev) < 0) {
+virReportError(VIR_ERR_XML_ERROR, "%s",
+   _("Cannot assign SCSI host device address"));
+return -1;
+} else {
+/* Ensure provided address doesn't conflict with existing
+ * scsi disk drive address
+ */
+virDomainDeviceDriveAddressPtr addr = >info->addr.drive;
+if (virDomainDriveAddressIsUsedByDisk(def,
+  VIR_DOMAIN_DISK_BUS_SCSI,
+  addr)) {
+virReportError(VIR_ERR_XML_ERROR,
+   _("SCSI host address controller='%u' "
+ "bus='%u' target='%u' unit='%u' in "
+ "use by a SCSI disk"),
+   addr->controller, addr->bus,
+   addr->target, addr->unit);
+return -1;
+}
+}
+break;
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST:
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
+break;
+}
+
+return 0;
+}
+
+
+static int
 virDomainDeviceDefPostParseInternal(virDomainDeviceDefPtr dev,
 const virDomainDef *def,
 virCapsPtr caps ATTRIBUTE_UNUSED,
@@ -4287,34 +4332,9 @@ 
virDomainDeviceDefPostParseInternal(virDomainDeviceDefPtr dev,
 video->vram = VIR_ROUND_UP_POWER_OF_TWO(video->vram);
 }
 
-if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
-virDomainHostdevDefPtr hdev = dev->data.hostdev;
-
-if (virHostdevIsSCSIDevice(hdev)) {
-if (hdev->info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
-virDomainHostdevAssignAddress(xmlopt, def, hdev) < 0) {
-virReportError(VIR_ERR_XML_ERROR, "%s",
-   _("Cannot assign SCSI host device address"));
-return -1;
-} else {
-/* Ensure provided address doesn't conflict with existing
- * scsi disk drive address
- */
-virDomainDeviceDriveAddressPtr addr = >info->addr.drive;
-if (virDomainDriveAddressIsUsedByDisk(def,
-  VIR_DOMAIN_DISK_BUS_SCSI,
-  addr)) {
-virReportError(VIR_ERR_XML_ERROR,
-   _("SCSI host address controller='%u' "
- "bus='%u' target='%u' unit='%u' in "
- "use by a SCSI disk"),
-   addr->controller, addr->bus,
-   addr->target, addr->unit);
-return -1;
-}
-}
-}
-}
+if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV &&
+virDomainHostdevDefPostParse(dev->data.hostdev, def, xmlopt) < 0)
+return -1;
 
 if (dev->type == VIR_DOMAIN_DEVICE_CONTROLLER) {
 virDomainControllerDefPtr cdev = dev->data.controller;
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 09/18] conf: Enable cold-plug of a mediated device

2017-02-15 Thread Erik Skultety
This merely introduces virDomainHostdevMatchSubsysMediatedDev method that
is supposed to check whether device being cold-plugged does not already
exist in the domain configuration.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/conf/domain_conf.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 69874f0..0fcf9f8 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -14267,6 +14267,19 @@ 
virDomainHostdevMatchSubsysSCSIiSCSI(virDomainHostdevDefPtr first,
 }
 
 static int
+virDomainHostdevMatchSubsysMediatedDev(virDomainHostdevDefPtr a,
+   virDomainHostdevDefPtr b)
+{
+virDomainHostdevSubsysMediatedDevPtr src_a = >source.subsys.u.mdev;
+virDomainHostdevSubsysMediatedDevPtr src_b = >source.subsys.u.mdev;
+
+if (STREQ(src_a->uuidstr, src_b->uuidstr))
+return 1;
+
+return 0;
+}
+
+static int
 virDomainHostdevMatchSubsys(virDomainHostdevDefPtr a,
 virDomainHostdevDefPtr b)
 {
@@ -14297,6 +14310,7 @@ virDomainHostdevMatchSubsys(virDomainHostdevDefPtr a,
 else
 return 0;
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+return virDomainHostdevMatchSubsysMediatedDev(a, b);
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 return 0;
 }
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 13/18] qemu: cgroup: Adjust cgroups' logic to allow mediated devices

2017-02-15 Thread Erik Skultety
As goes for all the other hostdev device types, grant the qemu process
access to /dev/vfio/.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/qemu/qemu_cgroup.c | 29 +
 1 file changed, 29 insertions(+)

diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 0902624..bcd10db 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -318,6 +318,23 @@ qemuSetupHostSCSIVHostDeviceCgroup(virSCSIVHostDevicePtr 
dev ATTRIBUTE_UNUSED,
 return ret;
 }
 
+static int
+qemuSetupHostMediatedDeviceCgroup(virMediatedDevicePtr dev ATTRIBUTE_UNUSED,
+  const char *path,
+  void *opaque)
+{
+virDomainObjPtr vm = opaque;
+qemuDomainObjPrivatePtr priv = vm->privateData;
+int ret = -1;
+
+VIR_DEBUG("Process path '%s' for mediated device", path);
+ret = virCgroupAllowDevicePath(priv->cgroup, path,
+   VIR_CGROUP_DEVICE_RW, false);
+virDomainAuditCgroupPath(vm, priv->cgroup, "allow", path, "rw", ret == 0);
+
+return ret;
+}
+
 int
 qemuSetupHostdevCgroup(virDomainObjPtr vm,
virDomainHostdevDefPtr dev)
@@ -328,10 +345,12 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm,
 virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
 virDomainHostdevSubsysSCSIVHostPtr hostsrc = 
>source.subsys.u.scsi_host;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 virPCIDevicePtr pci = NULL;
 virUSBDevicePtr usb = NULL;
 virSCSIDevicePtr scsi = NULL;
 virSCSIVHostDevicePtr host = NULL;
+virMediatedDevicePtr mdev = NULL;
 char *path = NULL;
 
 /* currently this only does something for PCI devices using vfio
@@ -434,6 +453,15 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm,
 }
 
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+if (!(mdev = virMediatedDeviceNew(mdevsrc->uuidstr)))
+goto cleanup;
+
+if (!(path = virMediatedDeviceGetIOMMUGroupDev(mdev)))
+goto cleanup;
+
+if (qemuSetupHostMediatedDeviceCgroup(mdev, path, vm) < 0)
+goto cleanup;
+
 break;
 
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
@@ -447,6 +475,7 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm,
 virUSBDeviceFree(usb);
 virSCSIDeviceFree(scsi);
 virSCSIVHostDeviceFree(host);
+virMediatedDeviceFree(mdev);
 VIR_FREE(path);
 return ret;
 }
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 11/18] hostdev: Maintain a driver list of active mediated devices

2017-02-15 Thread Erik Skultety
Keep track of the assigned mediated devices the same way we do it for
the rest of hostdevs.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/libvirt_private.syms |   1 +
 src/qemu/qemu_hostdev.c  |  22 ++
 src/qemu/qemu_hostdev.h  |   4 ++
 src/util/virhostdev.c| 176 ++-
 src/util/virhostdev.h|   9 +++
 5 files changed, 211 insertions(+), 1 deletion(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 48c86a2..97f81ee 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1709,6 +1709,7 @@ virHostdevPCINodeDeviceDetach;
 virHostdevPCINodeDeviceReAttach;
 virHostdevPCINodeDeviceReset;
 virHostdevPrepareDomainDevices;
+virHostdevPrepareMediatedDevices;
 virHostdevPreparePCIDevices;
 virHostdevPrepareSCSIDevices;
 virHostdevPrepareSCSIVHostDevices;
diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index 7cd49e4..45b731c 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -305,6 +305,24 @@ qemuHostdevPrepareSCSIVHostDevices(virQEMUDriverPtr driver,
 }
 
 int
+qemuHostdevPrepareMediatedDevices(virQEMUDriverPtr driver,
+  const char *name,
+  virDomainHostdevDefPtr *hostdevs,
+  int nhostdevs)
+{
+virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
+
+if (!qemuHostdevHostSupportsPassthroughVFIO()) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("host doesn't support VFIO PCI interface"));
+return -1;
+}
+
+return virHostdevPrepareMediatedDevices(hostdev_mgr, QEMU_DRIVER_NAME,
+name, hostdevs, nhostdevs);
+}
+
+int
 qemuHostdevPrepareDomainDevices(virQEMUDriverPtr driver,
 virDomainDefPtr def,
 virQEMUCapsPtr qemuCaps,
@@ -330,6 +348,10 @@ qemuHostdevPrepareDomainDevices(virQEMUDriverPtr driver,
def->hostdevs, def->nhostdevs) < 0)
 return -1;
 
+if (qemuHostdevPrepareMediatedDevices(driver, def->name,
+  def->hostdevs, def->nhostdevs) < 0)
+return -1;
+
 return 0;
 }
 
diff --git a/src/qemu/qemu_hostdev.h b/src/qemu/qemu_hostdev.h
index 74a7d4f..9399241 100644
--- a/src/qemu/qemu_hostdev.h
+++ b/src/qemu/qemu_hostdev.h
@@ -59,6 +59,10 @@ int qemuHostdevPrepareSCSIVHostDevices(virQEMUDriverPtr 
driver,
const char *name,
virDomainHostdevDefPtr *hostdevs,
int nhostdevs);
+int qemuHostdevPrepareMediatedDevices(virQEMUDriverPtr driver,
+  const char *name,
+  virDomainHostdevDefPtr *hostdevs,
+  int nhostdevs);
 int qemuHostdevPrepareDomainDevices(virQEMUDriverPtr driver,
 virDomainDefPtr def,
 virQEMUCapsPtr qemuCaps,
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index 86ca8e0..681f720 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -1,6 +1,6 @@
 /* virhostdev.c: hostdev management
  *
- * Copyright (C) 2006-2007, 2009-2016 Red Hat, Inc.
+ * Copyright (C) 2006-2007, 2009-2017 Red Hat, Inc.
  * Copyright (C) 2006 Daniel P. Berrange
  * Copyright (C) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
  *
@@ -147,6 +147,7 @@ virHostdevManagerDispose(void *obj)
 virObjectUnref(hostdevMgr->activeUSBHostdevs);
 virObjectUnref(hostdevMgr->activeSCSIHostdevs);
 virObjectUnref(hostdevMgr->activeSCSIVHostHostdevs);
+virObjectUnref(hostdevMgr->activeMediatedHostdevs);
 VIR_FREE(hostdevMgr->stateDir);
 }
 
@@ -174,6 +175,9 @@ virHostdevManagerNew(void)
 if (!(hostdevMgr->activeSCSIVHostHostdevs = virSCSIVHostDeviceListNew()))
 goto error;
 
+if (!(hostdevMgr->activeMediatedHostdevs = virMediatedDeviceListNew()))
+goto error;
+
 if (privileged) {
 if (VIR_STRDUP(hostdevMgr->stateDir, HOSTDEV_STATE_DIR) < 0)
 goto error;
@@ -1595,6 +1599,176 @@ virHostdevPrepareSCSIVHostDevices(virHostdevManagerPtr 
mgr,
 return -1;
 }
 
+
+static bool
+virHostdevMediatedDeviceIsUsed(virMediatedDevicePtr dev,
+   virMediatedDeviceListPtr list)
+{
+const char *drvname, *domname;
+virMediatedDevicePtr tmp = NULL;
+
+virObjectLock(list);
+
+if ((tmp = virMediatedDeviceListFind(list, dev))) {
+virMediatedDeviceGetUsedBy(tmp, , );
+virReportError(VIR_ERR_OPERATION_INVALID,
+   _("Mediated device %s is in use by "
+ "driver %s, domain %s")

[libvirt] [RFC PATCH v2 18/18] news: Update the NEWS.xml about the new mdev feature

2017-02-15 Thread Erik Skultety
Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 docs/news.xml | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/docs/news.xml b/docs/news.xml
index b756a97..55fa5ed 100644
--- a/docs/news.xml
+++ b/docs/news.xml
@@ -53,6 +53,17 @@
   was virtio-net.
 
   
+  
+
+  qemu: add mediated devices framework support
+
+
+  With the upcomming kernel changes which introduce the new mediated
+  device framework, provide an initial support of this framework into
+  libvirt, mainly introduce new device type as well as an address type
+  in the XML.
+
+  
 
 
   
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 01/18] util: Introduce new module virmdev

2017-02-15 Thread Erik Skultety
Beside creation, disposal, getter, and setter methods the module exports
methods to work with lists of mediated devices.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 po/POTFILES.in   |   1 +
 src/Makefile.am  |   1 +
 src/libvirt_private.syms |  18 +++
 src/util/virmdev.c   | 358 +++
 src/util/virmdev.h   |  93 
 5 files changed, 471 insertions(+)
 create mode 100644 src/util/virmdev.c
 create mode 100644 src/util/virmdev.h

diff --git a/po/POTFILES.in b/po/POTFILES.in
index 365ea66..53c674e 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -218,6 +218,7 @@ src/util/virlease.c
 src/util/virlockspace.c
 src/util/virlog.c
 src/util/virmacmap.c
+src/util/virmdev.c
 src/util/virnetdev.c
 src/util/virnetdevbandwidth.c
 src/util/virnetdevbridge.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 2f32d41..6510e1d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -186,6 +186,7 @@ UTIL_SOURCES =  
\
util/viruuid.c util/viruuid.h   \
util/virxdrdefs.h   \
util/virxml.c util/virxml.h \
+   util/virmdev.c util/virmdev.h   \
$(NULL)
 
 EXTRA_DIST += $(srcdir)/util/keymaps.csv $(srcdir)/util/virkeycode-mapgen.py
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 6bbb36b..48c86a2 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1962,6 +1962,24 @@ virMacMapNew;
 virMacMapRemove;
 virMacMapWriteFile;
 
+# util/virmdev.h
+virMediatedDeviceFree;
+virMediatedDeviceGetDeviceAPI;
+virMediatedDeviceGetIOMMUGroupDev;
+virMediatedDeviceGetPath;
+virMediatedDeviceGetUsedBy;
+virMediatedDeviceListAdd;
+virMediatedDeviceListCount;
+virMediatedDeviceListDel;
+virMediatedDeviceListFind;
+virMediatedDeviceListGet;
+virMediatedDeviceListNew;
+virMediatedDeviceListSteal;
+virMediatedDeviceListStealIndex;
+virMediatedDeviceNew;
+virMediatedDeviceSetUsedBy;
+
+
 
 # util/virnetdev.h
 virNetDevAddMulti;
diff --git a/src/util/virmdev.c b/src/util/virmdev.c
new file mode 100644
index 000..9c80647
--- /dev/null
+++ b/src/util/virmdev.c
@@ -0,0 +1,358 @@
+/*
+ * virmdev.c: helper APIs for managing host MDEV devices
+ *
+ * Copyright (C) 2017-2018 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "virmdev.h"
+#include "dirname.h"
+#include "virlog.h"
+#include "viralloc.h"
+#include "vircommand.h"
+#include "virerror.h"
+#include "virfile.h"
+#include "virkmod.h"
+#include "virstring.h"
+#include "virutil.h"
+#include "viruuid.h"
+#include "virhostdev.h"
+
+VIR_LOG_INIT("util.mdev");
+
+struct _virMediatedDevice {
+char *path; /* sysfs path */
+
+char *used_by_drvname;
+char *used_by_domname;
+};
+
+struct _virMediatedDeviceList {
+virObjectLockable parent;
+
+size_t count;
+virMediatedDevicePtr *devs;
+};
+
+
+/* For virReportOOMError()  and virReportSystemError() */
+#define VIR_FROM_THIS VIR_FROM_NONE
+
+static virClassPtr virMediatedDeviceListClass;
+
+static void virMediatedDeviceListDispose(void *obj);
+
+static int virMediatedOnceInit(void)
+{
+if (!(virMediatedDeviceListClass = virClassNew(virClassForObjectLockable(),
+   "virMediatedDeviceList",
+   
sizeof(virMediatedDeviceList),
+   
virMediatedDeviceListDispose)))
+return -1;
+
+return 0;
+}
+
+VIR_ONCE_GLOBAL_INIT(virMediated)
+
+#ifdef __linux__
+# define MDEV_SYSFS_DEVICES "/sys/bus/mdev/devices/"
+
+virMediatedDevicePtr
+virMediatedDeviceNew(const char *uuidstr)
+{
+virMediatedDevicePtr dev = NULL, ret = NULL;
+
+if (VIR_ALLOC(dev) < 0)
+return NULL;
+
+if (virAsprintf(>path, MDEV_SYSFS_DEVICES "%s", uuidstr) < 0)
+   goto cleanup;
+
+  

[libvirt] [RFC PATCH v2 10/18] qemu: Assign PCI addresses for mediated devices as well

2017-02-15 Thread Erik Skultety
So far, the official support is for x86_64 arch guests so unless a
different device API than vfio-pci is available let's only turn on
support for PCI address assignment. Once a different device API is
introduced, we can enable another address type easily.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/qemu/qemu_domain.h |  1 +
 src/qemu/qemu_domain_address.c | 16 
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 524a672..341264b 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -34,6 +34,7 @@
 # include "qemu_agent.h"
 # include "qemu_conf.h"
 # include "qemu_capabilities.h"
+# include "virmdev.h"
 # include "virchrdev.h"
 # include "virobject.h"
 # include "logging/log_manager.h"
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 5b75044..cacd131 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -618,9 +618,11 @@ 
qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
 virPCIDeviceAddressPtr hostAddr = >source.subsys.u.pci.addr;
 
 if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
-hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) 
{
+(hostdev->source.subsys.type !=
+ VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
+ hostdev->source.subsys.type !=
+ VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV))
 return 0;
-}
 
 if (pciFlags == pcieFlags) {
 /* This arch/qemu only supports legacy PCI, so there
@@ -642,6 +644,9 @@ 
qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
 return pcieFlags;
 }
 
+if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV)
+return pcieFlags;
+
 if (!(pciDev = virPCIDeviceNew(hostAddr->domain,
hostAddr->bus,
hostAddr->slot,
@@ -1725,12 +1730,15 @@ qemuDomainAssignDevicePCISlots(virDomainDefPtr def,
 
 /* Host PCI devices */
 for (i = 0; i < def->nhostdevs; i++) {
+virDomainHostdevSubsysPtr subsys = >hostdevs[i]->source.subsys;
 if (!virDeviceInfoPCIAddressWanted(def->hostdevs[i]->info))
 continue;
 if (def->hostdevs[i]->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
 continue;
-if (def->hostdevs[i]->source.subsys.type != 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
-def->hostdevs[i]->source.subsys.type != 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST)
+if (subsys->type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
+subsys->type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST &&
+!(subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV &&
+  subsys->u.mdev.model == VIR_MDEV_MODEL_TYPE_VFIO_PCI))
 continue;
 
 if (qemuDomainPCIAddressReserveNextAddr(addrs,
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 08/18] security: selinux: Enable labeling of vfio mediated devices

2017-02-15 Thread Erik Skultety
Label the VFIO IOMMU devices under /dev/vfio/ referenced by the symlinks
in the sysfs (e.g. /sys/class/mdev_bus//iommu_group) which what
qemu actually gets formatted on the command line.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/security/security_selinux.c | 56 +++--
 1 file changed, 54 insertions(+), 2 deletions(-)

diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index e152c72..60bdb1c 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -36,6 +36,7 @@
 #include "virerror.h"
 #include "viralloc.h"
 #include "virlog.h"
+#include "virmdev.h"
 #include "virpci.h"
 #include "virusb.h"
 #include "virscsi.h"
@@ -1686,6 +1687,13 @@ virSecuritySELinuxSetHostLabel(virSCSIVHostDevicePtr dev 
ATTRIBUTE_UNUSED,
 }
 
 static int
+virSecuritySELinuxSetMediatedDevLabel(virMediatedDevicePtr dev 
ATTRIBUTE_UNUSED,
+  const char *file, void *opaque)
+{
+return virSecuritySELinuxSetHostdevLabelHelper(file, opaque);
+}
+
+static int
 virSecuritySELinuxSetHostdevSubsysLabel(virSecurityManagerPtr mgr,
 virDomainDefPtr def,
 virDomainHostdevDefPtr dev,
@@ -1696,7 +1704,9 @@ 
virSecuritySELinuxSetHostdevSubsysLabel(virSecurityManagerPtr mgr,
 virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
 virDomainHostdevSubsysSCSIVHostPtr hostsrc = 
>source.subsys.u.scsi_host;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 virSecuritySELinuxCallbackData data = {.mgr = mgr, .def = def};
+virMediatedDevicePtr mdev = NULL;
 
 int ret = -1;
 
@@ -1782,13 +1792,26 @@ 
virSecuritySELinuxSetHostdevSubsysLabel(virSecurityManagerPtr mgr,
 break;
 }
 
-case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
+char *vfio_dev = NULL;
+if (!(mdev = virMediatedDeviceNew(mdevsrc->uuidstr)))
+goto done;
+
+if (!(vfio_dev = virMediatedDeviceGetIOMMUGroupDev(mdev)))
+goto done;
+
+ret = virSecuritySELinuxSetMediatedDevLabel(mdev, vfio_dev, );
+VIR_FREE(vfio_dev);
+break;
+}
+
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 ret = 0;
 break;
 }
 
  done:
+virMediatedDeviceFree(mdev);
 return ret;
 }
 
@@ -1918,6 +1941,16 @@ virSecuritySELinuxRestoreHostLabel(virSCSIVHostDevicePtr 
dev ATTRIBUTE_UNUSED,
 }
 
 static int
+virSecuritySELinuxRestoreMediatedDevLabel(virMediatedDevicePtr dev 
ATTRIBUTE_UNUSED,
+   const char *file,
+   void *opaque)
+{
+virSecurityManagerPtr mgr = opaque;
+
+return virSecuritySELinuxRestoreFileLabel(mgr, file);
+}
+
+static int
 virSecuritySELinuxRestoreHostdevSubsysLabel(virSecurityManagerPtr mgr,
 virDomainHostdevDefPtr dev,
 const char *vroot)
@@ -1927,6 +1960,7 @@ 
virSecuritySELinuxRestoreHostdevSubsysLabel(virSecurityManagerPtr mgr,
 virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
 virDomainHostdevSubsysSCSIVHostPtr hostsrc = 
>source.subsys.u.scsi_host;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 int ret = -1;
 
 /* Like virSecuritySELinuxRestoreImageLabelInt() for a networked
@@ -2010,7 +2044,25 @@ 
virSecuritySELinuxRestoreHostdevSubsysLabel(virSecurityManagerPtr mgr,
 break;
 }
 
-case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
+char *vfiodev = NULL;
+virMediatedDevicePtr mdev = virMediatedDeviceNew(mdevsrc->uuidstr);
+
+if (!mdev)
+goto done;
+
+if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdev))) {
+virMediatedDeviceFree(mdev);
+goto done;
+}
+
+ret = virSecuritySELinuxRestoreMediatedDevLabel(mdev, vfiodev, mgr);
+
+VIR_FREE(vfiodev);
+virMediatedDeviceFree(mdev);
+break;
+}
+
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 ret = 0;
 break;
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 02/18] conf: Introduce new hostdev device type mdev

2017-02-15 Thread Erik Skultety
A mediated device will be identified by a UUID of the user pre-created
mediated device. The data necessary to identify a mediated device can
be easily extended in the future, e.g. when auto-creation of mediated
devices should be enabled.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/conf/domain_conf.c  | 36 +++-
 src/conf/domain_conf.h  |  9 +
 src/qemu/qemu_cgroup.c  |  5 +
 src/qemu/qemu_domain.c  |  1 +
 src/qemu/qemu_hotplug.c |  2 ++
 src/security/security_apparmor.c|  3 +++
 src/security/security_dac.c |  2 ++
 src/security/security_selinux.c |  2 ++
 tests/domaincapsschemadata/full.xml |  1 +
 9 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 1bc72a4..4911b0b 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -56,6 +56,7 @@
 #include "virstring.h"
 #include "virnetdev.h"
 #include "virhostdev.h"
+#include "virmdev.h"
 
 #define VIR_FROM_THIS VIR_FROM_DOMAIN
 
@@ -649,7 +650,8 @@ VIR_ENUM_IMPL(virDomainHostdevSubsys, 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST,
   "usb",
   "pci",
   "scsi",
-  "scsi_host")
+  "scsi_host",
+  "mdev")
 
 VIR_ENUM_IMPL(virDomainHostdevSubsysPCIBackend,
   VIR_DOMAIN_HOSTDEV_PCI_BACKEND_TYPE_LAST,
@@ -668,6 +670,11 @@ VIR_ENUM_IMPL(virDomainHostdevSubsysSCSIHostProtocol,
   "none",
   "vhost")
 
+VIR_ENUM_IMPL(virMediatedDeviceModel,
+  VIR_MDEV_MODEL_TYPE_LAST,
+  "default",
+  "vfio-pci")
+
 VIR_ENUM_IMPL(virDomainHostdevCaps, VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST,
   "storage",
   "misc",
@@ -6348,10 +6355,12 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
 char *sgio = NULL;
 char *rawio = NULL;
 char *backendStr = NULL;
+char *model = NULL;
 int backend;
 int ret = -1;
 virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 
 /* @managed can be read from the xml document - it is always an
  * attribute of the toplevel element, no matter what type of
@@ -6431,6 +6440,21 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
 }
 }
 
+if (model) {
+if (def->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV) {
+virReportError(VIR_ERR_XML_ERROR, "%s",
+   _("model is only supported with mediated devices"));
+goto error;
+}
+
+if ((mdevsrc->model = virMediatedDeviceModelTypeFromString(model)) <= 
0) {
+virReportError(VIR_ERR_XML_ERROR,
+   _("unknown hostdev model '%s'"),
+   model);
+goto error;
+}
+}
+
 switch (def->source.subsys.type) {
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
 if (virDomainHostdevSubsysPCIDefParseXML(sourcenode, def, flags) < 0)
@@ -6463,6 +6487,8 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
 if (virDomainHostdevSubsysSCSIVHostDefParseXML(sourcenode, def) < 0)
 goto error;
 break;
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+break;
 
 default:
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -13291,6 +13317,7 @@ virDomainHostdevDefParseXML(virDomainXMLOptionPtr 
xmlopt,
 }
 break;
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 break;
 }
@@ -14182,6 +14209,7 @@ virDomainHostdevMatchSubsys(virDomainHostdevDefPtr a,
 return 1;
 else
 return 0;
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 return 0;
 }
@@ -23105,6 +23133,7 @@ virDomainHostdevDefFormat(virBufferPtr buf,
 {
 const char *mode = virDomainHostdevModeTypeToString(def->mode);
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 const char *type;
 
 if (!mode) {
@@ -23154,6 +23183,11 @@ virDomainHostdevDefFormat(virBufferPtr buf,
 virBufferAsprintf(buf, " rawio='%s'",
   virTristateBoolTypeToString(scsisrc->rawio));
 }
+
+if (def->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV &&
+mdevsrc->model)
+virBuff

[libvirt] [RFC PATCH v2 15/18] qemu: Format mdevs on the qemu command line

2017-02-15 Thread Erik Skultety
Format the mediated devices on the qemu command line as
-device vfio-pci,sysfsdev='/path/to/device/in/syfs'.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/qemu/qemu_command.c | 49 +
 src/qemu/qemu_command.h |  5 +
 2 files changed, 54 insertions(+)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index c00a47a..9c12c21 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -57,6 +57,7 @@
 #include "virscsi.h"
 #include "virnuma.h"
 #include "virgic.h"
+#include "virmdev.h"
 #if defined(__linux__)
 # include 
 #endif
@@ -5161,6 +5162,35 @@ qemuBuildChrChardevStr(virLogManagerPtr logManager,
 return ret;
 }
 
+char *
+qemuBuildHostdevMediatedDevStr(const virDomainDef *def,
+   virDomainHostdevDefPtr dev,
+   virQEMUCapsPtr qemuCaps)
+{
+virBuffer buf = VIR_BUFFER_INITIALIZER;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
+virMediatedDevicePtr mdev = NULL;
+char *ret = NULL;
+
+if (!(mdev = virMediatedDeviceNew(mdevsrc->uuidstr)))
+goto cleanup;
+
+virBufferAddLit(, "vfio-pci");
+virBufferAsprintf(, ",sysfsdev=%s", virMediatedDeviceGetPath(mdev));
+
+if (qemuBuildDeviceAddressStr(, def, dev->info, qemuCaps) < 0)
+goto cleanup;
+
+if (virBufferCheckError() < 0)
+goto cleanup;
+
+ret = virBufferContentAndReset();
+
+ cleanup:
+virBufferFreeAndReset();
+virMediatedDeviceFree(mdev);
+return ret;
+}
 
 static int
 qemuBuildHostdevCommandLine(virCommandPtr cmd,
@@ -5349,6 +5379,25 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd,
 VIR_FREE(devstr);
 }
 }
+
+/* MDEV */
+if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
+subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV) {
+
+if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("VFIO PCI device assignment is not "
+ "supported by this version of qemu"));
+return -1;
+}
+
+virCommandAddArg(cmd, "-device");
+if (!(devstr =
+  qemuBuildHostdevMediatedDevStr(def, hostdev, qemuCaps)))
+return -1;
+virCommandAddArg(cmd, devstr);
+VIR_FREE(devstr);
+}
 }
 
 return 0;
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index 69fe846..b263b87 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -171,6 +171,11 @@ qemuBuildSCSIVHostHostdevDevStr(const virDomainDef *def,
 virQEMUCapsPtr qemuCaps,
 char *vhostfdName);
 
+char *
+qemuBuildHostdevMediatedDevStr(const virDomainDef *def,
+   virDomainHostdevDefPtr dev,
+   virQEMUCapsPtr qemuCaps);
+
 char *qemuBuildRedirdevDevStr(const virDomainDef *def,
   virDomainRedirdevDefPtr dev,
   virQEMUCapsPtr qemuCaps);
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 12/18] hostdev: Introduce a reattach method for mediated devices

2017-02-15 Thread Erik Skultety
The name "reattach" does not really reflect the truth behind mediated
devices, since these are purely software devices that do not need to be
plugged back into the host in any way, however this patch pushes for
naming consistency for methods where the logic behind the underlying
operation stays the same except that in case of mdevs the operation
itself is effectively a NO-OP.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/libvirt_private.syms |  1 +
 src/qemu/qemu_hostdev.c  | 15 ++
 src/qemu/qemu_hostdev.h  |  4 
 src/util/virhostdev.c| 53 
 src/util/virhostdev.h|  7 +++
 5 files changed, 80 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 97f81ee..52aa7eb 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1715,6 +1715,7 @@ virHostdevPrepareSCSIDevices;
 virHostdevPrepareSCSIVHostDevices;
 virHostdevPrepareUSBDevices;
 virHostdevReAttachDomainDevices;
+virHostdevReAttachMediatedDevices;
 virHostdevReAttachPCIDevices;
 virHostdevReAttachSCSIDevices;
 virHostdevReAttachSCSIVHostDevices;
diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index 45b731c..6a7232f 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -419,6 +419,18 @@ qemuHostdevReAttachSCSIVHostDevices(virQEMUDriverPtr 
driver,
 }
 
 void
+qemuHostdevReAttachMediatedDevices(virQEMUDriverPtr driver,
+   const char *name,
+   virDomainHostdevDefPtr *hostdevs,
+   int nhostdevs)
+{
+virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
+
+virHostdevReAttachMediatedDevices(hostdev_mgr, QEMU_DRIVER_NAME,
+  name, hostdevs, nhostdevs);
+}
+
+void
 qemuHostdevReAttachDomainDevices(virQEMUDriverPtr driver,
  virDomainDefPtr def)
 {
@@ -436,4 +448,7 @@ qemuHostdevReAttachDomainDevices(virQEMUDriverPtr driver,
 
 qemuHostdevReAttachSCSIVHostDevices(driver, def->name, def->hostdevs,
 def->nhostdevs);
+
+qemuHostdevReAttachMediatedDevices(driver, def->name, def->hostdevs,
+   def->nhostdevs);
 }
diff --git a/src/qemu/qemu_hostdev.h b/src/qemu/qemu_hostdev.h
index 9399241..0096497 100644
--- a/src/qemu/qemu_hostdev.h
+++ b/src/qemu/qemu_hostdev.h
@@ -84,6 +84,10 @@ void qemuHostdevReAttachSCSIVHostDevices(virQEMUDriverPtr 
driver,
  const char *name,
  virDomainHostdevDefPtr *hostdevs,
  int nhostdevs);
+void qemuHostdevReAttachMediatedDevices(virQEMUDriverPtr driver,
+const char *name,
+virDomainHostdevDefPtr *hostdevs,
+int nhostdevs);
 void qemuHostdevReAttachDomainDevices(virQEMUDriverPtr driver,
   virDomainDefPtr def);
 
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index 681f720..2a43b4d 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -1963,6 +1963,59 @@ virHostdevReAttachSCSIVHostDevices(virHostdevManagerPtr 
mgr,
 virObjectUnlock(mgr->activeSCSIVHostHostdevs);
 }
 
+void
+virHostdevReAttachMediatedDevices(virHostdevManagerPtr mgr,
+  const char *drv_name,
+  const char *dom_name,
+  virDomainHostdevDefPtr *hostdevs,
+  int nhostdevs)
+{
+const char *used_by_drvname = NULL;
+const char *used_by_domname = NULL;
+virDomainHostdevDefPtr hostdev = NULL;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = NULL;
+size_t i;
+
+if (nhostdevs == 0)
+return;
+
+virObjectLock(mgr->activeMediatedHostdevs);
+for (i = 0; i < nhostdevs; i++) {
+virMediatedDevicePtr mdev, tmp;
+
+hostdev = hostdevs[i];
+mdevsrc = >source.subsys.u.mdev;
+
+if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
+hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV)
+continue;
+
+if (!(mdev = virMediatedDeviceNew(mdevsrc->uuidstr))) {
+VIR_WARN("Failed to reattach mediated device %s attached to "
+ "domain %s", mdevsrc->uuidstr, dom_name);
+continue;
+}
+
+/* Remove from the list only mdevs assigned to @drv_name/@dom_name */
+
+tmp = virMediatedDeviceListFind(mgr->activeMediatedHostdevs, mdev);
+virMediatedDeviceFree(mdev);
+
+/* skip inactive devices */
+if (!tmp)
+continue;
+
+virMediatedDeviceGetUsedBy(t

[libvirt] [RFC PATCH v2 04/18] conf: Update XML parser, formatter, and RNG schema to support mdev

2017-02-15 Thread Erik Skultety
To keep the domain XML as much platform agnostic as possible, do not
expose an element/attribute which would contain path directly to the
syfs filesystem which the mediated devices are build upon. Instead,
identify each mediated device by a UUID attribute as well as specifying
the device API (e.g. vfio-pci) through the 'model' attribute.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 docs/schemas/domaincommon.rng | 26 ++
 src/conf/domain_conf.c| 50 +++
 2 files changed, 76 insertions(+)

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index d715bff..ad8f47c 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -4014,6 +4014,7 @@
   
   
   
+  
 
   
 
@@ -4164,6 +4165,20 @@
 
   
 
+  
+
+  mdev
+
+
+  
+vfio-pci
+  
+
+
+  
+
+  
+
   
 
   storage
@@ -4322,6 +4337,11 @@
   
 
   
+  
+
+  
+
+  
   
 
   
@@ -4703,6 +4723,12 @@
   
   
 
+
+  
+mdev
+  
+  
+
   
 
   
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 053f3cb..870aec6 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6348,6 +6348,47 @@ virDomainHostdevSubsysSCSIVHostDefParseXML(xmlNodePtr 
sourcenode,
 return ret;
 }
 
+static int
+virDomainHostdevSubsysMediatedDevDefParseXML(virDomainHostdevDefPtr def,
+ xmlXPathContextPtr ctxt)
+{
+int ret = -1;
+unsigned char uuid[VIR_UUID_BUFLEN] = {0};
+char *uuidxml = NULL;
+xmlNodePtr node = NULL;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
+
+if (mdevsrc->model == 0) {
+virReportError(VIR_ERR_XML_ERROR, "%s",
+   _("Missing 'model' attribute for element "));
+goto cleanup;
+}
+
+if (!(node = virXPathNode("./source/address", ctxt))) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("Missing  element"));
+goto cleanup;
+}
+
+if (!(uuidxml = virXMLPropString(node, "uuid"))) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("Missing 'uuid' attribute for element "));
+goto cleanup;
+}
+
+if (virUUIDParse(uuidxml, uuid) < 0) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   "%s",
+   _("Cannot parse uuid attribute of element "));
+goto cleanup;
+}
+
+virUUIDFormat(uuid, mdevsrc->uuidstr);
+ret = 0;
+ cleanup:
+VIR_FREE(uuidxml);
+return ret;
+}
 
 static int
 virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
@@ -6380,6 +6421,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
 
 sgio = virXMLPropString(node, "sgio");
 rawio = virXMLPropString(node, "rawio");
+model = virXMLPropString(node, "model");
 
 /* @type is passed in from the caller rather than read from the
  * xml document, because it is specified in different places for
@@ -6494,6 +6536,8 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
 goto error;
 break;
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+if (virDomainHostdevSubsysMediatedDevDefParseXML(def, ctxt) < 0)
+goto error;
 break;
 
 default:
@@ -6509,6 +6553,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
 VIR_FREE(sgio);
 VIR_FREE(rawio);
 VIR_FREE(backendStr);
+VIR_FREE(model);
 return ret;
 }
 
@@ -21180,6 +21225,7 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf,
 virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
 virDomainHostdevSubsysSCSIVHostPtr hostsrc = 
>source.subsys.u.scsi_host;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 virDomainHostdevSubsysSCSIHostPtr scsihostsrc = >u.host;
 virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc = >u.iscsi;
 
@@ -21284,6 +21330,10 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf,
 break;
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST:
 break;
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+virBufferAsprintf(buf, "\n",
+  mdevsrc->uuidstr);
+break;
 default:
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected hostdev type %d"),
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 00/18] Introduce vGPU mdev framework to libvirt

2017-02-15 Thread Erik Skultety
since v1:
- new  attribute model introduced which tells libvirt which device API
should be considered when auto-assigning guest address
- device_api is properly checked, thus taking the 'model' attribute only as a
hint to assign "some" address
- new address type 'mdev' is introduced rather than using plain  element,
since the address element is more conveniently extendable.
- the emulated mtty driver now works as well out of the box, so no HW needed to
review this series --> let's try it :)
- fixed all the nits from v1

Erik Skultety (18):
  util: Introduce new module virmdev
  conf: Introduce new hostdev device type mdev
  conf: Introduce new address type mdev
  conf: Update XML parser, formatter, and RNG schema to support mdev
  conf: Introduce virDomainHostdevDefPostParse
  conf: Add post parse code for mdevs to virDomainHostdevDefPostParse
  security: dac: Enable labeling of vfio mediated devices
  security: selinux: Enable labeling of vfio mediated devices
  conf: Enable cold-plug of a mediated device
  qemu: Assign PCI addresses for mediated devices as well
  hostdev: Maintain a driver list of active mediated devices
  hostdev: Introduce a reattach method for mediated devices
  qemu: cgroup: Adjust cgroups' logic to allow mediated devices
  qemu: namespace: Hook up the discovery of mdevs into the namespace
code
  qemu: Format mdevs on the qemu command line
  test: Add some test cases for our test suite regarding the mdevs
  docs: Document the new hostdev and address type 'mdev'
  news: Update the NEWS.xml about the new mdev feature

 docs/formatdomain.html.in  |  48 ++-
 docs/news.xml  |  11 +
 docs/schemas/domaincommon.rng  |  26 ++
 po/POTFILES.in |   1 +
 src/Makefile.am|   1 +
 src/conf/device_conf.h |   1 +
 src/conf/domain_conf.c | 203 ++--
 src/conf/domain_conf.h |   9 +
 src/libvirt_private.syms   |  20 ++
 src/qemu/qemu_cgroup.c |  34 ++
 src/qemu/qemu_command.c|  49 +++
 src/qemu/qemu_command.h|   5 +
 src/qemu/qemu_domain.c |  12 +
 src/qemu/qemu_domain.h |   1 +
 src/qemu/qemu_domain_address.c |  16 +-
 src/qemu/qemu_hostdev.c|  37 +++
 src/qemu/qemu_hostdev.h|   8 +
 src/qemu/qemu_hotplug.c|   2 +
 src/security/security_apparmor.c   |   3 +
 src/security/security_dac.c|  55 
 src/security/security_selinux.c|  54 
 src/util/virhostdev.c  | 229 -
 src/util/virhostdev.h  |  16 +
 src/util/virmdev.c | 358 +
 src/util/virmdev.h |  93 ++
 tests/domaincapsschemadata/full.xml|   1 +
 .../qemuxml2argv-hostdev-mdev-unmanaged.args   |  25 ++
 .../qemuxml2argv-hostdev-mdev-unmanaged.xml|  37 +++
 tests/qemuxml2argvtest.c   |   6 +
 .../qemuxml2xmlout-hostdev-mdev-unmanaged.xml  |  40 +++
 tests/qemuxml2xmltest.c|   1 +
 31 files changed, 1362 insertions(+), 40 deletions(-)
 create mode 100644 src/util/virmdev.c
 create mode 100644 src/util/virmdev.h
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.args
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.xml
 create mode 100644 
tests/qemuxml2xmloutdata/qemuxml2xmlout-hostdev-mdev-unmanaged.xml

-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 07/18] security: dac: Enable labeling of vfio mediated devices

2017-02-15 Thread Erik Skultety
Label the VFIO IOMMU devices under /dev/vfio/ referenced by the symlinks
in the sysfs (e.g. /sys/class/mdev_bus//iommu_group) which what
qemu actually gets formatted on the command line.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/security/security_dac.c | 57 +++--
 1 file changed, 55 insertions(+), 2 deletions(-)

diff --git a/src/security/security_dac.c b/src/security/security_dac.c
index ecce1d3..45bd24e 100644
--- a/src/security/security_dac.c
+++ b/src/security/security_dac.c
@@ -33,6 +33,7 @@
 #include "virfile.h"
 #include "viralloc.h"
 #include "virlog.h"
+#include "virmdev.h"
 #include "virpci.h"
 #include "virusb.h"
 #include "virscsi.h"
@@ -856,6 +857,15 @@ virSecurityDACSetHostLabel(virSCSIVHostDevicePtr dev 
ATTRIBUTE_UNUSED,
 
 
 static int
+virSecurityDACSetMediatedDevLabel(virMediatedDevicePtr dev ATTRIBUTE_UNUSED,
+  const char *file,
+  void *opaque)
+{
+return virSecurityDACSetHostdevLabelHelper(file, opaque);
+}
+
+
+static int
 virSecurityDACSetHostdevLabel(virSecurityManagerPtr mgr,
   virDomainDefPtr def,
   virDomainHostdevDefPtr dev,
@@ -867,7 +877,9 @@ virSecurityDACSetHostdevLabel(virSecurityManagerPtr mgr,
 virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
 virDomainHostdevSubsysSCSIVHostPtr hostsrc = 
>source.subsys.u.scsi_host;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 int ret = -1;
+virMediatedDevicePtr mdev = NULL;
 
 if (!priv->dynamicOwnership)
 return 0;
@@ -964,13 +976,26 @@ virSecurityDACSetHostdevLabel(virSecurityManagerPtr mgr,
 break;
 }
 
-case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
+char *vfio_dev = NULL;
+if (!(mdev = virMediatedDeviceNew(mdevsrc->uuidstr)))
+goto done;
+
+if (!(vfio_dev = virMediatedDeviceGetIOMMUGroupDev(mdev)))
+goto done;
+
+ret = virSecurityDACSetMediatedDevLabel(mdev, vfio_dev, );
+VIR_FREE(vfio_dev);
+break;
+}
+
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 ret = 0;
 break;
 }
 
  done:
+virMediatedDeviceFree(mdev);
 return ret;
 }
 
@@ -1018,6 +1043,15 @@ virSecurityDACRestoreHostLabel(virSCSIVHostDevicePtr dev 
ATTRIBUTE_UNUSED,
 return virSecurityDACRestoreFileLabel(priv, file);
 }
 
+static int
+virSecurityDACRestoreMediatedDevLabel(virMediatedDevicePtr dev 
ATTRIBUTE_UNUSED,
+  const char *file,
+  void *opaque)
+{
+virSecurityManagerPtr mgr = opaque;
+virSecurityDACDataPtr priv = virSecurityManagerGetPrivateData(mgr);
+return virSecurityDACRestoreFileLabel(priv, file);
+}
 
 static int
 virSecurityDACRestoreHostdevLabel(virSecurityManagerPtr mgr,
@@ -1032,6 +1066,7 @@ virSecurityDACRestoreHostdevLabel(virSecurityManagerPtr 
mgr,
 virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
 virDomainHostdevSubsysSCSIVHostPtr hostsrc = 
>source.subsys.u.scsi_host;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 int ret = -1;
 
 secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_DAC_NAME);
@@ -1120,7 +1155,25 @@ virSecurityDACRestoreHostdevLabel(virSecurityManagerPtr 
mgr,
 break;
 }
 
-case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
+char *vfiodev = NULL;
+virMediatedDevicePtr mdev = virMediatedDeviceNew(mdevsrc->uuidstr);
+
+if (!mdev)
+goto done;
+
+if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdev))) {
+virMediatedDeviceFree(mdev);
+goto done;
+}
+
+ret = virSecurityDACRestoreMediatedDevLabel(mdev, vfiodev, mgr);
+
+VIR_FREE(vfiodev);
+virMediatedDeviceFree(mdev);
+break;
+}
+
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 ret = 0;
 break;
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 17/18] docs: Document the new hostdev and address type 'mdev'

2017-02-15 Thread Erik Skultety
Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 docs/formatdomain.html.in | 48 +++
 1 file changed, 44 insertions(+), 4 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 0a115f5..8f21436 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -3277,8 +3277,20 @@
 attributes: iobase and irq.
 Since 1.2.1
   
+  mdev
+  Mediated devices' addresses have so far only one mandatory attribute
+uuid (since 3.1.0) which
+uniquely identifies a mediated device under the syfs file system.
+  
 
 
+
+Note: Due to nature of mediated devices, being only software devices
+defining an allocation of resources on the physical parent device, the
+address type mdev is supposed to be used to identify a
+device on the host only, rather than identifying it in the guest.
+
+
 Controllers
 
 
@@ -3774,6 +3786,19 @@
   /devices
   ...
 
+or:
+
+
+  ...
+  devices
+hostdev mode='subsystem' type='mdev' model='vfio-pci'
+source
+  address type='mdev' uuid='c2177883-f1bb-47f0-914d-32a22e3a8804'
+/source
+/hostdev
+  /devices
+  ...
+
 
   hostdev
   The hostdev element is the main container for describing
@@ -3818,12 +3843,23 @@
 type passes all LUNs presented by a single HBA to
 the guest.
   
+  mdev
+  For mediated devices (Since 3.1.0)
+  the model attribute specifies the device API which
+  determines how the host's vfio driver will expose the device to the
+  guest. Currently, only vfio-pci model is supported.
+  The model also has implications on the guest's address type, i.e.
+  for vfio-pci device API any address type other than PCI
+  will result in an error.
+  
 
 
-  Note: The managed attribute is only used with PCI 
devices
-  and is ignored by all the other device types, thus setting
-  managed explicitly with other than PCI device has the 
same
-  effect as omitting it.
+  Note: The managed attribute is only used with PCI and is
+  ignored by all the other device types, thus setting
+  managed explicitly with other than a PCI device has the
+  same effect as omitting it. Similarly, model attribute 
is
+  only supported by mediated devices and ignored by all other device
+  types.
 
   
   source
@@ -3888,6 +3924,10 @@
 is the vhost_scsi wwpn (16 hexadecimal digits with a prefix of
 "naa.") established in the host configfs.
   
+  mdev
+  Mediated devices (Since 3.1.0) are
+  described by the address element.
+  
 
   
   vendor, product
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 14/18] qemu: namespace: Hook up the discovery of mdevs into the namespace code

2017-02-15 Thread Erik Skultety
Again, as for all the other hostdev device types, make sure that the
/dev/vfio/ device will be added to the qemu namespace.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/qemu/qemu_domain.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index c4d7a47..eb86385 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -6852,10 +6852,12 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev,
 virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
 virDomainHostdevSubsysSCSIVHostPtr hostsrc = 
>source.subsys.u.scsi_host;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 virPCIDevicePtr pci = NULL;
 virUSBDevicePtr usb = NULL;
 virSCSIDevicePtr scsi = NULL;
 virSCSIVHostDevicePtr host = NULL;
+virMediatedDevicePtr mdev = NULL;
 char *tmpPath = NULL;
 bool freeTmpPath = false;
 
@@ -6930,6 +6932,14 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev,
 }
 
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+if (!(mdev = virMediatedDeviceNew(mdevsrc->uuidstr)))
+goto cleanup;
+
+if (!(tmpPath = virMediatedDeviceGetIOMMUGroupDev(mdev)))
+goto cleanup;
+
+freeTmpPath = true;
+break;
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 break;
 }
@@ -6950,6 +6960,7 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev,
 virUSBDeviceFree(usb);
 virSCSIDeviceFree(scsi);
 virSCSIVHostDeviceFree(host);
+virMediatedDeviceFree(mdev);
 if (freeTmpPath)
 VIR_FREE(tmpPath);
 return ret;
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 06/18] conf: Add post parse code for mdevs to virDomainHostdevDefPostParse

2017-02-15 Thread Erik Skultety
We need to make sure that if user explicitly provides a guest address
for a mdev device, the address type will be matching the device API
supported on that specific mediated device and error out with an
incorrect XML message.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/conf/domain_conf.c | 18 +-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 151a308..69874f0 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -4239,10 +4239,26 @@ virDomainHostdevDefPostParse(virDomainHostdevDefPtr dev,
 }
 }
 break;
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
+int model = dev->source.subsys.u.mdev.model;
+
+if (dev->info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE)
+return 0;
+
+if (model == VIR_MDEV_MODEL_TYPE_VFIO_PCI &&
+dev->info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
+virReportError(VIR_ERR_XML_ERROR,
+   _("Unsupported address type '%s' with mediated "
+ "device model '%s'"),
+   virDomainDeviceAddressTypeToString(dev->info->type),
+   virMediatedDeviceModelTypeToString(model));
+return -1;
+}
+}
+
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST:
-case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 break;
 }
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 16/18] test: Add some test cases for our test suite regarding the mdevs

2017-02-15 Thread Erik Skultety
For now, these only cover the unmanaged, i.e. user pre-created devices.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 .../qemuxml2argv-hostdev-mdev-unmanaged.args   | 25 ++
 .../qemuxml2argv-hostdev-mdev-unmanaged.xml| 37 
 tests/qemuxml2argvtest.c   |  6 
 .../qemuxml2xmlout-hostdev-mdev-unmanaged.xml  | 40 ++
 tests/qemuxml2xmltest.c|  1 +
 5 files changed, 109 insertions(+)
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.args
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.xml
 create mode 100644 
tests/qemuxml2xmloutdata/qemuxml2xmlout-hostdev-mdev-unmanaged.xml

diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.args 
b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.args
new file mode 100644
index 000..fdefeb6
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.args
@@ -0,0 +1,25 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/home/test \
+USER=test \
+LOGNAME=test \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu \
+-name QEMUGuest2 \
+-S \
+-M pc \
+-m 214 \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
+-nographic \
+-nodefconfig \
+-nodefaults \
+-monitor unix:/tmp/lib/domain--1-QEMUGuest2/monitor.sock,server,nowait \
+-no-acpi \
+-boot c \
+-usb \
+-drive file=/dev/HostVG/QEMUGuest2,format=raw,if=none,id=drive-ide0-0-0 \
+-device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \
+-device vfio-pci,\
+sysfsdev=/sys/bus/mdev/devices/53764d0e-85a0-42b4-af5c-2046b460b1dc,bus=pci.0,\
+addr=0x3
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.xml 
b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.xml
new file mode 100644
index 000..144b769
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.xml
@@ -0,0 +1,37 @@
+
+  QEMUGuest2
+  c7a5fdbd-edaf-9455-926a-d65c16db1809
+  219136
+  219136
+  1
+  
+hvm
+
+  
+  
+  destroy
+  restart
+  destroy
+  
+/usr/bin/qemu
+
+  
+  
+  
+  
+
+
+
+
+
+
+
+
+
+  
+
+  
+
+
+  
+
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index faa99c6..e1173ac 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1475,6 +1475,12 @@ mymain(void)
 DO_TEST("hostdev-vfio-multidomain",
 QEMU_CAPS_NODEFCONFIG,
 QEMU_CAPS_DEVICE_VFIO_PCI, QEMU_CAPS_HOST_PCI_MULTIDOMAIN);
+DO_TEST("hostdev-mdev-unmanaged",
+QEMU_CAPS_NODEFCONFIG,
+QEMU_CAPS_DEVICE_VFIO_PCI);
+DO_TEST_PARSE_ERROR("hostdev-mdev-unmanaged-no-uuid",
+QEMU_CAPS_NODEFCONFIG,
+QEMU_CAPS_DEVICE_VFIO_PCI);
 DO_TEST_FAILURE("hostdev-vfio-multidomain",
 QEMU_CAPS_NODEFCONFIG, QEMU_CAPS_DEVICE_VFIO_PCI);
 DO_TEST("pci-rom",
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-hostdev-mdev-unmanaged.xml 
b/tests/qemuxml2xmloutdata/qemuxml2xmlout-hostdev-mdev-unmanaged.xml
new file mode 100644
index 000..55f19c4
--- /dev/null
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-hostdev-mdev-unmanaged.xml
@@ -0,0 +1,40 @@
+
+  QEMUGuest2
+  c7a5fdbd-edaf-9455-926a-d65c16db1809
+  219136
+  219136
+  1
+  
+hvm
+
+  
+  
+  destroy
+  restart
+  destroy
+  
+/usr/bin/qemu
+
+  
+  
+  
+  
+
+
+  
+
+
+
+  
+
+
+
+
+  
+
+  
+  
+
+
+  
+
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 0702f58..fbb5192 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -550,6 +550,7 @@ mymain(void)
 DO_TEST("hostdev-usb-address", NONE);
 DO_TEST("hostdev-pci-address", NONE);
 DO_TEST("hostdev-vfio", NONE);
+DO_TEST("hostdev-mdev-unmanaged", NONE);
 DO_TEST("pci-rom", NONE);
 DO_TEST("pci-serial-dev-chardev", NONE);
 
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [RFC PATCH v2 14.5/18] qemu: Bump the memory locking limit for mdevs as well

2017-02-16 Thread Erik Skultety
> > Nice!  For series:
> > 
> > Tested-by: Alex Williamson 
> > 
> > (with KVMGT vGPU mdev)
> 

Thank you very much for the effort Alex. Given its current state, I'm glad
KVMGT was testable with my patches :).

> Nit, if I configure a VM for an invalid mdev uuid, I get the following
> error message:
> 
> Error starting domain: Requested operation is not valid: mediated devices are 
> not supported by this kernel
> 
> Traceback (most recent call last):
>   File "/usr/share/virt-manager/virtManager/asyncjob.py", line 88, in 
> cb_wrapper
> callback(asyncjob, *args, **kwargs)
>   File "/usr/share/virt-manager/virtManager/asyncjob.py", line 124, in tmpcb
> callback(*args, **kwargs)
>   File "/usr/share/virt-manager/virtManager/libvirtobject.py", line 83, in 
> newfn
> ret = fn(self, *args, **kwargs)
>   File "/usr/share/virt-manager/virtManager/domain.py", line 1404, in startup
> self._backend.create()
>   File "/usr/lib64/python2.7/site-packages/libvirt.py", line 1035, in create
> if ret == -1: raise libvirtError ('virDomainCreate() failed', dom=self)
> libvirtError: Requested operation is not valid: mediated devices are not 
> supported by this kernel
> 
> In this case it should really just be a device not found error, the
> speculation that the kernel doesn't support mediated devices is
> incorrect.  Thanks,
> 

Noted, I'll address this as part of, presumably, v3 when I get a patch
review.

Thanks,
Erik

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] cputest: Fix name of the file removed by cpu-parse.sh

2017-02-17 Thread Erik Skultety
On Thu, Feb 16, 2017 at 02:46:04PM +0100, Jiri Denemark wrote:
> We want to remove the file created by
> 
> json <<<"$data" >$fname.json
> 
> in case it was empty.
> 
> Signed-off-by: Jiri Denemark 
> ---
>  tests/cputestdata/cpu-parse.sh | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tests/cputestdata/cpu-parse.sh b/tests/cputestdata/cpu-parse.sh
> index 1b5ab4a5a..c3b5ef106 100755
> --- a/tests/cputestdata/cpu-parse.sh
> +++ b/tests/cputestdata/cpu-parse.sh
> @@ -53,5 +53,5 @@ json <<<"$data" >$fname.json
>  if [[ -s $fname.json ]]; then
>  echo $fname.json
>  else
> -rm $fname.new.json
> +rm $fname.json

Hmm, interesting mistake.

ACK

Erik


>  fi
> -- 
> 2.11.1
> 
> --
> libvir-list mailing list
> libvir-list@redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 1/2] security: DAC: fix the transaction model's list append

2017-01-17 Thread Erik Skultety
> > -if (VIR_APPEND_ELEMENT(list->items, list->nItems, item) < 0) {
> > -VIR_FREE(item);
> > -return -1;
> > -}
> > +if (VIR_APPEND_ELEMENT(list->items, list->nItems, item) < 0)
> > +goto cleanup;
> >  
> > -return 0;
> > +tmp = NULL;
> > +item = NULL;
> 
> This 'item = NULL' is not needed. VIR_APPEND_ELEMENT sets @item to NULL
> upon successful return. But I agree that it is hard to spot.

Oh, missed that one, thanks for the suggestion.

Erik

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 2/2] security: SELinux: fix the transaction model's list append

2017-01-17 Thread Erik Skultety
The problem is in the way how the list item is created prior to
appending it to the transaction list - the @path argument is just a
shallow copy instead of deep copy of the hostdev device's path.
Unfortunately, the hostdev devices from which the @path is extracted, in
order to add them into the transaction list, are only temporary and
freed before the buildup of the qemu namespace, thus making the @path
attribute in the transaction list NULL, causing 'permission denied' or
'double free' or 'unknown cause' errors.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1413773

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/security/security_selinux.c | 30 +-
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index f229b51..c799056 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -81,7 +81,7 @@ struct _virSecuritySELinuxCallbackData {
 typedef struct _virSecuritySELinuxContextItem virSecuritySELinuxContextItem;
 typedef virSecuritySELinuxContextItem *virSecuritySELinuxContextItemPtr;
 struct _virSecuritySELinuxContextItem {
-const char *path;
+char *path;
 const char *tcon;
 bool optional;
 };
@@ -111,21 +111,31 @@ 
virSecuritySELinuxContextListAppend(virSecuritySELinuxContextListPtr list,
 const char *tcon,
 bool optional)
 {
-virSecuritySELinuxContextItemPtr item;
+int ret = -1;
+char *tmp = NULL;
+virSecuritySELinuxContextItemPtr item = NULL;
 
 if (VIR_ALLOC(item) < 0)
 return -1;
 
-item->path = path;
+if (VIR_STRDUP(tmp, path) < 0)
+goto cleanup;
+
+item->path = tmp;
 item->tcon = tcon;
 item->optional = optional;
 
-if (VIR_APPEND_ELEMENT(list->items, list->nItems, item) < 0) {
-VIR_FREE(item);
-return -1;
-}
+if (VIR_APPEND_ELEMENT(list->items, list->nItems, item) < 0)
+goto cleanup;
 
-return 0;
+tmp = NULL;
+item = NULL;
+
+ret = 0;
+ cleanup:
+VIR_FREE(tmp);
+VIR_FREE(item);
+return ret;
 }
 
 static void
@@ -137,8 +147,10 @@ virSecuritySELinuxContextListFree(void *opaque)
 if (!list)
 return;
 
-for (i = 0; i < list->nItems; i++)
+for (i = 0; i < list->nItems; i++) {
+VIR_FREE(list->items[i]->path);
 VIR_FREE(list->items[i]);
+}
 VIR_FREE(list);
 }
 
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 1/2] security: DAC: fix the transaction model's list append

2017-01-17 Thread Erik Skultety
The problem is in the way how the list item is created prior to
appending it to the transaction list - the @path attribute is just a
shallow copy instead of deep copy of the hostdev device's path.
Unfortunately, the hostdev devices from which the @path is extracted, in
order to add them into the transaction list, are only temporary and
freed before the buildup of the qemu namespace, thus making the @path
attribute in the transaction list NULL, causing 'permission denied' or
'double free' or 'unknown cause' errors.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1413773

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 src/security/security_dac.c | 30 +-
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/src/security/security_dac.c b/src/security/security_dac.c
index d457e6a..d7a2de4 100644
--- a/src/security/security_dac.c
+++ b/src/security/security_dac.c
@@ -71,7 +71,7 @@ struct _virSecurityDACCallbackData {
 typedef struct _virSecurityDACChownItem virSecurityDACChownItem;
 typedef virSecurityDACChownItem *virSecurityDACChownItemPtr;
 struct _virSecurityDACChownItem {
-const char *path;
+char *path;
 const virStorageSource *src;
 uid_t uid;
 gid_t gid;
@@ -95,22 +95,32 @@ virSecurityDACChownListAppend(virSecurityDACChownListPtr 
list,
   uid_t uid,
   gid_t gid)
 {
-virSecurityDACChownItemPtr item;
+int ret = -1;
+char *tmp = NULL;
+virSecurityDACChownItemPtr item = NULL;
 
 if (VIR_ALLOC(item) < 0)
 return -1;
 
-item->path = path;
+if (VIR_STRDUP(tmp, path) < 0)
+goto cleanup;
+
+item->path = tmp;
 item->src = src;
 item->uid = uid;
 item->gid = gid;
 
-if (VIR_APPEND_ELEMENT(list->items, list->nItems, item) < 0) {
-VIR_FREE(item);
-return -1;
-}
+if (VIR_APPEND_ELEMENT(list->items, list->nItems, item) < 0)
+goto cleanup;
 
-return 0;
+tmp = NULL;
+item = NULL;
+
+ret = 0;
+ cleanup:
+VIR_FREE(tmp);
+VIR_FREE(item);
+return ret;
 }
 
 static void
@@ -122,8 +132,10 @@ virSecurityDACChownListFree(void *opaque)
 if (!list)
 return;
 
-for (i = 0; i < list->nItems; i++)
+for (i = 0; i < list->nItems; i++) {
+VIR_FREE(list->items[i]->path);
 VIR_FREE(list->items[i]);
+}
 VIR_FREE(list);
 }
 
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 0/2] security: Fix the transaction model's list appending

2017-01-17 Thread Erik Skultety
The problem lies in how elements are appended into the transaction list -
instead of making a deep copy of a string we were doing a shallow copy only.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1413773

Erik Skultety (2):
  security: DAC: fix the transaction model's list append
  security: SELinux: fix the transaction model's list append

 src/security/security_dac.c | 30 +-
 src/security/security_selinux.c | 30 +-
 2 files changed, 42 insertions(+), 18 deletions(-)

-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 2/2] security: SELinux: fix the transaction model's list append

2017-01-17 Thread Erik Skultety
> > @@ -111,21 +111,31 @@ 
> > virSecuritySELinuxContextListAppend(virSecuritySELinuxContextListPtr list,
> >  const char *tcon,
> >  bool optional)
> >  {
> > -virSecuritySELinuxContextItemPtr item;
> > +int ret = -1;
> > +char *tmp = NULL;
> > +virSecuritySELinuxContextItemPtr item = NULL;
> >  
> >  if (VIR_ALLOC(item) < 0)
> >  return -1;
> >  
> > -item->path = path;
> > +if (VIR_STRDUP(tmp, path) < 0)
> > +goto cleanup;
> > +
> > +item->path = tmp;
> >  item->tcon = tcon;
> 
> Unfortunately, while this was enough in the DAC driver, it is not enough
> here. @tcon may be dynamically allocated just for this call:
> 
> virSecuritySELinuxRestoreFileLabel ->
> virSecuritySELinuxSetFilecon ->
> virSecuritySELinuxSetFileconHelper ->
> virSecuritySELinuxTransactionAppend ->
> virSecuritySELinuxContextListAppend
> 
> However, I guess fixing that is trivial. ACK if you do so and safe for
> the freeze.

Adjusted both patches according to your suggestions and pushed, thanks.

Erik

> 
> Michal
> 
> --
> libvir-list mailing list
> libvir-list@redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [RFC PATCH v2 REBASE 00/18] Introduce vGPU mdev framework to libvirt

2017-02-27 Thread Erik Skultety
On Fri, Feb 24, 2017 at 11:10:00AM -0700, Alex Williamson wrote:
> On Mon, 20 Feb 2017 15:28:13 +0100
> Erik Skultety <eskul...@redhat.com> wrote:
> 
> > since the original v2 [1]:
> > - resolved a few merge conflicts caused by @9d92f533 which refactored out 
> > some
> > duplicate code which eventually lead to dropping patch 14/18 from the 
> > original
> > series due to being unnecessary
> > - rebased onto fresh HEAD
> > 
> > [1] https://www.redhat.com/archives/libvir-list/2017-February/msg00739.html
> > 
> > Erik Skultety (18):
> >   util: Introduce new module virmdev
> >   conf: Introduce new hostdev device type mdev
> >   conf: Introduce new address type mdev
> >   conf: Update XML parser, formatter, and RNG schema to support mdev
> >   conf: Introduce virDomainHostdevDefPostParse
> >   conf: Add post parse code for mdevs to virDomainHostdevDefPostParse
> >   security: dac: Enable labeling of vfio mediated devices
> >   security: selinux: Enable labeling of vfio mediated devices
> >   conf: Enable cold-plug of a mediated device
> >   qemu: Assign PCI addresses for mediated devices as well
> >   hostdev: Maintain a driver list of active mediated devices
> >   hostdev: Introduce a reattach method for mediated devices
> >   qemu: cgroup: Adjust cgroups' logic to allow mediated devices
> >   qemu: Bump the memory locking limit for mdevs as well
> >   qemu: Format mdevs on qemu command line
> >   test: Add some test cases for our test suite regarding the mdevs
> >   docs: Document the new hostdev and address type 'mdev'
> >   news: Update the NEWS.xml about the new mdev feature
> > 
> >  docs/formatdomain.html.in  |  48 ++-
> >  docs/news.xml  |   9 +
> >  docs/schemas/domaincommon.rng  |  26 ++
> >  po/POTFILES.in |   1 +
> >  src/Makefile.am|   1 +
> >  src/conf/device_conf.h |   1 +
> >  src/conf/domain_conf.c | 203 ++--
> >  src/conf/domain_conf.h |   9 +
> >  src/libvirt_private.syms   |  20 ++
> 
> I don't understand how these get generated, so I won't suggest where
> they should be added, but a usb test fails for me without adding
> these to this syms file:
> 

Hmm, weird, nothing fails for me, even rebased onto the current master.
Anyhow, I checked that we indeed put these generated methods into the .syms
file which I didn't know (never had a problem with that), but I'll fix it.

Thanks,
Erik

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] docs: Document the new hostdev and address type 'mdev'

2017-02-27 Thread Erik Skultety
On Mon, Feb 27, 2017 at 09:33:51AM +0100, Martin Polednik wrote:
> On 20/02/17 15:28 +0100, Erik Skultety wrote:
> > Signed-off-by: Erik Skultety <eskul...@redhat.com>
> > ---
> > docs/formatdomain.html.in | 48 
> > +++
> > 1 file changed, 44 insertions(+), 4 deletions(-)
> > 
> > diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
> > index b69bd4c..13cb767 100644
> > --- a/docs/formatdomain.html.in
> > +++ b/docs/formatdomain.html.in
> > @@ -3277,8 +3277,20 @@
> > attributes: iobase and irq.
> > Since 1.2.1
> >   
> > +  mdev
> > +  Mediated devices' addresses have so far only one mandatory 
> > attribute
> > +uuid (since 3.1.0) which
> > +uniquely identifies a mediated device under the syfs file system.
> > +  
> > 
> > 
> > +
> > +Note: Due to nature of mediated devices, being only software 
> > devices
> > +defining an allocation of resources on the physical parent device, 
> > the
> > +address type mdev is supposed to be used to identify a
> > +device on the host only, rather than identifying it in the guest.
> > +
> > +
> > Controllers
> > 
> > 
> > @@ -3774,6 +3786,19 @@
> >   /devices
> >   ...
> > 
> > +or:
> > +
> > +
> > +  ...
> > +  devices
> > +hostdev mode='subsystem' type='mdev' model='vfio-pci'
> > +source
> > +  address type='mdev' 
> > uuid='c2177883-f1bb-47f0-914d-32a22e3a8804'
> > +/source
> > +/hostdev
> > +  /devices
> > +  ...
> 
> Can't really test it yet, but from the docs/code seems to be OK for
> oVirt.
> 

Actually you can, with kernel 4.10, I don't know how the distro-packaged
kernels are configured, so my honest guess just would be to try modprobe mtty
and see what happens. Anyway, you can build your own kernel and just make sure
the vfio mediated devices framework is either included or modularized and the
CONFIG_SAMPLE_VFIO_MDEV_MTTY sample driver is checked and you're good to go.

Erik

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] virt-admin commands aliases

2016-09-05 Thread Erik Skultety
Hi there,

after my presentation at KVM Forum, it was pointed out from the audience
that we might think about doing something about the naming of the
virt-admin's comands, since there is some sort of inconsistency: srv-
vs. client- vs. dmn- (not merged yet). When I sent patches to upstream I
already knew that the naming was not optimal, but I didn't come up with
anything better so I hoped that the reviewer might think of something
better which unfortunately did not happen.

Anyway, there are multiple options how this can be approached but I'm
not 100% satisfied with neither of them:

1) rename the commands completely
Although clean, obviously this is the non-preferred option because this
would break any backwards compatibility however, I think there is a fair
chance that people haven't actually started using it yet (although that
might change between 7.3 and 7.4).

2) create aliases for non-abbreviated forms of the commands
That way, srv- would become server- and dmn- would become daemon-.
However, by doing this we'll end up with 6 almost identical entries in
the commands structure which might be error-prone once we decide to
add/create a flag to the command primitive, since the flag would
have to be added both to the alias and to the original (unlikely, but
possible that someone might forget about that)

3) abbreviate client- to something like clnt-
Identical to the above except for the amount of duplicate entries which
would be reduced to 2

4) leave it as is if such a consensus is reached and accepted
I guess this does no need any additional comments.

Thanks for any ideas.

Erik

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] virt-admin commands aliases

2016-09-06 Thread Erik Skultety
On 05/09/16 19:48, Daniel P. Berrange wrote:
> On Mon, Sep 05, 2016 at 05:37:07PM +0200, Erik Skultety wrote:
>> Hi there,
>>
>> after my presentation at KVM Forum, it was pointed out from the audience
>> that we might think about doing something about the naming of the
>> virt-admin's comands, since there is some sort of inconsistency: srv-
>> vs. client- vs. dmn- (not merged yet). When I sent patches to upstream I
>> already knew that the naming was not optimal, but I didn't come up with
>> anything better so I hoped that the reviewer might think of something
>> better which unfortunately did not happen.
>>
>> Anyway, there are multiple options how this can be approached but I'm
>> not 100% satisfied with neither of them:
>>
>> 1) rename the commands completely
>> Although clean, obviously this is the non-preferred option because this
>> would break any backwards compatibility however, I think there is a fair
>> chance that people haven't actually started using it yet (although that
>> might change between 7.3 and 7.4).
>>
>> 2) create aliases for non-abbreviated forms of the commands
>> That way, srv- would become server- and dmn- would become daemon-.
>> However, by doing this we'll end up with 6 almost identical entries in
>> the commands structure which might be error-prone once we decide to
>> add/create a flag to the command primitive, since the flag would
>> have to be added both to the alias and to the original (unlikely, but
>> possible that someone might forget about that)
>>
>> 3) abbreviate client- to something like clnt-
>> Identical to the above except for the amount of duplicate entries which
>> would be reduced to 2
>>
>> 4) leave it as is if such a consensus is reached and accepted
>> I guess this does no need any additional comments.
> 
> I just vote for 4.
> 
> In retrospect it would have been nice to use 'server' instead of
> 'srv', but ultimately it isn't a functional problem.  The "solutions"
> create extra code and/or inconsitency and/or break back-compat so just
> aren't worth it IMHO.
> 

Yeah, for me personally, it was either number 2 or 4 but as you write,
both of them suck in their own way and I just could not decide which one
sucked less.

Thanks for opinions guys, appreciated :)

Erik

> IOW, admit 'srv' sucks but don't change it, and ensure new server
> commands continue to use 'srv' for consistency.
> 
> We can of couse use 'daemon-' as prefix for new commands, since we
> have not yet released any versions using 'dmn-' as prefix
> 
> 
> Regards,
> Daniel
> 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] virsh: Fix *-event error string

2016-09-06 Thread Erik Skultety
On 06/09/16 13:17, Christophe Fergeau wrote:
> When using
> virsh net-event non-existing-net
> the error message says that 'either --list or event type is required'
> This is misleading as 'virsh net-event $valid-event-type' is not going
> to work either. What is expected is 'virsh net-event --event
> $valid-event-type'
> 
> This commit fixes the string in pool-event, nodedev-event, event, and
> net-event.
> ---
>  tools/virsh-domain.c  | 2 +-
>  tools/virsh-network.c | 2 +-
>  tools/virsh-nodedev.c | 2 +-
>  tools/virsh-pool.c| 2 +-
>  4 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
> index a614512..702a8bd8 100644
> --- a/tools/virsh-domain.c
> +++ b/tools/virsh-domain.c
> @@ -12694,7 +12694,7 @@ cmdEvent(vshControl *ctl, const vshCmd *cmd)
>  }
>  } else if (!all) {
>  vshError(ctl, "%s",
> - _("one of --list, --all, or event type is required"));
> + _("one of --list, --all, or --event type is required"));
>  return false;
>  }
>  
> diff --git a/tools/virsh-network.c b/tools/virsh-network.c
> index eec7faf..c6bd132 100644
> --- a/tools/virsh-network.c
> +++ b/tools/virsh-network.c
> @@ -1238,7 +1238,7 @@ cmdNetworkEvent(vshControl *ctl, const vshCmd *cmd)
>  if (vshCommandOptStringReq(ctl, cmd, "event", ) < 0)
>  return false;
>  if (!eventName) {
> -vshError(ctl, "%s", _("either --list or event type is required"));
> +vshError(ctl, "%s", _("either --list or --event type is required"));
>  return false;
>  }
>  if ((event = virshNetworkEventIdTypeFromString(eventName)) < 0) {
> diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c
> index 805c0ff..0e695b9 100644
> --- a/tools/virsh-nodedev.c
> +++ b/tools/virsh-nodedev.c
> @@ -903,7 +903,7 @@ cmdNodeDeviceEvent(vshControl *ctl, const vshCmd *cmd)
>  if (vshCommandOptStringReq(ctl, cmd, "event", ) < 0)
>  return false;
>  if (!eventName) {
> -vshError(ctl, "%s", _("either --list or event type is required"));
> +vshError(ctl, "%s", _("either --list or --event type is required"));
>  return false;
>  }
>  
> diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c
> index d25851e..70b2bdd 100644
> --- a/tools/virsh-pool.c
> +++ b/tools/virsh-pool.c
> @@ -2057,7 +2057,7 @@ cmdPoolEvent(vshControl *ctl, const vshCmd *cmd)
>  if (vshCommandOptStringReq(ctl, cmd, "event", ) < 0)
>  return false;
>  if (!eventName) {
> -vshError(ctl, "%s", _("either --list or event type is required"));
> +vshError(ctl, "%s", _("either --list or --event type is required"));
>  return false;
>  }
>  

ACK, although, I have a really small nitpick the decision on fixing of
which I leave to you. After the fix, "--list or --event type...", at
least to me, sounds like "--event" was the mentioned type itself which
is of course wrong. Maybe it could be better (just an idea) to use angle
brackets like this '' to make the message more clear, but as I
said, your call.

Regards,
Erik

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] virt-admin commands aliases

2016-09-06 Thread Erik Skultety
On 06/09/16 11:52, Martin Kletzander wrote:
> On Tue, Sep 06, 2016 at 09:02:19AM +0200, Erik Skultety wrote:
>> On 05/09/16 19:48, Daniel P. Berrange wrote:
>>> On Mon, Sep 05, 2016 at 05:37:07PM +0200, Erik Skultety wrote:
>>>> Hi there,
>>>>
>>>> after my presentation at KVM Forum, it was pointed out from the
>>>> audience
>>>> that we might think about doing something about the naming of the
>>>> virt-admin's comands, since there is some sort of inconsistency: srv-
>>>> vs. client- vs. dmn- (not merged yet). When I sent patches to
>>>> upstream I
>>>> already knew that the naming was not optimal, but I didn't come up with
>>>> anything better so I hoped that the reviewer might think of something
>>>> better which unfortunately did not happen.
>>>>
>>>> Anyway, there are multiple options how this can be approached but I'm
>>>> not 100% satisfied with neither of them:
>>>>
>>>> 1) rename the commands completely
>>>> Although clean, obviously this is the non-preferred option because this
>>>> would break any backwards compatibility however, I think there is a
>>>> fair
>>>> chance that people haven't actually started using it yet (although that
>>>> might change between 7.3 and 7.4).
>>>>
>>>> 2) create aliases for non-abbreviated forms of the commands
>>>> That way, srv- would become server- and dmn- would become daemon-.
>>>> However, by doing this we'll end up with 6 almost identical entries in
>>>> the commands structure which might be error-prone once we decide to
>>>> add/create a flag to the command primitive, since the flag would
>>>> have to be added both to the alias and to the original (unlikely, but
>>>> possible that someone might forget about that)
>>>>
>>>> 3) abbreviate client- to something like clnt-
>>>> Identical to the above except for the amount of duplicate entries which
>>>> would be reduced to 2
>>>>
>>>> 4) leave it as is if such a consensus is reached and accepted
>>>> I guess this does no need any additional comments.
>>>
>>> I just vote for 4.
>>>
>>> In retrospect it would have been nice to use 'server' instead of
>>> 'srv', but ultimately it isn't a functional problem.  The "solutions"
>>> create extra code and/or inconsitency and/or break back-compat so just
>>> aren't worth it IMHO.
>>>
>>
>> Yeah, for me personally, it was either number 2 or 4 but as you write,
>> both of them suck in their own way and I just could not decide which one
>> sucked less.
>>
>> Thanks for opinions guys, appreciated :)
>>
> 
> I, honestly, would go with #2.  I know you know it, but to recapitulate;
> we already have a wiring in the code for aliases, so if you change:
> 
>{.name = "srv-list",
> .handler = cmdSrvList,
> .opts = NULL,
> .info = info_srv_list,
> .flags = 0
>},
> 
> to:
>{.name = "server-list",
> .handler = cmdSrvList,
> .opts = NULL,
> .info = info_srv_list,
> .flags = 0
>},
>{.name = "srv-list",
> .handler = cmdSrvList,
> .opts = NULL,
> .info = info_srv_list,
> .flags = VSH_CMD_FLAG_ALIAS
>},
> 
> You will have both commands, you will only see the 'server-list' in the
> help and both will work.  The only thing you need to change is, that if
> you add options to the commands that don't have any (yet), you need to
> add the opts_srv_list to both commands.  But that's it.  For
> srv-clients-list (BTW why isn't it named list-clients or client-list)
> that would require no future change.  I know you mentioned that flag
> changes would need to be done in both structures as well, but honestly,
> thre's VSH_CMD_FLAG_NOCONNECT and VSH_CMD_FLAG_ALIAS.  And that's it.
> And I don't think we'll have any new flags anytime soon.  I even dare to
> say never.
> 
> But even if you don't like that, there are ways to mitigate even this
> duplication.  Just make VSH_CMD_FLAG_ALIAS work as VSH_OT_ALIAS.  That
> is just make the following work:
> 
>{.name = "server-list",
> .handler = cmdSrvList,
> .opts = NULL,
> .info = info_srv_list,
> .flags = 0
>},
>{.name = "srv-list",
> .flags = VSH_CMD_FLAG_ALIAS,
> .aliased = "server-list"
>},
> 

Hmm, well you'll still end up with N more entries (possibly) creating
more unne

[libvirt] [PATCH] virt-admin: Document srv-list command in virt-admin's man page

2016-09-07 Thread Erik Skultety
srv-list command was missing in the man page.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 tools/virt-admin.pod | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/tools/virt-admin.pod b/tools/virt-admin.pod
index 2199038..c74707a 100644
--- a/tools/virt-admin.pod
+++ b/tools/virt-admin.pod
@@ -143,6 +143,20 @@ libvirtd:///system is used.
 
 =back
 
+=head1 DAEMON COMMANDS
+
+Following commands allow to monitor daemon's state as well as directly change
+its internal configuration.
+
+=over 4
+
+=item B
+
+Lists all manageable servers on daemon the client is currently connected to
+through administration interface.
+
+=back
+
 =head1 SERVER COMMANDS
 
 Following commands manipulate daemon's server internal configuration.
-- 
2.5.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] virt-admin: Output srv-clients-set data as unsigned int rather than signed

2016-09-07 Thread Erik Skultety
Unfortunately, commit a8962f70 only fixed first half of the reported issue of
virt-admin outputting negative values where unsigned int is expected by
BZ below, so this commit represents the other missing half of the fix.

resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1356769

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
Pushed under trivial rule.
Erik

 tools/virt-admin.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/virt-admin.c b/tools/virt-admin.c
index 513054b..12ec057 100644
--- a/tools/virt-admin.c
+++ b/tools/virt-admin.c
@@ -857,7 +857,7 @@ cmdSrvClientsInfo(vshControl *ctl, const vshCmd *cmd)
 }
 
 for (i = 0; i < nparams; i++)
-vshPrint(ctl, "%-20s: %d\n", params[i].field, params[i].value.ui);
+vshPrint(ctl, "%-20s: %u\n", params[i].field, params[i].value.ui);
 
 ret = true;
 
-- 
2.5.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] virt-admin: Fix some English grammar in the manpage

2016-09-08 Thread Erik Skultety
Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 tools/virt-admin.pod | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Pushed as trivial.

diff --git a/tools/virt-admin.pod b/tools/virt-admin.pod
index 0195001..020eb51 100644
--- a/tools/virt-admin.pod
+++ b/tools/virt-admin.pod
@@ -159,7 +159,7 @@ currently connected to.
 
 =head1 SERVER COMMANDS
 
-Following commands manipulate daemon's server internal configuration.
+The following commands manipulate daemon's server internal configuration.
 The I is specified by its name.
 
 =over 4
@@ -281,7 +281,7 @@ I<--max-clients>.
 
 =head1 CLIENT COMMANDS
 
-Following commands provide management and monitoring of clients connected to
+The following commands provide management and monitoring of clients connected 
to
 one of daemon's available servers. Clients are specified by their numeric ID
 which is obtained by listing all clients connected to a specified server
 (see command B).
-- 
2.5.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] virt-admin: Document srv-list command in virt-admin's man page

2016-09-08 Thread Erik Skultety
On 08/09/16 10:27, Andrea Bolognani wrote:
> On Wed, 2016-09-07 at 13:43 +0200, Erik Skultety wrote:
>> srv-list command was missing in the man page.
>>  
>> Signed-off-by: Erik Skultety <eskul...@redhat.com>
>> ---
>>   tools/virt-admin.pod | 14 ++
>>   1 file changed, 14 insertions(+)
>>  
>> diff --git a/tools/virt-admin.pod b/tools/virt-admin.pod
>> index 2199038..c74707a 100644
>> --- a/tools/virt-admin.pod
>> +++ b/tools/virt-admin.pod
>> @@ -143,6 +143,20 @@ libvirtd:///system is used.
>>   
>>   =back
>>   
>> +=head1 DAEMON COMMANDS
>> +
>> +Following commands allow to monitor daemon's state as well as directly 
>> change
>> +its internal configuration.
> 
> s/Following/The following/
> s/daemon's/the daemon's/
> 
> Moreover, I see "Following commands" is used throughout the
> man page: all other occurences should probably be changed as
> well, in a separate patch of course.
> 

Yep,
http://dictionary.cambridge.org/grammar/british-grammar/following-or-the-following,
it makes sense, thanks for pointing that out, I can add English to my
"TO LEARN" list once again :Panyway, I adjusted and pushed along
with the separate patch you mentioned.

Erik

>> +
>> +=over 4
>> +
>> +=item B
>> +
>> +Lists all manageable servers on daemon the client is currently connected to
>> +through administration interface.
> 
> How about something like this?
> 
>   List all manageable servers that are part of the deamon the
>   client is currently connected to.
> 
> I'm not sure if "being part of" is a technically sound
> description of the relationship between servers and daemons,
> you tell me ;) But "on" doesn't sound right either.
> 
> I removed the "through administration interface" bit because
> it seemed quite redundant - this is virt-admin(1) after all,
> so of course all connections we might refer to will have been
> made through the admin interface.
> 
>> +
>> +=back
>> +
>>   =head1 SERVER COMMANDS
>>   
>>   Following commands manipulate daemon's server internal configuration.
> 
> ACK whether or not you decide to go with my suggested changes,
> as the additional documentation is valuable as is and I'm no
> native speaker either :)
> 
> -- 
> Andrea Bolognani / Red Hat / Virtualization
> 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 4/4] virt-admin: Replace the (now) aliases with new command names in the man page

2016-09-12 Thread Erik Skultety
Since the old command names are being shadowed by the new ones in the code as
well as in the help messages, update the man page accordingly.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 tools/virt-admin.pod | 30 +++---
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/tools/virt-admin.pod b/tools/virt-admin.pod
index 020eb51..443730e 100644
--- a/tools/virt-admin.pod
+++ b/tools/virt-admin.pod
@@ -150,7 +150,7 @@ change its internal configuration.
 
 =over 4
 
-=item B
+=item B
 
 Lists all manageable servers contained within the daemon the client is
 currently connected to.
@@ -164,7 +164,7 @@ The I is specified by its name.
 
 =over 4
 
-=item B I
+=item B I
 
 Retrieve server's threadpool attributes. These attributes include:
 
@@ -207,11 +207,11 @@ control and libvirt guarantees that such a task cannot 
hang, thus will always
 finish. An example of such a task this would be destroying a domain:
 $ virsh destroy .
 
-=item B I [I<--min-workers> B]
+=item B I [I<--min-workers> B]
 [I<--max-workers> B] [I<--priority-workers> B]
 
 Change threadpool attributes on a server. Only a fraction of all attributes as
-described in I is supported for the setter.
+described in I is supported for the setter.
 
 =over 4
 
@@ -232,14 +232,7 @@ The current number of active priority workers in a 
threadpool.
 
 =back
 
-=item B I
-
-Print a table showing the list of clients connected to , also providing
-information about transport type used on client's connection (supported
-transports include B, B, and B), as well as providing
-information about client's connection time (system local time is used).
-
-=item B I
+=item B I
 
 Get information about the current setting of limits regarding connections of 
new
 clients. This information comprises of the limits to the maximum number of
@@ -249,13 +242,13 @@ runtime values, more specifically, the current number of 
clients connected to
 I and the current number of clients waiting for authentication.
 
 B
-# virt-admin srv-clients-info libvirtd
+# virt-admin server-clients-info libvirtd
 nclients_max: 120
 nclients: 3
 nclients_unauth_max : 20
 nclients_unauth : 0
 
-=item B I [I<--max-clients> B]
+=item B I [I<--max-clients> B]
 [I<--max-unauth-clients> B]
 
 Set new client-related limits on I.
@@ -284,10 +277,17 @@ I<--max-clients>.
 The following commands provide management and monitoring of clients connected 
to
 one of daemon's available servers. Clients are specified by their numeric ID
 which is obtained by listing all clients connected to a specified server
-(see command B).
+(see command B).
 
 =over 4
 
+=item B I
+
+Print a table showing the list of clients connected to , also providing
+information about transport type used on client's connection (supported
+transports include B, B, and B), as well as providing
+information about client's connection time (system local time is used).
+
 =item B I I
 
 Retrieve identity information about I from I. The attributes
-- 
2.5.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 0/4] Introduce aliases for virt-admin's srv-* commands

2016-09-12 Thread Erik Skultety
So, as suggested by Martin in [1], this series tweaks the command alias
handling logic, so that when creating alias, it is not necessary to duplicate
the original command's structure, thus creating a bit more noise. Instead,
the new format for an alias structure hints very clearly that it's just an
alias for a different command, while linking the alias with the original
command's data by using new element '.alias'.

[1] https://www.redhat.com/archives/libvir-list/2016-September/msg00129.html

Erik Skultety (4):
  tests: fix incorrect status handling by virsh-self-test
  virt-admin: Tweak command parsing logic so that aliases point to new
commands
  virt-admin: Add some command aliases to provide syntax sugar over ugly
commands
  virt-admin: Replace the (now) aliases with new command names in the
man page

 tests/virsh-self-test |  2 +-
 tools/virsh-nodedev.c |  6 ++
 tools/virsh.c |  3 ++-
 tools/virt-admin.c| 24 
 tools/virt-admin.pod  | 30 +++---
 tools/vsh.c   |  6 ++
 tools/vsh.h   |  1 +
 7 files changed, 51 insertions(+), 21 deletions(-)

-- 
2.5.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 3/4] virt-admin: Add some command aliases to provide syntax sugar over ugly commands

2016-09-12 Thread Erik Skultety
Make use of the new recently introduced alias handling for virt-admin srv-*
commands.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 tools/virt-admin.c | 24 
 1 file changed, 24 insertions(+)

diff --git a/tools/virt-admin.c b/tools/virt-admin.c
index 12ec057..5d6beda 100644
--- a/tools/virt-admin.c
+++ b/tools/virt-admin.c
@@ -1265,18 +1265,30 @@ static const vshCmdDef vshAdmCmds[] = {
 
 static const vshCmdDef monitoringCmds[] = {
 {.name = "srv-list",
+ .flags = VSH_CMD_FLAG_ALIAS,
+ .alias = "server-list"
+},
+{.name = "server-list",
  .handler = cmdSrvList,
  .opts = NULL,
  .info = info_srv_list,
  .flags = 0
 },
 {.name = "srv-threadpool-info",
+ .flags = VSH_CMD_FLAG_ALIAS,
+ .alias = "server-threadpool-info"
+},
+{.name = "server-threadpool-info",
  .handler = cmdSrvThreadpoolInfo,
  .opts = opts_srv_threadpool_info,
  .info = info_srv_threadpool_info,
  .flags = 0
 },
 {.name = "srv-clients-list",
+ .flags = VSH_CMD_FLAG_ALIAS,
+ .alias = "client-list"
+},
+{.name = "client-list",
  .handler = cmdSrvClientsList,
  .opts = opts_srv_clients_list,
  .info = info_srv_clients_list,
@@ -1289,6 +1301,10 @@ static const vshCmdDef monitoringCmds[] = {
  .flags = 0
 },
 {.name = "srv-clients-info",
+ .flags = VSH_CMD_FLAG_ALIAS,
+ .alias = "server-clients-info"
+},
+{.name = "server-clients-info",
  .handler = cmdSrvClientsInfo,
  .opts = opts_srv_clients_info,
  .info = info_srv_clients_info,
@@ -1299,6 +1315,10 @@ static const vshCmdDef monitoringCmds[] = {
 
 static const vshCmdDef managementCmds[] = {
 {.name = "srv-threadpool-set",
+ .flags = VSH_CMD_FLAG_ALIAS,
+ .alias = "server-threadpool-set"
+},
+{.name = "server-threadpool-set",
  .handler = cmdSrvThreadpoolSet,
  .opts = opts_srv_threadpool_set,
  .info = info_srv_threadpool_set,
@@ -1311,6 +1331,10 @@ static const vshCmdDef managementCmds[] = {
  .flags = 0
 },
 {.name = "srv-clients-set",
+ .flags = VSH_CMD_FLAG_ALIAS,
+ .alias = "server-clients-set"
+},
+{.name = "server-clients-set",
  .handler = cmdSrvClientsSet,
  .opts = opts_srv_clients_set,
  .info = info_srv_clients_set,
-- 
2.5.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 1/4] tests: fix incorrect status handling by virsh-self-test

2016-09-12 Thread Erik Skultety
The virsh-self-test script compared the test's return code with 1 and only if
the return code matched this value then the test was marked as failed. Problem
is that SIGSEGV returns 139 (or 11 to be precise, since shell reserves the MSB
for abnormal exit signaling) which passes the check just fine and test then
appears as successful which it most certainly wasn't.
Therefore, flip the logic to compare against 0 instead and every other result
will be treated as a failed test case.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 tests/virsh-self-test | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/virsh-self-test b/tests/virsh-self-test
index c51fcf4..641810f 100755
--- a/tests/virsh-self-test
+++ b/tests/virsh-self-test
@@ -28,7 +28,7 @@ $abs_top_builddir/tools/virsh -c $test_url self-test > 
/dev/null
 status=$?
 test_result 1 "virsh-self-test" $status
 
-if test "$status" = "1" ; then
+if test "$status" != "0" ; then
fail=1
 fi
 
-- 
2.5.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 2/4] virt-admin: Tweak command parsing logic so that aliases point to new commands

2016-09-12 Thread Erik Skultety
Change the logic in a way, so that VSH_CMD_FLAG_ALIAS behaves similarly to
how VSH_OT_ALIAS for command options, i.e. there is no need for code duplication
for the alias and the aliased command structures. Along with that change,
switch any existing VSH_CMD_FLAG_ALIAS occurrences to this new format.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 tools/virsh-nodedev.c | 6 ++
 tools/virsh.c | 3 ++-
 tools/vsh.c   | 6 ++
 tools/vsh.h   | 1 +
 4 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c
index 321f15c..9446664 100644
--- a/tools/virsh-nodedev.c
+++ b/tools/virsh-nodedev.c
@@ -986,10 +986,8 @@ const vshCmdDef nodedevCmds[] = {
  .flags = 0
 },
 {.name = "nodedev-dettach",
- .handler = cmdNodeDeviceDetach,
- .opts = opts_node_device_detach,
- .info = info_node_device_detach,
- .flags = VSH_CMD_FLAG_ALIAS
+ .flags = VSH_CMD_FLAG_ALIAS,
+ .alias = "nodedev-detach"
 },
 {.name = "nodedev-dumpxml",
  .handler = cmdNodeDeviceDumpXML,
diff --git a/tools/virsh.c b/tools/virsh.c
index cb60edc..60fb02b 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -904,7 +904,8 @@ static const vshCmdDef virshCmds[] = {
  .handler = cmdSelfTest,
  .opts = NULL,
  .info = info_selftest,
- .flags = VSH_CMD_FLAG_NOCONNECT | VSH_CMD_FLAG_ALIAS
+ .flags = VSH_CMD_FLAG_NOCONNECT | VSH_CMD_FLAG_ALIAS,
+ .alias = "self-test"
 },
 {.name = NULL}
 };
diff --git a/tools/vsh.c b/tools/vsh.c
index be6a073..ad3e1c7 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -1410,6 +1410,12 @@ vshCommandParse(vshControl *ctl, vshCommandParser 
*parser)
 vshError(ctl, _("unknown command: '%s'"), tkdata);
 goto syntaxError;   /* ... or ignore this command only? */
 }
+/* aliases need to be resolved to the actual commands */
+if (cmd->flags & VSH_CMD_FLAG_ALIAS) {
+VIR_FREE(tkdata);
+tkdata = vshStrdup(ctl, cmd->alias);
+cmd = vshCmddefSearch(tkdata);
+}
 if (vshCmddefOptParse(cmd, _need_arg,
   _required) < 0) {
 vshError(ctl,
diff --git a/tools/vsh.h b/tools/vsh.h
index e53910f..e383e54 100644
--- a/tools/vsh.h
+++ b/tools/vsh.h
@@ -179,6 +179,7 @@ struct _vshCmdDef {
 const vshCmdOptDef *opts;   /* definition of command options */
 const vshCmdInfo *info; /* details about command */
 unsigned int flags; /* bitwise OR of VSH_CMD_FLAG */
+const char *alias;  /* name of the aliased command */
 };
 
 /*
-- 
2.5.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 2/3] virt-admin: Add some command aliases to provide syntax sugar over ugly commands

2016-09-13 Thread Erik Skultety
Make use of the new recently introduced alias handling for virt-admin srv-*
commands.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 tools/virt-admin.c | 24 
 1 file changed, 24 insertions(+)

diff --git a/tools/virt-admin.c b/tools/virt-admin.c
index 12ec057..5d6beda 100644
--- a/tools/virt-admin.c
+++ b/tools/virt-admin.c
@@ -1265,18 +1265,30 @@ static const vshCmdDef vshAdmCmds[] = {
 
 static const vshCmdDef monitoringCmds[] = {
 {.name = "srv-list",
+ .flags = VSH_CMD_FLAG_ALIAS,
+ .alias = "server-list"
+},
+{.name = "server-list",
  .handler = cmdSrvList,
  .opts = NULL,
  .info = info_srv_list,
  .flags = 0
 },
 {.name = "srv-threadpool-info",
+ .flags = VSH_CMD_FLAG_ALIAS,
+ .alias = "server-threadpool-info"
+},
+{.name = "server-threadpool-info",
  .handler = cmdSrvThreadpoolInfo,
  .opts = opts_srv_threadpool_info,
  .info = info_srv_threadpool_info,
  .flags = 0
 },
 {.name = "srv-clients-list",
+ .flags = VSH_CMD_FLAG_ALIAS,
+ .alias = "client-list"
+},
+{.name = "client-list",
  .handler = cmdSrvClientsList,
  .opts = opts_srv_clients_list,
  .info = info_srv_clients_list,
@@ -1289,6 +1301,10 @@ static const vshCmdDef monitoringCmds[] = {
  .flags = 0
 },
 {.name = "srv-clients-info",
+ .flags = VSH_CMD_FLAG_ALIAS,
+ .alias = "server-clients-info"
+},
+{.name = "server-clients-info",
  .handler = cmdSrvClientsInfo,
  .opts = opts_srv_clients_info,
  .info = info_srv_clients_info,
@@ -1299,6 +1315,10 @@ static const vshCmdDef monitoringCmds[] = {
 
 static const vshCmdDef managementCmds[] = {
 {.name = "srv-threadpool-set",
+ .flags = VSH_CMD_FLAG_ALIAS,
+ .alias = "server-threadpool-set"
+},
+{.name = "server-threadpool-set",
  .handler = cmdSrvThreadpoolSet,
  .opts = opts_srv_threadpool_set,
  .info = info_srv_threadpool_set,
@@ -1311,6 +1331,10 @@ static const vshCmdDef managementCmds[] = {
  .flags = 0
 },
 {.name = "srv-clients-set",
+ .flags = VSH_CMD_FLAG_ALIAS,
+ .alias = "server-clients-set"
+},
+{.name = "server-clients-set",
  .handler = cmdSrvClientsSet,
  .opts = opts_srv_clients_set,
  .info = info_srv_clients_set,
-- 
2.5.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 1/3] virt-admin: Tweak command parsing logic so that aliases point to new commands

2016-09-13 Thread Erik Skultety
Change the logic in a way, so that VSH_CMD_FLAG_ALIAS behaves similarly to
how VSH_OT_ALIAS for command options, i.e. there is no need for code duplication
for the alias and the aliased command structures. Along with that change,
switch any existing VSH_CMD_FLAG_ALIAS occurrences to this new format. Also,
since this patch introduces a new command structure element, adjust the
virsh-self-test test to make sure we won't ever miss to specify the '.alias'
member for an aliased command because doing that would lead to a segfault, as
would be the case for any missing element of the command structure.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 tools/virsh-nodedev.c |  6 ++
 tools/virsh.c | 10 ++
 tools/virsh.pod   |  2 --
 tools/vsh.c   |  6 ++
 tools/vsh.h   |  1 +
 5 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c
index 321f15c..9446664 100644
--- a/tools/virsh-nodedev.c
+++ b/tools/virsh-nodedev.c
@@ -986,10 +986,8 @@ const vshCmdDef nodedevCmds[] = {
  .flags = 0
 },
 {.name = "nodedev-dettach",
- .handler = cmdNodeDeviceDetach,
- .opts = opts_node_device_detach,
- .info = info_node_device_detach,
- .flags = VSH_CMD_FLAG_ALIAS
+ .flags = VSH_CMD_FLAG_ALIAS,
+ .alias = "nodedev-detach"
 },
 {.name = "nodedev-dumpxml",
  .handler = cmdNodeDeviceDumpXML,
diff --git a/tools/virsh.c b/tools/virsh.c
index cb60edc..918058c 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -373,10 +373,11 @@ cmdSelfTest(vshControl *ctl, const vshCmd *cmd 
ATTRIBUTE_UNUSED)
 
 for (grp = cmdGroups; grp->name; grp++) {
 for (def = grp->commands; def->name; def++) {
-if (def->flags & VSH_CMD_FLAG_ALIAS)
-continue;
+const vshCmdDef *c = def;
+if (c->flags & VSH_CMD_FLAG_ALIAS)
+c = vshCmddefSearch(c->alias);
 
-if (!vshCmddefHelp(ctl, def->name))
+if (!vshCmddefHelp(ctl, c->name))
 return false;
 }
 }
@@ -904,7 +905,8 @@ static const vshCmdDef virshCmds[] = {
  .handler = cmdSelfTest,
  .opts = NULL,
  .info = info_selftest,
- .flags = VSH_CMD_FLAG_NOCONNECT | VSH_CMD_FLAG_ALIAS
+ .flags = VSH_CMD_FLAG_NOCONNECT | VSH_CMD_FLAG_ALIAS,
+ .alias = "self-test"
 },
 {.name = NULL}
 };
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 3da7879..49abda9 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -2936,8 +2936,6 @@ make that device unusable by the rest of the physical 
host until a reboot.
 Detach I from the host, so that it can safely be used by
 guests via  passthrough.  This is reversed with
 B, and is done automatically for managed devices.
-For compatibility purposes, this command can also be spelled
-B.
 
 Different backend drivers expect the device to be bound to different
 dummy devices. For example, QEMU's "kvm" backend driver (the default)
diff --git a/tools/vsh.c b/tools/vsh.c
index be6a073..ad3e1c7 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -1410,6 +1410,12 @@ vshCommandParse(vshControl *ctl, vshCommandParser 
*parser)
 vshError(ctl, _("unknown command: '%s'"), tkdata);
 goto syntaxError;   /* ... or ignore this command only? */
 }
+/* aliases need to be resolved to the actual commands */
+if (cmd->flags & VSH_CMD_FLAG_ALIAS) {
+VIR_FREE(tkdata);
+tkdata = vshStrdup(ctl, cmd->alias);
+cmd = vshCmddefSearch(tkdata);
+}
 if (vshCmddefOptParse(cmd, _need_arg,
   _required) < 0) {
 vshError(ctl,
diff --git a/tools/vsh.h b/tools/vsh.h
index e53910f..e383e54 100644
--- a/tools/vsh.h
+++ b/tools/vsh.h
@@ -179,6 +179,7 @@ struct _vshCmdDef {
 const vshCmdOptDef *opts;   /* definition of command options */
 const vshCmdInfo *info; /* details about command */
 unsigned int flags; /* bitwise OR of VSH_CMD_FLAG */
+const char *alias;  /* name of the aliased command */
 };
 
 /*
-- 
2.5.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 0/3] Introduce aliases for virt-admin's srv-* commands

2016-09-13 Thread Erik Skultety
the original version:
https://www.redhat.com/archives/libvir-list/2016-September/msg00312.html

since v1:
- tweaked the virsh-self-test so that it also checks the aliased commands
instead of skipping them (since there was a good reason for that before the
changes this series introduces)
- patches 2-3 remained untouched

Erik Skultety (3):
  virt-admin: Tweak command parsing logic so that aliases point to new
commands
  virt-admin: Add some command aliases to provide syntax sugar over ugly
commands
  virt-admin: Replace the (now) aliases with new command names in the
man page

 tools/virsh-nodedev.c |  6 ++
 tools/virsh.c | 10 ++
 tools/virsh.pod   |  2 --
 tools/virt-admin.c| 24 
 tools/virt-admin.pod  | 30 +++---
 tools/vsh.c   |  6 ++
 tools/vsh.h   |  1 +
 7 files changed, 54 insertions(+), 25 deletions(-)

-- 
2.5.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 3/3] virt-admin: Replace the (now) aliases with new command names in the man page

2016-09-13 Thread Erik Skultety
Since the old command names are being shadowed by the new ones in the code as
well as in the help messages, update the man page accordingly.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 tools/virt-admin.pod | 30 +++---
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/tools/virt-admin.pod b/tools/virt-admin.pod
index 020eb51..443730e 100644
--- a/tools/virt-admin.pod
+++ b/tools/virt-admin.pod
@@ -150,7 +150,7 @@ change its internal configuration.
 
 =over 4
 
-=item B
+=item B
 
 Lists all manageable servers contained within the daemon the client is
 currently connected to.
@@ -164,7 +164,7 @@ The I is specified by its name.
 
 =over 4
 
-=item B I
+=item B I
 
 Retrieve server's threadpool attributes. These attributes include:
 
@@ -207,11 +207,11 @@ control and libvirt guarantees that such a task cannot 
hang, thus will always
 finish. An example of such a task this would be destroying a domain:
 $ virsh destroy .
 
-=item B I [I<--min-workers> B]
+=item B I [I<--min-workers> B]
 [I<--max-workers> B] [I<--priority-workers> B]
 
 Change threadpool attributes on a server. Only a fraction of all attributes as
-described in I is supported for the setter.
+described in I is supported for the setter.
 
 =over 4
 
@@ -232,14 +232,7 @@ The current number of active priority workers in a 
threadpool.
 
 =back
 
-=item B I
-
-Print a table showing the list of clients connected to , also providing
-information about transport type used on client's connection (supported
-transports include B, B, and B), as well as providing
-information about client's connection time (system local time is used).
-
-=item B I
+=item B I
 
 Get information about the current setting of limits regarding connections of 
new
 clients. This information comprises of the limits to the maximum number of
@@ -249,13 +242,13 @@ runtime values, more specifically, the current number of 
clients connected to
 I and the current number of clients waiting for authentication.
 
 B
-# virt-admin srv-clients-info libvirtd
+# virt-admin server-clients-info libvirtd
 nclients_max: 120
 nclients: 3
 nclients_unauth_max : 20
 nclients_unauth : 0
 
-=item B I [I<--max-clients> B]
+=item B I [I<--max-clients> B]
 [I<--max-unauth-clients> B]
 
 Set new client-related limits on I.
@@ -284,10 +277,17 @@ I<--max-clients>.
 The following commands provide management and monitoring of clients connected 
to
 one of daemon's available servers. Clients are specified by their numeric ID
 which is obtained by listing all clients connected to a specified server
-(see command B).
+(see command B).
 
 =over 4
 
+=item B I
+
+Print a table showing the list of clients connected to , also providing
+information about transport type used on client's connection (supported
+transports include B, B, and B), as well as providing
+information about client's connection time (system local time is used).
+
 =item B I I
 
 Retrieve identity information about I from I. The attributes
-- 
2.5.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 2/2] tests: Self test virt-admin

2016-09-14 Thread Erik Skultety
On 14/09/16 12:50, Michal Privoznik wrote:
> On 14.09.2016 12:39, Erik Skultety wrote:
>> On 14/09/16 10:17, Michal Privoznik wrote:
>>> Just like we are running 'virsh self-test' from within our test
>>> suite, we should run 'virt-admin self-test' too.
>>>
>>> Signed-off-by: Michal Privoznik <mpriv...@redhat.com>
>>> ---
>>>  .gitignore |  1 +
>>>  tests/Makefile.am  |  1 +
>>>  tests/virsh-self-test  | 21 -
>>>  tests/virt-admin-self-test |  1 +
>>>  tools/virt-admin.c |  1 +
>>>  5 files changed, 20 insertions(+), 5 deletions(-)
>>>  create mode 12 tests/virt-admin-self-test
>>>
>>> diff --git a/.gitignore b/.gitignore
>>> index e87c085..879ec24 100644
>>> --- a/.gitignore
>>> +++ b/.gitignore
>>> @@ -169,6 +169,7 @@
>>>  /tests/qemucapsprobe
>>>  !/tests/virsh-self-test
>>>  !/tests/virt-aa-helper-test
>>> +!/tests/virt-admin-self-test
>>>  /tests/objectlocking
>>>  /tests/objectlocking-files.txt
>>>  /tests/objectlocking.cm[ix]
>>> diff --git a/tests/Makefile.am b/tests/Makefile.am
>>> index 0cd8391..924029a 100644
>>> --- a/tests/Makefile.am
>>> +++ b/tests/Makefile.am
>>> @@ -369,6 +369,7 @@ libvirtd_test_scripts = \
>>> virsh-read-non-seekable \
>>> virsh-schedinfo \
>>> virsh-self-test \
>>> +   virt-admin-self-test\
>>> virsh-start \
>>> virsh-undefine  \
>>> virsh-uriprecedence \
>>> diff --git a/tests/virsh-self-test b/tests/virsh-self-test
>>> index 641810f..22396bc 100755
>>> --- a/tests/virsh-self-test
>>> +++ b/tests/virsh-self-test
>>> @@ -21,14 +21,25 @@
>>>  
>>>  fail=0
>>>  
>>> -test_url=test:///default
>>> +basename=$(basename $0)
>>>  
>>> -test_intro "virsh-self-test"
>>> -$abs_top_builddir/tools/virsh -c $test_url self-test > /dev/null
>>> +if test "x$basename" = "xvirsh-self-test" ; then
>>> +binary=virsh
>>> +extra_args="-c test:///default"
>>> +elif test "x$basename" = "xvirt-admin-self-test" ; then
>>> +binary=virt-admin
>>> +extra_args=""
>>> +else
>>> +echo "Unknown binary: $basename";
>>> +exit 1
>>> +fi
>>> +
>>> +test_intro "$0"
>>> +$abs_top_builddir/tools/${binary} ${extra_args} self-test > /dev/null
>>>  status=$?
>>> -test_result 1 "virsh-self-test" $status
>>> +test_result 1 "$0" ${status}
>>>  
>>> -if test "$status" != "0" ; then
>>> +if test "${status}" != "0" ; then
>>> fail=1
>>>  fi
>>>  
>>> diff --git a/tests/virt-admin-self-test b/tests/virt-admin-self-test
>>> new file mode 12
>>
>> Although a working solution, we would end up with two identical scripts.
> 
> Well, the virt-admin-self-test is really just a symlink to
> virsh-self-test (which can handle the case if run under different name).
> 

Sigh... never mind, ACK.
Erik

>> How about extracting the generic bit (since you've already refactored
>> the hunk above, thus putting some effort into making it nicely generic),
>> and enclosing it into a separate function and a separate module, e.g.
>> self_test() and let's say module virt-shell-test (or whatever) and then
>> just source it the same way as we do it with test-lib.sh from within
>> virsh-self-test and virt-admin-self-test.
> 
> Well, I like the symlink approach better. What you described is just
> more work IMO ;-)
> 
> Michal
> 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 2/2] tests: Self test virt-admin

2016-09-14 Thread Erik Skultety
On 14/09/16 10:17, Michal Privoznik wrote:
> Just like we are running 'virsh self-test' from within our test
> suite, we should run 'virt-admin self-test' too.
> 
> Signed-off-by: Michal Privoznik 
> ---
>  .gitignore |  1 +
>  tests/Makefile.am  |  1 +
>  tests/virsh-self-test  | 21 -
>  tests/virt-admin-self-test |  1 +
>  tools/virt-admin.c |  1 +
>  5 files changed, 20 insertions(+), 5 deletions(-)
>  create mode 12 tests/virt-admin-self-test
> 
> diff --git a/.gitignore b/.gitignore
> index e87c085..879ec24 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -169,6 +169,7 @@
>  /tests/qemucapsprobe
>  !/tests/virsh-self-test
>  !/tests/virt-aa-helper-test
> +!/tests/virt-admin-self-test
>  /tests/objectlocking
>  /tests/objectlocking-files.txt
>  /tests/objectlocking.cm[ix]
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index 0cd8391..924029a 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -369,6 +369,7 @@ libvirtd_test_scripts =   \
>   virsh-read-non-seekable \
>   virsh-schedinfo \
>   virsh-self-test \
> + virt-admin-self-test\
>   virsh-start \
>   virsh-undefine  \
>   virsh-uriprecedence \
> diff --git a/tests/virsh-self-test b/tests/virsh-self-test
> index 641810f..22396bc 100755
> --- a/tests/virsh-self-test
> +++ b/tests/virsh-self-test
> @@ -21,14 +21,25 @@
>  
>  fail=0
>  
> -test_url=test:///default
> +basename=$(basename $0)
>  
> -test_intro "virsh-self-test"
> -$abs_top_builddir/tools/virsh -c $test_url self-test > /dev/null
> +if test "x$basename" = "xvirsh-self-test" ; then
> +binary=virsh
> +extra_args="-c test:///default"
> +elif test "x$basename" = "xvirt-admin-self-test" ; then
> +binary=virt-admin
> +extra_args=""
> +else
> +echo "Unknown binary: $basename";
> +exit 1
> +fi
> +
> +test_intro "$0"
> +$abs_top_builddir/tools/${binary} ${extra_args} self-test > /dev/null
>  status=$?
> -test_result 1 "virsh-self-test" $status
> +test_result 1 "$0" ${status}
>  
> -if test "$status" != "0" ; then
> +if test "${status}" != "0" ; then
> fail=1
>  fi
>  
> diff --git a/tests/virt-admin-self-test b/tests/virt-admin-self-test
> new file mode 12

Although a working solution, we would end up with two identical scripts.
How about extracting the generic bit (since you've already refactored
the hunk above, thus putting some effort into making it nicely generic),
and enclosing it into a separate function and a separate module, e.g.
self_test() and let's say module virt-shell-test (or whatever) and then
just source it the same way as we do it with test-lib.sh from within
virsh-self-test and virt-admin-self-test.

Erik

> index 000..d4ad624
> --- /dev/null
> +++ b/tests/virt-admin-self-test
> @@ -0,0 +1 @@
> +./virsh-self-test
> \ No newline at end of file
> diff --git a/tools/virt-admin.c b/tools/virt-admin.c
> index 12ec057..36c92f5 100644
> --- a/tools/virt-admin.c
> +++ b/tools/virt-admin.c
> @@ -1242,6 +1242,7 @@ static const vshCmdDef vshAdmCmds[] = {
>  VSH_CMD_HELP,
>  VSH_CMD_PWD,
>  VSH_CMD_QUIT,
> +VSH_CMD_SELF_TEST,
>  {.name = "uri",
>   .handler = cmdURI,
>   .opts = NULL,
> 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 1/2] virsh: Move cmdSelfTest to vsh

2016-09-14 Thread Erik Skultety
On 14/09/16 10:17, Michal Privoznik wrote:
> This command should be exposed to other shells of ours.
> They are gonna need it as soon as we want to test them too.
> 
> Signed-off-by: Michal Privoznik 
> ---
>  tools/virsh.c | 45 +
>  tools/vsh.c   | 38 ++
>  tools/vsh.h   | 11 +++
>  3 files changed, 50 insertions(+), 44 deletions(-)
> 
> diff --git a/tools/virsh.c b/tools/virsh.c
> index cb60edc..1068447 100644
> --- a/tools/virsh.c
> +++ b/tools/virsh.c
> @@ -346,44 +346,6 @@ virshConnectionHandler(vshControl *ctl)
>  return NULL;
>  }
>  
> -/* -
> - * Command self-test
> - * - */
> -
> -static const vshCmdInfo info_selftest[] = {
> -{.name = "help",
> - .data = N_("internal command for testing virsh")
> -},
> -{.name = "desc",
> - .data = N_("internal use only")
> -},
> -{.name = NULL}
> -};
> -
> -/* Prints help for every command.
> - * That runs vshCmddefOptParse which validates
> - * the per-command options structure. */
> -static bool
> -cmdSelfTest(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
> -{
> -const vshCmdGrp *grp;
> -const vshCmdDef *def;
> -
> -vshPrint(ctl, "Do not use the following output:\n\n");
> -
> -for (grp = cmdGroups; grp->name; grp++) {
> -for (def = grp->commands; def->name; def++) {
> -if (def->flags & VSH_CMD_FLAG_ALIAS)
> -continue;
> -
> -if (!vshCmddefHelp(ctl, def->name))
> -return false;
> -}
> -}
> -
> -return true;
> -}
> -
>  
>  /* ---
>   * Misc utils
> @@ -894,18 +856,13 @@ static const vshCmdDef virshCmds[] = {
>  VSH_CMD_HELP,
>  VSH_CMD_PWD,
>  VSH_CMD_QUIT,
> +VSH_CMD_SELF_TEST,
>  {.name = "connect",
>   .handler = cmdConnect,
>   .opts = opts_connect,
>   .info = info_connect,
>   .flags = VSH_CMD_FLAG_NOCONNECT
>  },
> -{.name = "self-test",
> - .handler = cmdSelfTest,
> - .opts = NULL,
> - .info = info_selftest,
> - .flags = VSH_CMD_FLAG_NOCONNECT | VSH_CMD_FLAG_ALIAS
> -},
>  {.name = NULL}
>  };
>  
> diff --git a/tools/vsh.c b/tools/vsh.c
> index be6a073..c51bdd7 100644
> --- a/tools/vsh.c
> +++ b/tools/vsh.c
> @@ -3328,3 +3328,41 @@ cmdQuit(vshControl *ctl, const vshCmd *cmd 
> ATTRIBUTE_UNUSED)
>  ctl->imode = false;
>  return true;
>  }
> +
> +/* -
> + * Command self-test
> + * - */
> +
> +const vshCmdInfo info_selftest[] = {
> +{.name = "help",
> + .data = N_("internal command for testing virsh")
> +},

s/virsh/virt shells/ or something alike you can come up with :)
ACK

Erik

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v2 0/3] Introduce aliases for virt-admin's srv-* commands

2016-09-14 Thread Erik Skultety
On 13/09/16 17:11, Erik Skultety wrote:
> the original version:
> https://www.redhat.com/archives/libvir-list/2016-September/msg00312.html
> 
> since v1:
> - tweaked the virsh-self-test so that it also checks the aliased commands
> instead of skipping them (since there was a good reason for that before 
> the
> changes this series introduces)
> - patches 2-3 remained untouched
> 
> Erik Skultety (3):
>   virt-admin: Tweak command parsing logic so that aliases point to new
> commands
>   virt-admin: Add some command aliases to provide syntax sugar over ugly
> commands
>   virt-admin: Replace the (now) aliases with new command names in the
> man page
> 
>  tools/virsh-nodedev.c |  6 ++
>  tools/virsh.c | 10 ++
>  tools/virsh.pod   |  2 --
>  tools/virt-admin.c| 24 
>  tools/virt-admin.pod  | 30 +++---
>  tools/vsh.c   |  6 ++
>  tools/vsh.h   |  1 +
>  7 files changed, 54 insertions(+), 25 deletions(-)
> 

SNACK. Having an error like "internal error: bad command options" would
be nice indeed - thanks Michal [1] - which could be achieved by a tiny
refactor, also fixing a semantically incorrect check that can cause a
segfault on missing '.info' as well, pretty much the same way as the
missing '.alias' does.

[1] https://www.redhat.com/archives/libvir-list/2016-September/msg00386.html

Erik

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 2/4] virt-admin: Tweak command parsing logic so that aliases point to new commands

2016-09-13 Thread Erik Skultety
On 13/09/16 14:30, Michal Privoznik wrote:
> On 12.09.2016 10:20, Erik Skultety wrote:
>> Change the logic in a way, so that VSH_CMD_FLAG_ALIAS behaves similarly to
>> how VSH_OT_ALIAS for command options, i.e. there is no need for code 
>> duplication
>> for the alias and the aliased command structures. Along with that change,
>> switch any existing VSH_CMD_FLAG_ALIAS occurrences to this new format.
>>
>> Signed-off-by: Erik Skultety <eskul...@redhat.com>
>> ---
>>  tools/virsh-nodedev.c | 6 ++
>>  tools/virsh.c | 3 ++-
>>  tools/vsh.c   | 6 ++
>>  tools/vsh.h   | 1 +
>>  4 files changed, 11 insertions(+), 5 deletions(-)
>>
>> diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c
>> index 321f15c..9446664 100644
>> --- a/tools/virsh-nodedev.c
>> +++ b/tools/virsh-nodedev.c
>> @@ -986,10 +986,8 @@ const vshCmdDef nodedevCmds[] = {
>>   .flags = 0
>>  },
>>  {.name = "nodedev-dettach",
>> - .handler = cmdNodeDeviceDetach,
>> - .opts = opts_node_device_detach,
>> - .info = info_node_device_detach,
>> - .flags = VSH_CMD_FLAG_ALIAS
>> + .flags = VSH_CMD_FLAG_ALIAS,
>> + .alias = "nodedev-detach"
> 
> I think that if we do this we should just stop using the misspelled
> version. I mean, drop it from the man page, do not offer it for
> autocompletion.

Oh, I completely missed that one, I would never expected that we
actually document our (so far) only alias in the man page...

> Also, you need to update vshCmddefCheckInternals() to check whether all

^^not the correct spot to check, that is intended just for the command
opts (therefore internals) not for the command itself, so the command
structure should be checked in the vshCommandParse() function.

> commands passing VSH_CMD_FLAG_ALIAS also set .alias. Otherwise we will
> segfault later.

Aand I disagree, if we return just an error code, executing such a
command from virsh is visually a noop ==> so no-go. If we also error out
what purpose would the message serve to the user? Let's say a message
like "missing .alias element", it's our internal static structure and
such an error would have absolutely no meaning (and no value) to the
user because the error would not be caused by a certain combination of
user inputs, exposing a flaw in our logic, rather it is an incorrect
hard-coded setting in the binary.

Additionally, if we went your way, we would have to add a check
preventing a segfault for any missing element in the command structure
for every command, let's say '.opts' element, you'll experience a
segfault in that case as well, but since commit 920ab8bd you'll be
notified about this fact by the self-test command - see my further
comments below.

> 
>>  },
>>  {.name = "nodedev-dumpxml",
>>   .handler = cmdNodeDeviceDumpXML,
>> diff --git a/tools/virsh.c b/tools/virsh.c
>> index cb60edc..60fb02b 100644
>> --- a/tools/virsh.c
>> +++ b/tools/virsh.c
>> @@ -904,7 +904,8 @@ static const vshCmdDef virshCmds[] = {
>>   .handler = cmdSelfTest,
>>   .opts = NULL,
>>   .info = info_selftest,
>> - .flags = VSH_CMD_FLAG_NOCONNECT | VSH_CMD_FLAG_ALIAS
>> + .flags = VSH_CMD_FLAG_NOCONNECT | VSH_CMD_FLAG_ALIAS,
>> + .alias = "self-test"
> 
> So this is just for demonstration purposes? It seems so to me.

Well, omitting the .alias element would segfault as you pointed out, but
adding it here, although pointing to itself, was imho easier than adding
a check if an aliased command does have the .handler element filled in,
so it would be used instead of looking at the .alias element. This
command is also used for testing purposes only (thus it's hidden) and
this is actually the *right* spot to have a check, if an aliased command
also has the '.alias' element filled properly, because this test is
supposed to make us aware of such mistakes when someone adds a command,
but forgets to fill out certain structure element.

Regards,
Erik

> 
>>  },
>>  {.name = NULL}
>>  };
>> diff --git a/tools/vsh.c b/tools/vsh.c
>> index be6a073..ad3e1c7 100644
>> --- a/tools/vsh.c
>> +++ b/tools/vsh.c
>> @@ -1410,6 +1410,12 @@ vshCommandParse(vshControl *ctl, vshCommandParser 
>> *parser)
>>  vshError(ctl, _("unknown command: '%s'"), tkdata);
>>  goto syntaxError;   /* ... or ignore this command only? 
>> */
>>  }
>> +/* aliases need to be resolved to the actual commands */
>> +if (cmd->flags & VSH_CMD_FLAG_ALIAS) {
>> +  

[libvirt] [PATCH v3 6/8] virt-admin: Tweak command parsing logic so that aliases point to new commands

2016-09-16 Thread Erik Skultety
Change the logic in a way, so that VSH_CMD_FLAG_ALIAS behaves similarly to
how VSH_OT_ALIAS for command options, i.e. there is no need for code duplication
for the alias and the aliased command structures. Along with that change,
switch any existing VSH_CMD_FLAG_ALIAS occurrences to this new format. Also,
since this patch introduces a new command structure element, adjust the
virsh-self-test test to make sure we won't ever miss to specify the '.alias'
member for an aliased command because doing that would lead to an internal
error.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 tools/virsh-nodedev.c |  6 ++
 tools/virsh.pod   |  2 --
 tools/vsh.c   | 15 +--
 tools/vsh.h   |  4 +++-
 4 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c
index 321f15c..9446664 100644
--- a/tools/virsh-nodedev.c
+++ b/tools/virsh-nodedev.c
@@ -986,10 +986,8 @@ const vshCmdDef nodedevCmds[] = {
  .flags = 0
 },
 {.name = "nodedev-dettach",
- .handler = cmdNodeDeviceDetach,
- .opts = opts_node_device_detach,
- .info = info_node_device_detach,
- .flags = VSH_CMD_FLAG_ALIAS
+ .flags = VSH_CMD_FLAG_ALIAS,
+ .alias = "nodedev-detach"
 },
 {.name = "nodedev-dumpxml",
  .handler = cmdNodeDeviceDumpXML,
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 3da7879..49abda9 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -2936,8 +2936,6 @@ make that device unusable by the rest of the physical 
host until a reboot.
 Detach I from the host, so that it can safely be used by
 guests via  passthrough.  This is reversed with
 B, and is done automatically for managed devices.
-For compatibility purposes, this command can also be spelled
-B.
 
 Different backend drivers expect the device to be bound to different
 dummy devices. For example, QEMU's "kvm" backend driver (the default)
diff --git a/tools/vsh.c b/tools/vsh.c
index a66e2f9..88a6f37 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -329,6 +329,9 @@ vshCmddefCheckInternals(const vshCmdDef *cmd)
 {
 size_t i;
 
+if (cmd->flags & VSH_CMD_FLAG_ALIAS && !cmd->alias)
+return -1;
+
 if (!cmd->opts)
 return 0;
 
@@ -1408,6 +1411,13 @@ vshCommandParse(vshControl *ctl, vshCommandParser 
*parser)
 vshError(ctl, _("unknown command: '%s'"), tkdata);
 goto syntaxError;   /* ... or ignore this command only? */
 }
+
+/* aliases need to be resolved to the actual commands */
+if (cmd->flags & VSH_CMD_FLAG_ALIAS) {
+VIR_FREE(tkdata);
+tkdata = vshStrdup(ctl, cmd->alias);
+cmd = vshCmddefSearch(tkdata);
+}
 if (vshCmddefCheckInternals(cmd) < 0) {
 vshError(ctl, _("internal error: wrong command structure: "
 "'%s'"), tkdata);
@@ -3359,10 +3369,11 @@ cmdSelfTest(vshControl *ctl, const vshCmd *cmd 
ATTRIBUTE_UNUSED)
 
 for (grp = cmdGroups; grp->name; grp++) {
 for (def = grp->commands; def->name; def++) {
+const vshCmdDef *c = def;
 if (def->flags & VSH_CMD_FLAG_ALIAS)
-continue;
+c = vshCmddefSearch(c->alias);
 
-if (!vshCmddefHelp(ctl, def->name))
+if (!vshCmddefHelp(ctl, c->name))
 return false;
 }
 }
diff --git a/tools/vsh.h b/tools/vsh.h
index 7f08191..8f5d1a6 100644
--- a/tools/vsh.h
+++ b/tools/vsh.h
@@ -179,6 +179,7 @@ struct _vshCmdDef {
 const vshCmdOptDef *opts;   /* definition of command options */
 const vshCmdInfo *info; /* details about command */
 unsigned int flags; /* bitwise OR of VSH_CMD_FLAG */
+const char *alias;  /* name of the aliased command */
 };
 
 /*
@@ -445,7 +446,8 @@ bool cmdSelfTest(vshControl *ctl, const vshCmd *cmd);
 .handler = cmdSelfTest, \
 .opts = NULL,   \
 .info = info_selftest,  \
-.flags = VSH_CMD_FLAG_NOCONNECT | VSH_CMD_FLAG_ALIAS\
+.flags = VSH_CMD_FLAG_NOCONNECT | VSH_CMD_FLAG_ALIAS,\
+.alias = "self-test"\
 }
 
 
-- 
2.5.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v3 2/8] vsh: vshCmddefHelp: Drop the unnecessary 'else' branch

2016-09-16 Thread Erik Skultety
If the initial check is true the function immediately returns so there's no
need to enclose the code following the check within an 'else' block.
Also, by removing the 'else' block, the declarations need to be moved to
beginning of the function block to conform with our guidelines.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 tools/vsh.c | 222 ++--
 1 file changed, 111 insertions(+), 111 deletions(-)

diff --git a/tools/vsh.c b/tools/vsh.c
index 3772d92..4c63bd3 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -624,131 +624,131 @@ bool
 vshCmddefHelp(vshControl *ctl, const char *cmdname)
 {
 const vshCmdDef *def = vshCmddefSearch(cmdname);
+/* Don't translate desc if it is "".  */
+const char *desc = vshCmddefGetInfo(def, "desc");
+const char *help = _(vshCmddefGetInfo(def, "help"));
+char buf[256];
+uint64_t opts_need_arg;
+uint64_t opts_required;
+bool shortopt = false; /* true if 'arg' works instead of '--opt arg' */
 
 if (!def) {
 vshError(ctl, _("command '%s' doesn't exist"), cmdname);
 return false;
-} else {
-/* Don't translate desc if it is "".  */
-const char *desc = vshCmddefGetInfo(def, "desc");
-const char *help = _(vshCmddefGetInfo(def, "help"));
-char buf[256];
-uint64_t opts_need_arg;
-uint64_t opts_required;
-bool shortopt = false; /* true if 'arg' works instead of '--opt arg' */
-
-if (vshCmddefOptParse(def, _need_arg, _required)) {
-vshError(ctl, _("internal error: bad options in command: '%s'"),
- def->name);
-return false;
-}
+}
 
-fputs(_("  NAME\n"), stdout);
-fprintf(stdout, "%s - %s\n", def->name, help);
-
-fputs(_("\n  SYNOPSIS\n"), stdout);
-fprintf(stdout, "%s", def->name);
-if (def->opts) {
-const vshCmdOptDef *opt;
-for (opt = def->opts; opt->name; opt++) {
-const char *fmt = "%s";
-switch (opt->type) {
-case VSH_OT_BOOL:
-fmt = "[--%s]";
-break;
-case VSH_OT_INT:
-/* xgettext:c-format */
-fmt = ((opt->flags & VSH_OFLAG_REQ) ? "<%s>"
-   : _("[--%s ]"));
-if (!(opt->flags & VSH_OFLAG_REQ_OPT))
-shortopt = true;
-break;
-case VSH_OT_STRING:
-/* xgettext:c-format */
-fmt = _("[--%s ]");
-if (!(opt->flags & VSH_OFLAG_REQ_OPT))
-shortopt = true;
-break;
-case VSH_OT_DATA:
-fmt = ((opt->flags & VSH_OFLAG_REQ) ? "<%s>" : "[<%s>]");
-if (!(opt->flags & VSH_OFLAG_REQ_OPT))
-shortopt = true;
-break;
-case VSH_OT_ARGV:
-/* xgettext:c-format */
-if (shortopt) {
-fmt = (opt->flags & VSH_OFLAG_REQ)
-? _("{[--%s] }...")
-: _("[[--%s] ]...");
-} else {
-fmt = (opt->flags & VSH_OFLAG_REQ) ? _("<%s>...")
-: _("[<%s>]...");
-}
-break;
-case VSH_OT_ALIAS:
-/* aliases are intentionally undocumented */
-continue;
+if (vshCmddefOptParse(def, _need_arg, _required)) {
+vshError(ctl, _("internal error: bad options in command: '%s'"),
+ def->name);
+return false;
+}
+
+fputs(_("  NAME\n"), stdout);
+fprintf(stdout, "%s - %s\n", def->name, help);
+
+fputs(_("\n  SYNOPSIS\n"), stdout);
+fprintf(stdout, "%s", def->name);
+if (def->opts) {
+const vshCmdOptDef *opt;
+for (opt = def->opts; opt->name; opt++) {
+const char *fmt = "%s";
+switch (opt->type) {
+case VSH_OT_BOOL:
+fmt = "[--%s]";
+break;
+case VSH_OT_INT:
+/* xgettext:c-format */
+fmt = ((opt->flags & VSH_OFLAG_REQ) ? "<%s>"
+   : _("[--%s ]"));
+if (!(opt->flags & VSH_OFLAG_REQ_OPT))
+s

<    3   4   5   6   7   8   9   10   11   12   >