[lxc-devel] [PATCH] move fnv_64a_buf to utils.c and remove mutliple copies
Stéphane Graber
stgraber at ubuntu.com
Thu Feb 13 22:01:55 UTC 2014
On Thu, Feb 13, 2014 at 04:57:12PM -0500, S.Çağlar Onur wrote:
> Signed-off-by: S.Çağlar Onur <caglar at 10ur.org>
Acked-by: Stéphane Graber <stgraber at ubuntu.com>
> ---
> src/lxc/conf.c | 32 --------------------------------
> src/lxc/monitor.c | 25 -------------------------
> src/lxc/utils.c | 26 +++++++++++++++++++++++++-
> src/lxc/utils.h | 3 +++
> 4 files changed, 28 insertions(+), 58 deletions(-)
>
> diff --git a/src/lxc/conf.c b/src/lxc/conf.c
> index 0de189f..4336258 100644
> --- a/src/lxc/conf.c
> +++ b/src/lxc/conf.c
> @@ -1119,38 +1119,6 @@ static int setup_rootfs_pivot_root(const char *rootfs, const char *pivotdir)
> return 0;
> }
>
> -
> -/*
> - * Note: This is a verbatum copy of what is in monitor.c. We're just
> - * usint it here to generate a safe subdirectory in /dev/ for the
> - * containers /dev/
> - */
> -
> -/* Note we don't use SHA-1 here as we don't want to depend on HAVE_GNUTLS.
> - * FNV has good anti collision properties and we're not worried
> - * about pre-image resistance or one-way-ness, we're just trying to make
> - * the name unique in the 108 bytes of space we have.
> - */
> -#define FNV1A_64_INIT ((uint64_t)0xcbf29ce484222325ULL)
> -static uint64_t fnv_64a_buf(void *buf, size_t len, uint64_t hval)
> -{
> - unsigned char *bp;
> -
> - for(bp = buf; bp < (unsigned char *)buf + len; bp++)
> - {
> - /* xor the bottom with the current octet */
> - hval ^= (uint64_t)*bp;
> -
> - /* gcc optimised:
> - * multiply by the 64 bit FNV magic prime mod 2^64
> - */
> - hval += (hval << 1) + (hval << 4) + (hval << 5) +
> - (hval << 7) + (hval << 8) + (hval << 40);
> - }
> -
> - return hval;
> -}
> -
> /*
> * Check to see if a directory has something mounted on it and,
> * if it does, return the fstype.
> diff --git a/src/lxc/monitor.c b/src/lxc/monitor.c
> index 5e21dc5..ef658f5 100644
> --- a/src/lxc/monitor.c
> +++ b/src/lxc/monitor.c
> @@ -123,31 +123,6 @@ int lxc_monitor_close(int fd)
> return close(fd);
> }
>
> -/* Note we don't use SHA-1 here as we don't want to depend on HAVE_GNUTLS.
> - * FNV has good anti collision properties and we're not worried
> - * about pre-image resistance or one-way-ness, we're just trying to make
> - * the name unique in the 108 bytes of space we have.
> - */
> -#define FNV1A_64_INIT ((uint64_t)0xcbf29ce484222325ULL)
> -static uint64_t fnv_64a_buf(void *buf, size_t len, uint64_t hval)
> -{
> - unsigned char *bp;
> -
> - for(bp = buf; bp < (unsigned char *)buf + len; bp++)
> - {
> - /* xor the bottom with the current octet */
> - hval ^= (uint64_t)*bp;
> -
> - /* gcc optimised:
> - * multiply by the 64 bit FNV magic prime mod 2^64
> - */
> - hval += (hval << 1) + (hval << 4) + (hval << 5) +
> - (hval << 7) + (hval << 8) + (hval << 40);
> - }
> -
> - return hval;
> -}
> -
> int lxc_monitor_sock_name(const char *lxcpath, struct sockaddr_un *addr) {
> size_t len;
> int ret;
> diff --git a/src/lxc/utils.c b/src/lxc/utils.c
> index 90401a5..3dff104 100644
> --- a/src/lxc/utils.c
> +++ b/src/lxc/utils.c
> @@ -245,7 +245,7 @@ const char *lxc_global_config_value(const char *option_name)
> { NULL, NULL },
> };
>
> - /* placed in the thread local storage pool for non-bionic targets */
> + /* placed in the thread local storage pool for non-bionic targets */
> #ifdef HAVE_TLS
> static __thread const char *values[sizeof(options) / sizeof(options[0])] = { 0 };
> #else
> @@ -1151,3 +1151,27 @@ bool dir_exists(const char *path)
> return false;
> return S_ISDIR(sb.st_mode);
> }
> +
> +/* Note we don't use SHA-1 here as we don't want to depend on HAVE_GNUTLS.
> + * FNV has good anti collision properties and we're not worried
> + * about pre-image resistance or one-way-ness, we're just trying to make
> + * the name unique in the 108 bytes of space we have.
> + */
> +uint64_t fnv_64a_buf(void *buf, size_t len, uint64_t hval)
> +{
> + unsigned char *bp;
> +
> + for(bp = buf; bp < (unsigned char *)buf + len; bp++)
> + {
> + /* xor the bottom with the current octet */
> + hval ^= (uint64_t)*bp;
> +
> + /* gcc optimised:
> + * multiply by the 64 bit FNV magic prime mod 2^64
> + */
> + hval += (hval << 1) + (hval << 4) + (hval << 5) +
> + (hval << 7) + (hval << 8) + (hval << 40);
> + }
> +
> + return hval;
> +}
> diff --git a/src/lxc/utils.h b/src/lxc/utils.h
> index dec6526..887d54c 100644
> --- a/src/lxc/utils.h
> +++ b/src/lxc/utils.h
> @@ -272,4 +272,7 @@ inline static bool am_unpriv(void) {
> extern uid_t get_ns_uid(uid_t orig);
>
> extern bool dir_exists(const char *path);
> +
> +#define FNV1A_64_INIT ((uint64_t)0xcbf29ce484222325ULL)
> +extern inline uint64_t fnv_64a_buf(void *buf, size_t len, uint64_t hval);
> #endif
> --
> 1.8.3.2
>
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel
--
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20140213/55fce879/attachment.pgp>
More information about the lxc-devel
mailing list