qemu_monitor.h 19.6 KB
Newer Older
1 2 3
/*
 * qemu_monitor.h: interaction with QEMU monitor console
 *
4
 * Copyright (C) 2006-2011 Red Hat, Inc.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 * 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
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 *
 * Author: Daniel P. Berrange <berrange@redhat.com>
 */


#ifndef QEMU_MONITOR_H
26
# define QEMU_MONITOR_H
27

28
# include "internal.h"
29

30
# include "domain_conf.h"
31
# include "qemu_conf.h"
32
# include "hash.h"
33

34 35
typedef struct _qemuMonitor qemuMonitor;
typedef qemuMonitor *qemuMonitorPtr;
36

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
typedef struct _qemuMonitorMessage qemuMonitorMessage;
typedef qemuMonitorMessage *qemuMonitorMessagePtr;

typedef int (*qemuMonitorPasswordHandler)(qemuMonitorPtr mon,
                                          qemuMonitorMessagePtr msg,
                                          const char *data,
                                          size_t len,
                                          void *opaque);

struct _qemuMonitorMessage {
    int txFD;

    char *txBuffer;
    int txOffset;
    int txLength;

53
    /* Used by the text monitor reply / error */
54 55
    char *rxBuffer;
    int rxLength;
56 57
    /* Used by the JSON monitor to hold reply / error */
    void *rxObject;
58

59 60 61 62
    /* True if rxBuffer / rxObject are ready, or a
     * fatal error occurred on the monitor channel
     */
    bool finished;
63 64 65 66 67

    qemuMonitorPasswordHandler passwordHandler;
    void *passwordOpaque;
};

68 69 70
typedef struct _qemuMonitorCallbacks qemuMonitorCallbacks;
typedef qemuMonitorCallbacks *qemuMonitorCallbacksPtr;
struct _qemuMonitorCallbacks {
71 72 73
    void (*destroy)(qemuMonitorPtr mon,
                    virDomainObjPtr vm);

74
    void (*eofNotify)(qemuMonitorPtr mon,
75 76 77 78
                      virDomainObjPtr vm);
    void (*errorNotify)(qemuMonitorPtr mon,
                        virDomainObjPtr vm);
    /* XXX we'd really like to avoid virConnectPtr here
79 80 81 82 83 84 85 86 87 88
     * It is required so the callback can find the active
     * secret driver. Need to change this to work like the
     * security drivers do, to avoid this
     */
    int (*diskSecretLookup)(qemuMonitorPtr mon,
                            virConnectPtr conn,
                            virDomainObjPtr vm,
                            const char *path,
                            char **secret,
                            size_t *secretLen);
89 90 91 92 93 94 95 96 97

    int (*domainShutdown)(qemuMonitorPtr mon,
                          virDomainObjPtr vm);
    int (*domainReset)(qemuMonitorPtr mon,
                       virDomainObjPtr vm);
    int (*domainPowerdown)(qemuMonitorPtr mon,
                           virDomainObjPtr vm);
    int (*domainStop)(qemuMonitorPtr mon,
                      virDomainObjPtr vm);
98 99 100
    int (*domainRTCChange)(qemuMonitorPtr mon,
                           virDomainObjPtr vm,
                           long long offset);
101 102 103
    int (*domainWatchdog)(qemuMonitorPtr mon,
                          virDomainObjPtr vm,
                          int action);
104 105 106
    int (*domainIOError)(qemuMonitorPtr mon,
                         virDomainObjPtr vm,
                         const char *diskAlias,
107 108
                         int action,
                         const char *reason);
109 110 111 112 113 114 115 116 117 118 119 120
    int (*domainGraphics)(qemuMonitorPtr mon,
                          virDomainObjPtr vm,
                          int phase,
                          int localFamily,
                          const char *localNode,
                          const char *localService,
                          int remoteFamily,
                          const char *remoteNode,
                          const char *remoteService,
                          const char *authScheme,
                          const char *x509dname,
                          const char *saslUsername);
121 122 123 124 125
    int (*domainBlockJob)(qemuMonitorPtr mon,
                          virDomainObjPtr vm,
                          const char *diskAlias,
                          int type,
                          int status);
126 127
};

128

129 130
char *qemuMonitorEscapeArg(const char *in);

131
qemuMonitorPtr qemuMonitorOpen(virDomainObjPtr vm,
132
                               virDomainChrSourceDefPtr config,
D
Daniel P. Berrange 已提交
133
                               int json,
134
                               qemuMonitorCallbacksPtr cb);
