1 /*
2  * qemu_agent.h: interaction with QEMU guest agent
3  *
4  * Copyright (C) 2006-2012 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, see
19  * <http://www.gnu.org/licenses/>.
20  */
21 
22 #pragma once
23 
24 #include "internal.h"
25 #include "domain_conf.h"
26 
27 typedef struct _qemuAgent qemuAgent;
28 
29 typedef struct _qemuAgentCallbacks qemuAgentCallbacks;
30 struct _qemuAgentCallbacks {
31     void (*eofNotify)(qemuAgent *mon,
32                       virDomainObj *vm);
33     void (*errorNotify)(qemuAgent *mon,
34                         virDomainObj *vm);
35 };
36 
37 
38 qemuAgent *qemuAgentOpen(virDomainObj *vm,
39                            const virDomainChrSourceDef *config,
40                            GMainContext *context,
41                            qemuAgentCallbacks *cb,
42                            bool singleSync);
43 
44 void qemuAgentClose(qemuAgent *mon);
45 
46 void qemuAgentNotifyClose(qemuAgent *mon);
47 
48 typedef enum {
49     QEMU_AGENT_EVENT_NONE = 0,
50     QEMU_AGENT_EVENT_SHUTDOWN,
51     QEMU_AGENT_EVENT_SUSPEND,
52     QEMU_AGENT_EVENT_RESET,
53 } qemuAgentEvent;
54 
55 void qemuAgentNotifyEvent(qemuAgent *mon,
56                           qemuAgentEvent event);
57 
58 typedef enum {
59     QEMU_AGENT_SHUTDOWN_POWERDOWN,
60     QEMU_AGENT_SHUTDOWN_REBOOT,
61     QEMU_AGENT_SHUTDOWN_HALT,
62 
63     QEMU_AGENT_SHUTDOWN_LAST,
64 } qemuAgentShutdownMode;
65 
66 typedef struct _qemuAgentDiskAddress qemuAgentDiskAddress;
67 struct _qemuAgentDiskAddress {
68     char *serial;
69     virPCIDeviceAddress pci_controller;
70     char *bus_type;
71     unsigned int bus;
72     unsigned int target;
73     unsigned int unit;
74     char *devnode;
75     virDomainDeviceCCWAddress *ccw_addr;
76 };
77 void qemuAgentDiskAddressFree(qemuAgentDiskAddress *addr);
78 G_DEFINE_AUTOPTR_CLEANUP_FUNC(qemuAgentDiskAddress, qemuAgentDiskAddressFree);
79 
80 typedef struct _qemuAgentDiskInfo qemuAgentDiskInfo;
81 struct _qemuAgentDiskInfo {
82     char *name;
83     bool partition;
84     char **dependencies;
85     qemuAgentDiskAddress *address;
86     char *alias;
87 };
88 void qemuAgentDiskInfoFree(qemuAgentDiskInfo *info);
89 
90 typedef struct _qemuAgentFSInfo qemuAgentFSInfo;
91 struct _qemuAgentFSInfo {
92     char *mountpoint; /* path to mount point */
93     char *name;       /* device name in the guest (e.g. "sda1") */
94     char *fstype;     /* filesystem type */
95     long long total_bytes;
96     long long used_bytes;
97     size_t ndisks;
98     qemuAgentDiskAddress **disks;
99 };
100 void qemuAgentFSInfoFree(qemuAgentFSInfo *info);
101 
102 int qemuAgentShutdown(qemuAgent *mon,
103                       qemuAgentShutdownMode mode);
104 
105 int qemuAgentFSFreeze(qemuAgent *mon,
106                       const char **mountpoints, unsigned int nmountpoints);
107 int qemuAgentFSThaw(qemuAgent *mon);
108 int qemuAgentGetFSInfo(qemuAgent *mon,
109                        qemuAgentFSInfo ***info,
110                        bool report_unsupported);
111 
112 int qemuAgentSuspend(qemuAgent *mon,
113                      unsigned int target);
114 
115 int qemuAgentArbitraryCommand(qemuAgent *mon,
116                               const char *cmd,
117                               char **result,
118                               int timeout);
119 int qemuAgentFSTrim(qemuAgent *mon,
120                     unsigned long long minimum);
121 
122 
123 typedef struct _qemuAgentCPUInfo qemuAgentCPUInfo;
124 struct _qemuAgentCPUInfo {
125     unsigned int id;    /* logical cpu ID */
126     bool online;        /* true if the CPU is activated */
127     bool offlinable;    /* true if the CPU can be offlined */
128 
129     bool modified; /* set to true if the vcpu state needs to be changed */
130 };
131 
132 int qemuAgentGetVCPUs(qemuAgent *mon, qemuAgentCPUInfo **info);
133 int qemuAgentSetVCPUs(qemuAgent *mon, qemuAgentCPUInfo *cpus, size_t ncpus);
134 int qemuAgentUpdateCPUInfo(unsigned int nvcpus,
135                            qemuAgentCPUInfo *cpuinfo,
136                            int ncpuinfo);
137 
138 int
139 qemuAgentGetHostname(qemuAgent *mon,
140                      char **hostname,
141                      bool report_unsupported);
142 
143 int qemuAgentGetTime(qemuAgent *mon,
144                      long long *seconds,
145                      unsigned int *nseconds);
146 int qemuAgentSetTime(qemuAgent *mon,
147                      long long seconds,
148                      unsigned int nseconds,
149                      bool sync);
150 
151 int qemuAgentGetInterfaces(qemuAgent *mon,
152                            virDomainInterfacePtr **ifaces,
153                            bool report_unsupported);
154 
155 int qemuAgentSetUserPassword(qemuAgent *mon,
156                              const char *user,
157                              const char *password,
158                              bool crypted);
159 
160 int qemuAgentGetUsers(qemuAgent *mon,
161                       virTypedParameterPtr *params,
162                       int *nparams,
163                       int *maxparams,
164                       bool report_unsupported);
165 
166 int qemuAgentGetOSInfo(qemuAgent *mon,
167                        virTypedParameterPtr *params,
168                        int *nparams,
169                        int *maxparams,
170                        bool report_unsupported);
171 
172 int qemuAgentGetTimezone(qemuAgent *mon,
173                          virTypedParameterPtr *params,
174                          int *nparams,
175                          int *maxparams,
176                          bool report_unsupported);
177 
178 void qemuAgentSetResponseTimeout(qemuAgent *mon,
179                                  int timeout);
180 
181 int qemuAgentSSHGetAuthorizedKeys(qemuAgent *agent,
182                                   const char *user,
183                                   char ***keys);
184 
185 int qemuAgentSSHAddAuthorizedKeys(qemuAgent *agent,
186                                   const char *user,
187                                   const char **keys,
188                                   size_t nkeys,
189                                   bool reset);
190 
191 int qemuAgentSSHRemoveAuthorizedKeys(qemuAgent *agent,
192                                      const char *user,
193                                      const char **keys,
194                                      size_t nkeys);
195 
196 int qemuAgentGetDisks(qemuAgent *mon,
197                       qemuAgentDiskInfo ***disks,
198                       bool report_unsupported);
199