~n-muench/ubuntu/quantal/open-vm-tools/open-vm-tools.may2.sid-sync

« back to all changes in this revision

Viewing changes to modules/linux/vmblock/include/compat_fs.h

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-05-30 09:48:43 UTC
  • mfrom: (1.1.5 upstream) (2.4.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090530094843-gdpza57r5iqsf124
Tags: 2009.05.22-167859-1
MergingĀ upstreamĀ versionĀ 2009.05.22-167859.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*********************************************************
2
 
 * Copyright (C) 2006 VMware, Inc. All rights reserved.
3
 
 *
4
 
 * This program is free software; you can redistribute it and/or modify it
5
 
 * under the terms of the GNU General Public License as published by the
6
 
 * Free Software Foundation version 2 and no later version.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful, but
9
 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10
 
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11
 
 * for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU General Public License along
14
 
 * with this program; if not, write to the Free Software Foundation, Inc.,
15
 
 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
16
 
 *
17
 
 *********************************************************/
18
 
 
19
 
#ifndef __COMPAT_FS_H__
20
 
#   define __COMPAT_FS_H__
21
 
 
22
 
#include <linux/fs.h>
23
 
 
24
 
/*
25
 
 * 2.6.5+ kernels define FS_BINARY_MOUNTDATA. Since it didn't exist and
26
 
 * wasn't used prior, it's safe to define it to zero.
27
 
 */
28
 
 
29
 
#ifndef FS_BINARY_MOUNTDATA
30
 
#define FS_BINARY_MOUNTDATA 0
31
 
#endif
32
 
 
33
 
/*
34
 
 * MAX_LFS_FILESIZE wasn't defined until 2.5.4.
35
 
 */
36
 
#ifndef MAX_LFS_FILESIZE
37
 
#   include <linux/pagemap.h>
38
 
#   if BITS_PER_LONG == 32
39
 
#      define MAX_LFS_FILESIZE       (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG - 1)) - 1)
40
 
#   elif BITS_PER_LONG == 64
41
 
#      define MAX_LFS_FILESIZE       0x7fffffffffffffffUL
42
 
#   endif
43
 
#endif
44
 
 
45
 
 
46
 
/*
47
 
 * sendfile as a VFS op was born in 2.5.30. Unfortunately, it also changed
48
 
 * signatures, first in 2.5.47, then again in 2.5.70, then again in 2.6.8.
49
 
 * Luckily, the 2.6.8+ signature is the same as the 2.5.47 signature.  And
50
 
 * as of 2.6.23-rc1 sendfile is gone, replaced by splice_read...
51
 
 *
52
 
 * Let's not support sendfile from 2.5.30 to 2.5.47, because the 2.5.30
53
 
 * signature is much different and file_send_actor isn't externed.
54
 
 */
55
 
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23)
56
 
#define VMW_SENDFILE_NONE
57
 
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 8)
58
 
#define VMW_SENDFILE_NEW
59
 
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 70)
60
 
#define VMW_SENDFILE_OLD
61
 
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 47)
62
 
#define VMW_SENDFILE_NEW
63
 
#else
64
 
#define VMW_SENDFILE_NONE
65
 
#endif
66
 
 
67
 
/*
68
 
 * splice_read is there since 2.6.17, but let's avoid 2.6.17-rcX kernels...
69
 
 * After all nobody is using splice system call until 2.6.23 using it to
70
 
 * implement sendfile.
71
 
 */
72
 
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18)
73
 
#define VMW_SPLICE_READ 1
74
 
#endif
75
 
 
76
 
/*
77
 
 * Filesystems wishing to use generic page cache read/write routines are
78
 
 * supposed to implement aio_read and aio_write (calling into
79
 
 * generic_file_aio_read() and generic_file_aio_write() if necessary).
80
 
 *
81
 
 * The VFS exports do_sync_read() and do_sync_write() as the "new"
82
 
 * generic_file_read() and generic_file_write(), but filesystems need not
83
 
 * actually implement read and write- the VFS will automatically call
84
 
 * do_sync_write() and do_sync_read() when applications invoke the standard
85
 
 * read() and write() system calls.
86
 
 *
87
 
 * In 2.6.19, generic_file_read() and generic_file_write() were removed,
88
 
 * necessitating this change. AIO dates as far back as 2.5.42, but the API has
89
 
 * changed over time, so for simplicity, we'll only enable it from 2.6.19 and
90
 
 * on.
91
 
 */
92
 
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
93
 
# define VMW_USE_AIO
94
 
#endif
95
 
 
96
 
 
97
 
/*
98
 
 * The alloc_inode and destroy_inode VFS ops didn't exist prior to 2.4.21.
99
 
 * Without these functions, file systems can't embed inodes.
100
 
 */
101
 
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 21)
102
 
# define VMW_EMBED_INODE
103
 
#endif
104
 
 
105
 
 
106
 
/*
107
 
 * iget() was removed from the VFS as of 2.6.25-rc1. The replacement for iget()
108
 
 * is iget_locked() which was added in 2.5.17.
109
 
 */
110
 
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 17)
111
 
# define VMW_USE_IGET_LOCKED
112
 
#endif
113
 
 
114
 
/*
115
 
 * parent_ino was born in 2.5.5. For older kernels, let's use 2.5.5
116
 
 * implementation. It uses the dcache lock which is OK because per-dentry
117
 
 * locking appeared after 2.5.5.
118
 
 */
119
 
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 5)
120
 
#define compat_parent_ino(dentry) parent_ino(dentry)
121
 
#else
122
 
#define compat_parent_ino(dentry)                                             \
123
 
