qemu_monitor.h 41.5 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"
A
Andrea Bolognani 已提交
37
# include "util/virgic.h"
38

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

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

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

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

    qemuMonitorPasswordHandler passwordHandler;
    void *passwordOpaque;
};

J
Jiri Denemark 已提交
73 74

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

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

186 187 188 189
typedef int (*qemuMonitorDomainSpiceMigratedCallback)(qemuMonitorPtr mon,
                                                      virDomainObjPtr vm,
                                                      void *opaque);

190 191 192 193 194
typedef int (*qemuMonitorDomainMigrationStatusCallback)(qemuMonitorPtr mon,
                                                        virDomainObjPtr vm,
                                                        int status,
                                                        void *opaque);

195 196 197 198 199
typedef int (*qemuMonitorDomainMigrationPassCallback)(qemuMonitorPtr mon,
                                                      virDomainObjPtr vm,
                                                      int pass,
                                                      void *opaque);

200 201 202 203 204 205 206 207 208 209
typedef int (*qemuMonitorDomainAcpiOstInfoCallback)(qemuMonitorPtr mon,
                                                    virDomainObjPtr vm,
                                                    const char *alias,
                                                    const char *slotType,
                                                    const char *slot,
                                                    unsigned int source,
                                                    unsigned int status,
                                                    void *opaque);


210 211 212
typedef struct _qemuMonitorCallbacks qemuMonitorCallbacks;
typedef qemuMonitorCallbacks *qemuMonitorCallbacksPtr;
struct _qemuMonitorCallbacks {
J
Jiri Denemark 已提交
213 214 215 216
    qemuMonitorDestroyCallback destroy;
    qemuMonitorEofNotifyCallback eofNotify;
    qemuMonitorErrorNotifyCallback errorNotify;
    qemuMonitorDiskSecretLookupCallback diskSecretLookup;
217
    qemuMonitorDomainEventCallback domainEvent;
J
Jiri Denemark 已提交
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
    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;
235
    qemuMonitorDomainNicRxFilterChangedCallback domainNicRxFilterChanged;
236
    qemuMonitorDomainSerialChangeCallback domainSerialChange;
237
    qemuMonitorDomainSpiceMigratedCallback domainSpiceMigrated;
238
    qemuMonitorDomainMigrationStatusCallback domainMigrationStatus;
239
    qemuMonitorDomainMigrationPassCallback domainMigrationPass;
240
    qemuMonitorDomainAcpiOstInfoCallback domainAcpiOstInfo;
241 242
};

243
char *qemuMonitorEscapeArg(const char *in);
244
char *qemuMonitorUnescapeArg(const char *in);
245

246
qemuMonitorPtr qemuMonitorOpen(virDomainObjPtr vm,
247
                               virDomainChrSourceDefPtr config,
E
Eric Blake 已提交
248
                               bool json,
249 250
                               qemuMonitorCallbacksPtr cb,
                               void *opaque)
251
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4);
252 253
qemuMonitorPtr qemuMonitorOpenFD(virDomainObjPtr vm,
                                 int sockfd,
E
Eric Blake 已提交
254
                                 bool json,
255 256
                                 qemuMonitorCallbacksPtr cb,
                                 void *opaque)
257
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4);
258

259 260
void qemuMonitorUnregister(qemuMonitorPtr mon)
    ATTRIBUTE_NONNULL(1);
261
void qemuMonitorClose(qemuMonitorPtr mon);
262

263 264
virErrorPtr qemuMonitorLastError(qemuMonitorPtr mon);

265
int qemuMonitorSetCapabilities(qemuMonitorPtr mon);
266

267 268
int qemuMonitorSetLink(qemuMonitorPtr mon,
                       const char *name,
269 270
                       virDomainNetInterfaceLinkState state)
    ATTRIBUTE_NONNULL(2);
271

272
/* These APIs are for use by the internal Text/JSON monitor impl code only */
273
char *qemuMonitorNextCommandID(qemuMonitorPtr mon);
274 275
int qemuMonitorSend(qemuMonitorPtr mon,
                    qemuMonitorMessagePtr msg);
