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.
14 #include "qemu-common.h"
16 #include "qmp-commands.h"
18 #include "arch_init.h"
20 #include "qapi/qmp-input-visitor.h"
21 #include "qapi/qmp-output-visitor.h"
23 NameInfo
*qmp_query_name(Error
**errp
)
25 NameInfo
*info
= g_malloc0(sizeof(*info
));
28 info
->has_name
= true;
29 info
->name
= g_strdup(qemu_name
);
35 VersionInfo
*qmp_query_version(Error
**err
)
37 VersionInfo
*info
= g_malloc0(sizeof(*info
));
38 const char *version
= QEMU_VERSION
;
41 info
->qemu
.major
= strtol(version
, &tmp
, 10);
43 info
->qemu
.minor
= strtol(tmp
, &tmp
, 10);
45 info
->qemu
.micro
= strtol(tmp
, &tmp
, 10);
46 info
->package
= g_strdup(QEMU_PKGVERSION
);
51 KvmInfo
*qmp_query_kvm(Error
**errp
)
53 KvmInfo
*info
= g_malloc0(sizeof(*info
));
55 info
->enabled
= kvm_enabled();
56 info
->present
= kvm_available();
61 UuidInfo
*qmp_query_uuid(Error
**errp
)
63 UuidInfo
*info
= g_malloc0(sizeof(*info
));
66 snprintf(uuid
, sizeof(uuid
), UUID_FMT
, qemu_uuid
[0], qemu_uuid
[1],
67 qemu_uuid
[2], qemu_uuid
[3], qemu_uuid
[4], qemu_uuid
[5],
68 qemu_uuid
[6], qemu_uuid
[7], qemu_uuid
[8], qemu_uuid
[9],
69 qemu_uuid
[10], qemu_uuid
[11], qemu_uuid
[12], qemu_uuid
[13],
70 qemu_uuid
[14], qemu_uuid
[15]);
72 info
->UUID
= g_strdup(uuid
);
76 void qmp_quit(Error
**err
)
79 qemu_system_shutdown_request();
82 void qmp_stop(Error
**errp
)
84 vm_stop(RUN_STATE_PAUSED
);
87 void qmp_system_reset(Error
**errp
)
89 qemu_system_reset_request();
92 void qmp_system_powerdown(Error
**erp
)
94 qemu_system_powerdown_request();
97 void qmp_cpu(int64_t index
, Error
**errp
)
103 /* If VNC support is enabled, the "true" query-vnc command is
104 defined in the VNC subsystem */
105 VncInfo
*qmp_query_vnc(Error
**errp
)
107 error_set(errp
, QERR_FEATURE_DISABLED
, "vnc");
113 /* If SPICE support is enabled, the "true" query-spice command is
114 defined in the SPICE subsystem. Also note that we use a small
115 trick to maintain query-spice's original behavior, which is not
116 to be available in the namespace if SPICE is not compiled in */
117 SpiceInfo
*qmp_query_spice(Error
**errp
)
119 error_set(errp
, QERR_COMMAND_NOT_FOUND
, "query-spice");
124 static void iostatus_bdrv_it(void *opaque
, BlockDriverState
*bs
)
126 bdrv_iostatus_reset(bs
);
129 static void encrypted_bdrv_it(void *opaque
, BlockDriverState
*bs
)
131 Error
**err
= opaque
;
133 if (!error_is_set(err
) && bdrv_key_required(bs
)) {
134 error_set(err
, QERR_DEVICE_ENCRYPTED
, bdrv_get_device_name(bs
));
138 void qmp_cont(Error
**errp
)
140 Error
*local_err
= NULL
;
142 if (runstate_check(RUN_STATE_INMIGRATE
)) {
143 error_set(errp
, QERR_MIGRATION_EXPECTED
);
145 } else if (runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
146 runstate_check(RUN_STATE_SHUTDOWN
)) {
147 error_set(errp
, QERR_RESET_REQUIRED
);
151 bdrv_iterate(iostatus_bdrv_it
, NULL
);
152 bdrv_iterate(encrypted_bdrv_it
, &local_err
);
154 error_propagate(errp
, local_err
);
161 DevicePropertyInfoList
*qmp_qom_list(const char *path
, Error
**errp
)
164 bool ambiguous
= false;
165 DevicePropertyInfoList
*props
= NULL
;
166 DeviceProperty
*prop
;
168 dev
= qdev_resolve_path(path
, &ambiguous
);
170 error_set(errp
, QERR_DEVICE_NOT_FOUND
, path
);
174 QTAILQ_FOREACH(prop
, &dev
->properties
, node
) {
175 DevicePropertyInfoList
*entry
= g_malloc0(sizeof(*entry
));
177 entry
->value
= g_malloc0(sizeof(DevicePropertyInfo
));
181 entry
->value
->name
= g_strdup(prop
->name
);
182 entry
->value
->type
= g_strdup(prop
->type
);
188 /* FIXME: teach qapi about how to pass through Visitors */
189 int qmp_qom_set(Monitor
*mon
, const QDict
*qdict
, QObject
**ret
)
191 const char *path
= qdict_get_str(qdict
, "path");
192 const char *property
= qdict_get_str(qdict
, "property");
193 QObject
*value
= qdict_get(qdict
, "value");
194 Error
*local_err
= NULL
;
198 dev
= qdev_resolve_path(path
, NULL
);
200 error_set(&local_err
, QERR_DEVICE_NOT_FOUND
, path
);
204 mi
= qmp_input_visitor_new(value
);
205 qdev_property_set(dev
, qmp_input_get_visitor(mi
), property
, &local_err
);
207 qmp_input_visitor_cleanup(mi
);
211 qerror_report_err(local_err
);
212 error_free(local_err
);
219 int qmp_qom_get(Monitor
*mon
, const QDict
*qdict
, QObject
**ret
)
221 const char *path
= qdict_get_str(qdict
, "path");
222 const char *property
= qdict_get_str(qdict
, "property");
223 Error
*local_err
= NULL
;
224 QmpOutputVisitor
*mo
;
227 dev
= qdev_resolve_path(path
, NULL
);
229 error_set(&local_err
, QERR_DEVICE_NOT_FOUND
, path
);
233 mo
= qmp_output_visitor_new();
234 qdev_property_get(dev
, qmp_output_get_visitor(mo
), property
, &local_err
);
236 *ret
= qmp_output_get_qobject(mo
);
239 qmp_output_visitor_cleanup(mo
);
243 qerror_report_err(local_err
);
244 error_free(local_err
);