mirror of https://gitee.com/openkylin/libvirt.git
Move QEMU command line management into a separate file
The qemu_conf.c code is doing three jobs, driver config file loading, QEMU capabilities management and QEMU command line management. Move the command line code into its own file * src/qemu/qemu_command.c, src/qemu/qemu_command.h: New command line management code * src/qemu/qemu_conf.c, src/qemu/qemu_conf.h: Delete command line code * src/qemu/qemu_conf.h, src/qemu_conf.c: Adapt for API renames * src/Makefile.am: add src/qemu/qemu_command.c * src/qemu/qemu_monitor_json.c, src/qemu/qemu_monitor_text.c: Add import of qemu_command.h
This commit is contained in:
parent
d8ae147d8e
commit
0f2e4b9c68
|
@ -52,6 +52,7 @@ src/openvz/openvz_driver.c
|
|||
src/phyp/phyp_driver.c
|
||||
src/qemu/qemu_bridge_filter.c
|
||||
src/qemu/qemu_capabilities.c
|
||||
src/qemu/qemu_command.c
|
||||
src/qemu/qemu_conf.c
|
||||
src/qemu/qemu_driver.c
|
||||
src/qemu/qemu_monitor.c
|
||||
|
|
|
@ -268,6 +268,7 @@ VBOX_DRIVER_EXTRA_DIST = vbox/vbox_tmpl.c vbox/README
|
|||
|
||||
QEMU_DRIVER_SOURCES = \
|
||||
qemu/qemu_capabilities.c qemu/qemu_capabilities.h\
|
||||
qemu/qemu_command.c qemu/qemu_command.h \
|
||||
qemu/qemu_conf.c qemu/qemu_conf.h \
|
||||
qemu/qemu_monitor.c qemu/qemu_monitor.h \
|
||||
qemu/qemu_monitor_text.c \
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,165 @@
|
|||
/*
|
||||
* qemu_command.h: QEMU command generation
|
||||
*
|
||||
* Copyright (C) 2006-2007, 2009-2010 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, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Daniel P. Berrange <berrange@redhat.com>
|
||||
*/
|
||||
|
||||
#ifndef __QEMU_COMMAND_H__
|
||||
# define __QEMU_COMMAND_H__
|
||||
|
||||
# include "domain_conf.h"
|
||||
# include "command.h"
|
||||
# include "capabilities.h"
|
||||
# include "qemu_conf.h"
|
||||
|
||||
/* Config type for XML import/export conversions */
|
||||
# define QEMU_CONFIG_FORMAT_ARGV "qemu-argv"
|
||||
|
||||
# define QEMU_DRIVE_HOST_PREFIX "drive-"
|
||||
# define QEMU_VIRTIO_SERIAL_PREFIX "virtio-serial"
|
||||
# define QEMU_FSDEV_HOST_PREFIX "fsdev-"
|
||||
|
||||
virCommandPtr qemuBuildCommandLine(virConnectPtr conn,
|
||||
struct qemud_driver *driver,
|
||||
virDomainDefPtr def,
|
||||
virDomainChrDefPtr monitor_chr,
|
||||
bool monitor_json,
|
||||
unsigned long long qemuCmdFlags,
|
||||
const char *migrateFrom,
|
||||
virDomainSnapshotObjPtr current_snapshot,
|
||||
enum virVMOperationType vmop)
|
||||
ATTRIBUTE_NONNULL(1);
|
||||
|
||||
/* With vlan == -1, use netdev syntax, else old hostnet */
|
||||
char * qemuBuildHostNetStr(virDomainNetDefPtr net,
|
||||
char type_sep,
|
||||
int vlan,
|
||||
const char *tapfd,
|
||||
const char *vhostfd);
|
||||
|
||||
/* Legacy, pre device support */
|
||||
char * qemuBuildNicStr(virDomainNetDefPtr net,
|
||||
const char *prefix,
|
||||
int vlan);
|
||||
|
||||
/* Current, best practice */
|
||||
char * qemuBuildNicDevStr(virDomainNetDefPtr net,
|
||||
int vlan);
|
||||
|
||||
char *qemuDeviceDriveHostAlias(virDomainDiskDefPtr disk,
|
||||
unsigned long long qemuCmdFlags);
|
||||
|
||||
/* Both legacy & current support */
|
||||
char *qemuBuildDriveStr(virDomainDiskDefPtr disk,
|
||||
int bootable,
|
||||
unsigned long long qemuCmdFlags);
|
||||
char *qemuBuildFSStr(virDomainFSDefPtr fs,
|
||||
unsigned long long qemuCmdFlags);
|
||||
|
||||
/* Current, best practice */
|
||||
char * qemuBuildDriveDevStr(virDomainDiskDefPtr disk);
|
||||
char * qemuBuildFSDevStr(virDomainFSDefPtr fs);
|
||||
/* Current, best practice */
|
||||
char * qemuBuildControllerDevStr(virDomainControllerDefPtr def);
|
||||
|
||||
char * qemuBuildWatchdogDevStr(virDomainWatchdogDefPtr dev);
|
||||
|
||||
char * qemuBuildMemballoonDevStr(virDomainMemballoonDefPtr dev);
|
||||
|
||||
char * qemuBuildUSBInputDevStr(virDomainInputDefPtr dev);
|
||||
|
||||
char * qemuBuildSoundDevStr(virDomainSoundDefPtr sound);
|
||||
|
||||
/* Legacy, pre device support */
|
||||
char * qemuBuildPCIHostdevPCIDevStr(virDomainHostdevDefPtr dev);
|
||||
/* Current, best practice */
|
||||
char * qemuBuildPCIHostdevDevStr(virDomainHostdevDefPtr dev,
|
||||
const char *configfd);
|
||||
|
||||
int qemuOpenPCIConfig(virDomainHostdevDefPtr dev);
|
||||
|
||||
/* Current, best practice */
|
||||
char * qemuBuildChrChardevStr(virDomainChrDefPtr dev);
|
||||
/* Legacy, pre device support */
|
||||
char * qemuBuildChrArgStr(virDomainChrDefPtr dev, const char *prefix);
|
||||
|
||||
char * qemuBuildVirtioSerialPortDevStr(virDomainChrDefPtr dev);
|
||||
|
||||
/* Legacy, pre device support */
|
||||
char * qemuBuildUSBHostdevUsbDevStr(virDomainHostdevDefPtr dev);
|
||||
/* Current, best practice */
|
||||
char * qemuBuildUSBHostdevDevStr(virDomainHostdevDefPtr dev);
|
||||
|
||||
|
||||
|
||||
int qemuNetworkIfaceConnect(virConnectPtr conn,
|
||||
struct qemud_driver *driver,
|
||||
virDomainNetDefPtr net,
|
||||
unsigned long long qemCmdFlags)
|
||||
ATTRIBUTE_NONNULL(1);
|
||||
|
||||
int qemuOpenVhostNet(virDomainNetDefPtr net,
|
||||
unsigned long long qemuCmdFlags);
|
||||
|
||||
int qemuPhysIfaceConnect(virConnectPtr conn,
|
||||
struct qemud_driver *driver,
|
||||
virDomainNetDefPtr net,
|
||||
unsigned long long qemuCmdFlags,
|
||||
const unsigned char *vmuuid,
|
||||
enum virVMOperationType vmop);
|
||||
|
||||
int qemudCanonicalizeMachine(struct qemud_driver *driver,
|
||||
virDomainDefPtr def);
|
||||
|
||||
virDomainDefPtr qemuParseCommandLine(virCapsPtr caps,
|
||||
const char **progenv,
|
||||
const char **progargv);
|
||||
virDomainDefPtr qemuParseCommandLineString(virCapsPtr caps,
|
||||
const char *args);
|
||||
|
||||
qemuDomainPCIAddressSetPtr qemuDomainPCIAddressSetCreate(virDomainDefPtr def);
|
||||
int qemuDomainPCIAddressReserveSlot(qemuDomainPCIAddressSetPtr addrs,
|
||||
int slot);
|
||||
int qemuDomainPCIAddressReserveAddr(qemuDomainPCIAddressSetPtr addrs,
|
||||
virDomainDeviceInfoPtr dev);
|
||||
int qemuDomainPCIAddressSetNextAddr(qemuDomainPCIAddressSetPtr addrs,
|
||||
virDomainDeviceInfoPtr dev);
|
||||
int qemuDomainPCIAddressEnsureAddr(qemuDomainPCIAddressSetPtr addrs,
|
||||
virDomainDeviceInfoPtr dev);
|
||||
int qemuDomainPCIAddressReleaseAddr(qemuDomainPCIAddressSetPtr addrs,
|
||||
virDomainDeviceInfoPtr dev);
|
||||
|
||||
void qemuDomainPCIAddressSetFree(qemuDomainPCIAddressSetPtr addrs);
|
||||
int qemuAssignDevicePCISlots(virDomainDefPtr def, qemuDomainPCIAddressSetPtr addrs);
|
||||
|
||||
int qemuDomainNetVLAN(virDomainNetDefPtr def);
|
||||
int qemuAssignDeviceNetAlias(virDomainDefPtr def, virDomainNetDefPtr net, int idx);
|
||||
int qemuAssignDeviceDiskAlias(virDomainDiskDefPtr def, unsigned long long qemuCmdFlags);
|
||||
int qemuAssignDeviceHostdevAlias(virDomainDefPtr def, virDomainHostdevDefPtr net, int idx);
|
||||
int qemuAssignDeviceControllerAlias(virDomainControllerDefPtr controller);
|
||||
|
||||
int
|
||||
qemuParseKeywords(const char *str,
|
||||
char ***retkeywords,
|
||||
char ***retvalues,
|
||||
int allowEmptyValue);
|
||||
|
||||
|
||||
#endif /* __QEMU_COMMAND_H__*/
|
5751
src/qemu/qemu_conf.c
5751
src/qemu/qemu_conf.c
File diff suppressed because it is too large
Load Diff
|
@ -148,13 +148,6 @@ struct _qemuDomainCmdlineDef {
|
|||
# define QEMUD_MIGRATION_FIRST_PORT 49152
|
||||
# define QEMUD_MIGRATION_NUM_PORTS 64
|
||||
|
||||
/* Config type for XML import/export conversions */
|
||||
# define QEMU_CONFIG_FORMAT_ARGV "qemu-argv"
|
||||
|
||||
# define QEMU_DRIVE_HOST_PREFIX "drive-"
|
||||
# define QEMU_VIRTIO_SERIAL_PREFIX "virtio-serial"
|
||||
# define QEMU_FSDEV_HOST_PREFIX "fsdev-"
|
||||
|
||||
# define qemuReportError(code, ...) \
|
||||
virReportErrorHelper(NULL, VIR_FROM_QEMU, code, __FILE__, \
|
||||
__FUNCTION__, __LINE__, __VA_ARGS__)
|
||||
|
@ -163,131 +156,4 @@ struct _qemuDomainCmdlineDef {
|
|||
int qemudLoadDriverConfig(struct qemud_driver *driver,
|
||||
const char *filename);
|
||||
|
||||
virCommandPtr qemudBuildCommandLine (virConnectPtr conn,
|
||||
struct qemud_driver *driver,
|
||||
virDomainDefPtr def,
|
||||
virDomainChrDefPtr monitor_chr,
|
||||
bool monitor_json,
|
||||
unsigned long long qemuCmdFlags,
|
||||
const char *migrateFrom,
|
||||
virDomainSnapshotObjPtr current_snapshot,
|
||||
enum virVMOperationType vmop)
|
||||
ATTRIBUTE_NONNULL(1);
|
||||
|
||||
/* With vlan == -1, use netdev syntax, else old hostnet */
|
||||
char * qemuBuildHostNetStr(virDomainNetDefPtr net,
|
||||
char type_sep,
|
||||
int vlan,
|
||||
const char *tapfd,
|
||||
const char *vhostfd);
|
||||
|
||||
/* Legacy, pre device support */
|
||||
char * qemuBuildNicStr(virDomainNetDefPtr net,
|
||||
const char *prefix,
|
||||
int vlan);
|
||||
|
||||
/* Current, best practice */
|
||||
char * qemuBuildNicDevStr(virDomainNetDefPtr net,
|
||||
int vlan);
|
||||
|
||||
char *qemuDeviceDriveHostAlias(virDomainDiskDefPtr disk,
|
||||
unsigned long long qemudCmdFlags);
|
||||
|
||||
/* Both legacy & current support */
|
||||
char *qemuBuildDriveStr(virDomainDiskDefPtr disk,
|
||||
int bootable,
|
||||
unsigned long long qemuCmdFlags);
|
||||
char *qemuBuildFSStr(virDomainFSDefPtr fs,
|
||||
unsigned long long qemuCmdFlags);
|
||||
|
||||
/* Current, best practice */
|
||||
char * qemuBuildDriveDevStr(virDomainDiskDefPtr disk);
|
||||
char * qemuBuildFSDevStr(virDomainFSDefPtr fs);
|
||||
/* Current, best practice */
|
||||
char * qemuBuildControllerDevStr(virDomainControllerDefPtr def);
|
||||
|
||||
char * qemuBuildWatchdogDevStr(virDomainWatchdogDefPtr dev);
|
||||
|
||||
char * qemuBuildMemballoonDevStr(virDomainMemballoonDefPtr dev);
|
||||
|
||||
char * qemuBuildUSBInputDevStr(virDomainInputDefPtr dev);
|
||||
|
||||
char * qemuBuildSoundDevStr(virDomainSoundDefPtr sound);
|
||||
|
||||
/* Legacy, pre device support */
|
||||
char * qemuBuildPCIHostdevPCIDevStr(virDomainHostdevDefPtr dev);
|
||||
/* Current, best practice */
|
||||
char * qemuBuildPCIHostdevDevStr(virDomainHostdevDefPtr dev,
|
||||
const char *configfd);
|
||||
|
||||
int qemudOpenPCIConfig(virDomainHostdevDefPtr dev);
|
||||
|
||||
/* Current, best practice */
|
||||
char * qemuBuildChrChardevStr(virDomainChrDefPtr dev);
|
||||
/* Legacy, pre device support */
|
||||
char * qemuBuildChrArgStr(virDomainChrDefPtr dev, const char *prefix);
|
||||
|
||||
char * qemuBuildVirtioSerialPortDevStr(virDomainChrDefPtr dev);
|
||||
|
||||
/* Legacy, pre device support */
|
||||
char * qemuBuildUSBHostdevUsbDevStr(virDomainHostdevDefPtr dev);
|
||||
/* Current, best practice */
|
||||
char * qemuBuildUSBHostdevDevStr(virDomainHostdevDefPtr dev);
|
||||
|
||||
|
||||
|
||||
int qemudNetworkIfaceConnect (virConnectPtr conn,
|
||||
struct qemud_driver *driver,
|
||||
virDomainNetDefPtr net,
|
||||
unsigned long long qemuCmdFlags)
|
||||
ATTRIBUTE_NONNULL(1);
|
||||
|
||||
int
|
||||
qemudOpenVhostNet(virDomainNetDefPtr net,
|
||||
unsigned long long qemuCmdFlags);
|
||||
|
||||
int qemudPhysIfaceConnect(virConnectPtr conn,
|
||||
struct qemud_driver *driver,
|
||||
virDomainNetDefPtr net,
|
||||
unsigned long long qemuCmdFlags,
|
||||
const unsigned char *vmuuid,
|
||||
enum virVMOperationType vmop);
|
||||
|
||||
int qemudCanonicalizeMachine (struct qemud_driver *driver,
|
||||
virDomainDefPtr def);
|
||||
|
||||
virDomainDefPtr qemuParseCommandLine(virCapsPtr caps,
|
||||
const char **progenv,
|
||||
const char **progargv);
|
||||
virDomainDefPtr qemuParseCommandLineString(virCapsPtr caps,
|
||||
const char *args);
|
||||
|
||||
qemuDomainPCIAddressSetPtr qemuDomainPCIAddressSetCreate(virDomainDefPtr def);
|
||||
int qemuDomainPCIAddressReserveSlot(qemuDomainPCIAddressSetPtr addrs,
|
||||
int slot);
|
||||
int qemuDomainPCIAddressReserveAddr(qemuDomainPCIAddressSetPtr addrs,
|
||||
virDomainDeviceInfoPtr dev);
|
||||
int qemuDomainPCIAddressSetNextAddr(qemuDomainPCIAddressSetPtr addrs,
|
||||
virDomainDeviceInfoPtr dev);
|
||||
int qemuDomainPCIAddressEnsureAddr(qemuDomainPCIAddressSetPtr addrs,
|
||||
virDomainDeviceInfoPtr dev);
|
||||
int qemuDomainPCIAddressReleaseAddr(qemuDomainPCIAddressSetPtr addrs,
|
||||
virDomainDeviceInfoPtr dev);
|
||||
|
||||
void qemuDomainPCIAddressSetFree(qemuDomainPCIAddressSetPtr addrs);
|
||||
int qemuAssignDevicePCISlots(virDomainDefPtr def, qemuDomainPCIAddressSetPtr addrs);
|
||||
|
||||
int qemuDomainNetVLAN(virDomainNetDefPtr def);
|
||||
int qemuAssignDeviceNetAlias(virDomainDefPtr def, virDomainNetDefPtr net, int idx);
|
||||
int qemuAssignDeviceDiskAlias(virDomainDiskDefPtr def, unsigned long long qemuCmdFlags);
|
||||
int qemuAssignDeviceHostdevAlias(virDomainDefPtr def, virDomainHostdevDefPtr net, int idx);
|
||||
int qemuAssignDeviceControllerAlias(virDomainControllerDefPtr controller);
|
||||
|
||||
int
|
||||
qemuParseKeywords(const char *str,
|
||||
char ***retkeywords,
|
||||
char ***retvalues,
|
||||
int allowEmptyValue);
|
||||
|
||||
|
||||
#endif /* __QEMUD_CONF_H */
|
||||
|
|
|
@ -55,6 +55,7 @@
|
|||
#include "qemu_driver.h"
|
||||
#include "qemu_conf.h"
|
||||
#include "qemu_capabilities.h"
|
||||
#include "qemu_command.h"
|
||||
#include "qemu_monitor.h"
|
||||
#include "qemu_bridge_filter.h"
|
||||
#include "c-ctype.h"
|
||||
|
@ -4134,10 +4135,10 @@ static int qemudStartVMDaemon(virConnectPtr conn,
|
|||
|
||||
DEBUG0("Building emulator command line");
|
||||
vm->def->id = driver->nextvmid++;
|
||||
if (!(cmd = qemudBuildCommandLine(conn, driver, vm->def, priv->monConfig,
|
||||
priv->monJSON != 0, qemuCmdFlags,
|
||||
migrateFrom,
|
||||
vm->current_snapshot, vmop)))
|
||||
if (!(cmd = qemuBuildCommandLine(conn, driver, vm->def, priv->monConfig,
|
||||
priv->monJSON != 0, qemuCmdFlags,
|
||||
migrateFrom,
|
||||
vm->current_snapshot, vmop)))
|
||||
goto cleanup;
|
||||
|
||||
if (qemuDomainSnapshotSetInactive(vm, driver->snapshotDir) < 0)
|
||||
|
@ -7474,9 +7475,9 @@ static char *qemuDomainXMLToNative(virConnectPtr conn,
|
|||
if (qemuPrepareMonitorChr(driver, &monConfig, def->name) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!(cmd = qemudBuildCommandLine(conn, driver, def,
|
||||
&monConfig, false, qemuCmdFlags,
|
||||
NULL, NULL, VIR_VM_OP_NO_OP)))
|
||||
if (!(cmd = qemuBuildCommandLine(conn, driver, def,
|
||||
&monConfig, false, qemuCmdFlags,
|
||||
NULL, NULL, VIR_VM_OP_NO_OP)))
|
||||
goto cleanup;
|
||||
|
||||
ret = virCommandToString(cmd);
|
||||
|
@ -8368,7 +8369,7 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn,
|
|||
return -1;
|
||||
}
|
||||
|
||||
if ((tapfd = qemudNetworkIfaceConnect(conn, driver, net, qemuCmdFlags)) < 0)
|
||||
if ((tapfd = qemuNetworkIfaceConnect(conn, driver, net, qemuCmdFlags)) < 0)
|
||||
return -1;
|
||||
} else if (net->type == VIR_DOMAIN_NET_TYPE_DIRECT) {
|
||||
if (priv->monConfig->type != VIR_DOMAIN_CHR_TYPE_UNIX) {
|
||||
|
@ -8379,10 +8380,10 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn,
|
|||
return -1;
|
||||
}
|
||||
|
||||
if ((tapfd = qemudPhysIfaceConnect(conn, driver, net,
|
||||
qemuCmdFlags,
|
||||
vm->def->uuid,
|
||||
VIR_VM_OP_CREATE)) < 0)
|
||||
if ((tapfd = qemuPhysIfaceConnect(conn, driver, net,
|
||||
qemuCmdFlags,
|
||||
vm->def->uuid,
|
||||
VIR_VM_OP_CREATE)) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -8593,7 +8594,7 @@ static int qemudDomainAttachHostPciDevice(struct qemud_driver *driver,
|
|||
if (qemuDomainPCIAddressEnsureAddr(priv->pciaddrs, &hostdev->info) < 0)
|
||||
goto error;
|
||||
if (qemuCmdFlags & QEMUD_CMD_FLAG_PCI_CONFIGFD) {
|
||||
configfd = qemudOpenPCIConfig(hostdev);
|
||||
configfd = qemuOpenPCIConfig(hostdev);
|
||||
if (configfd >= 0) {
|
||||
if (virAsprintf(&configfd_name, "fd-%s",
|
||||
hostdev->info.alias) < 0) {
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#include <sys/time.h>
|
||||
|
||||
#include "qemu_monitor_json.h"
|
||||
#include "qemu_conf.h"
|
||||
#include "qemu_command.h"
|
||||
#include "memory.h"
|
||||
#include "logging.h"
|
||||
#include "driver.h"
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "qemu_monitor_text.h"
|
||||
#include "qemu_conf.h"
|
||||
#include "qemu_command.h"
|
||||
#include "c-ctype.h"
|
||||
#include "memory.h"
|
||||
#include "logging.h"
|
||||
|
|
Loading…
Reference in New Issue