Rationalise some #ifdefs in the LINUX osi layer
[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 #ifndef DO_SYNC_READ
13 static inline int
14 do_sync_read(struct file *fp, char *buf, size_t count, loff_t *offp) {
15     return generic_file_read(fp, buf, count, offp);
16 }
17
18 static inline int
19 do_sync_write(struct file *fp, char *buf, size_t count, loff_t *offp) {
20     return generic_file_write(fp, buf, count, offp);
21 }
22
23 #endif /* DO_SYNC_READ */
24
25 static inline int
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);
29 #else
30     flp->fl_flags &=~ FL_SLEEP;
31     return posix_lock_file(fp, flp);
32 #endif
33 }
34
35 static inline void
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;
42     }
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;
48     }
49 #else
50     posix_test_lock(fp, flp);
51 #endif
52 }
53
54 #ifdef DCACHE_NFSFS_RENAMED
55 static inline void
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);
60 }
61
62 static inline void
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);
67 }
68 #else
69 static inline void afs_linux_clear_nfsfs_renamed(void) { return; }
70 static inline void afs_linux_set_nfsfs_renamed(void) { return; }
71 #endif
72
73 #ifndef HAVE_KERNEL_HLIST_UNHASHED
74 static void
75 hlist_unhashed(const struct hlist_node *h) {
76     return (!h->pprev == NULL);
77 }
78 #endif
79
80 #if defined(WRITEPAGE_ACTIVATE)
81 #define AOP_WRITEPAGE_ACTIVATE WRITEPAGE_ACTIVATE
82 #endif
83
84 #if defined(HAVE_WRITE_BEGIN) && !defined(HAVE_GRAB_CACHE_PAGE_WRITE_BEGIN)
85 static inline struct page *
86 grab_cache_page_write_begin(struct address_space *mapping, pgoff_t index,
87                             unsigned int flags) {
88     return __grab_cache_page(mapping, index);
89 }
90 #endif
91
92 #endif