276 277 278 279
virJSONValuePtr qemuMonitorGetOptions(qemuMonitorPtr mon)
    ATTRIBUTE_NONNULL(1);
void qemuMonitorSetOptions(qemuMonitorPtr mon, virJSONValuePtr options)
    ATTRIBUTE_NONNULL(1);
280 281
int qemuMonitorUpdateVideoMemorySize(qemuMonitorPtr mon,
                                     virDomainVideoDefPtr video,
C
Cao jin 已提交
282
                                     const char *videoName)
283
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
284 285 286 287
int qemuMonitorUpdateVideoVram64Size(qemuMonitorPtr mon,
                                     virDomainVideoDefPtr video,
                                     const char *videoName)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
288 289 290 291 292 293
int qemuMonitorHMPCommandWithFd(qemuMonitorPtr mon,
                                const char *cmd,
                                int scm_fd,
                                char **reply);
# define qemuMonitorHMPCommand(mon, cmd, reply) \
    qemuMonitorHMPCommandWithFd(mon, cmd, -1, reply)
294

295
/* XXX same comment about virConnectPtr as above */
296 297 298 299 300
int qemuMonitorGetDiskSecret(qemuMonitorPtr mon,
                             virConnectPtr conn,
                             const char *path,
                             char **secret,
                             size_t *secretLen);
301

302 303 304
int qemuMonitorEmitEvent(qemuMonitorPtr mon, const char *event,
                         long long seconds, unsigned int micros,
                         const char *details);
305 306 307 308
int qemuMonitorEmitShutdown(qemuMonitorPtr mon);
int qemuMonitorEmitReset(qemuMonitorPtr mon);
int qemuMonitorEmitPowerdown(qemuMonitorPtr mon);
int qemuMonitorEmitStop(qemuMonitorPtr mon);
309
int qemuMonitorEmitResume(qemuMonitorPtr mon);
310
int qemuMonitorEmitRTCChange(qemuMonitorPtr mon, long long offset);
311
int qemuMonitorEmitWatchdog(qemuMonitorPtr mon, int action);
312 313
int qemuMonitorEmitIOError(qemuMonitorPtr mon,
                           const char *diskAlias,
314 315
                           int action,
                           const char *reason);
316 317 318 319 320 321 322 323 324 325 326
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);
327 328 329
int qemuMonitorEmitTrayChange(qemuMonitorPtr mon,
                              const char *devAlias,
                              int reason);
O
Osier Yang 已提交
330
int qemuMonitorEmitPMWakeup(qemuMonitorPtr mon);
O
Osier Yang 已提交
331
int qemuMonitorEmitPMSuspend(qemuMonitorPtr mon);
332 333 334 335
int qemuMonitorEmitBlockJob(qemuMonitorPtr mon,
                            const char *diskAlias,
                            int type,
                            int status);
336 337
int qemuMonitorEmitBalloonChange(qemuMonitorPtr mon,
                                 unsigned long long actual);
338
int qemuMonitorEmitPMSuspendDisk(qemuMonitorPtr mon);
339
int qemuMonitorEmitGuestPanic(qemuMonitorPtr mon);
340 341
int qemuMonitorEmitDeviceDeleted(qemuMonitorPtr mon,
                                 const char *devAlias);
342 343
int qemuMonitorEmitNicRxFilterChanged(qemuMonitorPtr mon,
                                      const char *devAlias);
344 345 346
int qemuMonitorEmitSerialChange(qemuMonitorPtr mon,
                                const char *devAlias,
                                bool connected);
347
int qemuMonitorEmitSpiceMigrated(qemuMonitorPtr mon);
348 349
int qemuMonitorEmitMigrationStatus(qemuMonitorPtr mon,
                                   int status);
350 351
int qemuMonitorEmitMigrationPass(qemuMonitorPtr mon,
                                 int pass);
352

353 354 355 356 357 358 359
int qemuMonitorEmitAcpiOstInfo(qemuMonitorPtr mon,
                               const char *alias,
                               const char *slotType,
                               const char *slot,
                               unsigned int source,
                               unsigned int status);

