qemu_monitor.h 18.6 KB
Newer Older
1 2 3
/*
 * qemu_monitor.h: interaction with QEMU monitor console
 *
4
 * Copyright (C) 2006-2011 Red Hat, Inc.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 * Copyright (C) 2006 Daniel P. Berrange
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 *
 * Author: Daniel P. Berrange <berrange@redhat.com>
 */


#ifndef QEMU_MONITOR_H
26
# define QEMU_MONITOR_H
27

28
# include "internal.h"
29

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

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

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

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

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

    qemuMonitorPasswordHandler passwordHandler;
    void *passwordOpaque;
};

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

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

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

127

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

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

136
void qemuMonitorClose(qemuMonitorPtr mon);
137

138 139
int qemuMonitorSetCapabilities(qemuMonitorPtr mon);

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

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

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

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

159
/* XXX same comment about virConnectPtr as above */
160 161 162 163 164
int qemuMonitorGetDiskSecret(qemuMonitorPtr mon,
                             virConnectPtr conn,
                             const char *path,
                             char **secret,
                             size_t *secretLen);
165

166 167 168 169
int qemuMonitorEmitShutdown(qemuMonitorPtr mon);
int qemuMonitorEmitReset(qemuMonitorPtr mon);
int qemuMonitorEmitPowerdown(qemuMonitorPtr mon);
int qemuMonitorEmitStop(qemuMonitorPtr mon);
170
int qemuMonitorEmitRTCChange(qemuMonitorPtr mon, long long offset);
171
int qemuMonitorEmitWatchdog(qemuMonitorPtr mon, int action);
172 173
int qemuMonitorEmitIOError(qemuMonitorPtr mon,
                           const char *diskAlias,
174 175
                           int action,
                           const char *reason);
176 177 178 179 180 181 182 183 184 185 186
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);
187 188 189 190 191
int qemuMonitorEmitBlockJob(qemuMonitorPtr mon,
                            const char *diskAlias,
                            int type,
                            int status);

192

193 194 195 196

int qemuMonitorStartCPUs(qemuMonitorPtr mon,
                         virConnectPtr conn);
int qemuMonitorStopCPUs(qemuMonitorPtr mon);
197
int qemuMonitorGetStatus(qemuMonitorPtr mon, bool *running);
198

199
int qemuMonitorSystemReset(qemuMonitorPtr mon);
200 201 202 203
int qemuMonitorSystemPowerdown(qemuMonitorPtr mon);

int qemuMonitorGetCPUInfo(qemuMonitorPtr mon,
                          int **pids);
204 205
int qemuMonitorGetVirtType(qemuMonitorPtr mon,
                           int *virtType);
206 207
int qemuMonitorGetBalloonInfo(qemuMonitorPtr mon,
                              unsigned long *currmem);
208 209 210
int qemuMonitorGetMemoryStats(qemuMonitorPtr mon,
                              virDomainMemoryStatPtr stats,
                              unsigned int nr_stats);
211 212 213 214
int qemuMonitorGetBlockStatsInfo(qemuMonitorPtr mon,
                                 const char *devname,
                                 long long *rd_req,
                                 long long *rd_bytes,
215
                                 long long *rd_total_times,
216 217
                                 long long *wr_req,
                                 long long *wr_bytes,
218 219 220
                                 long long *wr_total_times,
                                 long long *flush_req,
                                 long long *flush_total_times,
221
                                 long long *errs);
222 223
int qemuMonitorGetBlockStatsParamsNumber(qemuMonitorPtr mon,
                                         int *nparams);
224

225 226 227 228
int qemuMonitorGetBlockExtent(qemuMonitorPtr mon,
                              const char *devname,
                              unsigned long long *extent);

229 230 231

int qemuMonitorSetVNCPassword(qemuMonitorPtr mon,
                              const char *password);
232 233 234 235 236 237 238
int qemuMonitorSetPassword(qemuMonitorPtr mon,
                           int type,
                           const char *password,
                           const char *action_if_connected);
