Whamcloud - gitweb
merge b_devel into HEAD, which will become 0.7.3
[fs/lustre-release.git] / lustre / include / linux / lustre_lite.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * lustre lite cluster file system
5  *
6  * This code is issued under the GNU General Public License.
7  * See the file COPYING in this distribution
8  *
9  * Copyright (C) 2002 Cluster File Systems, Inc. <info@clusterfs.com>
10  */
11
12
13
14 #ifndef _LL_H
15 #define _LL_H
16
17 #ifdef __KERNEL__
18
19 #include <linux/version.h>
20
21 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
22 #include <asm/statfs.h>
23 #endif
24
25 #include <linux/fs.h>
26 #include <linux/dcache.h>
27 #include <linux/ext2_fs.h>
28 #include <linux/proc_fs.h>
29
30 #include <linux/obd_class.h>
31 #include <linux/lustre_net.h>
32 #include <linux/lustre_mds.h>
33 #include <linux/lustre_ha.h>
34
35 #include <linux/rbtree.h>
36 #include <linux/lustre_compat25.h>
37 #include <linux/pagemap.h>
38
39 /* careful, this is easy to screw up */
40 #define PAGE_CACHE_MAXBYTES ((__u64)(~0UL) << PAGE_CACHE_SHIFT)
41
42 extern kmem_cache_t *ll_file_data_slab;
43 struct ll_file_data {
44         struct obd_client_handle fd_mds_och;
45         struct obd_client_handle fd_ost_och;
46         __u32 fd_flags;
47 };
48
49 struct lustre_intent_data {
50         __u64 it_lock_handle[2];
51         __u32 it_disposition;
52         __u32 it_status;
53         __u32 it_lock_mode;
54 };
55
56 #define LL_IT2STR(it) ((it) ? ldlm_it2str((it)->it_op) : "0")
57
58 static inline struct lookup_intent *ll_nd2it(struct nameidata *nd)
59 {
60 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
61         return &nd->it;
62 #else
63         return nd->it;
64 #endif
65 }
66
67 struct ll_dentry_data {
68         int                      lld_cwd_count;
69         int                      lld_mnt_count;
70         struct obd_client_handle lld_cwd_och;
71         struct obd_client_handle lld_mnt_och;
72 };
73
74 #define ll_d2d(de) ((struct ll_dentry_data*) de->d_fsdata)
75
76 extern struct file_operations ll_pgcache_seq_fops;
77
78 /* 
79  * XXX used in obdecho/echo_client.c  must move (pjb)
80  *'p' list as its a list of pages linked together
81  * by ->private.. 
82  */
83 struct plist {
84         struct page *pl_head;
85         struct page *pl_tail;
86         int pl_num;
87 };
88
89 struct ll_dirty_offsets {
90         rb_root_t       do_root;
91         spinlock_t      do_lock;
92         unsigned long   do_num_dirty;
93 };
94
95 struct ll_writeback_pages {
96         obd_count npgs, max;
97 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
98         int rw;
99         struct inode *inode;
100         struct brw_page pga[0];
101 #else
102         struct brw_page *pga;
103 #endif
104 };
105
106 struct ll_inode_info {
107         struct lov_stripe_md   *lli_smd;
108         char                   *lli_symlink_name;
109         struct semaphore        lli_open_sem;
110         struct list_head        lli_read_extents;
111         __u64                   lli_maxbytes;
112         spinlock_t              lli_read_extent_lock;
113         unsigned long           lli_flags;
114 #define LLI_F_HAVE_SIZE_LOCK    0
115
116 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
117         struct inode            lli_vfs_inode;
118 #endif
119 };
120
121 /*
122  * this lets ll_file_read tell ll_readpages how far ahead it can read
123  * and still be covered by ll_file_read's lock.  2.5 won't need this, but
124  * we have the other problem of other readpage callers making sure that
125  * they're covered by a lock..  
126  */
127 struct ll_read_extent {
128         struct list_head re_lli_item;
129         struct task_struct *re_task;
130         struct ldlm_extent re_extent;
131 };
132
133 #define LL_SUPER_MAGIC 0x0BD00BD0
134
135 #define LL_COMMITCBD_STOPPING  0x1
136 #define LL_COMMITCBD_STOPPED   0x2
137 #define LL_COMMITCBD_RUNNING   0x4
138
139 #define LL_SBI_NOLCK   0x1
140
141 struct ll_sb_info {
142         struct obd_uuid           ll_sb_uuid;
143         struct lustre_handle      ll_mdc_conn;
144         struct lustre_handle      ll_osc_conn;
145         struct proc_dir_entry*    ll_proc_root;
146         obd_id                    ll_rootino; /* number of root inode */
147
148         int                       ll_flags;
149         wait_queue_head_t         ll_commitcbd_waitq;
150         wait_queue_head_t         ll_commitcbd_ctl_waitq;
151         int                       ll_commitcbd_flags;
152         struct task_struct       *ll_commitcbd_thread;
153         time_t                    ll_commitcbd_waketime;
154         time_t                    ll_commitcbd_timeout;
155         spinlock_t                ll_commitcbd_lock;
156         struct list_head          ll_conn_chain; /* per-conn chain of SBs */
157
158         struct list_head          ll_orphan_dentry_list; /*please don't ask -p*/
159
160         struct lprocfs_stats     *ll_stats; /* lprocfs stats counter */
161 };
162
163
164 #if  (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
165 #define    ll_s2sbi(sb)     ((struct ll_sb_info *)((sb)->s_fs_info))
166 void __d_rehash(struct dentry * entry, int lock);
167 static inline __u64 ll_ts2u64(struct timespec *time)
168 {
169         __u64 t = time->tv_sec;
170         return t;
171 }
172 #else  /* 2.4 here */
173 #define    ll_s2sbi(sb)     ((struct ll_sb_info *)((sb)->u.generic_sbp))
174 static inline __u64 ll_ts2u64(time_t *time)
175 {
176         return *time;
177 }
178 #endif 
179
180 static inline struct lustre_handle *ll_s2obdconn(struct super_block *sb)
181 {
182         return &(ll_s2sbi(sb))->ll_osc_conn;
183 }
184
185 static inline struct client_obd *sbi2mdc(struct ll_sb_info *sbi)
186 {
187         struct obd_device *obd = class_conn2obd(&sbi->ll_mdc_conn);
188         if (obd == NULL)
189                 LBUG();
190         return &obd->u.cli;
191 }
192
193 // FIXME: replace the name of this with LL_SB to conform to kernel stuff
194 static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
195 {
196         return ll_s2sbi(inode->i_sb);
197 }
198
199 // FIXME: replace the name of this with LL_I to conform to kernel stuff
200 // static inline struct ll_inode_info *LL_I(struct inode *inode)
201 static inline struct ll_inode_info *ll_i2info(struct inode *inode)
202 {
203 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
204         return container_of(inode, struct ll_inode_info, lli_vfs_inode);
205 #else
206         return (struct ll_inode_info *)&(inode->u.generic_ip);
207 #endif
208 }
209
210 static inline struct lustre_handle *ll_i2obdconn(struct inode *inode)
211 {
212         return ll_s2obdconn(inode->i_sb);
213 }
214
215 static inline void ll_ino2fid(struct ll_fid *fid, obd_id ino, __u32 generation,
216                               int type);
217
218 static inline void ll_inode2fid(struct ll_fid *fid, struct inode *inode)
219 {
220         ll_ino2fid(fid, inode->i_ino, inode->i_generation,
221                    inode->i_mode & S_IFMT);
222 }
223
224 static inline int ll_mds_max_easize(struct super_block *sb)
225 {
226         return sbi2mdc(ll_s2sbi(sb))->cl_max_mds_easize;
227 }
228
229 static inline __u64 ll_file_maxbytes(struct inode *inode)
230 {
231         return ll_i2info(inode)->lli_maxbytes;
232 }
233
234 /* namei.c */
235 typedef int (*intent_finish_cb)(struct ptlrpc_request *,
236                                 struct inode *parent, struct dentry **, 
237                                 struct lookup_intent *, int offset, obd_id ino);
238 int ll_intent_lock(struct inode *parent, struct dentry **,
239                    struct lookup_intent *, int, intent_finish_cb);
240 int ll_mdc_blocking_ast(struct ldlm_lock *lock,
241                         struct ldlm_lock_desc *desc,
242                         void *data, int flag);
243 void ll_mdc_lock_set_inode(struct lustre_handle *lock, struct inode *inode);
244 void ll_prepare_mdc_op_data(struct mdc_op_data *data,
245                             struct inode *i1, struct inode *i2,
246                             const char *name, int namelen, int mode);
247
248 /* lprocfs.c */
249 enum {
250          LPROC_LL_DIRTY_HITS = 0,
251          LPROC_LL_DIRTY_MISSES,
252          LPROC_LL_WB_WRITEPAGE,
253          LPROC_LL_WB_PRESSURE,
254          LPROC_LL_WB_OK,
255          LPROC_LL_WB_FAIL,
256          LPROC_LL_READ_BYTES,
257          LPROC_LL_WRITE_BYTES,
258          LPROC_LL_BRW_READ,
259          LPROC_LL_BRW_WRITE,
260          LPROC_LL_IOCTL,
261          LPROC_LL_OPEN,
262          LPROC_LL_RELEASE,
263          LPROC_LL_MAP,
264          LPROC_LL_LLSEEK,
265          LPROC_LL_FSYNC,
266          LPROC_LL_SETATTR_RAW,
267          LPROC_LL_SETATTR,
268          LPROC_LL_TRUNC,
269
270 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
271          LPROC_LL_GETATTR,
272 #else
273          LPROC_LL_REVALIDATE,
274 #endif
275          LPROC_LL_STAFS,
276          LPROC_LL_ALLOC_INODE,
277
278          LPROC_LL_DIRECT_READ,
279          LPROC_LL_DIRECT_WRITE,
280          LPROC_LL_FILE_OPCODES
281 };
282 /* dcache.c */
283 int ll_have_md_lock(struct dentry *de);
284
285 /* dir.c */
286 extern struct file_operations ll_dir_operations;
287 extern struct inode_operations ll_dir_inode_operations;
288
289 /* file.c */
290 extern struct file_operations ll_file_operations;
291 extern struct inode_operations ll_file_inode_operations;
292 extern struct inode_operations ll_special_inode_operations;
293 struct ldlm_lock;
294 int ll_extent_lock_no_validate(struct ll_file_data *fd, struct inode *inode,
295                    struct lov_stripe_md *lsm, int mode,
296                    struct ldlm_extent *extent, struct lustre_handle *lockh);
297 int ll_extent_lock(struct ll_file_data *fd, struct inode *inode,
298                    struct lov_stripe_md *lsm, int mode,
299                    struct ldlm_extent *extent, struct lustre_handle *lockh);
300 int ll_extent_unlock(struct ll_file_data *fd, struct inode *inode,
301                      struct lov_stripe_md *lsm, int mode,
302                      struct lustre_handle *lockh);
303 int ll_create_objects(struct super_block *sb, obd_id id, uid_t uid,
304                       gid_t gid, struct lov_stripe_md **lsmp);
305 int ll_file_open(struct inode *inode, struct file *file);
306 int ll_file_release(struct inode *inode, struct file *file);
307
308
309
310 /* super.c */
311 void ll_update_inode(struct inode *, struct mds_body *, struct lov_stripe_md *);
312 int ll_setattr_raw(struct inode *inode, struct iattr *attr);
313 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
314                        unsigned long maxage);
315
316 /* symlink.c */
317 extern struct inode_operations ll_fast_symlink_inode_operations;
318 extern struct inode_operations ll_symlink_inode_operations;
319
320 #else
321 #include <linux/lustre_idl.h>
322 #endif /* __KERNEL__ */
323
324 static inline void ll_ino2fid(struct ll_fid *fid, obd_id ino, __u32 generation,
325                               int type)
326 {
327         fid->id = ino;
328         fid->generation = generation;
329         fid->f_type = type;
330 }
331
332 #include <asm/types.h>
333
334 #define LL_IOC_GETFLAGS                 _IOR ('f', 151, long)
335 #define LL_IOC_SETFLAGS                 _IOW ('f', 152, long)
336 #define LL_IOC_CLRFLAGS                 _IOW ('f', 153, long)
337 #define LL_IOC_LOV_SETSTRIPE            _IOW ('f', 154, long)
338 #define LL_IOC_LOV_GETSTRIPE            _IOW ('f', 155, long)
339
340 #define O_LOV_DELAY_CREATE 0100000000  /* hopefully this does not conflict */
341
342 #define LL_FILE_IGNORE_LOCK             0x00000001
343
344 #endif