[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 23/26] FVD: add impl of interface bdrv_is_allocated(
From: |
Chunqiang Tang |
Subject: |
[Qemu-devel] [PATCH 23/26] FVD: add impl of interface bdrv_is_allocated() |
Date: |
Fri, 25 Feb 2011 17:38:03 -0500 |
This patch is part of the Fast Virtual Disk (FVD) proposal.
See http://wiki.qemu.org/Features/FVD.
This patch adds FVD's implementation of the bdrv_is_allocated() interface.
Signed-off-by: Chunqiang Tang <address@hidden>
---
block/fvd-misc.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 67 insertions(+), 0 deletions(-)
diff --git a/block/fvd-misc.c b/block/fvd-misc.c
index 63ed168..766b62b 100644
--- a/block/fvd-misc.c
+++ b/block/fvd-misc.c
@@ -169,6 +169,73 @@ static int fvd_probe(const uint8_t * buf, int buf_size,
const char *filename)
static int fvd_is_allocated(BlockDriverState * bs, int64_t sector_num,
int nb_sectors, int *pnum)
{
+ BDRVFvdState *s = bs->opaque;
+
+ if (s->prefetch_state == PREFETCH_STATE_FINISHED ||
+ sector_num >= s->base_img_sectors ||
+ !fresh_bitmap_show_sector_in_base_img(sector_num, s)) {
+ /* For the three cases that data may be saved in the FVD data file, we
+ * still need to check the underlying storage because those data could
+ * be holes in a sparse image, due to the optimization of "free write
+ * to zero-filled blocks". See Section 3.3.3 of the FVD-cow paper.
+ * This also covers the case of no base image. */
+
+ if (!s->table) {
+ return bdrv_is_allocated(s->fvd_data, s->data_offset + sector_num,
+ nb_sectors, pnum);
+ }
+
+ /* Use the table to figure it out. */
+ int64_t first_chunk = sector_num / s->chunk_size;
+ int64_t last_chunk = (sector_num + nb_sectors - 1) / s->chunk_size;
+ int allocated = !IS_EMPTY(s->table[first_chunk]);
+ int count;
+
+ if (first_chunk == last_chunk) {
+ /* All data in one chunk. */
+ *pnum = nb_sectors;
+ return allocated;
+ }
+
+ /* Data in the first chunk. */
+ count = s->chunk_size - (sector_num % s->chunk_size);
+
+ /* Full chunks. */
+ first_chunk++;
+ while (first_chunk < last_chunk) {
+ if ((allocated && IS_EMPTY(s->table[first_chunk]))
+ || (!allocated && !IS_EMPTY(s->table[first_chunk]))) {
+ *pnum = count;
+ return allocated;
+ }
+
+ count += s->chunk_size;
+ first_chunk++;
+ }
+
+ /* Data in the last chunk. */
+ if ((allocated && !IS_EMPTY(s->table[last_chunk]))
+ || (!allocated && IS_EMPTY(s->table[last_chunk]))) {
+ int nb = (sector_num + nb_sectors) % s->chunk_size;
+ count += nb ? nb : s->chunk_size;
+ }
+
+ *pnum = count;
+ return allocated;
+ }
+
+ /* Use the FVD metadata to find out sectors in the base image. */
+ int64_t end = sector_num + nb_sectors;
+ if (end > s->base_img_sectors) {
+ end = s->base_img_sectors;
+ }
+
+ int64_t next = sector_num + 1;
+ while (next < end && fresh_bitmap_show_sector_in_base_img(next, s)) {
+ next++;
+ }
+
+ *pnum = next - sector_num;
return 0;
}
--
1.7.0.4
- [Qemu-devel] [PATCH 01/26] FVD: add simulated block driver 'blksim', Chunqiang Tang, 2011/02/25
- [Qemu-devel] [PATCH 10/26] FVD: add impl of interface bdrv_file_open(), Chunqiang Tang, 2011/02/25
- [Qemu-devel] [PATCH 08/26] FVD: add debugging utilities, Chunqiang Tang, 2011/02/25
- [Qemu-devel] [PATCH 16/26] FVD: add impl for buffered journal updates, Chunqiang Tang, 2011/02/25
- [Qemu-devel] [PATCH 20/26] FVD: add impl of interface bdrv_get_info(), Chunqiang Tang, 2011/02/25
- [Qemu-devel] [PATCH 24/26] FVD: add impl of interface bdrv_has_zero_init(), Chunqiang Tang, 2011/02/25
- [Qemu-devel] [PATCH 21/26] FVD: add impl of interface bdrv_close(), Chunqiang Tang, 2011/02/25
- [Qemu-devel] [PATCH 14/26] FVD: add impl of loading data from compact image, Chunqiang Tang, 2011/02/25
- [Qemu-devel] [PATCH 26/26] FVD: add fully automated test-fvd.sh, Chunqiang Tang, 2011/02/25
- [Qemu-devel] [PATCH 23/26] FVD: add impl of interface bdrv_is_allocated(),
Chunqiang Tang <=
- [Qemu-devel] [PATCH 17/26] FVD: add impl of bdrv_flush() and bdrv_aio_flush(), Chunqiang Tang, 2011/02/25
- [Qemu-devel] [PATCH 22/26] FVD: add impl of interface bdrv_update(), Chunqiang Tang, 2011/02/25
- [Qemu-devel] [PATCH 13/26] FVD: add impl of storing data in compact image, Chunqiang Tang, 2011/02/25
- [Qemu-devel] [PATCH 19/26] FVD: add support for aio_cancel, Chunqiang Tang, 2011/02/25
- [Qemu-devel] [PATCH 25/26] FVD: add impl of interface bdrv_probe(), Chunqiang Tang, 2011/02/25
- [Qemu-devel] [PATCH 15/26] FVD: add basic journal functionality, Chunqiang Tang, 2011/02/25
- [Qemu-devel] [PATCH 18/26] FVD: add support for base image prefetching, Chunqiang Tang, 2011/02/25
- [Qemu-devel] [PATCH 03/26] FVD: add fully automated test-qcow2.sh, Chunqiang Tang, 2011/02/25
- [Qemu-devel] [PATCH 02/26] FVD: extend qemu-io to do fully automated testing, Chunqiang Tang, 2011/02/25
- [Qemu-devel] [PATCH 07/26] FVD: extend FVD header fvd.h to be more complete, Chunqiang Tang, 2011/02/25