qemu_monitor.h 35.3 KB
Newer Older
1 2 3
/*
 * qemu_monitor.h: interaction with QEMU monitor console
 *
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
 *
 * 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 "virbitmap.h"
32
# include "virhash.h"
33
# include "virjson.h"
34
# include "device_conf.h"
35
# include "cpu/cpu.h"
36

37 38
typedef struct _qemuMonitor qemuMonitor;
typedef qemuMonitor *qemuMonitorPtr;
39

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

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

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

    qemuMonitorPasswordHandler passwordHandler;
    void *passwordOpaque;
};

J
Jiri Denemark 已提交
71 72

typedef void (*qemuMonitorDestroyCallback)(qemuMonitorPtr mon,
73 74
                                           virDomainObjPtr vm,
                                           void *opaque);
J
Jiri Denemark 已提交
75
typedef void (*qemuMonitorEofNotifyCallback)(qemuMonitorPtr mon,
76 77
                                             virDomainObjPtr vm,
                                             void *opaque);
J
Jiri Denemark 已提交
78
typedef void (*qemuMonitorErrorNotifyCallback)(qemuMonitorPtr mon,
79 80
                                               virDomainObjPtr vm,
                                               void *opaque);
J
Jiri Denemark 已提交
81 82 83 84 85 86 87 88 89 90
/* XXX we'd really like to avoid virConnectPtr here
 * 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
 */
typedef int (*qemuMonitorDiskSecretLookupCallback)(qemuMonitorPtr mon,
                                                   virConnectPtr conn,
                                                   virDomainObjPtr vm,
                                                   const char *path,
                                                   char **secret,
91 92
                                                   size_t *secretLen,
                                                   void *opaque);
93 94 95 96 97 98 99
typedef int (*qemuMonitorDomainEventCallback)(qemuMonitorPtr mon,
                                              virDomainObjPtr vm,
                                              const char *event,
                                              long long seconds,
                                              unsigned int micros,
                                              const char *details,
                                              void *opaque);
J
Jiri Denemark 已提交
100
typedef int (*qemuMonitorDomainShutdownCallback)(qemuMonitorPtr mon,
101 102
                                                 virDomainObjPtr vm,
                                                 void *opaque);
J
Jiri Denemark 已提交
103
typedef int (*qemuMonitorDomainResetCallback)(qemuMonitorPtr mon,
104 105
                                              virDomainObjPtr vm,
                                              void *opaque);
J
Jiri Denemark 已提交
106
typedef int (*qemuMonitorDomainPowerdownCallback)(qemuMonitorPtr mon,
107 108
                                                  virDomainObjPtr vm,
                                                  void *opaque);
J
Jiri Denemark 已提交
109
typedef int (*qemuMonitorDomainStopCallback)(qemuMonitorPtr mon,
110 111
                                             virDomainObjPtr vm,
                                             void *opaque);
J
Jiri Denemark 已提交
112
typedef int (*qemuMonitorDomainResumeCallback)(qemuMonitorPtr mon,
113 114
                                               virDomainObjPtr vm,
                                               void *opaque);
J
Jiri Denemark 已提交
115 116
typedef int (*qemuMonitorDomainRTCChangeCallback)(qemuMonitorPtr mon,
                                                  virDomainObjPtr vm,
117 118
                                                  long long offset,
                                                  void *opaque);
J
Jiri Denemark 已提交
119 120
typedef int (*qemuMonitorDomainWatchdogCallback)(qemuMonitorPtr mon,
                                                 virDomainObjPtr vm,
121 122
                                                 int action,
                                                 void *opaque);
J
Jiri Denemark 已提交
123 124 125 126
typedef int (*qemuMonitorDomainIOErrorCallback)(qemuMonitorPtr mon,
                                                virDomainObjPtr vm,
                                                const char *diskAlias,
                                                int action,
127 128
                                                const char *reason,
                                                void *opaque);
J
Jiri Denemark 已提交
129 130 131 132 133 134 135 136 137 138 139
typedef int (*qemuMonitorDomainGraphicsCallback)(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,
140 141
                                                 const char *saslUsername,
                                                 void *opaque);
