1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00
libvirt/src/qemu/qemu_domain.h

1178 lines
40 KiB
C
Raw Normal View History

/*
* qemu_domain.h: QEMU domain private state
*
* Copyright (C) 2006-2019 Red Hat, Inc.
* 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
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <glib-object.h>
#include "vircgroup.h"
#include "virperf.h"
#include "domain_addr.h"
#include "domain_conf.h"
#include "qemu_monitor.h"
#include "qemu_agent.h"
#include "qemu_blockjob.h"
#include "qemu_domainjob.h"
#include "qemu_conf.h"
#include "qemu_capabilities.h"
#include "qemu_logcontext.h"
#include "qemu_migration_params.h"
#include "qemu_nbdkit.h"
#include "qemu_slirp.h"
#include "qemu_fd.h"
#include "virchrdev.h"
#include "virobject.h"
#include "virdomainmomentobjlist.h"
#include "virenum.h"
#include "vireventthread.h"
qemu_domin: Account for NVMe disks when calculating memlock limit on hotplug During hotplug of a NVMe disk we need to adjust the memlock limit. The computation of the limit is handled by qemuDomainGetMemLockLimitBytes() which looks at given domain definition and accounts for various device types (as different types require different amounts). But during disk hotplug the disk is not added to domain definition until the very last moment. Therefore, qemuDomainGetMemLockLimitBytes() has this @forceVFIO argument which tells it to assume VFIO even if there are no signs of VFIO in domain definition. And this kind of works, until the amount needed for NVMe disks changed (in v9.3.0-rc1~52). What's missing in the commit is making @forceVFIO behave the same as if there was an NVMe disk present in the domain definition. But, we can do even better - just mimic whatever we're doing for hostdevs. IOW - introduce qemuDomainAdjustMaxMemLockNVMe() that behaves the same as qemuDomainAdjustMaxMemLockHostdev(). There are subtle differences though: 1) qemuDomainAdjustMaxMemLockHostdev() can afford placing hostdev right at the end of vm->def->hostdevs, because the array was already reallocated (at the beginning of qemuDomainAttachHostPCIDevice()). But qemuDomainAdjustMaxMemLockNVMe() doesn't have that luxury. 2) qemuDomainAdjustMaxMemLockHostdev() places a virDomainHostdevDef pointer into domain definition, while qemuDomainStorageSourceAccessModifyNVMe() (which calls qemuDomainAdjustMaxMemLock()) sees a virStorageSource pointer but domain definition contains virDomainDiskDef. But that's okay, we can create a dummy disk definition and append it into the domain definition. After this, qemuDomainAdjustMaxMemLock() can be called with @forceVFIO = false, as the disk is now part of domain definition (when computing the new limit). Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2014030#c28 Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2023-05-09 13:19:12 +03:00
#include "storage_source_conf.h"
#define QEMU_DOMAIN_FORMAT_LIVE_FLAGS \
(VIR_DOMAIN_XML_SECURE)
#if ULONG_MAX == 4294967295
/* QEMU has a 64-bit limit, but we are limited by our historical choice of
* representing bandwidth in a long instead of a 64-bit int. */
# define QEMU_DOMAIN_MIG_BANDWIDTH_MAX ULONG_MAX
#else
# define QEMU_DOMAIN_MIG_BANDWIDTH_MAX (INT64_MAX / (1024 * 1024))
#endif
typedef void (*qemuDomainCleanupCallback)(virQEMUDriver *driver,
virDomainObj *vm);
#define QEMU_DOMAIN_MASTER_KEY_LEN 32 /* 32 bytes for 256 bit random key */
void qemuDomainSaveStatus(virDomainObj *obj);
void qemuDomainSaveConfig(virDomainObj *obj);
/* helper data types for async device unplug */
typedef enum {
QEMU_DOMAIN_UNPLUGGING_DEVICE_STATUS_NONE = 0,
QEMU_DOMAIN_UNPLUGGING_DEVICE_STATUS_OK,
QEMU_DOMAIN_UNPLUGGING_DEVICE_STATUS_GUEST_REJECTED,
} qemuDomainUnpluggingDeviceStatus;
typedef struct _qemuDomainUnpluggingDevice qemuDomainUnpluggingDevice;
struct _qemuDomainUnpluggingDevice {
const char *alias;
qemuDomainUnpluggingDeviceStatus status;
qemu_hotplug: Fix a rare race condition when detaching a device twice https://bugzilla.redhat.com/show_bug.cgi?id=1623389 If a device is detached twice from the same domain the following race condition may happen: 1) The first DetachDevice() call will issue "device_del" on qemu monitor, but since the DEVICE_DELETED event did not arrive in time, the API ends claiming "Device detach request sent successfully". 2) The second DetachDevice() therefore still find the device in the domain and thus proceeds to detaching it again. It calls EnterMonitor() and qemuMonitorSend() trying to issue "device_del" command again. This gets both domain lock and monitor lock released. 3) At this point, qemu sends us the DEVICE_DELETED event which is going to be handled by the event loop which ends up calling qemuDomainSignalDeviceRemoval() to determine who is going to remove the device from domain definition. Whether it is the caller that marked the device for removal or whether it is going to be the event processing thread. 4) Because the device was marked for removal, qemuDomainSignalDeviceRemoval() returns true, which means the event is to be processed by the thread that has marked the device for removal (and is currently still trying to issue "device_del" command) 5) The thread finally issues the "device_del" command, which fails (obviously) and therefore it calls qemuDomainResetDeviceRemoval() to reset the device marking and quits immediately after, NOT removing any device from the domain definition. At this point, the device is still present in the domain definition but doesn't exist in qemu anymore. Worse, there is no way to remove it from the domain definition. Solution is to note down that we've seen the event and if the second "device_del" fails, not take it as a failure but carry on with the usual execution. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> ACKed-by: Peter Krempa <pkrempa@redhat.com>
2019-03-14 11:02:52 +01:00
bool eventSeen; /* True if DEVICE_DELETED event arrived. */
};
qemu: Spawn qemu under mount namespace Prime time. When it comes to spawning qemu process and relabelling all the devices it's going to touch, there's inherent race with other applications in the system (e.g. udev). Instead of trying convincing udev to not touch libvirt managed devices, we can create a separate mount namespace for the qemu, and mount our own /dev there. Of course this puts more work onto us as we have to maintain /dev files on each domain start and device hot(un-)plug. On the other hand, this enhances security also. From technical POV, on domain startup process the parent (libvirtd) creates: /var/lib/libvirt/qemu/$domain.dev /var/lib/libvirt/qemu/$domain.devpts The child (which is going to be qemu eventually) calls unshare() to create new mount namespace. From now on anything that child does is invisible to the parent. Child then mounts tmpfs on $domain.dev (so that it still sees original /dev from the host) and creates some devices (as explained in one of the previous patches). The devices have to be created exactly as they are in the host (including perms, seclabels, ACLs, ...). After that it moves $domain.dev mount to /dev. What's the $domain.devpts mount there for then you ask? QEMU can create PTYs for some chardevs. And historically we exposed the host ends in our domain XML allowing users to connect to them. Therefore we must preserve devpts mount to be shared with the host's one. To make this patch as small as possible, creating of devices configured for domain in question is implemented in next patches. Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-11-15 11:30:18 +01:00
#define QEMU_PROC_MOUNTS "/proc/mounts"
#define QEMU_DEVPREFIX "/dev/"
#define QEMU_DEV_VFIO "/dev/vfio/vfio"
#define QEMU_DEV_SEV "/dev/sev"
#define QEMU_DEV_SGX_VEPVC "/dev/sgx_vepc"
#define QEMU_DEV_SGX_PROVISION "/dev/sgx_provision"
#define QEMU_DEVICE_MAPPER_CONTROL_PATH "/dev/mapper/control"
#define QEMU_DEV_UDMABUF "/dev/udmabuf"
#define QEMU_DOMAIN_AES_IV_LEN 16 /* 16 bytes for 128 bit random */
/* initialization vector */
typedef struct _qemuDomainSecretInfo qemuDomainSecretInfo;
struct _qemuDomainSecretInfo {
char *username;
char *alias; /* generated alias for secret */
char *iv; /* base64 encoded initialization vector */
char *ciphertext; /* encoded/encrypted secret */
};
typedef struct _qemuDomainObjPrivate qemuDomainObjPrivate;
struct _qemuDomainObjPrivate {
virQEMUDriver *driver;
virBitmap *namespaces;
qemu: Spawn qemu under mount namespace Prime time. When it comes to spawning qemu process and relabelling all the devices it's going to touch, there's inherent race with other applications in the system (e.g. udev). Instead of trying convincing udev to not touch libvirt managed devices, we can create a separate mount namespace for the qemu, and mount our own /dev there. Of course this puts more work onto us as we have to maintain /dev files on each domain start and device hot(un-)plug. On the other hand, this enhances security also. From technical POV, on domain startup process the parent (libvirtd) creates: /var/lib/libvirt/qemu/$domain.dev /var/lib/libvirt/qemu/$domain.devpts The child (which is going to be qemu eventually) calls unshare() to create new mount namespace. From now on anything that child does is invisible to the parent. Child then mounts tmpfs on $domain.dev (so that it still sees original /dev from the host) and creates some devices (as explained in one of the previous patches). The devices have to be created exactly as they are in the host (including perms, seclabels, ACLs, ...). After that it moves $domain.dev mount to /dev. What's the $domain.devpts mount there for then you ask? QEMU can create PTYs for some chardevs. And historically we exposed the host ends in our domain XML allowing users to connect to them. Therefore we must preserve devpts mount to be shared with the host's one. To make this patch as small as possible, creating of devices configured for domain in question is implemented in next patches. Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-11-15 11:30:18 +01:00
virEventThread *eventThread;
qemuMonitor *mon;
virDomainChrSourceDef *monConfig;
bool monError;
unsigned long long monStart;
int agentTimeout;
qemuAgent *agent;
bool agentError;
bool beingDestroyed;
char *pidfile;
int pidMonitored;
virDomainPCIAddressSet *pciaddrs;
virDomainUSBAddressSet *usbaddrs;
virQEMUCaps *qemuCaps;
char *lockState;
bool fakeReboot;
bool pausedShutdown;
/* allowReboot:
*
* Unused with new QEMU versions which have QEMU_CAPS_SET_ACTION.
*
* Otherwise if it's set to VIR_TRISTATE_BOOL_YES, QEMU was started with
* -no-shutdown, and if set to VIR_TRISTATE_BOOL_NO qemu was started with
* -no-reboot instead.
*/
virTristateBool allowReboot;
unsigned long migMaxBandwidth;
char *origname;
int nbdPort; /* Port used for migration with NBD */
unsigned short migrationPort;
int preMigrationState;
unsigned long long preMigrationMemlock; /* Original RLIMIT_MEMLOCK in case
it was changed for the current
migration job. */
virChrdevs *devs;
qemuDomainCleanupCallback *cleanupCallbacks;
size_t ncleanupCallbacks;
size_t ncleanupCallbacks_max;
virCgroup *cgroup;
virPerf *perf;
qemuDomainUnpluggingDevice unplug;
char **qemuDevices; /* NULL-terminated list of devices aliases known to QEMU */
bool hookRun; /* true if there was a hook run over this domain */
/* Bitmaps below hold data from the auto NUMA feature */
virBitmap *autoNodeset;
virBitmap *autoCpuset;
bool signalIOError; /* true if the domain condition should be signalled on
I/O error */
bool signalStop; /* true if the domain condition should be signalled on
QMP STOP event */
systemd: Modernize machine naming So, systemd-machined has this philosophy that machine names are like hostnames and hence should follow the same rules. But we always allowed international characters in domain names. Thus we need to modify the machine name we are passing to systemd. In order to change some machine names that we will be passing to systemd, we also need to call TerminateMachine at the end of a lifetime of a domain. Even for domains that were started with older libvirt. That can be achieved thanks to virSystemdGetMachineNameByPID(). And because we can change machine names, we can get rid of the inconsistent and pointless escaping of domain names when creating machine names. So this patch modifies the naming in the following way. It creates the name as <drivername>-<id>-<name> where invalid hostname characters are stripped out of the name and if the resulting name is longer, it truncates it to 64 characters. That way we can start domains we couldn't start before. Well, at least on systemd. To make it work all together, the machineName (which is needed only with systemd) is saved in domain's private data. That way the generation is moved to the driver and we don't need to pass various unnecessary arguments to cgroup functions. The only thing this complicates a bit is the scope generation when validating a cgroup where we must check both old and new naming, so a slight modification was needed there. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1282846 Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-02-01 16:50:54 +01:00
char *machineName;
char *libDir; /* base path for per-domain files */
char *channelTargetDir; /* base path for per-domain channel targets */
qemu: Create domain master key Add a masterKey and masterKeyLen to _qemuDomainObjPrivate to store a random domain master key and its length in order to support the ability to encrypt/decrypt sensitive data shared between libvirt and qemu. The key will be base64 encoded and written to a file to be used by the command line building code to share with qemu. New API's from this patch: qemuDomainGetMasterKeyFilePath: Return a path to where the key is located qemuDomainWriteMasterKeyFile: (private) Open (create/trunc) the masterKey path and write the masterKey qemuDomainMasterKeyReadFile: Using the master key path, open/read the file, and store the masterKey and masterKeyLen. Expected use only from qemuProcessReconnect qemuDomainGenerateRandomKey: (private) Generate a random key using available algorithms The key is generated either from the gnutls_rnd function if it exists or a less cryptographically strong mechanism using virGenerateRandomBytes qemuDomainMasterKeyRemove: Remove traces of the master key, remove the *KeyFilePath qemuDomainMasterKeyCreate: Generate the domain master key and save the key in the location returned by qemuDomainGetMasterKeyFilePath. This API will first ensure the QEMU_CAPS_OBJECT_SECRET is set in the capabilities. If not, then there's no need to generate the secret or file. The creation of the key will be attempted from qemuProcessPrepareHost once the libDir directory structure exists. The removal of the key will handled from qemuProcessStop just prior to deleting the libDir tree. Since the key will not be written out to the domain object XML file, the qemuProcessReconnect will read the saved file and restore the masterKey and masterKeyLen.
2016-03-29 18:22:46 -04:00
/* random masterKey and length for encryption (not to be saved in our */
/* private XML) - need to restore at process reconnect */
uint8_t *masterKey;
size_t masterKeyLen;
/* for migrations using TLS with a secret (not to be saved in our */
/* private XML). */
qemuDomainSecretInfo *migSecinfo;
/* CPU def used to start the domain when it differs from the one actually
* provided by QEMU. */
virCPUDef *origCPU;
/* If true virtlogd is used as stdio handler for character devices. */
bool chardevStdioLogd;
/* Tracks blockjob state for vm. Valid only while reconnecting to qemu. */
virTristateBool reconnectBlockjobs;
/* Migration capabilities. Rechecked on reconnect, not to be saved in
* private XML. */
virBitmap *migrationCaps;
/* True if QEMU supports "postcopy-recover-setup" migration state. Checked
* QEMU enters the state, not to be stored in private XML. */
bool migrationRecoverSetup;
/* true if qemu-pr-helper process is running for the domain */
bool prDaemonRunning;
/* counter for generating node names for qemu disks */
unsigned long long nodenameindex;
/* counter for generating IDs of fdsets */
unsigned int fdsetindex;
bool fdsetindexParsed;
/* qemuProcessStartCPUs stores the reason for starting vCPUs here for the
* RESUME event handler to use it */
virDomainRunningReason runningReason;
/* qemuProcessStopCPUs stores the reason for pausing vCPUs here for the
* STOP event handler to use it */
virDomainPausedReason pausedReason;
/* true if libvirt remembers the original owner for files */
bool rememberOwner;
/* true if global -mem-prealloc appears on cmd line */
bool memPrealloc;
/* running block jobs */
GHashTable *blockjobs;
bool disableSlirp;
/* Until we add full support for backing chains for pflash drives, these
* pointers hold the temporary virStorageSources for creating the -blockdev
* commandline for pflash drives. */
virStorageSource *pflash0;
/* running backup job */
virDomainBackupDef *backup;
bool dbusDaemonRunning;
/* list of Ids to migrate */
GSList *dbusVMStateIds;
/* true if -object dbus-vmstate was added */
bool dbusVMState;
unsigned long long originalMemlock; /* Original RLIMIT_MEMLOCK, zero if no
* restore will be required later */
GHashTable *statsSchema; /* (name, data) pair for stats */
/* Info on dummy process for schedCore. A short lived process used only
* briefly when starting a guest. Don't save/parse into XML. */
pid_t schedCoreChildPID;
pid_t schedCoreChildFD;
GSList *threadContextAliases; /* List of IDs of thread-context objects */
/* named file descriptor groups associated with the VM */
GHashTable *fds;
char *memoryBackingDir;
};
#define QEMU_DOMAIN_PRIVATE(vm) \
((qemuDomainObjPrivate *) (vm)->privateData)
#define QEMU_DOMAIN_DISK_PRIVATE(disk) \
((qemuDomainDiskPrivate *) (disk)->privateData)
typedef struct _qemuDomainDiskPrivate qemuDomainDiskPrivate;
struct _qemuDomainDiskPrivate {
virObject parent;
/* ideally we want a smarter way to interlock block jobs on single qemu disk
* in the future, but for now we just disallow any concurrent job on a
* single disk */
qemuBlockJobData *blockjob;
bool migrating; /* the disk is being migrated */
virStorageSource *migrSource; /* disk source object used for NBD migration */
bool migrationslice; /* storage slice was added for migration purposes */
/* information about the device */
bool tray; /* device has tray */
bool removable; /* device media can be removed/changed */
char *qomName; /* QOM path of the disk (also refers to the block backend) */
char *nodeCopyOnRead; /* nodename of the disk-wide copy-on-read blockdev layer */
bool transientOverlayCreated; /* the overlay image of a transient disk was
created and the definition was updated */
};
#define QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src) \
((qemuDomainStorageSourcePrivate *) (src)->privateData)
typedef struct _qemuDomainStorageSourcePrivate qemuDomainStorageSourcePrivate;
struct _qemuDomainStorageSourcePrivate {
virObject parent;
/* data required for authentication to the storage source */
qemuDomainSecretInfo *secinfo;
/* data required for decryption of encrypted storage source */
size_t enccount;
qemuDomainSecretInfo **encinfo;
/* secure passthrough of the http cookie */
qemuDomainSecretInfo *httpcookie;
/* key for decrypting TLS certificate */
qemuDomainSecretInfo *tlsKeySecret;
/* file descriptors if user asks for FDs to be passed */
qemuFDPass *fdpass;
/* an nbdkit process for serving network storage sources */
qemuNbdkitProcess *nbdkitProcess;
};
virObject *qemuDomainStorageSourcePrivateNew(void);
qemuDomainStorageSourcePrivate *
qemuDomainStorageSourcePrivateFetch(virStorageSource *src);
typedef struct _qemuDomainVcpuPrivate qemuDomainVcpuPrivate;
struct _qemuDomainVcpuPrivate {
virObject parent;
pid_t tid; /* vcpu thread id */
int enable_id; /* order in which the vcpus were enabled in qemu */
int qemu_id; /* ID reported by qemu as 'CPU' in query-cpus */
char *alias;
virTristateBool halted;
/* copy of the data that qemu returned */
virJSONValue *props;
/* information for hotpluggable cpus */
char *type;
int socket_id;
int core_id;
int thread_id;
int node_id;
int vcpus;
char *qomPath;
};
#define QEMU_DOMAIN_VCPU_PRIVATE(vcpu) \
((qemuDomainVcpuPrivate *) (vcpu)->privateData)
struct qemuDomainDiskInfo {
bool removable;
bool tray;
bool tray_open;
bool empty;
int io_status;
char *nodename;
};
#define QEMU_DOMAIN_CHR_SOURCE_PRIVATE(dev) \
((qemuDomainChrSourcePrivate *) (dev)->privateData)
typedef struct _qemuDomainChrSourcePrivate qemuDomainChrSourcePrivate;
struct _qemuDomainChrSourcePrivate {
virObject parent;
/* for char devices using secret
* NB: *not* to be written to qemu domain object XML */
qemuDomainSecretInfo *secinfo;
qemuFDPass *sourcefd;
qemuFDPass *logfd;
qemuFDPassDirect *directfd;
bool wait; /* wait for incoming connections on chardev */
char *tlsCertPath; /* path to certificates if TLS is requested */
bool tlsVerify; /* whether server should verify client certificates */
char *tlsCredsAlias; /* alias of the x509 tls credentials object */
};
void
qemuDomainChrSourcePrivateClearFDPass(qemuDomainChrSourcePrivate *priv);
typedef struct _qemuDomainVsockPrivate qemuDomainVsockPrivate;
struct _qemuDomainVsockPrivate {
virObject parent;
int vhostfd;
};
#define QEMU_DOMAIN_VIDEO_PRIVATE(dev) \
((qemuDomainVideoPrivate *) (dev)->privateData)
typedef struct _qemuDomainVideoPrivate qemuDomainVideoPrivate;
struct _qemuDomainVideoPrivate {
virObject parent;
int vhost_user_fd;
};
#define QEMU_DOMAIN_GRAPHICS_PRIVATE(dev) \
((qemuDomainGraphicsPrivate *) (dev)->privateData)
typedef struct _qemuDomainGraphicsPrivate qemuDomainGraphicsPrivate;
struct _qemuDomainGraphicsPrivate {
virObject parent;
char *tlsAlias;
qemuDomainSecretInfo *secinfo;
};
#define QEMU_DOMAIN_NETWORK_PRIVATE(dev) \
((qemuDomainNetworkPrivate *) (dev)->privateData)
typedef struct _qemuDomainNetworkPrivate qemuDomainNetworkPrivate;
struct _qemuDomainNetworkPrivate {
virObject parent;
/* Don't forget to possibly copy these members in qemuDomainChangeNet(). */
/* True if the device was created by us. Otherwise we should
* avoid removing it. Currently only used for
* VIR_DOMAIN_NET_TYPE_DIRECT. */
bool created;
qemuSlirp *slirp;
/* file descriptor transfer helpers */
qemuFDPassDirect *slirpfd;
GSList *tapfds; /* qemuFDPassDirect */
GSList *vhostfds; /* qemuFDPassDirect */
qemuFDPass *vdpafd;
};
#define QEMU_DOMAIN_TPM_PRIVATE(dev) \
((qemuDomainTPMPrivate *) (dev)->privateData)
typedef struct _qemuDomainTPMPrivate qemuDomainTPMPrivate;
struct _qemuDomainTPMPrivate {
virObject parent;
struct {
bool can_migrate_shared_storage;
} swtpm;
};
void
qemuDomainNetworkPrivateClearFDs(qemuDomainNetworkPrivate *priv);
typedef enum {
QEMU_PROCESS_EVENT_WATCHDOG = 0,
QEMU_PROCESS_EVENT_GUESTPANIC,
QEMU_PROCESS_EVENT_DEVICE_DELETED,
qemu: respond to NETDEV_STREAM_DISCONNECTED event When a QEMU netdev is of type "stream", if the socket it uses for connectivity to the host network gets closed, then QEMU will send a NETDEV_STREAM_DISCONNECTED event. We know that any stream netdev we've created is backed by a passt process, and if the socket was closed, that means the passt process has disappeared. When we receive this event, we can respond by starting a new passt process with the same options (including socket path) we originally used. If we have previously created the stream netdev device with a "reconnect" option, then QEMU will automatically reconnect to this new passt process. (If we hadn't used "reconnect", then QEMU will never try to reconnect to the new passt process, so there's no point in starting it.) Note that NETDEV_STREAM_DISCONNECTED is an event sent for the netdev (ie "host side") of the network device, and so it sends the "netdev-id" to specify which device was disconnected. But libvirt's virDomainNetDef (the object used to keep track of network devices) is the internal representation of both the host-side "netdev", and the guest side device, and virDomainNetDef doesn't directly keep track of the netdev-id, only of the device's "alias" (which is the "id" parameter of the *guest* side of the device). Fortunately, by convention libvirt always names the host-side of devices as "host" + alias, so in order to search for the affected NetDef, all we need to do is trim the 1st 4 characters from the netdev-id and look for the NetDef having that resulting trimmed string as its alias. (Contrast this to NIC_RX_FILTER_CHANGED, which is an event received for the guest side of the device, and so directly contains the device alias.) Resolves: https://bugzilla.redhat.com/2172098 Signed-off-by: Laine Stump <laine@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2023-02-21 01:16:04 -05:00
QEMU_PROCESS_EVENT_NETDEV_STREAM_DISCONNECTED,
QEMU_PROCESS_EVENT_NIC_RX_FILTER_CHANGED,
QEMU_PROCESS_EVENT_SERIAL_CHANGED,
QEMU_PROCESS_EVENT_JOB_STATUS_CHANGE,
QEMU_PROCESS_EVENT_MONITOR_EOF,
QEMU_PROCESS_EVENT_PR_DISCONNECT,
QEMU_PROCESS_EVENT_RDMA_GID_STATUS_CHANGED,
QEMU_PROCESS_EVENT_GUEST_CRASHLOADED,
QEMU_PROCESS_EVENT_MEMORY_DEVICE_SIZE_CHANGE,
QEMU_PROCESS_EVENT_UNATTENDED_MIGRATION,
QEMU_PROCESS_EVENT_RESET,
QEMU_PROCESS_EVENT_NBDKIT_EXITED,
QEMU_PROCESS_EVENT_SHUTDOWN_COMPLETED,
QEMU_PROCESS_EVENT_LAST
} qemuProcessEventType;
struct qemuProcessEvent {
virDomainObj *vm;
qemuProcessEventType eventType;
int action;
int status;
void *data;
};
void qemuProcessEventFree(struct qemuProcessEvent *event);
typedef struct _qemuDomainSaveCookie qemuDomainSaveCookie;
struct _qemuDomainSaveCookie {
virObject parent;
virCPUDef *cpu;
bool slirpHelper;
};
G_DEFINE_AUTOPTR_CLEANUP_FUNC(qemuDomainSaveCookie, virObjectUnref);
typedef struct _qemuDomainXmlNsEnvTuple qemuDomainXmlNsEnvTuple;
struct _qemuDomainXmlNsEnvTuple {
char *name;
char *value;
};
typedef enum {
QEMU_DOMAIN_XML_NS_OVERRIDE_NONE,
QEMU_DOMAIN_XML_NS_OVERRIDE_STRING,
QEMU_DOMAIN_XML_NS_OVERRIDE_SIGNED,
QEMU_DOMAIN_XML_NS_OVERRIDE_UNSIGNED,
QEMU_DOMAIN_XML_NS_OVERRIDE_BOOL,
QEMU_DOMAIN_XML_NS_OVERRIDE_REMOVE,
QEMU_DOMAIN_XML_NS_OVERRIDE_LAST
} qemuDomainXmlNsOverrideType;
VIR_ENUM_DECL(qemuDomainXmlNsOverride);
typedef struct _qemuDomainXmlNsOverrideProperty qemuDomainXmlNsOverrideProperty;
struct _qemuDomainXmlNsOverrideProperty {
char *name;
qemuDomainXmlNsOverrideType type;
char *value;
virJSONValue *json;
};
typedef struct _qemuDomainXmlNsDeviceOverride qemuDomainXmlNsDeviceOverride;
struct _qemuDomainXmlNsDeviceOverride {
char *alias;
size_t nfrontend;
qemuDomainXmlNsOverrideProperty *frontend;
};
typedef struct _qemuDomainXmlNsDef qemuDomainXmlNsDef;
struct _qemuDomainXmlNsDef {
char **args;
unsigned int num_env;
qemuDomainXmlNsEnvTuple *env;
char **capsadd;
char **capsdel;
/* We deliberately keep this as a string so that it's parsed only when
* starting the VM to avoid any form of errors in the parser or when
* changing qemu versions. The knob is mainly for development/CI purposes */
char *deprecationBehavior;
size_t ndeviceOverride;
qemuDomainXmlNsDeviceOverride *deviceOverride;
};
typedef struct _qemuDomainJobPrivateMigrateTempBitmap qemuDomainJobPrivateMigrateTempBitmap;
struct _qemuDomainJobPrivateMigrateTempBitmap {
char *nodename;
char *bitmapname;
};
void
qemuDomainJobPrivateMigrateTempBitmapFree(qemuDomainJobPrivateMigrateTempBitmap *bmp);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(qemuDomainJobPrivateMigrateTempBitmap, qemuDomainJobPrivateMigrateTempBitmapFree);
typedef struct _qemuDomainJobPrivate qemuDomainJobPrivate;
struct _qemuDomainJobPrivate {
bool spiceMigration; /* we asked for spice migration and we
* should wait for it to finish */
bool spiceMigrated; /* spice migration completed */
bool dumpCompleted; /* dump completed */
bool snapshotDelete; /* indicate that snapshot job is
* deleting snapshot */
qemuMigrationParams *migParams;
GSList *migTempBitmaps; /* temporary block dirty bitmaps - qemuDomainJobPrivateMigrateTempBitmap */
};
int qemuDomainObjStartWorker(virDomainObj *dom);
void qemuDomainObjStopWorker(virDomainObj *dom);
virDomainObj *qemuDomainObjFromDomain(virDomainPtr domain);
qemuDomainSaveCookie *qemuDomainSaveCookieNew(virDomainObj *vm);
void qemuDomainEventFlush(int timer, void *opaque);
qemuMonitor *qemuDomainGetMonitor(virDomainObj *vm)
ATTRIBUTE_NONNULL(1);
void qemuDomainObjEnterMonitor(virDomainObj *obj)
ATTRIBUTE_NONNULL(1);
void qemuDomainObjExitMonitor(virDomainObj *obj)
ATTRIBUTE_NONNULL(1);
int qemuDomainObjEnterMonitorAsync(virDomainObj *obj,
virDomainAsyncJob asyncJob)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT;
qemuAgent *qemuDomainObjEnterAgent(virDomainObj *obj)
ATTRIBUTE_NONNULL(1);
void qemuDomainObjExitAgent(virDomainObj *obj, qemuAgent *agent)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
void qemuDomainObjEnterRemote(virDomainObj *obj)
ATTRIBUTE_NONNULL(1);
int qemuDomainObjExitRemote(virDomainObj *obj,
bool checkActive)
ATTRIBUTE_NONNULL(1) G_GNUC_WARN_UNUSED_RESULT;
virDomainDef *qemuDomainDefCopy(virQEMUDriver *driver,
virQEMUCaps *qemuCaps,
virDomainDef *src,
unsigned int flags);
int qemuDomainDefFormatBuf(virQEMUDriver *driver,
virQEMUCaps *qemuCaps,
virDomainDef *vm,
unsigned int flags,
virBuffer *buf);
char *qemuDomainDefFormatXML(virQEMUDriver *driver,
virQEMUCaps *qemuCaps,
virDomainDef *vm,
unsigned int flags);
char *qemuDomainFormatXML(virQEMUDriver *driver,
virDomainObj *vm,
unsigned int flags);
char *qemuDomainDefFormatLive(virQEMUDriver *driver,
virQEMUCaps *qemuCaps,
virDomainDef *def,
virCPUDef *origCPU,
bool inactive,
bool compatible);
void qemuDomainObjTaint(virQEMUDriver *driver,
virDomainObj *obj,
virDomainTaintFlags taint,
qemuLogContext *logCtxt);
char **qemuDomainObjGetTainting(virQEMUDriver *driver,
virDomainObj *obj);
void qemuDomainObjCheckTaint(virQEMUDriver *driver,
virDomainObj *obj,
qemuLogContext *logCtxt,
bool incomingMigration);
void qemuDomainObjCheckDiskTaint(virQEMUDriver *driver,
virDomainObj *obj,
virDomainDiskDef *disk,
qemuLogContext *logCtxt);
void qemuDomainObjCheckHostdevTaint(virQEMUDriver *driver,
virDomainObj *obj,
virDomainHostdevDef *disk,
qemuLogContext *logCtxt);
void qemuDomainObjCheckNetTaint(virQEMUDriver *driver,
virDomainObj *obj,
virDomainNetDef *net,
qemuLogContext *logCtxt);
int qemuDomainLogAppendMessage(virQEMUDriver *driver,
virDomainObj *vm,
const char *fmt,
...) G_GNUC_PRINTF(3, 4);
const char *qemuFindQemuImgBinary(virQEMUDriver *driver);
int qemuDomainSnapshotWriteMetadata(virDomainObj *vm,
virDomainMomentObj *snapshot,
virDomainXMLOption *xmlopt,
const char *snapshotDir);
int qemuDomainSnapshotForEachQcow2(virQEMUDriver *driver,
virDomainDef *def,
virDomainMomentObj *snap,
const char *op,
bool try_all);
typedef struct _virQEMUMomentRemove virQEMUMomentRemove;
struct _virQEMUMomentRemove {
virQEMUDriver *driver;
virDomainObj *vm;
int err;
bool metadata_only;
virDomainMomentObj *current;
bool found;
int (*momentDiscard)(virQEMUDriver *, virDomainObj *,
virDomainMomentObj *, bool, bool);
};
int qemuDomainMomentDiscardAll(void *payload,
const char *name,
void *data);
void qemuDomainRemoveInactive(virQEMUDriver *driver,
virDomainObj *vm,
virDomainUndefineFlagsValues flags,
bool outgoingMigration);
void
qemuDomainRemoveInactiveLocked(virQEMUDriver *driver,
virDomainObj *vm);
void qemuDomainSetFakeReboot(virDomainObj *vm,
bool value);
int qemuDomainCheckDiskStartupPolicy(virQEMUDriver *driver,
virDomainObj *vm,
size_t diskIndex,
bool cold_boot);
int qemuDomainCheckDiskPresence(virQEMUDriver *driver,
virDomainObj *vm,
unsigned int flags);
int qemuDomainStorageSourceValidateDepth(virStorageSource *src,
int add,
const char *diskdst);
int qemuDomainDetermineDiskChain(virQEMUDriver *driver,
virDomainObj *vm,
virDomainDiskDef *disk,
virStorageSource *disksrc);
bool qemuDomainDiskChangeSupported(virDomainDiskDef *disk,
virDomainDiskDef *orig_disk);
void qemuDomainGetImageIds(virQEMUDriverConfig *cfg,
virDomainDef *def,
virStorageSource *src,
virStorageSource *parentSrc,
uid_t *uid,
gid_t *gid);
int qemuDomainStorageFileInit(virQEMUDriver *driver,
virDomainObj *vm,
virStorageSource *src,
virStorageSource *parent);
char *qemuDomainStorageAlias(const char *device, int depth);
const char *
qemuDomainDiskGetTopNodename(virDomainDiskDef *disk)
ATTRIBUTE_NONNULL(1);
int qemuDomainDiskGetBackendAlias(virDomainDiskDef *disk,
char **backendAlias)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT;
int qemuDomainStorageSourceChainAccessAllow(virQEMUDriver *driver,
virDomainObj *vm,
virStorageSource *src);
int qemuDomainStorageSourceChainAccessRevoke(virQEMUDriver *driver,
virDomainObj *vm,
virStorageSource *src);
void qemuDomainStorageSourceAccessRevoke(virQEMUDriver *driver,
virDomainObj *vm,
virStorageSource *elem);
int qemuDomainStorageSourceAccessAllow(virQEMUDriver *driver,
virDomainObj *vm,
virStorageSource *elem,
bool readonly,
bool newSource,
bool chainTop);
int qemuDomainPrepareStorageSourceBlockdevNodename(virDomainDiskDef *disk,
virStorageSource *src,
const char *nodenameprefix,
qemuDomainObjPrivate *priv,
virQEMUDriverConfig *cfg);
int qemuDomainPrepareStorageSourceBlockdev(virDomainDiskDef *disk,
virStorageSource *src,
qemuDomainObjPrivate *priv,
virQEMUDriverConfig *cfg);
void qemuDomainCleanupAdd(virDomainObj *vm,
qemuDomainCleanupCallback cb);
void qemuDomainCleanupRemove(virDomainObj *vm,
qemuDomainCleanupCallback cb);
void qemuDomainCleanupRun(virQEMUDriver *driver,
virDomainObj *vm);
void qemuDomainObjPrivateDataClear(qemuDomainObjPrivate *priv);
extern virDomainXMLPrivateDataCallbacks virQEMUDriverPrivateDataCallbacks;
extern virXMLNamespace virQEMUDriverDomainXMLNamespace;
extern virDomainDefParserConfig virQEMUDriverDomainDefParserConfig;
extern virDomainABIStability virQEMUDriverDomainABIStability;
extern virSaveCookieCallbacks virQEMUDriverDomainSaveCookie;
extern virDomainJobObjConfig virQEMUDriverDomainJobConfig;
int qemuDomainUpdateDeviceList(virDomainObj *vm, int asyncJob);
int qemuDomainUpdateMemoryDeviceInfo(virDomainObj *vm,
int asyncJob);
bool qemuDomainDefCheckABIStability(virQEMUDriver *driver,
virQEMUCaps *qemuCaps,
virDomainDef *src,
virDomainDef *dst);
bool qemuDomainCheckABIStability(virQEMUDriver *driver,
virDomainObj *vm,
virDomainDef *dst);
bool qemuDomainAgentAvailable(virDomainObj *vm,
bool reportError);
bool qemuDomainDiskBlockJobIsActive(virDomainDiskDef *disk);
bool qemuDomainHasBlockjob(virDomainObj *vm, bool copy_only)
ATTRIBUTE_NONNULL(1);
int qemuDomainAlignMemorySizes(virDomainDef *def);
int qemuDomainMemoryDeviceAlignSize(virDomainDef *def,
virDomainMemoryDef *mem);
virDomainChrDef *qemuFindAgentConfig(virDomainDef *def);
/* You should normally avoid these functions and use the variant that
* doesn't have "Machine" in the name instead. */
bool qemuDomainMachineIsQ35(const char *machine,
const virArch arch);
bool qemuDomainMachineIsI440FX(const char *machine,
const virArch arch);
bool qemuDomainMachineIsARMVirt(const char *machine,
const virArch arch);
bool qemuDomainMachineIsPSeries(const char *machine,
const virArch arch);
bool qemuDomainMachineIsXenFV(const char *machine,
const virArch arch);
bool qemuDomainMachineHasBuiltinIDE(const char *machine,
const virArch arch);
bool qemuDomainIsQ35(const virDomainDef *def);
bool qemuDomainIsI440FX(const virDomainDef *def);
bool qemuDomainIsS390CCW(const virDomainDef *def);
bool qemuDomainIsARMVirt(const virDomainDef *def);
bool qemuDomainIsLoongArchVirt(const virDomainDef *def);
bool qemuDomainIsRISCVVirt(const virDomainDef *def);
bool qemuDomainIsPSeries(const virDomainDef *def);
bool qemuDomainIsMipsMalta(const virDomainDef *def);
bool qemuDomainIsXenFV(const virDomainDef *def);
bool qemuDomainHasPCIRoot(const virDomainDef *def);
bool qemuDomainHasPCIeRoot(const virDomainDef *def);
bool qemuDomainHasBuiltinIDE(const virDomainDef *def);
bool qemuDomainHasBuiltinESP(const virDomainDef *def);
bool qemuDomainNeedsFDC(const virDomainDef *def);
bool qemuDomainSupportsPCI(const virDomainDef *def);
bool qemuDomainSupportsPCIMultibus(const virDomainDef *def);
int qemuDomainGetSCSIControllerModel(const virDomainDef *def,
const virDomainControllerDef *cont,
virQEMUCaps *qemuCaps);
void qemuDomainUpdateCurrentMemorySize(virDomainObj *vm);
unsigned long long qemuDomainGetMemLockLimitBytes(virDomainDef *def);
int qemuDomainAdjustMaxMemLock(virDomainObj *vm);
int qemuDomainAdjustMaxMemLockHostdev(virDomainObj *vm,
virDomainHostdevDef *hostdev);
qemu_domin: Account for NVMe disks when calculating memlock limit on hotplug During hotplug of a NVMe disk we need to adjust the memlock limit. The computation of the limit is handled by qemuDomainGetMemLockLimitBytes() which looks at given domain definition and accounts for various device types (as different types require different amounts). But during disk hotplug the disk is not added to domain definition until the very last moment. Therefore, qemuDomainGetMemLockLimitBytes() has this @forceVFIO argument which tells it to assume VFIO even if there are no signs of VFIO in domain definition. And this kind of works, until the amount needed for NVMe disks changed (in v9.3.0-rc1~52). What's missing in the commit is making @forceVFIO behave the same as if there was an NVMe disk present in the domain definition. But, we can do even better - just mimic whatever we're doing for hostdevs. IOW - introduce qemuDomainAdjustMaxMemLockNVMe() that behaves the same as qemuDomainAdjustMaxMemLockHostdev(). There are subtle differences though: 1) qemuDomainAdjustMaxMemLockHostdev() can afford placing hostdev right at the end of vm->def->hostdevs, because the array was already reallocated (at the beginning of qemuDomainAttachHostPCIDevice()). But qemuDomainAdjustMaxMemLockNVMe() doesn't have that luxury. 2) qemuDomainAdjustMaxMemLockHostdev() places a virDomainHostdevDef pointer into domain definition, while qemuDomainStorageSourceAccessModifyNVMe() (which calls qemuDomainAdjustMaxMemLock()) sees a virStorageSource pointer but domain definition contains virDomainDiskDef. But that's okay, we can create a dummy disk definition and append it into the domain definition. After this, qemuDomainAdjustMaxMemLock() can be called with @forceVFIO = false, as the disk is now part of domain definition (when computing the new limit). Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2014030#c28 Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2023-05-09 13:19:12 +03:00
int qemuDomainAdjustMaxMemLockNVMe(virDomainObj *vm,
virStorageSource *src);
int qemuDomainSetMaxMemLock(virDomainObj *vm,
unsigned long long limit,
unsigned long long *origPtr);
int qemuDomainDefValidateMemoryHotplug(const virDomainDef *def,
const virDomainMemoryDef *mem);
bool qemuDomainSupportsVcpuHotplug(virDomainObj *vm);
bool qemuDomainHasVcpuPids(virDomainObj *vm);
pid_t qemuDomainGetVcpuPid(virDomainObj *vm, unsigned int vcpuid);
int qemuDomainValidateVcpuInfo(virDomainObj *vm);
int qemuDomainRefreshVcpuInfo(virDomainObj *vm,
int asyncJob,
bool state);
bool qemuDomainGetVcpuHalted(virDomainObj *vm, unsigned int vcpu);
int qemuDomainRefreshVcpuHalted(virDomainObj *vm,
int asyncJob);
bool qemuDomainSupportsNicdev(virDomainDef *def,
virDomainNetDef *net);
bool qemuDomainNetSupportsMTU(virDomainNetType type,
virDomainNetBackendType backend);
int qemuDomainSetPrivatePaths(virQEMUDriver *driver,
virDomainObj *vm);
virDomainDiskDef *qemuDomainDiskByName(virDomainDef *def, const char *name);
qemu: Create domain master key Add a masterKey and masterKeyLen to _qemuDomainObjPrivate to store a random domain master key and its length in order to support the ability to encrypt/decrypt sensitive data shared between libvirt and qemu. The key will be base64 encoded and written to a file to be used by the command line building code to share with qemu. New API's from this patch: qemuDomainGetMasterKeyFilePath: Return a path to where the key is located qemuDomainWriteMasterKeyFile: (private) Open (create/trunc) the masterKey path and write the masterKey qemuDomainMasterKeyReadFile: Using the master key path, open/read the file, and store the masterKey and masterKeyLen. Expected use only from qemuProcessReconnect qemuDomainGenerateRandomKey: (private) Generate a random key using available algorithms The key is generated either from the gnutls_rnd function if it exists or a less cryptographically strong mechanism using virGenerateRandomBytes qemuDomainMasterKeyRemove: Remove traces of the master key, remove the *KeyFilePath qemuDomainMasterKeyCreate: Generate the domain master key and save the key in the location returned by qemuDomainGetMasterKeyFilePath. This API will first ensure the QEMU_CAPS_OBJECT_SECRET is set in the capabilities. If not, then there's no need to generate the secret or file. The creation of the key will be attempted from qemuProcessPrepareHost once the libDir directory structure exists. The removal of the key will handled from qemuProcessStop just prior to deleting the libDir tree. Since the key will not be written out to the domain object XML file, the qemuProcessReconnect will read the saved file and restore the masterKey and masterKeyLen.
2016-03-29 18:22:46 -04:00
char *qemuDomainGetMasterKeyFilePath(const char *libDir);
int qemuDomainMasterKeyReadFile(qemuDomainObjPrivate *priv);
qemu: Create domain master key Add a masterKey and masterKeyLen to _qemuDomainObjPrivate to store a random domain master key and its length in order to support the ability to encrypt/decrypt sensitive data shared between libvirt and qemu. The key will be base64 encoded and written to a file to be used by the command line building code to share with qemu. New API's from this patch: qemuDomainGetMasterKeyFilePath: Return a path to where the key is located qemuDomainWriteMasterKeyFile: (private) Open (create/trunc) the masterKey path and write the masterKey qemuDomainMasterKeyReadFile: Using the master key path, open/read the file, and store the masterKey and masterKeyLen. Expected use only from qemuProcessReconnect qemuDomainGenerateRandomKey: (private) Generate a random key using available algorithms The key is generated either from the gnutls_rnd function if it exists or a less cryptographically strong mechanism using virGenerateRandomBytes qemuDomainMasterKeyRemove: Remove traces of the master key, remove the *KeyFilePath qemuDomainMasterKeyCreate: Generate the domain master key and save the key in the location returned by qemuDomainGetMasterKeyFilePath. This API will first ensure the QEMU_CAPS_OBJECT_SECRET is set in the capabilities. If not, then there's no need to generate the secret or file. The creation of the key will be attempted from qemuProcessPrepareHost once the libDir directory structure exists. The removal of the key will handled from qemuProcessStop just prior to deleting the libDir tree. Since the key will not be written out to the domain object XML file, the qemuProcessReconnect will read the saved file and restore the masterKey and masterKeyLen.
2016-03-29 18:22:46 -04:00
int qemuDomainWriteMasterKeyFile(virQEMUDriver *driver,
virDomainObj *vm);
int qemuDomainMasterKeyCreate(virDomainObj *vm);
qemu: Create domain master key Add a masterKey and masterKeyLen to _qemuDomainObjPrivate to store a random domain master key and its length in order to support the ability to encrypt/decrypt sensitive data shared between libvirt and qemu. The key will be base64 encoded and written to a file to be used by the command line building code to share with qemu. New API's from this patch: qemuDomainGetMasterKeyFilePath: Return a path to where the key is located qemuDomainWriteMasterKeyFile: (private) Open (create/trunc) the masterKey path and write the masterKey qemuDomainMasterKeyReadFile: Using the master key path, open/read the file, and store the masterKey and masterKeyLen. Expected use only from qemuProcessReconnect qemuDomainGenerateRandomKey: (private) Generate a random key using available algorithms The key is generated either from the gnutls_rnd function if it exists or a less cryptographically strong mechanism using virGenerateRandomBytes qemuDomainMasterKeyRemove: Remove traces of the master key, remove the *KeyFilePath qemuDomainMasterKeyCreate: Generate the domain master key and save the key in the location returned by qemuDomainGetMasterKeyFilePath. This API will first ensure the QEMU_CAPS_OBJECT_SECRET is set in the capabilities. If not, then there's no need to generate the secret or file. The creation of the key will be attempted from qemuProcessPrepareHost once the libDir directory structure exists. The removal of the key will handled from qemuProcessStop just prior to deleting the libDir tree. Since the key will not be written out to the domain object XML file, the qemuProcessReconnect will read the saved file and restore the masterKey and masterKeyLen.
2016-03-29 18:22:46 -04:00
void qemuDomainMasterKeyRemove(qemuDomainObjPrivate *priv);
qemu: Create domain master key Add a masterKey and masterKeyLen to _qemuDomainObjPrivate to store a random domain master key and its length in order to support the ability to encrypt/decrypt sensitive data shared between libvirt and qemu. The key will be base64 encoded and written to a file to be used by the command line building code to share with qemu. New API's from this patch: qemuDomainGetMasterKeyFilePath: Return a path to where the key is located qemuDomainWriteMasterKeyFile: (private) Open (create/trunc) the masterKey path and write the masterKey qemuDomainMasterKeyReadFile: Using the master key path, open/read the file, and store the masterKey and masterKeyLen. Expected use only from qemuProcessReconnect qemuDomainGenerateRandomKey: (private) Generate a random key using available algorithms The key is generated either from the gnutls_rnd function if it exists or a less cryptographically strong mechanism using virGenerateRandomBytes qemuDomainMasterKeyRemove: Remove traces of the master key, remove the *KeyFilePath qemuDomainMasterKeyCreate: Generate the domain master key and save the key in the location returned by qemuDomainGetMasterKeyFilePath. This API will first ensure the QEMU_CAPS_OBJECT_SECRET is set in the capabilities. If not, then there's no need to generate the secret or file. The creation of the key will be attempted from qemuProcessPrepareHost once the libDir directory structure exists. The removal of the key will handled from qemuProcessStop just prior to deleting the libDir tree. Since the key will not be written out to the domain object XML file, the qemuProcessReconnect will read the saved file and restore the masterKey and masterKeyLen.
2016-03-29 18:22:46 -04:00
void qemuDomainSecretInfoFree(qemuDomainSecretInfo *secinfo)
ATTRIBUTE_NONNULL(1);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(qemuDomainSecretInfo, qemuDomainSecretInfoFree);
void qemuDomainSecretInfoDestroy(qemuDomainSecretInfo *secinfo);
void qemuDomainSecretDiskDestroy(virDomainDiskDef *disk)
ATTRIBUTE_NONNULL(1);
qemuDomainSecretInfo *
qemuDomainSecretInfoTLSNew(qemuDomainObjPrivate *priv,
const char *srcAlias,
const char *secretUUID);
void qemuDomainSecretHostdevDestroy(virDomainHostdevDef *disk)
ATTRIBUTE_NONNULL(1);
void qemuDomainSecretChardevDestroy(virDomainChrSourceDef *dev)
ATTRIBUTE_NONNULL(1);
int qemuDomainSecretChardevPrepare(virQEMUDriverConfig *cfg,
qemuDomainObjPrivate *priv,
const char *chrAlias,
virDomainChrSourceDef *dev)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
ATTRIBUTE_NONNULL(4);
void qemuDomainCleanupStorageSourceFD(virStorageSource *src);
void qemuDomainStartupCleanup(virDomainObj *vm);
int qemuGetMemoryBackingPath(qemuDomainObjPrivate *priv,
const char *alias,
char **memPath);
int qemuDomainSecretPrepare(virQEMUDriver *driver,
virDomainObj *vm)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
int qemuDomainDeviceDefValidateDisk(const virDomainDiskDef *disk,
virQEMUCaps *qemuCaps);
int qemuDomainDeviceDiskDefPostParse(virDomainDiskDef *disk,
unsigned int parseFlags);
int qemuDomainPrepareChannel(virDomainChrDef *chr,
const char *domainChannelTargetDir)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
struct qemuDomainPrepareChardevSourceData {
virQEMUDriverConfig *cfg;
bool hotplug;
};
int
qemuDomainPrepareChardevSourceOne(virDomainDeviceDef *dev,
virDomainChrSourceDef *charsrc,
void *opaque);
void qemuDomainPrepareShmemChardev(virDomainShmemDef *shmem)
ATTRIBUTE_NONNULL(1);
bool qemuDomainVcpuHotplugIsInOrder(virDomainDef *def)
ATTRIBUTE_NONNULL(1);
void qemuDomainVcpuPersistOrder(virDomainDef *def)
ATTRIBUTE_NONNULL(1);
int qemuDomainCheckMonitor(virDomainObj *vm,
virDomainAsyncJob asyncJob);
bool qemuDomainSupportsVideoVga(const virDomainVideoDef *video,
virQEMUCaps *qemuCaps);
bool qemuDomainNeedsVFIO(const virDomainDef *def);
int qemuDomainGetHostdevPath(virDomainHostdevDef *dev,
char **path,
int *perms);
virDomainDiskDef *qemuDomainDiskLookupByNodename(virDomainDef *def,
virDomainBackupDef *backupdef,
const char *nodename,
virStorageSource **src);
char *qemuDomainDiskBackingStoreGetName(virDomainDiskDef *disk,
unsigned int idx);
virStorageSource *qemuDomainGetStorageSourceByDevstr(const char *devstr,
virDomainDef *def,
virDomainBackupDef *backupdef);
void
qemuDomainUpdateCPU(virDomainObj *vm,
virCPUDef *cpu,
virCPUDef **origCPU);
void
qemuDomainFixupCPUs(virDomainObj *vm,
virCPUDef **origCPU);
char *
qemuDomainGetMachineName(virDomainObj *vm);
void
qemuDomainObjPrivateXMLFormatAllowReboot(virBuffer *buf,
virTristateBool allowReboot);
int
qemuDomainObjPrivateXMLParseAllowReboot(xmlXPathContextPtr ctxt,
virTristateBool *allowReboot);
void
qemuDomainPrepareDiskSourceData(virDomainDiskDef *disk,
virStorageSource *src);
int
qemuDomainValidateStorageSource(virStorageSource *src,
virQEMUCaps *qemuCaps);
int
qemuDomainPrepareDiskSource(virDomainDiskDef *disk,
qemuDomainObjPrivate *priv,
virQEMUDriverConfig *cfg);
bool
qemuDomainDiskCachemodeFlags(virDomainDiskCache cachemode,
bool *writeback,
bool *direct,
bool *noflush);
int
qemuDomainPrepareHostdev(virDomainHostdevDef *hostdev,
qemuDomainObjPrivate *priv);
char * qemuDomainGetManagedPRSocketPath(qemuDomainObjPrivate *priv);
bool qemuDomainDefHasManagedPR(virDomainObj *vm);
unsigned int qemuDomainFDSetIDNew(qemuDomainObjPrivate *priv);
virDomainEventResumedDetailType
qemuDomainRunningReasonToResumeEvent(virDomainRunningReason reason);
bool
qemuDomainDiskIsMissingLocalOptional(virDomainDiskDef *disk);
virDomainEventSuspendedDetailType
qemuDomainPausedReasonToSuspendedEvent(virDomainPausedReason reason);
int
qemuDomainValidateActualNetDef(const virDomainNetDef *net,
virQEMUCaps *qemuCaps);
int
qemuDomainSupportsCheckpointsBlockjobs(virDomainObj *vm)
G_GNUC_WARN_UNUSED_RESULT;
int
qemuDomainMakeCPUMigratable(virArch arch,
virCPUDef *cpu,
virCPUDef *origCPU);
int
qemuDomainInitializePflashStorageSource(virDomainObj *vm,
virQEMUDriverConfig *cfg);
bool
qemuDomainDiskBlockJobIsSupported(virDomainDiskDef *disk);
qemu_domain.c: NUMA CPUs auto-fill for incomplete topologies Libvirt allows the user to define an incomplete NUMA topology, where the sum of all CPUs in each cell is less than the total of VCPUs. What ends up happening is that QEMU allocates the non-enumerated CPUs in the first NUMA node. This behavior is being flagged as 'to be deprecated' at least since QEMU commit ec78f8114bc4 ("numa: use possible_cpus for not mapped CPUs check"). In [1], Maxiwell suggested that we forbid the user to define such topologies. In his review [2], Peter Krempa pointed out that we can't break existing guests, and suggested that Libvirt should emulate the QEMU behavior of putting the remaining vCPUs in the first NUMA node in these cases. This patch implements Peter Krempa's suggestion. Since we're going to most likely end up with disjointed NUMA configuration in node 0 after the auto-fill, we're making auto-fill dependent on QEMU_CAPS_NUMA. A following patch will update the documentation not just to inform about the auto-fill mechanic with incomplete NUMA topologies, but also to discourage the user to create such topologies in the future. This approach also makes Libvirt independent of whether QEMU changes its current behavior since we're either auto-filling the CPUs in node 0 or the user (hopefully) is aware that incomplete topologies, although supported in Libvirt, are to be avoided. [1] https://www.redhat.com/archives/libvir-list/2019-June/msg00224.html [2] https://www.redhat.com/archives/libvir-list/2019-June/msg00263.html Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-06-10 15:35:51 -03:00
int
qemuDomainDefNumaCPUsRectify(virDomainDef *def,
virQEMUCaps *qemuCaps);
int virQEMUFileOpenAs(uid_t fallback_uid,
gid_t fallback_gid,
bool dynamicOwnership,
const char *path,
int oflags,
bool *needUnlink);
int
qemuDomainOpenFile(virQEMUDriverConfig *cfg,
const virDomainDef *def,
const char *path,
int oflags,
bool *needUnlink);
int
qemuDomainFileWrapperFDClose(virDomainObj *vm,
virFileWrapperFd *fd);
int
qemuDomainInterfaceSetDefaultQDisc(virQEMUDriver *driver,
virDomainNetDef *net);
int
qemuDomainNamePathsCleanup(virQEMUDriverConfig *cfg,
const char *name,
bool bestEffort);
char *
qemuDomainGetVHostUserFSSocketPath(qemuDomainObjPrivate *priv,
const virDomainFSDef *fs);
typedef int (*qemuDomainDeviceBackendChardevForeachCallback)(virDomainDeviceDef *dev,
virDomainChrSourceDef *charsrc,
void *opaque);
int
qemuDomainDeviceBackendChardevForeachOne(virDomainDeviceDef *dev,
qemuDomainDeviceBackendChardevForeachCallback cb,
void *opaque);
int
qemuDomainDeviceBackendChardevForeach(virDomainDef *def,
qemuDomainDeviceBackendChardevForeachCallback cb,
void *opaque);
int
qemuDomainRemoveLogs(virQEMUDriver *driver,
const char *name);
int
qemuDomainObjWait(virDomainObj *vm);
bool
qemuDomainObjIsActive(virDomainObj *vm);
int
qemuDomainRefreshStatsSchema(virDomainObj *dom);
int
qemuDomainSyncRxFilter(virDomainObj *vm,
virDomainNetDef *def,
virDomainAsyncJob asyncJob);
int
qemuDomainSchedCoreStart(virQEMUDriverConfig *cfg,
virDomainObj *vm);
void
qemuDomainSchedCoreStop(qemuDomainObjPrivate *priv);
virBitmap *
qemuDomainEvaluateCPUMask(const virDomainDef *def,
virBitmap *cpumask,
virBitmap *autoCpuset);
qemu: Start emulator thread with more generous cpuset.mems Consider a domain with two guest NUMA nodes and the following <numatune/> setting : <numatune> <memory mode="strict" nodeset="0"/> <memnode cellid="0" mode="strict" nodeset="1"/> </numatune> What this means is the emulator thread is pinned onto host NUMA node #0 (by setting corresponding cpuset.mems to "0"), and two memory-backend-* objects are created: -object '{"qom-type":"memory-backend-ram","id":"ram-node0", .., "host-nodes":[1],"policy":"bind"}' \ -numa node,nodeid=0,cpus=0-1,memdev=ram-node0 \ -object '{"qom-type":"memory-backend-ram","id":"ram-node1", .., "host-nodes":[0],"policy":"bind"}' \ -numa node,nodeid=1,cpus=2-3,memdev=ram-node1 \ Note, the emulator thread is pinned well before QEMU is even exec()-ed. Now, the way memory allocation works in QEMU is: the emulator thread calls mmap() followed by mbind() (which is sane, that's how everybody should do it). BUT, because the thread is already restricted by CGroups to just NUMA node #0, calling: mbind(host-nodes:[1]); /* made up syntax (TM) */ fails. This is expected though. Kernel was instructed to place the memory at NUMA node "0" and yet, process is trying to place it elsewhere. We used to solve this by not restricting emulator thread at all initially, and only after it's done initializing (i.e. we got the QMP greeting) we placed it onto desired nodes. But this had its own problems (e.g. QEMU might have locked pieces of its memory which were then unable to migrate onto different NUMA nodes). Therefore, in v5.1.0-rc1~282 we've changed this and set cgroups upfront (even before exec()-ing QEMU). And this used to work, but something has changed (I can't really put my finger on it). Therefore, for the initialization start the thread with union of all configured host NUMA nodes ("0-1" in our example) and fix the placement only after QEMU is started. NB, the memory hotplug suffers the same problem, but that will be fixed in the next commit. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2138150 Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2023-05-19 14:02:06 +02:00
void
qemuDomainNumatuneMaybeFormatNodesetUnion(virDomainObj *vm,
virBitmap **nodeset,
char **nodesetStr);
int
qemuDomainStorageOpenStat(virQEMUDriverConfig *cfg,
virDomainObj *vm,
virStorageSource *src,
int *ret_fd,
struct stat *ret_sb,
bool skipInaccessible);
void
qemuDomainStorageCloseStat(virStorageSource *src,
int *fd);
int
qemuDomainStorageUpdatePhysical(virQEMUDriverConfig *cfg,
virDomainObj *vm,
virStorageSource *src);