提交 dc5a1371 编写于 作者: P Paolo Bonzini 提交者: Kevin Wolf

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: NPaolo Bonzini <pbonzini@redhat.com>
Signed-off-by: NKevin Wolf <kwolf@redhat.com>
上级 6405875c
...@@ -270,6 +270,15 @@ void path_combine(char *dest, int dest_size, ...@@ -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) void bdrv_register(BlockDriver *bdrv)
{ {
/* Block drivers without coroutine functions need emulation */ /* Block drivers without coroutine functions need emulation */
...@@ -796,14 +805,8 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags, ...@@ -796,14 +805,8 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags,
BlockDriver *back_drv = NULL; BlockDriver *back_drv = NULL;
bs->backing_hd = bdrv_new(""); bs->backing_hd = bdrv_new("");
bdrv_get_full_backing_filename(bs, backing_filename,
if (path_has_protocol(bs->backing_file)) { sizeof(backing_filename));
pstrcpy(backing_filename, sizeof(backing_filename),
bs->backing_file);
} else {
path_combine(backing_filename, sizeof(backing_filename),
filename, bs->backing_file);
}
if (bs->backing_format[0] != '\0') { if (bs->backing_format[0] != '\0') {
back_drv = bdrv_find_format(bs->backing_format); back_drv = bdrv_find_format(bs->backing_format);
......
...@@ -303,6 +303,8 @@ int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi); ...@@ -303,6 +303,8 @@ int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi);
const char *bdrv_get_encrypted_filename(BlockDriverState *bs); const char *bdrv_get_encrypted_filename(BlockDriverState *bs);
void bdrv_get_backing_filename(BlockDriverState *bs, void bdrv_get_backing_filename(BlockDriverState *bs,
char *filename, int filename_size); char *filename, int filename_size);
void bdrv_get_full_backing_filename(BlockDriverState *bs,
char *dest, size_t sz);
int bdrv_can_snapshot(BlockDriverState *bs); int bdrv_can_snapshot(BlockDriverState *bs);
int bdrv_is_snapshot(BlockDriverState *bs); int bdrv_is_snapshot(BlockDriverState *bs);
BlockDriverState *bdrv_snapshots(void); BlockDriverState *bdrv_snapshots(void);
......
...@@ -1138,11 +1138,13 @@ static int img_info(int argc, char **argv) ...@@ -1138,11 +1138,13 @@ static int img_info(int argc, char **argv)
} }
bdrv_get_backing_filename(bs, backing_filename, sizeof(backing_filename)); bdrv_get_backing_filename(bs, backing_filename, sizeof(backing_filename));
if (backing_filename[0] != '\0') { if (backing_filename[0] != '\0') {
path_combine(backing_filename2, sizeof(backing_filename2), bdrv_get_full_backing_filename(bs, backing_filename2,
filename, backing_filename); sizeof(backing_filename2));
printf("backing file: %s (actual path: %s)\n", printf("backing file: %s", backing_filename);
backing_filename, if (strcmp(backing_filename, backing_filename2) != 0) {
backing_filename2); printf(" (actual path: %s)", backing_filename2);
}
putchar('\n');
} }
dump_snapshots(bs); dump_snapshots(bs);
bdrv_delete(bs); bdrv_delete(bs);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册