qemu_command.h 13.0 KB
Newer Older
1 2 3
/*
 * qemu_command.h: QEMU command generation
 *
4
 * Copyright (C) 2006-2013 Red Hat, Inc.
5 6 7 8 9 10 11 12 13 14 15 16 17
 * 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
18
 * License along with this library.  If not, see
O
Osier Yang 已提交
19
 * <http://www.gnu.org/licenses/>.
20 21 22 23 24 25 26 27
 *
 * Author: Daniel P. Berrange <berrange@redhat.com>
 */

#ifndef __QEMU_COMMAND_H__
# define __QEMU_COMMAND_H__

# include "domain_conf.h"
28
# include "vircommand.h"
29 30
# include "capabilities.h"
# include "qemu_conf.h"
31
# include "qemu_domain.h"
32
# include "qemu_capabilities.h"
33 34 35 36 37 38 39 40

/* 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-"

41 42 43 44 45 46 47
/* These are only defaults, they can be changed now in qemu.conf and
 * explicitely specified port is checked against these two (makes
 * sense to limit the values).
 *
 * This limitation is mentioned in qemu.conf, so bear in mind that the
 * configuration file should reflect any changes made to these values.
 */
48 49
# define QEMU_REMOTE_PORT_MIN  5900
# define QEMU_REMOTE_PORT_MAX  65535
50

51 52 53
# define QEMU_WEBSOCKET_PORT_MIN  5700
# define QEMU_WEBSOCKET_PORT_MAX  65535

54 55 56
# define QEMU_MIGRATION_PORT_MIN 49152
# define QEMU_MIGRATION_PORT_MAX 49215

57 58 59 60 61 62 63 64 65 66
typedef struct _qemuBuildCommandLineCallbacks qemuBuildCommandLineCallbacks;
typedef qemuBuildCommandLineCallbacks *qemuBuildCommandLineCallbacksPtr;
struct _qemuBuildCommandLineCallbacks {
    char * (*qemuGetSCSIDeviceSgName) (const char *adapter,
                                       unsigned int bus,
                                       unsigned int target,
                                       unsigned int unit);
};

extern qemuBuildCommandLineCallbacks buildCommandLineCallbacks;
67

68
virCommandPtr qemuBuildCommandLine(virConnectPtr conn,
69
                                   virQEMUDriverPtr driver,
70
                                   virDomainDefPtr def,
71
                                   virDomainChrSourceDefPtr monitor_chr,
72
                                   bool monitor_json,
73
                                   virQEMUCapsPtr qemuCaps,
74
                                   const char *migrateFrom,
75
                                   int migrateFd,
76
                                   virDomainSnapshotObjPtr current_snapshot,
77 78 79
                                   enum virNetDevVPortProfileOp vmop,
                                   qemuBuildCommandLineCallbacksPtr callbacks)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(11);
80

81 82 83 84 85 86
/* Generate '-device' string for chardev device */
int
qemuBuildChrDeviceStr(char **deviceStr,
                      virDomainDefPtr vmdef,
                      virDomainChrDefPtr chr,
                      virQEMUCapsPtr qemuCaps);
87

88 89
/* With vlan == -1, use netdev syntax, else old hostnet */
char * qemuBuildHostNetStr(virDomainNetDefPtr net,
90
                           virQEMUDriverPtr driver,
91 92
                           char type_sep,
                           int vlan,
93 94 95 96
                           char **tapfd,
                           int tapfdSize,
                           char **vhostfd,
                           int vhostfdSize);
97 98 99 100 101 102 103

/* Legacy, pre device support */
char * qemuBuildNicStr(virDomainNetDefPtr net,
                       const char *prefix,
                       int vlan);

/* Current, best practice */
104 105
char * qemuBuildNicDevStr(virDomainDefPtr def,
                          virDomainNetDefPtr net,
106
                          int vlan,
107
                          int bootindex,
108
                          bool multiqueue,
109
                          virQEMUCapsPtr qemuCaps);
110 111

char *qemuDeviceDriveHostAlias(virDomainDiskDefPtr disk,
112
                               virQEMUCapsPtr qemuCaps);
113 114

/* Both legacy & current support */
115 116
char *qemuBuildDriveStr(virConnectPtr conn,
                        virDomainDiskDefPtr disk,
117
                        bool bootable,
118
                        virQEMUCapsPtr qemuCaps);
119
char *qemuBuildFSStr(virDomainFSDefPtr fs,
120
                     virQEMUCapsPtr qemuCaps);
121 122

/* Current, best practice */
123 124
char * qemuBuildDriveDevStr(virDomainDefPtr def,
                            virDomainDiskDefPtr disk,
125
                            int bootindex,
126
                            virQEMUCapsPtr qemuCaps);
127 128
char * qemuBuildFSDevStr(virDomainDefPtr domainDef,
                         virDomainFSDefPtr fs,
129
                         virQEMUCapsPtr qemuCaps);
