2010-12-16 16:10:54 +00:00
|
|
|
/*
|
|
|
|
* qemu_hostdev.h: QEMU hostdev management
|
|
|
|
*
|
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
|
|
|
* Copyright (C) 2006-2007, 2009-2013 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
|
|
|
*
|
|
|
|
* Author: Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __QEMU_HOSTDEV_H__
|
|
|
|
# define __QEMU_HOSTDEV_H__
|
|
|
|
|
|
|
|
# include "qemu_conf.h"
|
|
|
|
# include "domain_conf.h"
|
|
|
|
|
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 qemuHostdevHostSupportsPassthroughLegacy(void);
|
|
|
|
bool qemuHostdevHostSupportsPassthroughVFIO(void);
|
2015-10-20 12:10:16 +00:00
|
|
|
|
2017-02-03 13:04:59 +00:00
|
|
|
int qemuHostdevUpdateActiveMediatedDevices(virQEMUDriverPtr driver,
|
|
|
|
virDomainDefPtr def);
|
2015-10-20 12:26:30 +00:00
|
|
|
int qemuHostdevUpdateActivePCIDevices(virQEMUDriverPtr driver,
|
|
|
|
virDomainDefPtr def);
|
|
|
|
int qemuHostdevUpdateActiveUSBDevices(virQEMUDriverPtr driver,
|
|
|
|
virDomainDefPtr def);
|
|
|
|
int qemuHostdevUpdateActiveSCSIDevices(virQEMUDriverPtr driver,
|
|
|
|
virDomainDefPtr def);
|
2015-10-26 11:09:33 +00:00
|
|
|
int qemuHostdevUpdateActiveDomainDevices(virQEMUDriverPtr driver,
|
|
|
|
virDomainDefPtr def);
|
2015-10-20 12:26:30 +00:00
|
|
|
|
2015-10-20 12:10:16 +00:00
|
|
|
int qemuHostdevPreparePCIDevices(virQEMUDriverPtr driver,
|
qemu: Do not reattach PCI device used by other domain when shutdown
When failing on starting a domain, it tries to reattach all the PCI
devices defined in the domain conf, regardless of whether the devices
are still used by other domain. This will cause the devices to be deleted
from the list qemu_driver->activePciHostdevs, thus the devices will be
thought as usable even if it's not true. And following commands
nodedev-{reattach,reset} will be successful.
How to reproduce:
1) Define two domains with same PCI device defined in the confs.
2) # virsh start domain1
3) # virsh start domain2
4) # virsh nodedev-reattach $pci_device
You will see the device will be reattached to host successfully.
As pciDeviceReattach just check if the device is still used by
other domain via checking if the device is in list driver->activePciHostdevs,
however, the device is deleted from the list by step 2).
This patch is to prohibit the bug by:
1) Prohibit a domain starting or device attachment right at
preparation period (qemuPrepareHostdevPCIDevices) if the
device is in list driver->activePciHostdevs, which means
it's used by other domain.
2) Introduces a new field for struct _pciDevice, (const char *used_by),
it will be set as the domain name at preparation period,
(qemuPrepareHostdevPCIDevices). Thus we can prohibit deleting
the device from driver->activePciHostdevs if it's still used by
other domain when stopping the domain process.
* src/pci.h (define two internal functions, pciDeviceSetUsedBy and
pciDevceGetUsedBy)
* src/pci.c (new field "const char *used_by" for struct _pciDevice,
implementations for the two new functions)
* src/libvirt_private.syms (Add the two new internal functions)
* src/qemu_hostdev.h (Modify the definition of functions
qemuPrepareHostdevPCIDevices, and qemuDomainReAttachHostdevDevices)
* src/qemu_hostdev.c (Prohibit preparation and don't delete the
device from activePciHostdevs list if it's still used by other domain)
* src/qemu_hotplug.c (Update function usage, as the definitions are
changed)
Signed-off-by: Eric Blake <eblake@redhat.com>
2011-10-13 04:05:04 +00:00
|
|
|
const char *name,
|
2012-03-06 01:12:44 +00:00
|
|
|
const unsigned char *uuid,
|
2010-12-16 16:10:54 +00:00
|
|
|
virDomainHostdevDefPtr *hostdevs,
|
2013-09-20 08:39:51 +00:00
|
|
|
int nhostdevs,
|
2014-03-05 10:56:26 +00:00
|
|
|
virQEMUCapsPtr qemuCaps,
|
|
|
|
unsigned int flags);
|
2015-10-20 12:10:16 +00:00
|
|
|
int qemuHostdevPrepareUSBDevices(virQEMUDriverPtr driver,
|
|
|
|
const char *name,
|
|
|
|
virDomainHostdevDefPtr *hostdevs,
|
|
|
|
int nhostdevs,
|
|
|
|
unsigned int flags);
|
|
|
|
int qemuHostdevPrepareSCSIDevices(virQEMUDriverPtr driver,
|
2013-05-03 18:07:29 +00:00
|
|
|
const char *name,
|
|
|
|
virDomainHostdevDefPtr *hostdevs,
|
|
|
|
int nhostdevs);
|
2016-11-22 03:58:18 +00:00
|
|
|
int qemuHostdevPrepareSCSIVHostDevices(virQEMUDriverPtr driver,
|
|
|
|
const char *name,
|
|
|
|
virDomainHostdevDefPtr *hostdevs,
|
|
|
|
int nhostdevs);
|
2017-02-03 13:04:59 +00:00
|
|
|
int qemuHostdevPrepareMediatedDevices(virQEMUDriverPtr driver,
|
|
|
|
const char *name,
|
|
|
|
virDomainHostdevDefPtr *hostdevs,
|
|
|
|
int nhostdevs);
|
2015-10-20 12:10:16 +00:00
|
|
|
int qemuHostdevPrepareDomainDevices(virQEMUDriverPtr driver,
|
|
|
|
virDomainDefPtr def,
|
|
|
|
virQEMUCapsPtr qemuCaps,
|
|
|
|
unsigned int flags);
|
2015-10-20 12:12:48 +00:00
|
|
|
|
|
|
|
void qemuHostdevReAttachPCIDevices(virQEMUDriverPtr driver,
|
|
|
|
const char *name,
|
|
|
|
virDomainHostdevDefPtr *hostdevs,
|
|
|
|
int nhostdevs);
|
|
|
|
void qemuHostdevReAttachUSBDevices(virQEMUDriverPtr driver,
|
|
|
|
const char *name,
|
|
|
|
virDomainHostdevDefPtr *hostdevs,
|
|
|
|
int nhostdevs);
|
|
|
|
void qemuHostdevReAttachSCSIDevices(virQEMUDriverPtr driver,
|
|
|
|
const char *name,
|
|
|
|
virDomainHostdevDefPtr *hostdevs,
|
|
|
|
int nhostdevs);
|
2016-11-22 03:58:18 +00:00
|
|
|
void qemuHostdevReAttachSCSIVHostDevices(virQEMUDriverPtr driver,
|
|
|
|
const char *name,
|
|
|
|
virDomainHostdevDefPtr *hostdevs,
|
|
|
|
int nhostdevs);
|
2017-02-03 13:04:59 +00:00
|
|
|
void qemuHostdevReAttachMediatedDevices(virQEMUDriverPtr driver,
|
|
|
|
const char *name,
|
|
|
|
virDomainHostdevDefPtr *hostdevs,
|
|
|
|
int nhostdevs);
|
2015-10-20 12:12:48 +00:00
|
|
|
void qemuHostdevReAttachDomainDevices(virQEMUDriverPtr driver,
|
|
|
|
virDomainDefPtr def);
|
2010-12-16 16:10:54 +00:00
|
|
|
|
|
|
|
#endif /* __QEMU_HOSTDEV_H__ */
|