qemu_command.h 13.0 KB
Newer Older
1 2 3
/*
 * qemu_command.h: QEMU command generation
 *
4
 * Copyright (C) 2006-2015 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
 *
 * Author: Daniel P. Berrange <berrange@redhat.com>
 */

#ifndef __QEMU_COMMAND_H__
# define __QEMU_COMMAND_H__

27
# include "domain_addr.h"
28
# include "domain_conf.h"
29
# include "vircommand.h"
30 31
# include "capabilities.h"
# include "qemu_conf.h"
32
# include "qemu_domain.h"
33
# include "qemu_capabilities.h"
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_FSDEV_HOST_PREFIX "fsdev-"

41
/* These are only defaults, they can be changed now in qemu.conf and
N
Nehal J Wani 已提交
42
 * explicitly specified port is checked against these two (makes
43 44 45 46 47
 * 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
# define QEMU_QXL_VGAMEM_DEFAULT 16 * 1024

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

extern qemuBuildCommandLineCallbacks buildCommandLineCallbacks;
70

71 72 73 74
char *qemuBuildObjectCommandlineFromJSON(const char *type,
                                         const char *alias,
                                         virJSONValuePtr props);

75
virCommandPtr qemuBuildCommandLine(virConnectPtr conn,
76
                                   virQEMUDriverPtr driver,
77
                                   virDomainDefPtr def,
78
                                   virDomainChrSourceDefPtr monitor_chr,
79
                                   bool monitor_json,
80
                                   virQEMUCapsPtr qemuCaps,
81
                                   const char *migrateFrom,
82
                                   int migrateFd,
83
                                   virDomainSnapshotObjPtr current_snapshot,
84
                                   virNetDevVPortProfileOp vmop,
C
Cole Robinson 已提交
85
                                   qemuBuildCommandLineCallbacksPtr callbacks,
86
                                   bool forXMLToArgv,
87
                                   bool enableFips,
88 89 90
                                   virBitmapPtr nodeset,
                                   size_t *nnicindexes,
                                   int **nicindexes)
91
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(11);
92

93 94 95 96 97 98
/* Generate '-device' string for chardev device */
int
qemuBuildChrDeviceStr(char **deviceStr,
                      virDomainDefPtr vmdef,
                      virDomainChrDefPtr chr,
                      virQEMUCapsPtr qemuCaps);
99

100
/* With vlan == -1, use netdev syntax, else old hostnet */
101 102 103 104 105
char *qemuBuildHostNetStr(virDomainNetDefPtr net,
                          virQEMUDriverPtr driver,
                          char type_sep,
                          int vlan,
                          char **tapfd,
106
                          size_t tapfdSize,
107
                          char **vhostfd,
108
                          size_t vhostfdSize);
109 110

/* Legacy, pre device support */
111 112 113
char *qemuBuildNicStr(virDomainNetDefPtr net,
                      const char *prefix,
                      int vlan);
114 115

/* Current, best practice */
116 117 118 119
char *qemuBuildNicDevStr(virDomainDefPtr def,
                         virDomainNetDefPtr net,
                         int vlan,
                         int bootindex,
120
                         size_t vhostfdSize,
121
                         virQEMUCapsPtr qemuCaps);
122 123

char *qemuDeviceDriveHostAlias(virDomainDiskDefPtr disk,
124
                               virQEMUCapsPtr qemuCaps);
125 126

/* Both legacy & current support */
127 128
char *qemuBuildDriveStr(virConnectPtr conn,
                        virDomainDiskDefPtr disk,
129
                        bool bootable,
130
                        virQEMUCapsPtr qemuCaps);
131
char *qemuBuildFSStr(virDomainFSDefPtr fs,
132
                     virQEMUCapsPtr qemuCaps);
133 134

/* Current, best practice */
135 136 137 138 139 140 141
char *qemuBuildDriveDevStr(virDomainDefPtr def,
                           virDomainDiskDefPtr disk,
                           int bootindex,
                           virQEMUCapsPtr qemuCaps);
char *qemuBuildFSDevStr(virDomainDefPtr domainDef,
                        virDomainFSDefPtr fs,
                        virQEMUCapsPtr qemuCaps);
