Whamcloud - gitweb
b=20563 libcfs_cfs_curproc_is_32bit() function
authorpravin <Pravin.Shelar@Sun.COM>
Thu, 24 Jun 2010 21:13:16 +0000 (02:43 +0530)
committerJohann Lombardi <johann@sun.com>
Thu, 24 Jun 2010 15:57:59 +0000 (17:57 +0200)
i=johann
i=rahul

adds function cfs_curproc_is_32bit() to check compatibility.

lnet/autoconf/lustre-lnet.m4
lnet/include/libcfs/curproc.h
lnet/libcfs/linux/linux-curproc.c

index 855baf3..4b138d6 100644 (file)
@@ -1535,6 +1535,26 @@ LB_LINUX_TRY_COMPILE([
 ])
 
 #
+# LN_HAVE_IS_COMPAT_TASK
+#
+# Added in 2.6.17, it wasn't until 2.6.29 that all
+# Linux architectures have is_compat_task()
+#
+AC_DEFUN([LN_HAVE_IS_COMPAT_TASK],
+[AC_MSG_CHECKING([if is_compat_task() is declared])
+LB_LINUX_TRY_COMPILE([
+        #include <linux/compat.h>
+],[
+        int i = is_compat_task();
+],[
+        AC_MSG_RESULT([yes])
+        AC_DEFINE(HAVE_IS_COMPAT_TASK, 1, [is_compat_task() is available])
+],[
+        AC_MSG_RESULT([no])
+])
+])
+
+#
 # LN_PROG_LINUX
 #
 # LNet linux kernel checks
@@ -1568,6 +1588,7 @@ LN_LE_TYPES
 LN_TASK_RCU
 # 2.6.18
 LN_TASKLIST_LOCK
+LN_HAVE_IS_COMPAT_TASK
 # 2.6.19
 LN_KMEM_CACHE_DESTROY_INT
 LN_ATOMIC_PANIC_NOTIFIER
index 38492a9..e7aa3a8 100644 (file)
@@ -76,6 +76,9 @@ char  *cfs_curproc_comm(void);
 
 typedef __u32 cfs_cap_t;
 
+/* check if task is running in compat mode.*/
+int cfs_curproc_is_32bit(void);
+
 #define CFS_CAP_CHOWN                   0
 #define CFS_CAP_DAC_OVERRIDE            1
 #define CFS_CAP_DAC_READ_SEARCH         2
index 7282b86..5f1201c 100644 (file)
@@ -42,6 +42,8 @@
 
 #include <linux/sched.h>
 #include <linux/fs_struct.h>
+#include <linux/compat.h>
+#include <linux/thread_info.h>
 
 #define DEBUG_SUBSYSTEM S_LNET
 
@@ -207,6 +209,22 @@ int cfs_capable(cfs_cap_t cap)
         return capable(cfs_cap_unpack(cap));
 }
 
+/* Check if task is running in 32-bit API mode, for the purpose of
+ * userspace binary interfaces.  On 32-bit Linux this is (unfortunately)
+ * always true, even if the application is using LARGEFILE64 and 64-bit
+ * APIs, because Linux provides no way for the filesystem to know if it
+ * is called via 32-bit or 64-bit APIs.  Other clients may vary.  On
+ * 64-bit systems, this will only be true if the binary is calling a
+ * 32-bit system call. */
+int cfs_curproc_is_32bit(void)
+{
+#ifdef HAVE_IS_COMPAT_TASK
+        return is_compat_task();
+#else
+        return (BITS_PER_LONG == 32);
+#endif
+}
+
 EXPORT_SYMBOL(cfs_curproc_uid);
 EXPORT_SYMBOL(cfs_curproc_pid);
 EXPORT_SYMBOL(cfs_curproc_euid);
@@ -227,6 +245,7 @@ EXPORT_SYMBOL(cfs_kernel_cap_unpack);
 EXPORT_SYMBOL(cfs_curproc_cap_pack);
 EXPORT_SYMBOL(cfs_curproc_cap_unpack);
 EXPORT_SYMBOL(cfs_capable);
+EXPORT_SYMBOL(cfs_curproc_is_32bit);
 
 /*
  * Local variables: