[v2,08/24] block: Add bdrv_make_absolute_filename()
diff mbox

Message ID 20161127015622.24105-9-mreitz@redhat.com
State New
Headers show

Commit Message

Max Reitz Nov. 27, 2016, 1:56 a.m. UTC
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>
---
 block.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

Patch
diff mbox

diff --git a/block.c b/block.c
index d6b3a5a..a384e28 100644
--- a/block.c
+++ b/block.c
@@ -220,15 +220,22 @@  char *bdrv_get_full_backing_filename_from_filename(const char *backed,
     }
 }
 
-char *bdrv_get_full_backing_filename(BlockDriverState *bs, Error **errp)
+static char *bdrv_make_absolute_filename(BlockDriverState *relative_to,
+                                         const char *filename, Error **errp)
 {
-    char *backed = bs->exact_filename[0] ? bs->exact_filename : bs->filename;
+    char *bs_filename = relative_to->exact_filename[0]
+                        ? relative_to->exact_filename
+                        : relative_to->filename;
 
-    return bdrv_get_full_backing_filename_from_filename(backed,
-                                                        bs->backing_file,
+    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)
 {
     QLIST_INSERT_HEAD(&bdrv_drivers, bdrv, list);