]> Git Repo - qemu.git/blob - hmp.c
test makefile overhaul
[qemu.git] / hmp.c
1 /*
2  * Human Monitor Interface
3  *
4  * Copyright IBM, Corp. 2011
5  *
6  * Authors:
7  *  Anthony Liguori   <[email protected]>
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
16 #include "hmp.h"
17 #include "qemu-timer.h"
18 #include "qmp-commands.h"
19
20 static void hmp_handle_error(Monitor *mon, Error **errp)
21 {
22     if (error_is_set(errp)) {
23         monitor_printf(mon, "%s\n", error_get_pretty(*errp));
24         error_free(*errp);
25     }
26 }
27
28 void hmp_info_name(Monitor *mon)
29 {
30     NameInfo *info;
31
32     info = qmp_query_name(NULL);
33     if (info->has_name) {
34         monitor_printf(mon, "%s\n", info->name);
35     }
36     qapi_free_NameInfo(info);
37 }
38
39 void hmp_info_version(Monitor *mon)
40 {
41     VersionInfo *info;
42
43     info = qmp_query_version(NULL);
44
45     monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
46                    info->qemu.major, info->qemu.minor, info->qemu.micro,
47                    info->package);
48
49     qapi_free_VersionInfo(info);
50 }
51
52 void hmp_info_kvm(Monitor *mon)
53 {
54     KvmInfo *info;
55
56     info = qmp_query_kvm(NULL);
57     monitor_printf(mon, "kvm support: ");
58     if (info->present) {
59         monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
60     } else {
61         monitor_printf(mon, "not compiled\n");
62     }
63
64     qapi_free_KvmInfo(info);
65 }
66
67 void hmp_info_status(Monitor *mon)
68 {
69     StatusInfo *info;
70
71     info = qmp_query_status(NULL);
72
73     monitor_printf(mon, "VM status: %s%s",
74                    info->running ? "running" : "paused",
75                    info->singlestep ? " (single step mode)" : "");
76
77     if (!info->running && info->status != RUN_STATE_PAUSED) {
78         monitor_printf(mon, " (%s)", RunState_lookup[info->status]);
79     }
80
81     monitor_printf(mon, "\n");
82
83     qapi_free_StatusInfo(info);
84 }
85
86 void hmp_info_uuid(Monitor *mon)
87 {
88     UuidInfo *info;
89
90     info = qmp_query_uuid(NULL);
91     monitor_printf(mon, "%s\n", info->UUID);
92     qapi_free_UuidInfo(info);
93 }
94
95 void hmp_info_chardev(Monitor *mon)
96 {
97     ChardevInfoList *char_info, *info;
98
99     char_info = qmp_query_chardev(NULL);
100     for (info = char_info; info; info = info->next) {
101         monitor_printf(mon, "%s: filename=%s\n", info->value->label,
102                                                  info->value->filename);
103     }
104
105     qapi_free_ChardevInfoList(char_info);
106 }
107
108 void hmp_info_mice(Monitor *mon)
109 {
110     MouseInfoList *mice_list, *mouse;
111
112     mice_list = qmp_query_mice(NULL);
113     if (!mice_list) {
114         monitor_printf(mon, "No mouse devices connected\n");
115         return;
116     }
117
118     for (mouse = mice_list; mouse; mouse = mouse->next) {
119         monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
120                        mouse->value->current ? '*' : ' ',
121                        mouse->value->index, mouse->value->name,
122                        mouse->value->absolute ? " (absolute)" : "");
123     }
124
125     qapi_free_MouseInfoList(mice_list);
126 }
127
128 void hmp_info_migrate(Monitor *mon)
129 {
130     MigrationInfo *info;
131
132     info = qmp_query_migrate(NULL);
133
134     if (info->has_status) {
135         monitor_printf(mon, "Migration status: %s\n", info->status);
136     }
137
138     if (info->has_ram) {
139         monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
140                        info->ram->transferred >> 10);
141         monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
142                        info->ram->remaining >> 10);
143         monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
144                        info->ram->total >> 10);
145     }
146
147     if (info->has_disk) {
148         monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
149                        info->disk->transferred >> 10);
150         monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
151                        info->disk->remaining >> 10);
152         monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
153                        info->disk->total >> 10);
154     }
155
156     qapi_free_MigrationInfo(info);
157 }
158
159 void hmp_info_cpus(Monitor *mon)
160 {
161     CpuInfoList *cpu_list, *cpu;
162
163     cpu_list = qmp_query_cpus(NULL);
164
165     for (cpu = cpu_list; cpu; cpu = cpu->next) {
166         int active = ' ';
167
168         if (cpu->value->CPU == monitor_get_cpu_index()) {
169             active = '*';
170         }
171
172         monitor_printf(mon, "%c CPU #%" PRId64 ": ", active, cpu->value->CPU);
173
174         if (cpu->value->has_pc) {
175             monitor_printf(mon, "pc=0x%016" PRIx64, cpu->value->pc);
176         }
177         if (cpu->value->has_nip) {
178             monitor_printf(mon, "nip=0x%016" PRIx64, cpu->value->nip);
179         }
180         if (cpu->value->has_npc) {
181             monitor_printf(mon, "pc=0x%016" PRIx64, cpu->value->pc);
182             monitor_printf(mon, "npc=0x%016" PRIx64, cpu->value->npc);
183         }
184         if (cpu->value->has_PC) {
185             monitor_printf(mon, "PC=0x%016" PRIx64, cpu->value->PC);
186         }
187
188         if (cpu->value->halted) {
189             monitor_printf(mon, " (halted)");
190         }
191
192         monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
193     }
194
195     qapi_free_CpuInfoList(cpu_list);
196 }
197
198 void hmp_info_block(Monitor *mon)
199 {
200     BlockInfoList *block_list, *info;
201
202     block_list = qmp_query_block(NULL);
203
204     for (info = block_list; info; info = info->next) {
205         monitor_printf(mon, "%s: removable=%d",
206                        info->value->device, info->value->removable);
207
208         if (info->value->removable) {
209             monitor_printf(mon, " locked=%d", info->value->locked);
210             monitor_printf(mon, " tray-open=%d", info->value->tray_open);
211         }
212
213         if (info->value->has_io_status) {
214             monitor_printf(mon, " io-status=%s",
215                            BlockDeviceIoStatus_lookup[info->value->io_status]);
216         }
217
218         if (info->value->has_inserted) {
219             monitor_printf(mon, " file=");
220             monitor_print_filename(mon, info->value->inserted->file);
221
222             if (info->value->inserted->has_backing_file) {
223                 monitor_printf(mon, " backing_file=");
224                 monitor_print_filename(mon, info->value->inserted->backing_file);
225             }
226             monitor_printf(mon, " ro=%d drv=%s encrypted=%d",
227                            info->value->inserted->ro,
228                            info->value->inserted->drv,
229                            info->value->inserted->encrypted);
230
231             monitor_printf(mon, " bps=%" PRId64 " bps_rd=%" PRId64
232                             " bps_wr=%" PRId64 " iops=%" PRId64
233                             " iops_rd=%" PRId64 " iops_wr=%" PRId64,
234                             info->value->inserted->bps,
235                             info->value->inserted->bps_rd,
236                             info->value->inserted->bps_wr,
237                             info->value->inserted->iops,
238                             info->value->inserted->iops_rd,
239                             info->value->inserted->iops_wr);
240         } else {
241             monitor_printf(mon, " [not inserted]");
242         }
243
244         monitor_printf(mon, "\n");
245     }
246
247     qapi_free_BlockInfoList(block_list);
248 }
249
250 void hmp_info_blockstats(Monitor *mon)
251 {
252     BlockStatsList *stats_list, *stats;
253
254     stats_list = qmp_query_blockstats(NULL);
255
256     for (stats = stats_list; stats; stats = stats->next) {
257         if (!stats->value->has_device) {
258             continue;
259         }
260
261         monitor_printf(mon, "%s:", stats->value->device);
262         monitor_printf(mon, " rd_bytes=%" PRId64
263                        " wr_bytes=%" PRId64
264                        " rd_operations=%" PRId64
265                        " wr_operations=%" PRId64
266                        " flush_operations=%" PRId64
267                        " wr_total_time_ns=%" PRId64
268                        " rd_total_time_ns=%" PRId64
269                        " flush_total_time_ns=%" PRId64
270                        "\n",
271                        stats->value->stats->rd_bytes,
272                        stats->value->stats->wr_bytes,
273                        stats->value->stats->rd_operations,
274                        stats->value->stats->wr_operations,
275                        stats->value->stats->flush_operations,
276                        stats->value->stats->wr_total_time_ns,
277                        stats->value->stats->rd_total_time_ns,
278                        stats->value->stats->flush_total_time_ns);
279     }
280
281     qapi_free_BlockStatsList(stats_list);
282 }
283
284 void hmp_info_vnc(Monitor *mon)
285 {
286     VncInfo *info;
287     Error *err = NULL;
288     VncClientInfoList *client;
289
290     info = qmp_query_vnc(&err);
291     if (err) {
292         monitor_printf(mon, "%s\n", error_get_pretty(err));
293         error_free(err);
294         return;
295     }
296
297     if (!info->enabled) {
298         monitor_printf(mon, "Server: disabled\n");
299         goto out;
300     }
301
302     monitor_printf(mon, "Server:\n");
303     if (info->has_host && info->has_service) {
304         monitor_printf(mon, "     address: %s:%s\n", info->host, info->service);
305     }
306     if (info->has_auth) {
307         monitor_printf(mon, "        auth: %s\n", info->auth);
308     }
309
310     if (!info->has_clients || info->clients == NULL) {
311         monitor_printf(mon, "Client: none\n");
312     } else {
313         for (client = info->clients; client; client = client->next) {
314             monitor_printf(mon, "Client:\n");
315             monitor_printf(mon, "     address: %s:%s\n",
316                            client->value->host, client->value->service);
317             monitor_printf(mon, "  x509_dname: %s\n",
318                            client->value->x509_dname ?
319                            client->value->x509_dname : "none");
320             monitor_printf(mon, "    username: %s\n",
321                            client->value->has_sasl_username ?
322                            client->value->sasl_username : "none");
323         }
324     }
325
326 out:
327     qapi_free_VncInfo(info);
328 }
329
330 void hmp_info_spice(Monitor *mon)
331 {
332     SpiceChannelList *chan;
333     SpiceInfo *info;
334
335     info = qmp_query_spice(NULL);
336
337     if (!info->enabled) {
338         monitor_printf(mon, "Server: disabled\n");
339         goto out;
340     }
341
342     monitor_printf(mon, "Server:\n");
343     if (info->has_port) {
344         monitor_printf(mon, "     address: %s:%" PRId64 "\n",
345                        info->host, info->port);
346     }
347     if (info->has_tls_port) {
348         monitor_printf(mon, "     address: %s:%" PRId64 " [tls]\n",
349                        info->host, info->tls_port);
350     }
351     monitor_printf(mon, "        auth: %s\n", info->auth);
352     monitor_printf(mon, "    compiled: %s\n", info->compiled_version);
353
354     if (!info->has_channels || info->channels == NULL) {
355         monitor_printf(mon, "Channels: none\n");
356     } else {
357         for (chan = info->channels; chan; chan = chan->next) {
358             monitor_printf(mon, "Channel:\n");
359             monitor_printf(mon, "     address: %s:%s%s\n",
360                            chan->value->host, chan->value->port,
361                            chan->value->tls ? " [tls]" : "");
362             monitor_printf(mon, "     session: %" PRId64 "\n",
363                            chan->value->connection_id);
364             monitor_printf(mon, "     channel: %" PRId64 ":%" PRId64 "\n",
365                            chan->value->channel_type, chan->value->channel_id);
366         }
367     }
368
369 out:
370     qapi_free_SpiceInfo(info);
371 }
372
373 void hmp_info_balloon(Monitor *mon)
374 {
375     BalloonInfo *info;
376     Error *err = NULL;
377
378     info = qmp_query_balloon(&err);
379     if (err) {
380         monitor_printf(mon, "%s\n", error_get_pretty(err));
381         error_free(err);
382         return;
383     }
384
385     monitor_printf(mon, "balloon: actual=%" PRId64, info->actual >> 20);
386     if (info->has_mem_swapped_in) {
387         monitor_printf(mon, " mem_swapped_in=%" PRId64, info->mem_swapped_in);
388     }
389     if (info->has_mem_swapped_out) {
390         monitor_printf(mon, " mem_swapped_out=%" PRId64, info->mem_swapped_out);
391     }
392     if (info->has_major_page_faults) {
393         monitor_printf(mon, " major_page_faults=%" PRId64,
394                        info->major_page_faults);
395     }
396     if (info->has_minor_page_faults) {
397         monitor_printf(mon, " minor_page_faults=%" PRId64,
398                        info->minor_page_faults);
399     }
400     if (info->has_free_mem) {
401         monitor_printf(mon, " free_mem=%" PRId64, info->free_mem);
402     }
403     if (info->has_total_mem) {
404         monitor_printf(mon, " total_mem=%" PRId64, info->total_mem);
405     }
406
407     monitor_printf(mon, "\n");
408
409     qapi_free_BalloonInfo(info);
410 }
411
412 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
413 {
414     PciMemoryRegionList *region;
415
416     monitor_printf(mon, "  Bus %2" PRId64 ", ", dev->bus);
417     monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
418                    dev->slot, dev->function);
419     monitor_printf(mon, "    ");
420
421     if (dev->class_info.has_desc) {
422         monitor_printf(mon, "%s", dev->class_info.desc);
423     } else {
424         monitor_printf(mon, "Class %04" PRId64, dev->class_info.class);
425     }
426
427     monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
428                    dev->id.vendor, dev->id.device);
429
430     if (dev->has_irq) {
431         monitor_printf(mon, "      IRQ %" PRId64 ".\n", dev->irq);
432     }
433
434     if (dev->has_pci_bridge) {
435         monitor_printf(mon, "      BUS %" PRId64 ".\n",
436                        dev->pci_bridge->bus.number);
437         monitor_printf(mon, "      secondary bus %" PRId64 ".\n",
438                        dev->pci_bridge->bus.secondary);
439         monitor_printf(mon, "      subordinate bus %" PRId64 ".\n",
440                        dev->pci_bridge->bus.subordinate);
441
442         monitor_printf(mon, "      IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
443                        dev->pci_bridge->bus.io_range->base,
444                        dev->pci_bridge->bus.io_range->limit);
445
446         monitor_printf(mon,
447                        "      memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
448                        dev->pci_bridge->bus.memory_range->base,
449                        dev->pci_bridge->bus.memory_range->limit);
450
451         monitor_printf(mon, "      prefetchable memory range "
452                        "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
453                        dev->pci_bridge->bus.prefetchable_range->base,
454                        dev->pci_bridge->bus.prefetchable_range->limit);
455     }
456
457     for (region = dev->regions; region; region = region->next) {
458         uint64_t addr, size;
459
460         addr = region->value->address;
461         size = region->value->size;
462
463         monitor_printf(mon, "      BAR%" PRId64 ": ", region->value->bar);
464
465         if (!strcmp(region->value->type, "io")) {
466             monitor_printf(mon, "I/O at 0x%04" PRIx64
467                                 " [0x%04" PRIx64 "].\n",
468                            addr, addr + size - 1);
469         } else {
470             monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
471                                " [0x%08" PRIx64 "].\n",
472                            region->value->mem_type_64 ? 64 : 32,
473                            region->value->prefetch ? " prefetchable" : "",
474                            addr, addr + size - 1);
475         }
476     }
477
478     monitor_printf(mon, "      id \"%s\"\n", dev->qdev_id);
479
480     if (dev->has_pci_bridge) {
481         if (dev->pci_bridge->has_devices) {
482             PciDeviceInfoList *cdev;
483             for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
484                 hmp_info_pci_device(mon, cdev->value);
485             }
486         }
487     }
488 }
489
490 void hmp_info_pci(Monitor *mon)
491 {
492     PciInfoList *info_list, *info;
493     Error *err = NULL;
494
495     info_list = qmp_query_pci(&err);
496     if (err) {
497         monitor_printf(mon, "PCI devices not supported\n");
498         error_free(err);
499         return;
500     }
501
502     for (info = info_list; info; info = info->next) {
503         PciDeviceInfoList *dev;
504
505         for (dev = info->value->devices; dev; dev = dev->next) {
506             hmp_info_pci_device(mon, dev->value);
507         }
508     }
509
510     qapi_free_PciInfoList(info_list);
511 }
512
513 void hmp_info_block_jobs(Monitor *mon)
514 {
515     BlockJobInfoList *list;
516     Error *err = NULL;
517
518     list = qmp_query_block_jobs(&err);
519     assert(!err);
520
521     if (!list) {
522         monitor_printf(mon, "No active jobs\n");
523         return;
524     }
525
526     while (list) {
527         if (strcmp(list->value->type, "stream") == 0) {
528             monitor_printf(mon, "Streaming device %s: Completed %" PRId64
529                            " of %" PRId64 " bytes, speed limit %" PRId64
530                            " bytes/s\n",
531                            list->value->device,
532                            list->value->offset,
533                            list->value->len,
534                            list->value->speed);
535         } else {
536             monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
537                            " of %" PRId64 " bytes, speed limit %" PRId64
538                            " bytes/s\n",
539                            list->value->type,
540                            list->value->device,
541                            list->value->offset,
542                            list->value->len,
543                            list->value->speed);
544         }
545         list = list->next;
546     }
547 }
548
549 void hmp_quit(Monitor *mon, const QDict *qdict)
550 {
551     monitor_suspend(mon);
552     qmp_quit(NULL);
553 }
554
555 void hmp_stop(Monitor *mon, const QDict *qdict)
556 {
557     qmp_stop(NULL);
558 }
559
560 void hmp_system_reset(Monitor *mon, const QDict *qdict)
561 {
562     qmp_system_reset(NULL);
563 }
564
565 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
566 {
567     qmp_system_powerdown(NULL);
568 }
569
570 void hmp_cpu(Monitor *mon, const QDict *qdict)
571 {
572     int64_t cpu_index;
573
574     /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
575             use it are converted to the QAPI */
576     cpu_index = qdict_get_int(qdict, "index");
577     if (monitor_set_cpu(cpu_index) < 0) {
578         monitor_printf(mon, "invalid CPU index\n");
579     }
580 }
581
582 void hmp_memsave(Monitor *mon, const QDict *qdict)
583 {
584     uint32_t size = qdict_get_int(qdict, "size");
585     const char *filename = qdict_get_str(qdict, "filename");
586     uint64_t addr = qdict_get_int(qdict, "val");
587     Error *errp = NULL;
588
589     qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &errp);
590     hmp_handle_error(mon, &errp);
591 }
592
593 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
594 {
595     uint32_t size = qdict_get_int(qdict, "size");
596     const char *filename = qdict_get_str(qdict, "filename");
597     uint64_t addr = qdict_get_int(qdict, "val");
598     Error *errp = NULL;
599
600     qmp_pmemsave(addr, size, filename, &errp);
601     hmp_handle_error(mon, &errp);
602 }
603
604 static void hmp_cont_cb(void *opaque, int err)
605 {
606     Monitor *mon = opaque;
607
608     if (!err) {
609         hmp_cont(mon, NULL);
610     }
611 }
612
613 void hmp_cont(Monitor *mon, const QDict *qdict)
614 {
615     Error *errp = NULL;
616
617     qmp_cont(&errp);
618     if (error_is_set(&errp)) {
619         if (error_is_type(errp, QERR_DEVICE_ENCRYPTED)) {
620             const char *device;
621
622             /* The device is encrypted. Ask the user for the password
623                and retry */
624
625             device = error_get_field(errp, "device");
626             assert(device != NULL);
627
628             monitor_read_block_device_key(mon, device, hmp_cont_cb, mon);
629             error_free(errp);
630             return;
631         }
632         hmp_handle_error(mon, &errp);
633     }
634 }
635
636 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
637 {
638     qmp_system_wakeup(NULL);
639 }
640
641 void hmp_inject_nmi(Monitor *mon, const QDict *qdict)
642 {
643     Error *errp = NULL;
644
645     qmp_inject_nmi(&errp);
646     hmp_handle_error(mon, &errp);
647 }
648
649 void hmp_set_link(Monitor *mon, const QDict *qdict)
650 {
651     const char *name = qdict_get_str(qdict, "name");
652     int up = qdict_get_bool(qdict, "up");
653     Error *errp = NULL;
654
655     qmp_set_link(name, up, &errp);
656     hmp_handle_error(mon, &errp);
657 }
658
659 void hmp_block_passwd(Monitor *mon, const QDict *qdict)
660 {
661     const char *device = qdict_get_str(qdict, "device");
662     const char *password = qdict_get_str(qdict, "password");
663     Error *errp = NULL;
664
665     qmp_block_passwd(device, password, &errp);
666     hmp_handle_error(mon, &errp);
667 }
668
669 void hmp_balloon(Monitor *mon, const QDict *qdict)
670 {
671     int64_t value = qdict_get_int(qdict, "value");
672     Error *errp = NULL;
673
674     qmp_balloon(value, &errp);
675     if (error_is_set(&errp)) {
676         monitor_printf(mon, "balloon: %s\n", error_get_pretty(errp));
677         error_free(errp);
678     }
679 }
680
681 void hmp_block_resize(Monitor *mon, const QDict *qdict)
682 {
683     const char *device = qdict_get_str(qdict, "device");
684     int64_t size = qdict_get_int(qdict, "size");
685     Error *errp = NULL;
686
687     qmp_block_resize(device, size, &errp);
688     hmp_handle_error(mon, &errp);
689 }
690
691 void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
692 {
693     const char *device = qdict_get_str(qdict, "device");
694     const char *filename = qdict_get_try_str(qdict, "snapshot-file");
695     const char *format = qdict_get_try_str(qdict, "format");
696     int reuse = qdict_get_try_bool(qdict, "reuse", 0);
697     enum NewImageMode mode;
698     Error *errp = NULL;
699
700     if (!filename) {
701         /* In the future, if 'snapshot-file' is not specified, the snapshot
702            will be taken internally. Today it's actually required. */
703         error_set(&errp, QERR_MISSING_PARAMETER, "snapshot-file");
704         hmp_handle_error(mon, &errp);
705         return;
706     }
707
708     mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
709     qmp_blockdev_snapshot_sync(device, filename, !!format, format,
710                                true, mode, &errp);
711     hmp_handle_error(mon, &errp);
712 }
713
714 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
715 {
716     qmp_migrate_cancel(NULL);
717 }
718
719 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
720 {
721     double value = qdict_get_double(qdict, "value");
722     qmp_migrate_set_downtime(value, NULL);
723 }
724
725 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
726 {
727     int64_t value = qdict_get_int(qdict, "value");
728     qmp_migrate_set_speed(value, NULL);
729 }
730
731 void hmp_set_password(Monitor *mon, const QDict *qdict)
732 {
733     const char *protocol  = qdict_get_str(qdict, "protocol");
734     const char *password  = qdict_get_str(qdict, "password");
735     const char *connected = qdict_get_try_str(qdict, "connected");
736     Error *err = NULL;
737
738     qmp_set_password(protocol, password, !!connected, connected, &err);
739     hmp_handle_error(mon, &err);
740 }
741
742 void hmp_expire_password(Monitor *mon, const QDict *qdict)
743 {
744     const char *protocol  = qdict_get_str(qdict, "protocol");
745     const char *whenstr = qdict_get_str(qdict, "time");
746     Error *err = NULL;
747
748     qmp_expire_password(protocol, whenstr, &err);
749     hmp_handle_error(mon, &err);
750 }
751
752 void hmp_eject(Monitor *mon, const QDict *qdict)
753 {
754     int force = qdict_get_try_bool(qdict, "force", 0);
755     const char *device = qdict_get_str(qdict, "device");
756     Error *err = NULL;
757
758     qmp_eject(device, true, force, &err);
759     hmp_handle_error(mon, &err);
760 }
761
762 static void hmp_change_read_arg(Monitor *mon, const char *password,
763                                 void *opaque)
764 {
765     qmp_change_vnc_password(password, NULL);
766     monitor_read_command(mon, 1);
767 }
768
769 static void cb_hmp_change_bdrv_pwd(Monitor *mon, const char *password,
770                                    void *opaque)
771 {
772     Error *encryption_err = opaque;
773     Error *err = NULL;
774     const char *device;
775
776     device = error_get_field(encryption_err, "device");
777
778     qmp_block_passwd(device, password, &err);
779     hmp_handle_error(mon, &err);
780     error_free(encryption_err);
781
782     monitor_read_command(mon, 1);
783 }
784
785 void hmp_change(Monitor *mon, const QDict *qdict)
786 {
787     const char *device = qdict_get_str(qdict, "device");
788     const char *target = qdict_get_str(qdict, "target");
789     const char *arg = qdict_get_try_str(qdict, "arg");
790     Error *err = NULL;
791
792     if (strcmp(device, "vnc") == 0 &&
793             (strcmp(target, "passwd") == 0 ||
794              strcmp(target, "password") == 0)) {
795         if (!arg) {
796             monitor_read_password(mon, hmp_change_read_arg, NULL);
797             return;
798         }
799     }
800
801     qmp_change(device, target, !!arg, arg, &err);
802     if (error_is_type(err, QERR_DEVICE_ENCRYPTED)) {
803         monitor_printf(mon, "%s (%s) is encrypted.\n",
804                        error_get_field(err, "device"),
805                        error_get_field(err, "filename"));
806         if (!monitor_get_rs(mon)) {
807             monitor_printf(mon,
808                     "terminal does not support password prompting\n");
809             error_free(err);
810             return;
811         }
812         readline_start(monitor_get_rs(mon), "Password: ", 1,
813                        cb_hmp_change_bdrv_pwd, err);
814         return;
815     }
816     hmp_handle_error(mon, &err);
817 }
818
819 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
820 {
821     Error *err = NULL;
822
823     qmp_block_set_io_throttle(qdict_get_str(qdict, "device"),
824                               qdict_get_int(qdict, "bps"),
825                               qdict_get_int(qdict, "bps_rd"),
826                               qdict_get_int(qdict, "bps_wr"),
827                               qdict_get_int(qdict, "iops"),
828                               qdict_get_int(qdict, "iops_rd"),
829                               qdict_get_int(qdict, "iops_wr"), &err);
830     hmp_handle_error(mon, &err);
831 }
832
833 void hmp_block_stream(Monitor *mon, const QDict *qdict)
834 {
835     Error *error = NULL;
836     const char *device = qdict_get_str(qdict, "device");
837     const char *base = qdict_get_try_str(qdict, "base");
838
839     qmp_block_stream(device, base != NULL, base, &error);
840
841     hmp_handle_error(mon, &error);
842 }
843
844 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
845 {
846     Error *error = NULL;
847     const char *device = qdict_get_str(qdict, "device");
848     int64_t value = qdict_get_int(qdict, "value");
849
850     qmp_block_job_set_speed(device, value, &error);
851
852     hmp_handle_error(mon, &error);
853 }
854
855 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
856 {
857     Error *error = NULL;
858     const char *device = qdict_get_str(qdict, "device");
859
860     qmp_block_job_cancel(device, &error);
861
862     hmp_handle_error(mon, &error);
863 }
864
865 typedef struct MigrationStatus
866 {
867     QEMUTimer *timer;
868     Monitor *mon;
869     bool is_block_migration;
870 } MigrationStatus;
871
872 static void hmp_migrate_status_cb(void *opaque)
873 {
874     MigrationStatus *status = opaque;
875     MigrationInfo *info;
876
877     info = qmp_query_migrate(NULL);
878     if (!info->has_status || strcmp(info->status, "active") == 0) {
879         if (info->has_disk) {
880             int progress;
881
882             if (info->disk->remaining) {
883                 progress = info->disk->transferred * 100 / info->disk->total;
884             } else {
885                 progress = 100;
886             }
887
888             monitor_printf(status->mon, "Completed %d %%\r", progress);
889             monitor_flush(status->mon);
890         }
891
892         qemu_mod_timer(status->timer, qemu_get_clock_ms(rt_clock) + 1000);
893     } else {
894         if (status->is_block_migration) {
895             monitor_printf(status->mon, "\n");
896         }
897         monitor_resume(status->mon);
898         qemu_del_timer(status->timer);
899         g_free(status);
900     }
901
902     qapi_free_MigrationInfo(info);
903 }
904
905 void hmp_migrate(Monitor *mon, const QDict *qdict)
906 {
907     int detach = qdict_get_try_bool(qdict, "detach", 0);
908     int blk = qdict_get_try_bool(qdict, "blk", 0);
909     int inc = qdict_get_try_bool(qdict, "inc", 0);
910     const char *uri = qdict_get_str(qdict, "uri");
911     Error *err = NULL;
912
913     qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
914     if (err) {
915         monitor_printf(mon, "migrate: %s\n", error_get_pretty(err));
916         error_free(err);
917         return;
918     }
919
920     if (!detach) {
921         MigrationStatus *status;
922
923         if (monitor_suspend(mon) < 0) {
924             monitor_printf(mon, "terminal does not allow synchronous "
925                            "migration, continuing detached\n");
926             return;
927         }
928
929         status = g_malloc0(sizeof(*status));
930         status->mon = mon;
931         status->is_block_migration = blk || inc;
932         status->timer = qemu_new_timer_ms(rt_clock, hmp_migrate_status_cb,
933                                           status);
934         qemu_mod_timer(status->timer, qemu_get_clock_ms(rt_clock));
935     }
936 }
This page took 0.154337 seconds and 4 git commands to generate.