qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: anthony@codemonkey.ws
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 15/20] qcow2: Add qcow2_alloc_clusters_at()
Date: Mon, 12 Mar 2012 16:19:46 +0100	[thread overview]
Message-ID: <1331565591-8414-16-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1331565591-8414-1-git-send-email-kwolf@redhat.com>

This function allows to allocate clusters at a given offset in the image
file. This is useful if you want to allocate the second part of an area
that must be contiguous.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
 block/qcow2-refcount.c |   28 ++++++++++++++++++++++++++++
 block/qcow2.h          |    2 ++
 2 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 2db2ede..f39928a 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -582,6 +582,34 @@ int64_t qcow2_alloc_clusters(BlockDriverState *bs, int64_t size)
     return offset;
 }
 
+int qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset,
+    int nb_clusters)
+{
+    BDRVQcowState *s = bs->opaque;
+    uint64_t cluster_index;
+    int i, refcount, ret;
+
+    /* Check how many clusters there are free */
+    cluster_index = offset >> s->cluster_bits;
+    for(i = 0; i < nb_clusters; i++) {
+        refcount = get_refcount(bs, cluster_index++);
+
+        if (refcount < 0) {
+            return refcount;
+        } else if (refcount != 0) {
+            break;
+        }
+    }
+
+    /* And then allocate them */
+    ret = update_refcount(bs, offset, i << s->cluster_bits, 1);
+    if (ret < 0) {
+        return ret;
+    }
+
+    return i;
+}
+
 /* only used to allocate compressed sectors. We try to allocate
    contiguous sectors. size must be <= cluster_size */
 int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size)
diff --git a/block/qcow2.h b/block/qcow2.h
index fc35838..5129e3e 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -193,6 +193,8 @@ int qcow2_refcount_init(BlockDriverState *bs);
 void qcow2_refcount_close(BlockDriverState *bs);
 
 int64_t qcow2_alloc_clusters(BlockDriverState *bs, int64_t size);
+int qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset,
+    int nb_clusters);
 int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size);
 void qcow2_free_clusters(BlockDriverState *bs,
     int64_t offset, int64_t size);
-- 
1.7.6.5

  parent reply	other threads:[~2012-03-12 15:17 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-12 15:19 [Qemu-devel] [PULL 00/20] Block patches Kevin Wolf
2012-03-12 15:19 ` [Qemu-devel] [PATCH 01/20] Group snapshot: Fix format name for backing file Kevin Wolf
2012-03-12 15:19 ` [Qemu-devel] [PATCH 02/20] qed: do not evict in-use L2 table cache entries Kevin Wolf
2012-03-12 15:19 ` [Qemu-devel] [PATCH 03/20] qcow2: Add some tracing Kevin Wolf
2012-03-12 15:19 ` [Qemu-devel] [PATCH 04/20] block: handle -EBUSY in bdrv_commit_all() Kevin Wolf
2012-03-12 15:19 ` [Qemu-devel] [PATCH 05/20] qcow2: Add error messages in qcow2_truncate Kevin Wolf
2012-03-12 15:19 ` [Qemu-devel] [PATCH 06/20] qemu-iotests: Mark some tests as quick Kevin Wolf
2012-03-12 15:19 ` [Qemu-devel] [PATCH 07/20] make check: Add qemu-iotests subset Kevin Wolf
2012-03-12 15:19 ` [Qemu-devel] [PATCH 08/20] Add 'make check-block' Kevin Wolf
2012-03-12 15:19 ` [Qemu-devel] [PATCH 09/20] use QSIMPLEQ_FOREACH_SAFE when freeing list elements Kevin Wolf
2012-03-12 15:19 ` [Qemu-devel] [PATCH 10/20] qapi: complete implementation of unions Kevin Wolf
2012-03-12 15:19 ` [Qemu-devel] [PATCH 11/20] rename blockdev-group-snapshot-sync Kevin Wolf
2012-03-12 15:19 ` [Qemu-devel] [PATCH 12/20] add mode field to blockdev-snapshot-sync transaction item Kevin Wolf
2012-03-12 15:19 ` [Qemu-devel] [PATCH 13/20] qmp: convert blockdev-snapshot-sync to a wrapper around transactions Kevin Wolf
2012-03-12 15:19 ` [Qemu-devel] [PATCH 14/20] qcow2: Factor out count_cow_clusters Kevin Wolf
2012-03-12 15:19 ` Kevin Wolf [this message]
2012-03-12 15:19 ` [Qemu-devel] [PATCH 16/20] qcow2: Reduce number of I/O requests Kevin Wolf
2012-03-12 15:19 ` [Qemu-devel] [PATCH 17/20] coroutine: adding sigaltstack method (.c source) Kevin Wolf
2012-03-12 15:19 ` [Qemu-devel] [PATCH 18/20] coroutine: adding configure choose mechanism for coroutine backend Kevin Wolf
2012-03-12 15:19 ` [Qemu-devel] [PATCH 19/20] coroutine: adding configure option for sigaltstack " Kevin Wolf
2012-03-12 15:19 ` [Qemu-devel] [PATCH 20/20] test-coroutine: add performance test for nesting Kevin Wolf
2012-03-13  2:23 ` [Qemu-devel] [PULL 00/20] Block patches Anthony Liguori

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=1331565591-8414-16-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=anthony@codemonkey.ws \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).