qemu_command.h 12.6 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 57 58 59 60 61 62 63
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;
64

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

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

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

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

/* Current, best practice */
char * qemuBuildNicDevStr(virDomainNetDefPtr net,
102
                          int vlan,
103
                          int bootindex,
104
                          virQEMUCapsPtr qemuCaps);
105 106

char *qemuDeviceDriveHostAlias(virDomainDiskDefPtr disk,
107
                               virQEMUCapsPtr qemuCaps);
108 109

/* Both legacy & current support */
110 111
char *qemuBuildDriveStr(virConnectPtr conn,
                        virDomainDiskDefPtr disk,
112
                        bool bootable,
113
                        virQEMUCapsPtr qemuCaps);
114
char *qemuBuildFSStr(virDomainFSDefPtr fs,
115
                     virQEMUCapsPtr qemuCaps);
116 117

/* Current, best practice */
118 119
char * qemuBuildDriveDevStr(virDomainDefPtr def,
                            virDomainDiskDefPtr disk,
120
                            int bootindex,
121
                            virQEMUCapsPtr qemuCaps);
122
char * qemuBuildFSDevStr(virDomainFSDefPtr fs,
123
                         virQEMUCapsPtr qemuCaps);
124
/* Current, best practice */
125 126
char * qemuBuildControllerDevStr(virDomainDefPtr domainDef,
                                 virDomainControllerDefPtr def,
127
                                 virQEMUCapsPtr qemuCaps,
128
                                 int *nusbcontroller);
129

130
char * qemuBuildWatchdogDevStr(virDomainWatchdogDefPtr dev,
131
                               virQEMUCapsPtr qemuCaps);
132

133
char * qemuBuildMemballoonDevStr(virDomainMemballoonDefPtr dev,
134
                                 virQEMUCapsPtr qemuCaps);
135

136
char * qemuBuildUSBInputDevStr(virDomainInputDefPtr dev,
137
                               virQEMUCapsPtr qemuCaps);
138

139
char * qemuBuildSoundDevStr(virDomainSoundDefPtr sound,
140
                            virQEMUCapsPtr qemuCaps);
141 142 143 144 145

/* Legacy, pre device support */
char * qemuBuildPCIHostdevPCIDevStr(virDomainHostdevDefPtr dev);
/* Current, best practice */
char * qemuBuildPCIHostdevDevStr(virDomainHostdevDefPtr dev,
146
                                 const char *configfd,
147
                                 virQEMUCapsPtr qemuCaps);
148 149 150 151 152 153

int qemuOpenPCIConfig(virDomainHostdevDefPtr dev);

/* Legacy, pre device support */
char * qemuBuildUSBHostdevUsbDevStr(virDomainHostdevDefPtr dev);
/* Current, best practice */
154
char * qemuBuildUSBHostdevDevStr(virDomainHostdevDefPtr dev,
155
                                 virQEMUCapsPtr qemuCaps);
156

157
char * qemuBuildSCSIHostdevDrvStr(virDomainHostdevDefPtr dev,
158 159 160
                                  virQEMUCapsPtr qemuCaps,
                                  qemuBuildCommandLineCallbacksPtr callbacks)
    ATTRIBUTE_NONNULL(3);
161 162 163 164
char * qemuBuildSCSIHostdevDevStr(virDomainDefPtr def,
                                  virDomainHostdevDefPtr dev,
                                  virQEMUCapsPtr qemuCaps);

165
char * qemuBuildHubDevStr(virDomainHubDefPtr dev, virQEMUCapsPtr qemuCaps);
166 167
char * qemuBuildRedirdevDevStr(virDomainDefPtr def,
                               virDomainRedirdevDefPtr dev,
168
                               virQEMUCapsPtr qemuCaps);
169

170 171
int qemuNetworkIfaceConnect(virDomainDefPtr def,
                            virConnectPtr conn,
172
                            virQEMUDriverPtr driver,
173
                            virDomainNetDefPtr net,
174 175 176
                            virQEMUCapsPtr qemuCaps,
                            int *tapfd,
                            int *tapfdSize)
177
    ATTRIBUTE_NONNULL(2);
178

179
int qemuPhysIfaceConnect(virDomainDefPtr def,
180
                         virQEMUDriverPtr driver,
181
                         virDomainNetDefPtr net,
182
                         virQEMUCapsPtr qemuCaps,
183
                         enum virNetDevVPortProfileOp vmop);
184

185 186
int qemuOpenVhostNet(virDomainDefPtr def,
                     virDomainNetDefPtr net,
187
                     virQEMUCapsPtr qemuCaps,
188 189
                     int *vhostfd,
                     int *vhostfdSize);
190

191 192
int qemuNetworkPrepareDevices(virDomainDefPtr def);

193 194 195 196
/*
 * NB: def->name can be NULL upon return and the caller
 * *must* decide how to fill in a name in this case
 */
197
virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
198
                                     virDomainXMLOptionPtr xmlopt,
199
                                     const char **progenv,
