From: Przemyslaw Iskra <sparky@pld-linux.org>
To: lvm-devel@redhat.com
Subject: [PATCH] Fix liblvm2cmd.so linking order for --as-needed builds
Date: Tue, 12 Oct 2010 17:15:24 +0200 [thread overview]
Message-ID: <20101012151524.GA6280@pld-linux.org> (raw)
In-Reply-To: <4CB4775B.2000009@redhat.com>
On Tue, Oct 12, 2010 at 04:57:31PM +0200, Zdenek Kabelac wrote:
> Hmm - ok - I'll need to take a look on this.
The Makefile should be fixed, but...
Why not just drop floor() usage (which is misused anyways) ?
Without it the whole -lm won't be needed.
I've sent a patch for this some time ago, resending it here.
[May be a bit outdated if configure.in changed]
--
____ Sparky{PI] -- Przemyslaw _ ___ _ _ ......... LANG...Pl,Ca,Es,En
/____) ___ ___ _ _ || Iskra | | _ \| | | : WWW...ppcrcd.pld-linux.org
\____\| -_)'___| ||^'||//\\// < | _/| | | : WWW2..............rsget.pl
(____/|| (_-_|_|| ||\\ || |_ |_| |_| _| : Mail..sparky@pld-linux.org
-------------- next part --------------
>From ab3a151bdae8566fddbd91cdc86c600083890f59 Mon Sep 17 00:00:00 2001
From: Przemyslaw Iskra <sparky@pld-linux.org>
Date: Fri, 30 Jul 2010 18:45:43 +0200
Subject: [PATCH] Don't use floor() in _bitset_with_random_bits
Use _even_rand() function instead of floor() in
_bitset_with_random_bits(). floor() function is missing in dietlibc (on
architectures other than x86). Moreover using floor() to clip rand
results does not assure even result distribution.
_even_rand() uses integer arithmetic only and is designed to return evenly
distributed results.
Signed-off-by: Przemyslaw Iskra <sparky@pld-linux.org>
---
configure.in | 3 +--
lib/metadata/metadata.c | 16 +++++++++++++++-
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/configure.in b/configure.in
index bd56136..6f6c67e 100644
--- a/configure.in
+++ b/configure.in
@@ -125,8 +125,7 @@ AC_STRUCT_TM
################################################################################
dnl -- Check for functions
-AC_SEARCH_LIBS([floor], [m], , [AC_MSG_ERROR(bailing out)])
-AC_CHECK_FUNCS([floor ftruncate gethostname getpagesize \
+AC_CHECK_FUNCS([ftruncate gethostname getpagesize \
gettimeofday memset mkdir mkfifo rmdir munmap nl_langinfo setenv setlocale \
strcasecmp strchr strcspn strspn strdup strncasecmp strerror strrchr \
strstr strtol strtoul uname], , [AC_MSG_ERROR(bailing out)])
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 07222a7..6ee7731 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -1018,6 +1018,20 @@ static int _recalc_extents(uint32_t *extents, const char *desc1,
return 1;
}
+/* return random integer in [0,max) interval */
+static unsigned _even_rand( unsigned *seed, unsigned max )
+{
+ unsigned r, ret;
+
+ /* make sure distribution is even */
+ do {
+ r = (unsigned) rand_r( seed );
+ ret = r % max;
+ } while ( r - ret > RAND_MAX - max );
+
+ return ret;
+}
+
static dm_bitset_t _bitset_with_random_bits(struct dm_pool *mem, uint32_t num_bits,
uint32_t num_set_bits, unsigned *seed)
{
@@ -1040,7 +1054,7 @@ static dm_bitset_t _bitset_with_random_bits(struct dm_pool *mem, uint32_t num_bi
/* Perform loop num_set_bits times, selecting one bit each time */
while (i++ < num_bits) {
/* Select a random bit between 0 and (i-1) inclusive. */
- bit_selected = (unsigned) floor(i * (rand_r(seed) / (RAND_MAX + 1.0)));
+ bit_selected = _even_rand( seed, i );
/*
* If the bit was already set, set the new bit that became
--
1.7.1
next prev parent reply other threads:[~2010-10-12 15:15 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-01 15:35 [PATCH] Fix liblvm2cmd.so linking order for --as-needed builds Diego Elio Pettenò
2010-10-12 13:55 ` Zdenek Kabelac
2010-10-12 14:26 ` Diego Elio Pettenò
2010-10-12 14:57 ` Zdenek Kabelac
2010-10-12 15:15 ` Przemyslaw Iskra [this message]
2010-10-15 9:50 ` Zdenek Kabelac
2010-11-30 10:31 ` Zdenek Kabelac
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=20101012151524.GA6280@pld-linux.org \
--to=sparky@pld-linux.org \
--cc=lvm-devel@redhat.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.