From e0d45df7a5794b6821d2f8893a7f343109debab9 Mon Sep 17 00:00:00 2001 From: Luiz Capitulino Date: Fri, 29 Jun 2012 20:53:37 -0300 Subject: [PATCH 1/4] qapi: qapi.py: allow the "'" character to be escaped Support escaping the escape character, and make more robust (don't die for '', handle ' without matching '. Signed-off-by: Markus Armbruster Reviewed-by: Peter Maydell Signed-off-by: Luiz Capitulino --- scripts/qapi.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index 8082af3fcd..d3b8b4d851 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -13,18 +13,29 @@ from ordereddict import OrderedDict def tokenize(data): while len(data): - if data[0] in ['{', '}', ':', ',', '[', ']']: - yield data[0] - data = data[1:] - elif data[0] in ' \n': - data = data[1:] - elif data[0] == "'": - data = data[1:] + ch = data[0] + data = data[1:] + if ch in ['{', '}', ':', ',', '[', ']']: + yield ch + elif ch in ' \n': + None + elif ch == "'": string = '' - while data[0] != "'": - string += data[0] + esc = False + while True: + if (data == ''): + raise Exception("Mismatched quotes") + ch = data[0] data = data[1:] - data = data[1:] + if esc: + string += ch + esc = False + elif ch == "\\": + esc = True + elif ch == "'": + break + else: + string += ch yield string def parse(tokens): From f198fd1c9aedaae2fa78eb94e236e95ce4f2aedd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Canet?= Date: Thu, 2 Aug 2012 10:22:47 +0200 Subject: [PATCH 2/4] block: create bdrv_get_backing_file_depth() Create bdrv_get_backing_file_depth() in order to be able to show in QMP and HMP how many ancestors backing an image a block device have. Signed-off-by: Benoit Canet Reviewed-by: Eric Blake Signed-off-by: Luiz Capitulino --- block.c | 13 +++++++++++++ block.h | 1 + 2 files changed, 14 insertions(+) diff --git a/block.c b/block.c index b38940bf85..1206bba84d 100644 --- a/block.c +++ b/block.c @@ -2754,6 +2754,19 @@ BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs, return NULL; } +int bdrv_get_backing_file_depth(BlockDriverState *bs) +{ + if (!bs->drv) { + return 0; + } + + if (!bs->backing_hd) { + return 0; + } + + return 1 + bdrv_get_backing_file_depth(bs->backing_hd); +} + #define NB_SUFFIXES 4 char *get_human_readable_size(char *buf, int buf_size, int64_t size) diff --git a/block.h b/block.h index c89590df4d..650d872f46 100644 --- a/block.h +++ b/block.h @@ -174,6 +174,7 @@ int coroutine_fn bdrv_co_is_allocated_above(BlockDriverState *top, int nb_sectors, int *pnum); BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs, const char *backing_file); +int bdrv_get_backing_file_depth(BlockDriverState *bs); int bdrv_truncate(BlockDriverState *bs, int64_t offset); int64_t bdrv_getlength(BlockDriverState *bs); int64_t bdrv_get_allocated_file_size(BlockDriverState *bs); From 2e3e331710faa8d0b7d70b73e87df1fb6d33d0d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Canet?= Date: Thu, 2 Aug 2012 10:22:48 +0200 Subject: [PATCH 3/4] block: Use bdrv_get_backing_file_depth() Use the dedicated counting function in qmp_query_block in order to propagate the backing file depth to HMP and add backing_file_depth to qmp-commands.hx Signed-off-by: Benoit Canet Reviewed-by: Eric Blake Signed-off-by: Luiz Capitulino --- block.c | 3 +++ qapi-schema.json | 9 ++++++--- qmp-commands.hx | 2 ++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index 1206bba84d..24323c11d0 100644 --- a/block.c +++ b/block.c @@ -2450,6 +2450,9 @@ BlockInfoList *qmp_query_block(Error **errp) info->value->inserted->backing_file = g_strdup(bs->backing_file); } + info->value->inserted->backing_file_depth = + bdrv_get_backing_file_depth(bs); + if (bs->io_limits_enabled) { info->value->inserted->bps = bs->io_limits.bps[BLOCK_IO_LIMIT_TOTAL]; diff --git a/qapi-schema.json b/qapi-schema.json index bc55ed2b6d..b58f5cded8 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -398,6 +398,8 @@ # # @backing_file: #optional the name of the backing file (for copy-on-write) # +# @backing_file_depth: number of files in the backing file chain (since: 1.2) +# # @encrypted: true if the backing device is encrypted # # @bps: total throughput limit in bytes per second is specified @@ -418,9 +420,10 @@ ## { 'type': 'BlockDeviceInfo', 'data': { 'file': 'str', 'ro': 'bool', 'drv': 'str', - '*backing_file': 'str', 'encrypted': 'bool', - 'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int', - 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int'} } + '*backing_file': 'str', 'backing_file_depth': 'int', + 'encrypted': 'bool', 'bps': 'int', 'bps_rd': 'int', + 'bps_wr': 'int', 'iops': 'int', 'iops_rd': 'int', + 'iops_wr': 'int'} } ## # @BlockDeviceIoStatus: diff --git a/qmp-commands.hx b/qmp-commands.hx index e3cf3c5a1a..ac466382c0 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -1317,6 +1317,7 @@ Each json-object contain the following: "nbd", "parallels", "qcow", "qcow2", "raw", "tftp", "vdi", "vmdk", "vpc", "vvfat" - "backing_file": backing file name (json-string, optional) + - "backing_file_depth": number of files in the backing file chain (json-int) - "encrypted": true if encrypted, false otherwise (json-bool) - "bps": limit total bytes per second (json-int) - "bps_rd": limit read bytes per second (json-int) @@ -1345,6 +1346,7 @@ Example: "drv":"qcow2", "encrypted":false, "file":"disks/test.img", + "backing_file_depth":0, "bps":1000000, "bps_rd":0, "bps_wr":0, From 75115d9569164b99a52847450d5133af62f3d370 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Canet?= Date: Thu, 2 Aug 2012 10:22:49 +0200 Subject: [PATCH 4/4] hmp: show the backing file depth Signed-off-by: Benoit Canet Reviewed-by: Eric Blake Signed-off-by: Luiz Capitulino --- hmp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hmp.c b/hmp.c index 6b72a64d99..25688ab0e2 100644 --- a/hmp.c +++ b/hmp.c @@ -227,6 +227,8 @@ void hmp_info_block(Monitor *mon) if (info->value->inserted->has_backing_file) { monitor_printf(mon, " backing_file="); monitor_print_filename(mon, info->value->inserted->backing_file); + monitor_printf(mon, " backing_file_depth=%" PRId64, + info->value->inserted->backing_file_depth); } monitor_printf(mon, " ro=%d drv=%s encrypted=%d", info->value->inserted->ro,