From a186aded74ca302c5dc4cc0b690681a255ace97b Mon Sep 17 00:00:00 2001
From: Olaf Faaland <faaland1@llnl.gov>
Date: Wed, 22 Feb 2017 17:53:56 -0800
Subject: [PATCH] linux 4.11 compat: avoid refcount_t name conflict

Linux 4.11 introduces a new type, refcount_t, which conflicts with the
type of the same name defined within ZFS.

Since the ZFS code never refers to the linux type, the ZFS type can be
renamed.

Rather than touching all the ZFS code that uses refcount_t, rename the
type at compile time to zfs_refcount_t via a #define macro.

Fixes https://github.com/zfsonlinux/zfs/issues/5823

Signed-off-by: Olaf Faaland <faaland1@llnl.gov>
---
 include/sys/refcount.h | 33 +++++++++++++++++++++++++++++++++
 man/man8/zdb.8         |  3 ++-
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/include/sys/refcount.h b/include/sys/refcount.h
index 3f50cddb6f51..e83ef42289f0 100644
--- a/include/sys/refcount.h
+++ b/include/sys/refcount.h
@@ -49,6 +49,39 @@ typedef struct reference {
 	uint8_t *ref_removed;
 } reference_t;
 
+/*
+ * Starting with 4.11, the linux kernel defines a refcount_t type of its
+ * own.  This macro effectively renames the refcount_t type defined within
+ * zfs so that it does not conflict, without requiring that the name of the
+ * type be changed within the ZFS code.  It also renames the functions
+ * that operate on the type as some of their names likely also conflict, and
+ * doing this for all cases makes it clearer to anyone changing the interface
+ * in the future.
+ */
+
+#define  refcount_t                   zfs_refcount_t
+
+#define  refcount_add                 zfs_refcount_add
+#define  refcount_add_many            zfs_refcount_add_many
+#define  refcount_count               zfs_refcount_count
+#define  refcount_create              zfs_refcount_create
+#define  refcount_create_tracked      zfs_refcount_create_tracked
+#define  refcount_create_untracked    zfs_refcount_create_untracked
+#define  refcount_destroy             zfs_refcount_destroy
+#define  refcount_destroy_many        zfs_refcount_destroy_many
+#define  refcount_fini                zfs_refcount_fini
+#define  refcount_held                zfs_refcount_held
+#define  refcount_init                zfs_refcount_init
+#define  refcount_is_zero             zfs_refcount_is_zero
+#define  refcount_not_held            zfs_refcount_not_held
+#define  refcount_remove              zfs_refcount_remove
+#define  refcount_remove_many         zfs_refcount_remove_many
+#define  refcount_transfer            zfs_refcount_transfer
+#define  refcount_transfer_ownership  zfs_refcount_transfer_ownership
+
+/*
+ * end linux 4.11 compat
+ */
 typedef struct refcount {
 	kmutex_t rc_mtx;
 	boolean_t rc_tracked;
diff --git a/man/man8/zdb.8 b/man/man8/zdb.8
index 02137e97faa5..10833e4c683e 100644
--- a/man/man8/zdb.8
+++ b/man/man8/zdb.8
@@ -178,7 +178,8 @@ transaction type.
 .sp .6
 .RS 4n
 Read the vdev labels from the specified device. \fBzdb -l\fR will return 0 if
-valid label was found, 1 if error occured, and 2 if no valid labels were found.
+valid configuration nvlist was found, 1 if error occured, and 2 if no valid
+labels were found.
 .P
 If the \fB-u\fR option is also specified, also display the uberblocks on this
 device.