From a54718cfe0d8e8a4b124f176f0d5c94141f9aea0 Mon Sep 17 00:00:00 2001
From: Richard Yao <ryao@cs.stonybrook.edu>
Date: Mon, 4 Mar 2013 00:24:04 -0500
Subject: [PATCH] Linux 3.9 compat: set_fs_root takes const struct path *

torvalds/linux@dcf787f39162ce32ca325b3e784aba2d2444619a enforces
const-correctness in passing struct path *.

Signed-off-by: Richard Yao <ryao@cs.stonybrook.edu>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
---
 config/spl-build.m4    | 44 ++++++++++++++++++++++++++++++++++++++++++
 module/spl/spl-vnode.c |  4 ++++
 2 files changed, 48 insertions(+)

diff --git a/config/spl-build.m4 b/config/spl-build.m4
index 83cefabd42..6a8e658a20 100644
--- a/config/spl-build.m4
+++ b/config/spl-build.m4
@@ -64,6 +64,7 @@ AC_DEFUN([SPL_AC_CONFIG_KERNEL], [
 	SPL_AC_USER_PATH_DIR
 	SPL_AC_SET_FS_PWD
 	SPL_AC_2ARGS_SET_FS_PWD
+	SPL_AC_SET_FS_PWD_WITH_CONST
 	SPL_AC_2ARGS_VFS_UNLINK
 	SPL_AC_4ARGS_VFS_RENAME
 	SPL_AC_VFS_FSYNC
@@ -1686,11 +1687,54 @@ AC_DEFUN([SPL_AC_2ARGS_SET_FS_PWD],
 		AC_MSG_RESULT(yes)
 		AC_DEFINE(HAVE_2ARGS_SET_FS_PWD, 1,
 		          [set_fs_pwd() wants 2 args])
+		HAVE_2ARGS_SET_FS_PWD=yes
 	],[
 		AC_MSG_RESULT(no)
 	])
 ])
 
+dnl #
+dnl # 3.9 API change
+dnl # set_fs_pwd takes const struct path *
+dnl #
+AC_DEFUN([SPL_AC_SET_FS_PWD_WITH_CONST],
+if test "x$HAVE_2ARGS_SET_FS_PWD" = xyes; then
+	tmp_flags="$EXTRA_KCFLAGS"
+	EXTRA_KCFLAGS="-Werror"
+	[AC_MSG_CHECKING([whether set_fs_pwd() requires const struct path *])
+	SPL_LINUX_TRY_COMPILE([
+		#include <linux/spinlock.h>
+		#include <linux/fs_struct.h>
+		#include <linux/path.h>
+		void (*const set_fs_pwd_func)
+			(struct fs_struct *, const struct path *)
+			= set_fs_pwd;
+	],[
+		return 0;
+	],[
+		AC_MSG_RESULT(yes)
+		AC_DEFINE(HAVE_SET_FS_PWD_WITH_CONST, 1,
+			[set_fs_pwd() needs const path *])
+	],[
+		SPL_LINUX_TRY_COMPILE([
+			#include <linux/spinlock.h>
+			#include <linux/fs_struct.h>
+			#include <linux/path.h>
+			void (*const set_fs_pwd_func)
+				(struct fs_struct *, struct path *)
+				= set_fs_pwd;
+		],[
+			return 0;
+		],[
+			AC_MSG_RESULT(no)
+		],[
+			AC_MSG_ERROR(unknown)
+		])
+	])
+	EXTRA_KCFLAGS="$tmp_flags"
+fi
+])
+
 dnl #
 dnl # SLES API change, never adopted in mainline,
 dnl # Third 'struct vfsmount *' argument removed.
diff --git a/module/spl/spl-vnode.c b/module/spl/spl-vnode.c
index e264fba050..dac452c10e 100644
--- a/module/spl/spl-vnode.c
+++ b/module/spl/spl-vnode.c
@@ -840,7 +840,11 @@ EXPORT_SYMBOL(releasef);
 # ifdef HAVE_2ARGS_SET_FS_PWD
 /* Used from 2.6.25 - 2.6.31+ */
 void
+#  ifdef HAVE_SET_FS_PWD_WITH_CONST
+set_fs_pwd(struct fs_struct *fs, const struct path *path)
+#  else
 set_fs_pwd(struct fs_struct *fs, struct path *path)
+#  endif
 {
 	struct path old_pwd;