qemu_monitor.h 37.9 KB
Newer Older
1 2 3
/*
 * qemu_monitor.h: interaction with QEMU monitor console
 *
4
 * Copyright (C) 2006-2015 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 "virnetdev.h"
35
# include "device_conf.h"
36
# include "cpu/cpu.h"
37

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

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

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

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

    qemuMonitorPasswordHandler passwordHandler;
    void *passwordOpaque;
};

J
Jiri Denemark 已提交
72 73

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

179 180 181 182 183 184
typedef int (*qemuMonitorDomainSerialChangeCallback)(qemuMonitorPtr mon,
                                                     virDomainObjPtr vm,
                                                     const char *devAlias,
                                                     bool connected,
                                                     void *opaque);

185 186 187
typedef struct _qemuMonitorCallbacks qemuMonitorCallbacks;
typedef qemuMonitorCallbacks *qemuMonitorCallbacksPtr;
struct _qemuMonitorCallbacks {
J
Jiri Denemark 已提交
188 189 190 191
    qemuMonitorDestroyCallback destroy;
    qemuMonitorEofNotifyCallback eofNotify;
    qemuMonitorErrorNotifyCallback errorNotify;
    qemuMonitorDiskSecretLookupCallback diskSecretLookup;
192
    qemuMonitorDomainEventCallback domainEvent;
J
Jiri Denemark 已提交
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
    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;
210
    qemuMonitorDomainNicRxFilterChangedCallback domainNicRxFilterChanged;
211
    qemuMonitorDomainSerialChangeCallback domainSerialChange;
212 213
};

214
char *qemuMonitorEscapeArg(const char *in);
215
char *qemuMonitorUnescapeArg(const char *in);
216

217
qemuMonitorPtr qemuMonitorOpen(virDomainObjPtr vm,
218
                               virDomainChrSourceDefPtr config,
E
Eric Blake 已提交
219
                               bool json,
220 221
                               qemuMonitorCallbacksPtr cb,
                               void *opaque)
222
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4);
223 224
qemuMonitorPtr qemuMonitorOpenFD(virDomainObjPtr vm,
                                 int sockfd,
E
Eric Blake 已提交
225
                                 bool json,
226 227
                                 qemuMonitorCallbacksPtr cb,
                                 void *opaque)
228
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4);
229

230
void qemuMonitorClose(qemuMonitorPtr mon);
231

232
int qemuMonitorSetCapabilities(qemuMonitorPtr mon);
233

234 235
int qemuMonitorSetLink(qemuMonitorPtr mon,
                       const char *name,
236 237
                       virDomainNetInterfaceLinkState state)
    ATTRIBUTE_NONNULL(2);
238

239
/* These APIs are for use by the internal Text/JSON monitor impl code only */
240
char *qemuMonitorNextCommandID(qemuMonitorPtr mon);
241 242
int qemuMonitorSend(qemuMonitorPtr mon,
                    qemuMonitorMessagePtr msg);
243 244 245 246
virJSONValuePtr qemuMonitorGetOptions(qemuMonitorPtr mon)
    ATTRIBUTE_NONNULL(1);
void qemuMonitorSetOptions(qemuMonitorPtr mon, virJSONValuePtr options)
    ATTRIBUTE_NONNULL(1);
247 248 249 250
int qemuMonitorUpdateVideoMemorySize(qemuMonitorPtr mon,
                                     virDomainVideoDefPtr video,
                                     const char *videName)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
251 252 253 254 255 256
int qemuMonitorHMPCommandWithFd(qemuMonitorPtr mon,
                                const char *cmd,
                                int scm_fd,
                                char **reply);
# define qemuMonitorHMPCommand(mon, cmd, reply) \
    qemuMonitorHMPCommandWithFd(mon, cmd, -1, reply)
257

258
/* XXX same comment about virConnectPtr as above */
259 260 261 262 263
int qemuMonitorGetDiskSecret(qemuMonitorPtr mon,
                             virConnectPtr conn,
                             const char *path,
                             char **secret,
                             size_t *secretLen);
