[libvirt] [PATCH] qemu: Don't use NULL path from qemuDomainGetHostdevPath

Jiri Denemark posted 1 patch 30 weeks ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/24cfc22a690378b6a9aac89bd173811b49e71596.1578581446.git.jdenemar@redhat.com
src/qemu/qemu_cgroup.c | 32 ++++++++++++++++++--------------
src/qemu/qemu_domain.c |  9 +++++----
2 files changed, 23 insertions(+), 18 deletions(-)

[libvirt] [PATCH] qemu: Don't use NULL path from qemuDomainGetHostdevPath

Posted by Jiri Denemark 30 weeks ago
Commit v5.10.0-290-g3a4787a301 refactored qemuDomainGetHostdevPath to
return a single path rather than an array of paths. When the function is
called on a missing device, it will now return NULL in @path rather than
a NULL array with zero items and the callers need to be adapted
properly.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/qemu/qemu_cgroup.c | 32 ++++++++++++++++++--------------
 src/qemu/qemu_domain.c |  9 +++++----
 2 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 2bcc0527f6..45701b4c6e 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -426,13 +426,15 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm,
     if (qemuDomainGetHostdevPath(dev, &path, &perms) < 0)
         return -1;
 
-    VIR_DEBUG("Cgroup allow %s perms=%d", path, perms);
-    rv = virCgroupAllowDevicePath(priv->cgroup, path, perms, false);
-    virDomainAuditCgroupPath(vm, priv->cgroup, "allow", path,
-                             virCgroupGetDevicePermsString(perms),
-                             rv);
-    if (rv < 0)
-        return -1;
+    if (path) {
+        VIR_DEBUG("Cgroup allow %s perms=%d", path, perms);
+        rv = virCgroupAllowDevicePath(priv->cgroup, path, perms, false);
+        virDomainAuditCgroupPath(vm, priv->cgroup, "allow", path,
+                                 virCgroupGetDevicePermsString(perms),
+                                 rv);
+        if (rv < 0)
+            return -1;
+    }
 
     if (qemuHostdevNeedsVFIO(dev)) {
         VIR_DEBUG("Cgroup allow %s perms=%d", QEMU_DEV_VFIO, VIR_CGROUP_DEVICE_RW);
@@ -473,13 +475,15 @@ qemuTeardownHostdevCgroup(virDomainObjPtr vm,
     if (qemuDomainGetHostdevPath(dev, &path, NULL) < 0)
         return -1;
 
-    VIR_DEBUG("Cgroup deny %s", path);
-    rv = virCgroupDenyDevicePath(priv->cgroup, path,
-                                 VIR_CGROUP_DEVICE_RWM, false);
-    virDomainAuditCgroupPath(vm, priv->cgroup,
-                             "deny", path, "rwm", rv);
-    if (rv < 0)
-        return -1;
+    if (path) {
+        VIR_DEBUG("Cgroup deny %s", path);
+        rv = virCgroupDenyDevicePath(priv->cgroup, path,
+                                     VIR_CGROUP_DEVICE_RWM, false);
+        virDomainAuditCgroupPath(vm, priv->cgroup,
+                                 "deny", path, "rwm", rv);
+        if (rv < 0)
+            return -1;
+    }
 
     if (qemuHostdevNeedsVFIO(dev) &&
         !qemuDomainNeedsVFIO(vm->def)) {
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 24e84a5966..1f358544ab 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -14001,7 +14001,8 @@ qemuDomainNeedsVFIO(const virDomainDef *def)
  *
  * For given device @dev fetch its host path and store it at
  * @path. Optionally, caller can get @perms on the path (e.g.
- * rw/ro).
+ * rw/ro). When called on a missing device, the function will return success
+ * and store NULL at @path.
  *
  * The caller is responsible for freeing the @path when no longer
  * needed.
@@ -14625,7 +14626,7 @@ qemuDomainSetupHostdev(virQEMUDriverConfigPtr cfg G_GNUC_UNUSED,
     if (qemuDomainGetHostdevPath(dev, &path, NULL) < 0)
         return -1;
 
-    if (qemuDomainCreateDevice(path, data, false) < 0)
+    if (path && qemuDomainCreateDevice(path, data, false) < 0)
         return -1;
 
     if (qemuHostdevNeedsVFIO(dev) &&
@@ -15688,7 +15689,7 @@ qemuDomainNamespaceSetupHostdev(virDomainObjPtr vm,
     if (qemuDomainGetHostdevPath(hostdev, &path, NULL) < 0)
         return -1;
 
-    if (qemuDomainNamespaceMknodPath(vm, path) < 0)
+    if (path && qemuDomainNamespaceMknodPath(vm, path) < 0)
         return -1;
 
     if (qemuHostdevNeedsVFIO(hostdev) &&
@@ -15720,7 +15721,7 @@ qemuDomainNamespaceTeardownHostdev(virDomainObjPtr vm,
     if (qemuDomainGetHostdevPath(hostdev, &path, NULL) < 0)
         return -1;
 
-    if (qemuDomainNamespaceUnlinkPath(vm, path) < 0)
+    if (path && qemuDomainNamespaceUnlinkPath(vm, path) < 0)
         return -1;
 
     if (qemuHostdevNeedsVFIO(hostdev) &&
-- 
2.24.1

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

Re: [libvirt] [PATCH] qemu: Don't use NULL path from qemuDomainGetHostdevPath

Posted by Michal Privoznik 30 weeks ago
On 1/9/20 3:50 PM, Jiri Denemark wrote:
> Commit v5.10.0-290-g3a4787a301 refactored qemuDomainGetHostdevPath to
> return a single path rather than an array of paths. When the function is
> called on a missing device, it will now return NULL in @path rather than
> a NULL array with zero items and the callers need to be adapted
> properly.
> 
> Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
> ---
>   src/qemu/qemu_cgroup.c | 32 ++++++++++++++++++--------------
>   src/qemu/qemu_domain.c |  9 +++++----
>   2 files changed, 23 insertions(+), 18 deletions(-)

Why do I have the feeling that I've seen this patch somewhere? ;-)

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

Michal

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