J
Jiri Denemark 已提交
142 143 144 145
typedef int (*qemuMonitorDomainBlockJobCallback)(qemuMonitorPtr mon,
                                                 virDomainObjPtr vm,
                                                 const char *diskAlias,
                                                 int type,
146 147
                                                 int status,
                                                 void *opaque);
J
Jiri Denemark 已提交
148 149 150
typedef int (*qemuMonitorDomainTrayChangeCallback)(qemuMonitorPtr mon,
                                                   virDomainObjPtr vm,
                                                   const char *devAlias,
151 152
                                                   int reason,
                                                   void *opaque);
J
Jiri Denemark 已提交
153
typedef int (*qemuMonitorDomainPMWakeupCallback)(qemuMonitorPtr mon,
154 155
                                                 virDomainObjPtr vm,
                                                 void *opaque);
J
Jiri Denemark 已提交
156
typedef int (*qemuMonitorDomainPMSuspendCallback)(qemuMonitorPtr mon,
157 158
                                                  virDomainObjPtr vm,
                                                  void *opaque);
J
Jiri Denemark 已提交
159 160
typedef int (*qemuMonitorDomainBalloonChangeCallback)(qemuMonitorPtr mon,
                                                      virDomainObjPtr vm,
161 162
                                                      unsigned long long actual,
                                                      void *opaque);
J
Jiri Denemark 已提交
163
typedef int (*qemuMonitorDomainPMSuspendDiskCallback)(qemuMonitorPtr mon,
164 165
                                                      virDomainObjPtr vm,
                                                      void *opaque);
J
Jiri Denemark 已提交
166
typedef int (*qemuMonitorDomainGuestPanicCallback)(qemuMonitorPtr mon,
167 168
                                                   virDomainObjPtr vm,
                                                   void *opaque);
J
Jiri Denemark 已提交
169 170
typedef int (*qemuMonitorDomainDeviceDeletedCallback)(qemuMonitorPtr mon,
                                                      virDomainObjPtr vm,
171 172
                                                      const char *devAlias,
                                                      void *opaque);
J
Jiri Denemark 已提交
173

174 175 176
typedef struct _qemuMonitorCallbacks qemuMonitorCallbacks;
typedef qemuMonitorCallbacks *qemuMonitorCallbacksPtr;
struct _qemuMonitorCallbacks {
J
Jiri Denemark 已提交
177 178 179 180
    qemuMonitorDestroyCallback destroy;
    qemuMonitorEofNotifyCallback eofNotify;
    qemuMonitorErrorNotifyCallback errorNotify;
    qemuMonitorDiskSecretLookupCallback diskSecretLookup;
181
    qemuMonitorDomainEventCallback domainEvent;
J
Jiri Denemark 已提交
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
    qemuMonitorDomainShutdownCallback domainShutdown;
    qemuMonitorDomainResetCallback domainReset;
    qemuMonitorDomainPowerdownCallback domainPowerdown;
    qemuMonitorDomainStopCallback domainStop;
    qemuMonitorDomainResumeCallback domainResume;
    qemuMonitorDomainRTCChangeCallback domainRTCChange;
    qemuMonitorDomainWatchdogCallback domainWatchdog;
    qemuMonitorDomainIOErrorCallback domainIOError;
    qemuMonitorDomainGraphicsCallback domainGraphics;
    qemuMonitorDomainBlockJobCallback domainBlockJob;
    qemuMonitorDomainTrayChangeCallback domainTrayChange;
    qemuMonitorDomainPMWakeupCallback domainPMWakeup;
    qemuMonitorDomainPMSuspendCallback domainPMSuspend;
    qemuMonitorDomainBalloonChangeCallback domainBalloonChange;
    qemuMonitorDomainPMSuspendDiskCallback domainPMSuspendDisk;
    qemuMonitorDomainGuestPanicCallback domainGuestPanic;
    qemuMonitorDomainDeviceDeletedCallback domainDeviceDeleted;
199 200
};

201
char *qemuMonitorEscapeArg(const char *in);
202
char *qemuMonitorUnescapeArg(const char *in);
203

