linux26-more-updates-20040420
[openafs.git] / src / afs / LINUX / osi_machdep.h
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /*
11  * Linux implementation.
12  *
13  */
14
15 #ifndef OSI_MACHDEP_H_
16 #define OSI_MACHDEP_H_
17
18 /* Only needed for xdr.h in glibc 2.1.x */
19 #ifndef quad_t
20 #define quad_t __quad_t
21 #define u_quad_t __u_quad_t
22 #endif
23
24 #undef getuerror
25
26 #define getpid() current->pid
27 #ifdef STRUCT_TASK_STRUCT_HAS_REAL_PARENT
28 #define getppid() current->real_parent->pid
29 #else
30 #define getppid() current->p_opptr->pid
31 #endif
32
33 #ifdef RECALC_SIGPENDING_TAKES_VOID
34 #define RECALC_SIGPENDING(X) recalc_sigpending()
35 #else
36 #define RECALC_SIGPENDING(X) recalc_sigpending(X)
37 #endif
38
39 #if defined (STRUCT_TASK_STRUCT_HAS_SIGMASK_LOCK)
40 #define SIG_LOCK(X) spin_lock_irq(&X->sigmask_lock)
41 #define SIG_UNLOCK(X) spin_unlock_irq(&X->sigmask_lock)
42 #elif defined (STRUCT_TASK_STRUCT_HAS_SIGHAND)
43 #define SIG_LOCK(X) spin_lock_irq(&X->sighand->siglock)
44 #define SIG_UNLOCK(X) spin_unlock_irq(&X->sighand->siglock)
45 #else
46 #define SIG_LOCK(X) spin_lock_irq(&X->sig->siglock)
47 #define SIG_UNLOCK(X) spin_unlock_irq(&X->sig->siglock)
48 #endif
49
50
51 #define afs_hz HZ
52 #include "h/sched.h"
53 #define osi_Time() (xtime.tv_sec)
54 #define osi_GetTime(V) do_gettimeofday((V))
55
56 #undef gop_lookupname
57 #define gop_lookupname osi_lookupname
58
59 #define osi_vnhold(v, n) do { VN_HOLD(AFSTOV(v)); } while (0)
60
61 #if defined(AFS_LINUX24_ENV)
62 #define VN_HOLD(V) atomic_inc(&((vnode_t *) V)->i_count)
63 #else
64 #define VN_HOLD(V) ((vnode_t *) V)->i_count++
65 #endif
66
67 #if defined(AFS_LINUX26_ENV)
68 #define VN_RELE(V) iput((struct inode *) V)
69 #else
70 #define VN_RELE(V) osi_iput((struct inode *) V)
71 #endif
72
73 #define osi_AllocSmall afs_osi_Alloc
74 #define osi_FreeSmall afs_osi_Free
75
76 #define afs_suser(x) capable(CAP_SYS_ADMIN)
77 #define wakeup afs_osi_Wakeup
78
79 #undef vType
80 #define vType(V) ((( vnode_t *)V)->v_type & S_IFMT)
81
82 /* IsAfsVnode relies on the fast that there is only one vnodeop table for AFS.
83  * Use the same type of test as other OS's for compatibility.
84  */
85 #undef IsAfsVnode
86 extern struct vnodeops afs_file_iops, afs_dir_iops, afs_symlink_iops;
87 #define IsAfsVnode(v) (((v)->v_op == &afs_file_iops) ? 1 : \
88                         ((v)->v_op == &afs_dir_iops) ? 1 : \
89                         ((v)->v_op == &afs_symlink_iops))
90 #undef SetAfsVnode
91 #define SetAfsVnode(v)
92
93 /* We often need to pretend we're in user space to get memory transfers
94  * right for the kernel calls we use.
95  */
96 #ifdef KERNEL_SPACE_DECL
97 #undef KERNEL_SPACE_DECL
98 #undef TO_USER_SPACE
99 #undef TO_KERNEL_SPACE
100 #endif
101 #define KERNEL_SPACE_DECL mm_segment_t _fs_space_decl
102 #define TO_USER_SPACE() { _fs_space_decl = get_fs(); set_fs(get_ds()); }
103 #define TO_KERNEL_SPACE() set_fs(_fs_space_decl)
104
105 /* Backwards compatibilty macros - copyin/copyout are redone because macro
106  * inside parentheses is not evalutated.
107  */
108 #define memcpy_fromfs copy_from_user
109 #define memcpy_tofs copy_to_user
110 #define copyin(F, T, C)  (copy_from_user ((char*)(T), (char*)(F), (C)), 0)
111 #define copyinstr(F, T, C, L) (copyin(F, T, C), *(L)=strlen(T), 0)
112 #define copyout(F, T, C) (copy_to_user ((char*)(T), (char*)(F), (C)), 0)
113
114 /* kernel print statements */
115 #define printf printk
116 #define uprintf printk
117
118
119 #define PAGESIZE PAGE_SIZE
120
121 /* cred struct */
122 typedef struct cred {           /* maps to task field: */
123 #if (CPU == sparc64)
124     long cr_ref;
125 #else
126     int cr_ref;
127 #endif
128     uid_t cr_uid;               /* euid */
129     uid_t cr_ruid;              /* uid */
130     gid_t cr_gid;               /* egid */
131     gid_t cr_rgid;              /* gid */
132 #if defined(AFS_LINUX26_ENV)
133     struct group_info *cr_group_info;
134 #else
135     gid_t cr_groups[NGROUPS];   /* 32 groups - empty set to NOGROUP */
136     int cr_ngroups;
137 #endif
138 } cred_t;
139 #define AFS_UCRED cred
140 #define AFS_PROC struct task_struct
141 #define crhold(c) (c)->cr_ref++
142
143 /* UIO manipulation */
144 typedef enum { AFS_UIOSYS, AFS_UIOUSER } uio_seg_t;
145 typedef enum { UIO_READ, UIO_WRITE } uio_flag_t;
146 typedef struct uio {
147     struct iovec *uio_iov;
148     int uio_iovcnt;
149     afs_offs_t uio_offset;
150     uio_seg_t uio_seg;
151     int uio_resid;
152     uio_flag_t uio_flag;
153 } uio_t;
154 #define afsio_iov       uio_iov
155 #define afsio_iovcnt    uio_iovcnt
156 #define afsio_offset    uio_offset
157 #define afsio_seg       uio_segflg
158 #define afsio_fmode     uio_fmode
159 #define afsio_resid     uio_resid
160
161 /* Get/set the inode in the osifile struct. */
162 #define FILE_INODE(F) (F)->f_dentry->d_inode
163
164
165 /* page offset is obtained and stored here during module initialization 
166  * We need a variable to do this because, the PAGE_OFFSET macro defined in
167  * include/asm/page.h can change from kernel to kernel and we cannot use
168  * the hardcoded version.
169  */
170 extern unsigned long afs_linux_page_offset;
171
172 /* function to help with the page offset stuff */
173 #define afs_linux_page_address(page) (afs_linux_page_offset + PAGE_SIZE * (page - mem_map))
174
175 #if defined(__KERNEL__) && defined(CONFIG_SMP)
176 #include "../h/sched.h"
177 #include "linux/wait.h"
178
179 extern struct semaphore afs_global_lock;
180 extern int afs_global_owner;
181
182 #define AFS_GLOCK() \
183 do { \
184          down(&afs_global_lock); \
185          if (afs_global_owner) \
186              osi_Panic("afs_global_lock already held by pid %d", \
187                        afs_global_owner); \
188          afs_global_owner = current->pid; \
189 } while (0)
190
191 #define ISAFS_GLOCK() (afs_global_owner == current->pid)
192
193 #define AFS_GUNLOCK() \
194 do { \
195     if (!ISAFS_GLOCK()) \
196         osi_Panic("afs global lock not held at %s:%d", __FILE__, __LINE__); \
197     afs_global_owner = 0; \
198     up(&afs_global_lock); \
199 } while (0)
200
201
202 #else
203 #define AFS_GLOCK()
204 #define AFS_GUNLOCK()
205 #define ISAFS_GLOCK() 1
206 #define AFS_ASSERT_GLOCK()
207 #define AFS_ASSERT_RXGLOCK()
208 #endif
209
210 #define AFS_RXGLOCK()
211 #define AFS_RXGUNLOCK()
212 #define ISAFS_RXGLOCK() 1
213 #endif /* OSI_MACHDEP_H_ */