qemu_monitor.h 20.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 "bitmap.h"
33
# include "virhash.h"
34

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

38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
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;

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

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

    qemuMonitorPasswordHandler passwordHandler;
    void *passwordOpaque;
};

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

75
    void (*eofNotify)(qemuMonitorPtr mon,
76 77 78 79
                      virDomainObjPtr vm);
    void (*errorNotify)(qemuMonitorPtr mon,
                        virDomainObjPtr vm);
    /* XXX we'd really like to avoid virConnectPtr here
80 81 82 83 84 85 86 87 88 89
     * 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);
90 91 92 93 94 95 96 97 98

    int (*domainShutdown)(qemuMonitorPtr mon,
                          virDomainObjPtr vm);
    int (*domainReset)(qemuMonitorPtr mon,
                       virDomainObjPtr vm);
    int (*domainPowerdown)(qemuMonitorPtr mon,
                           virDomainObjPtr vm);
    int (*domainStop)(qemuMonitorPtr mon,
                      virDomainObjPtr vm);
99 100 101
    int (*domainRTCChange)(qemuMonitorPtr mon,
                           virDomainObjPtr vm,
                           long long offset);
102 103 104
    int (*domainWatchdog)(qemuMonitorPtr mon,
                          virDomainObjPtr vm,
                          int action);
105 106 107
    int (*domainIOError)(qemuMonitorPtr mon,
                         virDomainObjPtr vm,
                         const char *diskAlias,
108 109
                         int action,
                         const char *reason);
110 111 112 113 114 115 116 117 118 119 120 121
    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);
122 123 124 125 126
    int (*domainBlockJob)(qemuMonitorPtr mon,
                          virDomainObjPtr vm,
                          const char *diskAlias,
                          int type,
                          int status);
127 128
};

129

130
char *qemuMonitorEscapeArg(const char *in);
131
char *qemuMonitorUnescapeArg(const char *in);
132

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

138
void qemuMonitorClose(qemuMonitorPtr mon);
139

140 141
int qemuMonitorSetCapabilities(qemuMonitorPtr mon,
                               virBitmapPtr qemuCaps);
142

143 144
int qemuMonitorCheckHMP(qemuMonitorPtr mon, const char *cmd);

145 146 147
void qemuMonitorLock(qemuMonitorPtr mon);
void qemuMonitorUnlock(qemuMonitorPtr mon);

148
int qemuMonitorRef(qemuMonitorPtr mon);
149
int qemuMonitorUnref(qemuMonitorPtr mon) ATTRIBUTE_RETURN_CHECK;
150

151 152 153 154
int qemuMonitorSetLink(qemuMonitorPtr mon,
                       const char *name,
                       enum virDomainNetInterfaceLinkState state) ;

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

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

173 174 175 176
int qemuMonitorEmitShutdown(qemuMonitorPtr mon);
int qemuMonitorEmitReset(qemuMonitorPtr mon);
int qemuMonitorEmitPowerdown(qemuMonitorPtr mon);
int qemuMonitorEmitStop(qemuMonitorPtr mon);
177
int qemuMonitorEmitRTCChange(qemuMonitorPtr mon, long long offset);
178
int qemuMonitorEmitWatchdog(qemuMonitorPtr mon, int action);
179 180
int qemuMonitorEmitIOError(qemuMonitorPtr mon,
                           const char *diskAlias,
181 182
                           int action,
                           const char *reason);
183 184 185 186 187 188 189 190 191 192 193
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);
194 195 196 197 198
int qemuMonitorEmitBlockJob(qemuMonitorPtr mon,
                            const char *diskAlias,
                            int type,
                            int status);

199

200 201 202 203

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

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);
228

229
int qemuMonitorSystemReset(qemuMonitorPtr mon);
230 231 232 233
int qemuMonitorSystemPowerdown(qemuMonitorPtr mon);

int qemuMonitorGetCPUInfo(qemuMonitorPtr mon,
                          int **pids);
234 235
int qemuMonitorGetVirtType(qemuMonitorPtr mon,
                           int *virtType);
236 237
int qemuMonitorGetBalloonInfo(qemuMonitorPtr mon,
                              unsigned long *currmem);
238 239 240
int qemuMonitorGetMemoryStats(qemuMonitorPtr mon,
                              virDomainMemoryStatPtr stats,
                              unsigned int nr_stats);
241

242
int qemuMonitorBlockIOStatusToError(const char *status);
243 244 245 246 247
virHashTablePtr qemuMonitorGetBlockInfo(qemuMonitorPtr mon);
struct qemuDomainDiskInfo *
qemuMonitorBlockInfoLookup(virHashTablePtr blockInfo,
                           const char *devname);

248
int qemuMonitorGetBlockStatsInfo(qemuMonitorPtr mon,
249
                                 const char *dev_name,
250 251
                                 long long *rd_req,
                                 long long *rd_bytes,
252
                                 long long *rd_total_times,
253 254
                                 long long *wr_req,
                                 long long *wr_bytes,
255 256 257
                                 long long *wr_total_times,
                                 long long *flush_req,
                                 long long *flush_total_times,
258
                                 long long *errs);
259 260
int qemuMonitorGetBlockStatsParamsNumber(qemuMonitorPtr mon,
                                         int *nparams);
261

262
int qemuMonitorGetBlockExtent(qemuMonitorPtr mon,
263
                              const char *dev_name,
264
                              unsigned long long *extent);
265 266 267
int qemuMonitorBlockResize(qemuMonitorPtr mon,
                           const char *devname,
                           unsigned long long size);
268 269
int qemuMonitorSetVNCPassword(qemuMonitorPtr mon,
                              const char *password);
270 271 272 273 274 275 276
int qemuMonitorSetPassword(qemuMonitorPtr mon,
                           int type,
                           const char *password,
                           const char *action_if_connected);
int qemuMonitorExpirePassword(qemuMonitorPtr mon,
                              int type,
                              const char *expire_time);
277 278
int qemuMonitorSetBalloon(qemuMonitorPtr mon,
                          unsigned long newmem);
279 280
int qemuMonitorSetCPU(qemuMonitorPtr mon, int cpu, int online);

281 282 283 284 285 286

/* XXX should we pass the virDomainDiskDefPtr instead
 * and hide devname details inside monitor. Reconsider
 * this when doing the QMP implementation
 */
