diff mbox

[v3,1/5] block: Get full backing filename from string

Message ID 1416822200-31088-2-git-send-email-mreitz@redhat.com
State New
Headers show

Commit Message

Max Reitz Nov. 24, 2014, 9:43 a.m. UTC
Introduce bdrv_get_full_backing_filename_from_filename(), a function
which takes the name of the backed file and a potentially relative
backing filename to produce the full (absolute) backing filename.

Use this function from bdrv_get_full_backing_filename().

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
---
 block.c               | 16 ++++++++++++----
 include/block/block.h |  3 +++
 2 files changed, 15 insertions(+), 4 deletions(-)

Comments

Eric Blake Nov. 25, 2014, 7:53 p.m. UTC | #1
On 11/24/2014 02:43 AM, Max Reitz wrote:
> Introduce bdrv_get_full_backing_filename_from_filename(), a function
> which takes the name of the backed file and a potentially relative
> backing filename to produce the full (absolute) backing filename.
> 
> Use this function from bdrv_get_full_backing_filename().
> 
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> Reviewed-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  block.c               | 16 ++++++++++++----
>  include/block/block.h |  3 +++
>  2 files changed, 15 insertions(+), 4 deletions(-)
> 

Reviewed-by: Eric Blake <eblake@redhat.com>
Fam Zheng Nov. 26, 2014, 5:38 a.m. UTC | #2
On Mon, 11/24 10:43, Max Reitz wrote:
> Introduce bdrv_get_full_backing_filename_from_filename(), a function
> which takes the name of the backed file and a potentially relative
> backing filename to produce the full (absolute) backing filename.
> 
> Use this function from bdrv_get_full_backing_filename().
> 
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> Reviewed-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  block.c               | 16 ++++++++++++----
>  include/block/block.h |  3 +++
>  2 files changed, 15 insertions(+), 4 deletions(-)
> 
> diff --git a/block.c b/block.c
> index 866c8b4..0c1be37 100644
> --- a/block.c
> +++ b/block.c
> @@ -303,15 +303,23 @@ void path_combine(char *dest, int dest_size,
>      }
>  }
>  
> -void bdrv_get_full_backing_filename(BlockDriverState *bs, char *dest, size_t sz)
> +void bdrv_get_full_backing_filename_from_filename(const char *backed,
> +                                                  const char *backing,
> +                                                  char *dest, size_t sz)
>  {
> -    if (bs->backing_file[0] == '\0' || path_has_protocol(bs->backing_file)) {
> -        pstrcpy(dest, sz, bs->backing_file);
> +    if (backing[0] == '\0' || path_has_protocol(backing)) {
> +        pstrcpy(dest, sz, backing);
>      } else {
> -        path_combine(dest, sz, bs->filename, bs->backing_file);
> +        path_combine(dest, sz, backed, backing);
>      }
>  }
>  
> +void bdrv_get_full_backing_filename(BlockDriverState *bs, char *dest, size_t sz)
> +{
> +    bdrv_get_full_backing_filename_from_filename(bs->filename, bs->backing_file,
> +                                                 dest, sz);
> +}
> +
>  void bdrv_register(BlockDriver *bdrv)
>  {
>      /* Block drivers without coroutine functions need emulation */
> diff --git a/include/block/block.h b/include/block/block.h
> index 610be9f..1c7ecaa 100644
> --- a/include/block/block.h
> +++ b/include/block/block.h
> @@ -399,6 +399,9 @@ void bdrv_get_backing_filename(BlockDriverState *bs,
>                                 char *filename, int filename_size);
>  void bdrv_get_full_backing_filename(BlockDriverState *bs,
>                                      char *dest, size_t sz);
> +void bdrv_get_full_backing_filename_from_filename(const char *backed,
> +                                                  const char *backing,
> +                                                  char *dest, size_t sz);
>  int bdrv_is_snapshot(BlockDriverState *bs);
>  
>  int path_is_absolute(const char *path);
> -- 
> 1.9.3
> 
> 

Reviewed-by: Fam Zheng <famz@redhat.com>
diff mbox

Patch

diff --git a/block.c b/block.c
index 866c8b4..0c1be37 100644
--- a/block.c
+++ b/block.c
@@ -303,15 +303,23 @@  void path_combine(char *dest, int dest_size,
     }
 }
 
-void bdrv_get_full_backing_filename(BlockDriverState *bs, char *dest, size_t sz)
+void bdrv_get_full_backing_filename_from_filename(const char *backed,
+                                                  const char *backing,
+                                                  char *dest, size_t sz)
 {
-    if (bs->backing_file[0] == '\0' || path_has_protocol(bs->backing_file)) {
-        pstrcpy(dest, sz, bs->backing_file);
+    if (backing[0] == '\0' || path_has_protocol(backing)) {
+        pstrcpy(dest, sz, backing);
     } else {
-        path_combine(dest, sz, bs->filename, bs->backing_file);
+        path_combine(dest, sz, backed, backing);
     }
 }
 
+void bdrv_get_full_backing_filename(BlockDriverState *bs, char *dest, size_t sz)
+{
+    bdrv_get_full_backing_filename_from_filename(bs->filename, bs->backing_file,
+                                                 dest, sz);
+}
+
 void bdrv_register(BlockDriver *bdrv)
 {
     /* Block drivers without coroutine functions need emulation */
diff --git a/include/block/block.h b/include/block/block.h
index 610be9f..1c7ecaa 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -399,6 +399,9 @@  void bdrv_get_backing_filename(BlockDriverState *bs,
                                char *filename, int filename_size);
 void bdrv_get_full_backing_filename(BlockDriverState *bs,
                                     char *dest, size_t sz);
+void bdrv_get_full_backing_filename_from_filename(const char *backed,
+                                                  const char *backing,
+                                                  char *dest, size_t sz);
 int bdrv_is_snapshot(BlockDriverState *bs);
 
 int path_is_absolute(const char *path);