204
qemuMonitorPtr qemuMonitorOpen(virDomainObjPtr vm,
205
                               virDomainChrSourceDefPtr config,
E
Eric Blake 已提交
206
                               bool json,
207 208
                               qemuMonitorCallbacksPtr cb,
                               void *opaque)
209
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4);
210 211
qemuMonitorPtr qemuMonitorOpenFD(virDomainObjPtr vm,
                                 int sockfd,
E
Eric Blake 已提交
212
                                 bool json,
213 214
                                 qemuMonitorCallbacksPtr cb,
                                 void *opaque)
215
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4);
216

217
void qemuMonitorClose(qemuMonitorPtr mon);
218

219
int qemuMonitorSetCapabilities(qemuMonitorPtr mon);
220

221 222
int qemuMonitorSetLink(qemuMonitorPtr mon,
                       const char *name,
223
                       virDomainNetInterfaceLinkState state);
224

225
/* These APIs are for use by the internal Text/JSON monitor impl code only */
226
char *qemuMonitorNextCommandID(qemuMonitorPtr mon);
227 228
int qemuMonitorSend(qemuMonitorPtr mon,
                    qemuMonitorMessagePtr msg);
229 230 231 232
virJSONValuePtr qemuMonitorGetOptions(qemuMonitorPtr mon)
    ATTRIBUTE_NONNULL(1);
void qemuMonitorSetOptions(qemuMonitorPtr mon, virJSONValuePtr options)
    ATTRIBUTE_NONNULL(1);
233 234 235 236 237 238
int qemuMonitorHMPCommandWithFd(qemuMonitorPtr mon,
                                const char *cmd,
                                int scm_fd,
                                char **reply);
# define qemuMonitorHMPCommand(mon, cmd, reply) \
    qemuMonitorHMPCommandWithFd(mon, cmd, -1, reply)
239

240
/* XXX same comment about virConnectPtr as above */
241 242 243 244 245
int qemuMonitorGetDiskSecret(qemuMonitorPtr mon,
                             virConnectPtr conn,
                             const char *path,
                             char **secret,
                             size_t *secretLen);
246

247 248 249
int qemuMonitorEmitEvent(qemuMonitorPtr mon, const char *event,
                         long long seconds, unsigned int micros,
                         const char *details);
250 251 252 253
int qemuMonitorEmitShutdown(qemuMonitorPtr mon);
int qemuMonitorEmitReset(qemuMonitorPtr mon);
int qemuMonitorEmitPowerdown(qemuMonitorPtr mon);
int qemuMonitorEmitStop(qemuMonitorPtr mon);
254
int qemuMonitorEmitResume(qemuMonitorPtr mon);
255
int qemuMonitorEmitRTCChange(qemuMonitorPtr mon, long long offset);
256
int qemuMonitorEmitWatchdog(qemuMonitorPtr mon, int action);
257 258
int qemuMonitorEmitIOError(qemuMonitorPtr mon,
                           const char *diskAlias,
259 260
                           int action,
                           const char *reason);
261 262 263 264 265 266 267 268 269 270 271
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);
272 273 274
int qemuMonitorEmitTrayChange(qemuMonitorPtr mon,
                              const char *devAlias,
                              int reason);
O
Osier Yang 已提交
275
int qemuMonitorEmitPMWakeup(qemuMonitorPtr mon);
O
Osier Yang 已提交
276
int qemuMonitorEmitPMSuspend(qemuMonitorPtr mon);
277 278 279 280
int qemuMonitorEmitBlockJob(qemuMonitorPtr mon,
                            const char *diskAlias,
                            int type,
                            int status);
281 282
int qemuMonitorEmitBalloonChange(qemuMonitorPtr mon,
                                 unsigned long long actual);
283
int qemuMonitorEmitPMSuspendDisk(qemuMonitorPtr mon);
284
int qemuMonitorEmitGuestPanic(qemuMonitorPtr mon);
285 286
int qemuMonitorEmitDeviceDeleted(qemuMonitorPtr mon,
                                 const char *devAlias);
287

288 289 290
int qemuMonitorStartCPUs(qemuMonitorPtr mon,
                         virConnectPtr conn);