142
/* Current, best practice */
143 144 145 146
char *qemuBuildControllerDevStr(virDomainDefPtr domainDef,
                                virDomainControllerDefPtr def,
                                virQEMUCapsPtr qemuCaps,
                                int *nusbcontroller);
147

148 149 150
char *qemuBuildWatchdogDevStr(virDomainDefPtr domainDef,
                              virDomainWatchdogDefPtr dev,
                              virQEMUCapsPtr qemuCaps);
151

152 153 154
char *qemuBuildMemballoonDevStr(virDomainDefPtr domainDef,
                                virDomainMemballoonDefPtr dev,
                                virQEMUCapsPtr qemuCaps);
155

156 157 158
char *qemuBuildUSBInputDevStr(virDomainDefPtr domainDef,
                              virDomainInputDefPtr dev,
                              virQEMUCapsPtr qemuCaps);
159

160 161 162
char *qemuBuildSoundDevStr(virDomainDefPtr domainDef,
                           virDomainSoundDefPtr sound,
                           virQEMUCapsPtr qemuCaps);
163

164 165 166 167 168 169 170 171 172 173 174 175 176
int qemuBuildMemoryBackendStr(unsigned long long size,
                              unsigned long long pagesize,
                              int guestNode,
                              virBitmapPtr userNodeset,
                              virBitmapPtr autoNodeset,
                              virDomainDefPtr def,
                              virQEMUCapsPtr qemuCaps,
                              virQEMUDriverConfigPtr cfg,
                              const char **backendType,
                              virJSONValuePtr *backendProps,
                              bool force);

char *qemuBuildMemoryDeviceStr(virDomainMemoryDefPtr mem,
177
                               virDomainDefPtr def,
178 179
                               virQEMUCapsPtr qemuCaps);

180
/* Legacy, pre device support */
181 182
char *qemuBuildPCIHostdevPCIDevStr(virDomainHostdevDefPtr dev,
                                   virQEMUCapsPtr qemuCaps);
183
/* Current, best practice */
184 185 186 187
char *qemuBuildPCIHostdevDevStr(virDomainDefPtr def,
                                virDomainHostdevDefPtr dev,
                                const char *configfd,
                                virQEMUCapsPtr qemuCaps);
188

189 190 191
char *qemuBuildRNGDevStr(virDomainDefPtr def,
                         virDomainRNGDefPtr dev,
                         virQEMUCapsPtr qemuCaps);
192 193 194 195
int qemuBuildRNGBackendProps(virDomainRNGDefPtr rng,
                             virQEMUCapsPtr qemuCaps,
                             const char **type,
                             virJSONValuePtr *props);
196

197 198 199
int qemuOpenPCIConfig(virDomainHostdevDefPtr dev);

/* Legacy, pre device support */
200
char *qemuBuildUSBHostdevUSBDevStr(virDomainHostdevDefPtr dev);
201
/* Current, best practice */
202 203 204 205 206 207 208 209 210 211
char *qemuBuildUSBHostdevDevStr(virDomainDefPtr def,
                                virDomainHostdevDefPtr dev,
                                virQEMUCapsPtr qemuCaps);

char *qemuBuildSCSIHostdevDrvStr(virConnectPtr conn,
                                 virDomainHostdevDefPtr dev,
                                 virQEMUCapsPtr qemuCaps,
                                 qemuBuildCommandLineCallbacksPtr callbacks)
    ATTRIBUTE_NONNULL(4);
char *qemuBuildSCSIHostdevDevStr(virDomainDefPtr def,
212
                                 virDomainHostdevDefPtr dev,
213
                                 virQEMUCapsPtr qemuCaps);
214

215 216 217 218 219 220
char *qemuBuildHubDevStr(virDomainDefPtr def,
                         virDomainHubDefPtr dev,
                         virQEMUCapsPtr qemuCaps);
char *qemuBuildRedirdevDevStr(virDomainDefPtr def,
                              virDomainRedirdevDefPtr dev,
                              virQEMUCapsPtr qemuCaps);
221
int qemuNetworkIfaceConnect(virDomainDefPtr def,
222
                            virQEMUDriverPtr driver,
223
                            virDomainNetDefPtr net,
224 225
                            virQEMUCapsPtr qemuCaps,
                            int *tapfd,
226
                            size_t *tapfdSize)