264

265 266 267
int qemuMonitorEmitEvent(qemuMonitorPtr mon, const char *event,
                         long long seconds, unsigned int micros,
                         const char *details);
268 269 270 271
int qemuMonitorEmitShutdown(qemuMonitorPtr mon);
int qemuMonitorEmitReset(qemuMonitorPtr mon);
int qemuMonitorEmitPowerdown(qemuMonitorPtr mon);
int qemuMonitorEmitStop(qemuMonitorPtr mon);
272
int qemuMonitorEmitResume(qemuMonitorPtr mon);
273
int qemuMonitorEmitRTCChange(qemuMonitorPtr mon, long long offset);
274
int qemuMonitorEmitWatchdog(qemuMonitorPtr mon, int action);
275 276
int qemuMonitorEmitIOError(qemuMonitorPtr mon,
                           const char *diskAlias,
277 278
                           int action,
                           const char *reason);
279 280 281 282 283 284 285 286 287 288 289
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);
290 291 292
int qemuMonitorEmitTrayChange(qemuMonitorPtr mon,
                              const char *devAlias,
                              int reason);
O
Osier Yang 已提交
293
int qemuMonitorEmitPMWakeup(qemuMonitorPtr mon);
O
Osier Yang 已提交
294
int qemuMonitorEmitPMSuspend(qemuMonitorPtr mon);
295 296 297 298
int qemuMonitorEmitBlockJob(qemuMonitorPtr mon,
                            const char *diskAlias,
                            int type,
                            int status);
299 300
int qemuMonitorEmitBalloonChange(qemuMonitorPtr mon,
                                 unsigned long long actual);
301
int qemuMonitorEmitPMSuspendDisk(qemuMonitorPtr mon);
302
int qemuMonitorEmitGuestPanic(qemuMonitorPtr mon);
303 304
int qemuMonitorEmitDeviceDeleted(qemuMonitorPtr mon,
                                 const char *devAlias);
305 306
int qemuMonitorEmitNicRxFilterChanged(qemuMonitorPtr mon,
                                      const char *devAlias);
307 308 309
int qemuMonitorEmitSerialChange(qemuMonitorPtr mon,
                                const char *devAlias,
                                bool connected);
310

311 312 313
int qemuMonitorStartCPUs(qemuMonitorPtr mon,
                         virConnectPtr conn);
int qemuMonitorStopCPUs(qemuMonitorPtr mon);
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328

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,
329
    QEMU_MONITOR_VM_STATUS_GUEST_PANICKED,
330 331 332 333 334 335 336 337

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

int qemuMonitorGetStatus(qemuMonitorPtr mon,
                         bool *running,
338 339
                         virDomainPausedReason *reason)
    ATTRIBUTE_NONNULL(2);
340

341
int qemuMonitorSystemReset(qemuMonitorPtr mon);
342 343 344 345
int qemuMonitorSystemPowerdown(qemuMonitorPtr mon);

int qemuMonitorGetCPUInfo(qemuMonitorPtr mon,
                          int **pids);
346 347
int qemuMonitorGetVirtType(qemuMonitorPtr mon,
                           int *virtType);
348
int qemuMonitorGetBalloonInfo(qemuMonitorPtr mon,
349
                              unsigned long long *currmem);
350 351 352
int qemuMonitorGetMemoryStats(qemuMonitorPtr mon,
                              virDomainMemoryStatPtr stats,
                              unsigned int nr_stats);
353 354
int qemuMonitorSetMemoryStatsPeriod(qemuMonitorPtr mon,
                                    int period);
355

356
int qemuMonitorBlockIOStatusToError(const char *status);
357 358 359
virHashTablePtr qemuMonitorGetBlockInfo(qemuMonitorPtr mon);
struct qemuDomainDiskInfo *
qemuMonitorBlockInfoLookup(virHashTablePtr blockInfo,
360
                           const char *dev_name);