135

136
void qemuMonitorClose(qemuMonitorPtr mon);
137

138 139
int qemuMonitorSetCapabilities(qemuMonitorPtr mon);

140 141
int qemuMonitorCheckHMP(qemuMonitorPtr mon, const char *cmd);

142 143 144
void qemuMonitorLock(qemuMonitorPtr mon);
void qemuMonitorUnlock(qemuMonitorPtr mon);

145
int qemuMonitorRef(qemuMonitorPtr mon);
146
int qemuMonitorUnref(qemuMonitorPtr mon) ATTRIBUTE_RETURN_CHECK;
147

148 149 150 151
int qemuMonitorSetLink(qemuMonitorPtr mon,
                       const char *name,
                       enum virDomainNetInterfaceLinkState state) ;

152
/* These APIs are for use by the internal Text/JSON monitor impl code only */
153
char *qemuMonitorNextCommandID(qemuMonitorPtr mon);
154 155
int qemuMonitorSend(qemuMonitorPtr mon,
                    qemuMonitorMessagePtr msg);
156 157 158 159 160 161
int qemuMonitorHMPCommandWithFd(qemuMonitorPtr mon,
                                const char *cmd,
                                int scm_fd,
                                char **reply);
# define qemuMonitorHMPCommand(mon, cmd, reply) \
    qemuMonitorHMPCommandWithFd(mon, cmd, -1, reply)
162

163
/* XXX same comment about virConnectPtr as above */
164 165 166 167 168
int qemuMonitorGetDiskSecret(qemuMonitorPtr mon,
                             virConnectPtr conn,
                             const char *path,
                             char **secret,
                             size_t *secretLen);
169

170 171 172 173
int qemuMonitorEmitShutdown(qemuMonitorPtr mon);
int qemuMonitorEmitReset(qemuMonitorPtr mon);
int qemuMonitorEmitPowerdown(qemuMonitorPtr mon);
int qemuMonitorEmitStop(qemuMonitorPtr mon);
174
int qemuMonitorEmitRTCChange(qemuMonitorPtr mon, long long offset);
175
int qemuMonitorEmitWatchdog(qemuMonitorPtr mon, int action);
176 177
int qemuMonitorEmitIOError(qemuMonitorPtr mon,
                           const char *diskAlias,
178 179
                           int action,
                           const char *reason);
180 181 182 183 184 185 186 187 188 189 190
int qemuMonitorEmitGraphics(qemuMonitorPtr mon,
                            int phase,
                            int localFamily,
                            const char *localNode,
                            const char *localService,
                            int remoteFamily,
                            const char *remoteNode,
                            const char *remoteService,
                            const char *authScheme,
                            const char *x509dname,
                            const char *saslUsername);
191 192 193 194 195
int qemuMonitorEmitBlockJob(qemuMonitorPtr mon,
                            const char *diskAlias,
                            int type,
                            int status);

196

197 198 199 200

int qemuMonitorStartCPUs(qemuMonitorPtr mon,
                         virConnectPtr conn);
int qemuMonitorStopCPUs(qemuMonitorPtr mon);
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224

typedef enum {
    QEMU_MONITOR_VM_STATUS_DEBUG,
    QEMU_MONITOR_VM_STATUS_INMIGRATE,
    QEMU_MONITOR_VM_STATUS_INTERNAL_ERROR,
    QEMU_MONITOR_VM_STATUS_IO_ERROR,
    QEMU_MONITOR_VM_STATUS_PAUSED,
    QEMU_MONITOR_VM_STATUS_POSTMIGRATE,
    QEMU_MONITOR_VM_STATUS_PRELAUNCH,
    QEMU_MONITOR_VM_STATUS_FINISH_MIGRATE,
    QEMU_MONITOR_VM_STATUS_RESTORE_VM,
    QEMU_MONITOR_VM_STATUS_RUNNING,
    QEMU_MONITOR_VM_STATUS_SAVE_VM,
    QEMU_MONITOR_VM_STATUS_SHUTDOWN,
    QEMU_MONITOR_VM_STATUS_WATCHDOG,

    QEMU_MONITOR_VM_STATUS_LAST
} qemuMonitorVMStatus;
VIR_ENUM_DECL(qemuMonitorVMStatus)
int qemuMonitorVMStatusToPausedReason(const char *status);