int qemuMonitorStopCPUs(qemuMonitorPtr mon);
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305

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,
306
    QEMU_MONITOR_VM_STATUS_GUEST_PANICKED,
307 308 309 310 311 312 313 314 315

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

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

317
int qemuMonitorSystemReset(qemuMonitorPtr mon);
318 319 320 321
int qemuMonitorSystemPowerdown(qemuMonitorPtr mon);

int qemuMonitorGetCPUInfo(qemuMonitorPtr mon,
                          int **pids);
322 323
int qemuMonitorGetVirtType(qemuMonitorPtr mon,
                           int *virtType);
324
int qemuMonitorGetBalloonInfo(qemuMonitorPtr mon,
325
                              unsigned long long *currmem);
326 327 328
int qemuMonitorGetMemoryStats(qemuMonitorPtr mon,
                              virDomainMemoryStatPtr stats,
                              unsigned int nr_stats);
329 330
int qemuMonitorSetMemoryStatsPeriod(qemuMonitorPtr mon,
                                    int period);
331

332
int qemuMonitorBlockIOStatusToError(const char *status);
333 334 335
virHashTablePtr qemuMonitorGetBlockInfo(qemuMonitorPtr mon);
struct qemuDomainDiskInfo *
qemuMonitorBlockInfoLookup(virHashTablePtr blockInfo,
336
                           const char *dev_name);
337

338
int qemuMonitorGetBlockStatsInfo(qemuMonitorPtr mon,
339
                                 const char *dev_name,
340 341
                                 long long *rd_req,
                                 long long *rd_bytes,
342
                                 long long *rd_total_times,
343 344
                                 long long *wr_req,
                                 long long *wr_bytes,
345 346 347
                                 long long *wr_total_times,
                                 long long *flush_req,
                                 long long *flush_total_times,
348
                                 long long *errs);
349 350 351 352 353 354 355 356 357 358 359 360

typedef struct _qemuBlockStats qemuBlockStats;
typedef qemuBlockStats *qemuBlockStatsPtr;
struct _qemuBlockStats {
    long long rd_req;
    long long rd_bytes;
    long long wr_req;
    long long wr_bytes;
    long long rd_total_times;
    long long wr_total_times;
    long long flush_req;
    long long flush_total_times;
361 362
    unsigned long long capacity;
    unsigned long long physical;
363
    unsigned long long wr_highest_offset;
364 365 366
};

int qemuMonitorGetAllBlockStatsInfo(qemuMonitorPtr mon,
367 368
                                    virHashTablePtr *ret_stats)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
369

370 371 372 373
int qemuMonitorBlockStatsUpdateCapacity(qemuMonitorPtr mon,
                                        virHashTablePtr stats)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);

374 375
int qemuMonitorGetBlockStatsParamsNumber(qemuMonitorPtr mon,
                                         int *nparams);
376

377
int qemuMonitorGetBlockExtent(qemuMonitorPtr mon,
378
                              const char *dev_name,
379
                              unsigned long long *extent);
380
int qemuMonitorBlockResize(qemuMonitorPtr mon,
381
                           const char *dev_name,
382
                           unsigned long long size);
383 384
int qemuMonitorSetVNCPassword(qemuMonitorPtr mon,
                              const char *password);
385 386 387 388 389 390 391
int qemuMonitorSetPassword(qemuMonitorPtr mon,
                           int type,
                           const char *password,
                           const char *action_if_connected);
int qemuMonitorExpirePassword(qemuMonitorPtr mon,
                              int type,
                              const char *expire_time);
392 393
int qemuMonitorSetBalloon(qemuMonitorPtr mon,
                          unsigned long newmem);
394
int qemuMonitorSetCPU(qemuMonitorPtr mon, int cpu, bool online);
395

396 397

/* XXX should we pass the virDomainDiskDefPtr instead
398
 * and hide dev_name details inside monitor. Reconsider
399 400 401
 * this when doing the QMP implementation
 */
int qemuMonitorEjectMedia(qemuMonitorPtr mon,
402
                          const char *dev_name,
403
                          bool force);
404
int qemuMonitorChangeMedia(qemuMonitorPtr mon,
405
                           const char *dev_name,
406 407
                           const char *newmedia,
                           const char *format);