361

362 363 364 365 366 367 368 369 370 371 372
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;
373 374
    unsigned long long capacity;
    unsigned long long physical;
375
    unsigned long long wr_highest_offset;
376 377 378
};

int qemuMonitorGetAllBlockStatsInfo(qemuMonitorPtr mon,
379 380
                                    virHashTablePtr *ret_stats,
                                    bool backingChain)
381
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
382

383
int qemuMonitorBlockStatsUpdateCapacity(qemuMonitorPtr mon,
384 385
                                        virHashTablePtr stats,
                                        bool backingChain)
386 387
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);

388
int qemuMonitorGetBlockExtent(qemuMonitorPtr mon,
389
                              const char *dev_name,
390
                              unsigned long long *extent);
391
int qemuMonitorBlockResize(qemuMonitorPtr mon,
392
                           const char *dev_name,
393
                           unsigned long long size);
394 395
int qemuMonitorSetVNCPassword(qemuMonitorPtr mon,
                              const char *password);
396 397 398 399 400 401 402
int qemuMonitorSetPassword(qemuMonitorPtr mon,
                           int type,
                           const char *password,
                           const char *action_if_connected);
int qemuMonitorExpirePassword(qemuMonitorPtr mon,
                              int type,
                              const char *expire_time);
403
int qemuMonitorSetBalloon(qemuMonitorPtr mon,
404
                          unsigned long long newmem);
405
int qemuMonitorSetCPU(qemuMonitorPtr mon, int cpu, bool online);
406

407 408

/* XXX should we pass the virDomainDiskDefPtr instead
409
 * and hide dev_name details inside monitor. Reconsider
410 411 412
 * this when doing the QMP implementation
 */
int qemuMonitorEjectMedia(qemuMonitorPtr mon,
413
                          const char *dev_name,
414
                          bool force);
415
int qemuMonitorChangeMedia(qemuMonitorPtr mon,
416
                           const char *dev_name,
417 418
                           const char *newmedia,
                           const char *format);
419 420 421 422 423 424 425 426 427 428 429 430 431 432


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

433 434 435
int qemuMonitorSetMigrationDowntime(qemuMonitorPtr mon,
                                    unsigned long long downtime);

436 437 438 439 440
int qemuMonitorGetMigrationCacheSize(qemuMonitorPtr mon,
                                     unsigned long long *cacheSize);
int qemuMonitorSetMigrationCacheSize(qemuMonitorPtr mon,
                                     unsigned long long cacheSize);

441 442 443 444 445
enum {
    QEMU_MONITOR_MIGRATION_STATUS_INACTIVE,
    QEMU_MONITOR_MIGRATION_STATUS_ACTIVE,
    QEMU_MONITOR_MIGRATION_STATUS_COMPLETED,
    QEMU_MONITOR_MIGRATION_STATUS_ERROR,
446
    QEMU_MONITOR_MIGRATION_STATUS_CANCELLING,
447
    QEMU_MONITOR_MIGRATION_STATUS_CANCELLED,
M
Michael Avdienko 已提交
448
    QEMU_MONITOR_MIGRATION_STATUS_SETUP,
449 450 451 452

    QEMU_MONITOR_MIGRATION_STATUS_LAST
};

453 454
VIR_ENUM_DECL(qemuMonitorMigrationStatus)