int qemuMonitorGetStatus(qemuMonitorPtr mon,
                         bool *running,
                         virDomainPausedReason *reason);
225

226
int qemuMonitorSystemReset(qemuMonitorPtr mon);
227 228 229 230
int qemuMonitorSystemPowerdown(qemuMonitorPtr mon);

int qemuMonitorGetCPUInfo(qemuMonitorPtr mon,
                          int **pids);
231 232
int qemuMonitorGetVirtType(qemuMonitorPtr mon,
                           int *virtType);
233 234
int qemuMonitorGetBalloonInfo(qemuMonitorPtr mon,
                              unsigned long *currmem);
235 236 237
int qemuMonitorGetMemoryStats(qemuMonitorPtr mon,
                              virDomainMemoryStatPtr stats,
                              unsigned int nr_stats);
238 239 240
int qemuMonitorGetBlockInfo(qemuMonitorPtr mon,
                            const char *devname,
                            struct qemuDomainDiskInfo *info);
241
int qemuMonitorGetBlockStatsInfo(qemuMonitorPtr mon,
242
                                 const char *dev_name,
243 244
                                 long long *rd_req,
                                 long long *rd_bytes,
245
                                 long long *rd_total_times,
246 247
                                 long long *wr_req,
                                 long long *wr_bytes,
248 249 250
                                 long long *wr_total_times,
                                 long long *flush_req,
                                 long long *flush_total_times,
251
                                 long long *errs);
252 253
int qemuMonitorGetBlockStatsParamsNumber(qemuMonitorPtr mon,
                                         int *nparams);
254

255
int qemuMonitorGetBlockExtent(qemuMonitorPtr mon,
256
                              const char *dev_name,
257 258
                              unsigned long long *extent);

259 260 261

int qemuMonitorSetVNCPassword(qemuMonitorPtr mon,
                              const char *password);
262 263 264 265 266 267 268
int qemuMonitorSetPassword(qemuMonitorPtr mon,
                           int type,
                           const char *password,
                           const char *action_if_connected);
int qemuMonitorExpirePassword(qemuMonitorPtr mon,
                              int type,
                              const char *expire_time);
269 270
int qemuMonitorSetBalloon(qemuMonitorPtr mon,
                          unsigned long newmem);
271 272
int qemuMonitorSetCPU(qemuMonitorPtr mon, int cpu, int online);

273 274 275 276 277 278

/* XXX should we pass the virDomainDiskDefPtr instead
 * and hide devname details inside monitor. Reconsider
 * this when doing the QMP implementation
 */
int qemuMonitorEjectMedia(qemuMonitorPtr mon,
279
                          const char *dev_name,
280
                          bool force);
281
int qemuMonitorChangeMedia(qemuMonitorPtr mon,
282
                           const char *dev_name,
283 284
                           const char *newmedia,
                           const char *format);
285 286 287 288 289 290 291 292 293 294 295 296 297 298


int qemuMonitorSaveVirtualMemory(qemuMonitorPtr mon,
                                 unsigned long long offset,
                                 size_t length,
                                 const char *path);
int qemuMonitorSavePhysicalMemory(qemuMonitorPtr mon,
                                  unsigned long long offset,
                                  size_t length,
                                  const char *path);

int qemuMonitorSetMigrationSpeed(qemuMonitorPtr mon,
                                 unsigned long bandwidth);

299 300 301
int qemuMonitorSetMigrationDowntime(qemuMonitorPtr mon,
                                    unsigned long long downtime);

302 303 304 305 306 307 308 309 310 311
enum {
    QEMU_MONITOR_MIGRATION_STATUS_INACTIVE,
    QEMU_MONITOR_MIGRATION_STATUS_ACTIVE,
    QEMU_MONITOR_MIGRATION_STATUS_COMPLETED,
    QEMU_MONITOR_MIGRATION_STATUS_ERROR,
    QEMU_MONITOR_MIGRATION_STATUS_CANCELLED,

    QEMU_MONITOR_MIGRATION_STATUS_LAST
};

312 313
VIR_ENUM_DECL(qemuMonitorMigrationStatus)

314 315 316 317 318 319
int qemuMonitorGetMigrationStatus(qemuMonitorPtr mon,
                                  int *status,
                                  unsigned long long *transferred,
                                  unsigned long long *remaining,
                                  unsigned long long *total);