360 361 362
int qemuMonitorStartCPUs(qemuMonitorPtr mon,
                         virConnectPtr conn);
int qemuMonitorStopCPUs(qemuMonitorPtr mon);
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377

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,
378
    QEMU_MONITOR_VM_STATUS_GUEST_PANICKED,
379 380 381 382 383 384

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

385
int qemuMonitorCheck(qemuMonitorPtr mon);
386 387
int qemuMonitorGetStatus(qemuMonitorPtr mon,
                         bool *running,
388 389
                         virDomainPausedReason *reason)
    ATTRIBUTE_NONNULL(2);
390

391
int qemuMonitorSystemReset(qemuMonitorPtr mon);
392 393
int qemuMonitorSystemPowerdown(qemuMonitorPtr mon);

394 395
struct qemuMonitorQueryCpusEntry {
    pid_t tid;
396
    char *qom_path;
397
    bool halted;
398 399 400 401
};
void qemuMonitorQueryCpusFree(struct qemuMonitorQueryCpusEntry *entries,
                              size_t nentries);

402

403 404 405 406 407 408 409 410 411 412 413
struct qemuMonitorQueryHotpluggableCpusEntry {
    char *type; /* name of the cpu to use with device_add */
    unsigned int vcpus; /* count of virtual cpus in the guest this entry adds */
    char *qom_path; /* full device qom path only present for online cpus */
    char *alias; /* device alias, may be NULL for non-hotpluggable entities */

    /* topology information -1 if qemu didn't report given parameter */
    int node_id;
    int socket_id;
    int core_id;
    int thread_id;
414 415 416

    /* internal data */
    int enable_id;
417 418 419 420 421
};
void qemuMonitorQueryHotpluggableCpusFree(struct qemuMonitorQueryHotpluggableCpusEntry *entries,
                                          size_t nentries);


422 423
struct _qemuMonitorCPUInfo {
    pid_t tid;
424 425
    int id; /* order of enabling of the given cpu */

426 427 428 429
    /* state data */
    bool online;
    bool hotpluggable;

430 431 432 433 434 435 436 437 438 439 440 441 442 443 444
    /* topology info for hotplug purposes. Hotplug of given vcpu impossible if
     * all entries are -1 */
    int socket_id;
    int core_id;
    int thread_id;
    unsigned int vcpus; /* number of vcpus added if given entry is hotplugged */

    /* name of the qemu type to add in case of hotplug */
    char *type;

    /* alias of an hotpluggable entry. Entries with alias can be hot-unplugged */
    char *alias;

    /* internal for use in the matching code */
    char *qom_path;
445 446

    bool halted;
447 448 449 450 451 452
};
typedef struct _qemuMonitorCPUInfo qemuMonitorCPUInfo;
typedef qemuMonitorCPUInfo *qemuMonitorCPUInfoPtr;

void qemuMonitorCPUInfoFree(qemuMonitorCPUInfoPtr list,
                            size_t nitems);
453
int qemuMonitorGetCPUInfo(qemuMonitorPtr mon,
454
                          qemuMonitorCPUInfoPtr *vcpus,
455 456
                          size_t maxvcpus,
                          bool hotplug);
457

458
int qemuMonitorGetVirtType(qemuMonitorPtr mon,
459
                           virDomainVirtType *virtType);
460
int qemuMonitorGetBalloonInfo(qemuMonitorPtr mon,
461
                              unsigned long long *currmem);
462
int qemuMonitorGetMemoryStats(qemuMonitorPtr mon,
463
                              virDomainMemballoonDefPtr balloon,
464 465
                              virDomainMemoryStatPtr stats,
                              unsigned int nr_stats);
466
int qemuMonitorSetMemoryStatsPeriod(qemuMonitorPtr mon,
467
                                    virDomainMemballoonDefPtr balloon,
468
                                    int period);
469

470
int qemuMonitorBlockIOStatusToError(const char *status);
471 472
virHashTablePtr qemuMonitorGetBlockInfo(qemuMonitorPtr mon);