408 409 410 411 412 413 414 415 416 417 418 419 420 421


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

422 423 424
int qemuMonitorSetMigrationDowntime(qemuMonitorPtr mon,
                                    unsigned long long downtime);

425 426 427 428 429
int qemuMonitorGetMigrationCacheSize(qemuMonitorPtr mon,
                                     unsigned long long *cacheSize);
int qemuMonitorSetMigrationCacheSize(qemuMonitorPtr mon,
                                     unsigned long long cacheSize);

430 431 432 433 434 435
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,
M
Michael Avdienko 已提交
436
    QEMU_MONITOR_MIGRATION_STATUS_SETUP,
437 438 439 440

    QEMU_MONITOR_MIGRATION_STATUS_LAST
};

441 442
VIR_ENUM_DECL(qemuMonitorMigrationStatus)

443 444 445 446 447 448 449 450
typedef struct _qemuMonitorMigrationStatus qemuMonitorMigrationStatus;
typedef qemuMonitorMigrationStatus *qemuMonitorMigrationStatusPtr;
struct _qemuMonitorMigrationStatus {
    int status;
    unsigned long long total_time;
    /* total or expected depending on status */
    bool downtime_set;
    unsigned long long downtime;
451 452 453 454 455 456 457
    /*
     * Duration of the QEMU 'setup' state.
     * for RDMA, this may be on the order of several seconds
     * if pinning support is requested before the migration begins.
     */
    bool setup_time_set;
    unsigned long long setup_time;
458 459 460 461

    unsigned long long ram_transferred;
    unsigned long long ram_remaining;
    unsigned long long ram_total;
462
    unsigned long long ram_bps;
463 464 465 466 467 468 469 470
    bool ram_duplicate_set;
    unsigned long long ram_duplicate;
    unsigned long long ram_normal;
    unsigned long long ram_normal_bytes;

    unsigned long long disk_transferred;
    unsigned long long disk_remaining;
    unsigned long long disk_total;
471
    unsigned long long disk_bps;
472 473 474 475 476 477 478 479 480

    bool xbzrle_set;
    unsigned long long xbzrle_cache_size;
    unsigned long long xbzrle_bytes;
    unsigned long long xbzrle_pages;
    unsigned long long xbzrle_cache_miss;
    unsigned long long xbzrle_overflow;
};

481
int qemuMonitorGetMigrationStatus(qemuMonitorPtr mon,
482
                                  qemuMonitorMigrationStatusPtr status);
483 484
int qemuMonitorGetSpiceMigrationStatus(qemuMonitorPtr mon,
                                       bool *spice_migrated);
485

486 487
typedef enum {
    QEMU_MONITOR_MIGRATION_CAPS_XBZRLE,
488
    QEMU_MONITOR_MIGRATION_CAPS_AUTO_CONVERGE,
489
    QEMU_MONITOR_MIGRATION_CAPS_RDMA_PIN_ALL,
490 491 492 493 494 495

    QEMU_MONITOR_MIGRATION_CAPS_LAST
} qemuMonitorMigrationCaps;

VIR_ENUM_DECL(qemuMonitorMigrationCaps);

496 497
int qemuMonitorGetMigrationCapabilities(qemuMonitorPtr mon,
                                        char ***capabilities);
498 499 500 501 502
int qemuMonitorGetMigrationCapability(qemuMonitorPtr mon,
                                      qemuMonitorMigrationCaps capability);
int qemuMonitorSetMigrationCapability(qemuMonitorPtr mon,
                                      qemuMonitorMigrationCaps capability);

