All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH V17 4/6] rename qcow2-cache.c to block-cache.c
Date: Mon, 10 Dec 2012 18:11:18 +0100	[thread overview]
Message-ID: <50C617B6.2050200@redhat.com> (raw)
In-Reply-To: <1354776711-12449-5-git-send-email-wdongxu@linux.vnet.ibm.com>

Am 06.12.2012 07:51, schrieb Dong Xu Wang:
> We will re-use qcow2-cache as block layer common cache code,
> so change its name and made some changes, define a struct named
> BlockTableType, pass BlockTableType and table size parameters to
> block cache initialization function.
> 
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> ---
>  block/Makefile.objs    |    3 +-
>  block/block-cache.c    |  317 +++++++++++++++++++++++++++++++++++++++++++++++
>  block/block-cache.h    |   76 +++++++++++
>  block/qcow2-cache.c    |  323 ------------------------------------------------
>  block/qcow2-cluster.c  |   53 ++++----
>  block/qcow2-refcount.c |   66 ++++++-----
>  block/qcow2.c          |   21 ++--
>  block/qcow2.h          |   24 +---
>  trace-events           |   13 +-
>  9 files changed, 481 insertions(+), 415 deletions(-)
>  create mode 100644 block/block-cache.c
>  create mode 100644 block/block-cache.h
>  delete mode 100644 block/qcow2-cache.c
> 
> diff --git a/block/Makefile.objs b/block/Makefile.objs
> index 7f01510..d23c250 100644
> --- a/block/Makefile.objs
> +++ b/block/Makefile.objs
> @@ -1,5 +1,6 @@
>  block-obj-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o vvfat.o
> -block-obj-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o qcow2-cache.o
> +block-obj-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o
> +block-obj-y += block-cache.o
>  block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o
>  block-obj-y += qed-check.o
>  block-obj-y += parallels.o blkdebug.o blkverify.o
> diff --git a/block/block-cache.c b/block/block-cache.c
> new file mode 100644
> index 0000000..bf5c57c
> --- /dev/null
> +++ b/block/block-cache.c
> @@ -0,0 +1,317 @@
> +/*
> + * QEMU Block Layer Cache
> + *
> + * Copyright IBM, Corp. 2012
> + *
> + * Authors:
> + *  Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> + *
> + * This file is based on qcow2-cache.c, see its copyrights below:
> + *
> + * L2/refcount table cache for the QCOW2 format
> + *
> + * Copyright (c) 2010 Kevin Wolf <kwolf@redhat.com>
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a copy
> + * of this software and associated documentation files (the "Software"), to deal
> + * in the Software without restriction, including without limitation the rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> + * THE SOFTWARE.
> + */
> +
> +#include "block_int.h"
> +#include "qemu-common.h"
> +#include "trace.h"
> +#include "block-cache.h"
> +
> +BlockCache *block_cache_create(BlockDriverState *bs, int num_tables,
> +                               size_t cluster_size, BlockTableType type)

cluster_size should probably be called table_size. It just happens that
qcow2 tables are always one cluster, but it may be different for other
formats using this implementation in the future.

> +int block_cache_put(BlockDriverState *bs, BlockCache *c, void **table)
> +{
> +    int i;
> +
> +    for (i = 0; i < c->size; i++) {
> +        if (c->entries[i].table == *table) {
> +            goto found;
> +        }
> +    }
> +    return -ENOENT;
> +
> +found:
> +    c->entries[i].ref--;
> +    assert(c->entries[i].ref >= 0);
> +    *table = NULL;
> +    return 0;
> +}

Why did you swap the assert() and *table = NULL?