473 474 475 476 477 478 479 480 481 482 483
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;
484 485
    unsigned long long capacity;
    unsigned long long physical;
486 487 488

    /* value of wr_highest_offset is valid if it's non 0 or
     * if wr_highest_offset_valid is true */
489
    unsigned long long wr_highest_offset;
490
    bool wr_highest_offset_valid;
491 492 493
};

int qemuMonitorGetAllBlockStatsInfo(qemuMonitorPtr mon,
494 495
                                    virHashTablePtr *ret_stats,
                                    bool backingChain)
496
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
497

498
int qemuMonitorBlockStatsUpdateCapacity(qemuMonitorPtr mon,
499 500
                                        virHashTablePtr stats,
                                        bool backingChain)
501 502
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);

503
int qemuMonitorBlockResize(qemuMonitorPtr mon,
504
                           const char *dev_name,
505
                           unsigned long long size);
506 507
int qemuMonitorSetVNCPassword(qemuMonitorPtr mon,
                              const char *password);
508 509 510 511 512 513 514
int qemuMonitorSetPassword(qemuMonitorPtr mon,
                           int type,
                           const char *password,
                           const char *action_if_connected);
int qemuMonitorExpirePassword(qemuMonitorPtr mon,
                              int type,
                              const char *expire_time);
515
int qemuMonitorSetBalloon(qemuMonitorPtr mon,
516
                          unsigned long long newmem);
517
int qemuMonitorSetCPU(qemuMonitorPtr mon, int cpu, bool online);
518

519 520

/* XXX should we pass the virDomainDiskDefPtr instead
521
 * and hide dev_name details inside monitor. Reconsider
522 523 524
 * this when doing the QMP implementation
 */
int qemuMonitorEjectMedia(qemuMonitorPtr mon,
525
                          const char *dev_name,
526
                          bool force);
527
int qemuMonitorChangeMedia(qemuMonitorPtr mon,
528
                           const char *dev_name,
529 530
                           const char *newmedia,
                           const char *format);
531 532 533 534 535 536 537 538 539 540 541 542 543 544


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

545 546 547
int qemuMonitorSetMigrationDowntime(qemuMonitorPtr mon,
                                    unsigned long long downtime);

548 549 550 551 552
int qemuMonitorGetMigrationCacheSize(qemuMonitorPtr mon,
                                     unsigned long long *cacheSize);
int qemuMonitorSetMigrationCacheSize(qemuMonitorPtr mon,
                                     unsigned long long cacheSize);

553 554 555 556 557 558 559 560 561 562 563
typedef struct _qemuMonitorMigrationParams qemuMonitorMigrationParams;
typedef qemuMonitorMigrationParams *qemuMonitorMigrationParamsPtr;
struct _qemuMonitorMigrationParams {
    bool compressLevel_set;
    int compressLevel;

    bool compressThreads_set;
    int compressThreads;

    bool decompressThreads_set;
    int decompressThreads;
564 565 566 567 568 569

    bool cpuThrottleInitial_set;
    int cpuThrottleInitial;

    bool cpuThrottleIncrement_set;
    int cpuThrottleIncrement;
570 571
};

572 573 574 575
int qemuMonitorGetMigrationParams(qemuMonitorPtr mon,
                                  qemuMonitorMigrationParamsPtr params);
int qemuMonitorSetMigrationParams(qemuMonitorPtr mon,
                                  qemuMonitorMigrationParamsPtr params);
576

577
typedef enum {
578
    QEMU_MONITOR_MIGRATION_STATUS_INACTIVE,
579
    QEMU_MONITOR_MIGRATION_STATUS_SETUP,
580
    QEMU_MONITOR_MIGRATION_STATUS_ACTIVE,
581
    QEMU_MONITOR_MIGRATION_STATUS_POSTCOPY,
582 583
    QEMU_MONITOR_MIGRATION_STATUS_COMPLETED,
    QEMU_MONITOR_MIGRATION_STATUS_ERROR,
584
    QEMU_MONITOR_MIGRATION_STATUS_CANCELLING,
585 586 587
    QEMU_MONITOR_MIGRATION_STATUS_CANCELLED,

    QEMU_MONITOR_MIGRATION_STATUS_LAST
588
} qemuMonitorMigrationStatus;
589

