Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / afs / LINUX / osi_compat.h
1 /* Kernel compatibility routines
2 *
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
6 * little cleaner...
7 */
8
9 #ifndef AFS_LINUX_OSI_COMPAT_H
10 #define AFS_LINUX_OSI_COMPAT_H
11
12 #if defined(HAVE_LINUX_FREEZER_H)
13 # include <linux/freezer.h>
14 #endif
15
16 #if defined(LINUX_KEYRING_SUPPORT)
17 # include <linux/rwsem.h>
18 # include <linux/key.h>
19 # if defined(HAVE_LINUX_KEY_TYPE_H)
20 # include <linux/key-type.h>
21 # endif
22 # ifndef KEY_ALLOC_IN_QUOTA
23 /* Before these flags were added in Linux commit v2.6.18-rc1~816,
24 * key_alloc just took a boolean not_in_quota */
25 # define KEY_ALLOC_IN_QUOTA 0
26 # define KEY_ALLOC_NOT_IN_QUOTA 1
27 # endif
28 #endif
29
30 #if defined(STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT) && !defined(DCACHE_NEED_AUTOMOUNT)
31 # define DCACHE_NEED_AUTOMOUNT DMANAGED_AUTOMOUNT
32 #endif
33
34 #ifdef HAVE_LINUX_STRUCT_VFS_PATH
35 typedef struct vfs_path afs_linux_path_t;
36 #else
37 typedef struct path afs_linux_path_t;
38 #endif
39
40 #if defined(STRUCT_DENTRY_HAS_D_U_D_ALIAS)
41 # define d_alias d_u.d_alias
42 #endif
43
44 #if defined(STRUCT_FILE_HAS_F_PATH)
45 # if !defined(f_dentry)
46 # define f_dentry f_path.dentry
47 # endif
48 #endif
49
50 #ifndef HAVE_LINUX_FILE_DENTRY
51 #define file_dentry(file) ((file)->f_dentry)
52 #endif
53
54 #if defined(HAVE_LINUX_LOCKS_LOCK_FILE_WAIT)
55 # define flock_lock_file_wait locks_lock_file_wait
56 #endif
57
58 #if !defined(HAVE_LINUX_DO_SYNC_READ) && !defined(STRUCT_FILE_OPERATIONS_HAS_READ_ITER)
59 static inline int
60 do_sync_read(struct file *fp, char *buf, size_t count, loff_t *offp) {
61 return generic_file_read(fp, buf, count, offp);
62 }
63
64 static inline int
65 do_sync_write(struct file *fp, char *buf, size_t count, loff_t *offp) {
66 return generic_file_write(fp, buf, count, offp);
67 }
68
69 #endif /* DO_SYNC_READ */
70
71 static inline int
72 afs_posix_lock_file(struct file *fp, struct file_lock *flp) {
73 #ifdef POSIX_LOCK_FILE_WAIT_ARG
74 return posix_lock_file(fp, flp, NULL);
75 #else
76 flp->fl_flags &=~ FL_SLEEP;
77 return posix_lock_file(fp, flp);
78 #endif
79 }
80
81 static inline void
82 afs_posix_test_lock(struct file *fp, struct file_lock *flp) {
83 #if defined(POSIX_TEST_LOCK_CONFLICT_ARG)
84 struct file_lock conflict;
85 if (posix_test_lock(fp, flp, &conflict)) {
86 locks_copy_lock(flp, &conflict);
87 flp->fl_type = F_UNLCK;
88 }
89 #elif defined(POSIX_TEST_LOCK_RETURNS_CONFLICT)
90 struct file_lock *conflict;
91 conflict = posix_test_lock(fp, flp);
92 if (conflict) {
93 locks_copy_lock(flp, conflict);
94 flp->fl_type = F_UNLCK;
95 }
96 #else
97 posix_test_lock(fp, flp);
98 #endif
99 }
100
101 #ifdef DCACHE_NFSFS_RENAMED
102 static inline void
103 afs_linux_clear_nfsfs_renamed(struct dentry *dp) {
104 spin_lock(&dp->d_lock);
105 dp->d_flags &= ~DCACHE_NFSFS_RENAMED;
106 spin_unlock(&dp->d_lock);
107 }
108
109 static inline void
110 afs_linux_set_nfsfs_renamed(struct dentry *dp) {
111 spin_lock(&dp->d_lock);
112 dp->d_flags |= DCACHE_NFSFS_RENAMED;
113 spin_unlock(&dp->d_lock);
114 }
115
116 static inline int
117 afs_linux_nfsfs_renamed(struct dentry *dp) {
118 return dp->d_flags & DCACHE_NFSFS_RENAMED;
119 }
120
121 #else
122 static inline void afs_linux_clear_nfsfs_renamed(void) { return; }
123 static inline void afs_linux_set_nfsfs_renamed(void) { return; }
124 #endif
125
126 #ifndef HAVE_LINUX_HLIST_UNHASHED
127 static void
128 hlist_unhashed(const struct hlist_node *h) {
129 return (!h->pprev == NULL);
130 }
131 #endif
132
133 #if defined(WRITEPAGE_ACTIVATE)
134 #define AOP_WRITEPAGE_ACTIVATE WRITEPAGE_ACTIVATE
135 #endif
136
137 #if defined(STRUCT_ADDRESS_SPACE_OPERATIONS_HAS_WRITE_BEGIN) && !defined(HAVE_LINUX_GRAB_CACHE_PAGE_WRITE_BEGIN)
138 static inline struct page *
139 grab_cache_page_write_begin(struct address_space *mapping, pgoff_t index,
140 unsigned int flags) {
141 return __grab_cache_page(mapping, index);
142 }
143 #endif
144
145 #if defined(HAVE_KMEM_CACHE_T)
146 #define afs_kmem_cache_t kmem_cache_t
147 #else
148 #define afs_kmem_cache_t struct kmem_cache
149 #endif
150
151 extern void init_once(void *);
152 #if defined(HAVE_KMEM_CACHE_T)
153 static inline void
154 init_once_func(void * foo, kmem_cache_t * cachep, unsigned long flags) {
155 #if defined(SLAB_CTOR_VERIFY)
156 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
157 SLAB_CTOR_CONSTRUCTOR)
158 #endif
159 init_once(foo);
160 }
161 #elif defined(KMEM_CACHE_INIT)
162 static inline void
163 init_once_func(struct kmem_cache * cachep, void * foo) {
164 init_once(foo);
165 }
166 #elif !defined(KMEM_CACHE_CTOR_TAKES_VOID)
167 static inline void
168 init_once_func(void * foo, struct kmem_cache * cachep, unsigned long flags) {
169 #if defined(SLAB_CTOR_VERIFY)
170 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
171 SLAB_CTOR_CONSTRUCTOR)
172 #endif
173 init_once(foo);
174 }
175 #else
176 static inline void
177 init_once_func(void * foo) {
178 init_once(foo);
179 }
180 #endif
181
182 #ifndef SLAB_RECLAIM_ACCOUNT
183 #define SLAB_RECLAIM_ACCOUNT 0
184 #endif
185
186 #if defined(SLAB_KERNEL)
187 #define KALLOC_TYPE SLAB_KERNEL
188 #else
189 #define KALLOC_TYPE GFP_KERNEL
190 #endif
191
192 #ifdef LINUX_KEYRING_SUPPORT
193 static inline struct key *
194 afs_linux_key_alloc(struct key_type *type, const char *desc, afs_kuid_t uid,
195 afs_kgid_t gid, key_perm_t perm, unsigned long flags)
196 {
197 # if defined(KEY_ALLOC_BYPASS_RESTRICTION)
198 return key_alloc(type, desc, uid, gid, current_cred(), perm, flags, NULL);
199 # elif defined(KEY_ALLOC_NEEDS_STRUCT_TASK)
200 return key_alloc(type, desc, uid, gid, current, perm, flags);
201 # elif defined(KEY_ALLOC_NEEDS_CRED)
202 return key_alloc(type, desc, uid, gid, current_cred(), perm, flags);
203 # else
204 return key_alloc(type, desc, uid, gid, perm, flags);
205 # endif
206 }
207
208 # if defined(STRUCT_TASK_STRUCT_HAS_CRED)
209 static inline struct key *
210 afs_session_keyring(afs_ucred_t *cred)
211 {
212 # if defined(STRUCT_CRED_HAS_SESSION_KEYRING)
213 return cred->session_keyring;
214 # else
215 return cred->tgcred->session_keyring;
216 # endif
217 }
218
219 static inline struct key*
220 afs_linux_search_keyring(afs_ucred_t *cred, struct key_type *type)
221 {
222 key_ref_t key_ref;
223
224 if (afs_session_keyring(cred)) {
225 # if defined(KEYRING_SEARCH_TAKES_RECURSE)
226 key_ref = keyring_search(
227 make_key_ref(afs_session_keyring(cred), 1),
228 type, "_pag", 1);
229 # else
230 key_ref = keyring_search(
231 make_key_ref(afs_session_keyring(cred), 1),
232 type, "_pag");
233 # endif
234 if (IS_ERR(key_ref))
235 return ERR_CAST(key_ref);
236
237 return key_ref_to_ptr(key_ref);
238 }
239
240 return ERR_PTR(-ENOKEY);
241 }
242 # else
243 static inline struct key*
244 afs_linux_search_keyring(afs_ucred_t *cred, struct key_type *type)
245 {
246 return request_key(type, "_pag", NULL);
247 }
248 # endif /* STRUCT_TASK_STRUCT_HAS_CRED */
249
250 static_inline struct key *
251 afs_set_session_keyring(struct key *keyring)
252 {
253 struct key *old;
254 #if defined(STRUCT_CRED_HAS_SESSION_KEYRING)
255 struct cred *new_creds;
256 old = current_session_keyring();
257 new_creds = prepare_creds();
258 rcu_assign_pointer(new_creds->session_keyring, keyring);
259 commit_creds(new_creds);
260 #else
261 spin_lock_irq(&current->sighand->siglock);
262 old = task_session_keyring(current);
263 smp_wmb();
264 task_session_keyring(current) = keyring;
265 spin_unlock_irq(&current->sighand->siglock);
266 #endif
267 return old;
268 }
269 #endif /* LINUX_KEYRING_SUPPORT */
270
271 #ifdef STRUCT_TASK_STRUCT_HAS_CRED
272 static inline int
273 afs_linux_cred_is_current(afs_ucred_t *cred)
274 {
275 return (cred == current_cred());
276 }
277 #else
278 static inline int
279 afs_linux_cred_is_current(afs_ucred_t *cred)
280 {
281 return 1;
282 }
283 #endif
284
285 #ifndef HAVE_LINUX_PAGE_OFFSET
286 static inline loff_t
287 page_offset(struct page *pp)
288 {
289 return (((loff_t) pp->index) << PAGE_SHIFT);
290 }
291 #endif
292
293 #ifndef HAVE_LINUX_ZERO_USER_SEGMENTS
294 static inline void
295 zero_user_segments(struct page *pp, unsigned int from1, unsigned int to1,
296 unsigned int from2, unsigned int to2)
297 {
298 void *base = kmap_atomic(pp, KM_USER0);
299
300 if (to1 > from1)
301 memset(base + from1, 0, to1 - from1);
302
303 if (to2 > from2)
304 memset(base + from2, 0, to2 - from2);
305
306 flush_dcache_page(pp);
307 kunmap_atomic(base, KM_USER0);
308 }
309
310 static inline void
311 zero_user_segment(struct page *pp, unsigned int from1, unsigned int to1)
312 {
313 zero_user_segments(pp, from1, to1, 0, 0);
314 }
315 #endif
316
317 #ifndef HAVE_LINUX_KERNEL_SETSOCKOPT
318 /* Available from 2.6.19 */
319
320 static inline int
321 kernel_setsockopt(struct socket *sockp, int level, int name, char *val,
322 unsigned int len) {
323 mm_segment_t old_fs = get_fs();
324 int ret;
325
326 set_fs(get_ds());
327 ret = sockp->ops->setsockopt(sockp, level, name, val, len);
328 set_fs(old_fs);
329
330 return ret;
331 }
332
333 static inline int
334 kernel_getsockopt(struct socket *sockp, int level, int name, char *val,
335 int *len) {
336 mm_segment_t old_fs = get_fs();
337 int ret;
338
339 set_fs(get_ds());
340 ret = sockp->ops->getsockopt(sockp, level, name, val, len);
341 set_fs(old_fs);
342
343 return ret;
344 }
345 #endif
346
347 #ifdef HAVE_TRY_TO_FREEZE
348 static inline int
349 afs_try_to_freeze(void) {
350 # ifdef LINUX_REFRIGERATOR_TAKES_PF_FREEZE
351 return try_to_freeze(PF_FREEZE);
352 # else
353 return try_to_freeze();
354 # endif
355 }
356 #else
357 static inline int
358 afs_try_to_freeze(void) {
359 # ifdef CONFIG_PM
360 if (current->flags & PF_FREEZE) {
361 refrigerator(PF_FREEZE);
362 return 1;
363 }
364 # endif
365 return 0;
366 }
367 #endif
368
369 /* The commit which changed refrigerator so that it takes no arguments
370 * also added freezing(), so if LINUX_REFRIGERATOR_TAKES_PF_FREEZE is
371 * true, the kernel doesn't have a freezing() function.
372 */
373 #ifdef LINUX_REFRIGERATOR_TAKES_PF_FREEZE
374 static inline int
375 freezing(struct task_struct *p)
376 {
377 # ifdef CONFIG_PM
378 return p->flags & PF_FREEZE;
379 # else
380 return 0;
381 # endif
382 }
383 #endif
384
385 #if !defined(HAVE_LINUX_PAGECHECKED)
386 # if defined(HAVE_LINUX_PAGEFSMISC)
387 # include <linux/page-flags.h>
388
389 # define PageChecked(p) PageFsMisc((p))
390 # define SetPageChecked(p) SetPageFsMisc((p))
391 # define ClearPageChecked(p) ClearPageFsMisc((p))
392
393 # endif
394 #endif
395
396 #if !defined(NEW_EXPORT_OPS)
397 extern struct export_operations export_op_default;
398 #endif
399
400 static inline struct dentry *
401 afs_get_dentry_from_fh(struct super_block *afs_cacheSBp, afs_dcache_id_t *ainode,
402 int cache_fh_len, int cache_fh_type,
403 int (*afs_fh_acceptable)(void *, struct dentry *)) {
404 #if defined(NEW_EXPORT_OPS)
405 return afs_cacheSBp->s_export_op->fh_to_dentry(afs_cacheSBp, &ainode->ufs.fh,
406 cache_fh_len, cache_fh_type);
407 #else
408 if (afs_cacheSBp->s_export_op && afs_cacheSBp->s_export_op->decode_fh)
409 return afs_cacheSBp->s_export_op->decode_fh(afs_cacheSBp, ainode->ufs.raw,
410 cache_fh_len, cache_fh_type, afs_fh_acceptable, NULL);
411 else
412 return export_op_default.decode_fh(afs_cacheSBp, ainode->ufs.raw,
413 cache_fh_len, cache_fh_type, afs_fh_acceptable, NULL);
414 #endif
415 }
416
417 static inline int
418 afs_get_fh_from_dentry(struct dentry *dp, afs_ufs_dcache_id_t *ainode, int *max_lenp) {
419 if (dp->d_sb->s_export_op->encode_fh)
420 #if defined(EXPORT_OP_ENCODE_FH_TAKES_INODES)
421 return dp->d_sb->s_export_op->encode_fh(dp->d_inode, &ainode->raw[0], max_lenp, NULL);
422 #else
423 return dp->d_sb->s_export_op->encode_fh(dp, &ainode->raw[0], max_lenp, 0);
424 #endif
425 #if defined(NEW_EXPORT_OPS)
426 /* If fs doesn't provide an encode_fh method, assume the default INO32 type */
427 *max_lenp = sizeof(struct fid)/4;
428 ainode->fh.i32.ino = dp->d_inode->i_ino;
429 ainode->fh.i32.gen = dp->d_inode->i_generation;
430 return FILEID_INO32_GEN;
431 #else
432 /* or call the default encoding function for the old API */
433 return export_op_default.encode_fh(dp, &ainode->raw[0], max_lenp, 0);
434 #endif
435 }
436
437 static inline void
438 afs_init_sb_export_ops(struct super_block *sb) {
439 #if !defined(NEW_EXPORT_OPS)
440 /*
441 * decode_fh will call this function. If not defined for this FS, make
442 * sure it points to the default
443 */
444 if (!sb->s_export_op->find_exported_dentry) {
445 /* Some kernels (at least 2.6.9) do not prototype find_exported_dentry,
446 * even though it is exported, so prototype it ourselves. Newer
447 * kernels do prototype it, but as long as our protoype matches the
448 * real one (the signature never changed before NEW_EXPORT_OPS came
449 * into play), there should be no problems. */
450 extern struct dentry * find_exported_dentry(struct super_block *sb, void *obj, void *parent,
451 int (*acceptable)(void *context, struct dentry *de),
452 void *context);
453 sb->s_export_op->find_exported_dentry = find_exported_dentry;
454 }
455 #endif
456 }
457
458 static inline void
459 afs_linux_lock_inode(struct inode *ip) {
460 #if defined(HAVE_LINUX_INODE_LOCK)
461 inode_lock(ip);
462 #elif defined(STRUCT_INODE_HAS_I_MUTEX)
463 mutex_lock(&ip->i_mutex);
464 #else
465 down(&ip->i_sem);
466 #endif
467 }
468
469 static inline void
470 afs_linux_unlock_inode(struct inode *ip) {
471 #if defined(HAVE_LINUX_INODE_LOCK)
472 inode_unlock(ip);
473 #elif defined(STRUCT_INODE_HAS_I_MUTEX)
474 mutex_unlock(&ip->i_mutex);
475 #else
476 up(&ip->i_sem);
477 #endif
478 }
479
480 /* Use these to lock or unlock an inode for processing
481 * its dentry aliases en masse.
482 */
483 #if defined(HAVE_DCACHE_LOCK)
484 #define afs_d_alias_lock(ip) spin_lock(&dcache_lock)
485 #define afs_d_alias_unlock(ip) spin_unlock(&dcache_lock)
486 #else
487 #define afs_d_alias_lock(ip) spin_lock(&(ip)->i_lock)
488 #define afs_d_alias_unlock(ip) spin_unlock(&(ip)->i_lock)
489 #endif
490
491
492 /* Use this instead of dget for dentry operations
493 * that occur under a higher lock (e.g. alias processing).
494 * Requires that the higher lock (e.g. dcache_lock or
495 * inode->i_lock) is already held.
496 */
497 static inline void
498 afs_linux_dget(struct dentry *dp) {
499 #if defined(HAVE_DCACHE_LOCK)
500 dget_locked(dp);
501 #else
502 dget(dp);
503 #endif
504 }
505
506
507 static inline int
508 afs_inode_setattr(struct osi_file *afile, struct iattr *newattrs) {
509
510 int code = 0;
511 struct inode *inode = OSIFILE_INODE(afile);
512 #if !defined(HAVE_LINUX_INODE_SETATTR)
513 code = inode->i_op->setattr(afile->filp->f_dentry, newattrs);
514 #elif defined(INODE_SETATTR_NOT_VOID)
515 if (inode->i_op && inode->i_op->setattr)
516 code = inode->i_op->setattr(afile->filp->f_dentry, newattrs);
517 else
518 code = inode_setattr(inode, newattrs);
519 #else
520 inode_setattr(inode, newattrs);
521 #endif
522 return code;
523 }
524
525 #if defined(HAVE_LINUX_PATH_LOOKUP)
526 static inline int
527 afs_kern_path(char *aname, int flags, struct nameidata *nd) {
528 return path_lookup(aname, flags, nd);
529 }
530 #else
531 static inline int
532 afs_kern_path(char *aname, int flags, afs_linux_path_t *path) {
533 return kern_path(aname, flags, path);
534 }
535 #endif
536
537 static inline void
538 #if defined(HAVE_LINUX_PATH_LOOKUP)
539 afs_get_dentry_ref(struct nameidata *nd, struct vfsmount **mnt, struct dentry **dpp) {
540 #else
541 afs_get_dentry_ref(afs_linux_path_t *path, struct vfsmount **mnt, struct dentry **dpp) {
542 #endif
543 #if defined(HAVE_LINUX_PATH_LOOKUP)
544 # if defined(STRUCT_NAMEIDATA_HAS_PATH)
545 *dpp = dget(nd->path.dentry);
546 if (mnt)
547 *mnt = mntget(nd->path.mnt);
548 path_put(&nd->path);
549 # else
550 *dpp = dget(nd->dentry);
551 if (mnt)
552 *mnt = mntget(nd->mnt);
553 path_release(nd);
554 # endif
555 #else
556 *dpp = dget(path->dentry);
557 if (mnt)
558 *mnt = mntget(path->mnt);
559 path_put(path);
560 #endif
561 }
562
563 /* wait_event_freezable appeared with 2.6.24 */
564
565 /* These implement the original AFS wait behaviour, with respect to the
566 * refrigerator, rather than the behaviour of the current wait_event_freezable
567 * implementation.
568 */
569
570 #ifndef wait_event_freezable
571 # define wait_event_freezable(waitqueue, condition) \
572 ({ \
573 int _ret; \
574 do { \
575 _ret = wait_event_interruptible(waitqueue, \
576 (condition) || freezing(current)); \
577 if (_ret && !freezing(current)) \
578 break; \
579 else if (!(condition)) \
580 _ret = -EINTR; \
581 } while (afs_try_to_freeze()); \
582 _ret; \
583 })
584
585 # define wait_event_freezable_timeout(waitqueue, condition, timeout) \
586 ({ \
587 int _ret; \
588 do { \
589 _ret = wait_event_interruptible_timeout(waitqueue, \
590 (condition || \
591 freezing(current)), \
592 timeout); \
593 } while (afs_try_to_freeze()); \
594 _ret; \
595 })
596 #endif
597
598 #if defined(STRUCT_TASK_STRUCT_HAS_CRED)
599 static inline struct file *
600 afs_dentry_open(struct dentry *dp, struct vfsmount *mnt, int flags, const struct cred *creds) {
601 #if defined(DENTRY_OPEN_TAKES_PATH)
602 afs_linux_path_t path;
603 struct file *filp;
604 path.mnt = mnt;
605 path.dentry = dp;
606 /* note that dentry_open will path_get for us */
607 filp = dentry_open(&path, flags, creds);
608 return filp;
609 #else
610 return dentry_open(dget(dp), mntget(mnt), flags, creds);
611 #endif
612 }
613 #endif
614
615 static inline int
616 afs_truncate(struct inode *inode, int len)
617 {
618 int code;
619 #if defined(STRUCT_INODE_OPERATIONS_HAS_TRUNCATE)
620 code = vmtruncate(inode, len);
621 #else
622 code = inode_newsize_ok(inode, len);
623 if (!code)
624 truncate_setsize(inode, len);
625 #endif
626 return code;
627 }
628
629 static inline struct proc_dir_entry *
630 afs_proc_create(char *name, umode_t mode, struct proc_dir_entry *parent, struct file_operations *fops) {
631 #if defined(HAVE_LINUX_PROC_CREATE)
632 return proc_create(name, mode, parent, fops);
633 #else
634 struct proc_dir_entry *entry;
635 entry = create_proc_entry(name, mode, parent);
636 if (entry)
637 entry->proc_fops = fops;
638 return entry;
639 #endif
640 }
641
642 static inline int
643 afs_dentry_count(struct dentry *dp)
644 {
645 #if defined(HAVE_LINUX_D_COUNT)
646 return d_count(dp);
647 #elif defined(D_COUNT_INT)
648 return dp->d_count;
649 #else
650 return atomic_read(&dp->d_count);
651 #endif
652 }
653
654 static inline void
655 afs_maybe_shrink_dcache(struct dentry *dp)
656 {
657 #if defined(HAVE_LINUX_D_COUNT) || defined(D_COUNT_INT)
658 spin_lock(&dp->d_lock);
659 if (afs_dentry_count(dp) > 1) {
660 spin_unlock(&dp->d_lock);
661 shrink_dcache_parent(dp);
662 } else
663 spin_unlock(&dp->d_lock);
664 #else
665 if (afs_dentry_count(dp) > 1)
666 shrink_dcache_parent(dp);
667 #endif
668 }
669
670 static inline int
671 afs_d_invalidate(struct dentry *dp)
672 {
673 #if defined(D_INVALIDATE_IS_VOID)
674 d_invalidate(dp);
675 return 0;
676 #else
677 return d_invalidate(dp);
678 #endif
679 }
680
681 #if defined(HAVE_LINUX___VFS_WRITE)
682 # define AFS_FILE_NEEDS_SET_FS 1
683 #elif defined(HAVE_LINUX_KERNEL_WRITE)
684 /* #undef AFS_FILE_NEEDS_SET_FS */
685 #else
686 # define AFS_FILE_NEEDS_SET_FS 1
687 #endif
688
689 static inline int
690 afs_file_read(struct file *filp, char __user *buf, size_t len, loff_t *pos)
691 {
692 #if defined(HAVE_LINUX___VFS_WRITE)
693 return __vfs_read(filp, buf, len, pos);
694 #elif defined(HAVE_LINUX_KERNEL_WRITE)
695 # if defined(KERNEL_READ_OFFSET_IS_LAST)
696 return kernel_read(filp, buf, len, pos);
697 # else
698 return kernel_read(filp, *pos, buf, len);
699 # endif
700 #else
701 return filp->f_op->read(filp, buf, len, pos);
702 #endif
703 }
704
705 static inline int
706 afs_file_write(struct file *filp, char __user *buf, size_t len, loff_t *pos)
707 {
708 #if defined(HAVE_LINUX___VFS_WRITE)
709 return __vfs_write(filp, buf, len, pos);
710 #elif defined(HAVE_LINUX_KERNEL_WRITE)
711 # if defined(KERNEL_READ_OFFSET_IS_LAST)
712 return kernel_write(filp, buf, len, pos);
713 # else
714 return kernel_write(filp, buf, len, *pos);
715 # endif
716 #else
717 return filp->f_op->write(filp, buf, len, pos);
718 #endif
719 }
720
721 #endif /* AFS_LINUX_OSI_COMPAT_H */