block/qed: Keep auto_backing_file if possible

Just like qcow2, qed invokes its open function in its
.bdrv_co_invalidate_cache() implementation.  Therefore, just like done
for qcow2 in HEAD^, update auto_backing_file only if the backing file
string in the image header differs from the one we have read before.

Signed-off-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20220803144446.20723-3-hreitz@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
Hanna Reitz 2022-08-03 16:44:45 +02:00 committed by Kevin Wolf
parent ec64b1ca08
commit dc70638ff6

View File

@ -445,6 +445,8 @@ static int coroutine_fn bdrv_qed_do_open(BlockDriverState *bs, QDict *options,
}
if ((s->header.features & QED_F_BACKING_FILE)) {
g_autofree char *backing_file_str = NULL;
if ((uint64_t)s->header.backing_filename_offset +
s->header.backing_filename_size >
s->header.cluster_size * s->header.header_size) {
@ -452,16 +454,21 @@ static int coroutine_fn bdrv_qed_do_open(BlockDriverState *bs, QDict *options,
return -EINVAL;
}
backing_file_str = g_malloc(sizeof(bs->backing_file));
ret = qed_read_string(bs->file, s->header.backing_filename_offset,
s->header.backing_filename_size,
bs->auto_backing_file,
sizeof(bs->auto_backing_file));
backing_file_str, sizeof(bs->backing_file));
if (ret < 0) {
error_setg(errp, "Failed to read backing filename");
return ret;
}
pstrcpy(bs->backing_file, sizeof(bs->backing_file),
bs->auto_backing_file);
if (!g_str_equal(backing_file_str, bs->backing_file)) {
pstrcpy(bs->backing_file, sizeof(bs->backing_file),
backing_file_str);
pstrcpy(bs->auto_backing_file, sizeof(bs->auto_backing_file),
backing_file_str);
}
if (s->header.features & QED_F_BACKING_FORMAT_NO_PROBE) {
pstrcpy(bs->backing_format, sizeof(bs->backing_format), "raw");