2 * QEMU Management Protocol
4 * Copyright IBM, Corp. 2011
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
12 * Contributions after 2012-01-13 are licensed under the terms of the
13 * GNU GPL, version 2 or (at your option) any later version.
16 #include "qemu-common.h"
18 #include "qmp-commands.h"
20 #include "arch_init.h"
22 #include "qapi/qmp-input-visitor.h"
23 #include "qapi/qmp-output-visitor.h"
25 NameInfo
*qmp_query_name(Error
**errp
)
27 NameInfo
*info
= g_malloc0(sizeof(*info
));
30 info
->has_name
= true;
31 info
->name
= g_strdup(qemu_name
);
37 VersionInfo
*qmp_query_version(Error
**err
)
39 VersionInfo
*info
= g_malloc0(sizeof(*info
));
40 const char *version
= QEMU_VERSION
;
43 info
->qemu
.major
= strtol(version
, &tmp
, 10);
45 info
->qemu
.minor
= strtol(tmp
, &tmp
, 10);
47 info
->qemu
.micro
= strtol(tmp
, &tmp
, 10);
48 info
->package
= g_strdup(QEMU_PKGVERSION
);
53 KvmInfo
*qmp_query_kvm(Error
**errp
)
55 KvmInfo
*info
= g_malloc0(sizeof(*info
));
57 info
->enabled
= kvm_enabled();
58 info
->present
= kvm_available();
63 UuidInfo
*qmp_query_uuid(Error
**errp
)
65 UuidInfo
*info
= g_malloc0(sizeof(*info
));
68 snprintf(uuid
, sizeof(uuid
), UUID_FMT
, qemu_uuid
[0], qemu_uuid
[1],
69 qemu_uuid
[2], qemu_uuid
[3], qemu_uuid
[4], qemu_uuid
[5],
70 qemu_uuid
[6], qemu_uuid
[7], qemu_uuid
[8], qemu_uuid
[9],
71 qemu_uuid
[10], qemu_uuid
[11], qemu_uuid
[12], qemu_uuid
[13],
72 qemu_uuid
[14], qemu_uuid
[15]);
74 info
->UUID
= g_strdup(uuid
);
78 void qmp_quit(Error
**err
)
81 qemu_system_shutdown_request();
84 void qmp_stop(Error
**errp
)
86 vm_stop(RUN_STATE_PAUSED
);
89 void qmp_system_reset(Error
**errp
)
91 qemu_system_reset_request();
94 void qmp_system_powerdown(Error
**erp
)
96 qemu_system_powerdown_request();
99 void qmp_cpu(int64_t index
, Error
**errp
)
101 /* Just do nothing */
105 /* If VNC support is enabled, the "true" query-vnc command is
106 defined in the VNC subsystem */
107 VncInfo
*qmp_query_vnc(Error
**errp
)
109 error_set(errp
, QERR_FEATURE_DISABLED
, "vnc");
115 /* If SPICE support is enabled, the "true" query-spice command is
116 defined in the SPICE subsystem. Also note that we use a small
117 trick to maintain query-spice's original behavior, which is not
118 to be available in the namespace if SPICE is not compiled in */
119 SpiceInfo
*qmp_query_spice(Error
**errp
)
121 error_set(errp
, QERR_COMMAND_NOT_FOUND
, "query-spice");
126 static void iostatus_bdrv_it(void *opaque
, BlockDriverState
*bs
)
128 bdrv_iostatus_reset(bs
);
131 static void encrypted_bdrv_it(void *opaque
, BlockDriverState
*bs
)
133 Error
**err
= opaque
;
135 if (!error_is_set(err
) && bdrv_key_required(bs
)) {
136 error_set(err
, QERR_DEVICE_ENCRYPTED
, bdrv_get_device_name(bs
));
140 void qmp_cont(Error
**errp
)
142 Error
*local_err
= NULL
;
144 if (runstate_check(RUN_STATE_INMIGRATE
)) {
145 error_set(errp
, QERR_MIGRATION_EXPECTED
);
147 } else if (runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
148 runstate_check(RUN_STATE_SHUTDOWN
)) {
149 error_set(errp
, QERR_RESET_REQUIRED
);
153 bdrv_iterate(iostatus_bdrv_it
, NULL
);
154 bdrv_iterate(encrypted_bdrv_it
, &local_err
);
156 error_propagate(errp
, local_err
);
163 DevicePropertyInfoList
*qmp_qom_list(const char *path
, Error
**errp
)
166 bool ambiguous
= false;
167 DevicePropertyInfoList
*props
= NULL
;
168 DeviceProperty
*prop
;
170 dev
= qdev_resolve_path(path
, &ambiguous
);
172 error_set(errp
, QERR_DEVICE_NOT_FOUND
, path
);
176 QTAILQ_FOREACH(prop
, &dev
->properties
, node
) {
177 DevicePropertyInfoList
*entry
= g_malloc0(sizeof(*entry
));
179 entry
->value
= g_malloc0(sizeof(DevicePropertyInfo
));
183 entry
->value
->name
= g_strdup(prop
->name
);
184 entry
->value
->type
= g_strdup(prop
->type
);
190 /* FIXME: teach qapi about how to pass through Visitors */
191 int qmp_qom_set(Monitor
*mon
, const QDict
*qdict
, QObject
**ret
)
193 const char *path
= qdict_get_str(qdict
, "path");
194 const char *property
= qdict_get_str(qdict
, "property");
195 QObject
*value
= qdict_get(qdict
, "value");
196 Error
*local_err
= NULL
;
200 dev
= qdev_resolve_path(path
, NULL
);
202 error_set(&local_err
, QERR_DEVICE_NOT_FOUND
, path
);
206 mi
= qmp_input_visitor_new(value
);
207 qdev_property_set(dev
, qmp_input_get_visitor(mi
), property
, &local_err
);
209 qmp_input_visitor_cleanup(mi
);
213 qerror_report_err(local_err
);
214 error_free(local_err
);
221 int qmp_qom_get(Monitor
*mon
, const QDict
*qdict
, QObject
**ret
)
223 const char *path
= qdict_get_str(qdict
, "path");
224 const char *property
= qdict_get_str(qdict
, "property");
225 Error
*local_err
= NULL
;
226 QmpOutputVisitor
*mo
;
229 dev
= qdev_resolve_path(path
, NULL
);
231 error_set(&local_err
, QERR_DEVICE_NOT_FOUND
, path
);
235 mo
= qmp_output_visitor_new();
236 qdev_property_get(dev
, qmp_output_get_visitor(mo
), property
, &local_err
);
238 *ret
= qmp_output_get_qobject(mo
);
241 qmp_output_visitor_cleanup(mo
);
245 qerror_report_err(local_err
);
246 error_free(local_err
);