All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Vivier <Laurent.Vivier@bull.net>
To: qemu-devel@nongnu.org
Cc: Laurent Vivier <Laurent.Vivier@bull.net>
Subject: [Qemu-devel] [PATCH 4/4] qcow2: detect if no disk cache
Date: Thu, 06 Nov 2008 17:56:01 +0100	[thread overview]
Message-ID: <1225990561.6576.14.camel@frecb07144> (raw)
In-Reply-To: 20081106165212.380421945@bull.net

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 <Laurent.Vivier@bull.net>
---
 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 +

-- 

      parent reply	other threads:[~2008-11-06 16:56 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20081106165212.380421945@bull.net>
2008-11-06 16:55 ` [Qemu-devel] [PATCH 1/4] qcow2: Clean-up update_cluster_refcount() Laurent Vivier
2008-11-06 17:32   ` Kevin Wolf
2008-11-07  8:48     ` Laurent Vivier
2008-11-07  8:54       ` Kevin Wolf
2008-11-07  9:22         ` Laurent Vivier
2008-11-06 16:55 ` [Qemu-devel] [PATCH 2/4] qcow2: Allow update_cluster_refcount() to update several clusters refcount Laurent Vivier
2008-11-06 18:11   ` Kevin Wolf
2008-11-07 10:03     ` Laurent Vivier
2008-11-07 10:21       ` Kevin Wolf
2008-11-07 11:39         ` Laurent Vivier
2008-11-06 16:55 ` [Qemu-devel] [PATCH 3/4] qcow2: Align I/O access to l2 table and refcount block Laurent Vivier
2008-11-06 16:56 ` Laurent Vivier [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1225990561.6576.14.camel@frecb07144 \
    --to=laurent.vivier@bull.net \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.