提交 3a4787a3 编写于 作者: M Michal Privoznik

qemuDomainGetHostdevPath: Don't include /dev/vfio/vfio in returned paths

Now that all callers of qemuDomainGetHostdevPath() handle
/dev/vfio/vfio on their own, we can safely drop handling in this
function. In near future the decision whether domain needs VFIO
file is going to include more device types than just
virDomainHostdev.
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
Reviewed-by: NCole Robinson <crobinso@redhat.com>
上级 f9765165
...@@ -375,26 +375,23 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm, ...@@ -375,26 +375,23 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm,
virDomainHostdevDefPtr dev) virDomainHostdevDefPtr dev)
{ {
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
char **path = NULL; g_autofree char *path = NULL;
int *perms = NULL; int perms;
size_t i, npaths = 0;
int rv, ret = -1; int rv, ret = -1;
if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES))
return 0; return 0;
if (qemuDomainGetHostdevPath(NULL, dev, false, &npaths, &path, &perms) < 0) if (qemuDomainGetHostdevPath(dev, &path, &perms) < 0)
goto cleanup; goto cleanup;
for (i = 0; i < npaths; i++) { VIR_DEBUG("Cgroup allow %s perms=%d", path, perms);
VIR_DEBUG("Cgroup allow %s perms=%d", path[i], perms[i]); rv = virCgroupAllowDevicePath(priv->cgroup, path, perms, false);
rv = virCgroupAllowDevicePath(priv->cgroup, path[i], perms[i], false); virDomainAuditCgroupPath(vm, priv->cgroup, "allow", path,
virDomainAuditCgroupPath(vm, priv->cgroup, "allow", path[i], virCgroupGetDevicePermsString(perms),
virCgroupGetDevicePermsString(perms[i]), rv);
rv); if (rv < 0)
if (rv < 0) goto cleanup;
goto cleanup;
}
if (qemuHostdevNeedsVFIO(dev)) { if (qemuHostdevNeedsVFIO(dev)) {
VIR_DEBUG("Cgroup allow %s perms=%d", QEMU_DEV_VFIO, VIR_CGROUP_DEVICE_RW); VIR_DEBUG("Cgroup allow %s perms=%d", QEMU_DEV_VFIO, VIR_CGROUP_DEVICE_RW);
...@@ -409,10 +406,6 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm, ...@@ -409,10 +406,6 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm,
ret = 0; ret = 0;
cleanup: cleanup:
for (i = 0; i < npaths; i++)
VIR_FREE(path[i]);
VIR_FREE(path);
VIR_FREE(perms);
return ret; return ret;
} }
...@@ -433,26 +426,22 @@ qemuTeardownHostdevCgroup(virDomainObjPtr vm, ...@@ -433,26 +426,22 @@ qemuTeardownHostdevCgroup(virDomainObjPtr vm,
virDomainHostdevDefPtr dev) virDomainHostdevDefPtr dev)
{ {
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
char **path = NULL; g_autofree char *path = NULL;
size_t i, npaths = 0;
int rv, ret = -1; int rv, ret = -1;
if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES))
return 0; return 0;
if (qemuDomainGetHostdevPath(vm->def, dev, true, if (qemuDomainGetHostdevPath(dev, &path, NULL) < 0)
&npaths, &path, NULL) < 0)
goto cleanup; goto cleanup;
for (i = 0; i < npaths; i++) { VIR_DEBUG("Cgroup deny %s", path);
VIR_DEBUG("Cgroup deny %s", path[i]); rv = virCgroupDenyDevicePath(priv->cgroup, path,
rv = virCgroupDenyDevicePath(priv->cgroup, path[i], VIR_CGROUP_DEVICE_RWM, false);
VIR_CGROUP_DEVICE_RWM, false); virDomainAuditCgroupPath(vm, priv->cgroup,
virDomainAuditCgroupPath(vm, priv->cgroup, "deny", path, "rwm", rv);
"deny", path[i], "rwm", rv); if (rv < 0)
if (rv < 0) goto cleanup;
goto cleanup;
}
if (qemuHostdevNeedsVFIO(dev) && if (qemuHostdevNeedsVFIO(dev) &&
!qemuDomainNeedsVFIO(vm->def)) { !qemuDomainNeedsVFIO(vm->def)) {
...@@ -467,9 +456,6 @@ qemuTeardownHostdevCgroup(virDomainObjPtr vm, ...@@ -467,9 +456,6 @@ qemuTeardownHostdevCgroup(virDomainObjPtr vm,
ret = 0; ret = 0;
cleanup: cleanup:
for (i = 0; i < npaths; i++)
VIR_FREE(path[i]);
VIR_FREE(path);
return ret; return ret;
} }
......
...@@ -13822,29 +13822,23 @@ qemuDomainNeedsVFIO(const virDomainDef *def) ...@@ -13822,29 +13822,23 @@ qemuDomainNeedsVFIO(const virDomainDef *def)
/** /**
* qemuDomainGetHostdevPath: * qemuDomainGetHostdevPath:
* @def: domain definition
* @dev: host device definition * @dev: host device definition
* @teardown: true if device will be removed
* @npaths: number of items in @path and @perms arrays
* @path: resulting path to @dev * @path: resulting path to @dev
* @perms: Optional pointer to VIR_CGROUP_DEVICE_* perms * @perms: Optional pointer to VIR_CGROUP_DEVICE_* perms
* *
* For given device @dev fetch its host path and store it at * For given device @dev fetch its host path and store it at
* @path. If a device requires other paths to be present/allowed * @path. Optionally, caller can get @perms on the path (e.g.
* they are stored in the @path array after the actual path. * rw/ro).
* Optionally, caller can get @perms on the path (e.g. rw/ro).
* *
* The caller is responsible for freeing the memory. * The caller is responsible for freeing the @path when no longer
* needed.
* *
* Returns 0 on success, -1 otherwise. * Returns 0 on success, -1 otherwise.
*/ */
int int
qemuDomainGetHostdevPath(virDomainDefPtr def, qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev,
virDomainHostdevDefPtr dev, char **path,
bool teardown, int *perms)
size_t *npaths,
char ***path,
int **perms)
{ {
int ret = -1; int ret = -1;
virDomainHostdevSubsysUSBPtr usbsrc = &dev->source.subsys.u.usb; virDomainHostdevSubsysUSBPtr usbsrc = &dev->source.subsys.u.usb;
...@@ -13857,14 +13851,9 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, ...@@ -13857,14 +13851,9 @@ qemuDomainGetHostdevPath(virDomainDefPtr def,
g_autoptr(virSCSIDevice) scsi = NULL; g_autoptr(virSCSIDevice) scsi = NULL;
g_autoptr(virSCSIVHostDevice) host = NULL; g_autoptr(virSCSIVHostDevice) host = NULL;
g_autofree char *tmpPath = NULL; g_autofree char *tmpPath = NULL;
bool includeVFIO = false;
char **tmpPaths = NULL;
g_autofree int *tmpPerms = NULL; g_autofree int *tmpPerms = NULL;
size_t tmpNpaths = 0;
int perm = 0; int perm = 0;
*npaths = 0;
switch ((virDomainHostdevMode) dev->mode) { switch ((virDomainHostdevMode) dev->mode) {
case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS: case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
switch ((virDomainHostdevSubsysType)dev->source.subsys.type) { switch ((virDomainHostdevSubsysType)dev->source.subsys.type) {
...@@ -13881,12 +13870,6 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, ...@@ -13881,12 +13870,6 @@ qemuDomainGetHostdevPath(virDomainDefPtr def,
goto cleanup; goto cleanup;
perm = VIR_CGROUP_DEVICE_RW; perm = VIR_CGROUP_DEVICE_RW;
if (teardown) {
if (!virDomainDefHasVFIOHostdev(def))
includeVFIO = true;
} else {
includeVFIO = true;
}
} }
break; break;
...@@ -13942,7 +13925,6 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, ...@@ -13942,7 +13925,6 @@ qemuDomainGetHostdevPath(virDomainDefPtr def,
if (!(tmpPath = virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuidstr))) if (!(tmpPath = virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuidstr)))
goto cleanup; goto cleanup;
includeVFIO = true;
perm = VIR_CGROUP_DEVICE_RW; perm = VIR_CGROUP_DEVICE_RW;
break; break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST: case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
...@@ -13956,36 +13938,11 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, ...@@ -13956,36 +13938,11 @@ qemuDomainGetHostdevPath(virDomainDefPtr def,
break; break;
} }
if (tmpPath) { *path = g_steal_pointer(&tmpPath);
size_t toAlloc = 1; if (perms)
*perms = perm;
if (includeVFIO)
toAlloc = 2;
if (VIR_ALLOC_N(tmpPaths, toAlloc) < 0 ||
VIR_ALLOC_N(tmpPerms, toAlloc) < 0)
goto cleanup;
tmpPaths[0] = g_strdup(tmpPath);
tmpNpaths = toAlloc;
tmpPerms[0] = perm;
if (includeVFIO) {
tmpPaths[1] = g_strdup(QEMU_DEV_VFIO);
tmpPerms[1] = VIR_CGROUP_DEVICE_RW;
}
}
*npaths = tmpNpaths;
tmpNpaths = 0;
*path = tmpPaths;
tmpPaths = NULL;
if (perms) {
*perms = tmpPerms;
tmpPerms = NULL;
}
ret = 0; ret = 0;
cleanup: cleanup:
virStringListFreeCount(tmpPaths, tmpNpaths);
return ret; return ret;
} }
...@@ -14486,16 +14443,13 @@ qemuDomainSetupHostdev(virQEMUDriverConfigPtr cfg G_GNUC_UNUSED, ...@@ -14486,16 +14443,13 @@ qemuDomainSetupHostdev(virQEMUDriverConfigPtr cfg G_GNUC_UNUSED,
const struct qemuDomainCreateDeviceData *data) const struct qemuDomainCreateDeviceData *data)
{ {
int ret = -1; int ret = -1;
char **path = NULL; g_autofree char *path = NULL;
size_t i, npaths = 0;
if (qemuDomainGetHostdevPath(NULL, dev, false, &npaths, &path, NULL) < 0) if (qemuDomainGetHostdevPath(dev, &path, NULL) < 0)
goto cleanup; goto cleanup;
for (i = 0; i < npaths; i++) { if (qemuDomainCreateDevice(path, data, false) < 0)
if (qemuDomainCreateDevice(path[i], data, false) < 0) goto cleanup;
goto cleanup;
}
if (qemuHostdevNeedsVFIO(dev) && if (qemuHostdevNeedsVFIO(dev) &&
qemuDomainCreateDevice(QEMU_DEV_VFIO, data, false) < 0) qemuDomainCreateDevice(QEMU_DEV_VFIO, data, false) < 0)
...@@ -14503,9 +14457,6 @@ qemuDomainSetupHostdev(virQEMUDriverConfigPtr cfg G_GNUC_UNUSED, ...@@ -14503,9 +14457,6 @@ qemuDomainSetupHostdev(virQEMUDriverConfigPtr cfg G_GNUC_UNUSED,
ret = 0; ret = 0;
cleanup: cleanup:
for (i = 0; i < npaths; i++)
VIR_FREE(path[i]);
VIR_FREE(path);
return ret; return ret;
} }
...@@ -15540,13 +15491,12 @@ qemuDomainNamespaceSetupHostdev(virDomainObjPtr vm, ...@@ -15540,13 +15491,12 @@ qemuDomainNamespaceSetupHostdev(virDomainObjPtr vm,
virDomainHostdevDefPtr hostdev) virDomainHostdevDefPtr hostdev)
{ {
int ret = -1; int ret = -1;
char **paths = NULL; g_autofree char *path = NULL;
size_t i, npaths = 0;
if (qemuDomainGetHostdevPath(NULL, hostdev, false, &npaths, &paths, NULL) < 0) if (qemuDomainGetHostdevPath(hostdev, &path, NULL) < 0)
goto cleanup; goto cleanup;
if (qemuDomainNamespaceMknodPaths(vm, (const char **)paths, npaths) < 0) if (qemuDomainNamespaceMknodPath(vm, path) < 0)
goto cleanup; goto cleanup;
if (qemuHostdevNeedsVFIO(hostdev) && if (qemuHostdevNeedsVFIO(hostdev) &&
...@@ -15556,9 +15506,6 @@ qemuDomainNamespaceSetupHostdev(virDomainObjPtr vm, ...@@ -15556,9 +15506,6 @@ qemuDomainNamespaceSetupHostdev(virDomainObjPtr vm,
ret = 0; ret = 0;
cleanup: cleanup:
for (i = 0; i < npaths; i++)
VIR_FREE(paths[i]);
VIR_FREE(paths);
return ret; return ret;
} }
...@@ -15579,14 +15526,12 @@ qemuDomainNamespaceTeardownHostdev(virDomainObjPtr vm, ...@@ -15579,14 +15526,12 @@ qemuDomainNamespaceTeardownHostdev(virDomainObjPtr vm,
virDomainHostdevDefPtr hostdev) virDomainHostdevDefPtr hostdev)
{ {
int ret = -1; int ret = -1;
char **paths = NULL; g_autofree char *path = NULL;
size_t i, npaths = 0;
if (qemuDomainGetHostdevPath(vm->def, hostdev, true, if (qemuDomainGetHostdevPath(hostdev, &path, NULL) < 0)
&npaths, &paths, NULL) < 0)
goto cleanup; goto cleanup;
if (qemuDomainNamespaceUnlinkPaths(vm, (const char **)paths, npaths) < 0) if (qemuDomainNamespaceUnlinkPath(vm, path) < 0)
goto cleanup; goto cleanup;
if (qemuHostdevNeedsVFIO(hostdev) && if (qemuHostdevNeedsVFIO(hostdev) &&
...@@ -15596,9 +15541,6 @@ qemuDomainNamespaceTeardownHostdev(virDomainObjPtr vm, ...@@ -15596,9 +15541,6 @@ qemuDomainNamespaceTeardownHostdev(virDomainObjPtr vm,
ret = 0; ret = 0;
cleanup: cleanup:
for (i = 0; i < npaths; i++)
VIR_FREE(paths[i]);
VIR_FREE(paths);
return ret; return ret;
} }
......
...@@ -1099,12 +1099,9 @@ bool qemuDomainSupportsVideoVga(virDomainVideoDefPtr video, ...@@ -1099,12 +1099,9 @@ bool qemuDomainSupportsVideoVga(virDomainVideoDefPtr video,
bool qemuDomainNeedsVFIO(const virDomainDef *def); bool qemuDomainNeedsVFIO(const virDomainDef *def);
int qemuDomainGetHostdevPath(virDomainDefPtr def, int qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev,
virDomainHostdevDefPtr dev, char **path,
bool teardown, int *perms);
size_t *npaths,
char ***path,
int **perms);
int qemuDomainBuildNamespace(virQEMUDriverConfigPtr cfg, int qemuDomainBuildNamespace(virQEMUDriverConfigPtr cfg,
virSecurityManagerPtr mgr, virSecurityManagerPtr mgr,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册