455 456 457 458 459 460 461 462
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;
463 464 465 466 467 468 469
    /*
     * 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;
470 471 472 473

    unsigned long long ram_transferred;
    unsigned long long ram_remaining;
    unsigned long long ram_total;
474
    unsigned long long ram_bps;
475 476 477 478 479 480 481 482
    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;
483
    unsigned long long disk_bps;
484 485 486 487 488 489 490 491 492

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

493
int qemuMonitorGetMigrationStatus(qemuMonitorPtr mon,
494
                                  qemuMonitorMigrationStatusPtr status);
495 496
int qemuMonitorGetSpiceMigrationStatus(qemuMonitorPtr mon,
                                       bool *spice_migrated);
497

498 499
typedef enum {
    QEMU_MONITOR_MIGRATION_CAPS_XBZRLE,
500
    QEMU_MONITOR_MIGRATION_CAPS_AUTO_CONVERGE,
501
    QEMU_MONITOR_MIGRATION_CAPS_RDMA_PIN_ALL,
502 503 504 505 506 507

    QEMU_MONITOR_MIGRATION_CAPS_LAST
} qemuMonitorMigrationCaps;

VIR_ENUM_DECL(qemuMonitorMigrationCaps);

508 509
int qemuMonitorGetMigrationCapabilities(qemuMonitorPtr mon,
                                        char ***capabilities);
510 511 512
int qemuMonitorGetMigrationCapability(qemuMonitorPtr mon,
                                      qemuMonitorMigrationCaps capability);
int qemuMonitorSetMigrationCapability(qemuMonitorPtr mon,
513 514
                                      qemuMonitorMigrationCaps capability,
                                      bool state);
515

516
typedef enum {
E
Eric Blake 已提交
517
  QEMU_MONITOR_MIGRATE_BACKGROUND	= 1 << 0,
518 519 520 521 522
  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 已提交
523 524 525 526
int qemuMonitorMigrateToFd(qemuMonitorPtr mon,
                           unsigned int flags,
                           int fd);

527
int qemuMonitorMigrateToHost(qemuMonitorPtr mon,
528
                             unsigned int flags,
529
                             const char *protocol,
530 531 532 533
                             const char *hostname,
                             int port);

int qemuMonitorMigrateToCommand(qemuMonitorPtr mon,
534
                                unsigned int flags,
535 536
                                const char * const *argv);

537 538 539 540 541 542 543
/* 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.
544
 */
545 546
# define QEMU_MONITOR_MIGRATE_TO_FILE_BS (1024llu * 4)
# define QEMU_MONITOR_MIGRATE_TO_FILE_TRANSFER_SIZE (1024llu * 1024)
547 548

int qemuMonitorMigrateToFile(qemuMonitorPtr mon,
549
                             unsigned int flags,
550 551 552
                             const char * const *argv,
                             const char *target,
                             unsigned long long offset);
553 554

int qemuMonitorMigrateToUnix(qemuMonitorPtr mon,
555
                             unsigned int flags,
556 557 558 559
                             const char *unixfile);

int qemuMonitorMigrateCancel(qemuMonitorPtr mon);

560 561 562
int qemuMonitorGetDumpGuestMemoryCapability(qemuMonitorPtr mon,
                                            const char *capability);

563
int qemuMonitorDumpToFd(qemuMonitorPtr mon,
564 565
                        int fd,
                        const char *dumpformat);
566

567 568 569 570 571 572
int qemuMonitorGraphicsRelocate(qemuMonitorPtr mon,
                                int type,
                                const char *hostname,
                                int port,
                                int tlsPort,
                                const char *tlsSubject);
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588

/* 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,
589 590
                                virDevicePCIAddress *hostAddr,
                                virDevicePCIAddress *guestAddr);
591 592 593 594 595 596 597

/* XXX disk driver type eg,  qcow/etc.
 * XXX cache mode
 */
int qemuMonitorAddPCIDisk(qemuMonitorPtr mon,
                          const char *path,
                          const char *bus,
598
                          virDevicePCIAddress *guestAddr);
599 600 601 602 603 604

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

int qemuMonitorRemovePCIDevice(qemuMonitorPtr mon,
608
                               virDevicePCIAddress *guestAddr);
609 610 611 612 613


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

616 617
/* These two functions preserve previous error and only set their own
 * error if no error was set before.
618
 */
619 620
int qemuMonitorCloseFileHandle(qemuMonitorPtr mon,
                               const char *fdname);
621
int qemuMonitorRemoveFd(qemuMonitorPtr mon, int fdset, int fd);
622 623 624 625 626

