From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M8WfG-0005ha-GH for qemu-devel@nongnu.org; Mon, 25 May 2009 05:40:14 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M8Wf8-0005ed-6o for qemu-devel@nongnu.org; Mon, 25 May 2009 05:40:12 -0400 Received: from [199.232.76.173] (port=52299 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M8Wf7-0005ea-Tf for qemu-devel@nongnu.org; Mon, 25 May 2009 05:40:06 -0400 Received: from mx2.redhat.com ([66.187.237.31]:48220) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1M8Wf7-0007vc-BI for qemu-devel@nongnu.org; Mon, 25 May 2009 05:40:05 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n4P9e4eT012330 for ; Mon, 25 May 2009 05:40:04 -0400 From: Kevin Wolf Date: Mon, 25 May 2009 11:38:59 +0200 Message-Id: <1243244339-15179-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH v2] qcow/qcow2: Drop synchronous qcow_write() List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf There is only one (internal) user left and it can be switched to the normal emulation provided in block.c Signed-off-by: Kevin Wolf --- block/qcow.c | 37 +------------------------------------ block/qcow2.c | 42 +----------------------------------------- 2 files changed, 2 insertions(+), 77 deletions(-) diff --git a/block/qcow.c b/block/qcow.c index 6ecf2e8..77c86e4 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -488,41 +488,6 @@ static int qcow_read(BlockDriverState *bs, int64_t sector_num, } #endif -static int qcow_write(BlockDriverState *bs, int64_t sector_num, - const uint8_t *buf, int nb_sectors) -{ - BDRVQcowState *s = bs->opaque; - int ret, index_in_cluster, n; - uint64_t cluster_offset; - - while (nb_sectors > 0) { - index_in_cluster = sector_num & (s->cluster_sectors - 1); - n = s->cluster_sectors - index_in_cluster; - if (n > nb_sectors) - n = nb_sectors; - cluster_offset = get_cluster_offset(bs, sector_num << 9, 1, 0, - index_in_cluster, - index_in_cluster + n); - if (!cluster_offset) - return -1; - if (s->crypt_method) { - encrypt_sectors(s, sector_num, s->cluster_data, buf, n, 1, - &s->aes_encrypt_key); - ret = bdrv_pwrite(s->hd, cluster_offset + index_in_cluster * 512, - s->cluster_data, n * 512); - } else { - ret = bdrv_pwrite(s->hd, cluster_offset + index_in_cluster * 512, buf, n * 512); - } - if (ret != n * 512) - return -1; - nb_sectors -= n; - sector_num += n; - buf += n * 512; - } - s->cluster_cache_offset = -1; /* disable compressed cache */ - return 0; -} - typedef struct QCowAIOCB { BlockDriverAIOCB common; int64_t sector_num; @@ -904,7 +869,7 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num, if (ret != Z_STREAM_END || out_len >= s->cluster_size) { /* could not compress: write normal cluster */ - qcow_write(bs, sector_num, buf, s->cluster_sectors); + bdrv_write(bs, sector_num, buf, s->cluster_sectors); } else { cluster_offset = get_cluster_offset(bs, sector_num << 9, 2, out_len, 0, 0); diff --git a/block/qcow2.c b/block/qcow2.c index 77f433e..aeb3340 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1229,46 +1229,6 @@ static int qcow_read(BlockDriverState *bs, int64_t sector_num, return 0; } -static int qcow_write(BlockDriverState *bs, int64_t sector_num, - const uint8_t *buf, int nb_sectors) -{ - BDRVQcowState *s = bs->opaque; - int ret, index_in_cluster, n; - uint64_t cluster_offset; - int n_end; - QCowL2Meta l2meta; - - while (nb_sectors > 0) { - index_in_cluster = sector_num & (s->cluster_sectors - 1); - n_end = index_in_cluster + nb_sectors; - if (s->crypt_method && - n_end > QCOW_MAX_CRYPT_CLUSTERS * s->cluster_sectors) - n_end = QCOW_MAX_CRYPT_CLUSTERS * s->cluster_sectors; - cluster_offset = alloc_cluster_offset(bs, sector_num << 9, - index_in_cluster, - n_end, &n, &l2meta); - if (!cluster_offset) - return -1; - if (s->crypt_method) { - encrypt_sectors(s, sector_num, s->cluster_data, buf, n, 1, - &s->aes_encrypt_key); - ret = bdrv_pwrite(s->hd, cluster_offset + index_in_cluster * 512, - s->cluster_data, n * 512); - } else { - ret = bdrv_pwrite(s->hd, cluster_offset + index_in_cluster * 512, buf, n * 512); - } - if (ret != n * 512 || alloc_cluster_link_l2(bs, cluster_offset, &l2meta) < 0) { - free_any_clusters(bs, cluster_offset, l2meta.nb_clusters); - return -1; - } - nb_sectors -= n; - sector_num += n; - buf += n * 512; - } - s->cluster_cache_offset = -1; /* disable compressed cache */ - return 0; -} - typedef struct QCowAIOCB { BlockDriverAIOCB common; int64_t sector_num; @@ -1834,7 +1794,7 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num, if (ret != Z_STREAM_END || out_len >= s->cluster_size) { /* could not compress: write normal cluster */ - qcow_write(bs, sector_num, buf, s->cluster_sectors); + bdrv_write(bs, sector_num, buf, s->cluster_sectors); } else { cluster_offset = alloc_compressed_cluster_offset(bs, sector_num << 9, out_len); -- 1.6.0.6