int qemuMonitorExpirePassword(qemuMonitorPtr mon,
                              int type,
                              const char *expire_time);
239 240
int qemuMonitorSetBalloon(qemuMonitorPtr mon,
                          unsigned long newmem);
241 242
int qemuMonitorSetCPU(qemuMonitorPtr mon, int cpu, int online);

243 244 245 246 247 248

/* XXX should we pass the virDomainDiskDefPtr instead
 * and hide devname details inside monitor. Reconsider
 * this when doing the QMP implementation
 */
int qemuMonitorEjectMedia(qemuMonitorPtr mon,
249 250
                          const char *devname,
                          bool force);
251 252
int qemuMonitorChangeMedia(qemuMonitorPtr mon,
                           const char *devname,
253 254
                           const char *newmedia,
                           const char *format);
255 256 257 258 259 260 261 262 263 264 265 266 267 268


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

269 270 271
int qemuMonitorSetMigrationDowntime(qemuMonitorPtr mon,
                                    unsigned long long downtime);

272 273 274 275 276 277 278 279 280 281
enum {
    QEMU_MONITOR_MIGRATION_STATUS_INACTIVE,
    QEMU_MONITOR_MIGRATION_STATUS_ACTIVE,
    QEMU_MONITOR_MIGRATION_STATUS_COMPLETED,
    QEMU_MONITOR_MIGRATION_STATUS_ERROR,
    QEMU_MONITOR_MIGRATION_STATUS_CANCELLED,

    QEMU_MONITOR_MIGRATION_STATUS_LAST
};

282 283
VIR_ENUM_DECL(qemuMonitorMigrationStatus)

284 285 286 287 288 289
int qemuMonitorGetMigrationStatus(qemuMonitorPtr mon,
                                  int *status,
                                  unsigned long long *transferred,
                                  unsigned long long *remaining,
                                  unsigned long long *total);

