* [Qemu-devel] [PATCH] block: implement bdrv_co_is_allocated() boundary cases
@ 2011-11-29 13:49 Stefan Hajnoczi
2011-11-30 11:36 ` Kevin Wolf
0 siblings, 1 reply; 2+ messages in thread
From: Stefan Hajnoczi @ 2011-11-29 13:49 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Mark Wu, Stefan Hajnoczi
Cases beyond the end of the disk image are only implemented for block
drivers that do not provide .bdrv_co_is_allocated(). It's worth making
these cases generic so that block drivers that do implement
.bdrv_co_is_allocated() also get them for free.
Suggested-by: Mark Wu <wudxw@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
block.c | 26 ++++++++++++++++++--------
1 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/block.c b/block.c
index 4310eb5..1e468a7 100644
--- a/block.c
+++ b/block.c
@@ -2117,23 +2117,33 @@ typedef struct BdrvCoIsAllocatedData {
* not implementing the functionality are assumed to not support backing files,
* hence all their sectors are reported as allocated.
*
+ * If 'sector_num' is beyond the end of the disk image the return value is 0
+ * and 'pnum' is set to 0.
+ *
* 'pnum' is set to the number of sectors (including and immediately following
* the specified sector) that are known to be in the same
* allocated/unallocated state.
*
- * 'nb_sectors' is the max value 'pnum' should be set to.
+ * 'nb_sectors' is the max value 'pnum' should be set to. If nb_sectors goes
+ * beyond the end of the disk image it will be clamped.
*/
int coroutine_fn bdrv_co_is_allocated(BlockDriverState *bs, int64_t sector_num,
int nb_sectors, int *pnum)
{
+ int64_t n;
+
+ if (sector_num >= bs->total_sectors) {
+ *pnum = 0;
+ return 0;
+ }
+
+ n = bs->total_sectors - sector_num;
+ if (n < nb_sectors) {
+ nb_sectors = n;
+ }
+
if (!bs->drv->bdrv_co_is_allocated) {
- int64_t n;
- if (sector_num >= bs->total_sectors) {
- *pnum = 0;
- return 0;
- }
- n = bs->total_sectors - sector_num;
- *pnum = (n < nb_sectors) ? (n) : (nb_sectors);
+ *pnum = nb_sectors;
return 1;
}
--
1.7.7.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] block: implement bdrv_co_is_allocated() boundary cases
2011-11-29 13:49 [Qemu-devel] [PATCH] block: implement bdrv_co_is_allocated() boundary cases Stefan Hajnoczi
@ 2011-11-30 11:36 ` Kevin Wolf
0 siblings, 0 replies; 2+ messages in thread
From: Kevin Wolf @ 2011-11-30 11:36 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: Mark Wu, qemu-devel
Am 29.11.2011 14:49, schrieb Stefan Hajnoczi:
> Cases beyond the end of the disk image are only implemented for block
> drivers that do not provide .bdrv_co_is_allocated(). It's worth making
> these cases generic so that block drivers that do implement
> .bdrv_co_is_allocated() also get them for free.
>
> Suggested-by: Mark Wu <wudxw@linux.vnet.ibm.com>
> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Thanks, applied to the block branch.
Kevin
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-11-30 11:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-29 13:49 [Qemu-devel] [PATCH] block: implement bdrv_co_is_allocated() boundary cases Stefan Hajnoczi
2011-11-30 11:36 ` Kevin Wolf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).