130
/* Current, best practice */
131 132
char * qemuBuildControllerDevStr(virDomainDefPtr domainDef,
                                 virDomainControllerDefPtr def,
133
                                 virQEMUCapsPtr qemuCaps,
134
                                 int *nusbcontroller);
135

136 137
char * qemuBuildWatchdogDevStr(virDomainDefPtr domainDef,
                               virDomainWatchdogDefPtr dev,
138
                               virQEMUCapsPtr qemuCaps);
139

140 141
char * qemuBuildMemballoonDevStr(virDomainDefPtr domainDef,
                                 virDomainMemballoonDefPtr dev,
142
                                 virQEMUCapsPtr qemuCaps);
143

144 145
char * qemuBuildUSBInputDevStr(virDomainDefPtr domainDef,
                               virDomainInputDefPtr dev,
146
                               virQEMUCapsPtr qemuCaps);
147

148 149
char * qemuBuildSoundDevStr(virDomainDefPtr domainDef,
                            virDomainSoundDefPtr sound,
150
                            virQEMUCapsPtr qemuCaps);
151 152 153 154

/* Legacy, pre device support */
char * qemuBuildPCIHostdevPCIDevStr(virDomainHostdevDefPtr dev);
/* Current, best practice */
155 156
char * qemuBuildPCIHostdevDevStr(virDomainDefPtr def,
                                 virDomainHostdevDefPtr dev,
157
                                 const char *configfd,
158
                                 virQEMUCapsPtr qemuCaps);
159 160 161 162 163 164

int qemuOpenPCIConfig(virDomainHostdevDefPtr dev);

/* Legacy, pre device support */
char * qemuBuildUSBHostdevUsbDevStr(virDomainHostdevDefPtr dev);
/* Current, best practice */
165 166
char * qemuBuildUSBHostdevDevStr(virDomainDefPtr def,
                                 virDomainHostdevDefPtr dev,
167
                                 virQEMUCapsPtr qemuCaps);
168

169
char * qemuBuildSCSIHostdevDrvStr(virDomainHostdevDefPtr dev,
170 171 172
                                  virQEMUCapsPtr qemuCaps,
                                  qemuBuildCommandLineCallbacksPtr callbacks)
    ATTRIBUTE_NONNULL(3);
173 174 175 176
char * qemuBuildSCSIHostdevDevStr(virDomainDefPtr def,
                                  virDomainHostdevDefPtr dev,
                                  virQEMUCapsPtr qemuCaps);

177 178 179
char * qemuBuildHubDevStr(virDomainDefPtr def,
                          virDomainHubDefPtr dev,
                          virQEMUCapsPtr qemuCaps);
180 181
char * qemuBuildRedirdevDevStr(virDomainDefPtr def,
                               virDomainRedirdevDefPtr dev,
182
                               virQEMUCapsPtr qemuCaps);
183

184 185
int qemuNetworkIfaceConnect(virDomainDefPtr def,
                            virConnectPtr conn,
186
                            virQEMUDriverPtr driver,
187
                            virDomainNetDefPtr net,
188 189 190
                            virQEMUCapsPtr qemuCaps,
                            int *tapfd,
                            int *tapfdSize)
191
    ATTRIBUTE_NONNULL(2);
192

193
int qemuPhysIfaceConnect(virDomainDefPtr def,
194
                         virQEMUDriverPtr driver,
195
                         virDomainNetDefPtr net,
196
                         virQEMUCapsPtr qemuCaps,
197
                         enum virNetDevVPortProfileOp vmop);
198

199 200
int qemuOpenVhostNet(virDomainDefPtr def,
                     virDomainNetDefPtr net,
201
                     virQEMUCapsPtr qemuCaps,
202 203
                     int *vhostfd,
                     int *vhostfdSize);
204

205 206
int qemuNetworkPrepareDevices(virDomainDefPtr def);

207 208 209 210
/*
 * NB: def->name can be NULL upon return and the caller
 * *must* decide how to fill in a name in this case
 */
211
virDomainDefPtr qemuParseCommandLineString(virCapsPtr qemuCaps,
212
                                           virDomainXMLOptionPtr xmlopt,
213 214 215 216
                                           const char *args,
                                           char **pidfile,
                                           virDomainChrSourceDefPtr *monConfig,
                                           bool *monJSON);
217
virDomainDefPtr qemuParseCommandLinePid(virCapsPtr qemuCaps,
218
                                        virDomainXMLOptionPtr xmlopt,
219
                                        pid_t pid,
220 221 222
                                        char **pidfile,
                                        virDomainChrSourceDefPtr *monConfig,
                                        bool *monJSON);
223

