Set cwd to '/' for the process executing insmod.

Ricardo has pointed out that under Solaris the cwd is set to '/'
during module load, while under Linux it is set to the callers cwd.
To handle this cleanly I've reworked the module *_init()/_exit()
macros so they call a *_setup()/_cleanup() function when any SPL
dependent module is loaded or unloaded.  This gives us a chance to
perform any needed modification of the process, in this case changing
the cwd.  It also handily provides a way to avoid creating wrapper
init()/exit() functions because the Solaris and Linux prototypes
differ slightly.  All dependent modules should now call the spl
helper macros spl_module_{init,exit}() instead of the native linux
versions.

Unfortunately, it appears that under Linux there has been no consistent
API in the kernel to set the cwd in a module.  Because of this I have
had to add more autoconf magic than I'd like.  However, what I have
done is correct and has been tested on RHEL5, SLES11, FC11, and CHAOS
kernels.

In addition, I have change the rootdir type from a 'void *' to the
correct 'vnode_t *' type.  And I've set rootdir to a non-NULL value.
This commit is contained in:
Brian Behlendorf
2009-10-01 16:06:15 -07:00
parent 0e77fc118e
commit 51a727e90f
10 changed files with 404 additions and 8 deletions
+33
View File
@@ -64,6 +64,8 @@ AC_DEFUN([SPL_AC_CONFIG_KERNEL], [
SPL_AC_ZONE_STAT_ITEM_INACTIVE
SPL_AC_ZONE_STAT_ITEM_ACTIVE
SPL_AC_GET_ZONE_COUNTS
SPL_AC_SET_FS_PWD
SPL_AC_2ARGS_SET_FS_PWD
SPL_AC_2ARGS_VFS_UNLINK
SPL_AC_4ARGS_VFS_RENAME
SPL_AC_CRED_STRUCT
@@ -1203,6 +1205,37 @@ AC_DEFUN([SPL_AC_GET_ZONE_COUNTS], [
])
])
dnl #
dnl # Symbol available in RHEL kernels not in stock kernels.
dnl #
AC_DEFUN([SPL_AC_SET_FS_PWD], [
SPL_CHECK_SYMBOL_EXPORT(
[set_fs_pwd],
[],
[AC_DEFINE(HAVE_SET_FS_PWD, 1,
[set_fs_pwd() is available])],
[])
])
dnl #
dnl # 2.6.25 API change,
dnl # Simplied API by replacing mnt+dentry args with a single path arg.
dnl #
AC_DEFUN([SPL_AC_2ARGS_SET_FS_PWD],
[AC_MSG_CHECKING([whether set_fs_pwd() wants 2 args])
SPL_LINUX_TRY_COMPILE([
#include <linux/sched.h>
],[
set_fs_pwd(NULL, NULL);
],[
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_2ARGS_SET_FS_PWD, 1,
[set_fs_pwd() wants 2 args])
],[
AC_MSG_RESULT(no)
])
])
dnl #
dnl # SLES API change, never adopted in mainline,
dnl # Third 'struct vfsmount *' argument removed.