/* XXX do we really want to hardcode 'netstr' as the
 * sendable item here
 */
int qemuMonitorAddHostNetwork(qemuMonitorPtr mon,
627
                              const char *netstr,
628 629
                              int *tapfd, char **tapfdName, int tapfdSize,
                              int *vhostfd, char **vhostfdName, int vhostfdSize);
630 631 632 633 634

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

635
int qemuMonitorAddNetdev(qemuMonitorPtr mon,
636
                         const char *netdevstr,
637 638
                         int *tapfd, char **tapfdName, int tapfdSize,
                         int *vhostfd, char **vhostfdName, int vhostfdSize);
639 640 641 642

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

643 644 645
int qemuMonitorQueryRxFilter(qemuMonitorPtr mon, const char *alias,
                             virNetDevRxFilterPtr *filter);

646 647 648 649 650 651
typedef struct _qemuMonitorChardevInfo qemuMonitorChardevInfo;
typedef qemuMonitorChardevInfo *qemuMonitorChardevInfoPtr;
struct _qemuMonitorChardevInfo {
    char *ptyPath;
    virDomainChrDeviceState state;
};
652
void qemuMonitorChardevInfoFree(void *data, const void *name);
653 654
int qemuMonitorGetChardevInfo(qemuMonitorPtr mon,
                              virHashTablePtr *retinfo);
655

656 657
int qemuMonitorAttachPCIDiskController(qemuMonitorPtr mon,
                                       const char *bus,
658
                                       virDevicePCIAddress *guestAddr);
659

660 661
int qemuMonitorAttachDrive(qemuMonitorPtr mon,
                           const char *drivestr,
662
                           virDevicePCIAddress *controllerAddr,
663 664
                           virDomainDeviceDriveAddress *driveAddr);

665 666 667 668 669

typedef struct _qemuMonitorPCIAddress qemuMonitorPCIAddress;
struct _qemuMonitorPCIAddress {
    unsigned int vendor;
    unsigned int product;
670
    virDevicePCIAddress addr;
671 672 673 674 675
};

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

676 677 678
int qemuMonitorAddDevice(qemuMonitorPtr mon,
                         const char *devicestr);

679 680 681 682 683
int qemuMonitorAddDeviceWithFd(qemuMonitorPtr mon,
                               const char *devicestr,
                               int fd,
                               const char *fdname);

684
int qemuMonitorDelDevice(qemuMonitorPtr mon,
685
                         const char *devalias);
686

687 688 689 690 691 692 693 694
int qemuMonitorAddObject(qemuMonitorPtr mon,
                         const char *type,
                         const char *objalias,
                         virJSONValuePtr props);

int qemuMonitorDelObject(qemuMonitorPtr mon,
                         const char *objalias);

695 696 697
int qemuMonitorAddDrive(qemuMonitorPtr mon,
                        const char *drivestr);

698
int qemuMonitorDriveDel(qemuMonitorPtr mon,
699 700
                        const char *drivestr);

701 702 703 704
int qemuMonitorSetDrivePassphrase(qemuMonitorPtr mon,
                                  const char *alias,
                                  const char *passphrase);

C
Chris Lalancette 已提交
705 706 707 708
int qemuMonitorCreateSnapshot(qemuMonitorPtr mon, const char *name);
int qemuMonitorLoadSnapshot(qemuMonitorPtr mon, const char *name);
int qemuMonitorDeleteSnapshot(qemuMonitorPtr mon, const char *name);

709
int qemuMonitorDiskSnapshot(qemuMonitorPtr mon,
710
                            virJSONValuePtr actions,
711
                            const char *device,
712 713 714
                            const char *file,
                            const char *format,
                            bool reuse);
715
int qemuMonitorTransaction(qemuMonitorPtr mon, virJSONValuePtr actions)
716
    ATTRIBUTE_NONNULL(2);