590 591
VIR_ENUM_DECL(qemuMonitorMigrationStatus)

592 593 594
typedef struct _qemuMonitorMigrationStats qemuMonitorMigrationStats;
typedef qemuMonitorMigrationStats *qemuMonitorMigrationStatsPtr;
struct _qemuMonitorMigrationStats {
595
    int status; /* qemuMonitorMigrationStatus */
596 597 598 599
    unsigned long long total_time;
    /* total or expected depending on status */
    bool downtime_set;
    unsigned long long downtime;
600 601 602 603 604 605 606
    /*
     * 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;
607 608 609 610

    unsigned long long ram_transferred;
    unsigned long long ram_remaining;
    unsigned long long ram_total;
611
    unsigned long long ram_bps;
612 613 614 615
    bool ram_duplicate_set;
    unsigned long long ram_duplicate;
    unsigned long long ram_normal;
    unsigned long long ram_normal_bytes;
616 617
    unsigned long long ram_dirty_rate;
    unsigned long long ram_iteration;
618 619 620 621

    unsigned long long disk_transferred;
    unsigned long long disk_remaining;
    unsigned long long disk_total;
622
    unsigned long long disk_bps;
623 624 625 626 627 628 629

    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;
630 631

    int cpu_throttle_percentage;
632 633
};

634 635
int qemuMonitorGetMigrationStats(qemuMonitorPtr mon,
                                 qemuMonitorMigrationStatsPtr stats);
636

637 638
typedef enum {
    QEMU_MONITOR_MIGRATION_CAPS_XBZRLE,
639
    QEMU_MONITOR_MIGRATION_CAPS_AUTO_CONVERGE,
640
    QEMU_MONITOR_MIGRATION_CAPS_RDMA_PIN_ALL,
641
    QEMU_MONITOR_MIGRATION_CAPS_EVENTS,
642
    QEMU_MONITOR_MIGRATION_CAPS_POSTCOPY,
643
    QEMU_MONITOR_MIGRATION_CAPS_COMPRESS,
644 645 646 647 648 649

    QEMU_MONITOR_MIGRATION_CAPS_LAST
} qemuMonitorMigrationCaps;

VIR_ENUM_DECL(qemuMonitorMigrationCaps);

650 651
int qemuMonitorGetMigrationCapabilities(qemuMonitorPtr mon,
                                        char ***capabilities);
652 653 654
int qemuMonitorGetMigrationCapability(qemuMonitorPtr mon,
                                      qemuMonitorMigrationCaps capability);
int qemuMonitorSetMigrationCapability(qemuMonitorPtr mon,
655 656
                                      qemuMonitorMigrationCaps capability,
                                      bool state);
657

A
Andrea Bolognani 已提交
658 659 660
int qemuMonitorGetGICCapabilities(qemuMonitorPtr mon,
                                  virGICCapability **capabilities);

661
typedef enum {
E
Eric Blake 已提交
662
  QEMU_MONITOR_MIGRATE_BACKGROUND	= 1 << 0,
663 664 665 666 667
  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 已提交
668 669 670 671
int qemuMonitorMigrateToFd(qemuMonitorPtr mon,
                           unsigned int flags,
                           int fd);

672
int qemuMonitorMigrateToHost(qemuMonitorPtr mon,
673
                             unsigned int flags,
674
                             const char *protocol,
675 676 677 678
                             const char *hostname,
                             int port);

int qemuMonitorMigrateToCommand(qemuMonitorPtr mon,
679
                                unsigned int flags,
680 681
                                const char * const *argv);

682
int qemuMonitorMigrateToUnix(qemuMonitorPtr mon,
683
                             unsigned int flags,
684 685 686 687
                             const char *unixfile);

int qemuMonitorMigrateCancel(qemuMonitorPtr mon);

688 689 690
int qemuMonitorGetDumpGuestMemoryCapability(qemuMonitorPtr mon,
                                            const char *capability);

691
int qemuMonitorDumpToFd(qemuMonitorPtr mon,
692 693
                        int fd,
                        const char *dumpformat);
694

695 696 697 698 699 700
int qemuMonitorGraphicsRelocate(qemuMonitorPtr mon,
                                int type,
                                const char *hostname,
                                int port,
                                int tlsPort,
                                const char *tlsSubject);
701 702 703 704

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

707 708
/* These two functions preserve previous error and only set their own
 * error if no error was set before.
709
 */
710 711
int qemuMonitorCloseFileHandle(qemuMonitorPtr mon,
                               const char *fdname);
712
int qemuMonitorRemoveFd(qemuMonitorPtr mon, int fdset, int fd);
713 714 715 716 717

/* XXX do we really want to hardcode 'netstr' as the
 * sendable item here
 */
int qemuMonitorAddHostNetwork(qemuMonitorPtr mon,
718
                              const char *netstr,
719 720
                              int *tapfd, char **tapfdName, int tapfdSize,
                              int *vhostfd, char **vhostfdName, int vhostfdSize);
721 722 723 724 725

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

726
int qemuMonitorAddNetdev(qemuMonitorPtr mon,
727
                         const char *netdevstr,
728 729
                         int *tapfd, char **tapfdName, int tapfdSize,
                         int *vhostfd, char **vhostfdName, int vhostfdSize);
730 731 732 733

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

734 735 736
int qemuMonitorQueryRxFilter(qemuMonitorPtr mon, const char *alias,
                             virNetDevRxFilterPtr *filter);

737 738 739 740 741 742
typedef struct _qemuMonitorChardevInfo qemuMonitorChardevInfo;
typedef qemuMonitorChardevInfo *qemuMonitorChardevInfoPtr;
struct _qemuMonitorChardevInfo {
    char *ptyPath;
    virDomainChrDeviceState state;
};
743
void qemuMonitorChardevInfoFree(void *data, const void *name);
744 745
int qemuMonitorGetChardevInfo(qemuMonitorPtr mon,
                              virHashTablePtr *retinfo);
746

747 748
int qemuMonitorAttachPCIDiskController(qemuMonitorPtr mon,
                                       const char *bus,
749
                                       virPCIDeviceAddress *guestAddr);
750

751 752
int qemuMonitorAddDeviceArgs(qemuMonitorPtr mon,
                             virJSONValuePtr args);
753 754 755
int qemuMonitorAddDevice(qemuMonitorPtr mon,
                         const char *devicestr);

756 757 758 759 760
int qemuMonitorAddDeviceWithFd(qemuMonitorPtr mon,
                               const char *devicestr,
                               int fd,
                               const char *fdname);

761
int qemuMonitorDelDevice(qemuMonitorPtr mon,
762
                         const char *devalias);
763

764 765 766 767 768 769 770 771
int qemuMonitorAddObject(qemuMonitorPtr mon,
                         const char *type,
                         const char *objalias,
                         virJSONValuePtr props);

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

772 773 774
int qemuMonitorAddDrive(qemuMonitorPtr mon,
                        const char *drivestr);

775
int qemuMonitorDriveDel(qemuMonitorPtr mon,
776 777
                        const char *drivestr);

778 779 780 781
int qemuMonitorSetDrivePassphrase(qemuMonitorPtr mon,
                                  const char *alias,
                                  const char *passphrase);

C
Chris Lalancette 已提交
782 783 784 785
int qemuMonitorCreateSnapshot(qemuMonitorPtr mon, const char *name);
int qemuMonitorLoadSnapshot(qemuMonitorPtr mon, const char *name);
int qemuMonitorDeleteSnapshot(qemuMonitorPtr mon, const char *name);

786
int qemuMonitorDiskSnapshot(qemuMonitorPtr mon,
787
                            virJSONValuePtr actions,
788
                            const char *device,
789 790 791
                            const char *file,
                            const char *format,
                            bool reuse);
792
int qemuMonitorTransaction(qemuMonitorPtr mon, virJSONValuePtr actions)
793
    ATTRIBUTE_NONNULL(2);
794 795 796 797
int qemuMonitorDriveMirror(qemuMonitorPtr mon,
                           const char *device,
                           const char *file,
                           const char *format,
798
                           unsigned long long bandwidth,
799 800
                           unsigned int granularity,
                           unsigned long long buf_size,
801
                           unsigned int flags)
802
    ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
803
int qemuMonitorDrivePivot(qemuMonitorPtr mon,
804
                          const char *device)
805
    ATTRIBUTE_NONNULL(2);
806

807 808 809 810
int qemuMonitorBlockCommit(qemuMonitorPtr mon,
                           const char *device,
                           const char *top,
                           const char *base,
811
                           const char *backingName,
812
                           unsigned long long bandwidth)
813
    ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);