503
typedef enum {
E
Eric Blake 已提交
504
  QEMU_MONITOR_MIGRATE_BACKGROUND	= 1 << 0,
505 506 507 508 509
  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 已提交
510 511 512 513
int qemuMonitorMigrateToFd(qemuMonitorPtr mon,
                           unsigned int flags,
                           int fd);

514
int qemuMonitorMigrateToHost(qemuMonitorPtr mon,
515
                             unsigned int flags,
516
                             const char *protocol,
517 518 519 520
                             const char *hostname,
                             int port);

int qemuMonitorMigrateToCommand(qemuMonitorPtr mon,
521
                                unsigned int flags,
522 523
                                const char * const *argv);

524 525 526 527 528 529 530
/* 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.
531
 */
532 533
# define QEMU_MONITOR_MIGRATE_TO_FILE_BS (1024llu * 4)
# define QEMU_MONITOR_MIGRATE_TO_FILE_TRANSFER_SIZE (1024llu * 1024)
534 535

int qemuMonitorMigrateToFile(qemuMonitorPtr mon,
536
                             unsigned int flags,
537 538 539
                             const char * const *argv,
                             const char *target,
                             unsigned long long offset);
540 541

int qemuMonitorMigrateToUnix(qemuMonitorPtr mon,
542
                             unsigned int flags,
543 544 545 546
                             const char *unixfile);

int qemuMonitorMigrateCancel(qemuMonitorPtr mon);

547 548 549
int qemuMonitorGetDumpGuestMemoryCapability(qemuMonitorPtr mon,
                                            const char *capability);

550
int qemuMonitorDumpToFd(qemuMonitorPtr mon,
551 552
                        int fd,
                        const char *dumpformat);
553

554 555 556 557 558 559
int qemuMonitorGraphicsRelocate(qemuMonitorPtr mon,
                                int type,
                                const char *hostname,
                                int port,
                                int tlsPort,
                                const char *tlsSubject);
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575

/* 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,
576 577
                                virDevicePCIAddress *hostAddr,
                                virDevicePCIAddress *guestAddr);
578 579 580 581 582 583 584

/* XXX disk driver type eg,  qcow/etc.
 * XXX cache mode
 */
int qemuMonitorAddPCIDisk(qemuMonitorPtr mon,
                          const char *path,
                          const char *bus,
585
                          virDevicePCIAddress *guestAddr);
586 587 588 589 590 591

/* XXX do we really want to hardcode 'nicstr' as the
 * sendable item here
 */
int qemuMonitorAddPCINetwork(qemuMonitorPtr mon,
                             const char *nicstr,
592
                             virDevicePCIAddress *guestAddr);
593 594

int qemuMonitorRemovePCIDevice(qemuMonitorPtr mon,
595
                               virDevicePCIAddress *guestAddr);
596 597 598 599 600


int qemuMonitorSendFileHandle(qemuMonitorPtr mon,
                              const char *fdname,
                              int fd);
601
int qemuMonitorAddFd(qemuMonitorPtr mon, int fdset, int fd, const char *name);
602

603 604
/* These two functions preserve previous error and only set their own
 * error if no error was set before.
605
 */
606 607
int qemuMonitorCloseFileHandle(qemuMonitorPtr mon,
                               const char *fdname);
608
int qemuMonitorRemoveFd(qemuMonitorPtr mon, int fdset, int fd);
609 610 611 612 613

/* XXX do we really want to hardcode 'netstr' as the
 * sendable item here
 */
int qemuMonitorAddHostNetwork(qemuMonitorPtr mon,
614
                              const char *netstr,
615 616
                              int *tapfd, char **tapfdName, int tapfdSize,
                              int *vhostfd, char **vhostfdName, int vhostfdSize);
617 618 619 620 621

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

622
int qemuMonitorAddNetdev(qemuMonitorPtr mon,
623
                         const char *netdevstr,
624 625
                         int *tapfd, char **tapfdName, int tapfdSize,
                         int *vhostfd, char **vhostfdName, int vhostfdSize);
626 627 628 629

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

630 631
int qemuMonitorGetPtyPaths(qemuMonitorPtr mon,
                           virHashTablePtr paths);
632

633 634
int qemuMonitorAttachPCIDiskController(qemuMonitorPtr mon,
                                       const char *bus,
635
                                       virDevicePCIAddress *guestAddr);
636

637 638
int qemuMonitorAttachDrive(qemuMonitorPtr mon,
                           const char *drivestr,
639
                           virDevicePCIAddress *controllerAddr,
640 641
                           virDomainDeviceDriveAddress *driveAddr);

642 643 644 645 646

typedef struct _qemuMonitorPCIAddress qemuMonitorPCIAddress;
struct _qemuMonitorPCIAddress {
    unsigned int vendor;
    unsigned int product;
647
    virDevicePCIAddress addr;
648 649 650 651 652
};

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

653 654 655
int qemuMonitorAddDevice(qemuMonitorPtr mon,
                         const char *devicestr);

656 657 658 659 660
int qemuMonitorAddDeviceWithFd(qemuMonitorPtr mon,
                               const char *devicestr,
                               int fd,
                               const char *fdname);

661
int qemuMonitorDelDevice(qemuMonitorPtr mon,
662
                         const char *devalias);
663

664 665 666
int qemuMonitorAddDrive(qemuMonitorPtr mon,
                        const char *drivestr);

667
int qemuMonitorDriveDel(qemuMonitorPtr mon,
668 669
                        const char *drivestr);

670 671 672 673
int qemuMonitorSetDrivePassphrase(qemuMonitorPtr mon,
                                  const char *alias,
                                  const char *passphrase);

C
Chris Lalancette 已提交
674 675 676 677
int qemuMonitorCreateSnapshot(qemuMonitorPtr mon, const char *name);
int qemuMonitorLoadSnapshot(qemuMonitorPtr mon, const char *name);
int qemuMonitorDeleteSnapshot(qemuMonitorPtr mon, const char *name);

678
int qemuMonitorDiskSnapshot(qemuMonitorPtr mon,
679
                            virJSONValuePtr actions,
680
                            const char *device,
681 682 683
                            const char *file,
                            const char *format,
                            bool reuse);
684 685
int qemuMonitorTransaction(qemuMonitorPtr mon, virJSONValuePtr actions)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
686 687 688 689
int qemuMonitorDriveMirror(qemuMonitorPtr mon,
                           const char *device,
                           const char *file,
                           const char *format,
690
                           unsigned long long bandwidth,
691 692
                           unsigned int granularity,
                           unsigned long long buf_size,
693 694 695 696 697 698 699
                           unsigned int flags)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
int qemuMonitorDrivePivot(qemuMonitorPtr mon,
                          const char *device,
                          const char *file,
                          const char *format)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
700

701 702 703 704
int qemuMonitorBlockCommit(qemuMonitorPtr mon,
                           const char *device,
                           const char *top,
                           const char *base,
705
                           const char *backingName,
706
                           unsigned long long bandwidth)
707 708
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
    ATTRIBUTE_NONNULL(4);
709
bool qemuMonitorSupportsActiveCommit(qemuMonitorPtr mon);
710

711 712 713 714
int qemuMonitorArbitraryCommand(qemuMonitorPtr mon,
                                const char *cmd,
                                char **reply,
                                bool hmp);
715

716 717
int qemuMonitorInjectNMI(qemuMonitorPtr mon);

718 719 720
int qemuMonitorScreendump(qemuMonitorPtr mon,
                          const char *file);

721 722 723 724 725
int qemuMonitorSendKey(qemuMonitorPtr mon,
                       unsigned int holdtime,
                       unsigned int *keycodes,
                       unsigned int nkeycodes);

726
typedef enum {
727 728 729 730
    BLOCK_JOB_ABORT,
    BLOCK_JOB_SPEED,
    BLOCK_JOB_PULL,
} qemuMonitorBlockJobCmd;
731 732 733

int qemuMonitorBlockJob(qemuMonitorPtr mon,
                        const char *device,
734 735
                        const char *base,
                        const char *backingName,
736
                        unsigned long long bandwidth,
737 738
                        qemuMonitorBlockJobCmd mode,
                        bool modern)
739
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
740

741 742
int qemuMonitorBlockJobInfo(qemuMonitorPtr mon,
                            const char *device,
743 744
                            virDomainBlockJobInfoPtr info,
                            unsigned long long *bandwidth)
745 746
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);

