Show backing file ancestors count in HMP
v3 cover Show backing file ancestors count in HMP
From: Benoît Canet <[email protected]>
In some setups many backing files and snapshot are chained. This lead to the formation of huge trees of snapshots all depending on a common ancestor.
Hence if something bad happen to this common ancestor all the snapshot of the tree will be broken.
This patch add an easy way for the user to monitor backing file ancestors count and take the good decision (streaming).
in v2:
lcapitulino: -Fix typo in qapi-schema.json
-rename *file_ancestors_count to
*backing_file_ancestors_count
in v3:
kwolf: qapi-schema.json backing_file_ancestors_count field not optional
Add a (since 1.2) comment
keep display in HMP optional
Benoît Canet (3):
block: create bdrv_get_backing_file_ancestors_count()
block: Use bdrv_get_backing_file_ancestors_count()
hmp: show the backing file ancestors count
block.c | 16 ++++++++++++++++ block.h | 1 + hmp.c | 2 ++ qapi-schema.json | 9 ++++++--- 4 files changed, 25 insertions(+), 3 deletions(-)
Signature · 1 line
1.7.9.5
PATCH v3 1/3 block: create bdrv_get_backing_file_ancestors_count()
From: Benoît Canet <[email protected]>
Create bdrv_get_backing_file_ancestors_count() in order to be able to show in QMP and HMP how many ancestors backing an image a block device have.
--- block.c | 13 +++++++++++++ block.h | 1 + 2 files changed, 14 insertions(+)
block.c +13 -0
@@ -2754,6 +2754,19 @@ BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs,return NULL ; } +int bdrv_get_backing_file_ancestors_count (BlockDriverState *bs) +{ +if (!bs->drv) { +return 0 ; + } + +if (!bs->backing_hd) { +return 0 ; + } + +return 1 +bdrv_get_backing_file_ancestors_count (bs->backing_hd); +} +#define NB_SUFFIXES 4char *get_human_readable_size (char *buf,int buf_size,int64_t size)
block.h +1 -0
@@ -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_ancestors_count (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);
Signature · 1 line
1.7.9.5
PATCH v3 3/3 hmp: show the backing file ancestors count
In reply to [email protected]From: Benoît Canet <[email protected]>
--- hmp.c | 2 ++ 1 file changed, 2 insertions(+)
hmp.c +2 -0
@@ -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_ancestors_count=%" PRId64, + info->value->inserted->backing_file_ancestors_count); } monitor_printf(mon, " ro=%d drv=%s encrypted=%d", info->value->inserted->ro,
Signature · 1 line
1.7.9.5
PATCH v3 2/3 block: Use bdrv_get_backing_file_ancestors_count()
In reply to [email protected]From: Benoît Canet <[email protected]>
Use the dedicated counting function in qmp_query_block in order to propagate the backing file count to HMP.
--- block.c | 3 +++ qapi-schema.json | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-)
block.c +3 -0
@@ -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_ancestors_count = +bdrv_get_backing_file_ancestors_count (bs); +if (bs->io_limits_enabled) { info->value->inserted->bps = bs->io_limits.bps[BLOCK_IO_LIMIT_TOTAL ];
qapi-schema.json +6 -3
@@ -398,6 +398,8 @@ # # @backing_file: #optional the name of the backing file (for copy-on-write) # +# @backing_file_ancestors_count: #the count of ancestors backing files (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_ancestors_count': 'int', + 'encrypted': 'bool', 'bps': 'int', 'bps_rd': 'int', + 'bps_wr': 'int', 'iops': 'int', 'iops_rd': 'int', + 'iops_wr': 'int'} } ## # @BlockDeviceIoStatus:
Signature · 1 line
1.7.9.5
Re: [Qemu-devel] [PATCH V3 1/3] block: create bdrv_get_backing_file_ancestors_count()
In reply to [email protected]Quoted 21 lines · On 07/25/2012 06:36 AM, [email protected] wrote:
From: Benoît Canet <[email protected]>
Create
bdrv_get_backing_file_ancestors_count()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 <[email protected]>--- block.c | 13 +++++++++++++ block.h | 1 + 2 files changed, 14 insertions(+)block.c +1
-0@@ -2754,6 +2754,19 @@ BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs,return NULL ; } +int bdrv_get_backing_file_ancestors_count (BlockDriverState *bs)
block.c BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs, · line 2767
Quoted 10 lines
block.c +10
-0+{ +if (!bs->drv) { +return 0 ; + } + +if (!bs->backing_hd) { +return 0 ; + } + +return 1 +bdrv_get_backing_file_ancestors_count (bs->backing_hd);
Is there any risk of stack overflow for a hugely nested setup? Then again, I suspect you are going to run into other issues if you are nested that deeply, before this recursion could cause overflow worth worrying about.
This is an O(n) operation; is it worth storing the nesting depth as part of a BlockDriverState to turn it into an O(1) operation? That is, you already have to do the O(n) traversal once when originally opening the chain, so why not have opening the chain populate a struct member with how deep the opening went, so that all future queries can just return that struct member. Of course, you then run into the issue that operations that change the depth (snapshot, block streaming, and the proposed block commit) would then be O(n) to adjust the counts of every member of the chain, instead of O(1) because the count is computed on the fly. Just food for thought, and not a technical reason requiring you to rewrite the patch unless you really like the idea.
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH V3 2/3] block: Use bdrv_get_backing_file_ancestors_count()
In reply to [email protected]qapi-schema.json line 401
Quoted 13 lines · On 07/25/2012 06:36 AM, [email protected] wrote:
From: Benoît Canet <[email protected]>
Use the dedicated counting function in
qmp_query_blockin order to propagate the backing file count to HMP.Signed-off-by Benoit Canet <[email protected]>+++
b/qapi-schema.jsonqapi-schema.json +1
-0@@ -398,6 +398,8 @@ # # @backing_file: #optional the name of the backing file (for copy-on-write) # +# @backing_file_ancestors_count: #the count of ancestors backing files (since: 1.2)
s/ancestors/ancestor's/ ?
s/#//
You are making it sound like this is the count of ancestors of the backing file (that is, 'base <- sn1 <- sn2' would have a count of 1, since there is 1 ancestor of the backing file sn1; and what if I have no backing file?), rather than a count of ancestors of this file (base has a count of 0, base <- sn1 has a count of 1). Maybe a better wording is:
@backing_file_depth: number of files in the backing file chain (since: 1.2)
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH V3 2/3] block: Use bdrv_get_backing_file_ancestors_count()
In reply to [email protected]Quoted 11 lines · On 07/25/2012 06:36 AM, [email protected] wrote:
+++
b/qapi-schema.jsonqapi-schema.json +2
-0@@ -398,6 +398,8 @@ # # @backing_file: #optional the name of the backing file (for copy-on-write) # +# @backing_file_ancestors_count: #the count of ancestors backing files (since: 1.2) +# # @encrypted: true if the backing device is encrypted # # @bps: total throughput limit in bytes per second is specified
qapi-schema.json line 423
Quoted 7 lines
qapi-schema.json +1
-3@@ -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_ancestors_count': 'int',
I hit send too soon. QMP prefers '-' over '_', so the new parameter should be 'backing-file-ancestors-count' (or with my proposal, 'backing-file-depth'). Yes, this particular struct has some _ for historical reasons, but that doesn't mean that new elements must share the misery.
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH V3 1/3] block: create bdrv_get_backing_file_ancestors_count()
In reply to Eric BlakeQuoted 21 lines · Eric Blake
Quoted 20 lines · On 07/25/2012 06:36 AM, [email protected] wrote:
From: Benoît Canet <[email protected]>
Create
bdrv_get_backing_file_ancestors_count()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 <[email protected]>--- block.c | 13 +++++++++++++ block.h | 1 + 2 files changed, 14 insertions(+)block.c +0
-0@@ -2754,6 +2754,19 @@ BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs,return NULL ; }
Quoted 17 lines
block.c BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs, · line 2767
Quoted 11 lines
block.c +11
-0+int bdrv_get_backing_file_ancestors_count (BlockDriverState *bs) +{ +if (!bs->drv) { +return 0 ; + } + +if (!bs->backing_hd) { +return 0 ; + } + +return 1 +bdrv_get_backing_file_ancestors_count (bs->backing_hd);Is there any risk of stack overflow for a hugely nested setup? Then again, I suspect you are going to run into other issues if you are nested that deeply, before this recursion could cause overflow worth worrying about.
I don't know.
Quoted 11 lines
This is an O(n) operation; is it worth storing the nesting depth as part of a BlockDriverState to turn it into an O(1) operation? That is, you already have to do the O(n) traversal once when originally opening the chain, so why not have opening the chain populate a struct member with how deep the opening went, so that all future queries can just return that struct member. Of course, you then run into the issue that operations that change the depth (snapshot, block streaming, and the proposed block commit) would then be O(n) to adjust the counts of every member of the chain, instead of O(1) because the count is computed on the fly. Just food for thought, and not a technical reason requiring you to rewrite the patch unless you really like the idea.
Hello,
I agree that 0(1) would be way better but wouldn't it increase further the know how required to touch the block layer.
(I think about newcomers like me implementing another feature requiring to change the depth and not being aware of this obligation)
Benoît
Quoted 5 lines
Signature · 3 lines
-- Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH V3 2/3] block: Use bdrv_get_backing_file_ancestors_count()
In reply to Eric BlakeQuoted 19 lines · Eric Blake
qapi-schema.json line 401
Quoted 13 lines · On 07/25/2012 06:36 AM, [email protected] wrote:
From: Benoît Canet <[email protected]>
Use the dedicated counting function in
qmp_query_blockin order to propagate the backing file count to HMP.Signed-off-by Benoit Canet <[email protected]>+++
b/qapi-schema.jsonqapi-schema.json +1
-0@@ -398,6 +398,8 @@ # # @backing_file: #optional the name of the backing file (for copy-on-write) # +# @backing_file_ancestors_count: #the count of ancestors backing files (since: 1.2)s/ancestors/ancestor's/ ?
s/#//
Quoted 7 lines
You are making it sound like this is the count of ancestors of the backing file (that is, 'base <- sn1 <- sn2' would have a count of 1, since there is 1 ancestor of the backing file sn1; and what if I have no backing file?), rather than a count of ancestors of this file (base has a count of 0, base <- sn1 has a count of 1). Maybe a better wording is:
@backing_file_depth: number of files in the backing file chain (since: 1.2)
I'll change it
Benoît
Quoted 5 lines
Signature · 3 lines
-- Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH V3 2/3] block: Use bdrv_get_backing_file_ancestors_count()
In reply to Eric BlakeQuoted 18 lines · Eric Blake
Quoted 16 lines · On 07/25/2012 06:36 AM, [email protected] wrote:
+++
b/qapi-schema.jsonqapi-schema.json +2
-2@@ -398,6 +398,8 @@ # # @backing_file: #optional the name of the backing file (for copy-on-write) # +# @backing_file_ancestors_count: #the count of ancestors backing files (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',
Quoted 8 lines
qapi-schema.json line 423
Quoted 2 lines
qapi-schema.json +1
-1- 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int'} } + '*backing_file': 'str', 'backing_file_ancestors_count': 'int',I hit send too soon. QMP prefers '-' over '_', so the new parameter should be 'backing-file-ancestors-count' (or with my proposal, 'backing-file-depth'). Yes, this particular struct has some _ for historical reasons, but that doesn't mean that new elements must share the misery.
I'll change it too.
Benoît
Quoted 5 lines
Signature · 3 lines
-- Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org