qemu_command.h 12.2 KB
Newer Older
1 2 3
/*
 * qemu_command.h: QEMU command generation
 *
4
 * Copyright (C) 2006-2014 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 41

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

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

52 53 54
# define QEMU_WEBSOCKET_PORT_MIN  5700
# define QEMU_WEBSOCKET_PORT_MAX  65535

55 56 57
# define QEMU_MIGRATION_PORT_MIN 49152
# define QEMU_MIGRATION_PORT_MAX 49215

58 59
# define QEMU_QXL_VGAMEM_DEFAULT 16 * 1024

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

extern qemuBuildCommandLineCallbacks buildCommandLineCallbacks;
71

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

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

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

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

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

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

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

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

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

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

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

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

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

/* Legacy, pre device support */
166 167
char *qemuBuildPCIHostdevPCIDevStr(virDomainHostdevDefPtr dev,
                                   virQEMUCapsPtr qemuCaps);
168
/* Current, best practice */
169 170 171 172
char *qemuBuildPCIHostdevDevStr(virDomainDefPtr def,
                                virDomainHostdevDefPtr dev,
                                const char *configfd,
                                virQEMUCapsPtr qemuCaps);
173

174 175 176
char *qemuBuildRNGDevStr(virDomainDefPtr def,
                         virDomainRNGDefPtr dev,
                         virQEMUCapsPtr qemuCaps);
177 178 179 180
int qemuBuildRNGBackendProps(virDomainRNGDefPtr rng,
                             virQEMUCapsPtr qemuCaps,
                             const char **type,
                             virJSONValuePtr *props);
181

182 183 184
int qemuOpenPCIConfig(virDomainHostdevDefPtr dev);

/* Legacy, pre device support */
185
char *qemuBuildUSBHostdevUSBDevStr(virDomainHostdevDefPtr dev);
186
/* Current, best practice */
187 188 189 190 191 192 193 194 195 196
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,
197
                                 virDomainHostdevDefPtr dev,
198
                                 virQEMUCapsPtr qemuCaps);
199

200 201 202 203 204 205
char *qemuBuildHubDevStr(virDomainDefPtr def,
                         virDomainHubDefPtr dev,
                         virQEMUCapsPtr qemuCaps);
char *qemuBuildRedirdevDevStr(virDomainDefPtr def,
                              virDomainRedirdevDefPtr dev,
                              virQEMUCapsPtr qemuCaps);
206
int qemuNetworkIfaceConnect(virDomainDefPtr def,
207
                            virQEMUDriverPtr driver,
208
                            virDomainNetDefPtr net,
209 210
                            virQEMUCapsPtr qemuCaps,
                            int *tapfd,
211 212
                            size_t *tapfdSize,
                            int *nicindex)
213
    ATTRIBUTE_NONNULL(2);
214

215
int qemuPhysIfaceConnect(virDomainDefPtr def,
216
                         virQEMUDriverPtr driver,
217
                         virDomainNetDefPtr net,
218
                         virQEMUCapsPtr qemuCaps,
219
                         virNetDevVPortProfileOp vmop);
220

221 222
int qemuOpenVhostNet(virDomainDefPtr def,
                     virDomainNetDefPtr net,
223
                     virQEMUCapsPtr qemuCaps,
224
                     int *vhostfd,
225
                     size_t *vhostfdSize);
226

227 228
int qemuNetworkPrepareDevices(virDomainDefPtr def);

229 230 231 232
/*
 * NB: def->name can be NULL upon return and the caller
 * *must* decide how to fill in a name in this case
 */
233
virDomainDefPtr qemuParseCommandLineString(virCapsPtr qemuCaps,
234
                                           virDomainXMLOptionPtr xmlopt,
235 236 237 238
                                           const char *args,
                                           char **pidfile,
                                           virDomainChrSourceDefPtr *monConfig,
                                           bool *monJSON);
239
virDomainDefPtr qemuParseCommandLinePid(virCapsPtr qemuCaps,
240
                                        virDomainXMLOptionPtr xmlopt,
241
                                        pid_t pid,
242 243 244
                                        char **pidfile,
                                        virDomainChrSourceDefPtr *monConfig,
                                        bool *monJSON);
245

246
int qemuDomainAssignAddresses(virDomainDefPtr def,
247
                              virQEMUCapsPtr qemuCaps,
248 249
                              virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
250
int qemuDomainAssignSpaprVIOAddresses(virDomainDefPtr def,
251
                                      virQEMUCapsPtr qemuCaps);
252

253 254 255 256
void qemuDomainReleaseDeviceAddress(virDomainObjPtr vm,
                                    virDomainDeviceInfoPtr info,
                                    const char *devstr);

257

258
int qemuDomainAssignPCIAddresses(virDomainDefPtr def,
259
                                 virQEMUCapsPtr qemuCaps,
260
                                 virDomainObjPtr obj);
261 262 263
virDomainPCIAddressSetPtr qemuDomainPCIAddressSetCreate(virDomainDefPtr def,
                                                        unsigned int nbuses,
                                                        bool dryRun);
264

J
Ján Tomko 已提交
265 266
int qemuAssignDevicePCISlots(virDomainDefPtr def,
                             virDomainPCIAddressSetPtr addrs);
267

268
int qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps);
269 270
int qemuDomainNetVLAN(virDomainNetDefPtr def);
int qemuAssignDeviceNetAlias(virDomainDefPtr def, virDomainNetDefPtr net, int idx);
271 272
int qemuAssignDeviceDiskAlias(virDomainDefPtr vmdef,
                              virDomainDiskDefPtr def,
273
                              virQEMUCapsPtr qemuCaps);
274
int qemuAssignDeviceHostdevAlias(virDomainDefPtr def, virDomainHostdevDefPtr hostdev, int idx);
275
int qemuAssignDeviceControllerAlias(virDomainControllerDefPtr controller);
276
int qemuAssignDeviceRedirdevAlias(virDomainDefPtr def, virDomainRedirdevDefPtr redirdev, int idx);
277 278 279
int qemuAssignDeviceChrAlias(virDomainDefPtr def,
                             virDomainChrDefPtr chr,
                             ssize_t idx);
280
int qemuAssignDeviceRNGAlias(virDomainRNGDefPtr rng, size_t idx);
281 282 283 284 285

int
qemuParseKeywords(const char *str,
                  char ***retkeywords,
                  char ***retvalues,
286
                  int *retnkeywords,
287 288
                  int allowEmptyValue);

289 290 291
int qemuGetDriveSourceString(virStorageSourcePtr src,
                             virConnectPtr conn,
                             char **source);
292 293

int qemuCheckDiskConfig(virDomainDiskDefPtr disk);
294 295 296

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