qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v4 1/3] qcow2: Add QcowCache


From: Stefan Hajnoczi
Subject: Re: [Qemu-devel] [PATCH v4 1/3] qcow2: Add QcowCache
Date: Mon, 24 Jan 2011 14:00:16 +0000

On Thu, Jan 20, 2011 at 5:10 PM, Kevin Wolf <address@hidden> wrote:
> +int qcow2_cache_get(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset,
> +    void **table)
[...]
> +int qcow2_cache_put(BlockDriverState *bs, Qcow2Cache *c, void **table)
> +{
> +    int i;
> +
> +    for (i = 0; i < c->size; i++) {
> +        if (c->entries[i].table == *table) {
> +            goto found;
> +        }
> +    }
> +    return -ENOENT;
> +
> +found:

Using void **table instead of a QCowCacheEntry struct has two disadvantages:

1. The fact that you're holding a reference is not explicit.  It makes
it unclear whether we're dealing with a cached table or not.  In user
code, uint64_t *l2_table doesn't tell me whether this table is in the
cache or is being managed outside the cache.  Therefore it's hard to
check that the necessary qcow2_cache_put() calls are being made.

2. qcow2-cache.c needs to scan through the cache linearly looking for
void *table on every call.  If the user holds an explicit
QCowCacheEntry then no lookup is necessary.

Stefan



reply via email to

[Prev in Thread] Current Thread [Next in Thread]