290
typedef enum {
E
Eric Blake 已提交
291
  QEMU_MONITOR_MIGRATE_BACKGROUND	= 1 << 0,
292 293 294 295 296
  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 已提交
297 298 299 300
int qemuMonitorMigrateToFd(qemuMonitorPtr mon,
                           unsigned int flags,
                           int fd);

301
int qemuMonitorMigrateToHost(qemuMonitorPtr mon,
302
                             unsigned int flags,
303 304 305 306
                             const char *hostname,
                             int port);

int qemuMonitorMigrateToCommand(qemuMonitorPtr mon,
307
                                unsigned int flags,
308 309
                                const char * const *argv);

310 311 312 313 314 315 316
/* 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.
317
 */
318 319
# define QEMU_MONITOR_MIGRATE_TO_FILE_BS (1024llu * 4)
# define QEMU_MONITOR_MIGRATE_TO_FILE_TRANSFER_SIZE (1024llu * 1024)
320 321

int qemuMonitorMigrateToFile(qemuMonitorPtr mon,
322
                             unsigned int flags,
323 324 325
                             const char * const *argv,
                             const char *target,
                             unsigned long long offset);
326 327

int qemuMonitorMigrateToUnix(qemuMonitorPtr mon,
328
                             unsigned int flags,
329 330 331 332
                             const char *unixfile);

int qemuMonitorMigrateCancel(qemuMonitorPtr mon);

333 334 335 336 337 338
int qemuMonitorGraphicsRelocate(qemuMonitorPtr mon,
                                int type,
                                const char *hostname,
                                int port,
                                int tlsPort,
                                const char *tlsSubject);
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354

/* 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,
355 356
                                virDomainDevicePCIAddress *hostAddr,
                                virDomainDevicePCIAddress *guestAddr);
357 358 359 360 361 362 363

/* XXX disk driver type eg,  qcow/etc.
 * XXX cache mode
 */
int qemuMonitorAddPCIDisk(qemuMonitorPtr mon,
                          const char *path,
                          const char *bus,
364
                          virDomainDevicePCIAddress *guestAddr);
365 366 367 368 369 370

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

int qemuMonitorRemovePCIDevice(qemuMonitorPtr mon,
374
                               virDomainDevicePCIAddress *guestAddr);
375 376 377 378 379 380


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

381 382 383
/* The function preserves previous error and only sets it's own error if no
 * error was set before.
 */
384 385 386 387 388 389 390 391
int qemuMonitorCloseFileHandle(qemuMonitorPtr mon,
                               const char *fdname);


/* XXX do we really want to hardcode 'netstr' as the
 * sendable item here
 */
int qemuMonitorAddHostNetwork(qemuMonitorPtr mon,
392 393 394
                              const char *netstr,
                              int tapfd, const char *tapfd_name,
                              int vhostfd, const char *vhostfd_name);
395 396 397 398 399

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

400
int qemuMonitorAddNetdev(qemuMonitorPtr mon,
401 402 403
                         const char *netdevstr,
                         int tapfd, const char *tapfd_name,
                         int vhostfd, const char *vhostfd_name);
404 405 406 407

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

408 409
int qemuMonitorGetPtyPaths(qemuMonitorPtr mon,
                           virHashTablePtr paths);
410

411 412 413 414
int qemuMonitorAttachPCIDiskController(qemuMonitorPtr mon,
                                       const char *bus,
                                       virDomainDevicePCIAddress *guestAddr);

415 416 417 418 419
int qemuMonitorAttachDrive(qemuMonitorPtr mon,
                           const char *drivestr,
                           virDomainDevicePCIAddress *controllerAddr,
                           virDomainDeviceDriveAddress *driveAddr);

420 421 422 423 424 425 426 427 428 429 430

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

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

431 432 433
int qemuMonitorAddDevice(qemuMonitorPtr mon,
                         const char *devicestr);

434 435 436 437 438
int qemuMonitorAddDeviceWithFd(qemuMonitorPtr mon,
                               const char *devicestr,
                               int fd,
                               const char *fdname);

439
int qemuMonitorDelDevice(qemuMonitorPtr mon,
440
                         const char *devalias);
441

442 443 444
int qemuMonitorAddDrive(qemuMonitorPtr mon,
                        const char *drivestr);

445
int qemuMonitorDriveDel(qemuMonitorPtr mon,
446 447
                        const char *drivestr);

448 449 450 451
int qemuMonitorSetDrivePassphrase(qemuMonitorPtr mon,
                                  const char *alias,
                                  const char *passphrase);

C
Chris Lalancette 已提交
452 453 454 455
int qemuMonitorCreateSnapshot(qemuMonitorPtr mon, const char *name);
int qemuMonitorLoadSnapshot(qemuMonitorPtr mon, const char *name);
int qemuMonitorDeleteSnapshot(qemuMonitorPtr mon, const char *name);

456 457 458 459
int qemuMonitorDiskSnapshot(qemuMonitorPtr mon,
                            const char *device,
                            const char *file);

460 461 462 463
int qemuMonitorArbitraryCommand(qemuMonitorPtr mon,
                                const char *cmd,
                                char **reply,
                                bool hmp);
464

465 466
int qemuMonitorInjectNMI(qemuMonitorPtr mon);

467 468 469
int qemuMonitorScreendump(qemuMonitorPtr mon,
                          const char *file);

470 471 472 473 474
int qemuMonitorSendKey(qemuMonitorPtr mon,
                       unsigned int holdtime,
                       unsigned int *keycodes,
                       unsigned int nkeycodes);

475 476 477 478 479 480 481 482 483 484 485 486 487
typedef enum {
    BLOCK_JOB_ABORT = 0,
    BLOCK_JOB_INFO = 1,
    BLOCK_JOB_SPEED = 2,
    BLOCK_JOB_PULL = 3,
} BLOCK_JOB_CMD;

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

488 489 490 491 492 493 494 495 496 497 498 499 500
/**
 * 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

501
#endif /* QEMU_MONITOR_H */