Skip to content

Commit 1b9ea89

Browse files
XanClicmdroth
authored andcommitted
block: Omit bdrv_find_format for essential drivers
We can always assume raw, file and qcow2 being available; so do not use bdrv_find_format() to locate their BlockDriver objects but statically reference the respective objects. Cc: [email protected] Signed-off-by: Max Reitz <[email protected]> Signed-off-by: Kevin Wolf <[email protected]> (cherry picked from commit ef81043) Signed-off-by: Michael Roth <[email protected]>
1 parent cdeb85c commit 1b9ea89

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

block.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ BlockDriver *bdrv_find_protocol(const char *filename,
633633
}
634634

635635
if (!path_has_protocol(filename) || !allow_protocol_prefix) {
636-
return bdrv_find_format("file");
636+
return &bdrv_file;
637637
}
638638

639639
p = strchr(filename, ':');
@@ -662,12 +662,7 @@ static int find_image_format(BlockDriverState *bs, const char *filename,
662662

663663
/* Return the raw BlockDriver * to scsi-generic devices or empty drives */
664664
if (bs->sg || !bdrv_is_inserted(bs) || bdrv_getlength(bs) == 0) {
665-
drv = bdrv_find_format("raw");
666-
if (!drv) {
667-
error_setg(errp, "Could not find raw image format");
668-
ret = -ENOENT;
669-
}
670-
*pdrv = drv;
665+
*pdrv = &bdrv_raw;
671666
return ret;
672667
}
673668

@@ -1296,7 +1291,6 @@ int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp)
12961291
/* TODO: extra byte is a hack to ensure MAX_PATH space on Windows. */
12971292
char *tmp_filename = g_malloc0(PATH_MAX + 1);
12981293
int64_t total_size;
1299-
BlockDriver *bdrv_qcow2;
13001294
QemuOpts *opts = NULL;
13011295
QDict *snapshot_options;
13021296
BlockDriverState *bs_snapshot;
@@ -1322,11 +1316,10 @@ int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp)
13221316
goto out;
13231317
}
13241318

1325-
bdrv_qcow2 = bdrv_find_format("qcow2");
1326-
opts = qemu_opts_create(bdrv_qcow2->create_opts, NULL, 0,
1319+
opts = qemu_opts_create(bdrv_qcow2.create_opts, NULL, 0,
13271320
&error_abort);
13281321
qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_size);
1329-
ret = bdrv_create(bdrv_qcow2, tmp_filename, opts, &local_err);
1322+
ret = bdrv_create(&bdrv_qcow2, tmp_filename, opts, &local_err);
13301323
qemu_opts_del(opts);
13311324
if (ret < 0) {
13321325
error_setg_errno(errp, -ret, "Could not create temporary overlay "
@@ -1346,7 +1339,7 @@ int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp)
13461339
bs_snapshot = bdrv_new("", &error_abort);
13471340

13481341
ret = bdrv_open(&bs_snapshot, NULL, NULL, snapshot_options,
1349-
flags, bdrv_qcow2, &local_err);
1342+
flags, &bdrv_qcow2, &local_err);
13501343
if (ret < 0) {
13511344
error_propagate(errp, local_err);
13521345
goto out;

block/qcow2.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,10 +1712,9 @@ static int qcow2_create2(const char *filename, int64_t total_size,
17121712
* refcount of the cluster that is occupied by the header and the refcount
17131713
* table)
17141714
*/
1715-
BlockDriver* drv = bdrv_find_format("qcow2");
1716-
assert(drv != NULL);
17171715
ret = bdrv_open(&bs, filename, NULL, NULL,
1718-
BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH, drv, &local_err);
1716+
BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH,
1717+
&bdrv_qcow2, &local_err);
17191718
if (ret < 0) {
17201719
error_propagate(errp, local_err);
17211720
goto out;
@@ -1767,7 +1766,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
17671766
/* Reopen the image without BDRV_O_NO_FLUSH to flush it before returning */
17681767
ret = bdrv_open(&bs, filename, NULL, NULL,
17691768
BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_BACKING,
1770-
drv, &local_err);
1769+
&bdrv_qcow2, &local_err);
17711770
if (local_err) {
17721771
error_propagate(errp, local_err);
17731772
goto out;

0 commit comments

Comments
 (0)