1 /* Kernel compatibility routines
3 * This file contains definitions to provide compatibility between different
4 * versions of the Linux kernel. It is an ifdef maze, but the idea is that
5 * by concentrating the horror here, the rest of the tree may remaing a
9 #ifndef AFS_LINUX_OSI_COMPAT_H
10 #define AFS_LINUX_OSI_COMPAT_H
14 do_sync_read(struct file *fp, char *buf, size_t count, loff_t *offp) {
15 return generic_file_read(fp, buf, count, offp);
19 do_sync_write(struct file *fp, char *buf, size_t count, loff_t *offp) {
20 return generic_file_write(fp, buf, count, offp);
23 #endif /* DO_SYNC_READ */
26 afs_posix_lock_file(struct file *fp, struct file_lock *flp) {
27 #ifdef POSIX_LOCK_FILE_WAIT_ARG
28 return posix_lock_file(fp, flp, NULL);
30 flp->fl_flags &=~ FL_SLEEP;
31 return posix_lock_file(fp, flp);
36 afs_posix_test_lock(struct file *fp, struct file_lock *flp) {
37 #if defined(POSIX_TEST_LOCK_CONFLICT_ARG)
38 struct file_lock conflict;
39 if (posix_test_lock(fp, flp, &conflict)) {
40 locks_copy_lock(flp, &conflict);
41 flp->fl_type = F_UNLCK;
43 #elif defined(POSIX_TEST_LOCK_RETURNS_CONFLICT)
44 struct file_lock *conflict;
45 if (conflict = posix_test_lock(fp, flp)) {
46 locks_copy_lock(flp, conflict);
47 flp->fl_type = F_UNLCK;
50 posix_test_lock(fp, flp);
54 #ifdef DCACHE_NFSFS_RENAMED
56 afs_linux_clear_nfsfs_renamed(struct dentry *dp) {
57 spin_lock(&dp->d_lock);
58 dp->d_flags &= ~DCACHE_NFSFS_RENAMED;
59 spin_unlock(&dp->d_lock);
63 afs_linux_set_nfsfs_renamed(struct dentry *dp) {
64 spin_lock(&dp->d_lock);
65 dp->d_flags |= DCACHE_NFSFS_RENAMED;
66 spin_unlock(&dp->d_lock);
70 afs_linux_nfsfs_renamed(struct dentry *dp) {
71 return dp->d_flags & DCACHE_NFSFS_RENAMED;
75 static inline void afs_linux_clear_nfsfs_renamed(void) { return; }
76 static inline void afs_linux_set_nfsfs_renamed(void) { return; }
79 #ifndef HAVE_KERNEL_HLIST_UNHASHED
81 hlist_unhashed(const struct hlist_node *h) {
82 return (!h->pprev == NULL);
86 #if defined(WRITEPAGE_ACTIVATE)
87 #define AOP_WRITEPAGE_ACTIVATE WRITEPAGE_ACTIVATE
90 #if defined(HAVE_WRITE_BEGIN) && !defined(HAVE_GRAB_CACHE_PAGE_WRITE_BEGIN)
91 static inline struct page *
92 grab_cache_page_write_begin(struct address_space *mapping, pgoff_t index,
94 return __grab_cache_page(mapping, index);
98 #if defined(HAVE_KMEM_CACHE_T)
99 #define afs_kmem_cache_t kmem_cache_t
101 #define afs_kmem_cache_t struct kmem_cache
104 extern void init_once(void *);
105 #if defined(HAVE_KMEM_CACHE_T)
107 init_once_func(void * foo, kmem_cache_t * cachep, unsigned long flags) {
108 #if defined(SLAB_CTOR_VERIFY)
109 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
110 SLAB_CTOR_CONSTRUCTOR)
114 #elif defined(KMEM_CACHE_INIT)
116 init_once_func(struct kmem_cache * cachep, void * foo) {
119 #elif !defined(KMEM_CACHE_CTOR_TAKES_VOID)
121 init_once_func(void * foo, struct kmem_cache * cachep, unsigned long flags) {
122 #if defined(SLAB_CTOR_VERIFY)
123 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
124 SLAB_CTOR_CONSTRUCTOR)
130 init_once_func(void * foo) {
135 #ifndef SLAB_RECLAIM_ACCOUNT
136 #define SLAB_RECLAIM_ACCOUNT 0
139 #if defined(SLAB_KERNEL)
140 #define KALLOC_TYPE SLAB_KERNEL
142 #define KALLOC_TYPE GFP_KERNEL
145 static inline struct key *
146 afs_linux_key_alloc(struct key_type *type, const char *desc, uid_t uid,
147 gid_t gid, key_perm_t perm, unsigned long flags)
149 #if defined(KEY_ALLOC_NEEDS_STRUCT_TASK)
150 return key_alloc(type, desc, uid, gid, current, perm, flags);
151 #elif defined(KEY_ALLOC_NEEDS_CRED)
152 return key_alloc(type, desc, uid, gid, current_cred(), perm, flags);
154 return key_alloc(type, desc, uid, gid, perm, flags);
158 #if defined(STRUCT_TASK_HAS_CRED)
159 static inline struct key*
160 afs_linux_search_keyring(afs_ucred_t *cred, struct key_type *type)
164 if (cred->tgcred->session_keyring) {
165 key_ref = keyring_search(
166 make_key_ref(cred->tgcred->session_keyring, 1),
169 return ERR_CAST(key_ref);
171 return key_ref_to_ptr(key_ref);
174 return ERR_PTR(-ENOKEY);
178 afs_linux_cred_is_current(afs_ucred_t *cred)
180 return (cred == current_cred());
184 static inline struct key*
185 afs_linux_search_keyring(afs_ucred_t *cred, struct key_type *type)
187 return request_key(type, "_pag", NULL);
191 afs_linux_cred_is_current(afs_ucred_t *cred)