From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:50897) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUAim-0007F9-6m for qemu-devel@nongnu.org; Mon, 22 Apr 2013 02:59:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UUAil-00019J-7S for qemu-devel@nongnu.org; Mon, 22 Apr 2013 02:59:28 -0400 Received: from mail-pa0-f42.google.com ([209.85.220.42]:43645) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUAil-00019D-1j for qemu-devel@nongnu.org; Mon, 22 Apr 2013 02:59:27 -0400 Received: by mail-pa0-f42.google.com with SMTP id kq13so3421492pab.15 for ; Sun, 21 Apr 2013 23:59:26 -0700 (PDT) From: Liu Yuan Date: Mon, 22 Apr 2013 14:59:10 +0800 Message-Id: <1366613950-10918-3-git-send-email-namei.unix@gmail.com> In-Reply-To: <1366613950-10918-1-git-send-email-namei.unix@gmail.com> References: <1366613950-10918-1-git-send-email-namei.unix@gmail.com> Subject: [Qemu-devel] [PATCH v2 2/2] sheepdog: implement .bdrv_co_is_allocated() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , sheepdog@lists.wpkg.org, Stefan Hajnoczi , MORITA Kazutaka From: Liu Yuan Cc: MORITA Kazutaka Cc: Kevin Wolf Cc: Stefan Hajnoczi Signed-off-by: Liu Yuan --- block/sheepdog.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/block/sheepdog.c b/block/sheepdog.c index 0b700a3..0dbf039 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -2137,6 +2137,39 @@ static coroutine_fn int sd_co_discard(BlockDriverState *bs, int64_t sector_num, return acb->ret; } +static coroutine_fn int +sd_co_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, + int *pnum) +{ + BDRVSheepdogState *s = bs->opaque; + SheepdogInode *inode = &s->inode; + unsigned long start = sector_num * BDRV_SECTOR_SIZE / SD_DATA_OBJ_SIZE, idx, + end = DIV_ROUND_UP((sector_num + nb_sectors) * + BDRV_SECTOR_SIZE, SD_DATA_OBJ_SIZE); + int ret = 1; + + for (idx = start; idx <= end; idx++) { + if (inode->data_vdi_id[idx] == 0) { + break; + } + } + if (idx == start) { + /* Get te longest length of unallocated sectors */ + ret = 0; + for (idx = start + 1; idx <= end; idx++) { + if (inode->data_vdi_id[idx] != 0) { + break; + } + } + } + + *pnum = (idx - start) * SD_DATA_OBJ_SIZE / BDRV_SECTOR_SIZE; + if (*pnum > nb_sectors) { + *pnum = nb_sectors; + } + return ret; +} + static QEMUOptionParameter sd_create_options[] = { { .name = BLOCK_OPT_SIZE, @@ -2170,6 +2203,7 @@ static BlockDriver bdrv_sheepdog = { .bdrv_co_writev = sd_co_writev, .bdrv_co_flush_to_disk = sd_co_flush_to_disk, .bdrv_co_discard = sd_co_discard, + .bdrv_co_is_allocated = sd_co_is_allocated, .bdrv_snapshot_create = sd_snapshot_create, .bdrv_snapshot_goto = sd_snapshot_goto, @@ -2196,6 +2230,7 @@ static BlockDriver bdrv_sheepdog_tcp = { .bdrv_co_writev = sd_co_writev, .bdrv_co_flush_to_disk = sd_co_flush_to_disk, .bdrv_co_discard = sd_co_discard, + .bdrv_co_is_allocated = sd_co_is_allocated, .bdrv_snapshot_create = sd_snapshot_create, .bdrv_snapshot_goto = sd_snapshot_goto, @@ -2222,6 +2257,7 @@ static BlockDriver bdrv_sheepdog_unix = { .bdrv_co_writev = sd_co_writev, .bdrv_co_flush_to_disk = sd_co_flush_to_disk, .bdrv_co_discard = sd_co_discard, + .bdrv_co_is_allocated = sd_co_is_allocated, .bdrv_snapshot_create = sd_snapshot_create, .bdrv_snapshot_goto = sd_snapshot_goto, -- 1.7.9.5