From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Ky89z-0005DW-Ea for qemu-devel@nongnu.org; Thu, 06 Nov 2008 11:56:43 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Ky89y-0005D2-Nc for qemu-devel@nongnu.org; Thu, 06 Nov 2008 11:56:42 -0500 Received: from [199.232.76.173] (port=41038 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ky89y-0005Cw-Gl for qemu-devel@nongnu.org; Thu, 06 Nov 2008 11:56:42 -0500 Received: from ecfrec.frec.bull.fr ([129.183.4.8]:40513) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Ky89y-0000Fh-6o for qemu-devel@nongnu.org; Thu, 06 Nov 2008 11:56:42 -0500 Received: from localhost (localhost [127.0.0.1]) by ecfrec.frec.bull.fr (Postfix) with ESMTP id 70A031A18C9 for ; Thu, 6 Nov 2008 17:56:06 +0100 (CET) Received: from ecfrec.frec.bull.fr ([127.0.0.1]) by localhost (ecfrec.frec.bull.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 01454-04 for ; Thu, 6 Nov 2008 17:56:03 +0100 (CET) Received: from cyclope.frec.bull.fr (cyclope.frec.bull.fr [129.183.4.9]) by ecfrec.frec.bull.fr (Postfix) with ESMTP id 59F1F1A18B9 for ; Thu, 6 Nov 2008 17:55:57 +0100 (CET) From: Laurent Vivier References: <20081106165212.380421945@bull.net> Content-Type: text/plain; charset=utf-8 Date: Thu, 06 Nov 2008 17:56:01 +0100 Message-Id: <1225990561.6576.14.camel@frecb07144> Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH 4/4] qcow2: detect if no disk cache Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Laurent Vivier pi=C3=A8ce jointe document texte brut (0004-qcow2-detect-if-no-disk-cache.patch) To reduce the number of bytes read and written, disable the forced I/O alignment when the file is not open with O_DIRECT. Signed-off-by: Laurent Vivier --- block-qcow2.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) Index: qemu/block-qcow2.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- qemu.orig/block-qcow2.c 2008-11-06 16:41:15.000000000 +0100 +++ qemu/block-qcow2.c 2008-11-06 16:41:16.000000000 +0100 @@ -147,6 +147,7 @@ typedef struct BDRVQcowState { int snapshots_size; int nb_snapshots; QCowSnapshot *snapshots; + int disk_nocache; } BDRVQcowState; =20 static int decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset)= ; @@ -193,6 +194,7 @@ static int qcow_open(BlockDriverState *b ret =3D bdrv_file_open(&s->hd, filename, flags); if (ret < 0) return ret; + s->disk_nocache =3D (flags & BDRV_O_NOCACHE) !=3D 0; if (bdrv_pread(s->hd, 0, &header, sizeof(header)) !=3D sizeof(header= )) goto fail; be32_to_cpus(&header.magic); @@ -994,8 +996,13 @@ static uint64_t alloc_cluster_offset(Blo * and s->l2_bits is (s->cluster_bits - 3) =3D 12 - 3 =3D 9; * and s->l2_size =3D 1 << s->l2_bits, so l2_cache is aligned on 512= boundary. */ - aligned_index =3D l2_index & ~63; - aligned_size =3D (l2_index - aligned_index + nb_clusters + 63) & ~63= ULL; + if (s->disk_nocache) { + aligned_index =3D l2_index & ~63; + aligned_size =3D (l2_index - aligned_index + nb_clusters + 63) &= ~63ULL; + } else { + aligned_index =3D l2_index; + aligned_size =3D nb_clusters; + } aligned_size *=3D sizeof(uint64_t); if (bdrv_pwrite(s->hd, l2_offset + aligned_index * sizeof(uint64_t), @@ -2467,10 +2474,15 @@ static int update_cluster_refcount(Block * size of refcount_block_cache is s->cluster_size (4096) * so we can align access on a 512 boundary */ - aligned_index =3D block_index & ~((512 >> REFCOUNT_SHIFT) - 1); - aligned_size =3D (block_index - aligned_index + nb_block_index += =20 - ((512 >> REFCOUNT_SHIFT) - 1)) & - ~((512 >> REFCOUNT_SHIFT) - 1); + if (s->disk_nocache) { + aligned_index =3D block_index & ~((512 >> REFCOUNT_SHIFT) - = 1); + aligned_size =3D (block_index - aligned_index + nb_block_ind= ex +=20 + ((512 >> REFCOUNT_SHIFT) - 1)) & + ~((512 >> REFCOUNT_SHIFT) - 1); + } else { + aligned_index =3D block_index; + aligned_size =3D nb_block_index; + } aligned_size *=3D sizeof(uint16_t); if (bdrv_pwrite(s->hd, refcount_block_offset + --=20