int qemuMonitorEjectMedia(qemuMonitorPtr mon,
287
                          const char *dev_name,
288
                          bool force);
289
int qemuMonitorChangeMedia(qemuMonitorPtr mon,
290
                           const char *dev_name,
291 292
                           const char *newmedia,
                           const char *format);
293 294 295 296 297 298 299 300 301 302 303 304 305 306


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);

307 308 309
int qemuMonitorSetMigrationDowntime(qemuMonitorPtr mon,
                                    unsigned long long downtime);

310 311 312 313 314 315 316 317 318 319
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
};

320 321
VIR_ENUM_DECL(qemuMonitorMigrationStatus)

322 323 324 325 326 327
int qemuMonitorGetMigrationStatus(qemuMonitorPtr mon,
                                  int *status,
                                  unsigned long long *transferred,
                                  unsigned long long *remaining,
                                  unsigned long long *total);

328
typedef enum {
E
Eric Blake 已提交
329
  QEMU_MONITOR_MIGRATE_BACKGROUND	= 1 << 0,
330 331 332 333 334
  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 已提交
335 336 337 338
int qemuMonitorMigrateToFd(qemuMonitorPtr mon,
                           unsigned int flags,
                           int fd);

339
int qemuMonitorMigrateToHost(qemuMonitorPtr mon,
340
                             unsigned int flags,
341 342 343 344
                             const char *hostname,
                             int port);

int qemuMonitorMigrateToCommand(qemuMonitorPtr mon,
345
                                unsigned int flags,
346 347
                                const char * const *argv);

348 349 350 351 352 353 354
/* 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.
355
 */
356 357
# define QEMU_MONITOR_MIGRATE_TO_FILE_BS (1024llu * 4)
# define QEMU_MONITOR_MIGRATE_TO_FILE_TRANSFER_SIZE (1024llu * 1024)
358 359

int qemuMonitorMigrateToFile(qemuMonitorPtr mon,
360
                             unsigned int flags,
361 362 363
                             const char * const *argv,
                             const char *target,
                             unsigned long long offset);
364 365

int qemuMonitorMigrateToUnix(qemuMonitorPtr mon,
366
                             unsigned int flags,
367 368 369 370
                             const char *unixfile);

int qemuMonitorMigrateCancel(qemuMonitorPtr mon);

371 372 373 374 375 376
int qemuMonitorGraphicsRelocate(qemuMonitorPtr mon,
                                int type,
                                const char *hostname,
                                int port,
                                int tlsPort,
                                const char *tlsSubject);
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392

/* 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,
393 394
                                virDomainDevicePCIAddress *hostAddr,
                                virDomainDevicePCIAddress *guestAddr);
395 396 397 398 399 400 401

/* XXX disk driver type eg,  qcow/etc.
 * XXX cache mode
 */
int qemuMonitorAddPCIDisk(qemuMonitorPtr mon,
                          const char *path,
                          const char *bus,
402
                          virDomainDevicePCIAddress *guestAddr);
403 404 405 406 407 408

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

int qemuMonitorRemovePCIDevice(qemuMonitorPtr mon,
412
                               virDomainDevicePCIAddress *guestAddr);
413 414 415 416 417 418


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

419 420 421
/* The function preserves previous error and only sets it's own error if no
 * error was set before.
 */
422 423 424 425 426 427 428 429
int qemuMonitorCloseFileHandle(qemuMonitorPtr mon,
                               const char *fdname);


/* XXX do we really want to hardcode 'netstr' as the
 * sendable item here
 */
int qemuMonitorAddHostNetwork(qemuMonitorPtr mon,
430 431 432
                              const char *netstr,
                              int tapfd, const char *tapfd_name,
                              int vhostfd, const char *vhostfd_name);
433 434 435 436 437

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

438
int qemuMonitorAddNetdev(qemuMonitorPtr mon,
439 440 441
                         const char *netdevstr,
                         int tapfd, const char *tapfd_name,
                         int vhostfd, const char *vhostfd_name);
442 443 444 445

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

446 447
int qemuMonitorGetPtyPaths(qemuMonitorPtr mon,
                           virHashTablePtr paths);
448

449 450 451 452
int qemuMonitorAttachPCIDiskController(qemuMonitorPtr mon,
                                       const char *bus,
                                       virDomainDevicePCIAddress *guestAddr);

453 454 455 456 457
int qemuMonitorAttachDrive(qemuMonitorPtr mon,
                           const char *drivestr,
                           virDomainDevicePCIAddress *controllerAddr,
                           virDomainDeviceDriveAddress *driveAddr);

458 459 460 461 462 463 464 465 466 467 468

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

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

469 470 471
int qemuMonitorAddDevice(qemuMonitorPtr mon,
                         const char *devicestr);

472 473 474 475 476
int qemuMonitorAddDeviceWithFd(qemuMonitorPtr mon,
                               const char *devicestr,
                               int fd,
                               const char *fdname);

477
int qemuMonitorDelDevice(qemuMonitorPtr mon,
478
                         const char *devalias);
479

480 481 482
int qemuMonitorAddDrive(qemuMonitorPtr mon,
                        const char *drivestr);

483
int qemuMonitorDriveDel(qemuMonitorPtr mon,
484 485
                        const char *drivestr);

486 487 488 489
int qemuMonitorSetDrivePassphrase(qemuMonitorPtr mon,
                                  const char *alias,
                                  const char *passphrase);

C
Chris Lalancette 已提交
490 491 492 493
int qemuMonitorCreateSnapshot(qemuMonitorPtr mon, const char *name);
int qemuMonitorLoadSnapshot(qemuMonitorPtr mon, const char *name);
int qemuMonitorDeleteSnapshot(qemuMonitorPtr mon, const char *name);

494 495 496 497
int qemuMonitorDiskSnapshot(qemuMonitorPtr mon,
                            const char *device,
                            const char *file);

498 499 500 501
int qemuMonitorArbitraryCommand(qemuMonitorPtr mon,
                                const char *cmd,
                                char **reply,
                                bool hmp);
502

503 504
int qemuMonitorInjectNMI(qemuMonitorPtr mon);

505 506 507
int qemuMonitorScreendump(qemuMonitorPtr mon,
                          const char *file);

508 509 510 511 512
int qemuMonitorSendKey(qemuMonitorPtr mon,
                       unsigned int holdtime,
                       unsigned int *keycodes,
                       unsigned int nkeycodes);

513 514 515 516 517 518 519 520 521 522 523 524 525
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);

526 527 528 529 530 531
int qemuMonitorOpenGraphics(qemuMonitorPtr mon,
                            const char *protocol,
                            int fd,
                            const char *fdname,
                            bool skipauth);

532 533 534 535 536 537 538 539
int qemuMonitorSetBlockIoThrottle(qemuMonitorPtr mon,
                                  const char *device,
                                  virDomainBlockIoTuneInfoPtr info);

int qemuMonitorGetBlockIoThrottle(qemuMonitorPtr mon,
                                  const char *device,
                                  virDomainBlockIoTuneInfoPtr reply);

540 541
int qemuMonitorSystemWakeup(qemuMonitorPtr mon);

542 543 544 545 546 547 548 549 550 551 552 553 554
/**
 * 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

555
#endif /* QEMU_MONITOR_H */