libvirt/src/qemu/qemu_command.h

252 lines
8.7 KiB
C
Raw Normal View History

/*
* qemu_command.h: QEMU command generation
*
* Copyright (C) 2006-2016 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 "domain_conf.h"
#include "virbitmap.h"
#include "vircommand.h"
#include "virenum.h"
#include "qemu_block.h"
#include "qemu_conf.h"
#include "qemu_domain.h"
#include "qemu_capabilities.h"
/* Config type for XML import/export conversions */
#define QEMU_CONFIG_FORMAT_ARGV "qemu-argv"
#define QEMU_FSDEV_HOST_PREFIX "fsdev-"
#define QEMU_BLOCK_IOTUNE_MAX 1000000000000000LL
VIR_ENUM_DECL(qemuVideo);
VIR_ENUM_DECL(qemuSoundCodec);
virCommand *qemuBuildCommandLine(virDomainObj *vm,
const char *migrateURI,
virDomainMomentObj *snapshot,
virNetDevVPortProfileOp vmop,
size_t *nnicindexes,
int **nicindexes);
/* Generate the object properties for pr-manager */
virJSONValue *qemuBuildPRManagerInfoProps(virStorageSource *src);
virJSONValue *qemuBuildPRManagedManagerInfoProps(qemuDomainObjPrivate *priv);
virJSONValue *qemuBuildDBusVMStateInfoProps(virQEMUDriver *driver,
virDomainObj *vm);
/* Generate the object properties for a secret */
int qemuBuildSecretInfoProps(qemuDomainSecretInfo *secinfo,
virJSONValue **propsret);
/* Generate the object properties for a tls-creds-x509 */
int qemuBuildTLSx509BackendProps(const char *tlspath,
bool isListen,
bool verifypeer,
const char *alias,
const char *secalias,
virJSONValue **propsret);
/* Open a UNIX socket for chardev FD passing */
int
qemuOpenChrChardevUNIXSocket(const virDomainChrSourceDef *dev) G_NO_INLINE;
virJSONValue *
qemuBuildChrDeviceProps(const virDomainDef *vmdef,
virDomainChrDef *chr,
virQEMUCaps *qemuCaps);
virJSONValue *
qemuBuildChannelGuestfwdNetdevProps(virDomainChrDef *chr);
virJSONValue *
qemuBuildHostNetProps(virDomainObj *vm,
virDomainNetDef *net);
int
qemuBuildInterfaceConnect(virDomainObj *vm,
virDomainNetDef *net,
virNetDevVPortProfileOp vmop);
/* Current, best practice */
virJSONValue *
qemuBuildNicDevProps(virDomainDef *def,
virDomainNetDef *net,
virQEMUCaps *qemuCaps);
char *qemuDeviceDriveHostAlias(virDomainDiskDef *disk);
bool qemuDiskBusIsSD(int bus);
int
qemuBuildStorageSourceAttachPrepareCommon(virStorageSource *src,
qemuBlockStorageSourceAttachData *data);
qemuBlockStorageSourceChainData *
qemuBuildStorageSourceChainAttachPrepareDrive(virDomainDiskDef *disk);
qemuBlockStorageSourceChainData *
qemuBuildStorageSourceChainAttachPrepareChardev(virDomainDiskDef *disk);
qemuBlockStorageSourceChainData *
qemuBuildStorageSourceChainAttachPrepareBlockdev(virStorageSource *top);
qemuBlockStorageSourceChainData *
qemuBuildStorageSourceChainAttachPrepareBlockdevTop(virStorageSource *top,
virStorageSource *backingStore);
qemuBuildDiskCommandLine: Generate via JSON The types for the special fields of the 'virtio-blk-pci' according to QEMU are: iothread=<link<iothread>> ioeventfd=<bool> - on/off (default: true) event_idx=<bool> - on/off (default: true) scsi=<bool> - on/off (default: false) num-queues=<uint16> - (default: 65535) queue-size=<uint16> - (default: 256) For all disks we also use the following properties (based on 'scsi-hd'): device_id=<str> share-rw=<bool> - (default: false) drive=<str> - Node name or ID of a block device to use as a backend chardev=<str> - ID of a chardev to use as a backend <- vhost-user-blk-pci bootindex=<int32> logical_block_size=<size> - A power of two between 512 B and 2 MiB (default: 0) physical_block_size=<size> - A power of two between 512 B and 2 MiB (default: 0) wwn=<uint64> - (default: 0) rotation_rate=<uint16> - (default: 0) vendor=<str> product=<str> removable=<bool> - on/off (default: false) write-cache=<OnOffAuto> - on/off/auto (default: "auto") cyls=<uint32> - (default: 0) heads=<uint32> - (default: 0) secs=<uint32> - (default: 0) bios-chs-trans=<BiosAtaTranslation> - Logical CHS translation algorithm, auto/none/lba/large/rechs (default: "auto") <- ide-hd serial=<str> werror=<BlockdevOnError> - Error handling policy, report/ignore/enospc/stop/auto (default: "auto") rerror=<BlockdevOnError> - Error handling policy, report/ignore/enospc/stop/auto (default: "auto") The 'wwn' field is changed from a hex string to a number since qemu actually treats it as a number. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-10-04 14:54:54 +00:00
virJSONValue *
qemuBuildDiskDeviceProps(const virDomainDef *def,
virDomainDiskDef *disk,
virQEMUCaps *qemuCaps);
virJSONValue *
qemuBuildVHostUserFsDevProps(virDomainFSDef *fs,
const virDomainDef *def,
const char *chardev_alias,
qemuDomainObjPrivate *priv);
/* Current, best practice */
int
qemuBuildControllerDevProps(const virDomainDef *domainDef,
virDomainControllerDef *def,
virQEMUCaps *qemuCaps,
virJSONValue **devprops);
int qemuBuildMemoryBackendProps(virJSONValue **backendProps,
const char *alias,
virQEMUDriverConfig *cfg,
qemuDomainObjPrivate *priv,
const virDomainDef *def,
const virDomainMemoryDef *mem,
qemu: Do not Use canonical path for system memory In commit 88957116c9d3cb4705380c3702c9d4315fb500bb I've adapted libvirt to QEMU's deprecation of -mem-path and -mem-prealloc and switched to memory-backend-* even for system memory. My claim was that that's what QEMU does under the hood anyway. And indeed it was: see QEMU commit 900c0ba373aada4c13d47d95330aa72ec4067ba5 and look at function create_default_memdev(). However, then commit d96c4d5f193e0e45beec80a6277728b32875bddb was merged into QEMU. While it was fixing a bug, it also changed the create_default_memdev() function in which it started turning off use of canonical path (by setting "x-use-canonical-path-for-ramblock-id" attribute to false). This wasn't documented until QEMU commit 8db0b20415c129cf5e577a593a4a0372d90b7cc9. The path affects migration - the same path has to be used on the source and on the destination. Therefore, if there is old guest started with '-m X' it has "pc.ram" block which doesn't use canonical path and thus when migrating to newer QEMU which uses memory-backend-* we have to turn off the canonical path explicitly. Otherwise, "/objects/pc.ram" path would be expected by QEMU which doesn't match the source. Ideally, we would need to set it only for some machine types (4.0 and older) because newer machine types already do what we are doing. However, we treat machine types as opaque strings and therefore we don't want to parse nor inspect their versions. But then again, newer machine types already do what we are doing in this commit, so when old machine types are deprecated and removed we can remove our hack and forget it ever happened. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1912201 Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-01-08 15:35:26 +00:00
bool force,
bool systemMemory,
virBitmap **nodemaskRet);
virJSONValue *
qemu: Allow prealloc for virtio-mem-pci There are a some scenarios in which we want to prealloc guest memory (e.g. when requested in domain XML, when using hugepages, etc.). With 'regular' <memory/> models (like 'dimm', 'nvdimm' or 'virtio-pmem') or regular guest memory it is corresponding memory-backend-* object that ends up with .prealloc attribute set. And that's desired because neither of those devices can change its size on the fly. However, with virtio-mem model things are a bit different. While one can set .prealloc attribute on corresponding memory-backend-* object it doesn't make much sense, because virtio-mem can inflate/deflate on the fly, i.e. change how big of a portion of the memory-backend-* object is exposed to the guest. For instance, from a say 4GiB module only a half can be exposed to the guest. Therefore, it doesn't make much sense to preallocate whole 4GiB and keep them allocated. But we still want the part exposed to the guest preallocated (when conditions described at the beginning are met). Having said that, with new enough QEMU the virtio-mem-pci device gained new attribute ".prealloc" which instructs the device to talk to the memory backend object and allocate only the requested portion of memory. Now, that our algorithm for setting .prealloc was isolated in a single function, the function can be called when constructing cmd line for virtio-mem-pci device. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-30 17:16:00 +00:00
qemuBuildMemoryDeviceProps(virQEMUDriverConfig *cfg,
qemuDomainObjPrivate *priv,
const virDomainDef *def,
const virDomainMemoryDef *mem);
int
qemuBuildThreadContextProps(virJSONValue **tcProps,
virJSONValue **memProps,
const virDomainDef *def,
qemuDomainObjPrivate *priv,
virBitmap *nodemask);
/* Current, best practice */
virJSONValue *
qemuBuildPCIHostdevDevProps(const virDomainDef *def,
virDomainHostdevDef *dev);
virJSONValue *
qemuBuildRNGDevProps(const virDomainDef *def,
virDomainRNGDef *dev,
virQEMUCaps *qemuCaps);
int qemuBuildRNGBackendProps(virDomainRNGDef *rng,
virJSONValue **props);
/* Current, best practice */
virJSONValue *
qemuBuildUSBHostdevDevProps(const virDomainDef *def,
virDomainHostdevDef *dev,
virQEMUCaps *qemuCaps);
virJSONValue *
qemuBuildSCSIHostdevDevProps(const virDomainDef *def,
virDomainHostdevDef *dev,
const char *backendAlias);
qemuBlockStorageSourceAttachData *
qemuBuildHostdevSCSIAttachPrepare(virDomainHostdevDef *hostdev,
const char **backendAlias,
virQEMUCaps *qemuCaps);
qemuBlockStorageSourceAttachData *
qemuBuildHostdevSCSIDetachPrepare(virDomainHostdevDef *hostdev,
virQEMUCaps *qemuCaps);
virJSONValue *
qemuBuildSCSIVHostHostdevDevProps(const virDomainDef *def,
virDomainHostdevDef *dev,
virQEMUCaps *qemuCaps,
char *vhostfdName);
virJSONValue *
qemuBuildHostdevMediatedDevProps(const virDomainDef *def,
virDomainHostdevDef *dev);
virJSONValue *
qemuBuildRedirdevDevProps(const virDomainDef *def,
virDomainRedirdevDef *dev);
virJSONValue *
qemuBuildZPCIDevProps(virDomainDeviceInfo *dev);
int qemuNetworkPrepareDevices(virDomainDef *def);
qemu: allocate network connections sooner during domain startup VFIO device assignment requires a cgroup ACL to be setup for access to the /dev/vfio/nn "group" device for any devices that will be assigned to a guest. In the case of a host device that is allocated from a pool, it was being allocated during qemuBuildCommandLine(), which is called by qemuProcessStart() *after* the all-encompassing qemuSetupCgroup() was called, meaning that the standard Cgroup ACL setup wasn't creating ACLs for these devices allocated from pools. One possible solution was to manually add a single ACL down inside qemuBuildCommandLine() when networkAllocateActualDevice() is called, but that has two problems: 1) the function that adds the cgroup ACL requires a virDomainObjPtr, which isn't available in qemuBuildCommandLine(), and 2) we really shouldn't be doing network device setup inside qemuBuildCommandLine() anyway. Instead, I've created a new function called qemuNetworkPrepareDevices() which is called just before qemuPrepareHostDevices() during qemuProcessStart() (explanation of ordering in the comments), i.e. well before the call to qemuSetupCgroup(). To minimize code churn in a patch that will be backported to 1.0.5-maint, qemuNetworkPrepareDevices only does networkAllocateActualDevice() and the bare amount of setup required for type='hostdev network devices, but it eventually should do *all* device setup for guest network devices. Note that some of the code that was previously needed in qemuBuildCommandLine() is no longer required when networkAllocateActualDevice() is called earlier: * qemuAssignDeviceHostdevAlias() is already done further down in qemuProcessStart(). * qemuPrepareHostdevPCIDevices() is called by qemuPrepareHostDevices() which is called after qemuNetworkPrepareDevices() in qemuProcessStart(). As hinted above, this new function should be moved into a separate qemu_network.c (or similarly named) file along with qemuPhysIfaceConnect(), qemuNetworkIfaceConnect(), and qemuOpenVhostNet(), and expanded to call those functions as well, then the nnets loop in qemuBuildCommandLine() should be reduced to only build the commandline string (which itself can be in a separate qemuInterfaceBuilldCommandLine() function as suggested by Michal). However, this will require storing away an array of tapfd and vhostfd that are needed for the commandline, so I would rather do that in a separate patch and leave this patch at the minimum to fix the bug.
2013-05-06 19:43:56 +00:00
bool
qemuDiskConfigBlkdeviotuneEnabled(const virDomainDiskDef *disk);
virJSONValue *qemuBuildHotpluggableCPUProps(const virDomainVcpuDef *vcpu)
ATTRIBUTE_NONNULL(1);
virJSONValue *qemuBuildShmemBackendMemProps(virDomainShmemDef *shmem)
ATTRIBUTE_NONNULL(1);
virJSONValue *
qemuBuildShmemDevProps(virDomainDef *def,
virDomainShmemDef *shmem);
virJSONValue *
qemuBuildWatchdogDevProps(const virDomainDef *def,
virDomainWatchdogDef *dev);
virJSONValue *
qemuBuildInputVirtioDevProps(const virDomainDef *def,
virDomainInputDef *dev,
virQEMUCaps *qemuCaps);
virJSONValue *
qemuBuildInputUSBDevProps(const virDomainDef *def,
virDomainInputDef *dev);
virJSONValue *
qemuBuildVsockDevProps(virDomainDef *def,
virDomainVsockDef *vsock,
virQEMUCaps *qemuCaps,
const char *fdprefix);
/* this function is exported so that tests can mock the FDs */
int
qemuBuildTPMOpenBackendFDs(const char *tpmdev,
int *tpmfd,
int *cancelfd)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) G_NO_INLINE;
const char * qemuAudioDriverTypeToString(virDomainAudioType type);
virDomainAudioType qemuAudioDriverTypeFromString(const char *str);
int qemuVDPAConnect(const char *devicepath) G_NO_INLINE;