747 748 749 750 751 752
int qemuMonitorOpenGraphics(qemuMonitorPtr mon,
                            const char *protocol,
                            int fd,
                            const char *fdname,
                            bool skipauth);

753 754 755 756 757 758 759 760
int qemuMonitorSetBlockIoThrottle(qemuMonitorPtr mon,
                                  const char *device,
                                  virDomainBlockIoTuneInfoPtr info);

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

761 762
int qemuMonitorSystemWakeup(qemuMonitorPtr mon);

763 764 765 766 767 768 769
int qemuMonitorGetVersion(qemuMonitorPtr mon,
                          int *major,
                          int *minor,
                          int *micro,
                          char **package)
    ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);

770 771 772 773 774 775 776 777

typedef struct _qemuMonitorMachineInfo qemuMonitorMachineInfo;
typedef qemuMonitorMachineInfo *qemuMonitorMachineInfoPtr;

struct _qemuMonitorMachineInfo {
    char *name;
    bool isDefault;
    char *alias;
778
    unsigned int maxCpus;
779 780 781 782 783 784 785
};

int qemuMonitorGetMachines(qemuMonitorPtr mon,
                           qemuMonitorMachineInfoPtr **machines);

void qemuMonitorMachineInfoFree(qemuMonitorMachineInfoPtr machine);

