qemu_command.h 11.5 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 60
typedef struct _qemuBuildCommandLineCallbacks qemuBuildCommandLineCallbacks;
typedef qemuBuildCommandLineCallbacks *qemuBuildCommandLineCallbacksPtr;
struct _qemuBuildCommandLineCallbacks {
61 62
    char * (*qemuGetSCSIDeviceSgName) (const char *sysfs_prefix,
                                       const char *adapter,
63 64 65 66 67 68
                                       unsigned int bus,
                                       unsigned int target,
                                       unsigned int unit);
};

extern qemuBuildCommandLineCallbacks buildCommandLineCallbacks;
69

70
virCommandPtr qemuBuildCommandLine(virConnectPtr conn,
71
                                   virQEMUDriverPtr driver,
72
                                   virDomainDefPtr def,
73
                                   virDomainChrSourceDefPtr monitor_chr,
74
                                   bool monitor_json,
75
                                   virQEMUCapsPtr qemuCaps,
76
                                   const char *migrateFrom,
77
                                   int migrateFd,
78
                                   virDomainSnapshotObjPtr current_snapshot,
79
                                   virNetDevVPortProfileOp vmop,
C
Cole Robinson 已提交
80 81
                                   qemuBuildCommandLineCallbacksPtr callbacks,
                                   bool forXMLToArgv)
82
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(11);
83

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

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

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

/* Current, best practice */
107 108
char * qemuBuildNicDevStr(virDomainDefPtr def,
                          virDomainNetDefPtr net,
109
                          int vlan,
110
                          int bootindex,
111
                          int vhostfdSize,
112
                          virQEMUCapsPtr qemuCaps);
113 114

char *qemuDeviceDriveHostAlias(virDomainDiskDefPtr disk,
115
                               virQEMUCapsPtr qemuCaps);
116 117

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

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

139 140
char * qemuBuildWatchdogDevStr(virDomainDefPtr domainDef,
                               virDomainWatchdogDefPtr dev,
141
                               virQEMUCapsPtr qemuCaps);
142

143 144
char * qemuBuildMemballoonDevStr(virDomainDefPtr domainDef,
                                 virDomainMemballoonDefPtr dev,
145
                                 virQEMUCapsPtr qemuCaps);
146

147 148
char * qemuBuildUSBInputDevStr(virDomainDefPtr domainDef,
                               virDomainInputDefPtr dev,
149
                               virQEMUCapsPtr qemuCaps);
150

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

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

int qemuOpenPCIConfig(virDomainHostdevDefPtr dev);

/* Legacy, pre device support */
167
char * qemuBuildUSBHostdevUSBDevStr(virDomainHostdevDefPtr dev);
168
/* Current, best practice */
169 170
char * qemuBuildUSBHostdevDevStr(virDomainDefPtr def,
                                 virDomainHostdevDefPtr dev,
171
                                 virQEMUCapsPtr qemuCaps);
172

173
char * qemuBuildSCSIHostdevDrvStr(virDomainHostdevDefPtr dev,
174 175 176
                                  virQEMUCapsPtr qemuCaps,
                                  qemuBuildCommandLineCallbacksPtr callbacks)
    ATTRIBUTE_NONNULL(3);
177 178 179 180
char * qemuBuildSCSIHostdevDevStr(virDomainDefPtr def,
                                  virDomainHostdevDefPtr dev,
                                  virQEMUCapsPtr qemuCaps);

181 182 183
char * qemuBuildHubDevStr(virDomainDefPtr def,
                          virDomainHubDefPtr dev,
                          virQEMUCapsPtr qemuCaps);
184 185
char * qemuBuildRedirdevDevStr(virDomainDefPtr def,
                               virDomainRedirdevDefPtr dev,
186
                               virQEMUCapsPtr qemuCaps);
187 188
int qemuNetworkIfaceConnect(virDomainDefPtr def,
                            virConnectPtr conn,
189
                            virQEMUDriverPtr driver,
190
                            virDomainNetDefPtr net,
191 192 193
                            virQEMUCapsPtr qemuCaps,
                            int *tapfd,
                            int *tapfdSize)
194
    ATTRIBUTE_NONNULL(2);
195

196
int qemuPhysIfaceConnect(virDomainDefPtr def,
197
                         virQEMUDriverPtr driver,
198
                         virDomainNetDefPtr net,
199
                         virQEMUCapsPtr qemuCaps,
200
                         virNetDevVPortProfileOp vmop);
201

202 203
int qemuOpenVhostNet(virDomainDefPtr def,
                     virDomainNetDefPtr net,
204
                     virQEMUCapsPtr qemuCaps,
205 206
                     int *vhostfd,
                     int *vhostfdSize);
207

208 209
int qemuNetworkPrepareDevices(virDomainDefPtr def);

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

227
int qemuDomainAssignAddresses(virDomainDefPtr def,
228
                              virQEMUCapsPtr qemuCaps,
229 230
                              virDomainObjPtr obj)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
231
int qemuDomainAssignSpaprVIOAddresses(virDomainDefPtr def,
232
                                      virQEMUCapsPtr qemuCaps);
233

234 235 236 237
void qemuDomainReleaseDeviceAddress(virDomainObjPtr vm,
                                    virDomainDeviceInfoPtr info,
                                    const char *devstr);

238

239
int qemuDomainAssignPCIAddresses(virDomainDefPtr def,
240
                                 virQEMUCapsPtr qemuCaps,
241
                                 virDomainObjPtr obj);
242 243 244
virDomainPCIAddressSetPtr qemuDomainPCIAddressSetCreate(virDomainDefPtr def,
                                                        unsigned int nbuses,
                                                        bool dryRun);
245

246
int  qemuAssignDevicePCISlots(virDomainDefPtr def,
247
                              virQEMUCapsPtr qemuCaps,
248
                              virDomainPCIAddressSetPtr addrs);
249

250 251 252 253
int qemuDomainCCWAddressAssign(virDomainDeviceInfoPtr dev, qemuDomainCCWAddressSetPtr addrs,
                               bool autoassign);
void qemuDomainCCWAddressSetFree(qemuDomainCCWAddressSetPtr addrs);

254
int qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps);
255 256
int qemuDomainNetVLAN(virDomainNetDefPtr def);
int qemuAssignDeviceNetAlias(virDomainDefPtr def, virDomainNetDefPtr net, int idx);
257 258
int qemuAssignDeviceDiskAlias(virDomainDefPtr vmdef,
                              virDomainDiskDefPtr def,
259
                              virQEMUCapsPtr qemuCaps);
260
int qemuAssignDeviceHostdevAlias(virDomainDefPtr def, virDomainHostdevDefPtr hostdev, int idx);
261
int qemuAssignDeviceControllerAlias(virDomainControllerDefPtr controller);
262
int qemuAssignDeviceRedirdevAlias(virDomainDefPtr def, virDomainRedirdevDefPtr redirdev, int idx);
263 264 265
int qemuAssignDeviceChrAlias(virDomainDefPtr def,
                             virDomainChrDefPtr chr,
                             ssize_t idx);
266 267 268 269 270

int
qemuParseKeywords(const char *str,
                  char ***retkeywords,
                  char ***retvalues,
271
                  int *retnkeywords,
272 273
                  int allowEmptyValue);

274 275 276
int qemuGetDriveSourceString(virStorageSourcePtr src,
                             virConnectPtr conn,
                             char **source);
277
#endif /* __QEMU_COMMAND_H__*/