Fix QEMU memory stats JSON mode
[libvirt.git] / src / qemu / qemu_monitor.h
1 /*
2  * qemu_monitor.h: interaction with QEMU monitor console
3  *
4  * Copyright (C) 2006-2009 Red Hat, Inc.
5  * Copyright (C) 2006 Daniel P. Berrange
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
20  *
21  * Author: Daniel P. Berrange <berrange@redhat.com>
22  */
23
24
25 #ifndef QEMU_MONITOR_H
26 # define QEMU_MONITOR_H
27
28 # include "internal.h"
29
30 # include "domain_conf.h"
31 # include "hash.h"
32
33 typedef struct _qemuMonitor qemuMonitor;
34 typedef qemuMonitor *qemuMonitorPtr;
35
36 typedef struct _qemuMonitorMessage qemuMonitorMessage;
37 typedef qemuMonitorMessage *qemuMonitorMessagePtr;
38
39 typedef int (*qemuMonitorPasswordHandler)(qemuMonitorPtr mon,
40                                           qemuMonitorMessagePtr msg,
41                                           const char *data,
42                                           size_t len,
43                                           void *opaque);
44
45 struct _qemuMonitorMessage {
46     int txFD;
47
48     char *txBuffer;
49     int txOffset;
50     int txLength;
51
52     char *rxBuffer;
53     int rxLength;
54
55     int finished;
56
57     int lastErrno;
58
59     qemuMonitorPasswordHandler passwordHandler;
60     void *passwordOpaque;
61 };
62
63 typedef struct _qemuMonitorCallbacks qemuMonitorCallbacks;
64 typedef qemuMonitorCallbacks *qemuMonitorCallbacksPtr;
65 struct _qemuMonitorCallbacks {
66     void (*eofNotify)(qemuMonitorPtr mon,
67                       virDomainObjPtr vm,
68                       int withError);
69     /* XXX we'd really like to avoid virCOnnectPtr here
70      * It is required so the callback can find the active
71      * secret driver. Need to change this to work like the
72      * security drivers do, to avoid this
73      */
74     int (*diskSecretLookup)(qemuMonitorPtr mon,
75                             virConnectPtr conn,
76                             virDomainObjPtr vm,
77                             const char *path,
78                             char **secret,
79                             size_t *secretLen);
80
81     int (*domainShutdown)(qemuMonitorPtr mon,
82                           virDomainObjPtr vm);
83     int (*domainReset)(qemuMonitorPtr mon,
84                        virDomainObjPtr vm);
85     int (*domainPowerdown)(qemuMonitorPtr mon,
86                            virDomainObjPtr vm);
87     int (*domainStop)(qemuMonitorPtr mon,
88                       virDomainObjPtr vm);
89     int (*domainRTCChange)(qemuMonitorPtr mon,
90                            virDomainObjPtr vm,
91                            long long offset);
92     int (*domainWatchdog)(qemuMonitorPtr mon,
93                           virDomainObjPtr vm,
94                           int action);
95     int (*domainIOError)(qemuMonitorPtr mon,
96                          virDomainObjPtr vm,
97                          const char *diskAlias,
98                          int action);
99     int (*domainGraphics)(qemuMonitorPtr mon,
100                           virDomainObjPtr vm,
101                           int phase,
102                           int localFamily,
103                           const char *localNode,
104                           const char *localService,
105                           int remoteFamily,
106                           const char *remoteNode,
107                           const char *remoteService,
108                           const char *authScheme,
109                           const char *x509dname,
110                           const char *saslUsername);
111 };
112
113
114 char *qemuMonitorEscapeArg(const char *in);
115 char *qemuMonitorEscapeShell(const char *in);
116
117 qemuMonitorPtr qemuMonitorOpen(virDomainObjPtr vm,
118                                virDomainChrDefPtr config,
119                                int json,
120                                qemuMonitorCallbacksPtr cb);
121
122 int qemuMonitorClose(qemuMonitorPtr mon);
123
124 int qemuMonitorSetCapabilities(qemuMonitorPtr mon);
125
126 void qemuMonitorLock(qemuMonitorPtr mon);
127 void qemuMonitorUnlock(qemuMonitorPtr mon);
128
129 int qemuMonitorRef(qemuMonitorPtr mon);
130 int qemuMonitorUnref(qemuMonitorPtr mon);
131
132 /* This API is for use by the internal Text/JSON monitor impl code only */
133 int qemuMonitorSend(qemuMonitorPtr mon,
134                     qemuMonitorMessagePtr msg);
135
136 /* XXX same comment about virConnectPtr as above */
137 int qemuMonitorGetDiskSecret(qemuMonitorPtr mon,
138                              virConnectPtr conn,
139                              const char *path,
140                              char **secret,
141                              size_t *secretLen);
142
143 int qemuMonitorEmitShutdown(qemuMonitorPtr mon);
144 int qemuMonitorEmitReset(qemuMonitorPtr mon);
145 int qemuMonitorEmitPowerdown(qemuMonitorPtr mon);
146 int qemuMonitorEmitStop(qemuMonitorPtr mon);
147 int qemuMonitorEmitRTCChange(qemuMonitorPtr mon, long long offset);
148 int qemuMonitorEmitWatchdog(qemuMonitorPtr mon, int action);
149 int qemuMonitorEmitIOError(qemuMonitorPtr mon,
150                            const char *diskAlias,
151                            int action);
152 int qemuMonitorEmitGraphics(qemuMonitorPtr mon,
153                             int phase,
154                             int localFamily,
155                             const char *localNode,
156                             const char *localService,
157                             int remoteFamily,
158                             const char *remoteNode,
159                             const char *remoteService,
160                             const char *authScheme,
161                             const char *x509dname,
162                             const char *saslUsername);
163
164
165 int qemuMonitorStartCPUs(qemuMonitorPtr mon,
166                          virConnectPtr conn);
167 int qemuMonitorStopCPUs(qemuMonitorPtr mon);
168
169 int qemuMonitorSystemPowerdown(qemuMonitorPtr mon);
170
171 int qemuMonitorGetCPUInfo(qemuMonitorPtr mon,
172                           int **pids);
173 int qemuMonitorGetBalloonInfo(qemuMonitorPtr mon,
174                               unsigned long *currmem);
175 int qemuMonitorGetMemoryStats(qemuMonitorPtr mon,
176                               virDomainMemoryStatPtr stats,
177                               unsigned int nr_stats);
178 int qemuMonitorGetBlockStatsInfo(qemuMonitorPtr mon,
179                                  const char *devname,
180                                  long long *rd_req,
181                                  long long *rd_bytes,
182                                  long long *wr_req,
183                                  long long *wr_bytes,
184                                  long long *errs);
185
186
187 int qemuMonitorSetVNCPassword(qemuMonitorPtr mon,
188                               const char *password);
189 int qemuMonitorSetBalloon(qemuMonitorPtr mon,
190                           unsigned long newmem);
191 int qemuMonitorSetCPU(qemuMonitorPtr mon, int cpu, int online);
192
193
194 /* XXX should we pass the virDomainDiskDefPtr instead
195  * and hide devname details inside monitor. Reconsider
196  * this when doing the QMP implementation
197  *
198  * XXXX 'eject' has gained a 'force' flag we might like
199  * to make use of...
200  */
201 int qemuMonitorEjectMedia(qemuMonitorPtr mon,
202                           const char *devname);
203 int qemuMonitorChangeMedia(qemuMonitorPtr mon,
204                            const char *devname,
205                            const char *newmedia,
206                            const char *format);
207
208
209 int qemuMonitorSaveVirtualMemory(qemuMonitorPtr mon,
210                                  unsigned long long offset,
211                                  size_t length,
212                                  const char *path);
213 int qemuMonitorSavePhysicalMemory(qemuMonitorPtr mon,
214                                   unsigned long long offset,
215                                   size_t length,
216                                   const char *path);
217
218 int qemuMonitorSetMigrationSpeed(qemuMonitorPtr mon,
219                                  unsigned long bandwidth);
220
221 int qemuMonitorSetMigrationDowntime(qemuMonitorPtr mon,
222                                     unsigned long long downtime);
223
224 enum {
225     QEMU_MONITOR_MIGRATION_STATUS_INACTIVE,
226     QEMU_MONITOR_MIGRATION_STATUS_ACTIVE,
227     QEMU_MONITOR_MIGRATION_STATUS_COMPLETED,
228     QEMU_MONITOR_MIGRATION_STATUS_ERROR,
229     QEMU_MONITOR_MIGRATION_STATUS_CANCELLED,
230
231     QEMU_MONITOR_MIGRATION_STATUS_LAST
232 };
233
234 VIR_ENUM_DECL(qemuMonitorMigrationStatus)
235
236 int qemuMonitorGetMigrationStatus(qemuMonitorPtr mon,
237                                   int *status,
238                                   unsigned long long *transferred,
239                                   unsigned long long *remaining,
240                                   unsigned long long *total);
241
242 int qemuMonitorMigrateToHost(qemuMonitorPtr mon,
243                              int background,
244                              const char *hostname,
245                              int port);
246
247 int qemuMonitorMigrateToCommand(qemuMonitorPtr mon,
248                                 int background,
249                                 const char * const *argv,
250                                 const char *target);
251
252 int qemuMonitorMigrateToUnix(qemuMonitorPtr mon,
253                              int background,
254                              const char *unixfile);
255
256 int qemuMonitorMigrateCancel(qemuMonitorPtr mon);
257
258
259 /* XXX disk driver type eg,  qcow/etc.
260  * XXX cache mode
261  */
262 int qemuMonitorAddUSBDisk(qemuMonitorPtr mon,
263                           const char *path);
264
265 int qemuMonitorAddUSBDeviceExact(qemuMonitorPtr mon,
266                                  int bus,
267                                  int dev);
268 int qemuMonitorAddUSBDeviceMatch(qemuMonitorPtr mon,
269                                  int vendor,
270                                  int product);
271
272
273 int qemuMonitorAddPCIHostDevice(qemuMonitorPtr mon,
274                                 virDomainDevicePCIAddress *hostAddr,
275                                 virDomainDevicePCIAddress *guestAddr);
276
277 /* XXX disk driver type eg,  qcow/etc.
278  * XXX cache mode
279  */
280 int qemuMonitorAddPCIDisk(qemuMonitorPtr mon,
281                           const char *path,
282                           const char *bus,
283                           virDomainDevicePCIAddress *guestAddr);
284
285 /* XXX do we really want to hardcode 'nicstr' as the
286  * sendable item here
287  */
288 int qemuMonitorAddPCINetwork(qemuMonitorPtr mon,
289                              const char *nicstr,
290                              virDomainDevicePCIAddress *guestAddr);
291
292 int qemuMonitorRemovePCIDevice(qemuMonitorPtr mon,
293                                virDomainDevicePCIAddress *guestAddr);
294
295
296 int qemuMonitorSendFileHandle(qemuMonitorPtr mon,
297                               const char *fdname,
298                               int fd);
299
300 int qemuMonitorCloseFileHandle(qemuMonitorPtr mon,
301                                const char *fdname);
302
303
304 /* XXX do we really want to hardcode 'netstr' as the
305  * sendable item here
306  */
307 int qemuMonitorAddHostNetwork(qemuMonitorPtr mon,
308                               const char *netstr);
309
310 int qemuMonitorRemoveHostNetwork(qemuMonitorPtr mon,
311                                  int vlan,
312                                  const char *netname);
313
314 int qemuMonitorGetPtyPaths(qemuMonitorPtr mon,
315                            virHashTablePtr paths);
316
317 int qemuMonitorAttachPCIDiskController(qemuMonitorPtr mon,
318                                        const char *bus,
319                                        virDomainDevicePCIAddress *guestAddr);
320
321 int qemuMonitorAttachDrive(qemuMonitorPtr mon,
322                            const char *drivestr,
323                            virDomainDevicePCIAddress *controllerAddr,
324                            virDomainDeviceDriveAddress *driveAddr);
325
326
327 typedef struct _qemuMonitorPCIAddress qemuMonitorPCIAddress;
328 struct _qemuMonitorPCIAddress {
329     unsigned int vendor;
330     unsigned int product;
331     virDomainDevicePCIAddress addr;
332 };
333
334 int qemuMonitorGetAllPCIAddresses(qemuMonitorPtr mon,
335                                   qemuMonitorPCIAddress **addrs);
336
337 int qemuMonitorAddDevice(qemuMonitorPtr mon,
338                          const char *devicestr);
339
340 int qemuMonitorDelDevice(qemuMonitorPtr mon,
341                          const char *devicestr);
342
343 int qemuMonitorAddDrive(qemuMonitorPtr mon,
344                         const char *drivestr);
345
346 int qemuMonitorSetDrivePassphrase(qemuMonitorPtr mon,
347                                   const char *alias,
348                                   const char *passphrase);
349
350 int qemuMonitorCreateSnapshot(qemuMonitorPtr mon, const char *name);
351 int qemuMonitorLoadSnapshot(qemuMonitorPtr mon, const char *name);
352 int qemuMonitorDeleteSnapshot(qemuMonitorPtr mon, const char *name);
353
354 #endif /* QEMU_MONITOR_H */