aboutsummaryrefslogtreecommitdiff
path: root/block.c
diff options
context:
space:
mode:
authorMax Reitz <mreitz@redhat.com>2019-02-01 20:29:16 +0100
committerMax Reitz <mreitz@redhat.com>2019-02-25 15:11:26 +0100
commit9f4793d8f2f1abf20dc1d7d55f65ce8df081ca7a (patch)
tree8d60c79015391170d67e48e2782cdb48bd6872b9 /block.c
parent6b6833c1b4d11d7d838bce34ed4a2d7c42855efe (diff)
block: Add bdrv_make_absolute_filename()
This is a general function for making a filename that is relative to a certain BDS absolute. It calls bdrv_get_full_backing_filename_from_filename() for now, but that will be changed in a follow-up patch. Signed-off-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Alberto Garcia <berto@igalia.com> Message-id: 20190201192935.18394-13-mreitz@redhat.com Signed-off-by: Max Reitz <mreitz@redhat.com>
Diffstat (limited to 'block.c')
-rw-r--r--block.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/block.c b/block.c
index a2203f0cfe..c66cd111e1 100644
--- a/block.c
+++ b/block.c
@@ -338,16 +338,29 @@ char *bdrv_get_full_backing_filename_from_filename(const char *backed,
}
}
-char *bdrv_get_full_backing_filename(BlockDriverState *bs, Error **errp)
+/*
+ * If @filename is empty or NULL, this function returns NULL without
+ * setting @errp. In all other cases, NULL will only be returned with
+ * @errp set.
+ */
+static char *bdrv_make_absolute_filename(BlockDriverState *relative_to,
+ const char *filename, Error **errp)
{
- char *backed;
+ char *bs_filename;
- bdrv_refresh_filename(bs);
+ bdrv_refresh_filename(relative_to);
+
+ bs_filename = relative_to->exact_filename[0]
+ ? relative_to->exact_filename
+ : relative_to->filename;
- backed = bs->exact_filename[0] ? bs->exact_filename : bs->filename;
- return bdrv_get_full_backing_filename_from_filename(backed,
- bs->backing_file,
- errp);
+ return bdrv_get_full_backing_filename_from_filename(bs_filename,
+ filename ?: "", errp);
+}
+
+char *bdrv_get_full_backing_filename(BlockDriverState *bs, Error **errp)
+{
+ return bdrv_make_absolute_filename(bs, bs->backing_file, errp);
}
void bdrv_register(BlockDriver *bdrv)