320
typedef enum {
E
Eric Blake 已提交
321
  QEMU_MONITOR_MIGRATE_BACKGROUND	= 1 << 0,
322 323 324 325 326
  QEMU_MONITOR_MIGRATE_NON_SHARED_DISK  = 1 << 1, /* migration with non-shared storage with full disk copy */
  QEMU_MONITOR_MIGRATE_NON_SHARED_INC   = 1 << 2, /* migration with non-shared storage with incremental copy */
  QEMU_MONITOR_MIGRATION_FLAGS_LAST
} QEMU_MONITOR_MIGRATE;

E
Eric Blake 已提交
327 328 329 330
int qemuMonitorMigrateToFd(qemuMonitorPtr mon,
                           unsigned int flags,
                           int fd);

331
int qemuMonitorMigrateToHost(qemuMonitorPtr mon,
332
                             unsigned int flags,
333 334 335 336
                             const char *hostname,
                             int port);

int qemuMonitorMigrateToCommand(qemuMonitorPtr mon,
337
                                unsigned int flags,
338 339
                                const char * const *argv);

340 341 342 343 344 345 346
/* In general, BS is the smallest fundamental block size we can use to
 * access a block device; everything must be aligned to a multiple of
 * this.  Linux generally supports a BS as small as 512, but with
 * newer disks with 4k sectors, performance is better if we guarantee
 * alignment to the sector size.  However, operating on BS-sized
 * blocks is painfully slow, so we also have a transfer size that is
 * larger but only aligned to the smaller block size.
347
 */
348 349
# define QEMU_MONITOR_MIGRATE_TO_FILE_BS (1024llu * 4)
# define QEMU_MONITOR_MIGRATE_TO_FILE_TRANSFER_SIZE (1024llu * 1024)
350 351

int qemuMonitorMigrateToFile(qemuMonitorPtr mon,
352
                             unsigned int flags,
353 354 355
                             const char * const *argv,
                             const char *target,
                             unsigned long long offset);
356 357

int qemuMonitorMigrateToUnix(qemuMonitorPtr mon,
358
                             unsigned int flags,
359 360 361 362
                             const char *unixfile);

int qemuMonitorMigrateCancel(qemuMonitorPtr mon);

363 364 365 366 367 368
int qemuMonitorGraphicsRelocate(qemuMonitorPtr mon,
                                int type,
                                const char *hostname,
                                int port,
                                int tlsPort,
                                const char *tlsSubject);
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384

/* XXX disk driver type eg,  qcow/etc.
 * XXX cache mode
 */
int qemuMonitorAddUSBDisk(qemuMonitorPtr mon,
                          const char *path);

int qemuMonitorAddUSBDeviceExact(qemuMonitorPtr mon,
                                 int bus,
                                 int dev);
int qemuMonitorAddUSBDeviceMatch(qemuMonitorPtr mon,
                                 int vendor,
                                 int product);


int qemuMonitorAddPCIHostDevice(qemuMonitorPtr mon,
385 386
                                virDomainDevicePCIAddress *hostAddr,
                                virDomainDevicePCIAddress *guestAddr);
387 388 389 390 391 392 393

/* XXX disk driver type eg,  qcow/etc.
 * XXX cache mode
 */
int qemuMonitorAddPCIDisk(qemuMonitorPtr mon,
                          const char *path,
                          const char *bus,
394
                          virDomainDevicePCIAddress *guestAddr);
395 396 397 398 399 400

/* XXX do we really want to hardcode 'nicstr' as the
 * sendable item here
 */
int qemuMonitorAddPCINetwork(qemuMonitorPtr mon,
                             const char *nicstr,
401
                             virDomainDevicePCIAddress *guestAddr);
402 403

int qemuMonitorRemovePCIDevice(qemuMonitorPtr mon,
404
                               virDomainDevicePCIAddress *guestAddr);
405 406 407 408 409 410


int qemuMonitorSendFileHandle(qemuMonitorPtr mon,
                              const char *fdname,
                              int fd);

411 412 413
/* The function preserves previous error and only sets it's own error if no
 * error was set before.
 */
414 415 416 417 418 419 420 421
int qemuMonitorCloseFileHandle(qemuMonitorPtr mon,
                               const char *fdname);


/* XXX do we really want to hardcode 'netstr' as the
 * sendable item here
 */
int qemuMonitorAddHostNetwork(qemuMonitorPtr mon,
422 423 424
                              const char *netstr,
                              int tapfd, const char *tapfd_name,
                              int vhostfd, const char *vhostfd_name);
425 426 427 428 429