814
bool qemuMonitorSupportsActiveCommit(qemuMonitorPtr mon);
815 816 817 818
char *qemuMonitorDiskNameLookup(qemuMonitorPtr mon,
                                const char *device,
                                virStorageSourcePtr top,
                                virStorageSourcePtr target)
819
    ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);
820

821 822 823 824
int qemuMonitorArbitraryCommand(qemuMonitorPtr mon,
                                const char *cmd,
                                char **reply,
                                bool hmp);
825

826 827
int qemuMonitorInjectNMI(qemuMonitorPtr mon);

828 829 830
int qemuMonitorScreendump(qemuMonitorPtr mon,
                          const char *file);

831 832 833 834 835
int qemuMonitorSendKey(qemuMonitorPtr mon,
                       unsigned int holdtime,
                       unsigned int *keycodes,
                       unsigned int nkeycodes);

836 837 838 839 840 841
int qemuMonitorBlockStream(qemuMonitorPtr mon,
                           const char *device,
                           const char *base,
                           const char *backingName,
                           unsigned long long bandwidth,
                           bool modern)
842
    ATTRIBUTE_NONNULL(2);
843

844 845 846
int qemuMonitorBlockJobCancel(qemuMonitorPtr mon,
                              const char *device,
                              bool modern)
847
    ATTRIBUTE_NONNULL(2);