717 718 719 720
int qemuMonitorDriveMirror(qemuMonitorPtr mon,
                           const char *device,
                           const char *file,
                           const char *format,
721
                           unsigned long long bandwidth,
722 723
                           unsigned int granularity,
                           unsigned long long buf_size,
724
                           unsigned int flags)
725
    ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
726
int qemuMonitorDrivePivot(qemuMonitorPtr mon,
727
                          const char *device)
728
    ATTRIBUTE_NONNULL(2);
729

730 731 732 733
int qemuMonitorBlockCommit(qemuMonitorPtr mon,
                           const char *device,
                           const char *top,
                           const char *base,
734
                           const char *backingName,
735
                           unsigned long long bandwidth)
736
    ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);
737
bool qemuMonitorSupportsActiveCommit(qemuMonitorPtr mon);
738 739 740 741
char *qemuMonitorDiskNameLookup(qemuMonitorPtr mon,
                                const char *device,
                                virStorageSourcePtr top,
                                virStorageSourcePtr target)
742
    ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);
743

744 745 746 747
int qemuMonitorArbitraryCommand(qemuMonitorPtr mon,
                                const char *cmd,
                                char **reply,
                                bool hmp);
748

749 750
int qemuMonitorInjectNMI(qemuMonitorPtr mon);

751 752 753
int qemuMonitorScreendump(qemuMonitorPtr mon,
                          const char *file);

754 755 756 757 758
int qemuMonitorSendKey(qemuMonitorPtr mon,
                       unsigned int holdtime,
                       unsigned int *keycodes,
                       unsigned int nkeycodes);

759 760 761 762 763 764
int qemuMonitorBlockStream(qemuMonitorPtr mon,
                           const char *device,
                           const char *base,
                           const char *backingName,
                           unsigned long long bandwidth,
                           bool modern)
765
    ATTRIBUTE_NONNULL(2);
766

767 768 769
int qemuMonitorBlockJobCancel(qemuMonitorPtr mon,
                              const char *device,
                              bool modern)
770
    ATTRIBUTE_NONNULL(2);
771

772 773 774 775 776
int qemuMonitorBlockJobSetSpeed(qemuMonitorPtr mon,
                                const char *device,
                                unsigned long long bandwidth,
                                bool modern);

777 778 779 780 781 782 783 784 785 786 787 788 789
typedef struct _qemuMonitorBlockJobInfo qemuMonitorBlockJobInfo;
typedef qemuMonitorBlockJobInfo *qemuMonitorBlockJobInfoPtr;
struct _qemuMonitorBlockJobInfo {
    int type; /* virDomainBlockJobType */
    unsigned long long bandwidth; /* in bytes/s */
    virDomainBlockJobCursor cur;
    virDomainBlockJobCursor end;
};

virHashTablePtr qemuMonitorGetAllBlockJobInfo(qemuMonitorPtr mon);
int qemuMonitorGetBlockJobInfo(qemuMonitorPtr mon,
                               const char *device,
                               qemuMonitorBlockJobInfoPtr info)
790
    ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
791

792 793 794 795 796 797
int qemuMonitorOpenGraphics(qemuMonitorPtr mon,
                            const char *protocol,
                            int fd,
                            const char *fdname,
                            bool skipauth);

798 799
int qemuMonitorSetBlockIoThrottle(qemuMonitorPtr mon,
                                  const char *device,
800 801
                                  virDomainBlockIoTuneInfoPtr info,
                                  bool supportMaxOptions);
802 803 804

int qemuMonitorGetBlockIoThrottle(qemuMonitorPtr mon,
                                  const char *device,
805 806
                                  virDomainBlockIoTuneInfoPtr reply,
                                  bool supportMaxOptions);
807

808 809
int qemuMonitorSystemWakeup(qemuMonitorPtr mon);

810 811 812 813 814 815 816
int qemuMonitorGetVersion(qemuMonitorPtr mon,
                          int *major,
                          int *minor,
                          int *micro,
                          char **package)
    ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);

