OpenAFS
OpenAFS distributed network file system
|
00001 /* 00002 * Copyright 2000, International Business Machines Corporation and others. 00003 * All Rights Reserved. 00004 * 00005 * This software has been released under the terms of the IBM Public 00006 * License. For details, see the LICENSE file in the top-level source 00007 * directory or online at http://www.openafs.org/dl/license10.html 00008 */ 00009 00010 /* 00011 * Linux implementation. 00012 * 00013 */ 00014 00015 #ifndef OSI_MACHDEP_H_ 00016 #define OSI_MACHDEP_H_ 00017 00018 #include <linux/version.h> 00019 00020 /* Only needed for xdr.h in glibc 2.1.x */ 00021 #ifndef quad_t 00022 #define quad_t __quad_t 00023 #define u_quad_t __u_quad_t 00024 #endif 00025 00026 #undef getuerror 00027 00028 #ifdef STRUCT_TASK_STRUCT_HAS_TGID 00029 #define getpid() current->tgid 00030 #ifdef STRUCT_TASK_STRUCT_HAS_REAL_PARENT 00031 #define getppid() current->real_parent->tgid 00032 #elif defined(STRUCT_TASK_STRUCT_HAS_PARENT) 00033 #define getppid() current->parent->tgid 00034 #else 00035 #define getppid() current->p_opptr->tgid 00036 #endif 00037 #else /* !STRUCT_TASK_STRUCT_HAS_TGID */ 00038 #define getpid() current->pid 00039 #ifdef STRUCT_TASK_STRUCT_HAS_REAL_PARENT 00040 #define getppid() current->real_parent->pid 00041 #elif defined(STRUCT_TASK_STRUCT_HAS_PARENT) 00042 #define getppid() current->parent->pid 00043 #else 00044 #define getppid() current->p_opptr->pid 00045 #endif 00046 #endif /* STRUCT_TASK_STRUCT_HAS_TGID */ 00047 00048 #ifdef RECALC_SIGPENDING_TAKES_VOID 00049 #define RECALC_SIGPENDING(X) recalc_sigpending() 00050 #else 00051 #define RECALC_SIGPENDING(X) recalc_sigpending(X) 00052 #endif 00053 00054 #if defined (STRUCT_TASK_STRUCT_HAS_SIGMASK_LOCK) 00055 #define SIG_LOCK(X) spin_lock_irq(&X->sigmask_lock) 00056 #define SIG_UNLOCK(X) spin_unlock_irq(&X->sigmask_lock) 00057 #elif defined (STRUCT_TASK_STRUCT_HAS_SIGHAND) 00058 #define SIG_LOCK(X) spin_lock_irq(&X->sighand->siglock) 00059 #define SIG_UNLOCK(X) spin_unlock_irq(&X->sighand->siglock) 00060 #else 00061 #define SIG_LOCK(X) spin_lock_irq(&X->sig->siglock) 00062 #define SIG_UNLOCK(X) spin_unlock_irq(&X->sig->siglock) 00063 #endif 00064 00065 #if defined (STRUCT_TASK_STRUCT_HAS_RLIM) 00066 #define TASK_STRUCT_RLIM rlim 00067 #elif defined (STRUCT_TASK_STRUCT_HAS_SIGNAL_RLIM) 00068 #define TASK_STRUCT_RLIM signal->rlim 00069 #else 00070 #error Not sure what to do about rlim (should be in the Linux task struct somewhere....) 00071 #endif 00072 00073 00074 #define afs_hz HZ 00075 #include "h/sched.h" 00076 #if defined(HAVE_LINUX_CURRENT_KERNEL_TIME) 00077 static inline time_t osi_Time(void) { 00078 struct timespec xtime; 00079 xtime = current_kernel_time(); 00080 return xtime.tv_sec; 00081 } 00082 #else 00083 #define osi_Time() (xtime.tv_sec) 00084 #endif 00085 00086 00087 00088 #ifdef AFS_LINUX_64BIT_KERNEL 00089 #define osi_GetTime(V) \ 00090 do { \ 00091 struct timeval __afs_tv; \ 00092 do_gettimeofday(&__afs_tv); \ 00093 (V)->tv_sec = (afs_int32)__afs_tv.tv_sec; \ 00094 (V)->tv_usec = (afs_int32)__afs_tv.tv_usec; \ 00095 } while (0) 00096 #else 00097 #define osi_GetTime(V) do_gettimeofday((V)) 00098 #endif 00099 00100 #undef gop_lookupname 00101 #define gop_lookupname osi_lookupname 00102 00103 #undef gop_lookupname_user 00104 #define gop_lookupname_user osi_lookupname 00105 00106 #define osi_vnhold(V, N) do { VN_HOLD(AFSTOV(V)); } while (0) 00107 #define VN_HOLD(V) osi_Assert(igrab((V)) == (V)) 00108 #define VN_RELE(V) iput((V)) 00109 00110 #define afs_suser(x) capable(CAP_SYS_ADMIN) 00111 #define wakeup afs_osi_Wakeup 00112 00113 #undef vType 00114 #define vType(V) ((AFSTOV((V)))->i_mode & S_IFMT) 00115 #undef vSetType 00116 #define vSetType(V, type) AFSTOV((V))->i_mode = ((type) | (AFSTOV((V))->i_mode & ~S_IFMT)) /* preserve mode */ 00117 00118 #undef IsAfsVnode 00119 #define IsAfsVnode(V) ((V)->i_sb == afs_globalVFS) /* test superblock instead */ 00120 #undef SetAfsVnode 00121 #define SetAfsVnode(V) /* unnecessary */ 00122 00123 /* We often need to pretend we're in user space to get memory transfers 00124 * right for the kernel calls we use. 00125 */ 00126 #include <asm/uaccess.h> 00127 00128 #ifdef KERNEL_SPACE_DECL 00129 #undef KERNEL_SPACE_DECL 00130 #undef TO_USER_SPACE 00131 #undef TO_KERNEL_SPACE 00132 #endif 00133 #define KERNEL_SPACE_DECL mm_segment_t _fs_space_decl={0} 00134 #define TO_USER_SPACE() { _fs_space_decl = get_fs(); set_fs(get_ds()); } 00135 #define TO_KERNEL_SPACE() set_fs(_fs_space_decl) 00136 00137 #define copyin(F, T, C) (copy_from_user ((char*)(T), (char*)(F), (C)) > 0 ? EFAULT : 0) 00138 static inline long copyinstr(char *from, char *to, int count, int *length) { 00139 long tmp; 00140 tmp = strncpy_from_user(to, from, count); 00141 if (tmp < 0) 00142 return EFAULT; 00143 *length = tmp; 00144 return 0; 00145 } 00146 #define copyout(F, T, C) (copy_to_user ((char*)(T), (char*)(F), (C)) > 0 ? EFAULT : 0) 00147 00148 /* kernel print statements */ 00149 #define printf printk 00150 #define uprintf printk 00151 00152 00153 #ifndef NGROUPS 00154 #define NGROUPS NGROUPS_SMALL 00155 #endif 00156 00157 /* cred struct */ 00158 typedef struct afs_cred { /* maps to task field: */ 00159 int cr_ref; 00160 uid_t cr_uid; /* euid */ 00161 uid_t cr_ruid; /* uid */ 00162 gid_t cr_gid; /* egid */ 00163 gid_t cr_rgid; /* gid */ 00164 gid_t cr_groups[NGROUPS]; /* 32 groups - empty set to NOGROUP */ 00165 int cr_ngroups; 00166 } cred_t; 00167 00168 typedef struct afs_cred afs_ucred_t; 00169 typedef struct task_struct afs_proc_t; 00170 00171 #if !defined(current_cred) 00172 #define current_gid() (current->gid) 00173 #define current_uid() (current->uid) 00174 #define current_fsgid() (current->fsgid) 00175 #define current_fsuid() (current->fsuid) 00176 #endif 00177 #if defined(STRUCT_TASK_STRUCT_HAS_CRED) 00178 #define current_group_info() (current->cred->group_info) 00179 #define task_gid(task) (task->cred->gid) 00180 #define task_user(task) (task->cred->user) 00181 #define task_session_keyring(task) (task->cred->tgcred->session_keyring) 00182 #define current_session_keyring() (current->cred->tgcred->session_keyring) 00183 #else 00184 #define current_group_info() (current->group_info) 00185 #if !defined(task_gid) 00186 #define task_gid(task) (task->gid) 00187 #endif 00188 #if !defined(task_uid) 00189 #define task_uid(task) (task->uid) 00190 #endif 00191 #define task_user(task) (task->user) 00192 #define task_session_keyring(task) (task->signal->session_keyring) 00193 #define current_session_keyring() (current->signal->session_keyring) 00194 #endif 00195 #define crhold(c) (c)->cr_ref++ 00196 00197 /* UIO manipulation */ 00198 typedef enum { AFS_UIOSYS, AFS_UIOUSER } uio_seg_t; 00199 typedef enum { UIO_READ, UIO_WRITE } uio_flag_t; 00200 struct uio { 00201 struct iovec *uio_iov; 00202 int uio_iovcnt; 00203 afs_offs_t uio_offset; 00204 uio_seg_t uio_seg; 00205 int uio_resid; 00206 uio_flag_t uio_flag; 00207 }; 00208 #define afsio_iov uio_iov 00209 #define afsio_iovcnt uio_iovcnt 00210 #define afsio_offset uio_offset 00211 #define afsio_seg uio_segflg 00212 #define afsio_fmode uio_fmode 00213 #define afsio_resid uio_resid 00214 00215 /* Get/set the inode in the osifile struct. */ 00216 #define FILE_INODE(F) (F)->f_dentry->d_inode 00217 00218 #define OSIFILE_INODE(a) FILE_INODE(&(a)->file) 00219 00220 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV) 00221 #define NEED_IOCTL32 00222 #endif 00223 00224 /* page offset is obtained and stored here during module initialization 00225 * We need a variable to do this because, the PAGE_OFFSET macro defined in 00226 * include/asm/page.h can change from kernel to kernel and we cannot use 00227 * the hardcoded version. 00228 */ 00229 extern unsigned long afs_linux_page_offset; 00230 00231 /* function to help with the page offset stuff */ 00232 #define afs_linux_page_address(page) (afs_linux_page_offset + PAGE_SIZE * (page - mem_map)) 00233 00234 #if defined(__KERNEL__) 00235 #include <linux/version.h> 00236 #include <linux/sched.h> 00237 #include <linux/wait.h> 00238 00239 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) 00240 extern struct mutex afs_global_lock; 00241 #else 00242 extern struct semaphore afs_global_lock; 00243 #define mutex_lock(lock) down(lock) 00244 #define mutex_unlock(lock) up(lock) 00245 #endif 00246 extern int afs_global_owner; 00247 00248 #define AFS_GLOCK() \ 00249 do { \ 00250 mutex_lock(&afs_global_lock); \ 00251 if (afs_global_owner) \ 00252 osi_Panic("afs_global_lock already held by pid %d", \ 00253 afs_global_owner); \ 00254 afs_global_owner = current->pid; \ 00255 } while (0) 00256 00257 #define ISAFS_GLOCK() (afs_global_owner == current->pid) 00258 00259 #define AFS_GUNLOCK() \ 00260 do { \ 00261 if (!ISAFS_GLOCK()) \ 00262 osi_Panic("afs global lock not held at %s:%d", __FILE__, __LINE__); \ 00263 afs_global_owner = 0; \ 00264 mutex_unlock(&afs_global_lock); \ 00265 } while (0) 00266 00267 #define osi_InitGlock() 00268 00269 #else 00270 #define AFS_GLOCK() 00271 #define AFS_GUNLOCK() 00272 #define ISAFS_GLOCK() 1 00273 #define AFS_ASSERT_GLOCK() 00274 #endif 00275 00276 #ifdef AFS_AMD64_LINUX20_ENV 00277 /* RHEL5 beta's kernel doesn't define these. They aren't gonna change, so... */ 00278 00279 #ifndef __NR_ia32_afs_syscall 00280 #define __NR_ia32_afs_syscall 137 00281 #endif 00282 #ifndef __NR_ia32_setgroups 00283 #define __NR_ia32_setgroups 81 00284 #endif 00285 #ifndef __NR_ia32_setgroups32 00286 #define __NR_ia32_setgroups32 206 00287 #endif 00288 #ifndef __NR_ia32_close 00289 #define __NR_ia32_close 6 00290 #endif 00291 #ifndef __NR_ia32_chdir 00292 #define __NR_ia32_chdir 12 00293 #endif 00294 #ifndef __NR_ia32_break 00295 #define __NR_ia32_break 17 00296 #endif 00297 #ifndef __NR_ia32_stty 00298 #define __NR_ia32_stty 31 00299 #endif 00300 #ifndef __NR_ia32_gtty 00301 #define __NR_ia32_gtty 32 00302 #endif 00303 #ifndef __NR_ia32_ftime 00304 #define __NR_ia32_ftime 35 00305 #endif 00306 #ifndef __NR_ia32_prof 00307 #define __NR_ia32_prof 44 00308 #endif 00309 #ifndef __NR_ia32_lock 00310 #define __NR_ia32_lock 53 00311 #endif 00312 #ifndef __NR_ia32_mpx 00313 #define __NR_ia32_mpx 56 00314 #endif 00315 #ifndef __NR_ia32_exit 00316 #define __NR_ia32_exit 1 00317 #endif 00318 #ifndef __NR_ia32_mount 00319 #define __NR_ia32_mount 21 00320 #endif 00321 #ifndef __NR_ia32_read 00322 #define __NR_ia32_read 3 00323 #endif 00324 #ifndef __NR_ia32_write 00325 #define __NR_ia32_write 4 00326 #endif 00327 #ifndef __NR_ia32_open 00328 #define __NR_ia32_open 5 00329 #endif 00330 #ifndef __NR_ia32_close 00331 #define __NR_ia32_close 6 00332 #endif 00333 #ifndef __NR_ia32_unlink 00334 #define __NR_ia32_unlink 10 00335 #endif 00336 #endif 00337 00338 #define osi_procname(procname, size) strncpy(procname, current->comm, size) 00339 00340 #endif /* OSI_MACHDEP_H_ */