]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Compile cityhash code into libzfs
authorMatthew Ahrens <mahrens@delphix.com>
Fri, 27 Mar 2020 16:11:22 +0000 (09:11 -0700)
committerGitHub <noreply@github.com>
Fri, 27 Mar 2020 16:11:22 +0000 (09:11 -0700)
Make the cityhash code compile into libzfs, in preparation for the new
"zstream" command.

Reviewed-by: Paul Dagnelie <pcd@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
Closes #10152

12 files changed:
include/Makefile.am
include/cityhash.h [new file with mode: 0644]
include/sys/Makefile.am
include/sys/cityhash.h [deleted file]
lib/libzfs/Makefile.am
module/zcommon/Makefile.in
module/zcommon/cityhash.c [new file with mode: 0644]
module/zfs/Makefile.in
module/zfs/arc.c
module/zfs/cityhash.c [deleted file]
module/zfs/dbuf.c
module/zfs/zio.c

index 5b37dc765d26d50b12d5d9a8257c12518133ecb3..9591d44239dd47e34685c6b4ef9015816223faa1 100644 (file)
@@ -1,6 +1,7 @@
 SUBDIRS = sys os
 
 COMMON_H = \
+       $(top_srcdir)/include/cityhash.h \
        $(top_srcdir)/include/zfeature_common.h \
        $(top_srcdir)/include/zfs_comutil.h \
        $(top_srcdir)/include/zfs_deleg.h \
diff --git a/include/cityhash.h b/include/cityhash.h
new file mode 100644 (file)
index 0000000..33c3b7b
--- /dev/null
@@ -0,0 +1,41 @@
+// Copyright (c) 2011 Google, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+
+/*
+ * Copyright (c) 2017 by Delphix. All rights reserved.
+ */
+
+#ifndef        _SYS_CITYHASH_H
+#define        _SYS_CITYHASH_H
+
+#include <sys/zfs_context.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+uint64_t cityhash4(uint64_t, uint64_t, uint64_t, uint64_t);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SYS_CITYHASH_H */
index bcfa12fca4b23a302a01713c6f62052742b1e4fc..82165170a386cc01b3f80cd565b0fe0b8071a8b6 100644 (file)
@@ -14,7 +14,6 @@ COMMON_H = \
        $(top_srcdir)/include/sys/bptree.h \
        $(top_srcdir)/include/sys/btree.h \
        $(top_srcdir)/include/sys/bqueue.h \
-       $(top_srcdir)/include/sys/cityhash.h \
        $(top_srcdir)/include/sys/dataset_kstats.h \
        $(top_srcdir)/include/sys/dbuf.h \
        $(top_srcdir)/include/sys/ddt.h \
diff --git a/include/sys/cityhash.h b/include/sys/cityhash.h
deleted file mode 100644 (file)
index 33c3b7b..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright (c) 2011 Google, Inc.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-
-/*
- * Copyright (c) 2017 by Delphix. All rights reserved.
- */
-
-#ifndef        _SYS_CITYHASH_H
-#define        _SYS_CITYHASH_H
-
-#include <sys/zfs_context.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-uint64_t cityhash4(uint64_t, uint64_t, uint64_t, uint64_t);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _SYS_CITYHASH_H */
index da42307bb6fbeb69b67579e065bf1ef2700da395..2747a7e9b3e38a8f5b4c77d83b1d6b813663778d 100644 (file)
@@ -38,6 +38,7 @@ endif
 
 KERNEL_C = \
        algs/sha2/sha2.c \
+       cityhash.c \
        zfeature_common.c \
        zfs_comutil.c \
        zfs_deleg.c \
index b2e34f2e9339feb1d3fea1768bf94ef2f8e82127..01e0692ebddf264234149e135e7530e27f6895cc 100644 (file)
@@ -11,6 +11,7 @@ ccflags-y := $(ZFS_MODULE_CFLAGS) $(ZFS_MODULE_CPPFLAGS)
 # Suppress unused-value warnings in sparc64 architecture headers
 ccflags-$(CONFIG_SPARC64) += -Wno-unused-value
 
+$(MODULE)-objs += cityhash.o
 $(MODULE)-objs += zfeature_common.o
 $(MODULE)-objs += zfs_comutil.o
 $(MODULE)-objs += zfs_deleg.o
