blob: 8fd17567773f47af99218d0a7e5fe11cc9f8f411 [file] [log] [blame]
Wenchao Xiade08c602013-05-25 11:09:43 +08001/*
2 * Block layer snapshot related functions
3 *
4 * Copyright (c) 2003-2008 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
Peter Maydell80c71a22016-01-18 18:01:42 +000025#include "qemu/osdep.h"
Wenchao Xiade08c602013-05-25 11:09:43 +080026#include "block/snapshot.h"
27#include "block/block_int.h"
Max Reitz609f45e2018-06-14 21:14:28 +020028#include "block/qdict.h"
Markus Armbrusterda34e652016-03-14 09:01:28 +010029#include "qapi/error.h"
Markus Armbruster452fcdb2018-02-01 12:18:39 +010030#include "qapi/qmp/qdict.h"
Dong Jia Shi7a9e5112017-04-05 11:19:09 +020031#include "qapi/qmp/qstring.h"
Markus Armbruster922a01a2018-02-01 12:18:46 +010032#include "qemu/option.h"
Kevin Wolf05f4ace2019-09-17 12:26:23 +020033#include "sysemu/block-backend.h"
Wenchao Xiade08c602013-05-25 11:09:43 +080034
Wenchao Xia8c116b02013-12-04 17:10:55 +080035QemuOptsList internal_snapshot_opts = {
36 .name = "snapshot",
37 .head = QTAILQ_HEAD_INITIALIZER(internal_snapshot_opts.head),
38 .desc = {
39 {
40 .name = SNAPSHOT_OPT_ID,
41 .type = QEMU_OPT_STRING,
42 .help = "snapshot id"
43 },{
44 .name = SNAPSHOT_OPT_NAME,
45 .type = QEMU_OPT_STRING,
46 .help = "snapshot name"
47 },{
48 /* end of list */
49 }
50 },
51};
52
Wenchao Xiade08c602013-05-25 11:09:43 +080053int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
54 const char *name)
55{
56 QEMUSnapshotInfo *sn_tab, *sn;
57 int nb_sns, i, ret;
58
Emanuele Giuseppe Esposito6b573ef2022-03-03 10:16:07 -050059 GLOBAL_STATE_CODE();
60
Wenchao Xiade08c602013-05-25 11:09:43 +080061 ret = -ENOENT;
62 nb_sns = bdrv_snapshot_list(bs, &sn_tab);
63 if (nb_sns < 0) {
64 return ret;
65 }
66 for (i = 0; i < nb_sns; i++) {
67 sn = &sn_tab[i];
Daniel Henrique Barboza6ca08042018-11-07 11:09:58 -020068 if (!strcmp(sn->name, name)) {
Wenchao Xiade08c602013-05-25 11:09:43 +080069 *sn_info = *sn;
70 ret = 0;
71 break;
72 }
73 }
74 g_free(sn_tab);
75 return ret;
76}
77
Wenchao Xia2ea1dd72013-09-11 14:04:32 +080078/**
79 * Look up an internal snapshot by @id and @name.
80 * @bs: block device to search
81 * @id: unique snapshot ID, or NULL
82 * @name: snapshot name, or NULL
83 * @sn_info: location to store information on the snapshot found
84 * @errp: location to store error, will be set only for exception
85 *
86 * This function will traverse snapshot list in @bs to search the matching
87 * one, @id and @name are the matching condition:
88 * If both @id and @name are specified, find the first one with id @id and
89 * name @name.
90 * If only @id is specified, find the first one with id @id.
91 * If only @name is specified, find the first one with name @name.
92 * if none is specified, abort().
93 *
94 * Returns: true when a snapshot is found and @sn_info will be filled, false
95 * when error or not found. If all operation succeed but no matching one is
96 * found, @errp will NOT be set.
97 */
98bool bdrv_snapshot_find_by_id_and_name(BlockDriverState *bs,
99 const char *id,
100 const char *name,
101 QEMUSnapshotInfo *sn_info,
102 Error **errp)
103{
104 QEMUSnapshotInfo *sn_tab, *sn;
105 int nb_sns, i;
106 bool ret = false;
107
108 assert(id || name);
Emanuele Giuseppe Esposito6b573ef2022-03-03 10:16:07 -0500109 GLOBAL_STATE_CODE();
Wenchao Xia2ea1dd72013-09-11 14:04:32 +0800110
111 nb_sns = bdrv_snapshot_list(bs, &sn_tab);
112 if (nb_sns < 0) {
113 error_setg_errno(errp, -nb_sns, "Failed to get a snapshot list");
114 return false;
115 } else if (nb_sns == 0) {
116 return false;
117 }
118
119 if (id && name) {
120 for (i = 0; i < nb_sns; i++) {
121 sn = &sn_tab[i];
122 if (!strcmp(sn->id_str, id) && !strcmp(sn->name, name)) {
123 *sn_info = *sn;
124 ret = true;
125 break;
126 }
127 }
128 } else if (id) {
129 for (i = 0; i < nb_sns; i++) {
130 sn = &sn_tab[i];
131 if (!strcmp(sn->id_str, id)) {
132 *sn_info = *sn;
133 ret = true;
134 break;
135 }
136 }
137 } else if (name) {
138 for (i = 0; i < nb_sns; i++) {
139 sn = &sn_tab[i];
140 if (!strcmp(sn->name, name)) {
141 *sn_info = *sn;
142 ret = true;
143 break;
144 }
145 }
146 }
147
148 g_free(sn_tab);
149 return ret;
150}
151
Max Reitzc8af8752019-06-12 18:21:07 +0200152/**
Vladimir Sementsov-Ogievskiyc5c21742022-07-26 23:11:33 +0300153 * Return a pointer to child of given BDS to which we can fall
Max Reitzc8af8752019-06-12 18:21:07 +0200154 * back if the given BDS does not support snapshots.
155 * Return NULL if there is no BDS to (safely) fall back to.
Max Reitzc8af8752019-06-12 18:21:07 +0200156 */
Kevin Wolfa32e7812023-09-29 16:51:42 +0200157static BdrvChild * GRAPH_RDLOCK
158bdrv_snapshot_fallback_child(BlockDriverState *bs)
Max Reitzc8af8752019-06-12 18:21:07 +0200159{
Vladimir Sementsov-Ogievskiyc5c21742022-07-26 23:11:33 +0300160 BdrvChild *fallback = bdrv_primary_child(bs);
161 BdrvChild *child;
Max Reitzc8af8752019-06-12 18:21:07 +0200162
Kevin Wolfa32e7812023-09-29 16:51:42 +0200163 GLOBAL_STATE_CODE();
164 assert_bdrv_graph_readable();
165
Vladimir Sementsov-Ogievskiy0c6100a2022-07-26 23:11:27 +0300166 /* We allow fallback only to primary child */
Vladimir Sementsov-Ogievskiyc5c21742022-07-26 23:11:33 +0300167 if (!fallback) {
Max Reitzc8af8752019-06-12 18:21:07 +0200168 return NULL;
169 }
170
171 /*
172 * Check that there are no other children that would need to be
173 * snapshotted. If there are, it is not safe to fall back to
Vladimir Sementsov-Ogievskiyc5c21742022-07-26 23:11:33 +0300174 * fallback.
Max Reitzc8af8752019-06-12 18:21:07 +0200175 */
176 QLIST_FOREACH(child, &bs->children, next) {
177 if (child->role & (BDRV_CHILD_DATA | BDRV_CHILD_METADATA |
178 BDRV_CHILD_FILTERED) &&
Vladimir Sementsov-Ogievskiyc5c21742022-07-26 23:11:33 +0300179 child != fallback)
Max Reitzc8af8752019-06-12 18:21:07 +0200180 {
181 return NULL;
182 }
183 }
184
185 return fallback;
186}
187
Kevin Wolfa32e7812023-09-29 16:51:42 +0200188static BlockDriverState * GRAPH_RDLOCK
189bdrv_snapshot_fallback(BlockDriverState *bs)
Max Reitzc8af8752019-06-12 18:21:07 +0200190{
Kevin Wolfa32e7812023-09-29 16:51:42 +0200191 GLOBAL_STATE_CODE();
Vladimir Sementsov-Ogievskiyc5c21742022-07-26 23:11:33 +0300192 return child_bs(bdrv_snapshot_fallback_child(bs));
Max Reitzc8af8752019-06-12 18:21:07 +0200193}
194
Wenchao Xiade08c602013-05-25 11:09:43 +0800195int bdrv_can_snapshot(BlockDriverState *bs)
196{
197 BlockDriver *drv = bs->drv;
Kevin Wolfd3007d32023-12-01 15:25:18 +0100198
Emanuele Giuseppe Esposito6b573ef2022-03-03 10:16:07 -0500199 GLOBAL_STATE_CODE();
Kevin Wolfd3007d32023-12-01 15:25:18 +0100200
201 if (!drv || !bdrv_is_inserted(bs) || !bdrv_is_writable(bs)) {
Wenchao Xiade08c602013-05-25 11:09:43 +0800202 return 0;
203 }
204
205 if (!drv->bdrv_snapshot_create) {
Max Reitzc8af8752019-06-12 18:21:07 +0200206 BlockDriverState *fallback_bs = bdrv_snapshot_fallback(bs);
207 if (fallback_bs) {
208 return bdrv_can_snapshot(fallback_bs);
Wenchao Xiade08c602013-05-25 11:09:43 +0800209 }
210 return 0;
211 }
212
213 return 1;
214}
215
216int bdrv_snapshot_create(BlockDriverState *bs,
217 QEMUSnapshotInfo *sn_info)
218{
219 BlockDriver *drv = bs->drv;
Max Reitzc8af8752019-06-12 18:21:07 +0200220 BlockDriverState *fallback_bs = bdrv_snapshot_fallback(bs);
Emanuele Giuseppe Esposito6b573ef2022-03-03 10:16:07 -0500221
222 GLOBAL_STATE_CODE();
223
Wenchao Xiade08c602013-05-25 11:09:43 +0800224 if (!drv) {
225 return -ENOMEDIUM;
226 }
227 if (drv->bdrv_snapshot_create) {
228 return drv->bdrv_snapshot_create(bs, sn_info);
229 }
Max Reitzc8af8752019-06-12 18:21:07 +0200230 if (fallback_bs) {
231 return bdrv_snapshot_create(fallback_bs, sn_info);
Wenchao Xiade08c602013-05-25 11:09:43 +0800232 }
233 return -ENOTSUP;
234}
235
236int bdrv_snapshot_goto(BlockDriverState *bs,
Kevin Wolf0b62bcb2017-11-20 15:28:41 +0100237 const char *snapshot_id,
238 Error **errp)
Wenchao Xiade08c602013-05-25 11:09:43 +0800239{
240 BlockDriver *drv = bs->drv;
Vladimir Sementsov-Ogievskiyc5c21742022-07-26 23:11:33 +0300241 BdrvChild *fallback;
Wenchao Xiade08c602013-05-25 11:09:43 +0800242 int ret, open_ret;
243
Emanuele Giuseppe Esposito6b573ef2022-03-03 10:16:07 -0500244 GLOBAL_STATE_CODE();
245
Wenchao Xiade08c602013-05-25 11:09:43 +0800246 if (!drv) {
Kevin Wolf0b62bcb2017-11-20 15:28:41 +0100247 error_setg(errp, "Block driver is closed");
Wenchao Xiade08c602013-05-25 11:09:43 +0800248 return -ENOMEDIUM;
249 }
Vladimir Sementsov-Ogievskiy04dec3c2017-10-23 12:29:45 +0300250
Kevin Wolf70a5afe2017-11-20 15:41:31 +0100251 if (!QLIST_EMPTY(&bs->dirty_bitmaps)) {
252 error_setg(errp, "Device has active dirty bitmaps");
253 return -EBUSY;
Vladimir Sementsov-Ogievskiy04dec3c2017-10-23 12:29:45 +0300254 }
Vladimir Sementsov-Ogievskiy04dec3c2017-10-23 12:29:45 +0300255
Wenchao Xiade08c602013-05-25 11:09:43 +0800256 if (drv->bdrv_snapshot_goto) {
Kevin Wolf0b62bcb2017-11-20 15:28:41 +0100257 ret = drv->bdrv_snapshot_goto(bs, snapshot_id);
258 if (ret < 0) {
259 error_setg_errno(errp, -ret, "Failed to load snapshot");
260 }
261 return ret;
Wenchao Xiade08c602013-05-25 11:09:43 +0800262 }
263
Kevin Wolfa32e7812023-09-29 16:51:42 +0200264 bdrv_graph_rdlock_main_loop();
Vladimir Sementsov-Ogievskiyc5c21742022-07-26 23:11:33 +0300265 fallback = bdrv_snapshot_fallback_child(bs);
Kevin Wolfa32e7812023-09-29 16:51:42 +0200266 bdrv_graph_rdunlock_main_loop();
267
Vladimir Sementsov-Ogievskiyc5c21742022-07-26 23:11:33 +0300268 if (fallback) {
Max Reitzc8af8752019-06-12 18:21:07 +0200269 QDict *options;
Dong Jia Shi7a9e5112017-04-05 11:19:09 +0200270 QDict *file_options;
Kevin Wolf0b62bcb2017-11-20 15:28:41 +0100271 Error *local_err = NULL;
Vladimir Sementsov-Ogievskiyc5c21742022-07-26 23:11:33 +0300272 BlockDriverState *fallback_bs = fallback->bs;
273 char *subqdict_prefix = g_strdup_printf("%s.", fallback->name);
Dong Jia Shi7a9e5112017-04-05 11:19:09 +0200274
Max Reitzc8af8752019-06-12 18:21:07 +0200275 options = qdict_clone_shallow(bs->options);
276
Dong Jia Shi7a9e5112017-04-05 11:19:09 +0200277 /* Prevent it from getting deleted when detached from bs */
Max Reitzc8af8752019-06-12 18:21:07 +0200278 bdrv_ref(fallback_bs);
Dong Jia Shi7a9e5112017-04-05 11:19:09 +0200279
Max Reitzc8af8752019-06-12 18:21:07 +0200280 qdict_extract_subqdict(options, &file_options, subqdict_prefix);
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200281 qobject_unref(file_options);
Max Reitzc8af8752019-06-12 18:21:07 +0200282 g_free(subqdict_prefix);
283
Vladimir Sementsov-Ogievskiyc5c21742022-07-26 23:11:33 +0300284 /* Force .bdrv_open() below to re-attach fallback_bs on fallback */
285 qdict_put_str(options, fallback->name,
Max Reitzc8af8752019-06-12 18:21:07 +0200286 bdrv_get_node_name(fallback_bs));
Dong Jia Shi7a9e5112017-04-05 11:19:09 +0200287
Max Reitz32a9a242021-05-03 02:54:18 -0700288 /* Now close bs, apply the snapshot on fallback_bs, and re-open bs */
Vladimir Sementsov-Ogievskiy3c005292018-08-14 15:43:19 +0300289 if (drv->bdrv_close) {
290 drv->bdrv_close(bs);
291 }
Dong Jia Shi7a9e5112017-04-05 11:19:09 +0200292
Max Reitz32a9a242021-05-03 02:54:18 -0700293 /* .bdrv_open() will re-attach it */
Stefan Hajnoczi6bc30f12023-12-05 13:20:02 -0500294 bdrv_graph_wrlock();
Vladimir Sementsov-Ogievskiyc5c21742022-07-26 23:11:33 +0300295 bdrv_unref_child(bs, fallback);
Stefan Hajnoczi6bc30f12023-12-05 13:20:02 -0500296 bdrv_graph_wrunlock();
Max Reitzc8af8752019-06-12 18:21:07 +0200297
298 ret = bdrv_snapshot_goto(fallback_bs, snapshot_id, errp);
Kevin Wolf0b62bcb2017-11-20 15:28:41 +0100299 open_ret = drv->bdrv_open(bs, options, bs->open_flags, &local_err);
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200300 qobject_unref(options);
Wenchao Xiade08c602013-05-25 11:09:43 +0800301 if (open_ret < 0) {
Max Reitzc8af8752019-06-12 18:21:07 +0200302 bdrv_unref(fallback_bs);
Wenchao Xiade08c602013-05-25 11:09:43 +0800303 bs->drv = NULL;
Kevin Wolf0b62bcb2017-11-20 15:28:41 +0100304 /* A bdrv_snapshot_goto() error takes precedence */
305 error_propagate(errp, local_err);
306 return ret < 0 ? ret : open_ret;
Wenchao Xiade08c602013-05-25 11:09:43 +0800307 }
Dong Jia Shi7a9e5112017-04-05 11:19:09 +0200308
Max Reitz32a9a242021-05-03 02:54:18 -0700309 /*
Vladimir Sementsov-Ogievskiy0c6100a2022-07-26 23:11:27 +0300310 * fallback was a primary child. It was closed above and set to NULL,
311 * but the .bdrv_open() call has opened it again, because we set the
312 * respective option (with the qdict_put_str() call above).
313 * Assert that .bdrv_open() has attached the right BDS as primary child.
Max Reitz32a9a242021-05-03 02:54:18 -0700314 */
Kevin Wolfc0fc5122023-09-29 16:51:46 +0200315 bdrv_graph_rdlock_main_loop();
Vladimir Sementsov-Ogievskiy0c6100a2022-07-26 23:11:27 +0300316 assert(bdrv_primary_bs(bs) == fallback_bs);
Kevin Wolfc0fc5122023-09-29 16:51:46 +0200317 bdrv_graph_rdunlock_main_loop();
318
Max Reitzc8af8752019-06-12 18:21:07 +0200319 bdrv_unref(fallback_bs);
Wenchao Xiade08c602013-05-25 11:09:43 +0800320 return ret;
321 }
322
Kevin Wolf0b62bcb2017-11-20 15:28:41 +0100323 error_setg(errp, "Block driver does not support snapshots");
Wenchao Xiade08c602013-05-25 11:09:43 +0800324 return -ENOTSUP;
325}
326
Wenchao Xiaa89d89d2013-09-11 14:04:33 +0800327/**
328 * Delete an internal snapshot by @snapshot_id and @name.
329 * @bs: block device used in the operation
330 * @snapshot_id: unique snapshot ID, or NULL
331 * @name: snapshot name, or NULL
332 * @errp: location to store error
333 *
334 * If both @snapshot_id and @name are specified, delete the first one with
335 * id @snapshot_id and name @name.
336 * If only @snapshot_id is specified, delete the first one with id
337 * @snapshot_id.
338 * If only @name is specified, delete the first one with name @name.
Wenchao Xia7b4c4782013-12-04 17:10:54 +0800339 * if none is specified, return -EINVAL.
Wenchao Xiaa89d89d2013-09-11 14:04:33 +0800340 *
341 * Returns: 0 on success, -errno on failure. If @bs is not inserted, return
342 * -ENOMEDIUM. If @snapshot_id and @name are both NULL, return -EINVAL. If @bs
343 * does not support internal snapshot deletion, return -ENOTSUP. If @bs does
344 * not support parameter @snapshot_id or @name, or one of them is not correctly
345 * specified, return -EINVAL. If @bs can't find one matching @id and @name,
346 * return -ENOENT. If @errp != NULL, it will always be filled with error
347 * message on failure.
348 */
349int bdrv_snapshot_delete(BlockDriverState *bs,
350 const char *snapshot_id,
351 const char *name,
352 Error **errp)
Wenchao Xiade08c602013-05-25 11:09:43 +0800353{
354 BlockDriver *drv = bs->drv;
Max Reitzc8af8752019-06-12 18:21:07 +0200355 BlockDriverState *fallback_bs = bdrv_snapshot_fallback(bs);
Paolo Bonzini27a76492015-12-16 19:33:45 +0100356 int ret;
357
Emanuele Giuseppe Esposito6b573ef2022-03-03 10:16:07 -0500358 GLOBAL_STATE_CODE();
359
Wenchao Xiade08c602013-05-25 11:09:43 +0800360 if (!drv) {
Philippe Mathieu-Daudéa95921f2024-03-12 15:13:36 +0100361 error_setg(errp, "Device '%s' has no medium",
362 bdrv_get_device_name(bs));
Wenchao Xiade08c602013-05-25 11:09:43 +0800363 return -ENOMEDIUM;
364 }
Wenchao Xiaa89d89d2013-09-11 14:04:33 +0800365 if (!snapshot_id && !name) {
366 error_setg(errp, "snapshot_id and name are both NULL");
367 return -EINVAL;
368 }
Zhang Haoyu3432a192014-10-21 16:38:01 +0800369
370 /* drain all pending i/o before deleting snapshot */
Paolo Bonzini27a76492015-12-16 19:33:45 +0100371 bdrv_drained_begin(bs);
Zhang Haoyu3432a192014-10-21 16:38:01 +0800372
Wenchao Xiade08c602013-05-25 11:09:43 +0800373 if (drv->bdrv_snapshot_delete) {
Paolo Bonzini27a76492015-12-16 19:33:45 +0100374 ret = drv->bdrv_snapshot_delete(bs, snapshot_id, name, errp);
Max Reitzc8af8752019-06-12 18:21:07 +0200375 } else if (fallback_bs) {
376 ret = bdrv_snapshot_delete(fallback_bs, snapshot_id, name, errp);
Paolo Bonzini27a76492015-12-16 19:33:45 +0100377 } else {
378 error_setg(errp, "Block format '%s' used by device '%s' "
379 "does not support internal snapshot deletion",
380 drv->format_name, bdrv_get_device_name(bs));
381 ret = -ENOTSUP;
Wenchao Xiade08c602013-05-25 11:09:43 +0800382 }
Paolo Bonzini27a76492015-12-16 19:33:45 +0100383
384 bdrv_drained_end(bs);
385 return ret;
Wenchao Xiade08c602013-05-25 11:09:43 +0800386}
387
Wenchao Xiade08c602013-05-25 11:09:43 +0800388int bdrv_snapshot_list(BlockDriverState *bs,
389 QEMUSnapshotInfo **psn_info)
390{
Kevin Wolfa32e7812023-09-29 16:51:42 +0200391 GLOBAL_STATE_CODE();
392 GRAPH_RDLOCK_GUARD_MAINLOOP();
393
Wenchao Xiade08c602013-05-25 11:09:43 +0800394 BlockDriver *drv = bs->drv;
Max Reitzc8af8752019-06-12 18:21:07 +0200395 BlockDriverState *fallback_bs = bdrv_snapshot_fallback(bs);
Emanuele Giuseppe Esposito6b573ef2022-03-03 10:16:07 -0500396
Wenchao Xiade08c602013-05-25 11:09:43 +0800397 if (!drv) {
398 return -ENOMEDIUM;
399 }
400 if (drv->bdrv_snapshot_list) {
401 return drv->bdrv_snapshot_list(bs, psn_info);
402 }
Max Reitzc8af8752019-06-12 18:21:07 +0200403 if (fallback_bs) {
404 return bdrv_snapshot_list(fallback_bs, psn_info);
Wenchao Xiade08c602013-05-25 11:09:43 +0800405 }
406 return -ENOTSUP;
407}
408
Wenchao Xia7b4c4782013-12-04 17:10:54 +0800409/**
410 * Temporarily load an internal snapshot by @snapshot_id and @name.
411 * @bs: block device used in the operation
412 * @snapshot_id: unique snapshot ID, or NULL
413 * @name: snapshot name, or NULL
414 * @errp: location to store error
415 *
416 * If both @snapshot_id and @name are specified, load the first one with
417 * id @snapshot_id and name @name.
418 * If only @snapshot_id is specified, load the first one with id
419 * @snapshot_id.
420 * If only @name is specified, load the first one with name @name.
421 * if none is specified, return -EINVAL.
422 *
423 * Returns: 0 on success, -errno on fail. If @bs is not inserted, return
424 * -ENOMEDIUM. If @bs is not readonly, return -EINVAL. If @bs did not support
425 * internal snapshot, return -ENOTSUP. If qemu can't find a matching @id and
426 * @name, return -ENOENT. If @errp != NULL, it will always be filled on
427 * failure.
428 */
Wenchao Xiade08c602013-05-25 11:09:43 +0800429int bdrv_snapshot_load_tmp(BlockDriverState *bs,
Wenchao Xia7b4c4782013-12-04 17:10:54 +0800430 const char *snapshot_id,
431 const char *name,
432 Error **errp)
Wenchao Xiade08c602013-05-25 11:09:43 +0800433{
434 BlockDriver *drv = bs->drv;
Wenchao Xia7b4c4782013-12-04 17:10:54 +0800435
Emanuele Giuseppe Esposito6b573ef2022-03-03 10:16:07 -0500436 GLOBAL_STATE_CODE();
Kevin Wolf4026f1c2023-09-29 16:51:47 +0200437 GRAPH_RDLOCK_GUARD_MAINLOOP();
Emanuele Giuseppe Esposito6b573ef2022-03-03 10:16:07 -0500438
Wenchao Xiade08c602013-05-25 11:09:43 +0800439 if (!drv) {
Philippe Mathieu-Daudéa95921f2024-03-12 15:13:36 +0100440 error_setg(errp, "Device '%s' has no medium",
441 bdrv_get_device_name(bs));
Wenchao Xiade08c602013-05-25 11:09:43 +0800442 return -ENOMEDIUM;
443 }
Wenchao Xia7b4c4782013-12-04 17:10:54 +0800444 if (!snapshot_id && !name) {
445 error_setg(errp, "snapshot_id and name are both NULL");
446 return -EINVAL;
447 }
Vladimir Sementsov-Ogievskiy307261b2021-05-27 18:40:54 +0300448 if (!bdrv_is_read_only(bs)) {
Wenchao Xia7b4c4782013-12-04 17:10:54 +0800449 error_setg(errp, "Device is not readonly");
Wenchao Xiade08c602013-05-25 11:09:43 +0800450 return -EINVAL;
451 }
452 if (drv->bdrv_snapshot_load_tmp) {
Wenchao Xia7b4c4782013-12-04 17:10:54 +0800453 return drv->bdrv_snapshot_load_tmp(bs, snapshot_id, name, errp);
Wenchao Xiade08c602013-05-25 11:09:43 +0800454 }
Alberto Garcia81e5f782015-04-08 12:29:19 +0300455 error_setg(errp, "Block format '%s' used by device '%s' "
456 "does not support temporarily loading internal snapshots",
457 drv->format_name, bdrv_get_device_name(bs));
Wenchao Xiade08c602013-05-25 11:09:43 +0800458 return -ENOTSUP;
459}
Wenchao Xia7b4c4782013-12-04 17:10:54 +0800460
461int bdrv_snapshot_load_tmp_by_id_or_name(BlockDriverState *bs,
462 const char *id_or_name,
463 Error **errp)
464{
465 int ret;
466 Error *local_err = NULL;
467
Emanuele Giuseppe Esposito6b573ef2022-03-03 10:16:07 -0500468 GLOBAL_STATE_CODE();
469
Wenchao Xia7b4c4782013-12-04 17:10:54 +0800470 ret = bdrv_snapshot_load_tmp(bs, id_or_name, NULL, &local_err);
471 if (ret == -ENOENT || ret == -EINVAL) {
472 error_free(local_err);
473 local_err = NULL;
474 ret = bdrv_snapshot_load_tmp(bs, NULL, id_or_name, &local_err);
475 }
476
Eduardo Habkost621ff942016-06-13 18:57:56 -0300477 error_propagate(errp, local_err);
Wenchao Xia7b4c4782013-12-04 17:10:54 +0800478
479 return ret;
480}
Denis V. Luneve9ff9572015-11-19 09:42:01 +0300481
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000482
Kevin Wolf2b3912f2023-09-29 16:51:39 +0200483static int GRAPH_RDLOCK
484bdrv_all_get_snapshot_devices(bool has_devices, strList *devices,
485 GList **all_bdrvs, Error **errp)
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000486{
487 g_autoptr(GList) bdrvs = NULL;
488
489 if (has_devices) {
490 if (!devices) {
491 error_setg(errp, "At least one device is required for snapshot");
492 return -1;
493 }
494
495 while (devices) {
496 BlockDriverState *bs = bdrv_find_node(devices->value);
497 if (!bs) {
498 error_setg(errp, "No block device node '%s'", devices->value);
499 return -1;
500 }
501 bdrvs = g_list_append(bdrvs, bs);
502 devices = devices->next;
503 }
504 } else {
505 BlockDriverState *bs;
506 BdrvNextIterator it;
507 for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
508 bdrvs = g_list_append(bdrvs, bs);
509 }
510 }
511
512 *all_bdrvs = g_steal_pointer(&bdrvs);
513 return 0;
514}
515
516
Kevin Wolf2b3912f2023-09-29 16:51:39 +0200517static bool GRAPH_RDLOCK bdrv_all_snapshots_includes_bs(BlockDriverState *bs)
Kevin Wolf05f4ace2019-09-17 12:26:23 +0200518{
Kevin Wolfa32e7812023-09-29 16:51:42 +0200519 GLOBAL_STATE_CODE();
520 assert_bdrv_graph_readable();
521
Kevin Wolf05f4ace2019-09-17 12:26:23 +0200522 if (!bdrv_is_inserted(bs) || bdrv_is_read_only(bs)) {
523 return false;
524 }
525
526 /* Include all nodes that are either in use by a BlockBackend, or that
527 * aren't attached to any node, but owned by the monitor. */
528 return bdrv_has_blk(bs) || QLIST_EMPTY(&bs->parents);
529}
Denis V. Luneve9ff9572015-11-19 09:42:01 +0300530
Stefan Hajnoczib49f4752023-12-05 13:20:03 -0500531/* Group operations. All block drivers are involved. */
Denis V. Luneve9ff9572015-11-19 09:42:01 +0300532
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000533bool bdrv_all_can_snapshot(bool has_devices, strList *devices,
534 Error **errp)
Denis V. Luneve9ff9572015-11-19 09:42:01 +0300535{
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000536 g_autoptr(GList) bdrvs = NULL;
537 GList *iterbdrvs;
Denis V. Luneve9ff9572015-11-19 09:42:01 +0300538
Emanuele Giuseppe Esposito6b573ef2022-03-03 10:16:07 -0500539 GLOBAL_STATE_CODE();
Kevin Wolf2b3912f2023-09-29 16:51:39 +0200540 GRAPH_RDLOCK_GUARD_MAINLOOP();
Emanuele Giuseppe Esposito6b573ef2022-03-03 10:16:07 -0500541
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000542 if (bdrv_all_get_snapshot_devices(has_devices, devices, &bdrvs, errp) < 0) {
543 return false;
544 }
545
546 iterbdrvs = bdrvs;
547 while (iterbdrvs) {
548 BlockDriverState *bs = iterbdrvs->data;
Daniel P. Berrangée26f98e2021-02-04 12:48:23 +0000549 bool ok = true;
Denis V. Luneve9ff9572015-11-19 09:42:01 +0300550
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000551 if (devices || bdrv_all_snapshots_includes_bs(bs)) {
Denis V. Luneve9ff9572015-11-19 09:42:01 +0300552 ok = bdrv_can_snapshot(bs);
553 }
Kevin Wolf88be7b42016-05-20 18:49:07 +0200554 if (!ok) {
Daniel P. Berrangée26f98e2021-02-04 12:48:23 +0000555 error_setg(errp, "Device '%s' is writable but does not support "
556 "snapshots", bdrv_get_device_or_node_name(bs));
Daniel P. Berrangée26f98e2021-02-04 12:48:23 +0000557 return false;
Kevin Wolf88be7b42016-05-20 18:49:07 +0200558 }
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000559
560 iterbdrvs = iterbdrvs->next;
Denis V. Luneve9ff9572015-11-19 09:42:01 +0300561 }
562
Daniel P. Berrangée26f98e2021-02-04 12:48:23 +0000563 return true;
Denis V. Luneve9ff9572015-11-19 09:42:01 +0300564}
Denis V. Lunev9b00ea32015-11-19 09:42:03 +0300565
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000566int bdrv_all_delete_snapshot(const char *name,
567 bool has_devices, strList *devices,
568 Error **errp)
Denis V. Lunev9b00ea32015-11-19 09:42:03 +0300569{
Zhao Liuce33d852024-03-11 11:38:03 +0800570 ERRP_GUARD();
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000571 g_autoptr(GList) bdrvs = NULL;
572 GList *iterbdrvs;
Denis V. Lunev9b00ea32015-11-19 09:42:03 +0300573
Emanuele Giuseppe Esposito6b573ef2022-03-03 10:16:07 -0500574 GLOBAL_STATE_CODE();
Kevin Wolf2b3912f2023-09-29 16:51:39 +0200575 GRAPH_RDLOCK_GUARD_MAINLOOP();
Emanuele Giuseppe Esposito6b573ef2022-03-03 10:16:07 -0500576
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000577 if (bdrv_all_get_snapshot_devices(has_devices, devices, &bdrvs, errp) < 0) {
578 return -1;
579 }
580
581 iterbdrvs = bdrvs;
582 while (iterbdrvs) {
583 BlockDriverState *bs = iterbdrvs->data;
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000584 QEMUSnapshotInfo sn1, *snapshot = &sn1;
Daniel P. Berrangée26f98e2021-02-04 12:48:23 +0000585 int ret = 0;
Denis V. Lunev9b00ea32015-11-19 09:42:03 +0300586
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000587 if ((devices || bdrv_all_snapshots_includes_bs(bs)) &&
Kevin Wolf05f4ace2019-09-17 12:26:23 +0200588 bdrv_snapshot_find(bs, snapshot, name) >= 0)
589 {
Daniel Henrique Barboza6ca08042018-11-07 11:09:58 -0200590 ret = bdrv_snapshot_delete(bs, snapshot->id_str,
Vladimir Sementsov-Ogievskiye53a5782019-12-05 20:46:24 +0300591 snapshot->name, errp);
Denis V. Lunev9b00ea32015-11-19 09:42:03 +0300592 }
Kevin Wolf88be7b42016-05-20 18:49:07 +0200593 if (ret < 0) {
Daniel P. Berrangée26f98e2021-02-04 12:48:23 +0000594 error_prepend(errp, "Could not delete snapshot '%s' on '%s': ",
595 name, bdrv_get_device_or_node_name(bs));
Daniel P. Berrangée26f98e2021-02-04 12:48:23 +0000596 return -1;
Kevin Wolf88be7b42016-05-20 18:49:07 +0200597 }
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000598
599 iterbdrvs = iterbdrvs->next;
Denis V. Lunev9b00ea32015-11-19 09:42:03 +0300600 }
601
Daniel P. Berrangée26f98e2021-02-04 12:48:23 +0000602 return 0;
Denis V. Lunev9b00ea32015-11-19 09:42:03 +0300603}
Denis V. Lunev4c1cdba2015-11-19 09:42:04 +0300604
605
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000606int bdrv_all_goto_snapshot(const char *name,
607 bool has_devices, strList *devices,
608 Error **errp)
Denis V. Lunev4c1cdba2015-11-19 09:42:04 +0300609{
Zhao Liuce33d852024-03-11 11:38:03 +0800610 ERRP_GUARD();
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000611 g_autoptr(GList) bdrvs = NULL;
612 GList *iterbdrvs;
Kevin Wolfa32e7812023-09-29 16:51:42 +0200613 int ret;
Denis V. Lunev4c1cdba2015-11-19 09:42:04 +0300614
Emanuele Giuseppe Esposito6b573ef2022-03-03 10:16:07 -0500615 GLOBAL_STATE_CODE();
616
Kevin Wolfa32e7812023-09-29 16:51:42 +0200617 bdrv_graph_rdlock_main_loop();
618 ret = bdrv_all_get_snapshot_devices(has_devices, devices, &bdrvs, errp);
619 bdrv_graph_rdunlock_main_loop();
620
621 if (ret < 0) {
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000622 return -1;
623 }
624
625 iterbdrvs = bdrvs;
626 while (iterbdrvs) {
627 BlockDriverState *bs = iterbdrvs->data;
Kevin Wolfa32e7812023-09-29 16:51:42 +0200628 bool all_snapshots_includes_bs;
Denis V. Lunev4c1cdba2015-11-19 09:42:04 +0300629
Kevin Wolfa32e7812023-09-29 16:51:42 +0200630 bdrv_graph_rdlock_main_loop();
631 all_snapshots_includes_bs = bdrv_all_snapshots_includes_bs(bs);
632 bdrv_graph_rdunlock_main_loop();
633
Thomas Huth6ab4f1c2023-10-23 19:50:38 +0200634 ret = (devices || all_snapshots_includes_bs) ?
635 bdrv_snapshot_goto(bs, name, errp) : 0;
Kevin Wolf2b624fe2017-11-20 15:36:48 +0100636 if (ret < 0) {
Kevin Wolf4026f1c2023-09-29 16:51:47 +0200637 bdrv_graph_rdlock_main_loop();
Daniel P. Berrangée26f98e2021-02-04 12:48:23 +0000638 error_prepend(errp, "Could not load snapshot '%s' on '%s': ",
639 name, bdrv_get_device_or_node_name(bs));
Kevin Wolf4026f1c2023-09-29 16:51:47 +0200640 bdrv_graph_rdunlock_main_loop();
Daniel P. Berrangée26f98e2021-02-04 12:48:23 +0000641 return -1;
Kevin Wolf88be7b42016-05-20 18:49:07 +0200642 }
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000643
644 iterbdrvs = iterbdrvs->next;
Denis V. Lunev4c1cdba2015-11-19 09:42:04 +0300645 }
646
Daniel P. Berrangée26f98e2021-02-04 12:48:23 +0000647 return 0;
Denis V. Lunev4c1cdba2015-11-19 09:42:04 +0300648}
Denis V. Lunev723ccda2015-11-19 09:42:06 +0300649
Daniel P. Berrangé3d3e9b12021-02-04 12:48:28 +0000650int bdrv_all_has_snapshot(const char *name,
651 bool has_devices, strList *devices,
652 Error **errp)
Denis V. Lunev723ccda2015-11-19 09:42:06 +0300653{
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000654 g_autoptr(GList) bdrvs = NULL;
655 GList *iterbdrvs;
Denis V. Lunev723ccda2015-11-19 09:42:06 +0300656
Emanuele Giuseppe Esposito6b573ef2022-03-03 10:16:07 -0500657 GLOBAL_STATE_CODE();
Kevin Wolf2b3912f2023-09-29 16:51:39 +0200658 GRAPH_RDLOCK_GUARD_MAINLOOP();
Emanuele Giuseppe Esposito6b573ef2022-03-03 10:16:07 -0500659
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000660 if (bdrv_all_get_snapshot_devices(has_devices, devices, &bdrvs, errp) < 0) {
661 return -1;
662 }
663
664 iterbdrvs = bdrvs;
665 while (iterbdrvs) {
666 BlockDriverState *bs = iterbdrvs->data;
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000667 QEMUSnapshotInfo sn;
Daniel P. Berrangée26f98e2021-02-04 12:48:23 +0000668 int ret = 0;
Denis V. Lunev723ccda2015-11-19 09:42:06 +0300669
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000670 if (devices || bdrv_all_snapshots_includes_bs(bs)) {
Daniel P. Berrangée26f98e2021-02-04 12:48:23 +0000671 ret = bdrv_snapshot_find(bs, &sn, name);
Denis V. Lunev723ccda2015-11-19 09:42:06 +0300672 }
Daniel P. Berrangée26f98e2021-02-04 12:48:23 +0000673 if (ret < 0) {
Daniel P. Berrangé3d3e9b12021-02-04 12:48:28 +0000674 if (ret == -ENOENT) {
675 return 0;
676 } else {
677 error_setg_errno(errp, errno,
678 "Could not check snapshot '%s' on '%s'",
679 name, bdrv_get_device_or_node_name(bs));
680 return -1;
681 }
Kevin Wolf88be7b42016-05-20 18:49:07 +0200682 }
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000683
684 iterbdrvs = iterbdrvs->next;
Denis V. Lunev723ccda2015-11-19 09:42:06 +0300685 }
686
Daniel P. Berrangé3d3e9b12021-02-04 12:48:28 +0000687 return 1;
Denis V. Lunev723ccda2015-11-19 09:42:06 +0300688}
Denis V. Luneva9085f92015-11-19 09:42:08 +0300689
690int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn,
691 BlockDriverState *vm_state_bs,
692 uint64_t vm_state_size,
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000693 bool has_devices, strList *devices,
Daniel P. Berrangée26f98e2021-02-04 12:48:23 +0000694 Error **errp)
Denis V. Luneva9085f92015-11-19 09:42:08 +0300695{
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000696 g_autoptr(GList) bdrvs = NULL;
697 GList *iterbdrvs;
Kevin Wolf2b3912f2023-09-29 16:51:39 +0200698
Emanuele Giuseppe Esposito6b573ef2022-03-03 10:16:07 -0500699 GLOBAL_STATE_CODE();
Kevin Wolf2b3912f2023-09-29 16:51:39 +0200700 GRAPH_RDLOCK_GUARD_MAINLOOP();
Denis V. Luneva9085f92015-11-19 09:42:08 +0300701
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000702 if (bdrv_all_get_snapshot_devices(has_devices, devices, &bdrvs, errp) < 0) {
703 return -1;
704 }
705
706 iterbdrvs = bdrvs;
707 while (iterbdrvs) {
708 BlockDriverState *bs = iterbdrvs->data;
Daniel P. Berrangée26f98e2021-02-04 12:48:23 +0000709 int ret = 0;
Denis V. Luneva9085f92015-11-19 09:42:08 +0300710
Denis V. Luneva9085f92015-11-19 09:42:08 +0300711 if (bs == vm_state_bs) {
712 sn->vm_state_size = vm_state_size;
Daniel P. Berrangée26f98e2021-02-04 12:48:23 +0000713 ret = bdrv_snapshot_create(bs, sn);
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000714 } else if (devices || bdrv_all_snapshots_includes_bs(bs)) {
Denis V. Luneva9085f92015-11-19 09:42:08 +0300715 sn->vm_state_size = 0;
Daniel P. Berrangée26f98e2021-02-04 12:48:23 +0000716 ret = bdrv_snapshot_create(bs, sn);
Denis V. Luneva9085f92015-11-19 09:42:08 +0300717 }
Daniel P. Berrangée26f98e2021-02-04 12:48:23 +0000718 if (ret < 0) {
719 error_setg(errp, "Could not create snapshot '%s' on '%s'",
720 sn->name, bdrv_get_device_or_node_name(bs));
Daniel P. Berrangée26f98e2021-02-04 12:48:23 +0000721 return -1;
Kevin Wolf88be7b42016-05-20 18:49:07 +0200722 }
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000723
724 iterbdrvs = iterbdrvs->next;
Denis V. Luneva9085f92015-11-19 09:42:08 +0300725 }
726
Daniel P. Berrangée26f98e2021-02-04 12:48:23 +0000727 return 0;
Denis V. Luneva9085f92015-11-19 09:42:08 +0300728}
Denis V. Lunev7cb14482015-11-19 09:42:10 +0300729
Daniel P. Berrangéc22d6442021-02-04 12:48:27 +0000730
731BlockDriverState *bdrv_all_find_vmstate_bs(const char *vmstate_bs,
732 bool has_devices, strList *devices,
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000733 Error **errp)
Denis V. Lunev7cb14482015-11-19 09:42:10 +0300734{
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000735 g_autoptr(GList) bdrvs = NULL;
736 GList *iterbdrvs;
Denis V. Lunev7cb14482015-11-19 09:42:10 +0300737
Emanuele Giuseppe Esposito6b573ef2022-03-03 10:16:07 -0500738 GLOBAL_STATE_CODE();
Kevin Wolf2b3912f2023-09-29 16:51:39 +0200739 GRAPH_RDLOCK_GUARD_MAINLOOP();
Emanuele Giuseppe Esposito6b573ef2022-03-03 10:16:07 -0500740
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000741 if (bdrv_all_get_snapshot_devices(has_devices, devices, &bdrvs, errp) < 0) {
742 return NULL;
743 }
744
745 iterbdrvs = bdrvs;
746 while (iterbdrvs) {
747 BlockDriverState *bs = iterbdrvs->data;
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000748 bool found = false;
Denis V. Lunev7cb14482015-11-19 09:42:10 +0300749
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000750 found = (devices || bdrv_all_snapshots_includes_bs(bs)) &&
751 bdrv_can_snapshot(bs);
Kevin Wolf88be7b42016-05-20 18:49:07 +0200752
Daniel P. Berrangéc22d6442021-02-04 12:48:27 +0000753 if (vmstate_bs) {
754 if (g_str_equal(vmstate_bs,
755 bdrv_get_node_name(bs))) {
756 if (found) {
757 return bs;
758 } else {
759 error_setg(errp,
760 "vmstate block device '%s' does not support snapshots",
761 vmstate_bs);
762 return NULL;
763 }
764 }
765 } else if (found) {
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000766 return bs;
Kevin Wolf88be7b42016-05-20 18:49:07 +0200767 }
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000768
769 iterbdrvs = iterbdrvs->next;
Denis V. Lunev7cb14482015-11-19 09:42:10 +0300770 }
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000771
Daniel P. Berrangéc22d6442021-02-04 12:48:27 +0000772 if (vmstate_bs) {
773 error_setg(errp,
774 "vmstate block device '%s' does not exist", vmstate_bs);
775 } else {
776 error_setg(errp,
777 "no block device can store vmstate for snapshot");
778 }
Daniel P. Berrangécf3a74c2021-02-04 12:48:26 +0000779 return NULL;
Denis V. Lunev7cb14482015-11-19 09:42:10 +0300780}