block: Fix bdrv_find_backing_image()

bdrv_find_backing_image() should use bdrv_get_full_backing_filename() or
bdrv_make_absolute_filename() instead of trying to do what those
functions do by itself.

path_combine_deprecated() can now be dropped, so let's do that.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Message-id: 20190201192935.18394-14-mreitz@redhat.com
Signed-off-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
Max Reitz 2019-02-01 20:29:17 +01:00
parent 9f4793d8f2
commit 2d9158ce79

33
block.c
View file

@ -201,15 +201,6 @@ char *path_combine(const char *base_path, const char *filename)
return result; return result;
} }
static void path_combine_deprecated(char *dest, int dest_size,
const char *base_path,
const char *filename)
{
char *combined = path_combine(base_path, filename);
pstrcpy(dest, dest_size, combined);
g_free(combined);
}
/* /*
* Helper function for bdrv_parse_filename() implementations to remove optional * Helper function for bdrv_parse_filename() implementations to remove optional
* protocol prefixes (especially "file:") from a filename and for putting the * protocol prefixes (especially "file:") from a filename and for putting the
@ -4654,13 +4645,9 @@ BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs,
filename_full = g_malloc(PATH_MAX); filename_full = g_malloc(PATH_MAX);
backing_file_full = g_malloc(PATH_MAX); backing_file_full = g_malloc(PATH_MAX);
filename_tmp = g_malloc(PATH_MAX);
is_protocol = path_has_protocol(backing_file); is_protocol = path_has_protocol(backing_file);
/* This will recursively refresh everything in the backing chain */
bdrv_refresh_filename(bs);
for (curr_bs = bs; curr_bs->backing; curr_bs = curr_bs->backing->bs) { for (curr_bs = bs; curr_bs->backing; curr_bs = curr_bs->backing->bs) {
/* If either of the filename paths is actually a protocol, then /* If either of the filename paths is actually a protocol, then
@ -4686,22 +4673,23 @@ BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs,
} else { } else {
/* If not an absolute filename path, make it relative to the current /* If not an absolute filename path, make it relative to the current
* image's filename path */ * image's filename path */
path_combine_deprecated(filename_tmp, PATH_MAX, curr_bs->filename, filename_tmp = bdrv_make_absolute_filename(curr_bs, backing_file,
backing_file); NULL);
/* We are going to compare canonicalized absolute pathnames */
/* We are going to compare absolute pathnames */ if (!filename_tmp || !realpath(filename_tmp, filename_full)) {
if (!realpath(filename_tmp, filename_full)) { g_free(filename_tmp);
continue; continue;
} }
g_free(filename_tmp);
/* We need to make sure the backing filename we are comparing against /* We need to make sure the backing filename we are comparing against
* is relative to the current image filename (or absolute) */ * is relative to the current image filename (or absolute) */
path_combine_deprecated(filename_tmp, PATH_MAX, curr_bs->filename, filename_tmp = bdrv_get_full_backing_filename(curr_bs, NULL);
curr_bs->backing_file); if (!filename_tmp || !realpath(filename_tmp, backing_file_full)) {
g_free(filename_tmp);
if (!realpath(filename_tmp, backing_file_full)) {
continue; continue;
} }
g_free(filename_tmp);
if (strcmp(backing_file_full, filename_full) == 0) { if (strcmp(backing_file_full, filename_full) == 0) {
retval = curr_bs->backing->bs; retval = curr_bs->backing->bs;
@ -4712,7 +4700,6 @@ BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs,
g_free(filename_full); g_free(filename_full);
g_free(backing_file_full); g_free(backing_file_full);
g_free(filename_tmp);
return retval; return retval;
} }