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 <jdenemar@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Jiri Denemark 2020-01-09 15:40:14 +01:00
parent 143b71a8ec
commit e0127260fb
2 changed files with 23 additions and 18 deletions

View File

@ -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)) {

View File

@ -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) &&