root / blockdev.c @ f53f81e0
History | View | Annotate | Download (70.5 kB)
1 | 666daa68 | Markus Armbruster | /*
|
---|---|---|---|
2 | 666daa68 | Markus Armbruster | * QEMU host block devices
|
3 | 666daa68 | Markus Armbruster | *
|
4 | 666daa68 | Markus Armbruster | * Copyright (c) 2003-2008 Fabrice Bellard
|
5 | 666daa68 | Markus Armbruster | *
|
6 | 666daa68 | Markus Armbruster | * This work is licensed under the terms of the GNU GPL, version 2 or
|
7 | 666daa68 | Markus Armbruster | * later. See the COPYING file in the top-level directory.
|
8 | 3618a094 | Markus Armbruster | *
|
9 | 3618a094 | Markus Armbruster | * This file incorporates work covered by the following copyright and
|
10 | 3618a094 | Markus Armbruster | * permission notice:
|
11 | 3618a094 | Markus Armbruster | *
|
12 | 3618a094 | Markus Armbruster | * Copyright (c) 2003-2008 Fabrice Bellard
|
13 | 3618a094 | Markus Armbruster | *
|
14 | 3618a094 | Markus Armbruster | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
15 | 3618a094 | Markus Armbruster | * of this software and associated documentation files (the "Software"), to deal
|
16 | 3618a094 | Markus Armbruster | * in the Software without restriction, including without limitation the rights
|
17 | 3618a094 | Markus Armbruster | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
18 | 3618a094 | Markus Armbruster | * copies of the Software, and to permit persons to whom the Software is
|
19 | 3618a094 | Markus Armbruster | * furnished to do so, subject to the following conditions:
|
20 | 3618a094 | Markus Armbruster | *
|
21 | 3618a094 | Markus Armbruster | * The above copyright notice and this permission notice shall be included in
|
22 | 3618a094 | Markus Armbruster | * all copies or substantial portions of the Software.
|
23 | 3618a094 | Markus Armbruster | *
|
24 | 3618a094 | Markus Armbruster | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
25 | 3618a094 | Markus Armbruster | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
26 | 3618a094 | Markus Armbruster | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
27 | 3618a094 | Markus Armbruster | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
28 | 3618a094 | Markus Armbruster | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
29 | 3618a094 | Markus Armbruster | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
30 | 3618a094 | Markus Armbruster | * THE SOFTWARE.
|
31 | 666daa68 | Markus Armbruster | */
|
32 | 666daa68 | Markus Armbruster | |
33 | 9c17d615 | Paolo Bonzini | #include "sysemu/blockdev.h" |
34 | 0d09e41a | Paolo Bonzini | #include "hw/block/block.h" |
35 | 737e150e | Paolo Bonzini | #include "block/blockjob.h" |
36 | 83c9089e | Paolo Bonzini | #include "monitor/monitor.h" |
37 | 7b1b5d19 | Paolo Bonzini | #include "qapi/qmp/qerror.h" |
38 | 1de7afc9 | Paolo Bonzini | #include "qemu/option.h" |
39 | 1de7afc9 | Paolo Bonzini | #include "qemu/config-file.h" |
40 | 7b1b5d19 | Paolo Bonzini | #include "qapi/qmp/types.h" |
41 | d26c9a15 | Kevin Wolf | #include "qapi-visit.h" |
42 | d26c9a15 | Kevin Wolf | #include "qapi/qmp-output-visitor.h" |
43 | 9c17d615 | Paolo Bonzini | #include "sysemu/sysemu.h" |
44 | 737e150e | Paolo Bonzini | #include "block/block_int.h" |
45 | a4dea8a9 | Luiz Capitulino | #include "qmp-commands.h" |
46 | 12bd451f | Stefan Hajnoczi | #include "trace.h" |
47 | 9c17d615 | Paolo Bonzini | #include "sysemu/arch_init.h" |
48 | 666daa68 | Markus Armbruster | |
49 | c9b62a7e | Markus Armbruster | static QTAILQ_HEAD(drivelist, DriveInfo) drives = QTAILQ_HEAD_INITIALIZER(drives);
|
50 | 666daa68 | Markus Armbruster | |
51 | 1960966d | Markus Armbruster | static const char *const if_name[IF_COUNT] = { |
52 | 1960966d | Markus Armbruster | [IF_NONE] = "none",
|
53 | 1960966d | Markus Armbruster | [IF_IDE] = "ide",
|
54 | 1960966d | Markus Armbruster | [IF_SCSI] = "scsi",
|
55 | 1960966d | Markus Armbruster | [IF_FLOPPY] = "floppy",
|
56 | 1960966d | Markus Armbruster | [IF_PFLASH] = "pflash",
|
57 | 1960966d | Markus Armbruster | [IF_MTD] = "mtd",
|
58 | 1960966d | Markus Armbruster | [IF_SD] = "sd",
|
59 | 1960966d | Markus Armbruster | [IF_VIRTIO] = "virtio",
|
60 | 1960966d | Markus Armbruster | [IF_XEN] = "xen",
|
61 | 1960966d | Markus Armbruster | }; |
62 | 1960966d | Markus Armbruster | |
63 | 1960966d | Markus Armbruster | static const int if_max_devs[IF_COUNT] = { |
64 | 27d6bf40 | Markus Armbruster | /*
|
65 | 27d6bf40 | Markus Armbruster | * Do not change these numbers! They govern how drive option
|
66 | 27d6bf40 | Markus Armbruster | * index maps to unit and bus. That mapping is ABI.
|
67 | 27d6bf40 | Markus Armbruster | *
|
68 | 27d6bf40 | Markus Armbruster | * All controllers used to imlement if=T drives need to support
|
69 | 27d6bf40 | Markus Armbruster | * if_max_devs[T] units, for any T with if_max_devs[T] != 0.
|
70 | 27d6bf40 | Markus Armbruster | * Otherwise, some index values map to "impossible" bus, unit
|
71 | 27d6bf40 | Markus Armbruster | * values.
|
72 | 27d6bf40 | Markus Armbruster | *
|
73 | 27d6bf40 | Markus Armbruster | * For instance, if you change [IF_SCSI] to 255, -drive
|
74 | 27d6bf40 | Markus Armbruster | * if=scsi,index=12 no longer means bus=1,unit=5, but
|
75 | 27d6bf40 | Markus Armbruster | * bus=0,unit=12. With an lsi53c895a controller (7 units max),
|
76 | 27d6bf40 | Markus Armbruster | * the drive can't be set up. Regression.
|
77 | 27d6bf40 | Markus Armbruster | */
|
78 | 27d6bf40 | Markus Armbruster | [IF_IDE] = 2,
|
79 | 27d6bf40 | Markus Armbruster | [IF_SCSI] = 7,
|
80 | 1960966d | Markus Armbruster | }; |
81 | 1960966d | Markus Armbruster | |
82 | 14bafc54 | Markus Armbruster | /*
|
83 | 14bafc54 | Markus Armbruster | * We automatically delete the drive when a device using it gets
|
84 | 14bafc54 | Markus Armbruster | * unplugged. Questionable feature, but we can't just drop it.
|
85 | 14bafc54 | Markus Armbruster | * Device models call blockdev_mark_auto_del() to schedule the
|
86 | 14bafc54 | Markus Armbruster | * automatic deletion, and generic qdev code calls blockdev_auto_del()
|
87 | 14bafc54 | Markus Armbruster | * when deletion is actually safe.
|
88 | 14bafc54 | Markus Armbruster | */
|
89 | 14bafc54 | Markus Armbruster | void blockdev_mark_auto_del(BlockDriverState *bs)
|
90 | 14bafc54 | Markus Armbruster | { |
91 | 14bafc54 | Markus Armbruster | DriveInfo *dinfo = drive_get_by_blockdev(bs); |
92 | 14bafc54 | Markus Armbruster | |
93 | 2d246f01 | Kevin Wolf | if (dinfo && !dinfo->enable_auto_del) {
|
94 | 2d246f01 | Kevin Wolf | return;
|
95 | 2d246f01 | Kevin Wolf | } |
96 | 2d246f01 | Kevin Wolf | |
97 | 12bde0ee | Paolo Bonzini | if (bs->job) {
|
98 | 12bde0ee | Paolo Bonzini | block_job_cancel(bs->job); |
99 | 12bde0ee | Paolo Bonzini | } |
100 | 0fc0f1fa | Ryan Harper | if (dinfo) {
|
101 | 0fc0f1fa | Ryan Harper | dinfo->auto_del = 1;
|
102 | 0fc0f1fa | Ryan Harper | } |
103 | 14bafc54 | Markus Armbruster | } |
104 | 14bafc54 | Markus Armbruster | |
105 | 14bafc54 | Markus Armbruster | void blockdev_auto_del(BlockDriverState *bs)
|
106 | 14bafc54 | Markus Armbruster | { |
107 | 14bafc54 | Markus Armbruster | DriveInfo *dinfo = drive_get_by_blockdev(bs); |
108 | 14bafc54 | Markus Armbruster | |
109 | 0fc0f1fa | Ryan Harper | if (dinfo && dinfo->auto_del) {
|
110 | 84fb3925 | Marcelo Tosatti | drive_put_ref(dinfo); |
111 | 14bafc54 | Markus Armbruster | } |
112 | 14bafc54 | Markus Armbruster | } |
113 | 14bafc54 | Markus Armbruster | |
114 | 505a7fb1 | Markus Armbruster | static int drive_index_to_bus_id(BlockInterfaceType type, int index) |
115 | 505a7fb1 | Markus Armbruster | { |
116 | 505a7fb1 | Markus Armbruster | int max_devs = if_max_devs[type];
|
117 | 505a7fb1 | Markus Armbruster | return max_devs ? index / max_devs : 0; |
118 | 505a7fb1 | Markus Armbruster | } |
119 | 505a7fb1 | Markus Armbruster | |
120 | 505a7fb1 | Markus Armbruster | static int drive_index_to_unit_id(BlockInterfaceType type, int index) |
121 | 505a7fb1 | Markus Armbruster | { |
122 | 505a7fb1 | Markus Armbruster | int max_devs = if_max_devs[type];
|
123 | 505a7fb1 | Markus Armbruster | return max_devs ? index % max_devs : index;
|
124 | 505a7fb1 | Markus Armbruster | } |
125 | 505a7fb1 | Markus Armbruster | |
126 | 2292ddae | Markus Armbruster | QemuOpts *drive_def(const char *optstr) |
127 | 2292ddae | Markus Armbruster | { |
128 | 2292ddae | Markus Armbruster | return qemu_opts_parse(qemu_find_opts("drive"), optstr, 0); |
129 | 2292ddae | Markus Armbruster | } |
130 | 2292ddae | Markus Armbruster | |
131 | 2292ddae | Markus Armbruster | QemuOpts *drive_add(BlockInterfaceType type, int index, const char *file, |
132 | 5645b0f4 | Markus Armbruster | const char *optstr) |
133 | 666daa68 | Markus Armbruster | { |
134 | 666daa68 | Markus Armbruster | QemuOpts *opts; |
135 | 2292ddae | Markus Armbruster | char buf[32]; |
136 | 666daa68 | Markus Armbruster | |
137 | 2292ddae | Markus Armbruster | opts = drive_def(optstr); |
138 | 666daa68 | Markus Armbruster | if (!opts) {
|
139 | 666daa68 | Markus Armbruster | return NULL; |
140 | 666daa68 | Markus Armbruster | } |
141 | 2292ddae | Markus Armbruster | if (type != IF_DEFAULT) {
|
142 | 2292ddae | Markus Armbruster | qemu_opt_set(opts, "if", if_name[type]);
|
143 | 2292ddae | Markus Armbruster | } |
144 | 2292ddae | Markus Armbruster | if (index >= 0) { |
145 | 2292ddae | Markus Armbruster | snprintf(buf, sizeof(buf), "%d", index); |
146 | 2292ddae | Markus Armbruster | qemu_opt_set(opts, "index", buf);
|
147 | 2292ddae | Markus Armbruster | } |
148 | 666daa68 | Markus Armbruster | if (file)
|
149 | 666daa68 | Markus Armbruster | qemu_opt_set(opts, "file", file);
|
150 | 666daa68 | Markus Armbruster | return opts;
|
151 | 666daa68 | Markus Armbruster | } |
152 | 666daa68 | Markus Armbruster | |
153 | 666daa68 | Markus Armbruster | DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit) |
154 | 666daa68 | Markus Armbruster | { |
155 | 666daa68 | Markus Armbruster | DriveInfo *dinfo; |
156 | 666daa68 | Markus Armbruster | |
157 | 666daa68 | Markus Armbruster | /* seek interface, bus and unit */
|
158 | 666daa68 | Markus Armbruster | |
159 | 666daa68 | Markus Armbruster | QTAILQ_FOREACH(dinfo, &drives, next) { |
160 | 666daa68 | Markus Armbruster | if (dinfo->type == type &&
|
161 | 666daa68 | Markus Armbruster | dinfo->bus == bus && |
162 | 666daa68 | Markus Armbruster | dinfo->unit == unit) |
163 | 666daa68 | Markus Armbruster | return dinfo;
|
164 | 666daa68 | Markus Armbruster | } |
165 | 666daa68 | Markus Armbruster | |
166 | 666daa68 | Markus Armbruster | return NULL; |
167 | 666daa68 | Markus Armbruster | } |
168 | 666daa68 | Markus Armbruster | |
169 | f1bd51ac | Markus Armbruster | DriveInfo *drive_get_by_index(BlockInterfaceType type, int index)
|
170 | f1bd51ac | Markus Armbruster | { |
171 | f1bd51ac | Markus Armbruster | return drive_get(type,
|
172 | f1bd51ac | Markus Armbruster | drive_index_to_bus_id(type, index), |
173 | f1bd51ac | Markus Armbruster | drive_index_to_unit_id(type, index)); |
174 | f1bd51ac | Markus Armbruster | } |
175 | f1bd51ac | Markus Armbruster | |
176 | 666daa68 | Markus Armbruster | int drive_get_max_bus(BlockInterfaceType type)
|
177 | 666daa68 | Markus Armbruster | { |
178 | 666daa68 | Markus Armbruster | int max_bus;
|
179 | 666daa68 | Markus Armbruster | DriveInfo *dinfo; |
180 | 666daa68 | Markus Armbruster | |
181 | 666daa68 | Markus Armbruster | max_bus = -1;
|
182 | 666daa68 | Markus Armbruster | QTAILQ_FOREACH(dinfo, &drives, next) { |
183 | 666daa68 | Markus Armbruster | if(dinfo->type == type &&
|
184 | 666daa68 | Markus Armbruster | dinfo->bus > max_bus) |
185 | 666daa68 | Markus Armbruster | max_bus = dinfo->bus; |
186 | 666daa68 | Markus Armbruster | } |
187 | 666daa68 | Markus Armbruster | return max_bus;
|
188 | 666daa68 | Markus Armbruster | } |
189 | 666daa68 | Markus Armbruster | |
190 | 13839974 | Markus Armbruster | /* Get a block device. This should only be used for single-drive devices
|
191 | 13839974 | Markus Armbruster | (e.g. SD/Floppy/MTD). Multi-disk devices (scsi/ide) should use the
|
192 | 13839974 | Markus Armbruster | appropriate bus. */
|
193 | 13839974 | Markus Armbruster | DriveInfo *drive_get_next(BlockInterfaceType type) |
194 | 13839974 | Markus Armbruster | { |
195 | 13839974 | Markus Armbruster | static int next_block_unit[IF_COUNT]; |
196 | 13839974 | Markus Armbruster | |
197 | 13839974 | Markus Armbruster | return drive_get(type, 0, next_block_unit[type]++); |
198 | 13839974 | Markus Armbruster | } |
199 | 13839974 | Markus Armbruster | |
200 | e4700e59 | Markus Armbruster | DriveInfo *drive_get_by_blockdev(BlockDriverState *bs) |
201 | 666daa68 | Markus Armbruster | { |
202 | 666daa68 | Markus Armbruster | DriveInfo *dinfo; |
203 | 666daa68 | Markus Armbruster | |
204 | 666daa68 | Markus Armbruster | QTAILQ_FOREACH(dinfo, &drives, next) { |
205 | e4700e59 | Markus Armbruster | if (dinfo->bdrv == bs) {
|
206 | e4700e59 | Markus Armbruster | return dinfo;
|
207 | e4700e59 | Markus Armbruster | } |
208 | 666daa68 | Markus Armbruster | } |
209 | e4700e59 | Markus Armbruster | return NULL; |
210 | 666daa68 | Markus Armbruster | } |
211 | 666daa68 | Markus Armbruster | |
212 | 666daa68 | Markus Armbruster | static void bdrv_format_print(void *opaque, const char *name) |
213 | 666daa68 | Markus Armbruster | { |
214 | 807105a7 | Markus Armbruster | error_printf(" %s", name);
|
215 | 666daa68 | Markus Armbruster | } |
216 | 666daa68 | Markus Armbruster | |
217 | 84fb3925 | Marcelo Tosatti | static void drive_uninit(DriveInfo *dinfo) |
218 | 666daa68 | Markus Armbruster | { |
219 | f298d071 | Kevin Wolf | if (dinfo->opts) {
|
220 | f298d071 | Kevin Wolf | qemu_opts_del(dinfo->opts); |
221 | f298d071 | Kevin Wolf | } |
222 | f298d071 | Kevin Wolf | |
223 | 4f6fd349 | Fam Zheng | bdrv_unref(dinfo->bdrv); |
224 | 7267c094 | Anthony Liguori | g_free(dinfo->id); |
225 | 666daa68 | Markus Armbruster | QTAILQ_REMOVE(&drives, dinfo, next); |
226 | bb44619b | Kevin Wolf | g_free(dinfo->serial); |
227 | 7267c094 | Anthony Liguori | g_free(dinfo); |
228 | 666daa68 | Markus Armbruster | } |
229 | 666daa68 | Markus Armbruster | |
230 | 84fb3925 | Marcelo Tosatti | void drive_put_ref(DriveInfo *dinfo)
|
231 | 84fb3925 | Marcelo Tosatti | { |
232 | 84fb3925 | Marcelo Tosatti | assert(dinfo->refcount); |
233 | 84fb3925 | Marcelo Tosatti | if (--dinfo->refcount == 0) { |
234 | 84fb3925 | Marcelo Tosatti | drive_uninit(dinfo); |
235 | 84fb3925 | Marcelo Tosatti | } |
236 | 84fb3925 | Marcelo Tosatti | } |
237 | 84fb3925 | Marcelo Tosatti | |
238 | 84fb3925 | Marcelo Tosatti | void drive_get_ref(DriveInfo *dinfo)
|
239 | 84fb3925 | Marcelo Tosatti | { |
240 | 84fb3925 | Marcelo Tosatti | dinfo->refcount++; |
241 | 84fb3925 | Marcelo Tosatti | } |
242 | 84fb3925 | Marcelo Tosatti | |
243 | aa398a5c | Stefan Hajnoczi | typedef struct { |
244 | aa398a5c | Stefan Hajnoczi | QEMUBH *bh; |
245 | fa510ebf | Fam Zheng | BlockDriverState *bs; |
246 | fa510ebf | Fam Zheng | } BDRVPutRefBH; |
247 | aa398a5c | Stefan Hajnoczi | |
248 | fa510ebf | Fam Zheng | static void bdrv_put_ref_bh(void *opaque) |
249 | aa398a5c | Stefan Hajnoczi | { |
250 | fa510ebf | Fam Zheng | BDRVPutRefBH *s = opaque; |
251 | aa398a5c | Stefan Hajnoczi | |
252 | fa510ebf | Fam Zheng | bdrv_unref(s->bs); |
253 | aa398a5c | Stefan Hajnoczi | qemu_bh_delete(s->bh); |
254 | aa398a5c | Stefan Hajnoczi | g_free(s); |
255 | aa398a5c | Stefan Hajnoczi | } |
256 | aa398a5c | Stefan Hajnoczi | |
257 | aa398a5c | Stefan Hajnoczi | /*
|
258 | fa510ebf | Fam Zheng | * Release a BDS reference in a BH
|
259 | aa398a5c | Stefan Hajnoczi | *
|
260 | fa510ebf | Fam Zheng | * It is not safe to use bdrv_unref() from a callback function when the callers
|
261 | fa510ebf | Fam Zheng | * still need the BlockDriverState. In such cases we schedule a BH to release
|
262 | fa510ebf | Fam Zheng | * the reference.
|
263 | aa398a5c | Stefan Hajnoczi | */
|
264 | fa510ebf | Fam Zheng | static void bdrv_put_ref_bh_schedule(BlockDriverState *bs) |
265 | aa398a5c | Stefan Hajnoczi | { |
266 | fa510ebf | Fam Zheng | BDRVPutRefBH *s; |
267 | aa398a5c | Stefan Hajnoczi | |
268 | fa510ebf | Fam Zheng | s = g_new(BDRVPutRefBH, 1);
|
269 | fa510ebf | Fam Zheng | s->bh = qemu_bh_new(bdrv_put_ref_bh, s); |
270 | fa510ebf | Fam Zheng | s->bs = bs; |
271 | aa398a5c | Stefan Hajnoczi | qemu_bh_schedule(s->bh); |
272 | aa398a5c | Stefan Hajnoczi | } |
273 | aa398a5c | Stefan Hajnoczi | |
274 | b681072d | Kevin Wolf | static int parse_block_error_action(const char *buf, bool is_read, Error **errp) |
275 | 666daa68 | Markus Armbruster | { |
276 | 666daa68 | Markus Armbruster | if (!strcmp(buf, "ignore")) { |
277 | 92aa5c6d | Paolo Bonzini | return BLOCKDEV_ON_ERROR_IGNORE;
|
278 | 666daa68 | Markus Armbruster | } else if (!is_read && !strcmp(buf, "enospc")) { |
279 | 92aa5c6d | Paolo Bonzini | return BLOCKDEV_ON_ERROR_ENOSPC;
|
280 | 666daa68 | Markus Armbruster | } else if (!strcmp(buf, "stop")) { |
281 | 92aa5c6d | Paolo Bonzini | return BLOCKDEV_ON_ERROR_STOP;
|
282 | 666daa68 | Markus Armbruster | } else if (!strcmp(buf, "report")) { |
283 | 92aa5c6d | Paolo Bonzini | return BLOCKDEV_ON_ERROR_REPORT;
|
284 | 666daa68 | Markus Armbruster | } else {
|
285 | b681072d | Kevin Wolf | error_setg(errp, "'%s' invalid %s error action",
|
286 | b681072d | Kevin Wolf | buf, is_read ? "read" : "write"); |
287 | 666daa68 | Markus Armbruster | return -1; |
288 | 666daa68 | Markus Armbruster | } |
289 | 666daa68 | Markus Armbruster | } |
290 | 666daa68 | Markus Armbruster | |
291 | cc0681c4 | Benoît Canet | static bool check_throttle_config(ThrottleConfig *cfg, Error **errp) |
292 | 0563e191 | Zhi Yong Wu | { |
293 | cc0681c4 | Benoît Canet | if (throttle_conflicting(cfg)) {
|
294 | cc0681c4 | Benoît Canet | error_setg(errp, "bps/iops/max total values and read/write values"
|
295 | cc0681c4 | Benoît Canet | " cannot be used at the same time");
|
296 | 0563e191 | Zhi Yong Wu | return false; |
297 | 0563e191 | Zhi Yong Wu | } |
298 | 0563e191 | Zhi Yong Wu | |
299 | cc0681c4 | Benoît Canet | if (!throttle_is_valid(cfg)) {
|
300 | cc0681c4 | Benoît Canet | error_setg(errp, "bps/iops/maxs values must be 0 or greater");
|
301 | 7d81c141 | Stefan Hajnoczi | return false; |
302 | 7d81c141 | Stefan Hajnoczi | } |
303 | 7d81c141 | Stefan Hajnoczi | |
304 | 0563e191 | Zhi Yong Wu | return true; |
305 | 0563e191 | Zhi Yong Wu | } |
306 | 0563e191 | Zhi Yong Wu | |
307 | 33cb7dc8 | Kevin Wolf | typedef enum { MEDIA_DISK, MEDIA_CDROM } DriveMediaType; |
308 | 33cb7dc8 | Kevin Wolf | |
309 | f298d071 | Kevin Wolf | /* Takes the ownership of bs_opts */
|
310 | d095b465 | Max Reitz | static DriveInfo *blockdev_init(const char *file, QDict *bs_opts, |
311 | b681072d | Kevin Wolf | Error **errp) |
312 | 666daa68 | Markus Armbruster | { |
313 | 666daa68 | Markus Armbruster | const char *buf; |
314 | 666daa68 | Markus Armbruster | const char *serial; |
315 | 666daa68 | Markus Armbruster | int ro = 0; |
316 | 666daa68 | Markus Armbruster | int bdrv_flags = 0; |
317 | 666daa68 | Markus Armbruster | int on_read_error, on_write_error;
|
318 | 666daa68 | Markus Armbruster | DriveInfo *dinfo; |
319 | cc0681c4 | Benoît Canet | ThrottleConfig cfg; |
320 | 666daa68 | Markus Armbruster | int snapshot = 0; |
321 | fb0490f6 | Stefan Hajnoczi | bool copy_on_read;
|
322 | 666daa68 | Markus Armbruster | int ret;
|
323 | c546194f | Stefan Hajnoczi | Error *error = NULL;
|
324 | 0006383e | Kevin Wolf | QemuOpts *opts; |
325 | 0006383e | Kevin Wolf | const char *id; |
326 | 74fe54f2 | Kevin Wolf | bool has_driver_specific_opts;
|
327 | 6db5f5d6 | Mike Qiu | BlockDriver *drv = NULL;
|
328 | 666daa68 | Markus Armbruster | |
329 | f298d071 | Kevin Wolf | /* Check common options by copying from bs_opts to opts, all other options
|
330 | f298d071 | Kevin Wolf | * stay in bs_opts for processing by bdrv_open(). */
|
331 | f298d071 | Kevin Wolf | id = qdict_get_try_str(bs_opts, "id");
|
332 | 0006383e | Kevin Wolf | opts = qemu_opts_create(&qemu_common_drive_opts, id, 1, &error);
|
333 | 84d18f06 | Markus Armbruster | if (error) {
|
334 | b681072d | Kevin Wolf | error_propagate(errp, error); |
335 | 0006383e | Kevin Wolf | return NULL; |
336 | 0006383e | Kevin Wolf | } |
337 | 0006383e | Kevin Wolf | |
338 | 0006383e | Kevin Wolf | qemu_opts_absorb_qdict(opts, bs_opts, &error); |
339 | 84d18f06 | Markus Armbruster | if (error) {
|
340 | b681072d | Kevin Wolf | error_propagate(errp, error); |
341 | ec9c10d2 | Stefan Hajnoczi | goto early_err;
|
342 | 0006383e | Kevin Wolf | } |
343 | 0006383e | Kevin Wolf | |
344 | 0006383e | Kevin Wolf | if (id) {
|
345 | 0006383e | Kevin Wolf | qdict_del(bs_opts, "id");
|
346 | 0006383e | Kevin Wolf | } |
347 | 0006383e | Kevin Wolf | |
348 | 74fe54f2 | Kevin Wolf | has_driver_specific_opts = !!qdict_size(bs_opts); |
349 | 74fe54f2 | Kevin Wolf | |
350 | 666daa68 | Markus Armbruster | /* extract parameters */
|
351 | 666daa68 | Markus Armbruster | snapshot = qemu_opt_get_bool(opts, "snapshot", 0); |
352 | 0f227a94 | Kevin Wolf | ro = qemu_opt_get_bool(opts, "read-only", 0); |
353 | fb0490f6 | Stefan Hajnoczi | copy_on_read = qemu_opt_get_bool(opts, "copy-on-read", false); |
354 | 666daa68 | Markus Armbruster | |
355 | 666daa68 | Markus Armbruster | serial = qemu_opt_get(opts, "serial");
|
356 | 666daa68 | Markus Armbruster | |
357 | a9384aff | Paolo Bonzini | if ((buf = qemu_opt_get(opts, "discard")) != NULL) { |
358 | a9384aff | Paolo Bonzini | if (bdrv_parse_discard_flags(buf, &bdrv_flags) != 0) { |
359 | b681072d | Kevin Wolf | error_setg(errp, "invalid discard option");
|
360 | ec9c10d2 | Stefan Hajnoczi | goto early_err;
|
361 | a9384aff | Paolo Bonzini | } |
362 | a9384aff | Paolo Bonzini | } |
363 | a9384aff | Paolo Bonzini | |
364 | 29c4e2b5 | Kevin Wolf | if (qemu_opt_get_bool(opts, "cache.writeback", true)) { |
365 | 29c4e2b5 | Kevin Wolf | bdrv_flags |= BDRV_O_CACHE_WB; |
366 | 29c4e2b5 | Kevin Wolf | } |
367 | 29c4e2b5 | Kevin Wolf | if (qemu_opt_get_bool(opts, "cache.direct", false)) { |
368 | 29c4e2b5 | Kevin Wolf | bdrv_flags |= BDRV_O_NOCACHE; |
369 | 29c4e2b5 | Kevin Wolf | } |
370 | 1df6fa4b | Paolo Bonzini | if (qemu_opt_get_bool(opts, "cache.no-flush", false)) { |
371 | 29c4e2b5 | Kevin Wolf | bdrv_flags |= BDRV_O_NO_FLUSH; |
372 | 666daa68 | Markus Armbruster | } |
373 | 666daa68 | Markus Armbruster | |
374 | 666daa68 | Markus Armbruster | #ifdef CONFIG_LINUX_AIO
|
375 | 666daa68 | Markus Armbruster | if ((buf = qemu_opt_get(opts, "aio")) != NULL) { |
376 | 666daa68 | Markus Armbruster | if (!strcmp(buf, "native")) { |
377 | 666daa68 | Markus Armbruster | bdrv_flags |= BDRV_O_NATIVE_AIO; |
378 | 666daa68 | Markus Armbruster | } else if (!strcmp(buf, "threads")) { |
379 | 666daa68 | Markus Armbruster | /* this is the default */
|
380 | 666daa68 | Markus Armbruster | } else {
|
381 | b681072d | Kevin Wolf | error_setg(errp, "invalid aio option");
|
382 | ec9c10d2 | Stefan Hajnoczi | goto early_err;
|
383 | 666daa68 | Markus Armbruster | } |
384 | 666daa68 | Markus Armbruster | } |
385 | 666daa68 | Markus Armbruster | #endif
|
386 | 666daa68 | Markus Armbruster | |
387 | 666daa68 | Markus Armbruster | if ((buf = qemu_opt_get(opts, "format")) != NULL) { |
388 | c8057f95 | Peter Maydell | if (is_help_option(buf)) {
|
389 | c8057f95 | Peter Maydell | error_printf("Supported formats:");
|
390 | c8057f95 | Peter Maydell | bdrv_iterate_format(bdrv_format_print, NULL);
|
391 | c8057f95 | Peter Maydell | error_printf("\n");
|
392 | ec9c10d2 | Stefan Hajnoczi | goto early_err;
|
393 | 666daa68 | Markus Armbruster | } |
394 | 74fe54f2 | Kevin Wolf | |
395 | 8f94a6e4 | Kevin Wolf | drv = bdrv_find_format(buf); |
396 | 6db5f5d6 | Mike Qiu | if (!drv) {
|
397 | b681072d | Kevin Wolf | error_setg(errp, "'%s' invalid format", buf);
|
398 | ec9c10d2 | Stefan Hajnoczi | goto early_err;
|
399 | 6db5f5d6 | Mike Qiu | } |
400 | 666daa68 | Markus Armbruster | } |
401 | 666daa68 | Markus Armbruster | |
402 | 0563e191 | Zhi Yong Wu | /* disk I/O throttling */
|
403 | cc0681c4 | Benoît Canet | memset(&cfg, 0, sizeof(cfg)); |
404 | cc0681c4 | Benoît Canet | cfg.buckets[THROTTLE_BPS_TOTAL].avg = |
405 | 57975222 | Kevin Wolf | qemu_opt_get_number(opts, "throttling.bps-total", 0); |
406 | cc0681c4 | Benoît Canet | cfg.buckets[THROTTLE_BPS_READ].avg = |
407 | 57975222 | Kevin Wolf | qemu_opt_get_number(opts, "throttling.bps-read", 0); |
408 | cc0681c4 | Benoît Canet | cfg.buckets[THROTTLE_BPS_WRITE].avg = |
409 | 57975222 | Kevin Wolf | qemu_opt_get_number(opts, "throttling.bps-write", 0); |
410 | cc0681c4 | Benoît Canet | cfg.buckets[THROTTLE_OPS_TOTAL].avg = |
411 | 57975222 | Kevin Wolf | qemu_opt_get_number(opts, "throttling.iops-total", 0); |
412 | cc0681c4 | Benoît Canet | cfg.buckets[THROTTLE_OPS_READ].avg = |
413 | 57975222 | Kevin Wolf | qemu_opt_get_number(opts, "throttling.iops-read", 0); |
414 | cc0681c4 | Benoît Canet | cfg.buckets[THROTTLE_OPS_WRITE].avg = |
415 | 57975222 | Kevin Wolf | qemu_opt_get_number(opts, "throttling.iops-write", 0); |
416 | 0563e191 | Zhi Yong Wu | |
417 | 3e9fab69 | Benoît Canet | cfg.buckets[THROTTLE_BPS_TOTAL].max = |
418 | 3e9fab69 | Benoît Canet | qemu_opt_get_number(opts, "throttling.bps-total-max", 0); |
419 | 3e9fab69 | Benoît Canet | cfg.buckets[THROTTLE_BPS_READ].max = |
420 | 3e9fab69 | Benoît Canet | qemu_opt_get_number(opts, "throttling.bps-read-max", 0); |
421 | 3e9fab69 | Benoît Canet | cfg.buckets[THROTTLE_BPS_WRITE].max = |
422 | 3e9fab69 | Benoît Canet | qemu_opt_get_number(opts, "throttling.bps-write-max", 0); |
423 | 3e9fab69 | Benoît Canet | cfg.buckets[THROTTLE_OPS_TOTAL].max = |
424 | 3e9fab69 | Benoît Canet | qemu_opt_get_number(opts, "throttling.iops-total-max", 0); |
425 | 3e9fab69 | Benoît Canet | cfg.buckets[THROTTLE_OPS_READ].max = |
426 | 3e9fab69 | Benoît Canet | qemu_opt_get_number(opts, "throttling.iops-read-max", 0); |
427 | 3e9fab69 | Benoît Canet | cfg.buckets[THROTTLE_OPS_WRITE].max = |
428 | 3e9fab69 | Benoît Canet | qemu_opt_get_number(opts, "throttling.iops-write-max", 0); |
429 | cc0681c4 | Benoît Canet | |
430 | 2024c1df | Benoît Canet | cfg.op_size = qemu_opt_get_number(opts, "throttling.iops-size", 0); |
431 | cc0681c4 | Benoît Canet | |
432 | cc0681c4 | Benoît Canet | if (!check_throttle_config(&cfg, &error)) {
|
433 | b681072d | Kevin Wolf | error_propagate(errp, error); |
434 | ec9c10d2 | Stefan Hajnoczi | goto early_err;
|
435 | 0563e191 | Zhi Yong Wu | } |
436 | 0563e191 | Zhi Yong Wu | |
437 | 92aa5c6d | Paolo Bonzini | on_write_error = BLOCKDEV_ON_ERROR_ENOSPC; |
438 | 666daa68 | Markus Armbruster | if ((buf = qemu_opt_get(opts, "werror")) != NULL) { |
439 | b681072d | Kevin Wolf | on_write_error = parse_block_error_action(buf, 0, &error);
|
440 | 84d18f06 | Markus Armbruster | if (error) {
|
441 | b681072d | Kevin Wolf | error_propagate(errp, error); |
442 | ec9c10d2 | Stefan Hajnoczi | goto early_err;
|
443 | 666daa68 | Markus Armbruster | } |
444 | 666daa68 | Markus Armbruster | } |
445 | 666daa68 | Markus Armbruster | |
446 | 92aa5c6d | Paolo Bonzini | on_read_error = BLOCKDEV_ON_ERROR_REPORT; |
447 | 666daa68 | Markus Armbruster | if ((buf = qemu_opt_get(opts, "rerror")) != NULL) { |
448 | b681072d | Kevin Wolf | on_read_error = parse_block_error_action(buf, 1, &error);
|
449 | 84d18f06 | Markus Armbruster | if (error) {
|
450 | b681072d | Kevin Wolf | error_propagate(errp, error); |
451 | ec9c10d2 | Stefan Hajnoczi | goto early_err;
|
452 | 666daa68 | Markus Armbruster | } |
453 | 666daa68 | Markus Armbruster | } |
454 | 666daa68 | Markus Armbruster | |
455 | 0c5e94ee | Benoît Canet | if (bdrv_find_node(qemu_opts_id(opts))) {
|
456 | 0c5e94ee | Benoît Canet | error_setg(errp, "device id=%s is conflicting with a node-name",
|
457 | 0c5e94ee | Benoît Canet | qemu_opts_id(opts)); |
458 | 0c5e94ee | Benoît Canet | goto early_err;
|
459 | 0c5e94ee | Benoît Canet | } |
460 | 0c5e94ee | Benoît Canet | |
461 | 326642bc | Kevin Wolf | /* init */
|
462 | 326642bc | Kevin Wolf | dinfo = g_malloc0(sizeof(*dinfo));
|
463 | 326642bc | Kevin Wolf | dinfo->id = g_strdup(qemu_opts_id(opts)); |
464 | 666daa68 | Markus Armbruster | dinfo->bdrv = bdrv_new(dinfo->id); |
465 | 80dd1aae | Kevin Shanahan | dinfo->bdrv->open_flags = snapshot ? BDRV_O_SNAPSHOT : 0;
|
466 | 80dd1aae | Kevin Shanahan | dinfo->bdrv->read_only = ro; |
467 | 84fb3925 | Marcelo Tosatti | dinfo->refcount = 1;
|
468 | bb44619b | Kevin Wolf | if (serial != NULL) { |
469 | bb44619b | Kevin Wolf | dinfo->serial = g_strdup(serial); |
470 | bb44619b | Kevin Wolf | } |
471 | 666daa68 | Markus Armbruster | QTAILQ_INSERT_TAIL(&drives, dinfo, next); |
472 | 666daa68 | Markus Armbruster | |
473 | abd7f68d | Markus Armbruster | bdrv_set_on_error(dinfo->bdrv, on_read_error, on_write_error); |
474 | abd7f68d | Markus Armbruster | |
475 | 0563e191 | Zhi Yong Wu | /* disk I/O throttling */
|
476 | cc0681c4 | Benoît Canet | if (throttle_enabled(&cfg)) {
|
477 | cc0681c4 | Benoît Canet | bdrv_io_limits_enable(dinfo->bdrv); |
478 | cc0681c4 | Benoît Canet | bdrv_set_io_limits(dinfo->bdrv, &cfg); |
479 | cc0681c4 | Benoît Canet | } |
480 | 0563e191 | Zhi Yong Wu | |
481 | dd5b0d71 | Markus Armbruster | if (!file || !*file) {
|
482 | 74fe54f2 | Kevin Wolf | if (has_driver_specific_opts) {
|
483 | c2ad1b0c | Kevin Wolf | file = NULL;
|
484 | c2ad1b0c | Kevin Wolf | } else {
|
485 | ec9c10d2 | Stefan Hajnoczi | QDECREF(bs_opts); |
486 | ec9c10d2 | Stefan Hajnoczi | qemu_opts_del(opts); |
487 | c2ad1b0c | Kevin Wolf | return dinfo;
|
488 | c2ad1b0c | Kevin Wolf | } |
489 | 666daa68 | Markus Armbruster | } |
490 | 666daa68 | Markus Armbruster | if (snapshot) {
|
491 | 666daa68 | Markus Armbruster | /* always use cache=unsafe with snapshot */
|
492 | 666daa68 | Markus Armbruster | bdrv_flags &= ~BDRV_O_CACHE_MASK; |
493 | 666daa68 | Markus Armbruster | bdrv_flags |= (BDRV_O_SNAPSHOT|BDRV_O_CACHE_WB|BDRV_O_NO_FLUSH); |
494 | 666daa68 | Markus Armbruster | } |
495 | 666daa68 | Markus Armbruster | |
496 | fb0490f6 | Stefan Hajnoczi | if (copy_on_read) {
|
497 | fb0490f6 | Stefan Hajnoczi | bdrv_flags |= BDRV_O_COPY_ON_READ; |
498 | fb0490f6 | Stefan Hajnoczi | } |
499 | fb0490f6 | Stefan Hajnoczi | |
500 | ed9d4205 | Benoît Canet | if (runstate_check(RUN_STATE_INMIGRATE)) {
|
501 | ed9d4205 | Benoît Canet | bdrv_flags |= BDRV_O_INCOMING; |
502 | ed9d4205 | Benoît Canet | } |
503 | ed9d4205 | Benoît Canet | |
504 | 666daa68 | Markus Armbruster | bdrv_flags |= ro ? 0 : BDRV_O_RDWR;
|
505 | 666daa68 | Markus Armbruster | |
506 | 74fe54f2 | Kevin Wolf | QINCREF(bs_opts); |
507 | ddf5636d | Max Reitz | ret = bdrv_open(&dinfo->bdrv, file, NULL, bs_opts, bdrv_flags, drv, &error);
|
508 | 0006383e | Kevin Wolf | |
509 | 666daa68 | Markus Armbruster | if (ret < 0) { |
510 | b681072d | Kevin Wolf | error_setg(errp, "could not open disk image %s: %s",
|
511 | b681072d | Kevin Wolf | file ?: dinfo->id, error_get_pretty(error)); |
512 | b681072d | Kevin Wolf | error_free(error); |
513 | a9ae2bff | Markus Armbruster | goto err;
|
514 | 666daa68 | Markus Armbruster | } |
515 | 666daa68 | Markus Armbruster | |
516 | 666daa68 | Markus Armbruster | if (bdrv_key_required(dinfo->bdrv))
|
517 | 666daa68 | Markus Armbruster | autostart = 0;
|
518 | 0006383e | Kevin Wolf | |
519 | 74fe54f2 | Kevin Wolf | QDECREF(bs_opts); |
520 | 0006383e | Kevin Wolf | qemu_opts_del(opts); |
521 | 0006383e | Kevin Wolf | |
522 | 666daa68 | Markus Armbruster | return dinfo;
|
523 | a9ae2bff | Markus Armbruster | |
524 | a9ae2bff | Markus Armbruster | err:
|
525 | 4f6fd349 | Fam Zheng | bdrv_unref(dinfo->bdrv); |
526 | 7267c094 | Anthony Liguori | g_free(dinfo->id); |
527 | a9ae2bff | Markus Armbruster | QTAILQ_REMOVE(&drives, dinfo, next); |
528 | 7267c094 | Anthony Liguori | g_free(dinfo); |
529 | ec9c10d2 | Stefan Hajnoczi | early_err:
|
530 | ec9c10d2 | Stefan Hajnoczi | QDECREF(bs_opts); |
531 | ec9c10d2 | Stefan Hajnoczi | qemu_opts_del(opts); |
532 | a9ae2bff | Markus Armbruster | return NULL; |
533 | 666daa68 | Markus Armbruster | } |
534 | 666daa68 | Markus Armbruster | |
535 | 57975222 | Kevin Wolf | static void qemu_opt_rename(QemuOpts *opts, const char *from, const char *to) |
536 | 57975222 | Kevin Wolf | { |
537 | 57975222 | Kevin Wolf | const char *value; |
538 | 57975222 | Kevin Wolf | |
539 | 57975222 | Kevin Wolf | value = qemu_opt_get(opts, from); |
540 | 57975222 | Kevin Wolf | if (value) {
|
541 | 57975222 | Kevin Wolf | qemu_opt_set(opts, to, value); |
542 | 57975222 | Kevin Wolf | qemu_opt_unset(opts, from); |
543 | 57975222 | Kevin Wolf | } |
544 | 57975222 | Kevin Wolf | } |
545 | 57975222 | Kevin Wolf | |
546 | 33cb7dc8 | Kevin Wolf | QemuOptsList qemu_legacy_drive_opts = { |
547 | 33cb7dc8 | Kevin Wolf | .name = "drive",
|
548 | 33cb7dc8 | Kevin Wolf | .head = QTAILQ_HEAD_INITIALIZER(qemu_legacy_drive_opts.head), |
549 | 33cb7dc8 | Kevin Wolf | .desc = { |
550 | 33cb7dc8 | Kevin Wolf | { |
551 | 87a899c5 | Kevin Wolf | .name = "bus",
|
552 | 87a899c5 | Kevin Wolf | .type = QEMU_OPT_NUMBER, |
553 | 87a899c5 | Kevin Wolf | .help = "bus number",
|
554 | 87a899c5 | Kevin Wolf | },{ |
555 | 87a899c5 | Kevin Wolf | .name = "unit",
|
556 | 87a899c5 | Kevin Wolf | .type = QEMU_OPT_NUMBER, |
557 | 87a899c5 | Kevin Wolf | .help = "unit number (i.e. lun for scsi)",
|
558 | 87a899c5 | Kevin Wolf | },{ |
559 | 87a899c5 | Kevin Wolf | .name = "index",
|
560 | 87a899c5 | Kevin Wolf | .type = QEMU_OPT_NUMBER, |
561 | 87a899c5 | Kevin Wolf | .help = "index number",
|
562 | 87a899c5 | Kevin Wolf | },{ |
563 | 33cb7dc8 | Kevin Wolf | .name = "media",
|
564 | 33cb7dc8 | Kevin Wolf | .type = QEMU_OPT_STRING, |
565 | 33cb7dc8 | Kevin Wolf | .help = "media type (disk, cdrom)",
|
566 | 593d464b | Kevin Wolf | },{ |
567 | 593d464b | Kevin Wolf | .name = "if",
|
568 | 593d464b | Kevin Wolf | .type = QEMU_OPT_STRING, |
569 | 593d464b | Kevin Wolf | .help = "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)",
|
570 | b41a7338 | Kevin Wolf | },{ |
571 | b41a7338 | Kevin Wolf | .name = "cyls",
|
572 | b41a7338 | Kevin Wolf | .type = QEMU_OPT_NUMBER, |
573 | b41a7338 | Kevin Wolf | .help = "number of cylinders (ide disk geometry)",
|
574 | b41a7338 | Kevin Wolf | },{ |
575 | b41a7338 | Kevin Wolf | .name = "heads",
|
576 | b41a7338 | Kevin Wolf | .type = QEMU_OPT_NUMBER, |
577 | b41a7338 | Kevin Wolf | .help = "number of heads (ide disk geometry)",
|
578 | b41a7338 | Kevin Wolf | },{ |
579 | b41a7338 | Kevin Wolf | .name = "secs",
|
580 | b41a7338 | Kevin Wolf | .type = QEMU_OPT_NUMBER, |
581 | b41a7338 | Kevin Wolf | .help = "number of sectors (ide disk geometry)",
|
582 | b41a7338 | Kevin Wolf | },{ |
583 | b41a7338 | Kevin Wolf | .name = "trans",
|
584 | b41a7338 | Kevin Wolf | .type = QEMU_OPT_STRING, |
585 | b41a7338 | Kevin Wolf | .help = "chs translation (auto, lba, none)",
|
586 | 26929298 | Kevin Wolf | },{ |
587 | 26929298 | Kevin Wolf | .name = "boot",
|
588 | 26929298 | Kevin Wolf | .type = QEMU_OPT_BOOL, |
589 | 26929298 | Kevin Wolf | .help = "(deprecated, ignored)",
|
590 | 394c7d4d | Kevin Wolf | },{ |
591 | 394c7d4d | Kevin Wolf | .name = "addr",
|
592 | 394c7d4d | Kevin Wolf | .type = QEMU_OPT_STRING, |
593 | 394c7d4d | Kevin Wolf | .help = "pci address (virtio only)",
|
594 | d095b465 | Max Reitz | },{ |
595 | d095b465 | Max Reitz | .name = "file",
|
596 | d095b465 | Max Reitz | .type = QEMU_OPT_STRING, |
597 | d095b465 | Max Reitz | .help = "file name",
|
598 | 33cb7dc8 | Kevin Wolf | }, |
599 | 0ebd24e0 | Kevin Wolf | |
600 | 0ebd24e0 | Kevin Wolf | /* Options that are passed on, but have special semantics with -drive */
|
601 | 0ebd24e0 | Kevin Wolf | { |
602 | 0ebd24e0 | Kevin Wolf | .name = "read-only",
|
603 | 0ebd24e0 | Kevin Wolf | .type = QEMU_OPT_BOOL, |
604 | 0ebd24e0 | Kevin Wolf | .help = "open drive file as read-only",
|
605 | 0ebd24e0 | Kevin Wolf | },{ |
606 | ee13ed1c | Kevin Wolf | .name = "rerror",
|
607 | ee13ed1c | Kevin Wolf | .type = QEMU_OPT_STRING, |
608 | ee13ed1c | Kevin Wolf | .help = "read error action",
|
609 | ee13ed1c | Kevin Wolf | },{ |
610 | ee13ed1c | Kevin Wolf | .name = "werror",
|
611 | ee13ed1c | Kevin Wolf | .type = QEMU_OPT_STRING, |
612 | ee13ed1c | Kevin Wolf | .help = "write error action",
|
613 | ee13ed1c | Kevin Wolf | },{ |
614 | 0ebd24e0 | Kevin Wolf | .name = "copy-on-read",
|
615 | 0ebd24e0 | Kevin Wolf | .type = QEMU_OPT_BOOL, |
616 | 0ebd24e0 | Kevin Wolf | .help = "copy read data from backing file into image file",
|
617 | 0ebd24e0 | Kevin Wolf | }, |
618 | 0ebd24e0 | Kevin Wolf | |
619 | 33cb7dc8 | Kevin Wolf | { /* end of list */ }
|
620 | 33cb7dc8 | Kevin Wolf | }, |
621 | 33cb7dc8 | Kevin Wolf | }; |
622 | 33cb7dc8 | Kevin Wolf | |
623 | 57975222 | Kevin Wolf | DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) |
624 | 57975222 | Kevin Wolf | { |
625 | 29c4e2b5 | Kevin Wolf | const char *value; |
626 | 33cb7dc8 | Kevin Wolf | DriveInfo *dinfo = NULL;
|
627 | f298d071 | Kevin Wolf | QDict *bs_opts; |
628 | 33cb7dc8 | Kevin Wolf | QemuOpts *legacy_opts; |
629 | 33cb7dc8 | Kevin Wolf | DriveMediaType media = MEDIA_DISK; |
630 | 593d464b | Kevin Wolf | BlockInterfaceType type; |
631 | b41a7338 | Kevin Wolf | int cyls, heads, secs, translation;
|
632 | 87a899c5 | Kevin Wolf | int max_devs, bus_id, unit_id, index;
|
633 | 394c7d4d | Kevin Wolf | const char *devaddr; |
634 | ee13ed1c | Kevin Wolf | const char *werror, *rerror; |
635 | a7fdbcf0 | Fam Zheng | bool read_only = false; |
636 | a7fdbcf0 | Fam Zheng | bool copy_on_read;
|
637 | d095b465 | Max Reitz | const char *filename; |
638 | 33cb7dc8 | Kevin Wolf | Error *local_err = NULL;
|
639 | 29c4e2b5 | Kevin Wolf | |
640 | 57975222 | Kevin Wolf | /* Change legacy command line options into QMP ones */
|
641 | 57975222 | Kevin Wolf | qemu_opt_rename(all_opts, "iops", "throttling.iops-total"); |
642 | 57975222 | Kevin Wolf | qemu_opt_rename(all_opts, "iops_rd", "throttling.iops-read"); |
643 | 57975222 | Kevin Wolf | qemu_opt_rename(all_opts, "iops_wr", "throttling.iops-write"); |
644 | 57975222 | Kevin Wolf | |
645 | 57975222 | Kevin Wolf | qemu_opt_rename(all_opts, "bps", "throttling.bps-total"); |
646 | 57975222 | Kevin Wolf | qemu_opt_rename(all_opts, "bps_rd", "throttling.bps-read"); |
647 | 57975222 | Kevin Wolf | qemu_opt_rename(all_opts, "bps_wr", "throttling.bps-write"); |
648 | 57975222 | Kevin Wolf | |
649 | 3e9fab69 | Benoît Canet | qemu_opt_rename(all_opts, "iops_max", "throttling.iops-total-max"); |
650 | 3e9fab69 | Benoît Canet | qemu_opt_rename(all_opts, "iops_rd_max", "throttling.iops-read-max"); |
651 | 3e9fab69 | Benoît Canet | qemu_opt_rename(all_opts, "iops_wr_max", "throttling.iops-write-max"); |
652 | 3e9fab69 | Benoît Canet | |
653 | 3e9fab69 | Benoît Canet | qemu_opt_rename(all_opts, "bps_max", "throttling.bps-total-max"); |
654 | 3e9fab69 | Benoît Canet | qemu_opt_rename(all_opts, "bps_rd_max", "throttling.bps-read-max"); |
655 | 3e9fab69 | Benoît Canet | qemu_opt_rename(all_opts, "bps_wr_max", "throttling.bps-write-max"); |
656 | 3e9fab69 | Benoît Canet | |
657 | 2024c1df | Benoît Canet | qemu_opt_rename(all_opts, |
658 | 2024c1df | Benoît Canet | "iops_size", "throttling.iops-size"); |
659 | 2024c1df | Benoît Canet | |
660 | 0f227a94 | Kevin Wolf | qemu_opt_rename(all_opts, "readonly", "read-only"); |
661 | 0f227a94 | Kevin Wolf | |
662 | 29c4e2b5 | Kevin Wolf | value = qemu_opt_get(all_opts, "cache");
|
663 | 29c4e2b5 | Kevin Wolf | if (value) {
|
664 | 29c4e2b5 | Kevin Wolf | int flags = 0; |
665 | 29c4e2b5 | Kevin Wolf | |
666 | 29c4e2b5 | Kevin Wolf | if (bdrv_parse_cache_flags(value, &flags) != 0) { |
667 | 29c4e2b5 | Kevin Wolf | error_report("invalid cache option");
|
668 | 29c4e2b5 | Kevin Wolf | return NULL; |
669 | 29c4e2b5 | Kevin Wolf | } |
670 | 29c4e2b5 | Kevin Wolf | |
671 | 29c4e2b5 | Kevin Wolf | /* Specific options take precedence */
|
672 | 29c4e2b5 | Kevin Wolf | if (!qemu_opt_get(all_opts, "cache.writeback")) { |
673 | 29c4e2b5 | Kevin Wolf | qemu_opt_set_bool(all_opts, "cache.writeback",
|
674 | 29c4e2b5 | Kevin Wolf | !!(flags & BDRV_O_CACHE_WB)); |
675 | 29c4e2b5 | Kevin Wolf | } |
676 | 29c4e2b5 | Kevin Wolf | if (!qemu_opt_get(all_opts, "cache.direct")) { |
677 | 29c4e2b5 | Kevin Wolf | qemu_opt_set_bool(all_opts, "cache.direct",
|
678 | 29c4e2b5 | Kevin Wolf | !!(flags & BDRV_O_NOCACHE)); |
679 | 29c4e2b5 | Kevin Wolf | } |
680 | 29c4e2b5 | Kevin Wolf | if (!qemu_opt_get(all_opts, "cache.no-flush")) { |
681 | 29c4e2b5 | Kevin Wolf | qemu_opt_set_bool(all_opts, "cache.no-flush",
|
682 | 29c4e2b5 | Kevin Wolf | !!(flags & BDRV_O_NO_FLUSH)); |
683 | 29c4e2b5 | Kevin Wolf | } |
684 | 29c4e2b5 | Kevin Wolf | qemu_opt_unset(all_opts, "cache");
|
685 | 29c4e2b5 | Kevin Wolf | } |
686 | 29c4e2b5 | Kevin Wolf | |
687 | f298d071 | Kevin Wolf | /* Get a QDict for processing the options */
|
688 | f298d071 | Kevin Wolf | bs_opts = qdict_new(); |
689 | f298d071 | Kevin Wolf | qemu_opts_to_qdict(all_opts, bs_opts); |
690 | f298d071 | Kevin Wolf | |
691 | 87ea75d5 | Peter Crosthwaite | legacy_opts = qemu_opts_create(&qemu_legacy_drive_opts, NULL, 0, |
692 | 87ea75d5 | Peter Crosthwaite | &error_abort); |
693 | 33cb7dc8 | Kevin Wolf | qemu_opts_absorb_qdict(legacy_opts, bs_opts, &local_err); |
694 | 84d18f06 | Markus Armbruster | if (local_err) {
|
695 | 33cb7dc8 | Kevin Wolf | qerror_report_err(local_err); |
696 | 33cb7dc8 | Kevin Wolf | error_free(local_err); |
697 | 33cb7dc8 | Kevin Wolf | goto fail;
|
698 | 33cb7dc8 | Kevin Wolf | } |
699 | 33cb7dc8 | Kevin Wolf | |
700 | 26929298 | Kevin Wolf | /* Deprecated option boot=[on|off] */
|
701 | 26929298 | Kevin Wolf | if (qemu_opt_get(legacy_opts, "boot") != NULL) { |
702 | 26929298 | Kevin Wolf | fprintf(stderr, "qemu-kvm: boot=on|off is deprecated and will be "
|
703 | 26929298 | Kevin Wolf | "ignored. Future versions will reject this parameter. Please "
|
704 | 26929298 | Kevin Wolf | "update your scripts.\n");
|
705 | 26929298 | Kevin Wolf | } |
706 | 26929298 | Kevin Wolf | |
707 | 33cb7dc8 | Kevin Wolf | /* Media type */
|
708 | 33cb7dc8 | Kevin Wolf | value = qemu_opt_get(legacy_opts, "media");
|
709 | 33cb7dc8 | Kevin Wolf | if (value) {
|
710 | 33cb7dc8 | Kevin Wolf | if (!strcmp(value, "disk")) { |
711 | 33cb7dc8 | Kevin Wolf | media = MEDIA_DISK; |
712 | 33cb7dc8 | Kevin Wolf | } else if (!strcmp(value, "cdrom")) { |
713 | 33cb7dc8 | Kevin Wolf | media = MEDIA_CDROM; |
714 | a7fdbcf0 | Fam Zheng | read_only = true;
|
715 | 33cb7dc8 | Kevin Wolf | } else {
|
716 | 33cb7dc8 | Kevin Wolf | error_report("'%s' invalid media", value);
|
717 | 33cb7dc8 | Kevin Wolf | goto fail;
|
718 | 33cb7dc8 | Kevin Wolf | } |
719 | 33cb7dc8 | Kevin Wolf | } |
720 | 33cb7dc8 | Kevin Wolf | |
721 | 0ebd24e0 | Kevin Wolf | /* copy-on-read is disabled with a warning for read-only devices */
|
722 | a7fdbcf0 | Fam Zheng | read_only |= qemu_opt_get_bool(legacy_opts, "read-only", false); |
723 | 0ebd24e0 | Kevin Wolf | copy_on_read = qemu_opt_get_bool(legacy_opts, "copy-on-read", false); |
724 | 0ebd24e0 | Kevin Wolf | |
725 | 0ebd24e0 | Kevin Wolf | if (read_only && copy_on_read) {
|
726 | 0ebd24e0 | Kevin Wolf | error_report("warning: disabling copy-on-read on read-only drive");
|
727 | 0ebd24e0 | Kevin Wolf | copy_on_read = false;
|
728 | 0ebd24e0 | Kevin Wolf | } |
729 | 0ebd24e0 | Kevin Wolf | |
730 | 0ebd24e0 | Kevin Wolf | qdict_put(bs_opts, "read-only",
|
731 | 0ebd24e0 | Kevin Wolf | qstring_from_str(read_only ? "on" : "off")); |
732 | 0ebd24e0 | Kevin Wolf | qdict_put(bs_opts, "copy-on-read",
|
733 | 0ebd24e0 | Kevin Wolf | qstring_from_str(copy_on_read ? "on" :"off")); |
734 | 0ebd24e0 | Kevin Wolf | |
735 | 593d464b | Kevin Wolf | /* Controller type */
|
736 | 593d464b | Kevin Wolf | value = qemu_opt_get(legacy_opts, "if");
|
737 | 593d464b | Kevin Wolf | if (value) {
|
738 | 593d464b | Kevin Wolf | for (type = 0; |
739 | 593d464b | Kevin Wolf | type < IF_COUNT && strcmp(value, if_name[type]); |
740 | 593d464b | Kevin Wolf | type++) { |
741 | 593d464b | Kevin Wolf | } |
742 | 593d464b | Kevin Wolf | if (type == IF_COUNT) {
|
743 | 593d464b | Kevin Wolf | error_report("unsupported bus type '%s'", value);
|
744 | 593d464b | Kevin Wolf | goto fail;
|
745 | 593d464b | Kevin Wolf | } |
746 | 593d464b | Kevin Wolf | } else {
|
747 | 593d464b | Kevin Wolf | type = block_default_type; |
748 | 593d464b | Kevin Wolf | } |
749 | 593d464b | Kevin Wolf | |
750 | b41a7338 | Kevin Wolf | /* Geometry */
|
751 | b41a7338 | Kevin Wolf | cyls = qemu_opt_get_number(legacy_opts, "cyls", 0); |
752 | b41a7338 | Kevin Wolf | heads = qemu_opt_get_number(legacy_opts, "heads", 0); |
753 | b41a7338 | Kevin Wolf | secs = qemu_opt_get_number(legacy_opts, "secs", 0); |
754 | b41a7338 | Kevin Wolf | |
755 | b41a7338 | Kevin Wolf | if (cyls || heads || secs) {
|
756 | b41a7338 | Kevin Wolf | if (cyls < 1) { |
757 | b41a7338 | Kevin Wolf | error_report("invalid physical cyls number");
|
758 | b41a7338 | Kevin Wolf | goto fail;
|
759 | b41a7338 | Kevin Wolf | } |
760 | b41a7338 | Kevin Wolf | if (heads < 1) { |
761 | b41a7338 | Kevin Wolf | error_report("invalid physical heads number");
|
762 | b41a7338 | Kevin Wolf | goto fail;
|
763 | b41a7338 | Kevin Wolf | } |
764 | b41a7338 | Kevin Wolf | if (secs < 1) { |
765 | b41a7338 | Kevin Wolf | error_report("invalid physical secs number");
|
766 | b41a7338 | Kevin Wolf | goto fail;
|
767 | b41a7338 | Kevin Wolf | } |
768 | b41a7338 | Kevin Wolf | } |
769 | b41a7338 | Kevin Wolf | |
770 | b41a7338 | Kevin Wolf | translation = BIOS_ATA_TRANSLATION_AUTO; |
771 | b41a7338 | Kevin Wolf | value = qemu_opt_get(legacy_opts, "trans");
|
772 | b41a7338 | Kevin Wolf | if (value != NULL) { |
773 | b41a7338 | Kevin Wolf | if (!cyls) {
|
774 | b41a7338 | Kevin Wolf | error_report("'%s' trans must be used with cyls, heads and secs",
|
775 | b41a7338 | Kevin Wolf | value); |
776 | b41a7338 | Kevin Wolf | goto fail;
|
777 | b41a7338 | Kevin Wolf | } |
778 | b41a7338 | Kevin Wolf | if (!strcmp(value, "none")) { |
779 | b41a7338 | Kevin Wolf | translation = BIOS_ATA_TRANSLATION_NONE; |
780 | b41a7338 | Kevin Wolf | } else if (!strcmp(value, "lba")) { |
781 | b41a7338 | Kevin Wolf | translation = BIOS_ATA_TRANSLATION_LBA; |
782 | f31c41ff | Paolo Bonzini | } else if (!strcmp(value, "large")) { |
783 | f31c41ff | Paolo Bonzini | translation = BIOS_ATA_TRANSLATION_LARGE; |
784 | f31c41ff | Paolo Bonzini | } else if (!strcmp(value, "rechs")) { |
785 | f31c41ff | Paolo Bonzini | translation = BIOS_ATA_TRANSLATION_RECHS; |
786 | b41a7338 | Kevin Wolf | } else if (!strcmp(value, "auto")) { |
787 | b41a7338 | Kevin Wolf | translation = BIOS_ATA_TRANSLATION_AUTO; |
788 | b41a7338 | Kevin Wolf | } else {
|
789 | b41a7338 | Kevin Wolf | error_report("'%s' invalid translation type", value);
|
790 | b41a7338 | Kevin Wolf | goto fail;
|
791 | b41a7338 | Kevin Wolf | } |
792 | b41a7338 | Kevin Wolf | } |
793 | b41a7338 | Kevin Wolf | |
794 | b41a7338 | Kevin Wolf | if (media == MEDIA_CDROM) {
|
795 | b41a7338 | Kevin Wolf | if (cyls || secs || heads) {
|
796 | b41a7338 | Kevin Wolf | error_report("CHS can't be set with media=cdrom");
|
797 | b41a7338 | Kevin Wolf | goto fail;
|
798 | b41a7338 | Kevin Wolf | } |
799 | b41a7338 | Kevin Wolf | } |
800 | b41a7338 | Kevin Wolf | |
801 | 87a899c5 | Kevin Wolf | /* Device address specified by bus/unit or index.
|
802 | 87a899c5 | Kevin Wolf | * If none was specified, try to find the first free one. */
|
803 | 87a899c5 | Kevin Wolf | bus_id = qemu_opt_get_number(legacy_opts, "bus", 0); |
804 | 87a899c5 | Kevin Wolf | unit_id = qemu_opt_get_number(legacy_opts, "unit", -1); |
805 | 87a899c5 | Kevin Wolf | index = qemu_opt_get_number(legacy_opts, "index", -1); |
806 | 87a899c5 | Kevin Wolf | |
807 | 87a899c5 | Kevin Wolf | max_devs = if_max_devs[type]; |
808 | 87a899c5 | Kevin Wolf | |
809 | 87a899c5 | Kevin Wolf | if (index != -1) { |
810 | 87a899c5 | Kevin Wolf | if (bus_id != 0 || unit_id != -1) { |
811 | 87a899c5 | Kevin Wolf | error_report("index cannot be used with bus and unit");
|
812 | 87a899c5 | Kevin Wolf | goto fail;
|
813 | 87a899c5 | Kevin Wolf | } |
814 | 87a899c5 | Kevin Wolf | bus_id = drive_index_to_bus_id(type, index); |
815 | 87a899c5 | Kevin Wolf | unit_id = drive_index_to_unit_id(type, index); |
816 | 87a899c5 | Kevin Wolf | } |
817 | 87a899c5 | Kevin Wolf | |
818 | 87a899c5 | Kevin Wolf | if (unit_id == -1) { |
819 | 87a899c5 | Kevin Wolf | unit_id = 0;
|
820 | 87a899c5 | Kevin Wolf | while (drive_get(type, bus_id, unit_id) != NULL) { |
821 | 87a899c5 | Kevin Wolf | unit_id++; |
822 | 87a899c5 | Kevin Wolf | if (max_devs && unit_id >= max_devs) {
|
823 | 87a899c5 | Kevin Wolf | unit_id -= max_devs; |
824 | 87a899c5 | Kevin Wolf | bus_id++; |
825 | 87a899c5 | Kevin Wolf | } |
826 | 87a899c5 | Kevin Wolf | } |
827 | 87a899c5 | Kevin Wolf | } |
828 | 87a899c5 | Kevin Wolf | |
829 | 87a899c5 | Kevin Wolf | if (max_devs && unit_id >= max_devs) {
|
830 | 87a899c5 | Kevin Wolf | error_report("unit %d too big (max is %d)", unit_id, max_devs - 1); |
831 | 87a899c5 | Kevin Wolf | goto fail;
|
832 | 87a899c5 | Kevin Wolf | } |
833 | 87a899c5 | Kevin Wolf | |
834 | 87a899c5 | Kevin Wolf | if (drive_get(type, bus_id, unit_id) != NULL) { |
835 | 87a899c5 | Kevin Wolf | error_report("drive with bus=%d, unit=%d (index=%d) exists",
|
836 | 87a899c5 | Kevin Wolf | bus_id, unit_id, index); |
837 | 87a899c5 | Kevin Wolf | goto fail;
|
838 | 87a899c5 | Kevin Wolf | } |
839 | 87a899c5 | Kevin Wolf | |
840 | 87a899c5 | Kevin Wolf | /* no id supplied -> create one */
|
841 | 87a899c5 | Kevin Wolf | if (qemu_opts_id(all_opts) == NULL) { |
842 | 87a899c5 | Kevin Wolf | char *new_id;
|
843 | 87a899c5 | Kevin Wolf | const char *mediastr = ""; |
844 | 87a899c5 | Kevin Wolf | if (type == IF_IDE || type == IF_SCSI) {
|
845 | 87a899c5 | Kevin Wolf | mediastr = (media == MEDIA_CDROM) ? "-cd" : "-hd"; |
846 | 87a899c5 | Kevin Wolf | } |
847 | 87a899c5 | Kevin Wolf | if (max_devs) {
|
848 | 87a899c5 | Kevin Wolf | new_id = g_strdup_printf("%s%i%s%i", if_name[type], bus_id,
|
849 | 87a899c5 | Kevin Wolf | mediastr, unit_id); |
850 | 87a899c5 | Kevin Wolf | } else {
|
851 | 87a899c5 | Kevin Wolf | new_id = g_strdup_printf("%s%s%i", if_name[type],
|
852 | 87a899c5 | Kevin Wolf | mediastr, unit_id); |
853 | 87a899c5 | Kevin Wolf | } |
854 | 87a899c5 | Kevin Wolf | qdict_put(bs_opts, "id", qstring_from_str(new_id));
|
855 | 87a899c5 | Kevin Wolf | g_free(new_id); |
856 | 87a899c5 | Kevin Wolf | } |
857 | 87a899c5 | Kevin Wolf | |
858 | 394c7d4d | Kevin Wolf | /* Add virtio block device */
|
859 | 394c7d4d | Kevin Wolf | devaddr = qemu_opt_get(legacy_opts, "addr");
|
860 | 394c7d4d | Kevin Wolf | if (devaddr && type != IF_VIRTIO) {
|
861 | 394c7d4d | Kevin Wolf | error_report("addr is not supported by this bus type");
|
862 | 394c7d4d | Kevin Wolf | goto fail;
|
863 | 394c7d4d | Kevin Wolf | } |
864 | 394c7d4d | Kevin Wolf | |
865 | 394c7d4d | Kevin Wolf | if (type == IF_VIRTIO) {
|
866 | 394c7d4d | Kevin Wolf | QemuOpts *devopts; |
867 | 87ea75d5 | Peter Crosthwaite | devopts = qemu_opts_create(qemu_find_opts("device"), NULL, 0, |
868 | 87ea75d5 | Peter Crosthwaite | &error_abort); |
869 | 394c7d4d | Kevin Wolf | if (arch_type == QEMU_ARCH_S390X) {
|
870 | 394c7d4d | Kevin Wolf | qemu_opt_set(devopts, "driver", "virtio-blk-s390"); |
871 | 394c7d4d | Kevin Wolf | } else {
|
872 | 394c7d4d | Kevin Wolf | qemu_opt_set(devopts, "driver", "virtio-blk-pci"); |
873 | 394c7d4d | Kevin Wolf | } |
874 | 394c7d4d | Kevin Wolf | qemu_opt_set(devopts, "drive", qdict_get_str(bs_opts, "id")); |
875 | 394c7d4d | Kevin Wolf | if (devaddr) {
|
876 | 394c7d4d | Kevin Wolf | qemu_opt_set(devopts, "addr", devaddr);
|
877 | 394c7d4d | Kevin Wolf | } |
878 | 394c7d4d | Kevin Wolf | } |
879 | 394c7d4d | Kevin Wolf | |
880 | d095b465 | Max Reitz | filename = qemu_opt_get(legacy_opts, "file");
|
881 | d095b465 | Max Reitz | |
882 | ee13ed1c | Kevin Wolf | /* Check werror/rerror compatibility with if=... */
|
883 | ee13ed1c | Kevin Wolf | werror = qemu_opt_get(legacy_opts, "werror");
|
884 | ee13ed1c | Kevin Wolf | if (werror != NULL) { |
885 | ee13ed1c | Kevin Wolf | if (type != IF_IDE && type != IF_SCSI && type != IF_VIRTIO &&
|
886 | ee13ed1c | Kevin Wolf | type != IF_NONE) { |
887 | ee13ed1c | Kevin Wolf | error_report("werror is not supported by this bus type");
|
888 | ee13ed1c | Kevin Wolf | goto fail;
|
889 | ee13ed1c | Kevin Wolf | } |
890 | ee13ed1c | Kevin Wolf | qdict_put(bs_opts, "werror", qstring_from_str(werror));
|
891 | ee13ed1c | Kevin Wolf | } |
892 | ee13ed1c | Kevin Wolf | |
893 | ee13ed1c | Kevin Wolf | rerror = qemu_opt_get(legacy_opts, "rerror");
|
894 | ee13ed1c | Kevin Wolf | if (rerror != NULL) { |
895 | ee13ed1c | Kevin Wolf | if (type != IF_IDE && type != IF_VIRTIO && type != IF_SCSI &&
|
896 | ee13ed1c | Kevin Wolf | type != IF_NONE) { |
897 | ee13ed1c | Kevin Wolf | error_report("rerror is not supported by this bus type");
|
898 | ee13ed1c | Kevin Wolf | goto fail;
|
899 | ee13ed1c | Kevin Wolf | } |
900 | ee13ed1c | Kevin Wolf | qdict_put(bs_opts, "rerror", qstring_from_str(rerror));
|
901 | ee13ed1c | Kevin Wolf | } |
902 | ee13ed1c | Kevin Wolf | |
903 | 2d246f01 | Kevin Wolf | /* Actual block device init: Functionality shared with blockdev-add */
|
904 | ee13ed1c | Kevin Wolf | dinfo = blockdev_init(filename, bs_opts, &local_err); |
905 | 2d246f01 | Kevin Wolf | if (dinfo == NULL) { |
906 | 84d18f06 | Markus Armbruster | if (local_err) {
|
907 | b681072d | Kevin Wolf | qerror_report_err(local_err); |
908 | b681072d | Kevin Wolf | error_free(local_err); |
909 | b681072d | Kevin Wolf | } |
910 | 2d246f01 | Kevin Wolf | goto fail;
|
911 | b681072d | Kevin Wolf | } else {
|
912 | 84d18f06 | Markus Armbruster | assert(!local_err); |
913 | 2d246f01 | Kevin Wolf | } |
914 | 2d246f01 | Kevin Wolf | |
915 | 2d246f01 | Kevin Wolf | /* Set legacy DriveInfo fields */
|
916 | 2d246f01 | Kevin Wolf | dinfo->enable_auto_del = true;
|
917 | f298d071 | Kevin Wolf | dinfo->opts = all_opts; |
918 | 2d246f01 | Kevin Wolf | |
919 | b41a7338 | Kevin Wolf | dinfo->cyls = cyls; |
920 | b41a7338 | Kevin Wolf | dinfo->heads = heads; |
921 | b41a7338 | Kevin Wolf | dinfo->secs = secs; |
922 | b41a7338 | Kevin Wolf | dinfo->trans = translation; |
923 | b41a7338 | Kevin Wolf | |
924 | ee13ed1c | Kevin Wolf | dinfo->type = type; |
925 | 87a899c5 | Kevin Wolf | dinfo->bus = bus_id; |
926 | 87a899c5 | Kevin Wolf | dinfo->unit = unit_id; |
927 | 394c7d4d | Kevin Wolf | dinfo->devaddr = devaddr; |
928 | 87a899c5 | Kevin Wolf | |
929 | e34ef046 | Kevin Wolf | switch(type) {
|
930 | e34ef046 | Kevin Wolf | case IF_IDE:
|
931 | e34ef046 | Kevin Wolf | case IF_SCSI:
|
932 | e34ef046 | Kevin Wolf | case IF_XEN:
|
933 | e34ef046 | Kevin Wolf | case IF_NONE:
|
934 | e34ef046 | Kevin Wolf | dinfo->media_cd = media == MEDIA_CDROM; |
935 | e34ef046 | Kevin Wolf | break;
|
936 | e34ef046 | Kevin Wolf | default:
|
937 | e34ef046 | Kevin Wolf | break;
|
938 | e34ef046 | Kevin Wolf | } |
939 | e34ef046 | Kevin Wolf | |
940 | 2d246f01 | Kevin Wolf | fail:
|
941 | 33cb7dc8 | Kevin Wolf | qemu_opts_del(legacy_opts); |
942 | 2d246f01 | Kevin Wolf | return dinfo;
|
943 | 57975222 | Kevin Wolf | } |
944 | 57975222 | Kevin Wolf | |
945 | 666daa68 | Markus Armbruster | void do_commit(Monitor *mon, const QDict *qdict) |
946 | 666daa68 | Markus Armbruster | { |
947 | 666daa68 | Markus Armbruster | const char *device = qdict_get_str(qdict, "device"); |
948 | 6ab4b5ab | Markus Armbruster | BlockDriverState *bs; |
949 | e8877497 | Stefan Hajnoczi | int ret;
|
950 | 666daa68 | Markus Armbruster | |
951 | 6ab4b5ab | Markus Armbruster | if (!strcmp(device, "all")) { |
952 | e8877497 | Stefan Hajnoczi | ret = bdrv_commit_all(); |
953 | 6ab4b5ab | Markus Armbruster | } else {
|
954 | 6ab4b5ab | Markus Armbruster | bs = bdrv_find(device); |
955 | ac59eb95 | Markus Armbruster | if (!bs) {
|
956 | 58513bde | Jeff Cody | monitor_printf(mon, "Device '%s' not found\n", device);
|
957 | ac59eb95 | Markus Armbruster | return;
|
958 | 6ab4b5ab | Markus Armbruster | } |
959 | 2d3735d3 | Stefan Hajnoczi | ret = bdrv_commit(bs); |
960 | 58513bde | Jeff Cody | } |
961 | 58513bde | Jeff Cody | if (ret < 0) { |
962 | 58513bde | Jeff Cody | monitor_printf(mon, "'commit' error for '%s': %s\n", device,
|
963 | 58513bde | Jeff Cody | strerror(-ret)); |
964 | 666daa68 | Markus Armbruster | } |
965 | 666daa68 | Markus Armbruster | } |
966 | 666daa68 | Markus Armbruster | |
967 | 6cc2a415 | Paolo Bonzini | static void blockdev_do_action(int kind, void *data, Error **errp) |
968 | 6cc2a415 | Paolo Bonzini | { |
969 | c8a83e85 | Kevin Wolf | TransactionAction action; |
970 | c8a83e85 | Kevin Wolf | TransactionActionList list; |
971 | 6cc2a415 | Paolo Bonzini | |
972 | 6cc2a415 | Paolo Bonzini | action.kind = kind; |
973 | 6cc2a415 | Paolo Bonzini | action.data = data; |
974 | 6cc2a415 | Paolo Bonzini | list.value = &action; |
975 | 6cc2a415 | Paolo Bonzini | list.next = NULL;
|
976 | 6cc2a415 | Paolo Bonzini | qmp_transaction(&list, errp); |
977 | 6cc2a415 | Paolo Bonzini | } |
978 | 6cc2a415 | Paolo Bonzini | |
979 | 0901f67e | Benoît Canet | void qmp_blockdev_snapshot_sync(bool has_device, const char *device, |
980 | 0901f67e | Benoît Canet | bool has_node_name, const char *node_name, |
981 | 0901f67e | Benoît Canet | const char *snapshot_file, |
982 | 0901f67e | Benoît Canet | bool has_snapshot_node_name,
|
983 | 0901f67e | Benoît Canet | const char *snapshot_node_name, |
984 | 6106e249 | Luiz Capitulino | bool has_format, const char *format, |
985 | 0901f67e | Benoît Canet | bool has_mode, NewImageMode mode, Error **errp)
|
986 | f8882568 | Jes Sorensen | { |
987 | 6cc2a415 | Paolo Bonzini | BlockdevSnapshot snapshot = { |
988 | 0901f67e | Benoît Canet | .has_device = has_device, |
989 | 6cc2a415 | Paolo Bonzini | .device = (char *) device,
|
990 | 0901f67e | Benoît Canet | .has_node_name = has_node_name, |
991 | 0901f67e | Benoît Canet | .node_name = (char *) node_name,
|
992 | 6cc2a415 | Paolo Bonzini | .snapshot_file = (char *) snapshot_file,
|
993 | 0901f67e | Benoît Canet | .has_snapshot_node_name = has_snapshot_node_name, |
994 | 0901f67e | Benoît Canet | .snapshot_node_name = (char *) snapshot_node_name,
|
995 | 6cc2a415 | Paolo Bonzini | .has_format = has_format, |
996 | 6cc2a415 | Paolo Bonzini | .format = (char *) format,
|
997 | 6cc2a415 | Paolo Bonzini | .has_mode = has_mode, |
998 | 6cc2a415 | Paolo Bonzini | .mode = mode, |
999 | 6cc2a415 | Paolo Bonzini | }; |
1000 | c8a83e85 | Kevin Wolf | blockdev_do_action(TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC, |
1001 | c8a83e85 | Kevin Wolf | &snapshot, errp); |
1002 | f8882568 | Jes Sorensen | } |
1003 | f8882568 | Jes Sorensen | |
1004 | f323bc9e | Wenchao Xia | void qmp_blockdev_snapshot_internal_sync(const char *device, |
1005 | f323bc9e | Wenchao Xia | const char *name, |
1006 | f323bc9e | Wenchao Xia | Error **errp) |
1007 | f323bc9e | Wenchao Xia | { |
1008 | f323bc9e | Wenchao Xia | BlockdevSnapshotInternal snapshot = { |
1009 | f323bc9e | Wenchao Xia | .device = (char *) device,
|
1010 | f323bc9e | Wenchao Xia | .name = (char *) name
|
1011 | f323bc9e | Wenchao Xia | }; |
1012 | f323bc9e | Wenchao Xia | |
1013 | f323bc9e | Wenchao Xia | blockdev_do_action(TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_INTERNAL_SYNC, |
1014 | f323bc9e | Wenchao Xia | &snapshot, errp); |
1015 | f323bc9e | Wenchao Xia | } |
1016 | f323bc9e | Wenchao Xia | |
1017 | 44e3e053 | Wenchao Xia | SnapshotInfo *qmp_blockdev_snapshot_delete_internal_sync(const char *device, |
1018 | 44e3e053 | Wenchao Xia | bool has_id,
|
1019 | 44e3e053 | Wenchao Xia | const char *id, |
1020 | 44e3e053 | Wenchao Xia | bool has_name,
|
1021 | 44e3e053 | Wenchao Xia | const char *name, |
1022 | 44e3e053 | Wenchao Xia | Error **errp) |
1023 | 44e3e053 | Wenchao Xia | { |
1024 | 44e3e053 | Wenchao Xia | BlockDriverState *bs = bdrv_find(device); |
1025 | 44e3e053 | Wenchao Xia | QEMUSnapshotInfo sn; |
1026 | 44e3e053 | Wenchao Xia | Error *local_err = NULL;
|
1027 | 44e3e053 | Wenchao Xia | SnapshotInfo *info = NULL;
|
1028 | 44e3e053 | Wenchao Xia | int ret;
|
1029 | 44e3e053 | Wenchao Xia | |
1030 | 44e3e053 | Wenchao Xia | if (!bs) {
|
1031 | 44e3e053 | Wenchao Xia | error_set(errp, QERR_DEVICE_NOT_FOUND, device); |
1032 | 44e3e053 | Wenchao Xia | return NULL; |
1033 | 44e3e053 | Wenchao Xia | } |
1034 | 44e3e053 | Wenchao Xia | |
1035 | 44e3e053 | Wenchao Xia | if (!has_id) {
|
1036 | 44e3e053 | Wenchao Xia | id = NULL;
|
1037 | 44e3e053 | Wenchao Xia | } |
1038 | 44e3e053 | Wenchao Xia | |
1039 | 44e3e053 | Wenchao Xia | if (!has_name) {
|
1040 | 44e3e053 | Wenchao Xia | name = NULL;
|
1041 | 44e3e053 | Wenchao Xia | } |
1042 | 44e3e053 | Wenchao Xia | |
1043 | 44e3e053 | Wenchao Xia | if (!id && !name) {
|
1044 | 44e3e053 | Wenchao Xia | error_setg(errp, "Name or id must be provided");
|
1045 | 44e3e053 | Wenchao Xia | return NULL; |
1046 | 44e3e053 | Wenchao Xia | } |
1047 | 44e3e053 | Wenchao Xia | |
1048 | 44e3e053 | Wenchao Xia | ret = bdrv_snapshot_find_by_id_and_name(bs, id, name, &sn, &local_err); |
1049 | 84d18f06 | Markus Armbruster | if (local_err) {
|
1050 | 44e3e053 | Wenchao Xia | error_propagate(errp, local_err); |
1051 | 44e3e053 | Wenchao Xia | return NULL; |
1052 | 44e3e053 | Wenchao Xia | } |
1053 | 44e3e053 | Wenchao Xia | if (!ret) {
|
1054 | 44e3e053 | Wenchao Xia | error_setg(errp, |
1055 | 44e3e053 | Wenchao Xia | "Snapshot with id '%s' and name '%s' does not exist on "
|
1056 | 44e3e053 | Wenchao Xia | "device '%s'",
|
1057 | 44e3e053 | Wenchao Xia | STR_OR_NULL(id), STR_OR_NULL(name), device); |
1058 | 44e3e053 | Wenchao Xia | return NULL; |
1059 | 44e3e053 | Wenchao Xia | } |
1060 | 44e3e053 | Wenchao Xia | |
1061 | 44e3e053 | Wenchao Xia | bdrv_snapshot_delete(bs, id, name, &local_err); |
1062 | 84d18f06 | Markus Armbruster | if (local_err) {
|
1063 | 44e3e053 | Wenchao Xia | error_propagate(errp, local_err); |
1064 | 44e3e053 | Wenchao Xia | return NULL; |
1065 | 44e3e053 | Wenchao Xia | } |
1066 | 44e3e053 | Wenchao Xia | |
1067 | 44e3e053 | Wenchao Xia | info = g_malloc0(sizeof(SnapshotInfo));
|
1068 | 44e3e053 | Wenchao Xia | info->id = g_strdup(sn.id_str); |
1069 | 44e3e053 | Wenchao Xia | info->name = g_strdup(sn.name); |
1070 | 44e3e053 | Wenchao Xia | info->date_nsec = sn.date_nsec; |
1071 | 44e3e053 | Wenchao Xia | info->date_sec = sn.date_sec; |
1072 | 44e3e053 | Wenchao Xia | info->vm_state_size = sn.vm_state_size; |
1073 | 44e3e053 | Wenchao Xia | info->vm_clock_nsec = sn.vm_clock_nsec % 1000000000;
|
1074 | 44e3e053 | Wenchao Xia | info->vm_clock_sec = sn.vm_clock_nsec / 1000000000;
|
1075 | 44e3e053 | Wenchao Xia | |
1076 | 44e3e053 | Wenchao Xia | return info;
|
1077 | 44e3e053 | Wenchao Xia | } |
1078 | 8802d1fd | Jeff Cody | |
1079 | 8802d1fd | Jeff Cody | /* New and old BlockDriverState structs for group snapshots */
|
1080 | ba0c86a3 | Wenchao Xia | |
1081 | ba5d6ab6 | Stefan Hajnoczi | typedef struct BlkTransactionState BlkTransactionState; |
1082 | ba0c86a3 | Wenchao Xia | |
1083 | ba0c86a3 | Wenchao Xia | /* Only prepare() may fail. In a single transaction, only one of commit() or
|
1084 | ba0c86a3 | Wenchao Xia | abort() will be called, clean() will always be called if it present. */
|
1085 | ba0c86a3 | Wenchao Xia | typedef struct BdrvActionOps { |
1086 | ba0c86a3 | Wenchao Xia | /* Size of state struct, in bytes. */
|
1087 | ba0c86a3 | Wenchao Xia | size_t instance_size; |
1088 | ba0c86a3 | Wenchao Xia | /* Prepare the work, must NOT be NULL. */
|
1089 | ba5d6ab6 | Stefan Hajnoczi | void (*prepare)(BlkTransactionState *common, Error **errp);
|
1090 | f9ea81e8 | Stefan Hajnoczi | /* Commit the changes, can be NULL. */
|
1091 | ba5d6ab6 | Stefan Hajnoczi | void (*commit)(BlkTransactionState *common);
|
1092 | ba0c86a3 | Wenchao Xia | /* Abort the changes on fail, can be NULL. */
|
1093 | ba5d6ab6 | Stefan Hajnoczi | void (*abort)(BlkTransactionState *common);
|
1094 | ba0c86a3 | Wenchao Xia | /* Clean up resource in the end, can be NULL. */
|
1095 | ba5d6ab6 | Stefan Hajnoczi | void (*clean)(BlkTransactionState *common);
|
1096 | ba0c86a3 | Wenchao Xia | } BdrvActionOps; |
1097 | ba0c86a3 | Wenchao Xia | |
1098 | ba0c86a3 | Wenchao Xia | /*
|
1099 | ba0c86a3 | Wenchao Xia | * This structure must be arranged as first member in child type, assuming
|
1100 | ba0c86a3 | Wenchao Xia | * that compiler will also arrange it to the same address with parent instance.
|
1101 | ba0c86a3 | Wenchao Xia | * Later it will be used in free().
|
1102 | ba0c86a3 | Wenchao Xia | */
|
1103 | ba5d6ab6 | Stefan Hajnoczi | struct BlkTransactionState {
|
1104 | c8a83e85 | Kevin Wolf | TransactionAction *action; |
1105 | ba0c86a3 | Wenchao Xia | const BdrvActionOps *ops;
|
1106 | ba5d6ab6 | Stefan Hajnoczi | QSIMPLEQ_ENTRY(BlkTransactionState) entry; |
1107 | ba0c86a3 | Wenchao Xia | }; |
1108 | ba0c86a3 | Wenchao Xia | |
1109 | bbe86010 | Wenchao Xia | /* internal snapshot private data */
|
1110 | bbe86010 | Wenchao Xia | typedef struct InternalSnapshotState { |
1111 | bbe86010 | Wenchao Xia | BlkTransactionState common; |
1112 | bbe86010 | Wenchao Xia | BlockDriverState *bs; |
1113 | bbe86010 | Wenchao Xia | QEMUSnapshotInfo sn; |
1114 | bbe86010 | Wenchao Xia | } InternalSnapshotState; |
1115 | bbe86010 | Wenchao Xia | |
1116 | bbe86010 | Wenchao Xia | static void internal_snapshot_prepare(BlkTransactionState *common, |
1117 | bbe86010 | Wenchao Xia | Error **errp) |
1118 | bbe86010 | Wenchao Xia | { |
1119 | bbe86010 | Wenchao Xia | const char *device; |
1120 | bbe86010 | Wenchao Xia | const char *name; |
1121 | bbe86010 | Wenchao Xia | BlockDriverState *bs; |
1122 | bbe86010 | Wenchao Xia | QEMUSnapshotInfo old_sn, *sn; |
1123 | bbe86010 | Wenchao Xia | bool ret;
|
1124 | bbe86010 | Wenchao Xia | qemu_timeval tv; |
1125 | bbe86010 | Wenchao Xia | BlockdevSnapshotInternal *internal; |
1126 | bbe86010 | Wenchao Xia | InternalSnapshotState *state; |
1127 | bbe86010 | Wenchao Xia | int ret1;
|
1128 | bbe86010 | Wenchao Xia | |
1129 | bbe86010 | Wenchao Xia | g_assert(common->action->kind == |
1130 | bbe86010 | Wenchao Xia | TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_INTERNAL_SYNC); |
1131 | bbe86010 | Wenchao Xia | internal = common->action->blockdev_snapshot_internal_sync; |
1132 | bbe86010 | Wenchao Xia | state = DO_UPCAST(InternalSnapshotState, common, common); |
1133 | bbe86010 | Wenchao Xia | |
1134 | bbe86010 | Wenchao Xia | /* 1. parse input */
|
1135 | bbe86010 | Wenchao Xia | device = internal->device; |
1136 | bbe86010 | Wenchao Xia | name = internal->name; |
1137 | bbe86010 | Wenchao Xia | |
1138 | bbe86010 | Wenchao Xia | /* 2. check for validation */
|
1139 | bbe86010 | Wenchao Xia | bs = bdrv_find(device); |
1140 | bbe86010 | Wenchao Xia | if (!bs) {
|
1141 | bbe86010 | Wenchao Xia | error_set(errp, QERR_DEVICE_NOT_FOUND, device); |
1142 | bbe86010 | Wenchao Xia | return;
|
1143 | bbe86010 | Wenchao Xia | } |
1144 | bbe86010 | Wenchao Xia | |
1145 | bbe86010 | Wenchao Xia | if (!bdrv_is_inserted(bs)) {
|
1146 | bbe86010 | Wenchao Xia | error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device); |
1147 | bbe86010 | Wenchao Xia | return;
|
1148 | bbe86010 | Wenchao Xia | } |
1149 | bbe86010 | Wenchao Xia | |
1150 | bbe86010 | Wenchao Xia | if (bdrv_is_read_only(bs)) {
|
1151 | bbe86010 | Wenchao Xia | error_set(errp, QERR_DEVICE_IS_READ_ONLY, device); |
1152 | bbe86010 | Wenchao Xia | return;
|
1153 | bbe86010 | Wenchao Xia | } |
1154 | bbe86010 | Wenchao Xia | |
1155 | bbe86010 | Wenchao Xia | if (!bdrv_can_snapshot(bs)) {
|
1156 | bbe86010 | Wenchao Xia | error_set(errp, QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED, |
1157 | bbe86010 | Wenchao Xia | bs->drv->format_name, device, "internal snapshot");
|
1158 | bbe86010 | Wenchao Xia | return;
|
1159 | bbe86010 | Wenchao Xia | } |
1160 | bbe86010 | Wenchao Xia | |
1161 | bbe86010 | Wenchao Xia | if (!strlen(name)) {
|
1162 | bbe86010 | Wenchao Xia | error_setg(errp, "Name is empty");
|
1163 | bbe86010 | Wenchao Xia | return;
|
1164 | bbe86010 | Wenchao Xia | } |
1165 | bbe86010 | Wenchao Xia | |
1166 | bbe86010 | Wenchao Xia | /* check whether a snapshot with name exist */
|
1167 | bbe86010 | Wenchao Xia | ret = bdrv_snapshot_find_by_id_and_name(bs, NULL, name, &old_sn, errp);
|
1168 | bbe86010 | Wenchao Xia | if (error_is_set(errp)) {
|
1169 | bbe86010 | Wenchao Xia | return;
|
1170 | bbe86010 | Wenchao Xia | } else if (ret) { |
1171 | bbe86010 | Wenchao Xia | error_setg(errp, |
1172 | bbe86010 | Wenchao Xia | "Snapshot with name '%s' already exists on device '%s'",
|
1173 | bbe86010 | Wenchao Xia | name, device); |
1174 | bbe86010 | Wenchao Xia | return;
|
1175 | bbe86010 | Wenchao Xia | } |
1176 | bbe86010 | Wenchao Xia | |
1177 | bbe86010 | Wenchao Xia | /* 3. take the snapshot */
|
1178 | bbe86010 | Wenchao Xia | sn = &state->sn; |
1179 | bbe86010 | Wenchao Xia | pstrcpy(sn->name, sizeof(sn->name), name);
|
1180 | bbe86010 | Wenchao Xia | qemu_gettimeofday(&tv); |
1181 | bbe86010 | Wenchao Xia | sn->date_sec = tv.tv_sec; |
1182 | bbe86010 | Wenchao Xia | sn->date_nsec = tv.tv_usec * 1000;
|
1183 | bbe86010 | Wenchao Xia | sn->vm_clock_nsec = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); |
1184 | bbe86010 | Wenchao Xia | |
1185 | bbe86010 | Wenchao Xia | ret1 = bdrv_snapshot_create(bs, sn); |
1186 | bbe86010 | Wenchao Xia | if (ret1 < 0) { |
1187 | bbe86010 | Wenchao Xia | error_setg_errno(errp, -ret1, |
1188 | bbe86010 | Wenchao Xia | "Failed to create snapshot '%s' on device '%s'",
|
1189 | bbe86010 | Wenchao Xia | name, device); |
1190 | bbe86010 | Wenchao Xia | return;
|
1191 | bbe86010 | Wenchao Xia | } |
1192 | bbe86010 | Wenchao Xia | |
1193 | bbe86010 | Wenchao Xia | /* 4. succeed, mark a snapshot is created */
|
1194 | bbe86010 | Wenchao Xia | state->bs = bs; |
1195 | bbe86010 | Wenchao Xia | } |
1196 | bbe86010 | Wenchao Xia | |
1197 | bbe86010 | Wenchao Xia | static void internal_snapshot_abort(BlkTransactionState *common) |
1198 | bbe86010 | Wenchao Xia | { |
1199 | bbe86010 | Wenchao Xia | InternalSnapshotState *state = |
1200 | bbe86010 | Wenchao Xia | DO_UPCAST(InternalSnapshotState, common, common); |
1201 | bbe86010 | Wenchao Xia | BlockDriverState *bs = state->bs; |
1202 | bbe86010 | Wenchao Xia | QEMUSnapshotInfo *sn = &state->sn; |
1203 | bbe86010 | Wenchao Xia | Error *local_error = NULL;
|
1204 | bbe86010 | Wenchao Xia | |
1205 | bbe86010 | Wenchao Xia | if (!bs) {
|
1206 | bbe86010 | Wenchao Xia | return;
|
1207 | bbe86010 | Wenchao Xia | } |
1208 | bbe86010 | Wenchao Xia | |
1209 | bbe86010 | Wenchao Xia | if (bdrv_snapshot_delete(bs, sn->id_str, sn->name, &local_error) < 0) { |
1210 | bbe86010 | Wenchao Xia | error_report("Failed to delete snapshot with id '%s' and name '%s' on "
|
1211 | bbe86010 | Wenchao Xia | "device '%s' in abort: %s",
|
1212 | bbe86010 | Wenchao Xia | sn->id_str, |
1213 | bbe86010 | Wenchao Xia | sn->name, |
1214 | bbe86010 | Wenchao Xia | bdrv_get_device_name(bs), |
1215 | bbe86010 | Wenchao Xia | error_get_pretty(local_error)); |
1216 | bbe86010 | Wenchao Xia | error_free(local_error); |
1217 | bbe86010 | Wenchao Xia | } |
1218 | bbe86010 | Wenchao Xia | } |
1219 | bbe86010 | Wenchao Xia | |
1220 | ba0c86a3 | Wenchao Xia | /* external snapshot private data */
|
1221 | ba5d6ab6 | Stefan Hajnoczi | typedef struct ExternalSnapshotState { |
1222 | ba5d6ab6 | Stefan Hajnoczi | BlkTransactionState common; |
1223 | 8802d1fd | Jeff Cody | BlockDriverState *old_bs; |
1224 | 8802d1fd | Jeff Cody | BlockDriverState *new_bs; |
1225 | ba5d6ab6 | Stefan Hajnoczi | } ExternalSnapshotState; |
1226 | 8802d1fd | Jeff Cody | |
1227 | ba5d6ab6 | Stefan Hajnoczi | static void external_snapshot_prepare(BlkTransactionState *common, |
1228 | 9b9877ee | Wenchao Xia | Error **errp) |
1229 | 9b9877ee | Wenchao Xia | { |
1230 | 9b9877ee | Wenchao Xia | BlockDriver *drv; |
1231 | 9b9877ee | Wenchao Xia | int flags, ret;
|
1232 | 0901f67e | Benoît Canet | QDict *options = NULL;
|
1233 | 9b9877ee | Wenchao Xia | Error *local_err = NULL;
|
1234 | 0901f67e | Benoît Canet | bool has_device = false; |
1235 | e2a31e87 | Wenchao Xia | const char *device; |
1236 | 0901f67e | Benoît Canet | bool has_node_name = false; |
1237 | 0901f67e | Benoît Canet | const char *node_name; |
1238 | 0901f67e | Benoît Canet | bool has_snapshot_node_name = false; |
1239 | 0901f67e | Benoît Canet | const char *snapshot_node_name; |
1240 | e2a31e87 | Wenchao Xia | const char *new_image_file; |
1241 | e2a31e87 | Wenchao Xia | const char *format = "qcow2"; |
1242 | e2a31e87 | Wenchao Xia | enum NewImageMode mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
|
1243 | ba5d6ab6 | Stefan Hajnoczi | ExternalSnapshotState *state = |
1244 | ba5d6ab6 | Stefan Hajnoczi | DO_UPCAST(ExternalSnapshotState, common, common); |
1245 | c8a83e85 | Kevin Wolf | TransactionAction *action = common->action; |
1246 | 9b9877ee | Wenchao Xia | |
1247 | e2a31e87 | Wenchao Xia | /* get parameters */
|
1248 | c8a83e85 | Kevin Wolf | g_assert(action->kind == TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC); |
1249 | e2a31e87 | Wenchao Xia | |
1250 | 0901f67e | Benoît Canet | has_device = action->blockdev_snapshot_sync->has_device; |
1251 | e2a31e87 | Wenchao Xia | device = action->blockdev_snapshot_sync->device; |
1252 | 0901f67e | Benoît Canet | has_node_name = action->blockdev_snapshot_sync->has_node_name; |
1253 | 0901f67e | Benoît Canet | node_name = action->blockdev_snapshot_sync->node_name; |
1254 | 0901f67e | Benoît Canet | has_snapshot_node_name = |
1255 | 0901f67e | Benoît Canet | action->blockdev_snapshot_sync->has_snapshot_node_name; |
1256 | 0901f67e | Benoît Canet | snapshot_node_name = action->blockdev_snapshot_sync->snapshot_node_name; |
1257 | 0901f67e | Benoît Canet | |
1258 | e2a31e87 | Wenchao Xia | new_image_file = action->blockdev_snapshot_sync->snapshot_file; |
1259 | e2a31e87 | Wenchao Xia | if (action->blockdev_snapshot_sync->has_format) {
|
1260 | e2a31e87 | Wenchao Xia | format = action->blockdev_snapshot_sync->format; |
1261 | e2a31e87 | Wenchao Xia | } |
1262 | e2a31e87 | Wenchao Xia | if (action->blockdev_snapshot_sync->has_mode) {
|
1263 | e2a31e87 | Wenchao Xia | mode = action->blockdev_snapshot_sync->mode; |
1264 | e2a31e87 | Wenchao Xia | } |
1265 | e2a31e87 | Wenchao Xia | |
1266 | e2a31e87 | Wenchao Xia | /* start processing */
|
1267 | 9b9877ee | Wenchao Xia | drv = bdrv_find_format(format); |
1268 | 9b9877ee | Wenchao Xia | if (!drv) {
|
1269 | 9b9877ee | Wenchao Xia | error_set(errp, QERR_INVALID_BLOCK_FORMAT, format); |
1270 | 9b9877ee | Wenchao Xia | return;
|
1271 | 9b9877ee | Wenchao Xia | } |
1272 | 9b9877ee | Wenchao Xia | |
1273 | 0901f67e | Benoît Canet | state->old_bs = bdrv_lookup_bs(has_device ? device : NULL,
|
1274 | 0901f67e | Benoît Canet | has_node_name ? node_name : NULL,
|
1275 | 0901f67e | Benoît Canet | &local_err); |
1276 | 84d18f06 | Markus Armbruster | if (local_err) {
|
1277 | 0901f67e | Benoît Canet | error_propagate(errp, local_err); |
1278 | 0901f67e | Benoît Canet | return;
|
1279 | 0901f67e | Benoît Canet | } |
1280 | 0901f67e | Benoît Canet | |
1281 | 0901f67e | Benoît Canet | if (has_node_name && !has_snapshot_node_name) {
|
1282 | 0901f67e | Benoît Canet | error_setg(errp, "New snapshot node name missing");
|
1283 | 0901f67e | Benoît Canet | return;
|
1284 | 0901f67e | Benoît Canet | } |
1285 | 0901f67e | Benoît Canet | |
1286 | 0901f67e | Benoît Canet | if (has_snapshot_node_name && bdrv_find_node(snapshot_node_name)) {
|
1287 | 0901f67e | Benoît Canet | error_setg(errp, "New snapshot node name already existing");
|
1288 | 9b9877ee | Wenchao Xia | return;
|
1289 | 9b9877ee | Wenchao Xia | } |
1290 | 9b9877ee | Wenchao Xia | |
1291 | ba5d6ab6 | Stefan Hajnoczi | if (!bdrv_is_inserted(state->old_bs)) {
|
1292 | 9b9877ee | Wenchao Xia | error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device); |
1293 | 9b9877ee | Wenchao Xia | return;
|
1294 | 9b9877ee | Wenchao Xia | } |
1295 | 9b9877ee | Wenchao Xia | |
1296 | ba5d6ab6 | Stefan Hajnoczi | if (bdrv_in_use(state->old_bs)) {
|
1297 | 9b9877ee | Wenchao Xia | error_set(errp, QERR_DEVICE_IN_USE, device); |
1298 | 9b9877ee | Wenchao Xia | return;
|
1299 | 9b9877ee | Wenchao Xia | } |
1300 | 9b9877ee | Wenchao Xia | |
1301 | ba5d6ab6 | Stefan Hajnoczi | if (!bdrv_is_read_only(state->old_bs)) {
|
1302 | ba5d6ab6 | Stefan Hajnoczi | if (bdrv_flush(state->old_bs)) {
|
1303 | 9b9877ee | Wenchao Xia | error_set(errp, QERR_IO_ERROR); |
1304 | 9b9877ee | Wenchao Xia | return;
|
1305 | 9b9877ee | Wenchao Xia | } |
1306 | 9b9877ee | Wenchao Xia | } |
1307 | 9b9877ee | Wenchao Xia | |
1308 | 212a5a8f | Benoît Canet | if (!bdrv_is_first_non_filter(state->old_bs)) {
|
1309 | f6186f49 | Benoît Canet | error_set(errp, QERR_FEATURE_DISABLED, "snapshot");
|
1310 | f6186f49 | Benoît Canet | return;
|
1311 | f6186f49 | Benoît Canet | } |
1312 | f6186f49 | Benoît Canet | |
1313 | ba5d6ab6 | Stefan Hajnoczi | flags = state->old_bs->open_flags; |
1314 | 9b9877ee | Wenchao Xia | |
1315 | 9b9877ee | Wenchao Xia | /* create new image w/backing file */
|
1316 | 9b9877ee | Wenchao Xia | if (mode != NEW_IMAGE_MODE_EXISTING) {
|
1317 | 9b9877ee | Wenchao Xia | bdrv_img_create(new_image_file, format, |
1318 | ba5d6ab6 | Stefan Hajnoczi | state->old_bs->filename, |
1319 | ba5d6ab6 | Stefan Hajnoczi | state->old_bs->drv->format_name, |
1320 | 9b9877ee | Wenchao Xia | NULL, -1, flags, &local_err, false); |
1321 | 84d18f06 | Markus Armbruster | if (local_err) {
|
1322 | 9b9877ee | Wenchao Xia | error_propagate(errp, local_err); |
1323 | 9b9877ee | Wenchao Xia | return;
|
1324 | 9b9877ee | Wenchao Xia | } |
1325 | 9b9877ee | Wenchao Xia | } |
1326 | 9b9877ee | Wenchao Xia | |
1327 | 0901f67e | Benoît Canet | if (has_snapshot_node_name) {
|
1328 | 0901f67e | Benoît Canet | options = qdict_new(); |
1329 | 0901f67e | Benoît Canet | qdict_put(options, "node-name",
|
1330 | 0901f67e | Benoît Canet | qstring_from_str(snapshot_node_name)); |
1331 | 0901f67e | Benoît Canet | } |
1332 | 0901f67e | Benoît Canet | |
1333 | 9b9877ee | Wenchao Xia | /* TODO Inherit bs->options or only take explicit options with an
|
1334 | 9b9877ee | Wenchao Xia | * extended QMP command? */
|
1335 | f67503e5 | Max Reitz | assert(state->new_bs == NULL);
|
1336 | ddf5636d | Max Reitz | ret = bdrv_open(&state->new_bs, new_image_file, NULL, options,
|
1337 | 34b5d2c6 | Max Reitz | flags | BDRV_O_NO_BACKING, drv, &local_err); |
1338 | f67503e5 | Max Reitz | /* We will manually add the backing_hd field to the bs later */
|
1339 | 9b9877ee | Wenchao Xia | if (ret != 0) { |
1340 | 34b5d2c6 | Max Reitz | error_propagate(errp, local_err); |
1341 | 9b9877ee | Wenchao Xia | } |
1342 | 9b9877ee | Wenchao Xia | } |
1343 | 9b9877ee | Wenchao Xia | |
1344 | ba5d6ab6 | Stefan Hajnoczi | static void external_snapshot_commit(BlkTransactionState *common) |
1345 | 3b0047e8 | Wenchao Xia | { |
1346 | ba5d6ab6 | Stefan Hajnoczi | ExternalSnapshotState *state = |
1347 | ba5d6ab6 | Stefan Hajnoczi | DO_UPCAST(ExternalSnapshotState, common, common); |
1348 | ba0c86a3 | Wenchao Xia | |
1349 | ba5d6ab6 | Stefan Hajnoczi | /* This removes our old bs and adds the new bs */
|
1350 | ba5d6ab6 | Stefan Hajnoczi | bdrv_append(state->new_bs, state->old_bs); |
1351 | 3b0047e8 | Wenchao Xia | /* We don't need (or want) to use the transactional
|
1352 | 3b0047e8 | Wenchao Xia | * bdrv_reopen_multiple() across all the entries at once, because we
|
1353 | 3b0047e8 | Wenchao Xia | * don't want to abort all of them if one of them fails the reopen */
|
1354 | ba5d6ab6 | Stefan Hajnoczi | bdrv_reopen(state->new_bs, state->new_bs->open_flags & ~BDRV_O_RDWR, |
1355 | 3b0047e8 | Wenchao Xia | NULL);
|
1356 | 3b0047e8 | Wenchao Xia | } |
1357 | 3b0047e8 | Wenchao Xia | |
1358 | ba5d6ab6 | Stefan Hajnoczi | static void external_snapshot_abort(BlkTransactionState *common) |
1359 | 96b86bf7 | Wenchao Xia | { |
1360 | ba5d6ab6 | Stefan Hajnoczi | ExternalSnapshotState *state = |
1361 | ba5d6ab6 | Stefan Hajnoczi | DO_UPCAST(ExternalSnapshotState, common, common); |
1362 | ba5d6ab6 | Stefan Hajnoczi | if (state->new_bs) {
|
1363 | 4f6fd349 | Fam Zheng | bdrv_unref(state->new_bs); |
1364 | 96b86bf7 | Wenchao Xia | } |
1365 | 96b86bf7 | Wenchao Xia | } |
1366 | 96b86bf7 | Wenchao Xia | |
1367 | 3037f364 | Stefan Hajnoczi | typedef struct DriveBackupState { |
1368 | 3037f364 | Stefan Hajnoczi | BlkTransactionState common; |
1369 | 3037f364 | Stefan Hajnoczi | BlockDriverState *bs; |
1370 | 3037f364 | Stefan Hajnoczi | BlockJob *job; |
1371 | 3037f364 | Stefan Hajnoczi | } DriveBackupState; |
1372 | 3037f364 | Stefan Hajnoczi | |
1373 | 3037f364 | Stefan Hajnoczi | static void drive_backup_prepare(BlkTransactionState *common, Error **errp) |
1374 | 3037f364 | Stefan Hajnoczi | { |
1375 | 3037f364 | Stefan Hajnoczi | DriveBackupState *state = DO_UPCAST(DriveBackupState, common, common); |
1376 | 3037f364 | Stefan Hajnoczi | DriveBackup *backup; |
1377 | 3037f364 | Stefan Hajnoczi | Error *local_err = NULL;
|
1378 | 3037f364 | Stefan Hajnoczi | |
1379 | 3037f364 | Stefan Hajnoczi | assert(common->action->kind == TRANSACTION_ACTION_KIND_DRIVE_BACKUP); |
1380 | 3037f364 | Stefan Hajnoczi | backup = common->action->drive_backup; |
1381 | 3037f364 | Stefan Hajnoczi | |
1382 | 3037f364 | Stefan Hajnoczi | qmp_drive_backup(backup->device, backup->target, |
1383 | 3037f364 | Stefan Hajnoczi | backup->has_format, backup->format, |
1384 | b53169ea | Stefan Hajnoczi | backup->sync, |
1385 | 3037f364 | Stefan Hajnoczi | backup->has_mode, backup->mode, |
1386 | 3037f364 | Stefan Hajnoczi | backup->has_speed, backup->speed, |
1387 | 3037f364 | Stefan Hajnoczi | backup->has_on_source_error, backup->on_source_error, |
1388 | 3037f364 | Stefan Hajnoczi | backup->has_on_target_error, backup->on_target_error, |
1389 | 3037f364 | Stefan Hajnoczi | &local_err); |
1390 | 84d18f06 | Markus Armbruster | if (local_err) {
|
1391 | 3037f364 | Stefan Hajnoczi | error_propagate(errp, local_err); |
1392 | 3037f364 | Stefan Hajnoczi | state->bs = NULL;
|
1393 | 3037f364 | Stefan Hajnoczi | state->job = NULL;
|
1394 | 3037f364 | Stefan Hajnoczi | return;
|
1395 | 3037f364 | Stefan Hajnoczi | } |
1396 | 3037f364 | Stefan Hajnoczi | |
1397 | 3037f364 | Stefan Hajnoczi | state->bs = bdrv_find(backup->device); |
1398 | 3037f364 | Stefan Hajnoczi | state->job = state->bs->job; |
1399 | 3037f364 | Stefan Hajnoczi | } |
1400 | 3037f364 | Stefan Hajnoczi | |
1401 | 3037f364 | Stefan Hajnoczi | static void drive_backup_abort(BlkTransactionState *common) |
1402 | 3037f364 | Stefan Hajnoczi | { |
1403 | 3037f364 | Stefan Hajnoczi | DriveBackupState *state = DO_UPCAST(DriveBackupState, common, common); |
1404 | 3037f364 | Stefan Hajnoczi | BlockDriverState *bs = state->bs; |
1405 | 3037f364 | Stefan Hajnoczi | |
1406 | 3037f364 | Stefan Hajnoczi | /* Only cancel if it's the job we started */
|
1407 | 3037f364 | Stefan Hajnoczi | if (bs && bs->job && bs->job == state->job) {
|
1408 | 3037f364 | Stefan Hajnoczi | block_job_cancel_sync(bs->job); |
1409 | 3037f364 | Stefan Hajnoczi | } |
1410 | 3037f364 | Stefan Hajnoczi | } |
1411 | 3037f364 | Stefan Hajnoczi | |
1412 | 78b18b78 | Stefan Hajnoczi | static void abort_prepare(BlkTransactionState *common, Error **errp) |
1413 | 78b18b78 | Stefan Hajnoczi | { |
1414 | 78b18b78 | Stefan Hajnoczi | error_setg(errp, "Transaction aborted using Abort action");
|
1415 | 78b18b78 | Stefan Hajnoczi | } |
1416 | 78b18b78 | Stefan Hajnoczi | |
1417 | 78b18b78 | Stefan Hajnoczi | static void abort_commit(BlkTransactionState *common) |
1418 | 78b18b78 | Stefan Hajnoczi | { |
1419 | dfc6f865 | Stefan Weil | g_assert_not_reached(); /* this action never succeeds */
|
1420 | 78b18b78 | Stefan Hajnoczi | } |
1421 | 78b18b78 | Stefan Hajnoczi | |
1422 | ba0c86a3 | Wenchao Xia | static const BdrvActionOps actions[] = { |
1423 | c8a83e85 | Kevin Wolf | [TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC] = { |
1424 | ba5d6ab6 | Stefan Hajnoczi | .instance_size = sizeof(ExternalSnapshotState),
|
1425 | ba0c86a3 | Wenchao Xia | .prepare = external_snapshot_prepare, |
1426 | ba0c86a3 | Wenchao Xia | .commit = external_snapshot_commit, |
1427 | ba0c86a3 | Wenchao Xia | .abort = external_snapshot_abort, |
1428 | ba0c86a3 | Wenchao Xia | }, |
1429 | 3037f364 | Stefan Hajnoczi | [TRANSACTION_ACTION_KIND_DRIVE_BACKUP] = { |
1430 | 3037f364 | Stefan Hajnoczi | .instance_size = sizeof(DriveBackupState),
|
1431 | 3037f364 | Stefan Hajnoczi | .prepare = drive_backup_prepare, |
1432 | 3037f364 | Stefan Hajnoczi | .abort = drive_backup_abort, |
1433 | 3037f364 | Stefan Hajnoczi | }, |
1434 | 78b18b78 | Stefan Hajnoczi | [TRANSACTION_ACTION_KIND_ABORT] = { |
1435 | 78b18b78 | Stefan Hajnoczi | .instance_size = sizeof(BlkTransactionState),
|
1436 | 78b18b78 | Stefan Hajnoczi | .prepare = abort_prepare, |
1437 | 78b18b78 | Stefan Hajnoczi | .commit = abort_commit, |
1438 | 78b18b78 | Stefan Hajnoczi | }, |
1439 | bbe86010 | Wenchao Xia | [TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_INTERNAL_SYNC] = { |
1440 | bbe86010 | Wenchao Xia | .instance_size = sizeof(InternalSnapshotState),
|
1441 | bbe86010 | Wenchao Xia | .prepare = internal_snapshot_prepare, |
1442 | bbe86010 | Wenchao Xia | .abort = internal_snapshot_abort, |
1443 | bbe86010 | Wenchao Xia | }, |
1444 | ba0c86a3 | Wenchao Xia | }; |
1445 | ba0c86a3 | Wenchao Xia | |
1446 | 8802d1fd | Jeff Cody | /*
|
1447 | 8802d1fd | Jeff Cody | * 'Atomic' group snapshots. The snapshots are taken as a set, and if any fail
|
1448 | 8802d1fd | Jeff Cody | * then we do not pivot any of the devices in the group, and abandon the
|
1449 | 8802d1fd | Jeff Cody | * snapshots
|
1450 | 8802d1fd | Jeff Cody | */
|
1451 | c8a83e85 | Kevin Wolf | void qmp_transaction(TransactionActionList *dev_list, Error **errp)
|
1452 | 8802d1fd | Jeff Cody | { |
1453 | c8a83e85 | Kevin Wolf | TransactionActionList *dev_entry = dev_list; |
1454 | ba5d6ab6 | Stefan Hajnoczi | BlkTransactionState *state, *next; |
1455 | 43e17041 | Luiz Capitulino | Error *local_err = NULL;
|
1456 | 8802d1fd | Jeff Cody | |
1457 | ba5d6ab6 | Stefan Hajnoczi | QSIMPLEQ_HEAD(snap_bdrv_states, BlkTransactionState) snap_bdrv_states; |
1458 | 8802d1fd | Jeff Cody | QSIMPLEQ_INIT(&snap_bdrv_states); |
1459 | 8802d1fd | Jeff Cody | |
1460 | 8802d1fd | Jeff Cody | /* drain all i/o before any snapshots */
|
1461 | 8802d1fd | Jeff Cody | bdrv_drain_all(); |
1462 | 8802d1fd | Jeff Cody | |
1463 | 8802d1fd | Jeff Cody | /* We don't do anything in this loop that commits us to the snapshot */
|
1464 | 8802d1fd | Jeff Cody | while (NULL != dev_entry) { |
1465 | c8a83e85 | Kevin Wolf | TransactionAction *dev_info = NULL;
|
1466 | ba0c86a3 | Wenchao Xia | const BdrvActionOps *ops;
|
1467 | 52e7c241 | Paolo Bonzini | |
1468 | 8802d1fd | Jeff Cody | dev_info = dev_entry->value; |
1469 | 8802d1fd | Jeff Cody | dev_entry = dev_entry->next; |
1470 | 8802d1fd | Jeff Cody | |
1471 | ba0c86a3 | Wenchao Xia | assert(dev_info->kind < ARRAY_SIZE(actions)); |
1472 | ba0c86a3 | Wenchao Xia | |
1473 | ba0c86a3 | Wenchao Xia | ops = &actions[dev_info->kind]; |
1474 | aa3fe714 | Max Reitz | assert(ops->instance_size > 0);
|
1475 | aa3fe714 | Max Reitz | |
1476 | ba5d6ab6 | Stefan Hajnoczi | state = g_malloc0(ops->instance_size); |
1477 | ba5d6ab6 | Stefan Hajnoczi | state->ops = ops; |
1478 | ba5d6ab6 | Stefan Hajnoczi | state->action = dev_info; |
1479 | ba5d6ab6 | Stefan Hajnoczi | QSIMPLEQ_INSERT_TAIL(&snap_bdrv_states, state, entry); |
1480 | 8802d1fd | Jeff Cody | |
1481 | ba5d6ab6 | Stefan Hajnoczi | state->ops->prepare(state, &local_err); |
1482 | 84d18f06 | Markus Armbruster | if (local_err) {
|
1483 | ba0c86a3 | Wenchao Xia | error_propagate(errp, local_err); |
1484 | ba0c86a3 | Wenchao Xia | goto delete_and_fail;
|
1485 | 8802d1fd | Jeff Cody | } |
1486 | 8802d1fd | Jeff Cody | } |
1487 | 8802d1fd | Jeff Cody | |
1488 | ba5d6ab6 | Stefan Hajnoczi | QSIMPLEQ_FOREACH(state, &snap_bdrv_states, entry) { |
1489 | f9ea81e8 | Stefan Hajnoczi | if (state->ops->commit) {
|
1490 | f9ea81e8 | Stefan Hajnoczi | state->ops->commit(state); |
1491 | f9ea81e8 | Stefan Hajnoczi | } |
1492 | 8802d1fd | Jeff Cody | } |
1493 | 8802d1fd | Jeff Cody | |
1494 | 8802d1fd | Jeff Cody | /* success */
|
1495 | 8802d1fd | Jeff Cody | goto exit;
|
1496 | 8802d1fd | Jeff Cody | |
1497 | 8802d1fd | Jeff Cody | delete_and_fail:
|
1498 | 8802d1fd | Jeff Cody | /*
|
1499 | 8802d1fd | Jeff Cody | * failure, and it is all-or-none; abandon each new bs, and keep using
|
1500 | 8802d1fd | Jeff Cody | * the original bs for all images
|
1501 | 8802d1fd | Jeff Cody | */
|
1502 | ba5d6ab6 | Stefan Hajnoczi | QSIMPLEQ_FOREACH(state, &snap_bdrv_states, entry) { |
1503 | ba5d6ab6 | Stefan Hajnoczi | if (state->ops->abort) {
|
1504 | ba5d6ab6 | Stefan Hajnoczi | state->ops->abort(state); |
1505 | ba0c86a3 | Wenchao Xia | } |
1506 | 8802d1fd | Jeff Cody | } |
1507 | 8802d1fd | Jeff Cody | exit:
|
1508 | ba5d6ab6 | Stefan Hajnoczi | QSIMPLEQ_FOREACH_SAFE(state, &snap_bdrv_states, entry, next) { |
1509 | ba5d6ab6 | Stefan Hajnoczi | if (state->ops->clean) {
|
1510 | ba5d6ab6 | Stefan Hajnoczi | state->ops->clean(state); |
1511 | ba0c86a3 | Wenchao Xia | } |
1512 | ba5d6ab6 | Stefan Hajnoczi | g_free(state); |
1513 | 8802d1fd | Jeff Cody | } |
1514 | 8802d1fd | Jeff Cody | } |
1515 | 8802d1fd | Jeff Cody | |
1516 | 8802d1fd | Jeff Cody | |
1517 | 92d48558 | Luiz Capitulino | static void eject_device(BlockDriverState *bs, int force, Error **errp) |
1518 | 666daa68 | Markus Armbruster | { |
1519 | 2d3735d3 | Stefan Hajnoczi | if (bdrv_in_use(bs)) {
|
1520 | 2d3735d3 | Stefan Hajnoczi | error_set(errp, QERR_DEVICE_IN_USE, bdrv_get_device_name(bs)); |
1521 | 2d3735d3 | Stefan Hajnoczi | return;
|
1522 | 2d3735d3 | Stefan Hajnoczi | } |
1523 | 2c6942fa | Markus Armbruster | if (!bdrv_dev_has_removable_media(bs)) {
|
1524 | 92d48558 | Luiz Capitulino | error_set(errp, QERR_DEVICE_NOT_REMOVABLE, bdrv_get_device_name(bs)); |
1525 | 92d48558 | Luiz Capitulino | return;
|
1526 | ea8f942f | Markus Armbruster | } |
1527 | 92d48558 | Luiz Capitulino | |
1528 | 025ccaa7 | Paolo Bonzini | if (bdrv_dev_is_medium_locked(bs) && !bdrv_dev_is_tray_open(bs)) {
|
1529 | 025ccaa7 | Paolo Bonzini | bdrv_dev_eject_request(bs, force); |
1530 | 025ccaa7 | Paolo Bonzini | if (!force) {
|
1531 | 92d48558 | Luiz Capitulino | error_set(errp, QERR_DEVICE_LOCKED, bdrv_get_device_name(bs)); |
1532 | 92d48558 | Luiz Capitulino | return;
|
1533 | 025ccaa7 | Paolo Bonzini | } |
1534 | 666daa68 | Markus Armbruster | } |
1535 | 92d48558 | Luiz Capitulino | |
1536 | 3b5276b5 | Eduardo Habkost | bdrv_close(bs); |
1537 | 666daa68 | Markus Armbruster | } |
1538 | 666daa68 | Markus Armbruster | |
1539 | c245b6a3 | Luiz Capitulino | void qmp_eject(const char *device, bool has_force, bool force, Error **errp) |
1540 | 666daa68 | Markus Armbruster | { |
1541 | 666daa68 | Markus Armbruster | BlockDriverState *bs; |
1542 | 666daa68 | Markus Armbruster | |
1543 | c245b6a3 | Luiz Capitulino | bs = bdrv_find(device); |
1544 | 666daa68 | Markus Armbruster | if (!bs) {
|
1545 | c245b6a3 | Luiz Capitulino | error_set(errp, QERR_DEVICE_NOT_FOUND, device); |
1546 | c245b6a3 | Luiz Capitulino | return;
|
1547 | 92d48558 | Luiz Capitulino | } |
1548 | 92d48558 | Luiz Capitulino | |
1549 | c245b6a3 | Luiz Capitulino | eject_device(bs, force, errp); |
1550 | 666daa68 | Markus Armbruster | } |
1551 | 666daa68 | Markus Armbruster | |
1552 | 12d3ba82 | Benoît Canet | void qmp_block_passwd(bool has_device, const char *device, |
1553 | 12d3ba82 | Benoît Canet | bool has_node_name, const char *node_name, |
1554 | 12d3ba82 | Benoît Canet | const char *password, Error **errp) |
1555 | 666daa68 | Markus Armbruster | { |
1556 | 12d3ba82 | Benoît Canet | Error *local_err = NULL;
|
1557 | 666daa68 | Markus Armbruster | BlockDriverState *bs; |
1558 | 666daa68 | Markus Armbruster | int err;
|
1559 | 666daa68 | Markus Armbruster | |
1560 | 12d3ba82 | Benoît Canet | bs = bdrv_lookup_bs(has_device ? device : NULL,
|
1561 | 12d3ba82 | Benoît Canet | has_node_name ? node_name : NULL,
|
1562 | 12d3ba82 | Benoît Canet | &local_err); |
1563 | 84d18f06 | Markus Armbruster | if (local_err) {
|
1564 | 12d3ba82 | Benoît Canet | error_propagate(errp, local_err); |
1565 | a4dea8a9 | Luiz Capitulino | return;
|
1566 | 666daa68 | Markus Armbruster | } |
1567 | 666daa68 | Markus Armbruster | |
1568 | a4dea8a9 | Luiz Capitulino | err = bdrv_set_key(bs, password); |
1569 | 666daa68 | Markus Armbruster | if (err == -EINVAL) {
|
1570 | a4dea8a9 | Luiz Capitulino | error_set(errp, QERR_DEVICE_NOT_ENCRYPTED, bdrv_get_device_name(bs)); |
1571 | a4dea8a9 | Luiz Capitulino | return;
|
1572 | 666daa68 | Markus Armbruster | } else if (err < 0) { |
1573 | a4dea8a9 | Luiz Capitulino | error_set(errp, QERR_INVALID_PASSWORD); |
1574 | a4dea8a9 | Luiz Capitulino | return;
|
1575 | 666daa68 | Markus Armbruster | } |
1576 | 666daa68 | Markus Armbruster | } |
1577 | 666daa68 | Markus Armbruster | |
1578 | 333a96ec | Luiz Capitulino | static void qmp_bdrv_open_encrypted(BlockDriverState *bs, const char *filename, |
1579 | 333a96ec | Luiz Capitulino | int bdrv_flags, BlockDriver *drv,
|
1580 | 333a96ec | Luiz Capitulino | const char *password, Error **errp) |
1581 | 333a96ec | Luiz Capitulino | { |
1582 | 34b5d2c6 | Max Reitz | Error *local_err = NULL;
|
1583 | 0eef407c | Luiz Capitulino | int ret;
|
1584 | 0eef407c | Luiz Capitulino | |
1585 | ddf5636d | Max Reitz | ret = bdrv_open(&bs, filename, NULL, NULL, bdrv_flags, drv, &local_err); |
1586 | 0eef407c | Luiz Capitulino | if (ret < 0) { |
1587 | 34b5d2c6 | Max Reitz | error_propagate(errp, local_err); |
1588 | 333a96ec | Luiz Capitulino | return;
|
1589 | 333a96ec | Luiz Capitulino | } |
1590 | 333a96ec | Luiz Capitulino | |
1591 | 333a96ec | Luiz Capitulino | if (bdrv_key_required(bs)) {
|
1592 | 333a96ec | Luiz Capitulino | if (password) {
|
1593 | 333a96ec | Luiz Capitulino | if (bdrv_set_key(bs, password) < 0) { |
1594 | 333a96ec | Luiz Capitulino | error_set(errp, QERR_INVALID_PASSWORD); |
1595 | 333a96ec | Luiz Capitulino | } |
1596 | 333a96ec | Luiz Capitulino | } else {
|
1597 | 333a96ec | Luiz Capitulino | error_set(errp, QERR_DEVICE_ENCRYPTED, bdrv_get_device_name(bs), |
1598 | 333a96ec | Luiz Capitulino | bdrv_get_encrypted_filename(bs)); |
1599 | 333a96ec | Luiz Capitulino | } |
1600 | 333a96ec | Luiz Capitulino | } else if (password) { |
1601 | 333a96ec | Luiz Capitulino | error_set(errp, QERR_DEVICE_NOT_ENCRYPTED, bdrv_get_device_name(bs)); |
1602 | 333a96ec | Luiz Capitulino | } |
1603 | 333a96ec | Luiz Capitulino | } |
1604 | 333a96ec | Luiz Capitulino | |
1605 | 333a96ec | Luiz Capitulino | void qmp_change_blockdev(const char *device, const char *filename, |
1606 | 314f7ea7 | Marc-André Lureau | const char *format, Error **errp) |
1607 | 666daa68 | Markus Armbruster | { |
1608 | 666daa68 | Markus Armbruster | BlockDriverState *bs; |
1609 | 666daa68 | Markus Armbruster | BlockDriver *drv = NULL;
|
1610 | 666daa68 | Markus Armbruster | int bdrv_flags;
|
1611 | 92d48558 | Luiz Capitulino | Error *err = NULL;
|
1612 | 666daa68 | Markus Armbruster | |
1613 | 666daa68 | Markus Armbruster | bs = bdrv_find(device); |
1614 | 666daa68 | Markus Armbruster | if (!bs) {
|
1615 | 333a96ec | Luiz Capitulino | error_set(errp, QERR_DEVICE_NOT_FOUND, device); |
1616 | 333a96ec | Luiz Capitulino | return;
|
1617 | 666daa68 | Markus Armbruster | } |
1618 | 333a96ec | Luiz Capitulino | |
1619 | 333a96ec | Luiz Capitulino | if (format) {
|
1620 | b64ec4e4 | Fam Zheng | drv = bdrv_find_whitelisted_format(format, bs->read_only); |
1621 | 666daa68 | Markus Armbruster | if (!drv) {
|
1622 | 333a96ec | Luiz Capitulino | error_set(errp, QERR_INVALID_BLOCK_FORMAT, format); |
1623 | 333a96ec | Luiz Capitulino | return;
|
1624 | 666daa68 | Markus Armbruster | } |
1625 | 666daa68 | Markus Armbruster | } |
1626 | 333a96ec | Luiz Capitulino | |
1627 | 92d48558 | Luiz Capitulino | eject_device(bs, 0, &err);
|
1628 | 84d18f06 | Markus Armbruster | if (err) {
|
1629 | 333a96ec | Luiz Capitulino | error_propagate(errp, err); |
1630 | 333a96ec | Luiz Capitulino | return;
|
1631 | 666daa68 | Markus Armbruster | } |
1632 | 333a96ec | Luiz Capitulino | |
1633 | 528f7663 | Markus Armbruster | bdrv_flags = bdrv_is_read_only(bs) ? 0 : BDRV_O_RDWR;
|
1634 | 199630b6 | Blue Swirl | bdrv_flags |= bdrv_is_snapshot(bs) ? BDRV_O_SNAPSHOT : 0;
|
1635 | 333a96ec | Luiz Capitulino | |
1636 | 333a96ec | Luiz Capitulino | qmp_bdrv_open_encrypted(bs, filename, bdrv_flags, drv, NULL, errp);
|
1637 | 666daa68 | Markus Armbruster | } |
1638 | 9063f814 | Ryan Harper | |
1639 | 727f005e | Zhi Yong Wu | /* throttling disk I/O limits */
|
1640 | 80047da5 | Luiz Capitulino | void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd, |
1641 | 3e9fab69 | Benoît Canet | int64_t bps_wr, |
1642 | 3e9fab69 | Benoît Canet | int64_t iops, |
1643 | 3e9fab69 | Benoît Canet | int64_t iops_rd, |
1644 | 3e9fab69 | Benoît Canet | int64_t iops_wr, |
1645 | 3e9fab69 | Benoît Canet | bool has_bps_max,
|
1646 | 3e9fab69 | Benoît Canet | int64_t bps_max, |
1647 | 3e9fab69 | Benoît Canet | bool has_bps_rd_max,
|
1648 | 3e9fab69 | Benoît Canet | int64_t bps_rd_max, |
1649 | 3e9fab69 | Benoît Canet | bool has_bps_wr_max,
|
1650 | 3e9fab69 | Benoît Canet | int64_t bps_wr_max, |
1651 | 3e9fab69 | Benoît Canet | bool has_iops_max,
|
1652 | 3e9fab69 | Benoît Canet | int64_t iops_max, |
1653 | 3e9fab69 | Benoît Canet | bool has_iops_rd_max,
|
1654 | 3e9fab69 | Benoît Canet | int64_t iops_rd_max, |
1655 | 3e9fab69 | Benoît Canet | bool has_iops_wr_max,
|
1656 | 2024c1df | Benoît Canet | int64_t iops_wr_max, |
1657 | 2024c1df | Benoît Canet | bool has_iops_size,
|
1658 | 2024c1df | Benoît Canet | int64_t iops_size, Error **errp) |
1659 | 727f005e | Zhi Yong Wu | { |
1660 | cc0681c4 | Benoît Canet | ThrottleConfig cfg; |
1661 | 727f005e | Zhi Yong Wu | BlockDriverState *bs; |
1662 | 727f005e | Zhi Yong Wu | |
1663 | 80047da5 | Luiz Capitulino | bs = bdrv_find(device); |
1664 | 727f005e | Zhi Yong Wu | if (!bs) {
|
1665 | 80047da5 | Luiz Capitulino | error_set(errp, QERR_DEVICE_NOT_FOUND, device); |
1666 | 80047da5 | Luiz Capitulino | return;
|
1667 | 727f005e | Zhi Yong Wu | } |
1668 | 727f005e | Zhi Yong Wu | |
1669 | cc0681c4 | Benoît Canet | memset(&cfg, 0, sizeof(cfg)); |
1670 | cc0681c4 | Benoît Canet | cfg.buckets[THROTTLE_BPS_TOTAL].avg = bps; |
1671 | cc0681c4 | Benoît Canet | cfg.buckets[THROTTLE_BPS_READ].avg = bps_rd; |
1672 | cc0681c4 | Benoît Canet | cfg.buckets[THROTTLE_BPS_WRITE].avg = bps_wr; |
1673 | cc0681c4 | Benoît Canet | |
1674 | cc0681c4 | Benoît Canet | cfg.buckets[THROTTLE_OPS_TOTAL].avg = iops; |
1675 | cc0681c4 | Benoît Canet | cfg.buckets[THROTTLE_OPS_READ].avg = iops_rd; |
1676 | cc0681c4 | Benoît Canet | cfg.buckets[THROTTLE_OPS_WRITE].avg = iops_wr; |
1677 | cc0681c4 | Benoît Canet | |
1678 | 3e9fab69 | Benoît Canet | if (has_bps_max) {
|
1679 | 3e9fab69 | Benoît Canet | cfg.buckets[THROTTLE_BPS_TOTAL].max = bps_max; |
1680 | 3e9fab69 | Benoît Canet | } |
1681 | 3e9fab69 | Benoît Canet | if (has_bps_rd_max) {
|
1682 | 3e9fab69 | Benoît Canet | cfg.buckets[THROTTLE_BPS_READ].max = bps_rd_max; |
1683 | 3e9fab69 | Benoît Canet | } |
1684 | 3e9fab69 | Benoît Canet | if (has_bps_wr_max) {
|
1685 | 3e9fab69 | Benoît Canet | cfg.buckets[THROTTLE_BPS_WRITE].max = bps_wr_max; |
1686 | 3e9fab69 | Benoît Canet | } |
1687 | 3e9fab69 | Benoît Canet | if (has_iops_max) {
|
1688 | 3e9fab69 | Benoît Canet | cfg.buckets[THROTTLE_OPS_TOTAL].max = iops_max; |
1689 | 3e9fab69 | Benoît Canet | } |
1690 | 3e9fab69 | Benoît Canet | if (has_iops_rd_max) {
|
1691 | 3e9fab69 | Benoît Canet | cfg.buckets[THROTTLE_OPS_READ].max = iops_rd_max; |
1692 | 3e9fab69 | Benoît Canet | } |
1693 | 3e9fab69 | Benoît Canet | if (has_iops_wr_max) {
|
1694 | 3e9fab69 | Benoît Canet | cfg.buckets[THROTTLE_OPS_WRITE].max = iops_wr_max; |
1695 | 3e9fab69 | Benoît Canet | } |
1696 | 727f005e | Zhi Yong Wu | |
1697 | 2024c1df | Benoît Canet | if (has_iops_size) {
|
1698 | 2024c1df | Benoît Canet | cfg.op_size = iops_size; |
1699 | 2024c1df | Benoît Canet | } |
1700 | cc0681c4 | Benoît Canet | |
1701 | cc0681c4 | Benoît Canet | if (!check_throttle_config(&cfg, errp)) {
|
1702 | 80047da5 | Luiz Capitulino | return;
|
1703 | 727f005e | Zhi Yong Wu | } |
1704 | 727f005e | Zhi Yong Wu | |
1705 | cc0681c4 | Benoît Canet | if (!bs->io_limits_enabled && throttle_enabled(&cfg)) {
|
1706 | 727f005e | Zhi Yong Wu | bdrv_io_limits_enable(bs); |
1707 | cc0681c4 | Benoît Canet | } else if (bs->io_limits_enabled && !throttle_enabled(&cfg)) { |
1708 | 727f005e | Zhi Yong Wu | bdrv_io_limits_disable(bs); |
1709 | cc0681c4 | Benoît Canet | } |
1710 | cc0681c4 | Benoît Canet | |
1711 | cc0681c4 | Benoît Canet | if (bs->io_limits_enabled) {
|
1712 | cc0681c4 | Benoît Canet | bdrv_set_io_limits(bs, &cfg); |
1713 | 727f005e | Zhi Yong Wu | } |
1714 | 727f005e | Zhi Yong Wu | } |
1715 | 727f005e | Zhi Yong Wu | |
1716 | 9063f814 | Ryan Harper | int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data) |
1717 | 9063f814 | Ryan Harper | { |
1718 | 9063f814 | Ryan Harper | const char *id = qdict_get_str(qdict, "id"); |
1719 | 9063f814 | Ryan Harper | BlockDriverState *bs; |
1720 | 9063f814 | Ryan Harper | |
1721 | 9063f814 | Ryan Harper | bs = bdrv_find(id); |
1722 | 9063f814 | Ryan Harper | if (!bs) {
|
1723 | 9063f814 | Ryan Harper | qerror_report(QERR_DEVICE_NOT_FOUND, id); |
1724 | 9063f814 | Ryan Harper | return -1; |
1725 | 9063f814 | Ryan Harper | } |
1726 | 8591675f | Marcelo Tosatti | if (bdrv_in_use(bs)) {
|
1727 | 8591675f | Marcelo Tosatti | qerror_report(QERR_DEVICE_IN_USE, id); |
1728 | 8591675f | Marcelo Tosatti | return -1; |
1729 | 8591675f | Marcelo Tosatti | } |
1730 | 9063f814 | Ryan Harper | |
1731 | 9063f814 | Ryan Harper | /* quiesce block driver; prevent further io */
|
1732 | 922453bc | Stefan Hajnoczi | bdrv_drain_all(); |
1733 | 9063f814 | Ryan Harper | bdrv_flush(bs); |
1734 | 9063f814 | Ryan Harper | bdrv_close(bs); |
1735 | 9063f814 | Ryan Harper | |
1736 | fa879d62 | Markus Armbruster | /* if we have a device attached to this BlockDriverState
|
1737 | d22b2f41 | Ryan Harper | * then we need to make the drive anonymous until the device
|
1738 | d22b2f41 | Ryan Harper | * can be removed. If this is a drive with no device backing
|
1739 | d22b2f41 | Ryan Harper | * then we can just get rid of the block driver state right here.
|
1740 | d22b2f41 | Ryan Harper | */
|
1741 | fa879d62 | Markus Armbruster | if (bdrv_get_attached_dev(bs)) {
|
1742 | d22b2f41 | Ryan Harper | bdrv_make_anon(bs); |
1743 | 293c51a6 | Stefan Hajnoczi | |
1744 | 293c51a6 | Stefan Hajnoczi | /* Further I/O must not pause the guest */
|
1745 | 293c51a6 | Stefan Hajnoczi | bdrv_set_on_error(bs, BLOCKDEV_ON_ERROR_REPORT, |
1746 | 293c51a6 | Stefan Hajnoczi | BLOCKDEV_ON_ERROR_REPORT); |
1747 | d22b2f41 | Ryan Harper | } else {
|
1748 | d22b2f41 | Ryan Harper | drive_uninit(drive_get_by_blockdev(bs)); |
1749 | 9063f814 | Ryan Harper | } |
1750 | 9063f814 | Ryan Harper | |
1751 | 9063f814 | Ryan Harper | return 0; |
1752 | 9063f814 | Ryan Harper | } |
1753 | 6d4a2b3a | Christoph Hellwig | |
1754 | 3b1dbd11 | Benoît Canet | void qmp_block_resize(bool has_device, const char *device, |
1755 | 3b1dbd11 | Benoît Canet | bool has_node_name, const char *node_name, |
1756 | 3b1dbd11 | Benoît Canet | int64_t size, Error **errp) |
1757 | 6d4a2b3a | Christoph Hellwig | { |
1758 | 3b1dbd11 | Benoît Canet | Error *local_err = NULL;
|
1759 | 6d4a2b3a | Christoph Hellwig | BlockDriverState *bs; |
1760 | 8732901e | Kevin Wolf | int ret;
|
1761 | 6d4a2b3a | Christoph Hellwig | |
1762 | 3b1dbd11 | Benoît Canet | bs = bdrv_lookup_bs(has_device ? device : NULL,
|
1763 | 3b1dbd11 | Benoît Canet | has_node_name ? node_name : NULL,
|
1764 | 3b1dbd11 | Benoît Canet | &local_err); |
1765 | 84d18f06 | Markus Armbruster | if (local_err) {
|
1766 | 3b1dbd11 | Benoît Canet | error_propagate(errp, local_err); |
1767 | 3b1dbd11 | Benoît Canet | return;
|
1768 | 3b1dbd11 | Benoît Canet | } |
1769 | 3b1dbd11 | Benoît Canet | |
1770 | 3b1dbd11 | Benoît Canet | if (!bdrv_is_first_non_filter(bs)) {
|
1771 | 3b1dbd11 | Benoît Canet | error_set(errp, QERR_FEATURE_DISABLED, "resize");
|
1772 | 5e7caacb | Luiz Capitulino | return;
|
1773 | 6d4a2b3a | Christoph Hellwig | } |
1774 | 6d4a2b3a | Christoph Hellwig | |
1775 | 6d4a2b3a | Christoph Hellwig | if (size < 0) { |
1776 | 939a1cc3 | Stefan Hajnoczi | error_set(errp, QERR_INVALID_PARAMETER_VALUE, "size", "a >0 size"); |
1777 | 5e7caacb | Luiz Capitulino | return;
|
1778 | 6d4a2b3a | Christoph Hellwig | } |
1779 | 6d4a2b3a | Christoph Hellwig | |
1780 | 92b7a08d | Peter Lieven | /* complete all in-flight operations before resizing the device */
|
1781 | 92b7a08d | Peter Lieven | bdrv_drain_all(); |
1782 | 92b7a08d | Peter Lieven | |
1783 | 8732901e | Kevin Wolf | ret = bdrv_truncate(bs, size); |
1784 | 8732901e | Kevin Wolf | switch (ret) {
|
1785 | 939a1cc3 | Stefan Hajnoczi | case 0: |
1786 | 939a1cc3 | Stefan Hajnoczi | break;
|
1787 | 939a1cc3 | Stefan Hajnoczi | case -ENOMEDIUM:
|
1788 | 939a1cc3 | Stefan Hajnoczi | error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device); |
1789 | 939a1cc3 | Stefan Hajnoczi | break;
|
1790 | 939a1cc3 | Stefan Hajnoczi | case -ENOTSUP:
|
1791 | 939a1cc3 | Stefan Hajnoczi | error_set(errp, QERR_UNSUPPORTED); |
1792 | 939a1cc3 | Stefan Hajnoczi | break;
|
1793 | 939a1cc3 | Stefan Hajnoczi | case -EACCES:
|
1794 | 939a1cc3 | Stefan Hajnoczi | error_set(errp, QERR_DEVICE_IS_READ_ONLY, device); |
1795 | 939a1cc3 | Stefan Hajnoczi | break;
|
1796 | 939a1cc3 | Stefan Hajnoczi | case -EBUSY:
|
1797 | 939a1cc3 | Stefan Hajnoczi | error_set(errp, QERR_DEVICE_IN_USE, device); |
1798 | 939a1cc3 | Stefan Hajnoczi | break;
|
1799 | 939a1cc3 | Stefan Hajnoczi | default:
|
1800 | 8732901e | Kevin Wolf | error_setg_errno(errp, -ret, "Could not resize");
|
1801 | 939a1cc3 | Stefan Hajnoczi | break;
|
1802 | 6d4a2b3a | Christoph Hellwig | } |
1803 | 6d4a2b3a | Christoph Hellwig | } |
1804 | 12bd451f | Stefan Hajnoczi | |
1805 | 9abf2dba | Jeff Cody | static void block_job_cb(void *opaque, int ret) |
1806 | 12bd451f | Stefan Hajnoczi | { |
1807 | 12bd451f | Stefan Hajnoczi | BlockDriverState *bs = opaque; |
1808 | 12bd451f | Stefan Hajnoczi | QObject *obj; |
1809 | 12bd451f | Stefan Hajnoczi | |
1810 | 9abf2dba | Jeff Cody | trace_block_job_cb(bs, bs->job, ret); |
1811 | 12bd451f | Stefan Hajnoczi | |
1812 | 12bd451f | Stefan Hajnoczi | assert(bs->job); |
1813 | 12bd451f | Stefan Hajnoczi | obj = qobject_from_block_job(bs->job); |
1814 | 12bd451f | Stefan Hajnoczi | if (ret < 0) { |
1815 | 12bd451f | Stefan Hajnoczi | QDict *dict = qobject_to_qdict(obj); |
1816 | 12bd451f | Stefan Hajnoczi | qdict_put(dict, "error", qstring_from_str(strerror(-ret)));
|
1817 | 12bd451f | Stefan Hajnoczi | } |
1818 | 12bd451f | Stefan Hajnoczi | |
1819 | 370521a1 | Stefan Hajnoczi | if (block_job_is_cancelled(bs->job)) {
|
1820 | 370521a1 | Stefan Hajnoczi | monitor_protocol_event(QEVENT_BLOCK_JOB_CANCELLED, obj); |
1821 | 370521a1 | Stefan Hajnoczi | } else {
|
1822 | 370521a1 | Stefan Hajnoczi | monitor_protocol_event(QEVENT_BLOCK_JOB_COMPLETED, obj); |
1823 | 370521a1 | Stefan Hajnoczi | } |
1824 | 12bd451f | Stefan Hajnoczi | qobject_decref(obj); |
1825 | aa398a5c | Stefan Hajnoczi | |
1826 | fa510ebf | Fam Zheng | bdrv_put_ref_bh_schedule(bs); |
1827 | 12bd451f | Stefan Hajnoczi | } |
1828 | 12bd451f | Stefan Hajnoczi | |
1829 | 12bd451f | Stefan Hajnoczi | void qmp_block_stream(const char *device, bool has_base, |
1830 | 1d809098 | Paolo Bonzini | const char *base, bool has_speed, int64_t speed, |
1831 | 1d809098 | Paolo Bonzini | bool has_on_error, BlockdevOnError on_error,
|
1832 | 1d809098 | Paolo Bonzini | Error **errp) |
1833 | 12bd451f | Stefan Hajnoczi | { |
1834 | 12bd451f | Stefan Hajnoczi | BlockDriverState *bs; |
1835 | c8c3080f | Marcelo Tosatti | BlockDriverState *base_bs = NULL;
|
1836 | fd7f8c65 | Stefan Hajnoczi | Error *local_err = NULL;
|
1837 | 12bd451f | Stefan Hajnoczi | |
1838 | 1d809098 | Paolo Bonzini | if (!has_on_error) {
|
1839 | 1d809098 | Paolo Bonzini | on_error = BLOCKDEV_ON_ERROR_REPORT; |
1840 | 1d809098 | Paolo Bonzini | } |
1841 | 1d809098 | Paolo Bonzini | |
1842 | 12bd451f | Stefan Hajnoczi | bs = bdrv_find(device); |
1843 | 12bd451f | Stefan Hajnoczi | if (!bs) {
|
1844 | 12bd451f | Stefan Hajnoczi | error_set(errp, QERR_DEVICE_NOT_FOUND, device); |
1845 | 12bd451f | Stefan Hajnoczi | return;
|
1846 | 12bd451f | Stefan Hajnoczi | } |
1847 | 12bd451f | Stefan Hajnoczi | |
1848 | 12bd451f | Stefan Hajnoczi | if (base) {
|
1849 | c8c3080f | Marcelo Tosatti | base_bs = bdrv_find_backing_image(bs, base); |
1850 | c8c3080f | Marcelo Tosatti | if (base_bs == NULL) { |
1851 | c8c3080f | Marcelo Tosatti | error_set(errp, QERR_BASE_NOT_FOUND, base); |
1852 | c8c3080f | Marcelo Tosatti | return;
|
1853 | c8c3080f | Marcelo Tosatti | } |
1854 | 12bd451f | Stefan Hajnoczi | } |
1855 | 12bd451f | Stefan Hajnoczi | |
1856 | c83c66c3 | Stefan Hajnoczi | stream_start(bs, base_bs, base, has_speed ? speed : 0,
|
1857 | 1d809098 | Paolo Bonzini | on_error, block_job_cb, bs, &local_err); |
1858 | 84d18f06 | Markus Armbruster | if (local_err) {
|
1859 | fd7f8c65 | Stefan Hajnoczi | error_propagate(errp, local_err); |
1860 | fd7f8c65 | Stefan Hajnoczi | return;
|
1861 | 12bd451f | Stefan Hajnoczi | } |
1862 | 12bd451f | Stefan Hajnoczi | |
1863 | 12bd451f | Stefan Hajnoczi | trace_qmp_block_stream(bs, bs->job); |
1864 | 12bd451f | Stefan Hajnoczi | } |
1865 | 2d47c6e9 | Stefan Hajnoczi | |
1866 | ed61fc10 | Jeff Cody | void qmp_block_commit(const char *device, |
1867 | ed61fc10 | Jeff Cody | bool has_base, const char *base, const char *top, |
1868 | ed61fc10 | Jeff Cody | bool has_speed, int64_t speed,
|
1869 | ed61fc10 | Jeff Cody | Error **errp) |
1870 | ed61fc10 | Jeff Cody | { |
1871 | ed61fc10 | Jeff Cody | BlockDriverState *bs; |
1872 | ed61fc10 | Jeff Cody | BlockDriverState *base_bs, *top_bs; |
1873 | ed61fc10 | Jeff Cody | Error *local_err = NULL;
|
1874 | ed61fc10 | Jeff Cody | /* This will be part of the QMP command, if/when the
|
1875 | ed61fc10 | Jeff Cody | * BlockdevOnError change for blkmirror makes it in
|
1876 | ed61fc10 | Jeff Cody | */
|
1877 | 92aa5c6d | Paolo Bonzini | BlockdevOnError on_error = BLOCKDEV_ON_ERROR_REPORT; |
1878 | ed61fc10 | Jeff Cody | |
1879 | ed61fc10 | Jeff Cody | /* drain all i/o before commits */
|
1880 | ed61fc10 | Jeff Cody | bdrv_drain_all(); |
1881 | ed61fc10 | Jeff Cody | |
1882 | ed61fc10 | Jeff Cody | bs = bdrv_find(device); |
1883 | ed61fc10 | Jeff Cody | if (!bs) {
|
1884 | ed61fc10 | Jeff Cody | error_set(errp, QERR_DEVICE_NOT_FOUND, device); |
1885 | ed61fc10 | Jeff Cody | return;
|
1886 | ed61fc10 | Jeff Cody | } |
1887 | ed61fc10 | Jeff Cody | |
1888 | ed61fc10 | Jeff Cody | /* default top_bs is the active layer */
|
1889 | ed61fc10 | Jeff Cody | top_bs = bs; |
1890 | ed61fc10 | Jeff Cody | |
1891 | ed61fc10 | Jeff Cody | if (top) {
|
1892 | ed61fc10 | Jeff Cody | if (strcmp(bs->filename, top) != 0) { |
1893 | ed61fc10 | Jeff Cody | top_bs = bdrv_find_backing_image(bs, top); |
1894 | ed61fc10 | Jeff Cody | } |
1895 | ed61fc10 | Jeff Cody | } |
1896 | ed61fc10 | Jeff Cody | |
1897 | ed61fc10 | Jeff Cody | if (top_bs == NULL) { |
1898 | ed61fc10 | Jeff Cody | error_setg(errp, "Top image file %s not found", top ? top : "NULL"); |
1899 | ed61fc10 | Jeff Cody | return;
|
1900 | ed61fc10 | Jeff Cody | } |
1901 | ed61fc10 | Jeff Cody | |
1902 | d5208c45 | Jeff Cody | if (has_base && base) {
|
1903 | d5208c45 | Jeff Cody | base_bs = bdrv_find_backing_image(top_bs, base); |
1904 | d5208c45 | Jeff Cody | } else {
|
1905 | d5208c45 | Jeff Cody | base_bs = bdrv_find_base(top_bs); |
1906 | d5208c45 | Jeff Cody | } |
1907 | d5208c45 | Jeff Cody | |
1908 | d5208c45 | Jeff Cody | if (base_bs == NULL) { |
1909 | d5208c45 | Jeff Cody | error_set(errp, QERR_BASE_NOT_FOUND, base ? base : "NULL");
|
1910 | d5208c45 | Jeff Cody | return;
|
1911 | d5208c45 | Jeff Cody | } |
1912 | d5208c45 | Jeff Cody | |
1913 | 20a63d2c | Fam Zheng | if (top_bs == bs) {
|
1914 | 20a63d2c | Fam Zheng | commit_active_start(bs, base_bs, speed, on_error, block_job_cb, |
1915 | 20a63d2c | Fam Zheng | bs, &local_err); |
1916 | 20a63d2c | Fam Zheng | } else {
|
1917 | 20a63d2c | Fam Zheng | commit_start(bs, base_bs, top_bs, speed, on_error, block_job_cb, bs, |
1918 | 20a63d2c | Fam Zheng | &local_err); |
1919 | 20a63d2c | Fam Zheng | } |
1920 | ed61fc10 | Jeff Cody | if (local_err != NULL) { |
1921 | ed61fc10 | Jeff Cody | error_propagate(errp, local_err); |
1922 | ed61fc10 | Jeff Cody | return;
|
1923 | ed61fc10 | Jeff Cody | } |
1924 | ed61fc10 | Jeff Cody | } |
1925 | ed61fc10 | Jeff Cody | |
1926 | 99a9addf | Stefan Hajnoczi | void qmp_drive_backup(const char *device, const char *target, |
1927 | 99a9addf | Stefan Hajnoczi | bool has_format, const char *format, |
1928 | b53169ea | Stefan Hajnoczi | enum MirrorSyncMode sync,
|
1929 | 99a9addf | Stefan Hajnoczi | bool has_mode, enum NewImageMode mode, |
1930 | 99a9addf | Stefan Hajnoczi | bool has_speed, int64_t speed,
|
1931 | 99a9addf | Stefan Hajnoczi | bool has_on_source_error, BlockdevOnError on_source_error,
|
1932 | 99a9addf | Stefan Hajnoczi | bool has_on_target_error, BlockdevOnError on_target_error,
|
1933 | 99a9addf | Stefan Hajnoczi | Error **errp) |
1934 | 99a9addf | Stefan Hajnoczi | { |
1935 | 99a9addf | Stefan Hajnoczi | BlockDriverState *bs; |
1936 | 99a9addf | Stefan Hajnoczi | BlockDriverState *target_bs; |
1937 | fc5d3f84 | Ian Main | BlockDriverState *source = NULL;
|
1938 | 99a9addf | Stefan Hajnoczi | BlockDriver *drv = NULL;
|
1939 | 99a9addf | Stefan Hajnoczi | Error *local_err = NULL;
|
1940 | 99a9addf | Stefan Hajnoczi | int flags;
|
1941 | 99a9addf | Stefan Hajnoczi | int64_t size; |
1942 | 99a9addf | Stefan Hajnoczi | int ret;
|
1943 | 99a9addf | Stefan Hajnoczi | |
1944 | 99a9addf | Stefan Hajnoczi | if (!has_speed) {
|
1945 | 99a9addf | Stefan Hajnoczi | speed = 0;
|
1946 | 99a9addf | Stefan Hajnoczi | } |
1947 | 99a9addf | Stefan Hajnoczi | if (!has_on_source_error) {
|
1948 | 99a9addf | Stefan Hajnoczi | on_source_error = BLOCKDEV_ON_ERROR_REPORT; |
1949 | 99a9addf | Stefan Hajnoczi | } |
1950 | 99a9addf | Stefan Hajnoczi | if (!has_on_target_error) {
|
1951 | 99a9addf | Stefan Hajnoczi | on_target_error = BLOCKDEV_ON_ERROR_REPORT; |
1952 | 99a9addf | Stefan Hajnoczi | } |
1953 | 99a9addf | Stefan Hajnoczi | if (!has_mode) {
|
1954 | 99a9addf | Stefan Hajnoczi | mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS; |
1955 | 99a9addf | Stefan Hajnoczi | } |
1956 | 99a9addf | Stefan Hajnoczi | |
1957 | 99a9addf | Stefan Hajnoczi | bs = bdrv_find(device); |
1958 | 99a9addf | Stefan Hajnoczi | if (!bs) {
|
1959 | 99a9addf | Stefan Hajnoczi | error_set(errp, QERR_DEVICE_NOT_FOUND, device); |
1960 | 99a9addf | Stefan Hajnoczi | return;
|
1961 | 99a9addf | Stefan Hajnoczi | } |
1962 | 99a9addf | Stefan Hajnoczi | |
1963 | 99a9addf | Stefan Hajnoczi | if (!bdrv_is_inserted(bs)) {
|
1964 | 99a9addf | Stefan Hajnoczi | error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device); |
1965 | 99a9addf | Stefan Hajnoczi | return;
|
1966 | 99a9addf | Stefan Hajnoczi | } |
1967 | 99a9addf | Stefan Hajnoczi | |
1968 | 99a9addf | Stefan Hajnoczi | if (!has_format) {
|
1969 | 99a9addf | Stefan Hajnoczi | format = mode == NEW_IMAGE_MODE_EXISTING ? NULL : bs->drv->format_name;
|
1970 | 99a9addf | Stefan Hajnoczi | } |
1971 | 99a9addf | Stefan Hajnoczi | if (format) {
|
1972 | 99a9addf | Stefan Hajnoczi | drv = bdrv_find_format(format); |
1973 | 99a9addf | Stefan Hajnoczi | if (!drv) {
|
1974 | 99a9addf | Stefan Hajnoczi | error_set(errp, QERR_INVALID_BLOCK_FORMAT, format); |
1975 | 99a9addf | Stefan Hajnoczi | return;
|
1976 | 99a9addf | Stefan Hajnoczi | } |
1977 | 99a9addf | Stefan Hajnoczi | } |
1978 | 99a9addf | Stefan Hajnoczi | |
1979 | 99a9addf | Stefan Hajnoczi | if (bdrv_in_use(bs)) {
|
1980 | 99a9addf | Stefan Hajnoczi | error_set(errp, QERR_DEVICE_IN_USE, device); |
1981 | 99a9addf | Stefan Hajnoczi | return;
|
1982 | 99a9addf | Stefan Hajnoczi | } |
1983 | 99a9addf | Stefan Hajnoczi | |
1984 | 99a9addf | Stefan Hajnoczi | flags = bs->open_flags | BDRV_O_RDWR; |
1985 | 99a9addf | Stefan Hajnoczi | |
1986 | fc5d3f84 | Ian Main | /* See if we have a backing HD we can use to create our new image
|
1987 | fc5d3f84 | Ian Main | * on top of. */
|
1988 | fc5d3f84 | Ian Main | if (sync == MIRROR_SYNC_MODE_TOP) {
|
1989 | fc5d3f84 | Ian Main | source = bs->backing_hd; |
1990 | fc5d3f84 | Ian Main | if (!source) {
|
1991 | fc5d3f84 | Ian Main | sync = MIRROR_SYNC_MODE_FULL; |
1992 | fc5d3f84 | Ian Main | } |
1993 | fc5d3f84 | Ian Main | } |
1994 | fc5d3f84 | Ian Main | if (sync == MIRROR_SYNC_MODE_NONE) {
|
1995 | fc5d3f84 | Ian Main | source = bs; |
1996 | fc5d3f84 | Ian Main | } |
1997 | fc5d3f84 | Ian Main | |
1998 | 99a9addf | Stefan Hajnoczi | size = bdrv_getlength(bs); |
1999 | 99a9addf | Stefan Hajnoczi | if (size < 0) { |
2000 | 99a9addf | Stefan Hajnoczi | error_setg_errno(errp, -size, "bdrv_getlength failed");
|
2001 | 99a9addf | Stefan Hajnoczi | return;
|
2002 | 99a9addf | Stefan Hajnoczi | } |
2003 | 99a9addf | Stefan Hajnoczi | |
2004 | 99a9addf | Stefan Hajnoczi | if (mode != NEW_IMAGE_MODE_EXISTING) {
|
2005 | 99a9addf | Stefan Hajnoczi | assert(format && drv); |
2006 | fc5d3f84 | Ian Main | if (source) {
|
2007 | fc5d3f84 | Ian Main | bdrv_img_create(target, format, source->filename, |
2008 | fc5d3f84 | Ian Main | source->drv->format_name, NULL,
|
2009 | fc5d3f84 | Ian Main | size, flags, &local_err, false);
|
2010 | fc5d3f84 | Ian Main | } else {
|
2011 | fc5d3f84 | Ian Main | bdrv_img_create(target, format, NULL, NULL, NULL, |
2012 | fc5d3f84 | Ian Main | size, flags, &local_err, false);
|
2013 | fc5d3f84 | Ian Main | } |
2014 | 99a9addf | Stefan Hajnoczi | } |
2015 | 99a9addf | Stefan Hajnoczi | |
2016 | 84d18f06 | Markus Armbruster | if (local_err) {
|
2017 | 99a9addf | Stefan Hajnoczi | error_propagate(errp, local_err); |
2018 | 99a9addf | Stefan Hajnoczi | return;
|
2019 | 99a9addf | Stefan Hajnoczi | } |
2020 | 99a9addf | Stefan Hajnoczi | |
2021 | f67503e5 | Max Reitz | target_bs = NULL;
|
2022 | ddf5636d | Max Reitz | ret = bdrv_open(&target_bs, target, NULL, NULL, flags, drv, &local_err); |
2023 | 99a9addf | Stefan Hajnoczi | if (ret < 0) { |
2024 | 34b5d2c6 | Max Reitz | error_propagate(errp, local_err); |
2025 | 99a9addf | Stefan Hajnoczi | return;
|
2026 | 99a9addf | Stefan Hajnoczi | } |
2027 | 99a9addf | Stefan Hajnoczi | |
2028 | fc5d3f84 | Ian Main | backup_start(bs, target_bs, speed, sync, on_source_error, on_target_error, |
2029 | 99a9addf | Stefan Hajnoczi | block_job_cb, bs, &local_err); |
2030 | 99a9addf | Stefan Hajnoczi | if (local_err != NULL) { |
2031 | 4f6fd349 | Fam Zheng | bdrv_unref(target_bs); |
2032 | 99a9addf | Stefan Hajnoczi | error_propagate(errp, local_err); |
2033 | 99a9addf | Stefan Hajnoczi | return;
|
2034 | 99a9addf | Stefan Hajnoczi | } |
2035 | 99a9addf | Stefan Hajnoczi | } |
2036 | 99a9addf | Stefan Hajnoczi | |
2037 | c13163fb | Benoît Canet | BlockDeviceInfoList *qmp_query_named_block_nodes(Error **errp) |
2038 | c13163fb | Benoît Canet | { |
2039 | c13163fb | Benoît Canet | return bdrv_named_nodes_list();
|
2040 | c13163fb | Benoît Canet | } |
2041 | c13163fb | Benoît Canet | |
2042 | 08e4ed6c | Paolo Bonzini | #define DEFAULT_MIRROR_BUF_SIZE (10 << 20) |
2043 | 08e4ed6c | Paolo Bonzini | |
2044 | d9b902db | Paolo Bonzini | void qmp_drive_mirror(const char *device, const char *target, |
2045 | d9b902db | Paolo Bonzini | bool has_format, const char *format, |
2046 | d9b902db | Paolo Bonzini | enum MirrorSyncMode sync,
|
2047 | d9b902db | Paolo Bonzini | bool has_mode, enum NewImageMode mode, |
2048 | b952b558 | Paolo Bonzini | bool has_speed, int64_t speed,
|
2049 | eee13dfe | Paolo Bonzini | bool has_granularity, uint32_t granularity,
|
2050 | 08e4ed6c | Paolo Bonzini | bool has_buf_size, int64_t buf_size,
|
2051 | b952b558 | Paolo Bonzini | bool has_on_source_error, BlockdevOnError on_source_error,
|
2052 | b952b558 | Paolo Bonzini | bool has_on_target_error, BlockdevOnError on_target_error,
|
2053 | b952b558 | Paolo Bonzini | Error **errp) |
2054 | d9b902db | Paolo Bonzini | { |
2055 | d9b902db | Paolo Bonzini | BlockDriverState *bs; |
2056 | d9b902db | Paolo Bonzini | BlockDriverState *source, *target_bs; |
2057 | d9b902db | Paolo Bonzini | BlockDriver *drv = NULL;
|
2058 | d9b902db | Paolo Bonzini | Error *local_err = NULL;
|
2059 | d9b902db | Paolo Bonzini | int flags;
|
2060 | ac3c5d83 | Stefan Hajnoczi | int64_t size; |
2061 | d9b902db | Paolo Bonzini | int ret;
|
2062 | d9b902db | Paolo Bonzini | |
2063 | d9b902db | Paolo Bonzini | if (!has_speed) {
|
2064 | d9b902db | Paolo Bonzini | speed = 0;
|
2065 | d9b902db | Paolo Bonzini | } |
2066 | b952b558 | Paolo Bonzini | if (!has_on_source_error) {
|
2067 | b952b558 | Paolo Bonzini | on_source_error = BLOCKDEV_ON_ERROR_REPORT; |
2068 | b952b558 | Paolo Bonzini | } |
2069 | b952b558 | Paolo Bonzini | if (!has_on_target_error) {
|
2070 | b952b558 | Paolo Bonzini | on_target_error = BLOCKDEV_ON_ERROR_REPORT; |
2071 | b952b558 | Paolo Bonzini | } |
2072 | d9b902db | Paolo Bonzini | if (!has_mode) {
|
2073 | d9b902db | Paolo Bonzini | mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS; |
2074 | d9b902db | Paolo Bonzini | } |
2075 | eee13dfe | Paolo Bonzini | if (!has_granularity) {
|
2076 | eee13dfe | Paolo Bonzini | granularity = 0;
|
2077 | eee13dfe | Paolo Bonzini | } |
2078 | 08e4ed6c | Paolo Bonzini | if (!has_buf_size) {
|
2079 | 08e4ed6c | Paolo Bonzini | buf_size = DEFAULT_MIRROR_BUF_SIZE; |
2080 | 08e4ed6c | Paolo Bonzini | } |
2081 | 08e4ed6c | Paolo Bonzini | |
2082 | eee13dfe | Paolo Bonzini | if (granularity != 0 && (granularity < 512 || granularity > 1048576 * 64)) { |
2083 | eee13dfe | Paolo Bonzini | error_set(errp, QERR_INVALID_PARAMETER, device); |
2084 | eee13dfe | Paolo Bonzini | return;
|
2085 | eee13dfe | Paolo Bonzini | } |
2086 | eee13dfe | Paolo Bonzini | if (granularity & (granularity - 1)) { |
2087 | eee13dfe | Paolo Bonzini | error_set(errp, QERR_INVALID_PARAMETER, device); |
2088 | eee13dfe | Paolo Bonzini | return;
|
2089 | eee13dfe | Paolo Bonzini | } |
2090 | d9b902db | Paolo Bonzini | |
2091 | d9b902db | Paolo Bonzini | bs = bdrv_find(device); |
2092 | d9b902db | Paolo Bonzini | if (!bs) {
|
2093 | d9b902db | Paolo Bonzini | error_set(errp, QERR_DEVICE_NOT_FOUND, device); |
2094 | d9b902db | Paolo Bonzini | return;
|
2095 | d9b902db | Paolo Bonzini | } |
2096 | d9b902db | Paolo Bonzini | |
2097 | d9b902db | Paolo Bonzini | if (!bdrv_is_inserted(bs)) {
|
2098 | d9b902db | Paolo Bonzini | error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device); |
2099 | d9b902db | Paolo Bonzini | return;
|
2100 | d9b902db | Paolo Bonzini | } |
2101 | d9b902db | Paolo Bonzini | |
2102 | d9b902db | Paolo Bonzini | if (!has_format) {
|
2103 | d9b902db | Paolo Bonzini | format = mode == NEW_IMAGE_MODE_EXISTING ? NULL : bs->drv->format_name;
|
2104 | d9b902db | Paolo Bonzini | } |
2105 | d9b902db | Paolo Bonzini | if (format) {
|
2106 | d9b902db | Paolo Bonzini | drv = bdrv_find_format(format); |
2107 | d9b902db | Paolo Bonzini | if (!drv) {
|
2108 | d9b902db | Paolo Bonzini | error_set(errp, QERR_INVALID_BLOCK_FORMAT, format); |
2109 | d9b902db | Paolo Bonzini | return;
|
2110 | d9b902db | Paolo Bonzini | } |
2111 | d9b902db | Paolo Bonzini | } |
2112 | d9b902db | Paolo Bonzini | |
2113 | d9b902db | Paolo Bonzini | if (bdrv_in_use(bs)) {
|
2114 | d9b902db | Paolo Bonzini | error_set(errp, QERR_DEVICE_IN_USE, device); |
2115 | d9b902db | Paolo Bonzini | return;
|
2116 | d9b902db | Paolo Bonzini | } |
2117 | d9b902db | Paolo Bonzini | |
2118 | d9b902db | Paolo Bonzini | flags = bs->open_flags | BDRV_O_RDWR; |
2119 | d9b902db | Paolo Bonzini | source = bs->backing_hd; |
2120 | d9b902db | Paolo Bonzini | if (!source && sync == MIRROR_SYNC_MODE_TOP) {
|
2121 | d9b902db | Paolo Bonzini | sync = MIRROR_SYNC_MODE_FULL; |
2122 | d9b902db | Paolo Bonzini | } |
2123 | 117e0c82 | Max Reitz | if (sync == MIRROR_SYNC_MODE_NONE) {
|
2124 | 117e0c82 | Max Reitz | source = bs; |
2125 | 117e0c82 | Max Reitz | } |
2126 | d9b902db | Paolo Bonzini | |
2127 | ac3c5d83 | Stefan Hajnoczi | size = bdrv_getlength(bs); |
2128 | ac3c5d83 | Stefan Hajnoczi | if (size < 0) { |
2129 | ac3c5d83 | Stefan Hajnoczi | error_setg_errno(errp, -size, "bdrv_getlength failed");
|
2130 | ac3c5d83 | Stefan Hajnoczi | return;
|
2131 | ac3c5d83 | Stefan Hajnoczi | } |
2132 | ac3c5d83 | Stefan Hajnoczi | |
2133 | 14526864 | Max Reitz | if ((sync == MIRROR_SYNC_MODE_FULL || !source)
|
2134 | 14526864 | Max Reitz | && mode != NEW_IMAGE_MODE_EXISTING) |
2135 | 14526864 | Max Reitz | { |
2136 | d9b902db | Paolo Bonzini | /* create new image w/o backing file */
|
2137 | d9b902db | Paolo Bonzini | assert(format && drv); |
2138 | cf8f2426 | Luiz Capitulino | bdrv_img_create(target, format, |
2139 | f382d43a | Miroslav Rezanina | NULL, NULL, NULL, size, flags, &local_err, false); |
2140 | d9b902db | Paolo Bonzini | } else {
|
2141 | d9b902db | Paolo Bonzini | switch (mode) {
|
2142 | d9b902db | Paolo Bonzini | case NEW_IMAGE_MODE_EXISTING:
|
2143 | d9b902db | Paolo Bonzini | break;
|
2144 | d9b902db | Paolo Bonzini | case NEW_IMAGE_MODE_ABSOLUTE_PATHS:
|
2145 | d9b902db | Paolo Bonzini | /* create new image with backing file */
|
2146 | cf8f2426 | Luiz Capitulino | bdrv_img_create(target, format, |
2147 | cf8f2426 | Luiz Capitulino | source->filename, |
2148 | cf8f2426 | Luiz Capitulino | source->drv->format_name, |
2149 | f382d43a | Miroslav Rezanina | NULL, size, flags, &local_err, false); |
2150 | d9b902db | Paolo Bonzini | break;
|
2151 | d9b902db | Paolo Bonzini | default:
|
2152 | d9b902db | Paolo Bonzini | abort(); |
2153 | d9b902db | Paolo Bonzini | } |
2154 | d9b902db | Paolo Bonzini | } |
2155 | d9b902db | Paolo Bonzini | |
2156 | 84d18f06 | Markus Armbruster | if (local_err) {
|
2157 | cf8f2426 | Luiz Capitulino | error_propagate(errp, local_err); |
2158 | d9b902db | Paolo Bonzini | return;
|
2159 | d9b902db | Paolo Bonzini | } |
2160 | d9b902db | Paolo Bonzini | |
2161 | b812f671 | Paolo Bonzini | /* Mirroring takes care of copy-on-write using the source's backing
|
2162 | b812f671 | Paolo Bonzini | * file.
|
2163 | b812f671 | Paolo Bonzini | */
|
2164 | f67503e5 | Max Reitz | target_bs = NULL;
|
2165 | ddf5636d | Max Reitz | ret = bdrv_open(&target_bs, target, NULL, NULL, flags | BDRV_O_NO_BACKING, |
2166 | ddf5636d | Max Reitz | drv, &local_err); |
2167 | d9b902db | Paolo Bonzini | if (ret < 0) { |
2168 | 34b5d2c6 | Max Reitz | error_propagate(errp, local_err); |
2169 | d9b902db | Paolo Bonzini | return;
|
2170 | d9b902db | Paolo Bonzini | } |
2171 | d9b902db | Paolo Bonzini | |
2172 | 08e4ed6c | Paolo Bonzini | mirror_start(bs, target_bs, speed, granularity, buf_size, sync, |
2173 | eee13dfe | Paolo Bonzini | on_source_error, on_target_error, |
2174 | b952b558 | Paolo Bonzini | block_job_cb, bs, &local_err); |
2175 | d9b902db | Paolo Bonzini | if (local_err != NULL) { |
2176 | 4f6fd349 | Fam Zheng | bdrv_unref(target_bs); |
2177 | d9b902db | Paolo Bonzini | error_propagate(errp, local_err); |
2178 | d9b902db | Paolo Bonzini | return;
|
2179 | d9b902db | Paolo Bonzini | } |
2180 | d9b902db | Paolo Bonzini | } |
2181 | d9b902db | Paolo Bonzini | |
2182 | 2d47c6e9 | Stefan Hajnoczi | static BlockJob *find_block_job(const char *device) |
2183 | 2d47c6e9 | Stefan Hajnoczi | { |
2184 | 2d47c6e9 | Stefan Hajnoczi | BlockDriverState *bs; |
2185 | 2d47c6e9 | Stefan Hajnoczi | |
2186 | 2d47c6e9 | Stefan Hajnoczi | bs = bdrv_find(device); |
2187 | 2d47c6e9 | Stefan Hajnoczi | if (!bs || !bs->job) {
|
2188 | 2d47c6e9 | Stefan Hajnoczi | return NULL; |
2189 | 2d47c6e9 | Stefan Hajnoczi | } |
2190 | 2d47c6e9 | Stefan Hajnoczi | return bs->job;
|
2191 | 2d47c6e9 | Stefan Hajnoczi | } |
2192 | 2d47c6e9 | Stefan Hajnoczi | |
2193 | 882ec7ce | Stefan Hajnoczi | void qmp_block_job_set_speed(const char *device, int64_t speed, Error **errp) |
2194 | 2d47c6e9 | Stefan Hajnoczi | { |
2195 | 2d47c6e9 | Stefan Hajnoczi | BlockJob *job = find_block_job(device); |
2196 | 2d47c6e9 | Stefan Hajnoczi | |
2197 | 2d47c6e9 | Stefan Hajnoczi | if (!job) {
|
2198 | 7ef15070 | Paolo Bonzini | error_set(errp, QERR_BLOCK_JOB_NOT_ACTIVE, device); |
2199 | 2d47c6e9 | Stefan Hajnoczi | return;
|
2200 | 2d47c6e9 | Stefan Hajnoczi | } |
2201 | 2d47c6e9 | Stefan Hajnoczi | |
2202 | 882ec7ce | Stefan Hajnoczi | block_job_set_speed(job, speed, errp); |
2203 | 2d47c6e9 | Stefan Hajnoczi | } |
2204 | 370521a1 | Stefan Hajnoczi | |
2205 | 6e37fb81 | Paolo Bonzini | void qmp_block_job_cancel(const char *device, |
2206 | 6e37fb81 | Paolo Bonzini | bool has_force, bool force, Error **errp) |
2207 | 370521a1 | Stefan Hajnoczi | { |
2208 | 370521a1 | Stefan Hajnoczi | BlockJob *job = find_block_job(device); |
2209 | 370521a1 | Stefan Hajnoczi | |
2210 | 6e37fb81 | Paolo Bonzini | if (!has_force) {
|
2211 | 6e37fb81 | Paolo Bonzini | force = false;
|
2212 | 6e37fb81 | Paolo Bonzini | } |
2213 | 6e37fb81 | Paolo Bonzini | |
2214 | 370521a1 | Stefan Hajnoczi | if (!job) {
|
2215 | 7ef15070 | Paolo Bonzini | error_set(errp, QERR_BLOCK_JOB_NOT_ACTIVE, device); |
2216 | 370521a1 | Stefan Hajnoczi | return;
|
2217 | 370521a1 | Stefan Hajnoczi | } |
2218 | 6e37fb81 | Paolo Bonzini | if (job->paused && !force) {
|
2219 | 8acc72a4 | Paolo Bonzini | error_set(errp, QERR_BLOCK_JOB_PAUSED, device); |
2220 | 8acc72a4 | Paolo Bonzini | return;
|
2221 | 8acc72a4 | Paolo Bonzini | } |
2222 | 370521a1 | Stefan Hajnoczi | |
2223 | 370521a1 | Stefan Hajnoczi | trace_qmp_block_job_cancel(job); |
2224 | 370521a1 | Stefan Hajnoczi | block_job_cancel(job); |
2225 | 370521a1 | Stefan Hajnoczi | } |
2226 | fb5458cd | Stefan Hajnoczi | |
2227 | 6e37fb81 | Paolo Bonzini | void qmp_block_job_pause(const char *device, Error **errp) |
2228 | 6e37fb81 | Paolo Bonzini | { |
2229 | 6e37fb81 | Paolo Bonzini | BlockJob *job = find_block_job(device); |
2230 | 6e37fb81 | Paolo Bonzini | |
2231 | 6e37fb81 | Paolo Bonzini | if (!job) {
|
2232 | 6e37fb81 | Paolo Bonzini | error_set(errp, QERR_BLOCK_JOB_NOT_ACTIVE, device); |
2233 | 6e37fb81 | Paolo Bonzini | return;
|
2234 | 6e37fb81 | Paolo Bonzini | } |
2235 | 6e37fb81 | Paolo Bonzini | |
2236 | 6e37fb81 | Paolo Bonzini | trace_qmp_block_job_pause(job); |
2237 | 6e37fb81 | Paolo Bonzini | block_job_pause(job); |
2238 | 6e37fb81 | Paolo Bonzini | } |
2239 | 6e37fb81 | Paolo Bonzini | |
2240 | 6e37fb81 | Paolo Bonzini | void qmp_block_job_resume(const char *device, Error **errp) |
2241 | 6e37fb81 | Paolo Bonzini | { |
2242 | 6e37fb81 | Paolo Bonzini | BlockJob *job = find_block_job(device); |
2243 | 6e37fb81 | Paolo Bonzini | |
2244 | 6e37fb81 | Paolo Bonzini | if (!job) {
|
2245 | 6e37fb81 | Paolo Bonzini | error_set(errp, QERR_BLOCK_JOB_NOT_ACTIVE, device); |
2246 | 6e37fb81 | Paolo Bonzini | return;
|
2247 | 6e37fb81 | Paolo Bonzini | } |
2248 | 6e37fb81 | Paolo Bonzini | |
2249 | 6e37fb81 | Paolo Bonzini | trace_qmp_block_job_resume(job); |
2250 | 6e37fb81 | Paolo Bonzini | block_job_resume(job); |
2251 | 6e37fb81 | Paolo Bonzini | } |
2252 | 6e37fb81 | Paolo Bonzini | |
2253 | aeae883b | Paolo Bonzini | void qmp_block_job_complete(const char *device, Error **errp) |
2254 | aeae883b | Paolo Bonzini | { |
2255 | aeae883b | Paolo Bonzini | BlockJob *job = find_block_job(device); |
2256 | aeae883b | Paolo Bonzini | |
2257 | aeae883b | Paolo Bonzini | if (!job) {
|
2258 | aeae883b | Paolo Bonzini | error_set(errp, QERR_BLOCK_JOB_NOT_ACTIVE, device); |
2259 | aeae883b | Paolo Bonzini | return;
|
2260 | aeae883b | Paolo Bonzini | } |
2261 | aeae883b | Paolo Bonzini | |
2262 | aeae883b | Paolo Bonzini | trace_qmp_block_job_complete(job); |
2263 | aeae883b | Paolo Bonzini | block_job_complete(job, errp); |
2264 | aeae883b | Paolo Bonzini | } |
2265 | aeae883b | Paolo Bonzini | |
2266 | d26c9a15 | Kevin Wolf | void qmp_blockdev_add(BlockdevOptions *options, Error **errp)
|
2267 | d26c9a15 | Kevin Wolf | { |
2268 | d26c9a15 | Kevin Wolf | QmpOutputVisitor *ov = qmp_output_visitor_new(); |
2269 | d26c9a15 | Kevin Wolf | QObject *obj; |
2270 | d26c9a15 | Kevin Wolf | QDict *qdict; |
2271 | d26c9a15 | Kevin Wolf | Error *local_err = NULL;
|
2272 | d26c9a15 | Kevin Wolf | |
2273 | d26c9a15 | Kevin Wolf | /* Require an ID in the top level */
|
2274 | d26c9a15 | Kevin Wolf | if (!options->has_id) {
|
2275 | d26c9a15 | Kevin Wolf | error_setg(errp, "Block device needs an ID");
|
2276 | d26c9a15 | Kevin Wolf | goto fail;
|
2277 | d26c9a15 | Kevin Wolf | } |
2278 | d26c9a15 | Kevin Wolf | |
2279 | d26c9a15 | Kevin Wolf | /* TODO Sort it out in raw-posix and drive_init: Reject aio=native with
|
2280 | d26c9a15 | Kevin Wolf | * cache.direct=false instead of silently switching to aio=threads, except
|
2281 | d26c9a15 | Kevin Wolf | * if called from drive_init.
|
2282 | d26c9a15 | Kevin Wolf | *
|
2283 | d26c9a15 | Kevin Wolf | * For now, simply forbidding the combination for all drivers will do. */
|
2284 | d26c9a15 | Kevin Wolf | if (options->has_aio && options->aio == BLOCKDEV_AIO_OPTIONS_NATIVE) {
|
2285 | d26c9a15 | Kevin Wolf | bool direct = options->cache->has_direct && options->cache->direct;
|
2286 | d26c9a15 | Kevin Wolf | if (!options->has_cache && !direct) {
|
2287 | d26c9a15 | Kevin Wolf | error_setg(errp, "aio=native requires cache.direct=true");
|
2288 | d26c9a15 | Kevin Wolf | goto fail;
|
2289 | d26c9a15 | Kevin Wolf | } |
2290 | d26c9a15 | Kevin Wolf | } |
2291 | d26c9a15 | Kevin Wolf | |
2292 | d26c9a15 | Kevin Wolf | visit_type_BlockdevOptions(qmp_output_get_visitor(ov), |
2293 | d26c9a15 | Kevin Wolf | &options, NULL, &local_err);
|
2294 | 84d18f06 | Markus Armbruster | if (local_err) {
|
2295 | d26c9a15 | Kevin Wolf | error_propagate(errp, local_err); |
2296 | d26c9a15 | Kevin Wolf | goto fail;
|
2297 | d26c9a15 | Kevin Wolf | } |
2298 | d26c9a15 | Kevin Wolf | |
2299 | d26c9a15 | Kevin Wolf | obj = qmp_output_get_qobject(ov); |
2300 | d26c9a15 | Kevin Wolf | qdict = qobject_to_qdict(obj); |
2301 | d26c9a15 | Kevin Wolf | |
2302 | d26c9a15 | Kevin Wolf | qdict_flatten(qdict); |
2303 | d26c9a15 | Kevin Wolf | |
2304 | ee13ed1c | Kevin Wolf | blockdev_init(NULL, qdict, &local_err);
|
2305 | 84d18f06 | Markus Armbruster | if (local_err) {
|
2306 | b681072d | Kevin Wolf | error_propagate(errp, local_err); |
2307 | d26c9a15 | Kevin Wolf | goto fail;
|
2308 | d26c9a15 | Kevin Wolf | } |
2309 | d26c9a15 | Kevin Wolf | |
2310 | d26c9a15 | Kevin Wolf | fail:
|
2311 | d26c9a15 | Kevin Wolf | qmp_output_visitor_cleanup(ov); |
2312 | d26c9a15 | Kevin Wolf | } |
2313 | d26c9a15 | Kevin Wolf | |
2314 | fb5458cd | Stefan Hajnoczi | static void do_qmp_query_block_jobs_one(void *opaque, BlockDriverState *bs) |
2315 | fb5458cd | Stefan Hajnoczi | { |
2316 | fb5458cd | Stefan Hajnoczi | BlockJobInfoList **prev = opaque; |
2317 | fb5458cd | Stefan Hajnoczi | BlockJob *job = bs->job; |
2318 | fb5458cd | Stefan Hajnoczi | |
2319 | fb5458cd | Stefan Hajnoczi | if (job) {
|
2320 | 30e628b7 | Paolo Bonzini | BlockJobInfoList *elem = g_new0(BlockJobInfoList, 1);
|
2321 | 30e628b7 | Paolo Bonzini | elem->value = block_job_query(bs->job); |
2322 | fb5458cd | Stefan Hajnoczi | (*prev)->next = elem; |
2323 | fb5458cd | Stefan Hajnoczi | *prev = elem; |
2324 | fb5458cd | Stefan Hajnoczi | } |
2325 | fb5458cd | Stefan Hajnoczi | } |
2326 | fb5458cd | Stefan Hajnoczi | |
2327 | fb5458cd | Stefan Hajnoczi | BlockJobInfoList *qmp_query_block_jobs(Error **errp) |
2328 | fb5458cd | Stefan Hajnoczi | { |
2329 | fb5458cd | Stefan Hajnoczi | /* Dummy is a fake list element for holding the head pointer */
|
2330 | fb5458cd | Stefan Hajnoczi | BlockJobInfoList dummy = {}; |
2331 | fb5458cd | Stefan Hajnoczi | BlockJobInfoList *prev = &dummy; |
2332 | fb5458cd | Stefan Hajnoczi | bdrv_iterate(do_qmp_query_block_jobs_one, &prev); |
2333 | fb5458cd | Stefan Hajnoczi | return dummy.next;
|
2334 | fb5458cd | Stefan Hajnoczi | } |
2335 | 4d454574 | Paolo Bonzini | |
2336 | 0006383e | Kevin Wolf | QemuOptsList qemu_common_drive_opts = { |
2337 | 4d454574 | Paolo Bonzini | .name = "drive",
|
2338 | 0006383e | Kevin Wolf | .head = QTAILQ_HEAD_INITIALIZER(qemu_common_drive_opts.head), |
2339 | 4d454574 | Paolo Bonzini | .desc = { |
2340 | 4d454574 | Paolo Bonzini | { |
2341 | 4d454574 | Paolo Bonzini | .name = "snapshot",
|
2342 | 4d454574 | Paolo Bonzini | .type = QEMU_OPT_BOOL, |
2343 | 4d454574 | Paolo Bonzini | .help = "enable/disable snapshot mode",
|
2344 | 4d454574 | Paolo Bonzini | },{ |
2345 | a9384aff | Paolo Bonzini | .name = "discard",
|
2346 | a9384aff | Paolo Bonzini | .type = QEMU_OPT_STRING, |
2347 | a9384aff | Paolo Bonzini | .help = "discard operation (ignore/off, unmap/on)",
|
2348 | a9384aff | Paolo Bonzini | },{ |
2349 | 29c4e2b5 | Kevin Wolf | .name = "cache.writeback",
|
2350 | 29c4e2b5 | Kevin Wolf | .type = QEMU_OPT_BOOL, |
2351 | 29c4e2b5 | Kevin Wolf | .help = "enables writeback mode for any caches",
|
2352 | 29c4e2b5 | Kevin Wolf | },{ |
2353 | 29c4e2b5 | Kevin Wolf | .name = "cache.direct",
|
2354 | 29c4e2b5 | Kevin Wolf | .type = QEMU_OPT_BOOL, |
2355 | 29c4e2b5 | Kevin Wolf | .help = "enables use of O_DIRECT (bypass the host page cache)",
|
2356 | 29c4e2b5 | Kevin Wolf | },{ |
2357 | 29c4e2b5 | Kevin Wolf | .name = "cache.no-flush",
|
2358 | 29c4e2b5 | Kevin Wolf | .type = QEMU_OPT_BOOL, |
2359 | 29c4e2b5 | Kevin Wolf | .help = "ignore any flush requests for the device",
|
2360 | 4d454574 | Paolo Bonzini | },{ |
2361 | 4d454574 | Paolo Bonzini | .name = "aio",
|
2362 | 4d454574 | Paolo Bonzini | .type = QEMU_OPT_STRING, |
2363 | 4d454574 | Paolo Bonzini | .help = "host AIO implementation (threads, native)",
|
2364 | 4d454574 | Paolo Bonzini | },{ |
2365 | 4d454574 | Paolo Bonzini | .name = "format",
|
2366 | 4d454574 | Paolo Bonzini | .type = QEMU_OPT_STRING, |
2367 | 4d454574 | Paolo Bonzini | .help = "disk format (raw, qcow2, ...)",
|
2368 | 4d454574 | Paolo Bonzini | },{ |
2369 | 4d454574 | Paolo Bonzini | .name = "serial",
|
2370 | 4d454574 | Paolo Bonzini | .type = QEMU_OPT_STRING, |
2371 | 4d454574 | Paolo Bonzini | .help = "disk serial number",
|
2372 | 4d454574 | Paolo Bonzini | },{ |
2373 | 4d454574 | Paolo Bonzini | .name = "rerror",
|
2374 | 4d454574 | Paolo Bonzini | .type = QEMU_OPT_STRING, |
2375 | 4d454574 | Paolo Bonzini | .help = "read error action",
|
2376 | 4d454574 | Paolo Bonzini | },{ |
2377 | 4d454574 | Paolo Bonzini | .name = "werror",
|
2378 | 4d454574 | Paolo Bonzini | .type = QEMU_OPT_STRING, |
2379 | 4d454574 | Paolo Bonzini | .help = "write error action",
|
2380 | 4d454574 | Paolo Bonzini | },{ |
2381 | 0f227a94 | Kevin Wolf | .name = "read-only",
|
2382 | 4d454574 | Paolo Bonzini | .type = QEMU_OPT_BOOL, |
2383 | 4d454574 | Paolo Bonzini | .help = "open drive file as read-only",
|
2384 | 4d454574 | Paolo Bonzini | },{ |
2385 | 57975222 | Kevin Wolf | .name = "throttling.iops-total",
|
2386 | 4d454574 | Paolo Bonzini | .type = QEMU_OPT_NUMBER, |
2387 | 4d454574 | Paolo Bonzini | .help = "limit total I/O operations per second",
|
2388 | 4d454574 | Paolo Bonzini | },{ |
2389 | 57975222 | Kevin Wolf | .name = "throttling.iops-read",
|
2390 | 4d454574 | Paolo Bonzini | .type = QEMU_OPT_NUMBER, |
2391 | 4d454574 | Paolo Bonzini | .help = "limit read operations per second",
|
2392 | 4d454574 | Paolo Bonzini | },{ |
2393 | 57975222 | Kevin Wolf | .name = "throttling.iops-write",
|
2394 | 4d454574 | Paolo Bonzini | .type = QEMU_OPT_NUMBER, |
2395 | 4d454574 | Paolo Bonzini | .help = "limit write operations per second",
|
2396 | 4d454574 | Paolo Bonzini | },{ |
2397 | 57975222 | Kevin Wolf | .name = "throttling.bps-total",
|
2398 | 4d454574 | Paolo Bonzini | .type = QEMU_OPT_NUMBER, |
2399 | 4d454574 | Paolo Bonzini | .help = "limit total bytes per second",
|
2400 | 4d454574 | Paolo Bonzini | },{ |
2401 | 57975222 | Kevin Wolf | .name = "throttling.bps-read",
|
2402 | 4d454574 | Paolo Bonzini | .type = QEMU_OPT_NUMBER, |
2403 | 4d454574 | Paolo Bonzini | .help = "limit read bytes per second",
|
2404 | 4d454574 | Paolo Bonzini | },{ |
2405 | 57975222 | Kevin Wolf | .name = "throttling.bps-write",
|
2406 | 4d454574 | Paolo Bonzini | .type = QEMU_OPT_NUMBER, |
2407 | 4d454574 | Paolo Bonzini | .help = "limit write bytes per second",
|
2408 | 4d454574 | Paolo Bonzini | },{ |
2409 | 3e9fab69 | Benoît Canet | .name = "throttling.iops-total-max",
|
2410 | 3e9fab69 | Benoît Canet | .type = QEMU_OPT_NUMBER, |
2411 | 3e9fab69 | Benoît Canet | .help = "I/O operations burst",
|
2412 | 3e9fab69 | Benoît Canet | },{ |
2413 | 3e9fab69 | Benoît Canet | .name = "throttling.iops-read-max",
|
2414 | 3e9fab69 | Benoît Canet | .type = QEMU_OPT_NUMBER, |
2415 | 3e9fab69 | Benoît Canet | .help = "I/O operations read burst",
|
2416 | 3e9fab69 | Benoît Canet | },{ |
2417 | 3e9fab69 | Benoît Canet | .name = "throttling.iops-write-max",
|
2418 | 3e9fab69 | Benoît Canet | .type = QEMU_OPT_NUMBER, |
2419 | 3e9fab69 | Benoît Canet | .help = "I/O operations write burst",
|
2420 | 3e9fab69 | Benoît Canet | },{ |
2421 | 3e9fab69 | Benoît Canet | .name = "throttling.bps-total-max",
|
2422 | 3e9fab69 | Benoît Canet | .type = QEMU_OPT_NUMBER, |
2423 | 3e9fab69 | Benoît Canet | .help = "total bytes burst",
|
2424 | 3e9fab69 | Benoît Canet | },{ |
2425 | 3e9fab69 | Benoît Canet | .name = "throttling.bps-read-max",
|
2426 | 3e9fab69 | Benoît Canet | .type = QEMU_OPT_NUMBER, |
2427 | 3e9fab69 | Benoît Canet | .help = "total bytes read burst",
|
2428 | 3e9fab69 | Benoît Canet | },{ |
2429 | 3e9fab69 | Benoît Canet | .name = "throttling.bps-write-max",
|
2430 | 3e9fab69 | Benoît Canet | .type = QEMU_OPT_NUMBER, |
2431 | 3e9fab69 | Benoît Canet | .help = "total bytes write burst",
|
2432 | 3e9fab69 | Benoît Canet | },{ |
2433 | 2024c1df | Benoît Canet | .name = "throttling.iops-size",
|
2434 | 2024c1df | Benoît Canet | .type = QEMU_OPT_NUMBER, |
2435 | 2024c1df | Benoît Canet | .help = "when limiting by iops max size of an I/O in bytes",
|
2436 | 2024c1df | Benoît Canet | },{ |
2437 | 4d454574 | Paolo Bonzini | .name = "copy-on-read",
|
2438 | 4d454574 | Paolo Bonzini | .type = QEMU_OPT_BOOL, |
2439 | 4d454574 | Paolo Bonzini | .help = "copy read data from backing file into image file",
|
2440 | 4d454574 | Paolo Bonzini | }, |
2441 | 4d454574 | Paolo Bonzini | { /* end of list */ }
|
2442 | 4d454574 | Paolo Bonzini | }, |
2443 | 4d454574 | Paolo Bonzini | }; |
2444 | 0006383e | Kevin Wolf | |
2445 | 0006383e | Kevin Wolf | QemuOptsList qemu_drive_opts = { |
2446 | 0006383e | Kevin Wolf | .name = "drive",
|
2447 | 0006383e | Kevin Wolf | .head = QTAILQ_HEAD_INITIALIZER(qemu_drive_opts.head), |
2448 | 0006383e | Kevin Wolf | .desc = { |
2449 | 492fdc6f | Kevin Wolf | /*
|
2450 | 492fdc6f | Kevin Wolf | * no elements => accept any params
|
2451 | 492fdc6f | Kevin Wolf | * validation will happen later
|
2452 | 492fdc6f | Kevin Wolf | */
|
2453 | 0006383e | Kevin Wolf | { /* end of list */ }
|
2454 | 0006383e | Kevin Wolf | }, |
2455 | 0006383e | Kevin Wolf | }; |