848

849 850 851 852 853
int qemuMonitorBlockJobSetSpeed(qemuMonitorPtr mon,
                                const char *device,
                                unsigned long long bandwidth,
                                bool modern);

854 855 856 857 858 859 860
typedef struct _qemuMonitorBlockJobInfo qemuMonitorBlockJobInfo;
typedef qemuMonitorBlockJobInfo *qemuMonitorBlockJobInfoPtr;
struct _qemuMonitorBlockJobInfo {
    int type; /* virDomainBlockJobType */
    unsigned long long bandwidth; /* in bytes/s */
    virDomainBlockJobCursor cur;
    virDomainBlockJobCursor end;
861
    int ready; /* -1 if unknown, 0 if not ready, 1 if ready */
862 863 864 865 866 867
};

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

870 871 872 873 874 875
int qemuMonitorOpenGraphics(qemuMonitorPtr mon,
                            const char *protocol,
                            int fd,
                            const char *fdname,
                            bool skipauth);

876 877
int qemuMonitorSetBlockIoThrottle(qemuMonitorPtr mon,
                                  const char *device,
878
                                  virDomainBlockIoTuneInfoPtr info,
879 880
                                  bool supportMaxOptions,
                                  bool supportMaxLengthOptions);
881 882 883

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

886 887
int qemuMonitorSystemWakeup(qemuMonitorPtr mon);

888 889 890 891 892 893 894
int qemuMonitorGetVersion(qemuMonitorPtr mon,
                          int *major,
                          int *minor,
                          int *micro,
                          char **package)
    ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);

895 896 897 898 899 900 901 902

typedef struct _qemuMonitorMachineInfo qemuMonitorMachineInfo;
typedef qemuMonitorMachineInfo *qemuMonitorMachineInfoPtr;

struct _qemuMonitorMachineInfo {
    char *name;
    bool isDefault;
    char *alias;
903
    unsigned int maxCpus;
904
    bool hotplugCpus;
905 906 907 908 909 910 911
};

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