200 201 202 203
                                     const char **progargv,
                                     char **pidfile,
                                     virDomainChrSourceDefPtr *monConfig,
                                     bool *monJSON);
204
virDomainDefPtr qemuParseCommandLineString(virCapsPtr qemuCaps,
205
                                           virDomainXMLOptionPtr xmlopt,
206 207 208 209
                                           const char *args,
                                           char **pidfile,
                                           virDomainChrSourceDefPtr *monConfig,
                                           bool *monJSON);
210
virDomainDefPtr qemuParseCommandLinePid(virCapsPtr qemuCaps,
211
                                        virDomainXMLOptionPtr xmlopt,
212
                                        pid_t pid,
213 214 215
                                        char **pidfile,
                                        virDomainChrSourceDefPtr *monConfig,
                                        bool *monJSON);
216

217
int qemuDomainAssignAddresses(virDomainDefPtr def,
218
                              virQEMUCapsPtr qemuCaps,
219 220
                              virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
221
int qemuDomainAssignSpaprVIOAddresses(virDomainDefPtr def,
222
                                      virQEMUCapsPtr qemuCaps);
223

224 225 226 227
void qemuDomainReleaseDeviceAddress(virDomainObjPtr vm,
                                    virDomainDeviceInfoPtr info,
                                    const char *devstr);

228 229 230 231 232 233 234 235
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 已提交
236 237
   QEMU_PCI_CONNECT_TYPE_PCIE    = 1 << 3,
   /* PCI Express devices can connect to this bus */
238 239 240 241 242 243
} 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 已提交
244
   (QEMU_PCI_CONNECT_TYPE_PCI | QEMU_PCI_CONNECT_TYPE_PCIE)
245 246


247
int qemuDomainAssignPCIAddresses(virDomainDefPtr def,
248
                                 virQEMUCapsPtr qemuCaps,
249
                                 virDomainObjPtr obj);
250
qemuDomainPCIAddressSetPtr qemuDomainPCIAddressSetCreate(virDomainDefPtr def,
251 252
                                                         unsigned int nbuses,
                                                         bool dryRun);
253
int qemuDomainPCIAddressReserveSlot(qemuDomainPCIAddressSetPtr addrs,
254 255
                                    virDevicePCIAddressPtr addr,
                                    qemuDomainPCIConnectFlags flags);
256
int qemuDomainPCIAddressReserveAddr(qemuDomainPCIAddressSetPtr addrs,
257
                                    virDevicePCIAddressPtr addr,
258 259 260
                                    qemuDomainPCIConnectFlags flags,
                                    bool reserveEntireSlot,
                                    bool fromConfig);
261 262 263
int qemuDomainPCIAddressReserveNextSlot(qemuDomainPCIAddressSetPtr addrs,
                                        virDomainDeviceInfoPtr dev,
                                        qemuDomainPCIConnectFlags flags);
264 265 266
int qemuDomainPCIAddressEnsureAddr(qemuDomainPCIAddressSetPtr addrs,
                                   virDomainDeviceInfoPtr dev);
int qemuDomainPCIAddressReleaseAddr(qemuDomainPCIAddressSetPtr addrs,
267
                                    virDevicePCIAddressPtr addr);
268 269

void qemuDomainPCIAddressSetFree(qemuDomainPCIAddressSetPtr addrs);
270
int  qemuAssignDevicePCISlots(virDomainDefPtr def,
271
                              virQEMUCapsPtr qemuCaps,
272
                              qemuDomainPCIAddressSetPtr addrs);
273

274 275 276 277
int qemuDomainCCWAddressAssign(virDomainDeviceInfoPtr dev, qemuDomainCCWAddressSetPtr addrs,
                               bool autoassign);
void qemuDomainCCWAddressSetFree(qemuDomainCCWAddressSetPtr addrs);

278
int qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps);
279 280
int qemuDomainNetVLAN(virDomainNetDefPtr def);
int qemuAssignDeviceNetAlias(virDomainDefPtr def, virDomainNetDefPtr net, int idx);
281 282
int qemuAssignDeviceDiskAlias(virDomainDefPtr vmdef,
                              virDomainDiskDefPtr def,
283
                              virQEMUCapsPtr qemuCaps);
284
int qemuAssignDeviceHostdevAlias(virDomainDefPtr def, virDomainHostdevDefPtr hostdev, int idx);
285
int qemuAssignDeviceControllerAlias(virDomainControllerDefPtr controller);
286
int qemuAssignDeviceRedirdevAlias(virDomainDefPtr def, virDomainRedirdevDefPtr redirdev, int idx);
287 288 289
int qemuAssignDeviceChrAlias(virDomainDefPtr def,
                             virDomainChrDefPtr chr,
                             ssize_t idx);
290 291 292 293 294 295 296 297

int
qemuParseKeywords(const char *str,
                  char ***retkeywords,
                  char ***retvalues,
                  int allowEmptyValue);

#endif /* __QEMU_COMMAND_H__*/