From: Anthony Liguori <aliguori@linux.vnet.ibm.com>
To: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Cc: Kevin Wolf <kwolf@redhat.com>, Avi Kivity <avi@redhat.com>,
qemu-devel@nongnu.org, Christoph Hellwig <hch@lst.de>
Subject: [Qemu-devel] Re: [PATCH v2 1/7] qcow2: Make get_bits_from_size() common
Date: Fri, 08 Oct 2010 13:01:48 -0500 [thread overview]
Message-ID: <4CAF5C8C.6090805@linux.vnet.ibm.com> (raw)
In-Reply-To: <1286552914-27014-2-git-send-email-stefanha@linux.vnet.ibm.com>
On 10/08/2010 10:48 AM, Stefan Hajnoczi wrote:
> The get_bits_from_size() calculates the log base-2 of a number. This is
> useful in bit manipulation code working with power-of-2s.
>
> Currently used by qcow2 and needed by qed in a follow-on patch.
>
> Signed-off-by: Stefan Hajnoczi<stefanha@linux.vnet.ibm.com>
>
Acked-by: Anthony Liguori <aliguori@us.ibm.com>
Regards,
Anthony Liguori
> ---
> block/qcow2.c | 22 ----------------------
> cutils.c | 18 ++++++++++++++++++
> qemu-common.h | 1 +
> 3 files changed, 19 insertions(+), 22 deletions(-)
>
> diff --git a/block/qcow2.c b/block/qcow2.c
> index ee3481b..6e25812 100644
> --- a/block/qcow2.c
> +++ b/block/qcow2.c
> @@ -794,28 +794,6 @@ static int qcow2_change_backing_file(BlockDriverState *bs,
> return qcow2_update_ext_header(bs, backing_file, backing_fmt);
> }
>
> -static int get_bits_from_size(size_t size)
> -{
> - int res = 0;
> -
> - if (size == 0) {
> - return -1;
> - }
> -
> - while (size != 1) {
> - /* Not a power of two */
> - if (size& 1) {
> - return -1;
> - }
> -
> - size>>= 1;
> - res++;
> - }
> -
> - return res;
> -}
> -
> -
> static int preallocate(BlockDriverState *bs)
> {
> uint64_t nb_sectors;
> diff --git a/cutils.c b/cutils.c
> index 5883737..6c32198 100644
> --- a/cutils.c
> +++ b/cutils.c
> @@ -283,3 +283,21 @@ int fcntl_setfl(int fd, int flag)
> }
> #endif
>
> +/**
> + * Get the number of bits for a power of 2
> + *
> + * The following is true for powers of 2:
> + * n == 1<< get_bits_from_size(n)
> + */
> +int get_bits_from_size(size_t size)
> +{
> + if (size == 0 || (size& (size - 1))) {
> + return -1;
> + }
> +
> +#if defined(_WIN32)&& defined(__x86_64__)
> + return __builtin_ctzll(size);
> +#else
> + return __builtin_ctzl(size);
> +#endif
> +}
> diff --git a/qemu-common.h b/qemu-common.h
> index 81aafa0..e0ca398 100644
> --- a/qemu-common.h
> +++ b/qemu-common.h
> @@ -153,6 +153,7 @@ time_t mktimegm(struct tm *tm);
> int qemu_fls(int i);
> int qemu_fdatasync(int fd);
> int fcntl_setfl(int fd, int flag);
> +int get_bits_from_size(size_t size);
>
> /* path.c */
> void init_paths(const char *prefix);
>
next prev parent reply other threads:[~2010-10-08 18:02 UTC|newest]
Thread overview: 72+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-08 15:48 [Qemu-devel] [PATCH v2 0/7] qed: Add QEMU Enhanced Disk format Stefan Hajnoczi
2010-10-08 15:48 ` [Qemu-devel] [PATCH v2 1/7] qcow2: Make get_bits_from_size() common Stefan Hajnoczi
2010-10-08 18:01 ` Anthony Liguori [this message]
2010-10-08 15:48 ` [Qemu-devel] [PATCH v2 2/7] cutils: Add bytes_to_str() to format byte values Stefan Hajnoczi
2010-10-11 11:09 ` [Qemu-devel] " Kevin Wolf
2010-10-13 9:15 ` [Qemu-devel] " Markus Armbruster
2010-10-13 9:28 ` Kevin Wolf
2010-10-13 10:58 ` Stefan Hajnoczi
2010-10-13 10:25 ` [Qemu-devel] " Avi Kivity
2010-10-08 15:48 ` [Qemu-devel] [PATCH v2 3/7] docs: Add QED image format specification Stefan Hajnoczi
2010-10-10 9:20 ` [Qemu-devel] " Avi Kivity
2010-10-11 10:09 ` Stefan Hajnoczi
2010-10-11 13:04 ` Avi Kivity
2010-10-11 13:42 ` Stefan Hajnoczi
2010-10-11 13:44 ` Avi Kivity
2010-10-11 14:06 ` Stefan Hajnoczi
2010-10-11 14:12 ` Avi Kivity
2010-10-11 15:02 ` Anthony Liguori
2010-10-11 15:24 ` Avi Kivity
2010-10-11 15:41 ` Anthony Liguori
2010-10-11 15:47 ` Avi Kivity
2010-10-11 14:54 ` Anthony Liguori
2010-10-11 14:58 ` Avi Kivity
2010-10-11 15:49 ` Anthony Liguori
2010-10-11 16:02 ` Avi Kivity
2010-10-11 16:10 ` Anthony Liguori
2010-10-12 10:25 ` Avi Kivity
2010-10-11 13:58 ` Kevin Wolf
2010-10-11 15:30 ` Stefan Hajnoczi
2010-10-11 15:39 ` Avi Kivity
2010-10-11 15:46 ` Stefan Hajnoczi
2010-10-11 16:18 ` Anthony Liguori
2010-10-11 17:14 ` Anthony Liguori
2010-10-12 8:07 ` Kevin Wolf
2010-10-12 13:16 ` Stefan Hajnoczi
2010-10-12 13:32 ` Anthony Liguori
2010-10-11 15:50 ` Kevin Wolf
2010-10-08 15:48 ` [Qemu-devel] [PATCH v2 4/7] qed: Add QEMU Enhanced Disk image format Stefan Hajnoczi
2010-10-11 15:16 ` [Qemu-devel] " Kevin Wolf
2010-10-08 15:48 ` [Qemu-devel] [PATCH v2 5/7] qed: Table, L2 cache, and cluster functions Stefan Hajnoczi
2010-10-12 14:44 ` [Qemu-devel] " Kevin Wolf
2010-10-13 13:41 ` Stefan Hajnoczi
2010-10-08 15:48 ` [Qemu-devel] [PATCH v2 6/7] qed: Read/write support Stefan Hajnoczi
2010-10-10 9:10 ` [Qemu-devel] " Avi Kivity
2010-10-11 10:37 ` Stefan Hajnoczi
2010-10-11 13:10 ` Avi Kivity
2010-10-11 13:55 ` Stefan Hajnoczi
2010-10-11 14:57 ` Anthony Liguori
2010-10-12 15:08 ` Kevin Wolf
2010-10-12 15:22 ` Anthony Liguori
2010-10-12 15:39 ` Kevin Wolf
2010-10-12 15:59 ` Stefan Hajnoczi
2010-10-12 16:16 ` Anthony Liguori
2010-10-12 16:21 ` Avi Kivity
2010-10-13 12:13 ` Stefan Hajnoczi
2010-10-13 13:07 ` Kevin Wolf
2010-10-13 13:24 ` Anthony Liguori
2010-10-13 13:50 ` Avi Kivity
2010-10-13 14:07 ` Stefan Hajnoczi
2010-10-13 14:08 ` Anthony Liguori
2010-10-13 14:10 ` Avi Kivity
2010-10-13 14:11 ` Anthony Liguori
2010-10-13 14:16 ` Avi Kivity
2010-10-13 14:53 ` Anthony Liguori
2010-10-13 15:08 ` Avi Kivity
2010-10-13 15:42 ` Anthony Liguori
2010-10-14 11:06 ` Stefan Hajnoczi
2010-10-13 14:10 ` Anthony Liguori
2010-10-08 15:48 ` [Qemu-devel] [PATCH v2 7/7] qed: Consistency check support Stefan Hajnoczi
2010-10-11 13:21 ` [Qemu-devel] Re: [PATCH v2 0/7] qed: Add QEMU Enhanced Disk format Kevin Wolf
2010-10-11 15:37 ` Stefan Hajnoczi
2010-10-16 7:51 ` [Qemu-devel] " Stefan Hajnoczi
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=4CAF5C8C.6090805@linux.vnet.ibm.com \
--to=aliguori@linux.vnet.ibm.com \
--cc=avi@redhat.com \
--cc=hch@lst.de \
--cc=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@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.