({                                                                            \
124
 
   ino_t res;                                                                 \
125
 
   spin_lock(&dcache_lock);                                                   \
126
 
   res = dentry->d_parent->d_inode->i_ino;                                    \
127
 
   spin_unlock(&dcache_lock);                                                 \
128
 
   res;                                                                       \
129
 
})
130
 
#endif
131
 
 
132
 
 
133
 
/*
134
 
 * putname changed to __putname in 2.6.6.
135
 
 */
136
 
#define compat___getname() __getname()
137
 
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 6)
138
 
#define compat___putname(name) putname(name)
139
 
#else
140
 
#define compat___putname(name) __putname(name)
141
 
#endif
142
 
 
143
 
 
144
 
/*
145
 
 * inc_nlink, drop_nlink, and clear_nlink were added in 2.6.19.
146
 
 */
147
 
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19)
148
 
#define compat_inc_nlink(inode) ((inode)->i_nlink++)
149
 
#define compat_drop_nlink(inode) ((inode)->i_nlink--)
150
 
#define compat_clear_nlink(inode) ((inode)->i_nlink = 0)
151
 
#else
152
 
#define compat_inc_nlink(inode) inc_nlink(inode)
153
 
#define compat_drop_nlink(inode) drop_nlink(inode)
154
 
#define compat_clear_nlink(inode) clear_nlink(inode)
155
 
#endif
156
 
 
157
 
 
158
 
/*
159
 
 * i_size_write and i_size_read were introduced in 2.6.0-test1 
160
 
 * (though we'll look for them as of 2.6.1). They employ slightly different
161
 
 * locking in order to guarantee atomicity, depending on the length of a long,
162
 
 * whether the kernel is SMP, or whether the kernel is preemptible. Prior to
163
 
 * i_size_write and i_size_read, there was no such locking, so that's the
164
 
 * behavior we'll emulate.
165
 
 */
166
 
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 1)
167
 
#define compat_i_size_read(inode) ((inode)->i_size)
168
 
#define compat_i_size_write(inode, size) ((inode)->i_size = size)
169
 
#else
170
 
#define compat_i_size_read(inode) i_size_read(inode)
171
 
#define compat_i_size_write(inode, size) i_size_write(inode, size)
172
 
#endif
173
 
 
174
 
 
175
 
/*
176
 
 * filemap_fdatawrite was introduced in 2.5.12. Prior to that, modules used
177
 
 * filemap_fdatasync instead. In 2.4.18, both filemap_fdatawrite and 
178
 
 * filemap_fdatawait began returning status codes. Prior to that, they were 
179
 
 * void functions, so we'll just have them return 0.
180
 
 */
181
 
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 18)
182
 
#define compat_filemap_fdatawrite(mapping)                                    \
183
 
({                                                                            \
184
 
   int result = 0;                                                            \
185
 
   filemap_fdatasync(mapping);                                                \
186
 
   result;                                                                    \
187
 
})
188
 
#define compat_filemap_fdatawait(mapping)                                     \
189
 
({                                                                            \
190
 
   int result = 0;                                                            \
191
 
   filemap_fdatawait(mapping);                                                \
192
 
   result;                                                                    \
193
 
})
194
 
#elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 12)
195
 
#define compat_filemap_fdatawrite(mapping) filemap_fdatasync(mapping)
196
 
#define compat_filemap_fdatawait(mapping) filemap_fdatawait(mapping)
197
 
#else
198
 
#define compat_filemap_fdatawrite(mapping) filemap_fdatawrite(mapping)
199
 
#define compat_filemap_fdatawait(mapping) filemap_fdatawait(mapping)
200
 
#endif
201
 
 
202
 
 
203
 
/*
204
 
 * filemap_write_and_wait was introduced in 2.6.6 and exported for module use
205
 
 * in 2.6.16. It's really just a simple wrapper around filemap_fdatawrite and 
206
 
 * and filemap_fdatawait, which initiates a flush of all dirty pages, then 
207
 
 * waits for the pages to flush. The implementation here is a simplified form 
208
 
 * of the one found in 2.6.20-rc3.
209
 
 *
210
 
 * Unfortunately, it just isn't possible to implement this prior to 2.4.5, when
211
 
 * neither filemap_fdatawait nor filemap_fdatasync were exported for module
212
 
 * use. So we'll define it out and hope for the best.
213
 
 */
214
 
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 5)
215
 
#define compat_filemap_write_and_wait(mapping)
216
 
#elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16)
217
 
#define compat_filemap_write_and_wait(mapping)                                \
218
 
({                                                                            \
219
 
   int result = 0;                                                            \
220
 
   if (mapping->nrpages) {                                                    \
221
 
      result = compat_filemap_fdatawrite(mapping);                            \
222
 
      if (result != -EIO) {                                                   \
223
 
         int result2 = compat_filemap_fdatawait(mapping);                     \
224
 
         if (!result) {                                                       \
225
 
            result = result2;                                                 \
226
 
         }                                                                    \
227
 
      }                                                                       \
228
 
   }                                                                          \
229
 
   result;                                                                    \
230
 
})
231
 
#else
232
 
#define compat_filemap_write_and_wait(mapping) filemap_write_and_wait(mapping)
233
 
#endif
234
 
 
235
 
 
236
 
/*
237
 
 * invalidate_remote_inode was introduced in 2.6.0-test5. Prior to that, 
238
 
 * filesystems wishing to invalidate pages belonging to an inode called 
239
 
 * invalidate_inode_pages.
240
 
 */
241
 
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
242
 
#define compat_invalidate_remote_inode(inode) invalidate_inode_pages(inode)
243
 
#else
244
 
#define compat_invalidate_remote_inode(inode) invalidate_remote_inode(inode)
245
 
#endif
246
 
 
247
 
#endif /* __COMPAT_FS_H__ */