[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 39/71] block: Fix bdrv_find_backing_image()
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 39/71] block: Fix bdrv_find_backing_image() |
Date: |
Mon, 25 Feb 2019 16:20:21 +0100 |
From: Max Reitz <address@hidden>
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 <address@hidden>
Reviewed-by: Alberto Garcia <address@hidden>
Message-id: address@hidden
Signed-off-by: Max Reitz <address@hidden>
---
block.c | 33 ++++++++++-----------------------
1 file changed, 10 insertions(+), 23 deletions(-)
diff --git a/block.c b/block.c
index c66cd111e1..d14ce1c98c 100644
--- a/block.c
+++ b/block.c
@@ -201,15 +201,6 @@ char *path_combine(const char *base_path, const char
*filename)
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
* 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);
backing_file_full = g_malloc(PATH_MAX);
- filename_tmp = g_malloc(PATH_MAX);
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) {
/* If either of the filename paths is actually a protocol, then
@@ -4686,22 +4673,23 @@ BlockDriverState
*bdrv_find_backing_image(BlockDriverState *bs,
} else {
/* If not an absolute filename path, make it relative to the
current
* image's filename path */
- path_combine_deprecated(filename_tmp, PATH_MAX, curr_bs->filename,
- backing_file);
-
- /* We are going to compare absolute pathnames */
- if (!realpath(filename_tmp, filename_full)) {
+ filename_tmp = bdrv_make_absolute_filename(curr_bs, backing_file,
+ NULL);
+ /* We are going to compare canonicalized absolute pathnames */
+ if (!filename_tmp || !realpath(filename_tmp, filename_full)) {
+ g_free(filename_tmp);
continue;
}
+ g_free(filename_tmp);
/* We need to make sure the backing filename we are comparing
against
* is relative to the current image filename (or absolute) */
- path_combine_deprecated(filename_tmp, PATH_MAX, curr_bs->filename,
- curr_bs->backing_file);
-
- if (!realpath(filename_tmp, backing_file_full)) {
+ filename_tmp = bdrv_get_full_backing_filename(curr_bs, NULL);
+ if (!filename_tmp || !realpath(filename_tmp, backing_file_full)) {
+ g_free(filename_tmp);
continue;
}
+ g_free(filename_tmp);
if (strcmp(backing_file_full, filename_full) == 0) {
retval = curr_bs->backing->bs;
@@ -4712,7 +4700,6 @@ BlockDriverState
*bdrv_find_backing_image(BlockDriverState *bs,
g_free(filename_full);
g_free(backing_file_full);
- g_free(filename_tmp);
return retval;
}
--
2.20.1
- [Qemu-block] [PULL 37/71] block: bdrv_get_full_backing_filename's ret. val., (continued)
- [Qemu-block] [PULL 37/71] block: bdrv_get_full_backing_filename's ret. val., Kevin Wolf, 2019/02/25
- [Qemu-block] [PULL 42/71] quorum: Make bdrv_dirname() return NULL, Kevin Wolf, 2019/02/25
- [Qemu-block] [PULL 34/71] iotests: Add test for backing file overrides, Kevin Wolf, 2019/02/25
- [Qemu-block] [PULL 41/71] blkverify: Make bdrv_dirname() return NULL, Kevin Wolf, 2019/02/25
- [Qemu-block] [PULL 26/71] block/nvme: Remove QEMU_PACKED from naturally aligned NVMeRegs struct, Kevin Wolf, 2019/02/25
- [Qemu-block] [PULL 40/71] block: Add bdrv_dirname(), Kevin Wolf, 2019/02/25
- [Qemu-block] [PULL 30/71] block: Add BDS.auto_backing_file, Kevin Wolf, 2019/02/25
- [Qemu-block] [PULL 43/71] block/nbd: Make bdrv_dirname() return NULL, Kevin Wolf, 2019/02/25
- [Qemu-block] [PULL 31/71] block: Respect backing bs in bdrv_refresh_filename, Kevin Wolf, 2019/02/25
- [Qemu-block] [PULL 27/71] block: Use bdrv_refresh_filename() to pull, Kevin Wolf, 2019/02/25
- [Qemu-block] [PULL 39/71] block: Fix bdrv_find_backing_image(),
Kevin Wolf <=
- [Qemu-block] [PULL 44/71] block/nfs: Implement bdrv_dirname(), Kevin Wolf, 2019/02/25
- [Qemu-block] [PULL 45/71] block: Use bdrv_dirname() for relative filenames, Kevin Wolf, 2019/02/25
- [Qemu-block] [PULL 47/71] block: Add strong_runtime_opts to BlockDriver, Kevin Wolf, 2019/02/25
- [Qemu-block] [PULL 46/71] iotests: Add quorum case to test 110, Kevin Wolf, 2019/02/25
- [Qemu-block] [PULL 51/71] block: Do not copy exact_filename from format file, Kevin Wolf, 2019/02/25
- [Qemu-block] [PULL 48/71] block: Add BlockDriver.bdrv_gather_child_options, Kevin Wolf, 2019/02/25
- [Qemu-block] [PULL 49/71] block: Generically refresh runtime options, Kevin Wolf, 2019/02/25
- [Qemu-block] [PULL 52/71] block/nvme: Fix bdrv_refresh_filename(), Kevin Wolf, 2019/02/25
- [Qemu-block] [PULL 54/71] block/curl: Implement bdrv_refresh_filename(), Kevin Wolf, 2019/02/25
- [Qemu-block] [PULL 50/71] block: Purify .bdrv_refresh_filename(), Kevin Wolf, 2019/02/25