diff --git a/module/zcommon/cityhash.c b/module/zcommon/cityhash.c
new file mode 100644 (file)
index 0000000..413a96d
--- /dev/null
@@ -0,0 +1,67 @@
+// Copyright (c) 2011 Google, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+/*
+ * Copyright (c) 2017 by Delphix. All rights reserved.
+ */
+
+#include <cityhash.h>
+
+#define        HASH_K1 0xb492b66fbe98f273ULL
+#define        HASH_K2 0x9ae16a3b2f90404fULL
+
+/*
+ * Bitwise right rotate.  Normally this will compile to a single
+ * instruction.
+ */
+static inline uint64_t
+rotate(uint64_t val, int shift)
+{
+       // Avoid shifting by 64: doing so yields an undefined result.
+       return (shift == 0 ? val : (val >> shift) | (val << (64 - shift)));
+}
+
+static inline uint64_t
+cityhash_helper(uint64_t u, uint64_t v, uint64_t mul)
+{
+       uint64_t a = (u ^ v) * mul;
+       a ^= (a >> 47);
+       uint64_t b = (v ^ a) * mul;
+       b ^= (b >> 47);
+       b *= mul;
+       return (b);
+}
+
+uint64_t
+cityhash4(uint64_t w1, uint64_t w2, uint64_t w3, uint64_t w4)
+{
+       uint64_t mul = HASH_K2 + 64;
+       uint64_t a = w1 * HASH_K1;
+       uint64_t b = w2;
+       uint64_t c = w4 * mul;
+       uint64_t d = w3 * HASH_K2;
+       return (cityhash_helper(rotate(a + b, 43) + rotate(c, 30) + d,
+           a + rotate(b + HASH_K2, 18) + c, mul));
+
+}
+
+#if defined(_KERNEL)
+EXPORT_SYMBOL(cityhash4);
+#endif
index 1ba7db27b96e9d2bd3175439db3502bc453cf513..6737336caef946183f28863082bc4fc91b354b6f 100644 (file)
@@ -22,7 +22,6 @@ $(MODULE)-objs += bpobj.o
 $(MODULE)-objs += bptree.o
 $(MODULE)-objs += btree.o
 $(MODULE)-objs += bqueue.o
-$(MODULE)-objs += cityhash.o
 $(MODULE)-objs += dataset_kstats.o
 $(MODULE)-objs += dbuf.o
 $(MODULE)-objs += dbuf_stats.o
index 6c9164f76bcb7fd3d2a678d0cc543663839b8362..c6b194183f2e417b8c15eaa012a59368a47ae126 100644 (file)
 #include <sys/arc_impl.h>
 #include <sys/trace_zfs.h>
 #include <sys/aggsum.h>
-#include <sys/cityhash.h>
+#include <cityhash.h>
 
 #ifndef _KERNEL
 /* set with ZFS_DEBUG=watch, to enable watchpoints on frozen buffers */
diff --git a/module/zfs/cityhash.c b/module/zfs/cityhash.c
deleted file mode 100644 (file)
index 2b62eda..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright (c) 2011 Google, Inc.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-/*
- * Copyright (c) 2017 by Delphix. All rights reserved.
- */
-
-#include <sys/cityhash.h>
-
-#define        HASH_K1 0xb492b66fbe98f273ULL
-#define        HASH_K2 0x9ae16a3b2f90404fULL
-
-/*
- * Bitwise right rotate.  Normally this will compile to a single
- * instruction.
- */
-static inline uint64_t
-rotate(uint64_t val, int shift)
-{
-       // Avoid shifting by 64: doing so yields an undefined result.
-       return (shift == 0 ? val : (val >> shift) | (val << (64 - shift)));
-}
-
-static inline uint64_t
-cityhash_helper(uint64_t u, uint64_t v, uint64_t mul)
-{
-       uint64_t a = (u ^ v) * mul;
-       a ^= (a >> 47);
-       uint64_t b = (v ^ a) * mul;
-       b ^= (b >> 47);
-       b *= mul;
-       return (b);
-}
-
-uint64_t
-cityhash4(uint64_t w1, uint64_t w2, uint64_t w3, uint64_t w4)
-{
-       uint64_t mul = HASH_K2 + 64;
-       uint64_t a = w1 * HASH_K1;
-       uint64_t b = w2;
-       uint64_t c = w4 * mul;
-       uint64_t d = w3 * HASH_K2;
-       return (cityhash_helper(rotate(a + b, 43) + rotate(c, 30) + d,
-           a + rotate(b + HASH_K2, 18) + c, mul));
-
-}
index d7f5e1ee32ec5dfc7dc87254530d167e3e60367e..be6a76830af394de43488d0de8bea4809b84f79b 100644 (file)
@@ -48,7 +48,7 @@
 #include <sys/callb.h>
 #include <sys/abd.h>
 #include <sys/vdev.h>
-#include <sys/cityhash.h>
+#include <cityhash.h>
 #include <sys/spa_impl.h>
 
 kstat_t *dbuf_ksp;
index de2e8e767200695a9677c9a43a4f9f12ad623273..b9a3ddcf237e909e5391522ab4a507b0e7eb2680 100644 (file)
@@ -47,7 +47,7 @@
 #include <sys/trace_zfs.h>
 #include <sys/abd.h>
 #include <sys/dsl_crypt.h>
-#include <sys/cityhash.h>
+#include <cityhash.h>
 
 /*
  * ==========================================================================