From: Tom Wu <tomwu@nvidia.com>
Subject: [PATCH] BACKPORT: net/sunrpc/xprtrdma/svc_rdma.c

Change-Id: Ib08f3d405ce2fcf23dd9260c4f4b5c2723f54f84
Signed-off-by: Tom Wu <tomwu@nvidia.com>
---
 net/sunrpc/xprtrdma/svc_rdma.c | 45 +++++++++++++++++++++++++++++++++-
 1 file changed, 44 insertions(+), 1 deletion(-)

--- a/net/sunrpc/xprtrdma/svc_rdma.c
+++ b/net/sunrpc/xprtrdma/svc_rdma.c
@@ -74,8 +74,16 @@ enum {
 	SVCRDMA_COUNTER_BUFSIZ	= sizeof(unsigned long long),
 };
 
+#ifdef HAVE_PROC_HANDLER_CONST_PARAM
+static int svcrdma_counter_handler(const struct ctl_table *table, int write,
+#else
 static int svcrdma_counter_handler(struct ctl_table *table, int write,
+#endif
+#ifdef HAVE_CGROUP_BPF_RUN_FILTER_SYSCTL_7_PARAMETERS
 				   void *buffer, size_t *lenp, loff_t *ppos)
+#else
+				   void __user *buffer, size_t *lenp, loff_t *ppos)
+#endif
 {
 	struct percpu_counter *stat = (struct percpu_counter *)table->data;
 	char tmp[SVCRDMA_COUNTER_BUFSIZ + 1];
@@ -98,8 +106,13 @@ static int svcrdma_counter_handler(struc
 	len -= *ppos;
 	if (len > *lenp)
 		len = *lenp;
+#ifdef HAVE_CGROUP_BPF_RUN_FILTER_SYSCTL_7_PARAMETERS
 	if (len)
 		memcpy(buffer, tmp, len);
+#else
+	if (len && copy_to_user(buffer, tmp, len))
+		return -EFAULT;
+#endif
 	*lenp = len;
 	*ppos += len;
 
@@ -212,6 +225,26 @@ static struct ctl_table svcrdma_parm_tab
 	{ },
 };
 
+#ifdef HAVE_CTL_TABLE_CHILD
+static struct ctl_table svcrdma_table[] = {
+	{
+		.procname	= "svc_rdma",
+		.mode		= 0555,
+		.child		= svcrdma_parm_table
+	},
+	{ },
+};
+
+static struct ctl_table svcrdma_root_table[] = {
+	{
+		.procname	= "sunrpc",
+		.mode		= 0555,
+		.child		= svcrdma_table
+	},
+	{ },
+};
+#endif
+
 static void svc_rdma_proc_cleanup(void)
 {
 	if (!svcrdma_table_header)
@@ -245,8 +278,12 @@ static int svc_rdma_proc_init(void)
 	if (rc)
 		goto out_err;
 
+#ifdef HAVE_CTL_TABLE_CHILD
+	svcrdma_table_header = register_sysctl_table(svcrdma_root_table);
+#else
 	svcrdma_table_header = register_sysctl("sunrpc/svc_rdma",
-					       svcrdma_parm_table);
+						svcrdma_parm_table);
+#endif
 	return 0;
 
 out_err:
@@ -260,6 +297,9 @@ struct workqueue_struct *svcrdma_wq;
 
 void svc_rdma_cleanup(void)
 {
+#if defined(CONFIG_SUNRPC_BACKCHANNEL) && defined(HAVE_RPC_XPRT_OPS_BC_UP)
+	svc_unreg_xprt_class(&svc_rdma_bc_class);
+#endif
 	svc_unreg_xprt_class(&svc_rdma_class);
 	svc_rdma_proc_cleanup();
 	if (svcrdma_wq) {
@@ -289,6 +329,9 @@ int svc_rdma_init(void)
 
 	svcrdma_wq = wq;
 	svc_reg_xprt_class(&svc_rdma_class);
+#if defined(CONFIG_SUNRPC_BACKCHANNEL) && defined(HAVE_RPC_XPRT_OPS_BC_UP)
+	svc_reg_xprt_class(&svc_rdma_bc_class);
+#endif
 
 	dprintk("SVCRDMA Module Init, register RPC RDMA transport\n");
 	dprintk("\tsvcrdma_ord      : %d\n", svcrdma_ord);
