linux-updates-20060811
[openafs.git] / src / afs / LINUX / osi_machdep.h
index 1ff8d59..8faca60 100644 (file)
@@ -26,6 +26,8 @@
 #define getpid() current->pid
 #ifdef STRUCT_TASK_STRUCT_HAS_REAL_PARENT
 #define getppid() current->real_parent->pid
+#elif defined(STRUCT_TASK_STRUCT_HAS_PARENT)
+#define getppid() current->parent->pid
 #else
 #define getppid() current->p_opptr->pid
 #endif
 #undef gop_lookupname
 #define gop_lookupname osi_lookupname
 
-#define osi_vnhold(v, n) do { VN_HOLD(AFSTOV(v)); } while (0)
-
-#if defined(AFS_LINUX24_ENV)
-#define VN_HOLD(V) atomic_inc(&((vnode_t *) V)->i_count)
-#else
-#define VN_HOLD(V) ((vnode_t *) V)->i_count++
-#endif
-
-#if defined(AFS_LINUX26_ENV)
-#define VN_RELE(V) iput((struct inode *) V)
-#else
-#define VN_RELE(V) osi_iput((struct inode *) V)
-#endif
-
-#define osi_AllocSmall afs_osi_Alloc
-#define osi_FreeSmall afs_osi_Free
+#define osi_vnhold(V, N) do { VN_HOLD(AFSTOV(V)); } while (0)
+#define VN_HOLD(V) osi_Assert(igrab((V)) == (V))
+#define VN_RELE(V) iput((V))
 
 #define afs_suser(x) capable(CAP_SYS_ADMIN)
 #define wakeup afs_osi_Wakeup
 
 #undef vType
-#define vType(V) ((( vnode_t *)V)->v_type & S_IFMT)
+#define vType(V) ((AFSTOV((V)))->i_mode & S_IFMT)
+#undef vSetType
+#define vSetType(V, type) AFSTOV((V))->i_mode = ((type) | (AFSTOV((V))->i_mode & ~S_IFMT))     /* preserve mode */
 
-/* IsAfsVnode relies on the fast that there is only one vnodeop table for AFS.
- * Use the same type of test as other OS's for compatibility.
- */
 #undef IsAfsVnode
-extern struct vnodeops afs_file_iops, afs_dir_iops, afs_symlink_iops;
-#define IsAfsVnode(v) (((v)->v_op == &afs_file_iops) ? 1 : \
-                       ((v)->v_op == &afs_dir_iops) ? 1 : \
-                       ((v)->v_op == &afs_symlink_iops))
+#define IsAfsVnode(V) ((V)->i_sb == afs_globalVFS)     /* test superblock instead */
 #undef SetAfsVnode
-#define SetAfsVnode(v)
+#define SetAfsVnode(V)                                 /* unnecessary */
 
 /* We often need to pretend we're in user space to get memory transfers
  * right for the kernel calls we use.
  */
+#include <asm/uaccess.h>
+
 #ifdef KERNEL_SPACE_DECL
 #undef KERNEL_SPACE_DECL
 #undef TO_USER_SPACE
@@ -120,14 +107,16 @@ extern struct vnodeops afs_file_iops, afs_dir_iops, afs_symlink_iops;
 #define TO_USER_SPACE() { _fs_space_decl = get_fs(); set_fs(get_ds()); }
 #define TO_KERNEL_SPACE() set_fs(_fs_space_decl)
 
-/* Backwards compatibilty macros - copyin/copyout are redone because macro
- * inside parentheses is not evalutated.
- */
-#define memcpy_fromfs copy_from_user
-#define memcpy_tofs copy_to_user
-#define copyin(F, T, C)  (copy_from_user ((char*)(T), (char*)(F), (C)), 0)
-#define copyinstr(F, T, C, L) (copyin(F, T, C), *(L)=strlen(T), 0)
-#define copyout(F, T, C) (copy_to_user ((char*)(T), (char*)(F), (C)), 0)
+#define copyin(F, T, C)  (copy_from_user ((char*)(T), (char*)(F), (C)) > 0 ? EFAULT : 0)
+static inline long copyinstr(char *from, char *to, int count, int *length) {
+    long tmp;
+    tmp = strncpy_from_user(to, from, count);
+    if (tmp < 0)
+            return EFAULT;
+    *length = tmp;
+    return 0;
+}
+#define copyout(F, T, C) (copy_to_user ((char*)(T), (char*)(F), (C)) > 0 ? EFAULT : 0)
 
 /* kernel print statements */
 #define printf printk
@@ -179,6 +168,12 @@ typedef struct uio {
 /* Get/set the inode in the osifile struct. */
 #define FILE_INODE(F) (F)->f_dentry->d_inode
 
+#ifdef AFS_LINUX26_ENV
+#define OSIFILE_INODE(a) FILE_INODE((a)->filp)
+#else
+#define OSIFILE_INODE(a) FILE_INODE(&(a)->file)
+#endif
+
 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
 #define NEED_IOCTL32
 #endif
@@ -193,16 +188,23 @@ extern unsigned long afs_linux_page_offset;
 /* function to help with the page offset stuff */
 #define afs_linux_page_address(page) (afs_linux_page_offset + PAGE_SIZE * (page - mem_map))
 
-#if defined(__KERNEL__) && defined(CONFIG_SMP)
-#include "../h/sched.h"
-#include "linux/wait.h"
+#if defined(__KERNEL__)
+#include <linux/version.h>
+#include <linux/sched.h>
+#include <linux/wait.h>
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
+extern struct mutex afs_global_lock;
+#else
 extern struct semaphore afs_global_lock;
+#define mutex_lock(lock) down(lock)
+#define mutex_unlock(lock) up(lock)
+#endif
 extern int afs_global_owner;
 
 #define AFS_GLOCK() \
 do { \
-        down(&afs_global_lock); \
+        mutex_lock(&afs_global_lock); \
         if (afs_global_owner) \
             osi_Panic("afs_global_lock already held by pid %d", \
                       afs_global_owner); \
@@ -216,10 +218,8 @@ do { \
     if (!ISAFS_GLOCK()) \
        osi_Panic("afs global lock not held at %s:%d", __FILE__, __LINE__); \
     afs_global_owner = 0; \
-    up(&afs_global_lock); \
+    mutex_unlock(&afs_global_lock); \
 } while (0)
-
-
 #else
 #define AFS_GLOCK()
 #define AFS_GUNLOCK()