227
    ATTRIBUTE_NONNULL(2);
228

229
int qemuPhysIfaceConnect(virDomainDefPtr def,
230
                         virQEMUDriverPtr driver,
231
                         virDomainNetDefPtr net,
232
                         virQEMUCapsPtr qemuCaps,
233
                         virNetDevVPortProfileOp vmop);
234

235 236
int qemuOpenVhostNet(virDomainDefPtr def,
                     virDomainNetDefPtr net,
237
                     virQEMUCapsPtr qemuCaps,
238
                     int *vhostfd,
239
                     size_t *vhostfdSize);
240

241 242
int qemuNetworkPrepareDevices(virDomainDefPtr def);

243 244 245 246
/*
 * NB: def->name can be NULL upon return and the caller
 * *must* decide how to fill in a name in this case
 */
247
virDomainDefPtr qemuParseCommandLineString(virCapsPtr qemuCaps,
248
                                           virDomainXMLOptionPtr xmlopt,
249 250 251 252
                                           const char *args,
                                           char **pidfile,
                                           virDomainChrSourceDefPtr *monConfig,
                                           bool *monJSON);
253
virDomainDefPtr qemuParseCommandLinePid(virCapsPtr qemuCaps,
254
                                        virDomainXMLOptionPtr xmlopt,
255
                                        pid_t pid,
256 257 258
                                        char **pidfile,
                                        virDomainChrSourceDefPtr *monConfig,
                                        bool *monJSON);
259

260
int qemuDomainAssignAddresses(virDomainDefPtr def,
261
                              virQEMUCapsPtr qemuCaps,
262 263
                              virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
264
int qemuDomainAssignSpaprVIOAddresses(virDomainDefPtr def,
265
                                      virQEMUCapsPtr qemuCaps);
266

267 268 269 270
void qemuDomainReleaseDeviceAddress(virDomainObjPtr vm,
                                    virDomainDeviceInfoPtr info,
                                    const char *devstr);

271

272
int qemuDomainAssignPCIAddresses(virDomainDefPtr def,
273
                                 virQEMUCapsPtr qemuCaps,
274
                                 virDomainObjPtr obj);
275 276 277
virDomainPCIAddressSetPtr qemuDomainPCIAddressSetCreate(virDomainDefPtr def,
                                                        unsigned int nbuses,
                                                        bool dryRun);
278

J
Ján Tomko 已提交
279 280
int qemuAssignDevicePCISlots(virDomainDefPtr def,
                             virDomainPCIAddressSetPtr addrs);
281

282
int qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps);
283 284
int qemuDomainNetVLAN(virDomainNetDefPtr def);
int qemuAssignDeviceNetAlias(virDomainDefPtr def, virDomainNetDefPtr net, int idx);
285 286
int qemuAssignDeviceDiskAlias(virDomainDefPtr vmdef,
                              virDomainDiskDefPtr def,
287
                              virQEMUCapsPtr qemuCaps);
288
int qemuAssignDeviceHostdevAlias(virDomainDefPtr def, virDomainHostdevDefPtr hostdev, int idx);
289 290 291 292
int
qemuAssignDeviceControllerAlias(virDomainDefPtr domainDef,
                                virQEMUCapsPtr qemuCaps,
                                virDomainControllerDefPtr controller);
293
int qemuAssignDeviceRedirdevAlias(virDomainDefPtr def, virDomainRedirdevDefPtr redirdev, int idx);
294 295 296
int qemuAssignDeviceChrAlias(virDomainDefPtr def,
                             virDomainChrDefPtr chr,
                             ssize_t idx);
297
int qemuAssignDeviceRNGAlias(virDomainRNGDefPtr rng, size_t idx);
298 299 300 301 302

int
qemuParseKeywords(const char *str,
                  char ***retkeywords,
                  char ***retvalues,
303
                  int *retnkeywords,
304 305
                  int allowEmptyValue);

306 307 308
int qemuGetDriveSourceString(virStorageSourcePtr src,
                             virConnectPtr conn,
                             char **source);
309 310

int qemuCheckDiskConfig(virDomainDiskDefPtr disk);
311 312 313

bool
qemuCheckFips(void);
314
#endif /* __QEMU_COMMAND_H__*/