int qemuMonitorRemoveHostNetwork(qemuMonitorPtr mon,
                                 int vlan,
                                 const char *netname);

430
int qemuMonitorAddNetdev(qemuMonitorPtr mon,
431 432 433
                         const char *netdevstr,
                         int tapfd, const char *tapfd_name,
                         int vhostfd, const char *vhostfd_name);
434 435 436 437

int qemuMonitorRemoveNetdev(qemuMonitorPtr mon,
                            const char *alias);

438 439
int qemuMonitorGetPtyPaths(qemuMonitorPtr mon,
                           virHashTablePtr paths);
440

441 442 443 444
int qemuMonitorAttachPCIDiskController(qemuMonitorPtr mon,
                                       const char *bus,
                                       virDomainDevicePCIAddress *guestAddr);

445 446 447 448 449
int qemuMonitorAttachDrive(qemuMonitorPtr mon,
                           const char *drivestr,
                           virDomainDevicePCIAddress *controllerAddr,
                           virDomainDeviceDriveAddress *driveAddr);

450 451 452 453 454 455 456 457 458 459 460

typedef struct _qemuMonitorPCIAddress qemuMonitorPCIAddress;
struct _qemuMonitorPCIAddress {
    unsigned int vendor;
    unsigned int product;
    virDomainDevicePCIAddress addr;
};

int qemuMonitorGetAllPCIAddresses(qemuMonitorPtr mon,
                                  qemuMonitorPCIAddress **addrs);

461 462 463
int qemuMonitorAddDevice(qemuMonitorPtr mon,
                         const char *devicestr);

464 465 466 467 468
int qemuMonitorAddDeviceWithFd(qemuMonitorPtr mon,
                               const char *devicestr,
                               int fd,
                               const char *fdname);

469
int qemuMonitorDelDevice(qemuMonitorPtr mon,
470
                         const char *devalias);
471

472 473 474
int qemuMonitorAddDrive(qemuMonitorPtr mon,
                        const char *drivestr);

475
int qemuMonitorDriveDel(qemuMonitorPtr mon,
476 477
                        const char *drivestr);

478 479 480 481
int qemuMonitorSetDrivePassphrase(qemuMonitorPtr mon,
                                  const char *alias,
                                  const char *passphrase);

C
Chris Lalancette 已提交
482 483 484 485
int qemuMonitorCreateSnapshot(qemuMonitorPtr mon, const char *name);
int qemuMonitorLoadSnapshot(qemuMonitorPtr mon, const char *name);
int qemuMonitorDeleteSnapshot(qemuMonitorPtr mon, const char *name);

486 487 488 489
int qemuMonitorDiskSnapshot(qemuMonitorPtr mon,
                            const char *device,
                            const char *file);

490 491 492 493
int qemuMonitorArbitraryCommand(qemuMonitorPtr mon,
                                const char *cmd,
                                char **reply,
                                bool hmp);
494

495 496
int qemuMonitorInjectNMI(qemuMonitorPtr mon);

497 498 499
int qemuMonitorScreendump(qemuMonitorPtr mon,
                          const char *file);

500 501 502 503 504
int qemuMonitorSendKey(qemuMonitorPtr mon,
                       unsigned int holdtime,
                       unsigned int *keycodes,
                       unsigned int nkeycodes);

505 506 507 508 509 510 511 512 513 514 515 516 517
typedef enum {
    BLOCK_JOB_ABORT = 0,
    BLOCK_JOB_INFO = 1,
    BLOCK_JOB_SPEED = 2,
    BLOCK_JOB_PULL = 3,
} BLOCK_JOB_CMD;

int qemuMonitorBlockJob(qemuMonitorPtr mon,
                        const char *device,
                        unsigned long bandwidth,
                        virDomainBlockJobInfoPtr info,
                        int mode);

518 519 520 521 522 523 524 525 526 527 528 529 530
/**
 * When running two dd process and using <> redirection, we need a
 * shell that will not truncate files.  These two strings serve that
 * purpose.
 */
# ifdef VIR_WRAPPER_SHELL
#  define VIR_WRAPPER_SHELL_PREFIX VIR_WRAPPER_SHELL " -c '"
#  define VIR_WRAPPER_SHELL_SUFFIX "'"
# else
#  define VIR_WRAPPER_SHELL_PREFIX /* nothing */
#  define VIR_WRAPPER_SHELL_SUFFIX /* nothing */
# endif

531
#endif /* QEMU_MONITOR_H */