[XFS] kill the v_flag member in struct bhv_vnode
[firefly-linux-kernel-4.4.55.git] / fs / xfs / linux-2.6 / xfs_vnode.h
1 /*
2  * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3  * All Rights Reserved.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it would be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write the Free Software Foundation,
16  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18 #ifndef __XFS_VNODE_H__
19 #define __XFS_VNODE_H__
20
21 struct file;
22 struct bhv_vfs;
23 struct bhv_vattr;
24 struct xfs_iomap;
25 struct attrlist_cursor_kern;
26
27 typedef struct dentry   bhv_vname_t;
28 typedef __u64           bhv_vnumber_t;
29
30 typedef struct bhv_vnode {
31         bhv_vnumber_t   v_number;               /* in-core vnode number */
32         atomic_t        v_iocount;              /* outstanding I/O count */
33 #ifdef XFS_VNODE_TRACE
34         struct ktrace   *v_trace;               /* trace header structure    */
35 #endif
36         struct inode    v_inode;                /* Linux inode */
37         /* inode MUST be last */
38 } bhv_vnode_t;
39
40 #define VN_ISLNK(vp)    S_ISLNK((vp)->v_inode.i_mode)
41 #define VN_ISREG(vp)    S_ISREG((vp)->v_inode.i_mode)
42 #define VN_ISDIR(vp)    S_ISDIR((vp)->v_inode.i_mode)
43 #define VN_ISCHR(vp)    S_ISCHR((vp)->v_inode.i_mode)
44 #define VN_ISBLK(vp)    S_ISBLK((vp)->v_inode.i_mode)
45
46 /*
47  * Vnode to Linux inode mapping.
48  */
49 static inline struct bhv_vnode *vn_from_inode(struct inode *inode)
50 {
51         return container_of(inode, bhv_vnode_t, v_inode);
52 }
53 static inline struct inode *vn_to_inode(struct bhv_vnode *vnode)
54 {
55         return &vnode->v_inode;
56 }
57
58 /*
59  * Values for the vop_rwlock/rwunlock flags parameter.
60  */
61 typedef enum bhv_vrwlock {
62         VRWLOCK_NONE,
63         VRWLOCK_READ,
64         VRWLOCK_WRITE,
65         VRWLOCK_WRITE_DIRECT,
66         VRWLOCK_TRY_READ,
67         VRWLOCK_TRY_WRITE
68 } bhv_vrwlock_t;
69
70 /*
71  * Return values for xfs_inactive.  A return value of
72  * VN_INACTIVE_NOCACHE implies that the file system behavior
73  * has disassociated its state and bhv_desc_t from the vnode.
74  */
75 #define VN_INACTIVE_CACHE       0
76 #define VN_INACTIVE_NOCACHE     1
77
78 /*
79  * Flags for read/write calls - same values as IRIX
80  */
81 #define IO_ISAIO        0x00001         /* don't wait for completion */
82 #define IO_ISDIRECT     0x00004         /* bypass page cache */
83 #define IO_INVIS        0x00020         /* don't update inode timestamps */
84
85 /*
86  * Flags for vop_iflush call
87  */
88 #define FLUSH_SYNC              1       /* wait for flush to complete   */
89 #define FLUSH_INODE             2       /* flush the inode itself       */
90 #define FLUSH_LOG               4       /* force the last log entry for
91                                          * this inode out to disk       */
92
93 /*
94  * Flush/Invalidate options for vop_toss/flush/flushinval_pages.
95  */
96 #define FI_NONE                 0       /* none */
97 #define FI_REMAPF               1       /* Do a remapf prior to the operation */
98 #define FI_REMAPF_LOCKED        2       /* Do a remapf prior to the operation.
99                                            Prevent VM access to the pages until
100                                            the operation completes. */
101
102 /*
103  * Vnode attributes.  va_mask indicates those attributes the caller
104  * wants to set or extract.
105  */
106 typedef struct bhv_vattr {
107         int             va_mask;        /* bit-mask of attributes present */
108         mode_t          va_mode;        /* file access mode and type */
109         xfs_nlink_t     va_nlink;       /* number of references to file */
110         uid_t           va_uid;         /* owner user id */
111         gid_t           va_gid;         /* owner group id */
112         xfs_ino_t       va_nodeid;      /* file id */
113         xfs_off_t       va_size;        /* file size in bytes */
114         u_long          va_blocksize;   /* blocksize preferred for i/o */
115         struct timespec va_atime;       /* time of last access */
116         struct timespec va_mtime;       /* time of last modification */
117         struct timespec va_ctime;       /* time file changed */
118         u_int           va_gen;         /* generation number of file */
119         xfs_dev_t       va_rdev;        /* device the special file represents */
120         __int64_t       va_nblocks;     /* number of blocks allocated */
121         u_long          va_xflags;      /* random extended file flags */
122         u_long          va_extsize;     /* file extent size */
123         u_long          va_nextents;    /* number of extents in file */
124         u_long          va_anextents;   /* number of attr extents in file */
125         prid_t          va_projid;      /* project id */
126 } bhv_vattr_t;
127
128 /*
129  * setattr or getattr attributes
130  */
131 #define XFS_AT_TYPE             0x00000001
132 #define XFS_AT_MODE             0x00000002
133 #define XFS_AT_UID              0x00000004
134 #define XFS_AT_GID              0x00000008
135 #define XFS_AT_FSID             0x00000010
136 #define XFS_AT_NODEID           0x00000020
137 #define XFS_AT_NLINK            0x00000040
138 #define XFS_AT_SIZE             0x00000080
139 #define XFS_AT_ATIME            0x00000100
140 #define XFS_AT_MTIME            0x00000200
141 #define XFS_AT_CTIME            0x00000400
142 #define XFS_AT_RDEV             0x00000800
143 #define XFS_AT_BLKSIZE          0x00001000
144 #define XFS_AT_NBLOCKS          0x00002000
145 #define XFS_AT_VCODE            0x00004000
146 #define XFS_AT_MAC              0x00008000
147 #define XFS_AT_UPDATIME         0x00010000
148 #define XFS_AT_UPDMTIME         0x00020000
149 #define XFS_AT_UPDCTIME         0x00040000
150 #define XFS_AT_ACL              0x00080000
151 #define XFS_AT_CAP              0x00100000
152 #define XFS_AT_INF              0x00200000
153 #define XFS_AT_XFLAGS           0x00400000
154 #define XFS_AT_EXTSIZE          0x00800000
155 #define XFS_AT_NEXTENTS         0x01000000
156 #define XFS_AT_ANEXTENTS        0x02000000
157 #define XFS_AT_PROJID           0x04000000
158 #define XFS_AT_SIZE_NOPERM      0x08000000
159 #define XFS_AT_GENCOUNT         0x10000000
160
161 #define XFS_AT_ALL      (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
162                 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
163                 XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
164                 XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|XFS_AT_MAC|\
165                 XFS_AT_ACL|XFS_AT_CAP|XFS_AT_INF|XFS_AT_XFLAGS|XFS_AT_EXTSIZE|\
166                 XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_PROJID|XFS_AT_GENCOUNT)
167
168 #define XFS_AT_STAT     (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
169                 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
170                 XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
171                 XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_PROJID)
172
173 #define XFS_AT_TIMES    (XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME)
174
175 #define XFS_AT_UPDTIMES (XFS_AT_UPDATIME|XFS_AT_UPDMTIME|XFS_AT_UPDCTIME)
176
177 #define XFS_AT_NOSET    (XFS_AT_NLINK|XFS_AT_RDEV|XFS_AT_FSID|XFS_AT_NODEID|\
178                 XFS_AT_TYPE|XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|\
179                 XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_GENCOUNT)
180
181 /*
182  *  Modes.
183  */
184 #define VSUID   S_ISUID         /* set user id on execution */
185 #define VSGID   S_ISGID         /* set group id on execution */
186 #define VSVTX   S_ISVTX         /* save swapped text even after use */
187 #define VREAD   S_IRUSR         /* read, write, execute permissions */
188 #define VWRITE  S_IWUSR
189 #define VEXEC   S_IXUSR
190
191 #define MODEMASK S_IALLUGO      /* mode bits plus permission bits */
192
193 /*
194  * Check whether mandatory file locking is enabled.
195  */
196 #define MANDLOCK(vp, mode)      \
197         (VN_ISREG(vp) && ((mode) & (VSGID|(VEXEC>>3))) == VSGID)
198
199 extern void     vn_init(void);
200 extern bhv_vnode_t      *vn_initialize(struct inode *);
201 extern int      vn_revalidate(struct bhv_vnode *);
202 extern int      __vn_revalidate(struct bhv_vnode *, bhv_vattr_t *);
203 extern void     vn_revalidate_core(struct bhv_vnode *, bhv_vattr_t *);
204
205 extern void     vn_iowait(struct bhv_vnode *vp);
206 extern void     vn_iowake(struct bhv_vnode *vp);
207
208 extern void     vn_ioerror(struct bhv_vnode *vp, int error, char *f, int l);
209
210 static inline int vn_count(struct bhv_vnode *vp)
211 {
212         return atomic_read(&vn_to_inode(vp)->i_count);
213 }
214
215 /*
216  * Vnode reference counting functions (and macros for compatibility).
217  */
218 extern bhv_vnode_t      *vn_hold(struct bhv_vnode *);
219
220 #if defined(XFS_VNODE_TRACE)
221 #define VN_HOLD(vp)             \
222         ((void)vn_hold(vp),     \
223           vn_trace_hold(vp, __FILE__, __LINE__, (inst_t *)__return_address))
224 #define VN_RELE(vp)             \
225           (vn_trace_rele(vp, __FILE__, __LINE__, (inst_t *)__return_address), \
226            iput(vn_to_inode(vp)))
227 #else
228 #define VN_HOLD(vp)             ((void)vn_hold(vp))
229 #define VN_RELE(vp)             (iput(vn_to_inode(vp)))
230 #endif
231
232 static inline struct bhv_vnode *vn_grab(struct bhv_vnode *vp)
233 {
234         struct inode *inode = igrab(vn_to_inode(vp));
235         return inode ? vn_from_inode(inode) : NULL;
236 }
237
238 /*
239  * Vname handling macros.
240  */
241 #define VNAME(dentry)           ((char *) (dentry)->d_name.name)
242 #define VNAMELEN(dentry)        ((dentry)->d_name.len)
243 #define VNAME_TO_VNODE(dentry)  (vn_from_inode((dentry)->d_inode))
244
245 /*
246  * Dealing with bad inodes
247  */
248 static inline void vn_mark_bad(struct bhv_vnode *vp)
249 {
250         make_bad_inode(vn_to_inode(vp));
251 }
252
253 static inline int VN_BAD(struct bhv_vnode *vp)
254 {
255         return is_bad_inode(vn_to_inode(vp));
256 }
257
258 /*
259  * Extracting atime values in various formats
260  */
261 static inline void vn_atime_to_bstime(bhv_vnode_t *vp, xfs_bstime_t *bs_atime)
262 {
263         bs_atime->tv_sec = vp->v_inode.i_atime.tv_sec;
264         bs_atime->tv_nsec = vp->v_inode.i_atime.tv_nsec;
265 }
266
267 static inline void vn_atime_to_timespec(bhv_vnode_t *vp, struct timespec *ts)
268 {
269         *ts = vp->v_inode.i_atime;
270 }
271
272 static inline void vn_atime_to_time_t(bhv_vnode_t *vp, time_t *tt)
273 {
274         *tt = vp->v_inode.i_atime.tv_sec;
275 }
276
277 /*
278  * Some useful predicates.
279  */
280 #define VN_MAPPED(vp)   mapping_mapped(vn_to_inode(vp)->i_mapping)
281 #define VN_CACHED(vp)   (vn_to_inode(vp)->i_mapping->nrpages)
282 #define VN_DIRTY(vp)    mapping_tagged(vn_to_inode(vp)->i_mapping, \
283                                         PAGECACHE_TAG_DIRTY)
284
285 /*
286  * Flags to vop_setattr/getattr.
287  */
288 #define ATTR_UTIME      0x01    /* non-default utime(2) request */
289 #define ATTR_DMI        0x08    /* invocation from a DMI function */
290 #define ATTR_LAZY       0x80    /* set/get attributes lazily */
291 #define ATTR_NONBLOCK   0x100   /* return EAGAIN if operation would block */
292 #define ATTR_NOLOCK     0x200   /* Don't grab any conflicting locks */
293 #define ATTR_NOSIZETOK  0x400   /* Don't get the SIZE token */
294
295 /*
296  * Flags to vop_fsync/reclaim.
297  */
298 #define FSYNC_NOWAIT    0       /* asynchronous flush */
299 #define FSYNC_WAIT      0x1     /* synchronous fsync or forced reclaim */
300 #define FSYNC_INVAL     0x2     /* flush and invalidate cached data */
301 #define FSYNC_DATA      0x4     /* synchronous fsync of data only */
302
303 /*
304  * Tracking vnode activity.
305  */
306 #if defined(XFS_VNODE_TRACE)
307
308 #define VNODE_TRACE_SIZE        16              /* number of trace entries */
309 #define VNODE_KTRACE_ENTRY      1
310 #define VNODE_KTRACE_EXIT       2
311 #define VNODE_KTRACE_HOLD       3
312 #define VNODE_KTRACE_REF        4
313 #define VNODE_KTRACE_RELE       5
314
315 extern void vn_trace_entry(struct bhv_vnode *, const char *, inst_t *);
316 extern void vn_trace_exit(struct bhv_vnode *, const char *, inst_t *);
317 extern void vn_trace_hold(struct bhv_vnode *, char *, int, inst_t *);
318 extern void vn_trace_ref(struct bhv_vnode *, char *, int, inst_t *);
319 extern void vn_trace_rele(struct bhv_vnode *, char *, int, inst_t *);
320
321 #define VN_TRACE(vp)            \
322         vn_trace_ref(vp, __FILE__, __LINE__, (inst_t *)__return_address)
323 #else
324 #define vn_trace_entry(a,b,c)
325 #define vn_trace_exit(a,b,c)
326 #define vn_trace_hold(a,b,c,d)
327 #define vn_trace_ref(a,b,c,d)
328 #define vn_trace_rele(a,b,c,d)
329 #define VN_TRACE(vp)
330 #endif
331
332 #endif  /* __XFS_VNODE_H__ */