1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include "hw/hw.h"
26#include "hw/boards.h"
27#include "sysemu/block-backend.h"
28#include "sysemu/blockdev.h"
29#include "qemu/config-file.h"
30#include "sysemu/sysemu.h"
31#include "monitor/monitor.h"
32
33static DriveInfo *add_init_drive(const char *optstr)
34{
35 DriveInfo *dinfo;
36 QemuOpts *opts;
37 MachineClass *mc;
38
39 opts = drive_def(optstr);
40 if (!opts)
41 return NULL;
42
43 mc = MACHINE_GET_CLASS(current_machine);
44 dinfo = drive_new(opts, mc->block_default_type);
45 if (!dinfo) {
46 qemu_opts_del(opts);
47 return NULL;
48 }
49
50 return dinfo;
51}
52
53void hmp_drive_add(Monitor *mon, const QDict *qdict)
54{
55 DriveInfo *dinfo = NULL;
56 const char *opts = qdict_get_str(qdict, "opts");
57
58 dinfo = add_init_drive(opts);
59 if (!dinfo) {
60 goto err;
61 }
62 if (dinfo->devaddr) {
63 monitor_printf(mon, "Parameter addr not supported\n");
64 goto err;
65 }
66
67 switch (dinfo->type) {
68 case IF_NONE:
69 monitor_printf(mon, "OK\n");
70 break;
71 default:
72 monitor_printf(mon, "Can't hot-add drive to type %d\n", dinfo->type);
73 goto err;
74 }
75 return;
76
77err:
78 if (dinfo) {
79 blk_unref(blk_by_legacy_dinfo(dinfo));
80 }
81}
82