786 787 788
int qemuMonitorGetCPUDefinitions(qemuMonitorPtr mon,
                                 char ***cpus);

789 790
int qemuMonitorGetCommands(qemuMonitorPtr mon,
                           char ***commands);
791 792
int qemuMonitorGetEvents(qemuMonitorPtr mon,
                         char ***events);
793 794
int qemuMonitorGetCommandLineOptionParameters(qemuMonitorPtr mon,
                                              const char *option,
795 796
                                              char ***params,
                                              bool *found);
797

798 799 800 801
int qemuMonitorGetKVMState(qemuMonitorPtr mon,
                           bool *enabled,
                           bool *present);

802 803
int qemuMonitorGetObjectTypes(qemuMonitorPtr mon,
                              char ***types);
804 805 806
int qemuMonitorGetObjectProps(qemuMonitorPtr mon,
                              const char *type,
                              char ***props);
807
char *qemuMonitorGetTargetArch(qemuMonitorPtr mon);
808

809 810 811
int qemuMonitorNBDServerStart(qemuMonitorPtr mon,
                              const char *host,
                              unsigned int port);
812 813 814
int qemuMonitorNBDServerAdd(qemuMonitorPtr mon,
                            const char *deviceID,
                            bool writable);
815
int qemuMonitorNBDServerStop(qemuMonitorPtr);
S
Stefan Berger 已提交
816 817 818 819 820 821
int qemuMonitorGetTPMModels(qemuMonitorPtr mon,
                            char ***tpmmodels);

int qemuMonitorGetTPMTypes(qemuMonitorPtr mon,
                           char ***tpmtypes);

822 823 824
int qemuMonitorAttachCharDev(qemuMonitorPtr mon,
                             const char *chrID,
                             virDomainChrSourceDefPtr chr);
825 826
int qemuMonitorDetachCharDev(qemuMonitorPtr mon,
                             const char *chrID);
827 828 829 830

int qemuMonitorGetDeviceAliases(qemuMonitorPtr mon,
                                char ***aliases);

831 832
int qemuMonitorSetDomainLog(qemuMonitorPtr mon, int logfd);

833 834 835
int qemuMonitorGetGuestCPU(qemuMonitorPtr mon,
                           virArch arch,
                           virCPUDataPtr *data);
836

837 838
int qemuMonitorRTCResetReinjection(qemuMonitorPtr mon);

839 840 841 842 843 844 845 846 847 848 849 850
typedef struct _qemuMonitorIOThreadsInfo qemuMonitorIOThreadsInfo;
typedef qemuMonitorIOThreadsInfo *qemuMonitorIOThreadsInfoPtr;

struct _qemuMonitorIOThreadsInfo {
    char *name;
    int thread_id;
};
int qemuMonitorGetIOThreads(qemuMonitorPtr mon,
                            qemuMonitorIOThreadsInfoPtr **iothreads);

void qemuMonitorIOThreadsInfoFree(qemuMonitorIOThreadsInfoPtr iothread);

851 852 853 854 855 856 857 858 859 860 861 862 863
/**
 * 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

864
#endif /* QEMU_MONITOR_H */