From e0127260fb4a22d591f3b8d0326021506fc0504e Mon Sep 17 00:00:00 2001 From: Jiri Denemark Date: Thu, 9 Jan 2020 15:40:14 +0100 Subject: [PATCH] qemu: Don't use NULL path from qemuDomainGetHostdevPath 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 Reviewed-by: Michal Privoznik --- 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) && -- GitLab