224
int qemuDomainAssignAddresses(virDomainDefPtr def,
225
                              virQEMUCapsPtr qemuCaps,
226 227
                              virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
228
int qemuDomainAssignSpaprVIOAddresses(virDomainDefPtr def,
229
                                      virQEMUCapsPtr qemuCaps);
230

231 232 233 234
void qemuDomainReleaseDeviceAddress(virDomainObjPtr vm,
                                    virDomainDeviceInfoPtr info,
                                    const char *devstr);

235 236 237 238 239 240 241 242
typedef enum {
   QEMU_PCI_CONNECT_HOTPLUGGABLE = 1 << 0,
   /* This bus supports hot-plug */
   QEMU_PCI_CONNECT_SINGLESLOT   = 1 << 1,
   /* This "bus" has only a single downstream slot/port */

   QEMU_PCI_CONNECT_TYPE_PCI     = 1 << 2,
   /* PCI devices can connect to this bus */
L
Laine Stump 已提交
243 244
   QEMU_PCI_CONNECT_TYPE_PCIE    = 1 << 3,
   /* PCI Express devices can connect to this bus */
245 246 247 248
   QEMU_PCI_CONNECT_TYPE_EITHER_IF_CONFIG = 1 << 4,
   /* PCI *and* PCIe devices allowed, if the address
    * was specified in the config by the user
    */
249 250 251 252 253 254
} qemuDomainPCIConnectFlags;

/* a combination of all bit that describe the type of connections
 * allowed, e.g. PCI, PCIe, switch
 */
# define QEMU_PCI_CONNECT_TYPES_MASK \
L
Laine Stump 已提交
255
   (QEMU_PCI_CONNECT_TYPE_PCI | QEMU_PCI_CONNECT_TYPE_PCIE)
256 257


258
int qemuDomainAssignPCIAddresses(virDomainDefPtr def,
259
                                 virQEMUCapsPtr qemuCaps,
260
                                 virDomainObjPtr obj);
261
qemuDomainPCIAddressSetPtr qemuDomainPCIAddressSetCreate(virDomainDefPtr def,
262 263
                                                         unsigned int nbuses,
                                                         bool dryRun);
264
int qemuDomainPCIAddressReserveSlot(qemuDomainPCIAddressSetPtr addrs,
265 266
                                    virDevicePCIAddressPtr addr,
                                    qemuDomainPCIConnectFlags flags);
267
int qemuDomainPCIAddressReserveAddr(qemuDomainPCIAddressSetPtr addrs,
268
                                    virDevicePCIAddressPtr addr,
269 270 271
                                    qemuDomainPCIConnectFlags flags,
                                    bool reserveEntireSlot,
                                    bool fromConfig);
272 273 274
int qemuDomainPCIAddressReserveNextSlot(qemuDomainPCIAddressSetPtr addrs,
                                        virDomainDeviceInfoPtr dev,
                                        qemuDomainPCIConnectFlags flags);
275 276 277
int qemuDomainPCIAddressEnsureAddr(qemuDomainPCIAddressSetPtr addrs,
                                   virDomainDeviceInfoPtr dev);
int qemuDomainPCIAddressReleaseAddr(qemuDomainPCIAddressSetPtr addrs,
278
                                    virDevicePCIAddressPtr addr);
279 280

void qemuDomainPCIAddressSetFree(qemuDomainPCIAddressSetPtr addrs);
281
int  qemuAssignDevicePCISlots(virDomainDefPtr def,
282
                              virQEMUCapsPtr qemuCaps,
283
                              qemuDomainPCIAddressSetPtr addrs);
284

285 286 287 288
int qemuDomainCCWAddressAssign(virDomainDeviceInfoPtr dev, qemuDomainCCWAddressSetPtr addrs,
                               bool autoassign);
void qemuDomainCCWAddressSetFree(qemuDomainCCWAddressSetPtr addrs);

289
int qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps);
290 291
int qemuDomainNetVLAN(virDomainNetDefPtr def);
int qemuAssignDeviceNetAlias(virDomainDefPtr def, virDomainNetDefPtr net, int idx);
292 293
int qemuAssignDeviceDiskAlias(virDomainDefPtr vmdef,
                              virDomainDiskDefPtr def,
294
                              virQEMUCapsPtr qemuCaps);
295
int qemuAssignDeviceHostdevAlias(virDomainDefPtr def, virDomainHostdevDefPtr hostdev, int idx);
296
int qemuAssignDeviceControllerAlias(virDomainControllerDefPtr controller);
297
int qemuAssignDeviceRedirdevAlias(virDomainDefPtr def, virDomainRedirdevDefPtr redirdev, int idx);
298 299 300
int qemuAssignDeviceChrAlias(virDomainDefPtr def,
                             virDomainChrDefPtr chr,
                             ssize_t idx);
301 302 303 304 305

int
qemuParseKeywords(const char *str,
                  char ***retkeywords,
                  char ***retvalues,
306
                  int *retnkeywords,
307 308 309
                  int allowEmptyValue);

#endif /* __QEMU_COMMAND_H__*/