qmp.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. /*
  2. * QEMU Management Protocol
  3. *
  4. * Copyright IBM, Corp. 2011
  5. *
  6. * Authors:
  7. * Anthony Liguori <aliguori@us.ibm.com>
  8. *
  9. * This work is licensed under the terms of the GNU GPL, version 2. See
  10. * the COPYING file in the top-level directory.
  11. *
  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.
  14. */
  15. #include "qemu/osdep.h"
  16. #include "qemu-common.h"
  17. #include "monitor/monitor.h"
  18. #include "sysemu/sysemu.h"
  19. #include "qmp-commands.h"
  20. #include "sysemu/char.h"
  21. #include "ui/qemu-spice.h"
  22. #include "ui/vnc.h"
  23. #include "sysemu/kvm.h"
  24. #include "sysemu/arch_init.h"
  25. #include "hw/qdev.h"
  26. #include "sysemu/blockdev.h"
  27. #include "sysemu/block-backend.h"
  28. #include "qom/qom-qobject.h"
  29. #include "qapi/qmp/qerror.h"
  30. #include "qapi/qmp/qobject.h"
  31. #include "qapi/qmp-input-visitor.h"
  32. #include "hw/boards.h"
  33. #include "qom/object_interfaces.h"
  34. #include "hw/mem/pc-dimm.h"
  35. #include "hw/acpi/acpi_dev_interface.h"
  36. NameInfo *qmp_query_name(Error **errp)
  37. {
  38. NameInfo *info = g_malloc0(sizeof(*info));
  39. if (qemu_name) {
  40. info->has_name = true;
  41. info->name = g_strdup(qemu_name);
  42. }
  43. return info;
  44. }
  45. VersionInfo *qmp_query_version(Error **errp)
  46. {
  47. VersionInfo *info = g_new0(VersionInfo, 1);
  48. const char *version = QEMU_VERSION;
  49. const char *tmp;
  50. int err;
  51. info->qemu = g_new0(VersionTriple, 1);
  52. err = qemu_strtoll(version, &tmp, 10, &info->qemu->major);
  53. assert(err == 0);
  54. tmp++;
  55. err = qemu_strtoll(tmp, &tmp, 10, &info->qemu->minor);
  56. assert(err == 0);
  57. tmp++;
  58. err = qemu_strtoll(tmp, &tmp, 10, &info->qemu->micro);
  59. assert(err == 0);
  60. info->package = g_strdup(QEMU_PKGVERSION);
  61. return info;
  62. }
  63. KvmInfo *qmp_query_kvm(Error **errp)
  64. {
  65. KvmInfo *info = g_malloc0(sizeof(*info));
  66. info->enabled = kvm_enabled();
  67. info->present = kvm_available();
  68. return info;
  69. }
  70. UuidInfo *qmp_query_uuid(Error **errp)
  71. {
  72. UuidInfo *info = g_malloc0(sizeof(*info));
  73. char uuid[64];
  74. snprintf(uuid, sizeof(uuid), UUID_FMT, qemu_uuid[0], qemu_uuid[1],
  75. qemu_uuid[2], qemu_uuid[3], qemu_uuid[4], qemu_uuid[5],
  76. qemu_uuid[6], qemu_uuid[7], qemu_uuid[8], qemu_uuid[9],
  77. qemu_uuid[10], qemu_uuid[11], qemu_uuid[12], qemu_uuid[13],
  78. qemu_uuid[14], qemu_uuid[15]);
  79. info->UUID = g_strdup(uuid);
  80. return info;
  81. }
  82. void qmp_quit(Error **errp)
  83. {
  84. no_shutdown = 0;
  85. qemu_system_shutdown_request();
  86. }
  87. void qmp_stop(Error **errp)
  88. {
  89. if (runstate_check(RUN_STATE_INMIGRATE)) {
  90. autostart = 0;
  91. } else {
  92. vm_stop(RUN_STATE_PAUSED);
  93. }
  94. }
  95. void qmp_system_reset(Error **errp)
  96. {
  97. qemu_system_reset_request();
  98. }
  99. void qmp_system_powerdown(Error **erp)
  100. {
  101. qemu_system_powerdown_request();
  102. }
  103. void qmp_cpu(int64_t index, Error **errp)
  104. {
  105. /* Just do nothing */
  106. }
  107. void qmp_cpu_add(int64_t id, Error **errp)
  108. {
  109. MachineClass *mc;
  110. mc = MACHINE_GET_CLASS(current_machine);
  111. if (mc->hot_add_cpu) {
  112. mc->hot_add_cpu(id, errp);
  113. } else {
  114. error_setg(errp, "Not supported");
  115. }
  116. }
  117. #ifndef CONFIG_VNC
  118. /* If VNC support is enabled, the "true" query-vnc command is
  119. defined in the VNC subsystem */
  120. VncInfo *qmp_query_vnc(Error **errp)
  121. {
  122. error_setg(errp, QERR_FEATURE_DISABLED, "vnc");
  123. return NULL;
  124. };
  125. VncInfo2List *qmp_query_vnc_servers(Error **errp)
  126. {
  127. error_setg(errp, QERR_FEATURE_DISABLED, "vnc");
  128. return NULL;
  129. };
  130. #endif
  131. #ifndef CONFIG_SPICE
  132. /*
  133. * qmp-commands.hx ensures that QMP command query-spice exists only
  134. * #ifdef CONFIG_SPICE. Necessary for an accurate query-commands
  135. * result. However, the QAPI schema is blissfully unaware of that,
  136. * and the QAPI code generator happily generates a dead
  137. * qmp_marshal_query_spice() that calls qmp_query_spice(). Provide it
  138. * one, or else linking fails. FIXME Educate the QAPI schema on
  139. * CONFIG_SPICE.
  140. */
  141. SpiceInfo *qmp_query_spice(Error **errp)
  142. {
  143. abort();
  144. };
  145. #endif
  146. void qmp_cont(Error **errp)
  147. {
  148. Error *local_err = NULL;
  149. BlockBackend *blk;
  150. BlockDriverState *bs;
  151. if (runstate_needs_reset()) {
  152. error_setg(errp, "Resetting the Virtual Machine is required");
  153. return;
  154. } else if (runstate_check(RUN_STATE_SUSPENDED)) {
  155. return;
  156. }
  157. for (blk = blk_next(NULL); blk; blk = blk_next(blk)) {
  158. blk_iostatus_reset(blk);
  159. }
  160. for (bs = bdrv_next(NULL); bs; bs = bdrv_next(bs)) {
  161. bdrv_add_key(bs, NULL, &local_err);
  162. if (local_err) {
  163. error_propagate(errp, local_err);
  164. return;
  165. }
  166. }
  167. /* Continuing after completed migration. Images have been inactivated to
  168. * allow the destination to take control. Need to get control back now. */
  169. if (runstate_check(RUN_STATE_FINISH_MIGRATE) ||
  170. runstate_check(RUN_STATE_POSTMIGRATE))
  171. {
  172. bdrv_invalidate_cache_all(&local_err);
  173. if (local_err) {
  174. error_propagate(errp, local_err);
  175. return;
  176. }
  177. }
  178. if (runstate_check(RUN_STATE_INMIGRATE)) {
  179. autostart = 1;
  180. } else {
  181. vm_start();
  182. }
  183. }
  184. void qmp_system_wakeup(Error **errp)
  185. {
  186. qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
  187. }
  188. ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp)
  189. {
  190. Object *obj;
  191. bool ambiguous = false;
  192. ObjectPropertyInfoList *props = NULL;
  193. ObjectProperty *prop;
  194. ObjectPropertyIterator iter;
  195. obj = object_resolve_path(path, &ambiguous);
  196. if (obj == NULL) {
  197. if (ambiguous) {
  198. error_setg(errp, "Path '%s' is ambiguous", path);
  199. } else {
  200. error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
  201. "Device '%s' not found", path);
  202. }
  203. return NULL;
  204. }
  205. object_property_iter_init(&iter, obj);
  206. while ((prop = object_property_iter_next(&iter))) {
  207. ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry));
  208. entry->value = g_malloc0(sizeof(ObjectPropertyInfo));
  209. entry->next = props;
  210. props = entry;
  211. entry->value->name = g_strdup(prop->name);
  212. entry->value->type = g_strdup(prop->type);
  213. }
  214. return props;
  215. }
  216. void qmp_qom_set(const char *path, const char *property, QObject *value,
  217. Error **errp)
  218. {
  219. Object *obj;
  220. obj = object_resolve_path(path, NULL);
  221. if (!obj) {
  222. error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
  223. "Device '%s' not found", path);
  224. return;
  225. }
  226. object_property_set_qobject(obj, value, property, errp);
  227. }
  228. QObject *qmp_qom_get(const char *path, const char *property, Error **errp)
  229. {
  230. Object *obj;
  231. obj = object_resolve_path(path, NULL);
  232. if (!obj) {
  233. error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
  234. "Device '%s' not found", path);
  235. return NULL;
  236. }
  237. return object_property_get_qobject(obj, property, errp);
  238. }
  239. void qmp_set_password(const char *protocol, const char *password,
  240. bool has_connected, const char *connected, Error **errp)
  241. {
  242. int disconnect_if_connected = 0;
  243. int fail_if_connected = 0;
  244. int rc;
  245. if (has_connected) {
  246. if (strcmp(connected, "fail") == 0) {
  247. fail_if_connected = 1;
  248. } else if (strcmp(connected, "disconnect") == 0) {
  249. disconnect_if_connected = 1;
  250. } else if (strcmp(connected, "keep") == 0) {
  251. /* nothing */
  252. } else {
  253. error_setg(errp, QERR_INVALID_PARAMETER, "connected");
  254. return;
  255. }
  256. }
  257. if (strcmp(protocol, "spice") == 0) {
  258. if (!qemu_using_spice(errp)) {
  259. return;
  260. }
  261. rc = qemu_spice_set_passwd(password, fail_if_connected,
  262. disconnect_if_connected);
  263. if (rc != 0) {
  264. error_setg(errp, QERR_SET_PASSWD_FAILED);
  265. }
  266. return;
  267. }
  268. if (strcmp(protocol, "vnc") == 0) {
  269. if (fail_if_connected || disconnect_if_connected) {
  270. /* vnc supports "connected=keep" only */
  271. error_setg(errp, QERR_INVALID_PARAMETER, "connected");
  272. return;
  273. }
  274. /* Note that setting an empty password will not disable login through
  275. * this interface. */
  276. rc = vnc_display_password(NULL, password);
  277. if (rc < 0) {
  278. error_setg(errp, QERR_SET_PASSWD_FAILED);
  279. }
  280. return;
  281. }
  282. error_setg(errp, QERR_INVALID_PARAMETER, "protocol");
  283. }
  284. void qmp_expire_password(const char *protocol, const char *whenstr,
  285. Error **errp)
  286. {
  287. time_t when;
  288. int rc;
  289. if (strcmp(whenstr, "now") == 0) {
  290. when = 0;
  291. } else if (strcmp(whenstr, "never") == 0) {
  292. when = TIME_MAX;
  293. } else if (whenstr[0] == '+') {
  294. when = time(NULL) + strtoull(whenstr+1, NULL, 10);
  295. } else {
  296. when = strtoull(whenstr, NULL, 10);
  297. }
  298. if (strcmp(protocol, "spice") == 0) {
  299. if (!qemu_using_spice(errp)) {
  300. return;
  301. }
  302. rc = qemu_spice_set_pw_expire(when);
  303. if (rc != 0) {
  304. error_setg(errp, QERR_SET_PASSWD_FAILED);
  305. }
  306. return;
  307. }
  308. if (strcmp(protocol, "vnc") == 0) {
  309. rc = vnc_display_pw_expire(NULL, when);
  310. if (rc != 0) {
  311. error_setg(errp, QERR_SET_PASSWD_FAILED);
  312. }
  313. return;
  314. }
  315. error_setg(errp, QERR_INVALID_PARAMETER, "protocol");
  316. }
  317. #ifdef CONFIG_VNC
  318. void qmp_change_vnc_password(const char *password, Error **errp)
  319. {
  320. if (vnc_display_password(NULL, password) < 0) {
  321. error_setg(errp, QERR_SET_PASSWD_FAILED);
  322. }
  323. }
  324. static void qmp_change_vnc_listen(const char *target, Error **errp)
  325. {
  326. QemuOptsList *olist = qemu_find_opts("vnc");
  327. QemuOpts *opts;
  328. if (strstr(target, "id=")) {
  329. error_setg(errp, "id not supported");
  330. return;
  331. }
  332. opts = qemu_opts_find(olist, "default");
  333. if (opts) {
  334. qemu_opts_del(opts);
  335. }
  336. opts = vnc_parse(target, errp);
  337. if (!opts) {
  338. return;
  339. }
  340. vnc_display_open("default", errp);
  341. }
  342. static void qmp_change_vnc(const char *target, bool has_arg, const char *arg,
  343. Error **errp)
  344. {
  345. if (strcmp(target, "passwd") == 0 || strcmp(target, "password") == 0) {
  346. if (!has_arg) {
  347. error_setg(errp, QERR_MISSING_PARAMETER, "password");
  348. } else {
  349. qmp_change_vnc_password(arg, errp);
  350. }
  351. } else {
  352. qmp_change_vnc_listen(target, errp);
  353. }
  354. }
  355. #else
  356. void qmp_change_vnc_password(const char *password, Error **errp)
  357. {
  358. error_setg(errp, QERR_FEATURE_DISABLED, "vnc");
  359. }
  360. static void qmp_change_vnc(const char *target, bool has_arg, const char *arg,
  361. Error **errp)
  362. {
  363. error_setg(errp, QERR_FEATURE_DISABLED, "vnc");
  364. }
  365. #endif /* !CONFIG_VNC */
  366. void qmp_change(const char *device, const char *target,
  367. bool has_arg, const char *arg, Error **errp)
  368. {
  369. if (strcmp(device, "vnc") == 0) {
  370. qmp_change_vnc(target, has_arg, arg, errp);
  371. } else {
  372. qmp_blockdev_change_medium(device, target, has_arg, arg, false, 0,
  373. errp);
  374. }
  375. }
  376. static void qom_list_types_tramp(ObjectClass *klass, void *data)
  377. {
  378. ObjectTypeInfoList *e, **pret = data;
  379. ObjectTypeInfo *info;
  380. info = g_malloc0(sizeof(*info));
  381. info->name = g_strdup(object_class_get_name(klass));
  382. e = g_malloc0(sizeof(*e));
  383. e->value = info;
  384. e->next = *pret;
  385. *pret = e;
  386. }
  387. ObjectTypeInfoList *qmp_qom_list_types(bool has_implements,
  388. const char *implements,
  389. bool has_abstract,
  390. bool abstract,
  391. Error **errp)
  392. {
  393. ObjectTypeInfoList *ret = NULL;
  394. object_class_foreach(qom_list_types_tramp, implements, abstract, &ret);
  395. return ret;
  396. }
  397. /* Return a DevicePropertyInfo for a qdev property.
  398. *
  399. * If a qdev property with the given name does not exist, use the given default
  400. * type. If the qdev property info should not be shown, return NULL.
  401. *
  402. * The caller must free the return value.
  403. */
  404. static DevicePropertyInfo *make_device_property_info(ObjectClass *klass,
  405. const char *name,
  406. const char *default_type,
  407. const char *description)
  408. {
  409. DevicePropertyInfo *info;
  410. Property *prop;
  411. do {
  412. for (prop = DEVICE_CLASS(klass)->props; prop && prop->name; prop++) {
  413. if (strcmp(name, prop->name) != 0) {
  414. continue;
  415. }
  416. /*
  417. * TODO Properties without a parser are just for dirty hacks.
  418. * qdev_prop_ptr is the only such PropertyInfo. It's marked
  419. * for removal. This conditional should be removed along with
  420. * it.
  421. */
  422. if (!prop->info->set) {
  423. return NULL; /* no way to set it, don't show */
  424. }
  425. info = g_malloc0(sizeof(*info));
  426. info->name = g_strdup(prop->name);
  427. info->type = g_strdup(prop->info->name);
  428. info->has_description = !!prop->info->description;
  429. info->description = g_strdup(prop->info->description);
  430. return info;
  431. }
  432. klass = object_class_get_parent(klass);
  433. } while (klass != object_class_by_name(TYPE_DEVICE));
  434. /* Not a qdev property, use the default type */
  435. info = g_malloc0(sizeof(*info));
  436. info->name = g_strdup(name);
  437. info->type = g_strdup(default_type);
  438. info->has_description = !!description;
  439. info->description = g_strdup(description);
  440. return info;
  441. }
  442. DevicePropertyInfoList *qmp_device_list_properties(const char *typename,
  443. Error **errp)
  444. {
  445. ObjectClass *klass;
  446. Object *obj;
  447. ObjectProperty *prop;
  448. ObjectPropertyIterator iter;
  449. DevicePropertyInfoList *prop_list = NULL;
  450. klass = object_class_by_name(typename);
  451. if (klass == NULL) {
  452. error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
  453. "Device '%s' not found", typename);
  454. return NULL;
  455. }
  456. klass = object_class_dynamic_cast(klass, TYPE_DEVICE);
  457. if (klass == NULL) {
  458. error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "name", TYPE_DEVICE);
  459. return NULL;
  460. }
  461. if (object_class_is_abstract(klass)) {
  462. error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "name",
  463. "non-abstract device type");
  464. return NULL;
  465. }
  466. if (DEVICE_CLASS(klass)->cannot_destroy_with_object_finalize_yet) {
  467. error_setg(errp, "Can't list properties of device '%s'", typename);
  468. return NULL;
  469. }
  470. obj = object_new(typename);
  471. object_property_iter_init(&iter, obj);
  472. while ((prop = object_property_iter_next(&iter))) {
  473. DevicePropertyInfo *info;
  474. DevicePropertyInfoList *entry;
  475. /* Skip Object and DeviceState properties */
  476. if (strcmp(prop->name, "type") == 0 ||
  477. strcmp(prop->name, "realized") == 0 ||
  478. strcmp(prop->name, "hotpluggable") == 0 ||
  479. strcmp(prop->name, "hotplugged") == 0 ||
  480. strcmp(prop->name, "parent_bus") == 0) {
  481. continue;
  482. }
  483. /* Skip legacy properties since they are just string versions of
  484. * properties that we already list.
  485. */
  486. if (strstart(prop->name, "legacy-", NULL)) {
  487. continue;
  488. }
  489. info = make_device_property_info(klass, prop->name, prop->type,
  490. prop->description);
  491. if (!info) {
  492. continue;
  493. }
  494. entry = g_malloc0(sizeof(*entry));
  495. entry->value = info;
  496. entry->next = prop_list;
  497. prop_list = entry;
  498. }
  499. object_unref(obj);
  500. return prop_list;
  501. }
  502. CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
  503. {
  504. return arch_query_cpu_definitions(errp);
  505. }
  506. void qmp_add_client(const char *protocol, const char *fdname,
  507. bool has_skipauth, bool skipauth, bool has_tls, bool tls,
  508. Error **errp)
  509. {
  510. CharDriverState *s;
  511. int fd;
  512. fd = monitor_get_fd(cur_mon, fdname, errp);
  513. if (fd < 0) {
  514. return;
  515. }
  516. if (strcmp(protocol, "spice") == 0) {
  517. if (!qemu_using_spice(errp)) {
  518. close(fd);
  519. return;
  520. }
  521. skipauth = has_skipauth ? skipauth : false;
  522. tls = has_tls ? tls : false;
  523. if (qemu_spice_display_add_client(fd, skipauth, tls) < 0) {
  524. error_setg(errp, "spice failed to add client");
  525. close(fd);
  526. }
  527. return;
  528. #ifdef CONFIG_VNC
  529. } else if (strcmp(protocol, "vnc") == 0) {
  530. skipauth = has_skipauth ? skipauth : false;
  531. vnc_display_add_client(NULL, fd, skipauth);
  532. return;
  533. #endif
  534. } else if ((s = qemu_chr_find(protocol)) != NULL) {
  535. if (qemu_chr_add_client(s, fd) < 0) {
  536. error_setg(errp, "failed to add client");
  537. close(fd);
  538. return;
  539. }
  540. return;
  541. }
  542. error_setg(errp, "protocol '%s' is invalid", protocol);
  543. close(fd);
  544. }
  545. void object_add(const char *type, const char *id, const QDict *qdict,
  546. Visitor *v, Error **errp)
  547. {
  548. Object *obj;
  549. ObjectClass *klass;
  550. const QDictEntry *e;
  551. Error *local_err = NULL;
  552. klass = object_class_by_name(type);
  553. if (!klass) {
  554. error_setg(errp, "invalid object type: %s", type);
  555. return;
  556. }
  557. if (!object_class_dynamic_cast(klass, TYPE_USER_CREATABLE)) {
  558. error_setg(errp, "object type '%s' isn't supported by object-add",
  559. type);
  560. return;
  561. }
  562. if (object_class_is_abstract(klass)) {
  563. error_setg(errp, "object type '%s' is abstract", type);
  564. return;
  565. }
  566. obj = object_new(type);
  567. if (qdict) {
  568. for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) {
  569. object_property_set(obj, v, e->key, &local_err);
  570. if (local_err) {
  571. goto out;
  572. }
  573. }
  574. }
  575. object_property_add_child(object_get_objects_root(),
  576. id, obj, &local_err);
  577. if (local_err) {
  578. goto out;
  579. }
  580. user_creatable_complete(obj, &local_err);
  581. if (local_err) {
  582. object_property_del(object_get_objects_root(),
  583. id, &error_abort);
  584. goto out;
  585. }
  586. out:
  587. if (local_err) {
  588. error_propagate(errp, local_err);
  589. }
  590. object_unref(obj);
  591. }
  592. void qmp_object_add(const char *type, const char *id,
  593. bool has_props, QObject *props, Error **errp)
  594. {
  595. const QDict *pdict = NULL;
  596. QmpInputVisitor *qiv;
  597. if (props) {
  598. pdict = qobject_to_qdict(props);
  599. if (!pdict) {
  600. error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict");
  601. return;
  602. }
  603. }
  604. qiv = qmp_input_visitor_new(props);
  605. object_add(type, id, pdict, qmp_input_get_visitor(qiv), errp);
  606. qmp_input_visitor_cleanup(qiv);
  607. }
  608. void qmp_object_del(const char *id, Error **errp)
  609. {
  610. Object *container;
  611. Object *obj;
  612. container = object_get_objects_root();
  613. obj = object_resolve_path_component(container, id);
  614. if (!obj) {
  615. error_setg(errp, "object id not found");
  616. return;
  617. }
  618. if (!user_creatable_can_be_deleted(USER_CREATABLE(obj), errp)) {
  619. error_setg(errp, "%s is in use, can not be deleted", id);
  620. return;
  621. }
  622. object_unparent(obj);
  623. }
  624. MemoryDeviceInfoList *qmp_query_memory_devices(Error **errp)
  625. {
  626. MemoryDeviceInfoList *head = NULL;
  627. MemoryDeviceInfoList **prev = &head;
  628. qmp_pc_dimm_device_list(qdev_get_machine(), &prev);
  629. return head;
  630. }
  631. ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **errp)
  632. {
  633. bool ambig;
  634. ACPIOSTInfoList *head = NULL;
  635. ACPIOSTInfoList **prev = &head;
  636. Object *obj = object_resolve_path_type("", TYPE_ACPI_DEVICE_IF, &ambig);
  637. if (obj) {
  638. AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(obj);
  639. AcpiDeviceIf *adev = ACPI_DEVICE_IF(obj);
  640. adevc->ospm_status(adev, &prev);
  641. } else {
  642. error_setg(errp, "command is not supported, missing ACPI device");
  643. }
  644. return head;
  645. }