[libvirt] [PATCH 1/7] qemu_cgroup: Kill qemuSetupHostUSBDeviceCgroup

Michal Privoznik posted 7 patches 8 years, 12 months ago
[libvirt] [PATCH 1/7] qemu_cgroup: Kill qemuSetupHostUSBDeviceCgroup
Posted by Michal Privoznik 8 years, 12 months ago
There's no need for this function. Currently it is passed as a
callback to virUSBDeviceFileIterate(). However, USB devices have
just one file path. Therefore we can mimic approach used in
qemuDomainGetHostdevPath() to get path and call
virCgroupAllowDevicePath() directly.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_cgroup.c | 34 +++++++++-------------------------
 1 file changed, 9 insertions(+), 25 deletions(-)

diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 6c90d46d1..7302c43ee 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -260,23 +260,6 @@ qemuSetupInputCgroup(virDomainObjPtr vm,
 }
 
 
-static int
-qemuSetupHostUSBDeviceCgroup(virUSBDevicePtr dev ATTRIBUTE_UNUSED,
-                             const char *path,
-                             void *opaque)
-{
-    virDomainObjPtr vm = opaque;
-    qemuDomainObjPrivatePtr priv = vm->privateData;
-    int ret;
-
-    VIR_DEBUG("Process path '%s' for USB device", path);
-    ret = virCgroupAllowDevicePath(priv->cgroup, path,
-                                   VIR_CGROUP_DEVICE_RW, false);
-    virDomainAuditCgroupPath(vm, priv->cgroup, "allow", path, "rw", ret == 0);
-
-    return ret;
-}
-
 static int
 qemuSetupHostSCSIDeviceCgroup(virSCSIDevicePtr dev ATTRIBUTE_UNUSED,
                               const char *path,
@@ -333,6 +316,7 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm,
     virSCSIDevicePtr scsi = NULL;
     virSCSIVHostDevicePtr host = NULL;
     char *path = NULL;
+    int rv;
 
     /* currently this only does something for PCI devices using vfio
      * for device assignment, but it is called for *all* hostdev
@@ -347,8 +331,6 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm,
         switch ((virDomainHostdevSubsysType) dev->source.subsys.type) {
         case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
             if (pcisrc->backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
-                int rv;
-
                 pci = virPCIDeviceNew(pcisrc->addr.domain,
                                       pcisrc->addr.bus,
                                       pcisrc->addr.slot,
@@ -381,13 +363,15 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm,
                 goto cleanup;
             }
 
-            /* oddly, qemuSetupHostUSBDeviceCgroup doesn't ever
-             * reference the usb object we just created
-             */
-            if (virUSBDeviceFileIterate(usb, qemuSetupHostUSBDeviceCgroup,
-                                        vm) < 0) {
+            if (VIR_STRDUP(path, virUSBDeviceGetPath(usb)) < 0)
+                goto cleanup;
+
+            VIR_DEBUG("Process path '%s' for USB device", path);
+            rv = virCgroupAllowDevicePath(priv->cgroup, path,
+                                          VIR_CGROUP_DEVICE_RW, false);
+            virDomainAuditCgroupPath(vm, priv->cgroup, "allow", path, "rw", rv == 0);
+            if (rv < 0)
                 goto cleanup;
-            }
             break;
 
         case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: {
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 1/7] qemu_cgroup: Kill qemuSetupHostUSBDeviceCgroup
Posted by Marc-André Lureau 8 years, 11 months ago
Hi

On Fri, Feb 10, 2017 at 6:57 PM Michal Privoznik <mprivozn@redhat.com>
wrote:

> There's no need for this function. Currently it is passed as a
> callback to virUSBDeviceFileIterate(). However, USB devices have
> just one file path. Therefore we can mimic approach used in
> qemuDomainGetHostdevPath() to get path and call
> virCgroupAllowDevicePath() directly.
>
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>

 Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

---
>  src/qemu/qemu_cgroup.c | 34 +++++++++-------------------------
>  1 file changed, 9 insertions(+), 25 deletions(-)
>
> diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
> index 6c90d46d1..7302c43ee 100644
> --- a/src/qemu/qemu_cgroup.c
> +++ b/src/qemu/qemu_cgroup.c
> @@ -260,23 +260,6 @@ qemuSetupInputCgroup(virDomainObjPtr vm,
>  }
>
>
> -static int
> -qemuSetupHostUSBDeviceCgroup(virUSBDevicePtr dev ATTRIBUTE_UNUSED,
> -                             const char *path,
> -                             void *opaque)
> -{
> -    virDomainObjPtr vm = opaque;
> -    qemuDomainObjPrivatePtr priv = vm->privateData;
> -    int ret;
> -
> -    VIR_DEBUG("Process path '%s' for USB device", path);
> -    ret = virCgroupAllowDevicePath(priv->cgroup, path,
> -                                   VIR_CGROUP_DEVICE_RW, false);
> -    virDomainAuditCgroupPath(vm, priv->cgroup, "allow", path, "rw", ret
> == 0);
> -
> -    return ret;
> -}
> -
>  static int
>  qemuSetupHostSCSIDeviceCgroup(virSCSIDevicePtr dev ATTRIBUTE_UNUSED,
>                                const char *path,
> @@ -333,6 +316,7 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm,
>      virSCSIDevicePtr scsi = NULL;
>      virSCSIVHostDevicePtr host = NULL;
>      char *path = NULL;
> +    int rv;
>
>      /* currently this only does something for PCI devices using vfio
>       * for device assignment, but it is called for *all* hostdev
> @@ -347,8 +331,6 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm,
>          switch ((virDomainHostdevSubsysType) dev->source.subsys.type) {
>          case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
>              if (pcisrc->backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
> -                int rv;
> -
>                  pci = virPCIDeviceNew(pcisrc->addr.domain,
>                                        pcisrc->addr.bus,
>                                        pcisrc->addr.slot,
> @@ -381,13 +363,15 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm,
>                  goto cleanup;
>              }
>
> -            /* oddly, qemuSetupHostUSBDeviceCgroup doesn't ever
> -             * reference the usb object we just created
> -             */
> -            if (virUSBDeviceFileIterate(usb, qemuSetupHostUSBDeviceCgroup,
> -                                        vm) < 0) {
> +            if (VIR_STRDUP(path, virUSBDeviceGetPath(usb)) < 0)
> +                goto cleanup;
> +
> +            VIR_DEBUG("Process path '%s' for USB device", path);
> +            rv = virCgroupAllowDevicePath(priv->cgroup, path,
> +                                          VIR_CGROUP_DEVICE_RW, false);
> +            virDomainAuditCgroupPath(vm, priv->cgroup, "allow", path,
> "rw", rv == 0);
> +            if (rv < 0)
>                  goto cleanup;
> -            }
>              break;
>
>          case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: {
> --
> 2.11.0
>
> --
> libvir-list mailing list
> libvir-list@redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
>
-- 
Marc-André Lureau
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list