void qemuMonitorMachineInfoFree(qemuMonitorMachineInfoPtr machine);

912 913 914 915 916 917 918
typedef struct _qemuMonitorCPUDefInfo qemuMonitorCPUDefInfo;
typedef qemuMonitorCPUDefInfo *qemuMonitorCPUDefInfoPtr;

struct _qemuMonitorCPUDefInfo {
    char *name;
};

919
int qemuMonitorGetCPUDefinitions(qemuMonitorPtr mon,
920 921
                                 qemuMonitorCPUDefInfoPtr **cpus);
void qemuMonitorCPUDefInfoFree(qemuMonitorCPUDefInfoPtr cpu);
922

923 924
int qemuMonitorGetCommands(qemuMonitorPtr mon,
                           char ***commands);
925 926
int qemuMonitorGetEvents(qemuMonitorPtr mon,
                         char ***events);
927 928
int qemuMonitorGetCommandLineOptionParameters(qemuMonitorPtr mon,
                                              const char *option,
929 930
                                              char ***params,
                                              bool *found);
931

932 933 934 935
int qemuMonitorGetKVMState(qemuMonitorPtr mon,
                           bool *enabled,
                           bool *present);

936 937
int qemuMonitorGetObjectTypes(qemuMonitorPtr mon,
                              char ***types);
938 939 940
int qemuMonitorGetObjectProps(qemuMonitorPtr mon,
                              const char *type,
                              char ***props);
941
char *qemuMonitorGetTargetArch(qemuMonitorPtr mon);
942

943 944 945
int qemuMonitorNBDServerStart(qemuMonitorPtr mon,
                              const char *host,
                              unsigned int port);
946 947 948
int qemuMonitorNBDServerAdd(qemuMonitorPtr mon,
                            const char *deviceID,
                            bool writable);
949
int qemuMonitorNBDServerStop(qemuMonitorPtr);
S
Stefan Berger 已提交
950 951 952 953 954 955
int qemuMonitorGetTPMModels(qemuMonitorPtr mon,
                            char ***tpmmodels);

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

956 957 958
int qemuMonitorAttachCharDev(qemuMonitorPtr mon,
                             const char *chrID,
                             virDomainChrSourceDefPtr chr);
959 960
int qemuMonitorDetachCharDev(qemuMonitorPtr mon,
                             const char *chrID);
961 962 963 964

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

965 966 967 968 969 970 971
typedef void (*qemuMonitorReportDomainLogError)(qemuMonitorPtr mon,
                                                const char *msg,
                                                void *opaque);
void qemuMonitorSetDomainLog(qemuMonitorPtr mon,
                             qemuMonitorReportDomainLogError func,
                             void *opaque,
                             virFreeCallback destroy);
972

973 974 975
int qemuMonitorGetGuestCPU(qemuMonitorPtr mon,
                           virArch arch,
                           virCPUDataPtr *data);
976

977 978
int qemuMonitorRTCResetReinjection(qemuMonitorPtr mon);

979 980
typedef struct _qemuMonitorIOThreadInfo qemuMonitorIOThreadInfo;
typedef qemuMonitorIOThreadInfo *qemuMonitorIOThreadInfoPtr;
981

982
struct _qemuMonitorIOThreadInfo {
983
    unsigned int iothread_id;
984 985 986
    int thread_id;
};
int qemuMonitorGetIOThreads(qemuMonitorPtr mon,
987
                            qemuMonitorIOThreadInfoPtr **iothreads);
988

989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002
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);

1003 1004 1005
int qemuMonitorMigrateIncoming(qemuMonitorPtr mon,
                               const char *uri);

1006 1007
int qemuMonitorMigrateStartPostCopy(qemuMonitorPtr mon);

1008 1009 1010
int qemuMonitorGetRTCTime(qemuMonitorPtr mon,
                          struct tm *tm);

1011 1012
virHashTablePtr qemuMonitorQueryQMPSchema(qemuMonitorPtr mon);

1013
#endif /* QEMU_MONITOR_H */