block.c (96796fae6f22931d91223d086e9fa56d0f3e6720) block.c (b11c8739ae38166acac0669cee94b7e236ccb639)
1/*
2 * QEMU System Emulator block driver
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 * Copyright (c) 2020 Virtuozzo International GmbH.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal

--- 5119 unchanged lines hidden (view full) ---

5128 * after the call (even on failure), so if the caller intends to reuse the
5129 * dictionary, it needs to use qobject_ref() before calling bdrv_open.
5130 */
5131BlockDriverState *bdrv_insert_node(BlockDriverState *bs, QDict *options,
5132 int flags, Error **errp)
5133{
5134 ERRP_GUARD();
5135 int ret;
1/*
2 * QEMU System Emulator block driver
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 * Copyright (c) 2020 Virtuozzo International GmbH.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal

--- 5119 unchanged lines hidden (view full) ---

5128 * after the call (even on failure), so if the caller intends to reuse the
5129 * dictionary, it needs to use qobject_ref() before calling bdrv_open.
5130 */
5131BlockDriverState *bdrv_insert_node(BlockDriverState *bs, QDict *options,
5132 int flags, Error **errp)
5133{
5134 ERRP_GUARD();
5135 int ret;
5136 BlockDriverState *new_node_bs;
5136 BlockDriverState *new_node_bs = NULL;
5137 const char *drvname, *node_name;
5138 BlockDriver *drv;
5137
5139
5138 new_node_bs = bdrv_open(NULL, NULL, options, flags, errp);
5139 if (new_node_bs == NULL) {
5140 drvname = qdict_get_try_str(options, "driver");
5141 if (!drvname) {
5142 error_setg(errp, "driver is not specified");
5143 goto fail;
5144 }
5145
5146 drv = bdrv_find_format(drvname);
5147 if (!drv) {
5148 error_setg(errp, "Unknown driver: '%s'", drvname);
5149 goto fail;
5150 }
5151
5152 node_name = qdict_get_try_str(options, "node-name");
5153
5154 new_node_bs = bdrv_new_open_driver_opts(drv, node_name, options, flags,
5155 errp);
5156 options = NULL; /* bdrv_new_open_driver() eats options */
5157 if (!new_node_bs) {
5140 error_prepend(errp, "Could not create node: ");
5158 error_prepend(errp, "Could not create node: ");
5141 return NULL;
5159 goto fail;
5142 }
5143
5144 bdrv_drained_begin(bs);
5145 ret = bdrv_replace_node(bs, new_node_bs, errp);
5146 bdrv_drained_end(bs);
5147
5148 if (ret < 0) {
5149 error_prepend(errp, "Could not replace node: ");
5160 }
5161
5162 bdrv_drained_begin(bs);
5163 ret = bdrv_replace_node(bs, new_node_bs, errp);
5164 bdrv_drained_end(bs);
5165
5166 if (ret < 0) {
5167 error_prepend(errp, "Could not replace node: ");
5150 bdrv_unref(new_node_bs);
5151 return NULL;
5168 goto fail;
5152 }
5153
5154 return new_node_bs;
5169 }
5170
5171 return new_node_bs;
5172
5173fail:
5174 qobject_unref(options);
5175 bdrv_unref(new_node_bs);
5176 return NULL;
5155}
5156
5157/*
5158 * Run consistency checks on an image
5159 *
5160 * Returns 0 if the check could be completed (it doesn't mean that the image is
5161 * free of errors) or -errno when an internal error occurred. The results of the
5162 * check are stored in res.

--- 2639 unchanged lines hidden ---
5177}
5178
5179/*
5180 * Run consistency checks on an image
5181 *
5182 * Returns 0 if the check could be completed (it doesn't mean that the image is
5183 * free of errors) or -errno when an internal error occurred. The results of the
5184 * check are stored in res.

--- 2639 unchanged lines hidden ---