817 818 819 820 821 822 823 824

typedef struct _qemuMonitorMachineInfo qemuMonitorMachineInfo;
typedef qemuMonitorMachineInfo *qemuMonitorMachineInfoPtr;

struct _qemuMonitorMachineInfo {
    char *name;
    bool isDefault;
    char *alias;
825
    unsigned int maxCpus;
826 827 828 829 830 831 832
};

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

void qemuMonitorMachineInfoFree(qemuMonitorMachineInfoPtr machine);

833 834 835
int qemuMonitorGetCPUDefinitions(qemuMonitorPtr mon,
                                 char ***cpus);

836 837
int qemuMonitorGetCommands(qemuMonitorPtr mon,
                           char ***commands);
838 839
int qemuMonitorGetEvents(qemuMonitorPtr mon,
                         char ***events);
840 841
int qemuMonitorGetCommandLineOptionParameters(qemuMonitorPtr mon,
                                              const char *option,
842 843
                                              char ***params,
                                              bool *found);
844

845 846 847 848
int qemuMonitorGetKVMState(qemuMonitorPtr mon,
                           bool *enabled,
                           bool *present);

849 850
int qemuMonitorGetObjectTypes(qemuMonitorPtr mon,
                              char ***types);
851 852 853
int qemuMonitorGetObjectProps(qemuMonitorPtr mon,
                              const char *type,
                              char ***props);
854
char *qemuMonitorGetTargetArch(qemuMonitorPtr mon);
855

856 857 858
int qemuMonitorNBDServerStart(qemuMonitorPtr mon,
                              const char *host,
                              unsigned int port);
859 860 861
int qemuMonitorNBDServerAdd(qemuMonitorPtr mon,
                            const char *deviceID,
                            bool writable);
862
int qemuMonitorNBDServerStop(qemuMonitorPtr);
S
Stefan Berger 已提交
863 864 865 866 867 868
int qemuMonitorGetTPMModels(qemuMonitorPtr mon,
                            char ***tpmmodels);

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

869 870 871
int qemuMonitorAttachCharDev(qemuMonitorPtr mon,
                             const char *chrID,
                             virDomainChrSourceDefPtr chr);
872 873
int qemuMonitorDetachCharDev(qemuMonitorPtr mon,
                             const char *chrID);
874 875 876 877

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

878 879
int qemuMonitorSetDomainLog(qemuMonitorPtr mon, int logfd);

880 881 882
int qemuMonitorGetGuestCPU(qemuMonitorPtr mon,
                           virArch arch,
                           virCPUDataPtr *data);
883

884 885
int qemuMonitorRTCResetReinjection(qemuMonitorPtr mon);

886 887
typedef struct _qemuMonitorIOThreadInfo qemuMonitorIOThreadInfo;
typedef qemuMonitorIOThreadInfo *qemuMonitorIOThreadInfoPtr;
888

889
struct _qemuMonitorIOThreadInfo {
890
    unsigned int iothread_id;
891 892 893
    int thread_id;
};
int qemuMonitorGetIOThreads(qemuMonitorPtr mon,
894
                            qemuMonitorIOThreadInfoPtr **iothreads);
895

896 897 898 899 900 901 902 903 904 905 906 907 908 909
typedef struct _qemuMonitorMemoryDeviceInfo qemuMonitorMemoryDeviceInfo;
typedef qemuMonitorMemoryDeviceInfo *qemuMonitorMemoryDeviceInfoPtr;

struct _qemuMonitorMemoryDeviceInfo {
    unsigned long long address;
    unsigned int slot;
    bool hotplugged;
    bool hotpluggable;
};

int qemuMonitorGetMemoryDeviceInfo(qemuMonitorPtr mon,
                                   virHashTablePtr *info)
    ATTRIBUTE_NONNULL(2);

910 911 912 913 914 915 916 917 918 919 920 921 922
/**
 * 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

923
#endif /* QEMU_MONITOR_H */