2010-12-16 16:10:54 +00:00
|
|
|
/*
|
|
|
|
* qemu_hostdev.c: QEMU hostdev management
|
|
|
|
*
|
2014-04-26 04:11:05 +00:00
|
|
|
* Copyright (C) 2006-2007, 2009-2014 Red Hat, Inc.
|
2010-12-16 16:10:54 +00:00
|
|
|
* Copyright (C) 2006 Daniel P. Berrange
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2010-12-16 16:10:54 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2013-09-19 15:01:17 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
2010-12-16 16:10:54 +00:00
|
|
|
#include "qemu_hostdev.h"
|
2019-06-25 11:21:39 +00:00
|
|
|
#include "qemu_domain.h"
|
2012-12-12 17:59:27 +00:00
|
|
|
#include "virlog.h"
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2012-12-13 14:52:25 +00:00
|
|
|
#include "virpci.h"
|
2012-12-12 17:04:51 +00:00
|
|
|
#include "virusb.h"
|
2013-05-03 18:07:29 +00:00
|
|
|
#include "virscsi.h"
|
2012-03-06 01:12:44 +00:00
|
|
|
#include "virnetdev.h"
|
2013-09-19 15:01:17 +00:00
|
|
|
#include "virfile.h"
|
2014-03-05 09:58:54 +00:00
|
|
|
#include "virhostdev.h"
|
2020-02-16 21:59:28 +00:00
|
|
|
#include "virutil.h"
|
2010-12-16 16:10:54 +00:00
|
|
|
|
2012-07-18 15:22:03 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_QEMU
|
|
|
|
|
2014-02-28 12:16:17 +00:00
|
|
|
VIR_LOG_INIT("qemu.qemu_hostdev");
|
|
|
|
|
|
|
|
|
2014-03-06 04:32:42 +00:00
|
|
|
int
|
2015-10-20 12:26:30 +00:00
|
|
|
qemuHostdevUpdateActivePCIDevices(virQEMUDriverPtr driver,
|
|
|
|
virDomainDefPtr def)
|
2014-03-06 04:32:42 +00:00
|
|
|
{
|
|
|
|
virHostdevManagerPtr mgr = driver->hostdevMgr;
|
|
|
|
|
|
|
|
if (!def->nhostdevs)
|
|
|
|
return 0;
|
|
|
|
|
2014-03-06 07:48:49 +00:00
|
|
|
return virHostdevUpdateActivePCIDevices(mgr, def->hostdevs, def->nhostdevs,
|
|
|
|
QEMU_DRIVER_NAME, def->name);
|
2014-03-06 04:32:42 +00:00
|
|
|
}
|
|
|
|
|
2014-03-06 04:45:16 +00:00
|
|
|
int
|
2015-10-20 12:26:30 +00:00
|
|
|
qemuHostdevUpdateActiveUSBDevices(virQEMUDriverPtr driver,
|
|
|
|
virDomainDefPtr def)
|
2014-03-06 04:45:16 +00:00
|
|
|
{
|
|
|
|
virHostdevManagerPtr mgr = driver->hostdevMgr;
|
|
|
|
|
|
|
|
if (!def->nhostdevs)
|
|
|
|
return 0;
|
|
|
|
|
2014-03-06 07:48:49 +00:00
|
|
|
return virHostdevUpdateActiveUSBDevices(mgr, def->hostdevs, def->nhostdevs,
|
|
|
|
QEMU_DRIVER_NAME, def->name);
|
2014-03-06 04:45:16 +00:00
|
|
|
}
|
|
|
|
|
2014-03-06 04:47:50 +00:00
|
|
|
int
|
2015-10-20 12:26:30 +00:00
|
|
|
qemuHostdevUpdateActiveSCSIDevices(virQEMUDriverPtr driver,
|
|
|
|
virDomainDefPtr def)
|
2014-03-06 04:47:50 +00:00
|
|
|
{
|
|
|
|
virHostdevManagerPtr mgr = driver->hostdevMgr;
|
|
|
|
|
|
|
|
if (!def->nhostdevs)
|
|
|
|
return 0;
|
|
|
|
|
2014-03-06 07:48:49 +00:00
|
|
|
return virHostdevUpdateActiveSCSIDevices(mgr, def->hostdevs, def->nhostdevs,
|
|
|
|
QEMU_DRIVER_NAME, def->name);
|
2014-03-06 04:47:50 +00:00
|
|
|
}
|
|
|
|
|
2017-02-03 13:04:59 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
qemuHostdevUpdateActiveMediatedDevices(virQEMUDriverPtr driver,
|
|
|
|
virDomainDefPtr def)
|
|
|
|
{
|
|
|
|
virHostdevManagerPtr mgr = driver->hostdevMgr;
|
|
|
|
|
|
|
|
if (!def->nhostdevs)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return virHostdevUpdateActiveMediatedDevices(mgr, def->hostdevs,
|
|
|
|
def->nhostdevs,
|
|
|
|
QEMU_DRIVER_NAME, def->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-06 09:58:42 +00:00
|
|
|
int
|
|
|
|
qemuHostdevUpdateActiveNVMeDisks(virQEMUDriverPtr driver,
|
|
|
|
virDomainDefPtr def)
|
|
|
|
{
|
|
|
|
return virHostdevUpdateActiveNVMeDevices(driver->hostdevMgr,
|
|
|
|
QEMU_DRIVER_NAME,
|
|
|
|
def->name,
|
|
|
|
def->disks,
|
|
|
|
def->ndisks);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-26 11:09:33 +00:00
|
|
|
int
|
|
|
|
qemuHostdevUpdateActiveDomainDevices(virQEMUDriverPtr driver,
|
|
|
|
virDomainDefPtr def)
|
|
|
|
{
|
2019-06-06 09:58:42 +00:00
|
|
|
if (!def->nhostdevs && !def->ndisks)
|
2015-10-26 11:09:33 +00:00
|
|
|
return 0;
|
|
|
|
|
2019-06-06 09:58:42 +00:00
|
|
|
if (qemuHostdevUpdateActiveNVMeDisks(driver, def) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2015-10-26 11:09:33 +00:00
|
|
|
if (qemuHostdevUpdateActivePCIDevices(driver, def) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (qemuHostdevUpdateActiveUSBDevices(driver, def) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (qemuHostdevUpdateActiveSCSIDevices(driver, def) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2017-02-03 13:04:59 +00:00
|
|
|
if (qemuHostdevUpdateActiveMediatedDevices(driver, def) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2015-10-26 11:09:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2013-10-08 13:47:36 +00:00
|
|
|
|
2019-09-17 07:33:28 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
qemuHostdevNeedsVFIO(const virDomainHostdevDef *hostdev)
|
|
|
|
{
|
|
|
|
return virHostdevIsVFIODevice(hostdev) ||
|
|
|
|
virHostdevIsMdevDevice(hostdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
qemu: default to vfio for nodedev-detach
This patch resolves:
https://bugzilla.redhat.com/show_bug.cgi?id=1035188
Commit f094aaac48a6 changed the PCI device assignment in qemu domains
to default to using VFIO rather than legacy KVM device assignment
(when VFIO is available). It didn't change which driver was used by
default for virNodeDeviceDetachFlags(), though, so that API (and the
virsh nodedev-detach command) was still binding to the pci-stub
driver, used by legacy KVM assignment, by default.
This patch publicizes (only within the qemu module, though, so no
additions to the symbol exports are needed) the functions that check
for presence of KVM and VFIO device assignment, then uses those
functions to decide what to do when no driver is specified for
virNodeDeviceDetachFlags(); if the vfio driver is loaded, the device
will be bound to vfio-pci, or if legacy KVM assignment is supported on
this system, the device will be bound to pci-stub; if neither method
is available, the detach will fail.
2013-11-29 11:19:26 +00:00
|
|
|
bool
|
2013-09-19 15:01:17 +00:00
|
|
|
qemuHostdevHostSupportsPassthroughVFIO(void)
|
|
|
|
{
|
2018-06-01 08:15:58 +00:00
|
|
|
/* condition 1 - host has IOMMU */
|
|
|
|
if (!virHostHasIOMMU())
|
|
|
|
return false;
|
2013-09-19 15:01:17 +00:00
|
|
|
|
|
|
|
/* condition 2 - /dev/vfio/vfio exists */
|
2019-06-25 11:21:39 +00:00
|
|
|
if (!virFileExists(QEMU_DEV_VFIO))
|
2018-06-01 08:15:58 +00:00
|
|
|
return false;
|
2013-09-19 15:01:17 +00:00
|
|
|
|
2018-06-01 08:15:58 +00:00
|
|
|
return true;
|
2013-09-19 15:01:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool
|
2015-10-20 12:10:16 +00:00
|
|
|
qemuHostdevPreparePCIDevicesCheckSupport(virDomainHostdevDefPtr *hostdevs,
|
|
|
|
size_t nhostdevs,
|
|
|
|
virQEMUCapsPtr qemuCaps)
|
2013-09-19 15:01:17 +00:00
|
|
|
{
|
|
|
|
bool supportsPassthroughVFIO = qemuHostdevHostSupportsPassthroughVFIO();
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
/* assign defaults for hostdev passthrough */
|
|
|
|
for (i = 0; i < nhostdevs; i++) {
|
|
|
|
virDomainHostdevDefPtr hostdev = hostdevs[i];
|
|
|
|
int *backend = &hostdev->source.subsys.u.pci.backend;
|
|
|
|
|
|
|
|
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
|
|
|
|
continue;
|
|
|
|
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
|
|
|
|
continue;
|
|
|
|
|
2018-04-25 12:42:34 +00:00
|
|
|
switch ((virDomainHostdevSubsysPCIBackendType)*backend) {
|
2013-09-20 08:39:51 +00:00
|
|
|
case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT:
|
|
|
|
if (supportsPassthroughVFIO &&
|
|
|
|
virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {
|
|
|
|
*backend = VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO;
|
|
|
|
} else {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("host doesn't support passthrough of "
|
|
|
|
"host PCI devices"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2013-09-19 15:01:17 +00:00
|
|
|
case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO:
|
|
|
|
if (!supportsPassthroughVFIO) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("host doesn't support VFIO PCI passthrough"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_KVM:
|
2019-05-03 13:25:07 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("host doesn't support legacy PCI passthrough"));
|
|
|
|
return false;
|
2013-09-19 15:01:17 +00:00
|
|
|
|
2014-03-06 08:44:22 +00:00
|
|
|
case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN:
|
2013-09-19 15:01:17 +00:00
|
|
|
case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_TYPE_LAST:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-09 15:39:33 +00:00
|
|
|
int
|
|
|
|
qemuHostdevPrepareOneNVMeDisk(virQEMUDriverPtr driver,
|
|
|
|
const char *name,
|
|
|
|
virStorageSourcePtr src)
|
|
|
|
{
|
|
|
|
return virHostdevPrepareOneNVMeDevice(driver->hostdevMgr,
|
|
|
|
QEMU_DRIVER_NAME,
|
|
|
|
name,
|
|
|
|
src);
|
|
|
|
}
|
|
|
|
|
2019-06-06 09:58:42 +00:00
|
|
|
int
|
|
|
|
qemuHostdevPrepareNVMeDisks(virQEMUDriverPtr driver,
|
|
|
|
const char *name,
|
|
|
|
virDomainDiskDefPtr *disks,
|
|
|
|
size_t ndisks)
|
|
|
|
{
|
|
|
|
return virHostdevPrepareNVMeDevices(driver->hostdevMgr,
|
|
|
|
QEMU_DRIVER_NAME,
|
|
|
|
name, disks, ndisks);
|
|
|
|
}
|
|
|
|
|
2014-03-05 11:37:51 +00:00
|
|
|
int
|
2015-10-20 12:10:16 +00:00
|
|
|
qemuHostdevPreparePCIDevices(virQEMUDriverPtr driver,
|
2014-03-05 11:37:51 +00:00
|
|
|
const char *name,
|
|
|
|
const unsigned char *uuid,
|
|
|
|
virDomainHostdevDefPtr *hostdevs,
|
|
|
|
int nhostdevs,
|
|
|
|
virQEMUCapsPtr qemuCaps,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
|
|
|
|
|
2015-10-20 12:10:16 +00:00
|
|
|
if (!qemuHostdevPreparePCIDevicesCheckSupport(hostdevs, nhostdevs, qemuCaps))
|
2020-01-06 21:57:40 +00:00
|
|
|
return -1;
|
2014-03-05 11:37:51 +00:00
|
|
|
|
2020-01-06 21:57:40 +00:00
|
|
|
return virHostdevPreparePCIDevices(hostdev_mgr, QEMU_DRIVER_NAME,
|
|
|
|
name, uuid, hostdevs,
|
|
|
|
nhostdevs, flags);
|
2010-12-16 16:10:54 +00:00
|
|
|
}
|
|
|
|
|
2014-03-06 05:31:47 +00:00
|
|
|
int
|
2015-10-20 12:10:16 +00:00
|
|
|
qemuHostdevPrepareUSBDevices(virQEMUDriverPtr driver,
|
|
|
|
const char *name,
|
|
|
|
virDomainHostdevDefPtr *hostdevs,
|
|
|
|
int nhostdevs,
|
|
|
|
unsigned int flags)
|
2014-03-06 05:31:47 +00:00
|
|
|
{
|
|
|
|
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
|
|
|
|
|
2014-03-06 05:42:19 +00:00
|
|
|
return virHostdevPrepareUSBDevices(hostdev_mgr, QEMU_DRIVER_NAME, name,
|
2014-03-06 05:31:47 +00:00
|
|
|
hostdevs, nhostdevs, flags);
|
|
|
|
}
|
|
|
|
|
2014-03-06 06:05:22 +00:00
|
|
|
int
|
2015-10-20 12:10:16 +00:00
|
|
|
qemuHostdevPrepareSCSIDevices(virQEMUDriverPtr driver,
|
2014-03-06 06:05:22 +00:00
|
|
|
const char *name,
|
|
|
|
virDomainHostdevDefPtr *hostdevs,
|
|
|
|
int nhostdevs)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
|
|
|
|
|
|
|
|
/* Loop 1: Add the shared scsi host device to shared device
|
|
|
|
* table.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < nhostdevs; i++) {
|
|
|
|
virDomainDeviceDef dev;
|
|
|
|
|
2019-01-10 23:05:12 +00:00
|
|
|
if (!virHostdevIsSCSIDevice(hostdevs[i]))
|
|
|
|
continue;
|
|
|
|
|
2014-03-06 06:05:22 +00:00
|
|
|
dev.type = VIR_DOMAIN_DEVICE_HOSTDEV;
|
|
|
|
dev.data.hostdev = hostdevs[i];
|
|
|
|
|
|
|
|
if (qemuAddSharedDevice(driver, &dev, name) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (qemuSetUnprivSGIO(&dev) < 0)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-03-06 06:12:52 +00:00
|
|
|
return virHostdevPrepareSCSIDevices(hostdev_mgr, QEMU_DRIVER_NAME,
|
|
|
|
name, hostdevs, nhostdevs);
|
2014-03-06 06:05:22 +00:00
|
|
|
}
|
|
|
|
|
2016-11-22 03:58:18 +00:00
|
|
|
int
|
|
|
|
qemuHostdevPrepareSCSIVHostDevices(virQEMUDriverPtr driver,
|
|
|
|
const char *name,
|
|
|
|
virDomainHostdevDefPtr *hostdevs,
|
|
|
|
int nhostdevs)
|
|
|
|
{
|
|
|
|
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
|
|
|
|
|
|
|
|
return virHostdevPrepareSCSIVHostDevices(hostdev_mgr, QEMU_DRIVER_NAME,
|
|
|
|
name, hostdevs, nhostdevs);
|
|
|
|
}
|
2013-10-08 13:47:36 +00:00
|
|
|
|
2017-02-03 13:04:59 +00:00
|
|
|
int
|
|
|
|
qemuHostdevPrepareMediatedDevices(virQEMUDriverPtr driver,
|
|
|
|
const char *name,
|
|
|
|
virDomainHostdevDefPtr *hostdevs,
|
|
|
|
int nhostdevs)
|
|
|
|
{
|
|
|
|
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
|
qemu: hostdev: Fix the error on VM start with an mdev when IOMMU is off
Commit b4c2ac8d56 made a false assumption that IOMMU support necessary
for an mdev device to be assigned to a VM. Unlike direct PCI assignment,
IOMMU support is not needed for mediated devices, as the physical parent
device provides the isolation, therefore, simply checking for VFIO
presence is enough to successfully start a VM.
Luckily, this issue is not serious, since as of yet, libvirt mandates
mdevs to be pre-created prior to a domain's launch - if it is,
everything does work smoothly even with IOMMU disabled, because the
parent device will ensure the iommu groups we try to access exist.
However, if there are *no* IOMMU groups yet, thus no mdev exists yet, one
would see the following error:
"unsupported configuration: Mediated host device assignment requires VFIO
support"
The error msg above is simply wrong and doesn't even reflect the IOMMU
reality, so after applying this patch one would rather see the following
error in such case instead:
"device not found: mediated device '<UUID>' not found"
Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-03-15 13:58:22 +00:00
|
|
|
bool supportsVFIO;
|
2017-04-12 08:46:35 +00:00
|
|
|
size_t i;
|
2017-02-03 13:04:59 +00:00
|
|
|
|
qemu: hostdev: Fix the error on VM start with an mdev when IOMMU is off
Commit b4c2ac8d56 made a false assumption that IOMMU support necessary
for an mdev device to be assigned to a VM. Unlike direct PCI assignment,
IOMMU support is not needed for mediated devices, as the physical parent
device provides the isolation, therefore, simply checking for VFIO
presence is enough to successfully start a VM.
Luckily, this issue is not serious, since as of yet, libvirt mandates
mdevs to be pre-created prior to a domain's launch - if it is,
everything does work smoothly even with IOMMU disabled, because the
parent device will ensure the iommu groups we try to access exist.
However, if there are *no* IOMMU groups yet, thus no mdev exists yet, one
would see the following error:
"unsupported configuration: Mediated host device assignment requires VFIO
support"
The error msg above is simply wrong and doesn't even reflect the IOMMU
reality, so after applying this patch one would rather see the following
error in such case instead:
"device not found: mediated device '<UUID>' not found"
Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-03-15 13:58:22 +00:00
|
|
|
/* Checking for VFIO only is fine with mdev, as IOMMU isolation is achieved
|
|
|
|
* by the physical parent device.
|
|
|
|
*/
|
2019-06-25 11:21:39 +00:00
|
|
|
supportsVFIO = virFileExists(QEMU_DEV_VFIO);
|
qemu: hostdev: Fix the error on VM start with an mdev when IOMMU is off
Commit b4c2ac8d56 made a false assumption that IOMMU support necessary
for an mdev device to be assigned to a VM. Unlike direct PCI assignment,
IOMMU support is not needed for mediated devices, as the physical parent
device provides the isolation, therefore, simply checking for VFIO
presence is enough to successfully start a VM.
Luckily, this issue is not serious, since as of yet, libvirt mandates
mdevs to be pre-created prior to a domain's launch - if it is,
everything does work smoothly even with IOMMU disabled, because the
parent device will ensure the iommu groups we try to access exist.
However, if there are *no* IOMMU groups yet, thus no mdev exists yet, one
would see the following error:
"unsupported configuration: Mediated host device assignment requires VFIO
support"
The error msg above is simply wrong and doesn't even reflect the IOMMU
reality, so after applying this patch one would rather see the following
error in such case instead:
"device not found: mediated device '<UUID>' not found"
Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-03-15 13:58:22 +00:00
|
|
|
|
2017-04-12 08:46:35 +00:00
|
|
|
for (i = 0; i < nhostdevs; i++) {
|
2018-05-07 14:41:13 +00:00
|
|
|
if (virHostdevIsMdevDevice(hostdevs[i])) {
|
2017-04-12 08:46:35 +00:00
|
|
|
if (!supportsVFIO) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("Mediated host device assignment requires "
|
|
|
|
"VFIO support"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-02-03 13:04:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return virHostdevPrepareMediatedDevices(hostdev_mgr, QEMU_DRIVER_NAME,
|
|
|
|
name, hostdevs, nhostdevs);
|
|
|
|
}
|
|
|
|
|
2013-10-08 13:47:36 +00:00
|
|
|
int
|
2015-10-20 12:10:16 +00:00
|
|
|
qemuHostdevPrepareDomainDevices(virQEMUDriverPtr driver,
|
|
|
|
virDomainDefPtr def,
|
|
|
|
virQEMUCapsPtr qemuCaps,
|
|
|
|
unsigned int flags)
|
2010-12-16 16:10:54 +00:00
|
|
|
{
|
2019-06-06 09:58:42 +00:00
|
|
|
if (!def->nhostdevs && !def->ndisks)
|
2010-12-16 16:10:54 +00:00
|
|
|
return 0;
|
|
|
|
|
2019-06-06 09:58:42 +00:00
|
|
|
if (qemuHostdevPrepareNVMeDisks(driver, def->name, def->disks, def->ndisks) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2015-10-20 12:10:16 +00:00
|
|
|
if (qemuHostdevPreparePCIDevices(driver, def->name, def->uuid,
|
2013-09-20 08:39:51 +00:00
|
|
|
def->hostdevs, def->nhostdevs,
|
2014-03-05 10:56:26 +00:00
|
|
|
qemuCaps, flags) < 0)
|
2010-12-16 16:10:54 +00:00
|
|
|
return -1;
|
|
|
|
|
2015-10-20 12:10:16 +00:00
|
|
|
if (qemuHostdevPrepareUSBDevices(driver, def->name,
|
|
|
|
def->hostdevs, def->nhostdevs, flags) < 0)
|
2010-12-16 16:10:54 +00:00
|
|
|
return -1;
|
|
|
|
|
2015-10-20 12:10:16 +00:00
|
|
|
if (qemuHostdevPrepareSCSIDevices(driver, def->name,
|
2013-05-03 18:07:29 +00:00
|
|
|
def->hostdevs, def->nhostdevs) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2016-11-22 03:58:18 +00:00
|
|
|
if (qemuHostdevPrepareSCSIVHostDevices(driver, def->name,
|
|
|
|
def->hostdevs, def->nhostdevs) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2017-02-03 13:04:59 +00:00
|
|
|
if (qemuHostdevPrepareMediatedDevices(driver, def->name,
|
|
|
|
def->hostdevs, def->nhostdevs) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2010-12-16 16:10:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-09 15:39:33 +00:00
|
|
|
void
|
|
|
|
qemuHostdevReAttachOneNVMeDisk(virQEMUDriverPtr driver,
|
|
|
|
const char *name,
|
|
|
|
virStorageSourcePtr src)
|
|
|
|
{
|
|
|
|
virHostdevReAttachOneNVMeDevice(driver->hostdevMgr,
|
|
|
|
QEMU_DRIVER_NAME,
|
|
|
|
name,
|
|
|
|
src);
|
|
|
|
}
|
|
|
|
|
2019-06-06 09:58:42 +00:00
|
|
|
void
|
|
|
|
qemuHostdevReAttachNVMeDisks(virQEMUDriverPtr driver,
|
|
|
|
const char *name,
|
|
|
|
virDomainDiskDefPtr *disks,
|
|
|
|
size_t ndisks)
|
|
|
|
{
|
|
|
|
virHostdevReAttachNVMeDevices(driver->hostdevMgr,
|
|
|
|
QEMU_DRIVER_NAME,
|
|
|
|
name, disks, ndisks);
|
|
|
|
}
|
|
|
|
|
2014-03-05 11:53:51 +00:00
|
|
|
void
|
2015-10-20 12:12:48 +00:00
|
|
|
qemuHostdevReAttachPCIDevices(virQEMUDriverPtr driver,
|
|
|
|
const char *name,
|
|
|
|
virDomainHostdevDefPtr *hostdevs,
|
|
|
|
int nhostdevs)
|
2014-03-05 11:53:51 +00:00
|
|
|
{
|
2020-09-04 06:59:08 +00:00
|
|
|
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
|
2014-03-12 16:01:39 +00:00
|
|
|
const char *oldStateDir = cfg->stateDir;
|
2014-03-05 11:53:51 +00:00
|
|
|
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
|
|
|
|
|
2014-03-05 11:55:45 +00:00
|
|
|
virHostdevReAttachPCIDevices(hostdev_mgr, QEMU_DRIVER_NAME, name,
|
2014-03-05 11:53:51 +00:00
|
|
|
hostdevs, nhostdevs, oldStateDir);
|
2010-12-16 16:10:54 +00:00
|
|
|
}
|
|
|
|
|
2014-03-06 06:28:07 +00:00
|
|
|
void
|
2015-10-20 12:12:48 +00:00
|
|
|
qemuHostdevReAttachUSBDevices(virQEMUDriverPtr driver,
|
|
|
|
const char *name,
|
|
|
|
virDomainHostdevDefPtr *hostdevs,
|
|
|
|
int nhostdevs)
|
2014-03-06 06:28:07 +00:00
|
|
|
{
|
|
|
|
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
|
|
|
|
|
2014-03-12 16:35:30 +00:00
|
|
|
virHostdevReAttachUSBDevices(hostdev_mgr, QEMU_DRIVER_NAME,
|
2014-03-06 06:33:29 +00:00
|
|
|
name, hostdevs, nhostdevs);
|
2014-03-06 06:28:07 +00:00
|
|
|
}
|
|
|
|
|
2014-03-06 06:45:23 +00:00
|
|
|
void
|
2015-10-20 12:12:48 +00:00
|
|
|
qemuHostdevReAttachSCSIDevices(virQEMUDriverPtr driver,
|
|
|
|
const char *name,
|
|
|
|
virDomainHostdevDefPtr *hostdevs,
|
|
|
|
int nhostdevs)
|
2014-03-06 06:45:23 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
|
|
|
|
|
|
|
|
for (i = 0; i < nhostdevs; i++) {
|
|
|
|
virDomainHostdevDefPtr hostdev = hostdevs[i];
|
|
|
|
virDomainDeviceDef dev;
|
|
|
|
|
|
|
|
dev.type = VIR_DOMAIN_DEVICE_HOSTDEV;
|
|
|
|
dev.data.hostdev = hostdev;
|
|
|
|
|
|
|
|
ignore_value(qemuRemoveSharedDevice(driver, &dev, name));
|
|
|
|
}
|
|
|
|
|
2014-03-12 16:35:30 +00:00
|
|
|
virHostdevReAttachSCSIDevices(hostdev_mgr, QEMU_DRIVER_NAME,
|
|
|
|
name, hostdevs, nhostdevs);
|
2014-03-06 06:45:23 +00:00
|
|
|
}
|
|
|
|
|
2016-11-22 03:58:18 +00:00
|
|
|
void
|
|
|
|
qemuHostdevReAttachSCSIVHostDevices(virQEMUDriverPtr driver,
|
|
|
|
const char *name,
|
|
|
|
virDomainHostdevDefPtr *hostdevs,
|
|
|
|
int nhostdevs)
|
|
|
|
{
|
|
|
|
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
|
|
|
|
|
|
|
|
virHostdevReAttachSCSIVHostDevices(hostdev_mgr, QEMU_DRIVER_NAME,
|
|
|
|
name, hostdevs, nhostdevs);
|
|
|
|
}
|
|
|
|
|
2017-02-03 13:04:59 +00:00
|
|
|
void
|
|
|
|
qemuHostdevReAttachMediatedDevices(virQEMUDriverPtr driver,
|
|
|
|
const char *name,
|
|
|
|
virDomainHostdevDefPtr *hostdevs,
|
|
|
|
int nhostdevs)
|
|
|
|
{
|
|
|
|
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
|
|
|
|
|
|
|
|
virHostdevReAttachMediatedDevices(hostdev_mgr, QEMU_DRIVER_NAME,
|
|
|
|
name, hostdevs, nhostdevs);
|
|
|
|
}
|
|
|
|
|
2013-10-08 13:47:36 +00:00
|
|
|
void
|
2015-10-20 12:12:48 +00:00
|
|
|
qemuHostdevReAttachDomainDevices(virQEMUDriverPtr driver,
|
|
|
|
virDomainDefPtr def)
|
2010-12-16 16:10:54 +00:00
|
|
|
{
|
2019-06-06 09:58:42 +00:00
|
|
|
if (!def->nhostdevs && !def->ndisks)
|
2010-12-16 16:10:54 +00:00
|
|
|
return;
|
|
|
|
|
2019-06-06 09:58:42 +00:00
|
|
|
qemuHostdevReAttachNVMeDisks(driver, def->name, def->disks,
|
|
|
|
def->ndisks);
|
|
|
|
|
2015-10-20 12:12:48 +00:00
|
|
|
qemuHostdevReAttachPCIDevices(driver, def->name, def->hostdevs,
|
|
|
|
def->nhostdevs);
|
2012-03-26 14:40:01 +00:00
|
|
|
|
2015-10-20 12:12:48 +00:00
|
|
|
qemuHostdevReAttachUSBDevices(driver, def->name, def->hostdevs,
|
|
|
|
def->nhostdevs);
|
2013-05-03 18:07:29 +00:00
|
|
|
|
2015-10-20 12:12:48 +00:00
|
|
|
qemuHostdevReAttachSCSIDevices(driver, def->name, def->hostdevs,
|
|
|
|
def->nhostdevs);
|
2016-11-22 03:58:18 +00:00
|
|
|
|
|
|
|
qemuHostdevReAttachSCSIVHostDevices(driver, def->name, def->hostdevs,
|
|
|
|
def->nhostdevs);
|
2017-02-03 13:04:59 +00:00
|
|
|
|
|
|
|
qemuHostdevReAttachMediatedDevices(driver, def->name, def->hostdevs,
|
|
|
|
def->nhostdevs);
|
2010-12-16 16:10:54 +00:00
|
|
|
}
|