From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L4eab-0005Sk-8X for qemu-devel@nongnu.org; Mon, 24 Nov 2008 11:47:09 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L4eaX-0005SH-MW for qemu-devel@nongnu.org; Mon, 24 Nov 2008 11:47:08 -0500 Received: from [199.232.76.173] (port=56157 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L4eaX-0005SE-Cn for qemu-devel@nongnu.org; Mon, 24 Nov 2008 11:47:05 -0500 Received: from an-out-0708.google.com ([209.85.132.242]:55322) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1L4eaW-0000lR-Uh for qemu-devel@nongnu.org; Mon, 24 Nov 2008 11:47:05 -0500 Received: by an-out-0708.google.com with SMTP id c38so785473ana.37 for ; Mon, 24 Nov 2008 08:47:04 -0800 (PST) Message-ID: <492ADA84.3040109@codemonkey.ws> Date: Mon, 24 Nov 2008 10:47:00 -0600 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH 4/5] Cleanup {alloc|get}_cluster_offset(). References: <20081123145248.22178.36228.stgit@dhcp-1-237.tlv.redhat.com> <20081123145319.22178.5237.stgit@dhcp-1-237.tlv.redhat.com> In-Reply-To: <20081123145319.22178.5237.stgit@dhcp-1-237.tlv.redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Gleb Natapov wrote: > Move duplicated code into helper functions. > > Signed-off-by: Gleb Natapov > --- > > block-qcow2.c | 160 +++++++++++++++++++++++++-------------------------------- > 1 files changed, 70 insertions(+), 90 deletions(-) > > diff --git a/block-qcow2.c b/block-qcow2.c > index 7f99921..0771281 100644 > --- a/block-qcow2.c > +++ b/block-qcow2.c > @@ -61,6 +61,8 @@ > > #define REFCOUNT_SHIFT 1 /* refcount size is 2 bytes */ > > +#define SIZE2CLUSTERS(Q, S) (((S) + ((Q)->cluster_size - 1)) >> (Q)->cluster_bits) > Please make this a static function. > @@ -668,38 +693,23 @@ static uint64_t get_cluster_offset(BlockDriverState *bs, > > l2_index = (offset >> s->cluster_bits) & (s->l2_size - 1); > cluster_offset = be64_to_cpu(l2_table[l2_index]); > - nb_available = s->cluster_sectors; > - l2_index++; > - > - if (!cluster_offset) { > - > - /* how many empty clusters ? */ > - > - while (nb_available < nb_needed && !l2_table[l2_index]) { > - l2_index++; > - nb_available += s->cluster_sectors; > - } > - } else { > + nb_clusters = SIZE2CLUSTERS(s, nb_needed << 9); > > + c = (!cluster_offset) ? > + /* how many empty clusters ? */ > + count_contiguous_free_clusters(nb_clusters, &l2_table[l2_index]) : > /* how many allocated clusters ? */ > + count_contiguous_clusters(nb_clusters, s->cluster_size, > + &l2_table[l2_index], QCOW_OFLAG_COPIED); > Just use an if() here. > nb_available = nb_clusters << (s->cluster_bits - 9); > if (nb_available > n_end) > @@ -951,6 +937,7 @@ static uint64_t alloc_cluster_offset(BlockDriverState *bs, > > cluster_offset = alloc_clusters(bs, nb_clusters * s->cluster_size); > > + > /* we must initialize the cluster content which won't be > written */ Unnecessary whitespace. Regards, Anthony Liguori