[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 4/4] qcow2: detect if no disk cache
From: |
Laurent Vivier |
Subject: |
[Qemu-devel] [PATCH 4/4] qcow2: detect if no disk cache |
Date: |
Thu, 06 Nov 2008 17:56:01 +0100 |
pièce 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 <address@hidden>
---
block-qcow2.c | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
Index: qemu/block-qcow2.c
===================================================================
--- 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;
static int decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset);
@@ -193,6 +194,7 @@ static int qcow_open(BlockDriverState *b
ret = bdrv_file_open(&s->hd, filename, flags);
if (ret < 0)
return ret;
+ s->disk_nocache = (flags & BDRV_O_NOCACHE) != 0;
if (bdrv_pread(s->hd, 0, &header, sizeof(header)) != 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) = 12 - 3 = 9;
* and s->l2_size = 1 << s->l2_bits, so l2_cache is aligned on 512
boundary.
*/
- aligned_index = l2_index & ~63;
- aligned_size = (l2_index - aligned_index + nb_clusters + 63) & ~63ULL;
+ if (s->disk_nocache) {
+ aligned_index = l2_index & ~63;
+ aligned_size = (l2_index - aligned_index + nb_clusters + 63) & ~63ULL;
+ } else {
+ aligned_index = l2_index;
+ aligned_size = nb_clusters;
+ }
aligned_size *= 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 = block_index & ~((512 >> REFCOUNT_SHIFT) - 1);
- aligned_size = (block_index - aligned_index + nb_block_index +
- ((512 >> REFCOUNT_SHIFT) - 1)) &
- ~((512 >> REFCOUNT_SHIFT) - 1);
+ if (s->disk_nocache) {
+ aligned_index = block_index & ~((512 >> REFCOUNT_SHIFT) - 1);
+ aligned_size = (block_index - aligned_index + nb_block_index +
+ ((512 >> REFCOUNT_SHIFT) - 1)) &
+ ~((512 >> REFCOUNT_SHIFT) - 1);
+ } else {
+ aligned_index = block_index;
+ aligned_size = nb_block_index;
+ }
aligned_size *= sizeof(uint16_t);
if (bdrv_pwrite(s->hd,
refcount_block_offset +
--
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemu-devel] [PATCH 4/4] qcow2: detect if no disk cache,
Laurent Vivier <=