aboutsummaryrefslogtreecommitdiff
path: root/block.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2012-05-08 16:51:50 +0200
committerKevin Wolf <kwolf@redhat.com>2012-05-10 10:32:12 +0200
commitdc5a137125d6ac641c566f10e68bf6e1fe31bcb5 (patch)
tree27ae82c1b297705351bbfdd8852b416e4804e4e3 /block.c
parent6405875cdd10e531ad3dedaad86ae1ccc4b14f20 (diff)
qemu-img: make "info" backing file output correct and easier to use
qemu-img info should use the same logic as qemu when printing the backing file path, or debugging becomes quite tricky. We can also simplify the output in case the backing file has an absolute path or a protocol. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block.c')
-rw-r--r--block.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/block.c b/block.c
index 29869987a9..af2ab4f3ea 100644
--- a/block.c
+++ b/block.c
@@ -270,6 +270,15 @@ void path_combine(char *dest, int dest_size,
}
}
+void bdrv_get_full_backing_filename(BlockDriverState *bs, char *dest, size_t sz)
+{
+ if (bs->backing_file[0] == '\0' || path_has_protocol(bs->backing_file)) {
+ pstrcpy(dest, sz, bs->backing_file);
+ } else {
+ path_combine(dest, sz, bs->filename, bs->backing_file);
+ }
+}
+
void bdrv_register(BlockDriver *bdrv)
{
/* Block drivers without coroutine functions need emulation */
@@ -796,14 +805,8 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags,
BlockDriver *back_drv = NULL;
bs->backing_hd = bdrv_new("");
-
- if (path_has_protocol(bs->backing_file)) {
- pstrcpy(backing_filename, sizeof(backing_filename),
- bs->backing_file);
- } else {
- path_combine(backing_filename, sizeof(backing_filename),
- filename, bs->backing_file);
- }
+ bdrv_get_full_backing_filename(bs, backing_filename,
+ sizeof(backing_filename));
if (bs->backing_format[0] != '\0') {
back_drv = bdrv_find_format(bs->backing_format);