Skip to content

Commit b11c873

Browse files
Vladimir Sementsov-Ogievskiykevmw
authored andcommitted
block: bdrv_insert_node(): don't use bdrv_open()
Use bdrv_new_open_driver_opts() instead of complicated bdrv_open(). Among other extra things bdrv_open() also check for white-listed formats, which we don't want for internal node creation: currently backup doesn't work when copy-before-write filter is not white-listed. As well block-stream doesn't work when copy-on-read is not white-listed. Fixes: 751cec7 Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2004812 Reported-by: Yanan Fu Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]> Message-Id: <[email protected]> Signed-off-by: Kevin Wolf <[email protected]>
1 parent 96796fa commit b11c873

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

block.c

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5133,12 +5133,30 @@ BlockDriverState *bdrv_insert_node(BlockDriverState *bs, QDict *options,
51335133
{
51345134
ERRP_GUARD();
51355135
int ret;
5136-
BlockDriverState *new_node_bs;
5136+
BlockDriverState *new_node_bs = NULL;
5137+
const char *drvname, *node_name;
5138+
BlockDriver *drv;
5139+
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+
}
51375151

5138-
new_node_bs = bdrv_open(NULL, NULL, options, flags, errp);
5139-
if (new_node_bs == NULL) {
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) {
51405158
error_prepend(errp, "Could not create node: ");
5141-
return NULL;
5159+
goto fail;
51425160
}
51435161

51445162
bdrv_drained_begin(bs);
@@ -5147,11 +5165,15 @@ BlockDriverState *bdrv_insert_node(BlockDriverState *bs, QDict *options,
51475165

51485166
if (ret < 0) {
51495167
error_prepend(errp, "Could not replace node: ");
5150-
bdrv_unref(new_node_bs);
5151-
return NULL;
5168+
goto fail;
51525169
}
51535170

51545171
return new_node_bs;
5172+
5173+
fail:
5174+
qobject_unref(options);
5175+
bdrv_unref(new_node_bs);
5176+
return NULL;
51555177
}
51565178

51575179
/*

0 commit comments

Comments
 (0)