> diff --git a/block/block-cache.h b/block/block-cache.h
> new file mode 100644
> index 0000000..4efa06e
> --- /dev/null
> +++ b/block/block-cache.h
> @@ -0,0 +1,76 @@
> +/*
> + * QEMU Block Layer Cache
> + *
> + * Copyright IBM, Corp. 2012
> + *
> + * Authors:
> + *  Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> + *
> + * This file is based on qcow2-cache.c, see its copyrights below:
> + *
> + * L2/refcount table cache for the QCOW2 format
> + *
> + * Copyright (c) 2010 Kevin Wolf <kwolf@redhat.com>
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a copy
> + * of this software and associated documentation files (the "Software"), to deal
> + * in the Software without restriction, including without limitation the rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> + * THE SOFTWARE.
> + */
> +
> +#ifndef BLOCK_CACHE_H
> +#define BLOCK_CACHE_H
> +
> +typedef enum {
> +    BLOCK_TABLE_REF,
> +    BLOCK_TABLE_L2,
> +} BlockTableType;

I'm not excited about exposing these types, but it's okay for now. We
can always change the implementation later to be nicer.

> +
> +typedef struct BlockCachedTable {
> +    void    *table;
> +    int64_t offset;
> +    bool    dirty;
> +    int     cache_hits;
> +    int     ref;
> +} BlockCachedTable;
> +
> +struct BlockCache {
> +    BlockCachedTable    *entries;
> +    struct BlockCache   *depends;
> +    int                 size;
> +    size_t              cluster_size;
> +    BlockTableType      table_type;
> +    bool                depends_on_flush;
> +};

Why have these definitions been moved to the header file? They are
supposed to be private to the implementation.

> +
> +struct BlockCache;
> +typedef struct BlockCache BlockCache;
> +
> +BlockCache *block_cache_create(BlockDriverState *bs, int num_tables,
> +                               size_t cluster_size, BlockTableType type);
> +int block_cache_destroy(BlockDriverState *bs, BlockCache *c);
> +int block_cache_flush(BlockDriverState *bs, BlockCache *c);
> +int block_cache_set_dependency(BlockDriverState *bs,
> +                               BlockCache *c,
> +                               BlockCache *dependency);
> +void block_cache_depends_on_flush(BlockCache *c);
> +int block_cache_get(BlockDriverState *bs, BlockCache *c, uint64_t offset,
> +                    void **table);
> +int block_cache_get_empty(BlockDriverState *bs, BlockCache *c,
> +                          uint64_t offset, void **table);
> +int block_cache_put(BlockDriverState *bs, BlockCache *c, void **table);
> +void block_cache_entry_mark_dirty(BlockCache *c, void *table);

Kevin

  reply	other threads:[~2012-12-10 17:11 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-06  6:51 [Qemu-devel] [PATCH V17 0/6] add-cow file format Dong Xu Wang
2012-12-06  6:51 ` [Qemu-devel] [PATCH V17 1/6] docs: document for " Dong Xu Wang
2012-12-10 15:39   ` Kevin Wolf
2012-12-11  8:02     ` Dong Xu Wang
2012-12-06  6:51 ` [Qemu-devel] [PATCH V17 2/6] make path_has_protocol non static Dong Xu Wang
2012-12-06  6:51 ` [Qemu-devel] [PATCH V17 3/6] qed_read_string to bdrv_read_string Dong Xu Wang
2012-12-06  6:51 ` [Qemu-devel] [PATCH V17 4/6] rename qcow2-cache.c to block-cache.c Dong Xu Wang
2012-12-10 17:11   ` Kevin Wolf [this message]
2012-12-11  8:25     ` Dong Xu Wang
2012-12-11  8:59       ` Kevin Wolf
2012-12-06  6:51 ` [Qemu-devel] [PATCH V17 5/6] add-cow file format core code Dong Xu Wang
2012-12-10 17:54   ` Kevin Wolf
2012-12-11  8:11     ` Dong Xu Wang
2012-12-11  9:03       ` Kevin Wolf
2012-12-06  6:51 ` [Qemu-devel] [PATCH V17 6/6] qemu-iotests: add add-cow iotests support Dong Xu Wang
2012-12-10 17:15   ` Kevin Wolf
2012-12-11  8:02     ` Dong Xu Wang

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=50C617B6.2050200@redhat.com \
    --to=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=wdongxu@linux.vnet.ibm.com \
    /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.