Whamcloud - gitweb
merge b_devel into HEAD (20030703)
[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/fs.h>
20 #include <linux/ext2_fs.h>
21 #include <linux/proc_fs.h>
22
23 #include <linux/obd_class.h>
24 #include <linux/lustre_net.h>
25 #include <linux/lustre_mds.h>
26 #include <linux/lustre_ha.h>
27
28 #include <linux/rbtree.h>
29 #include <linux/lustre_compat25.h>
30 #include <linux/pagemap.h>
31
32 /* careful, this is easy to screw up */
33 #define PAGE_CACHE_MAXBYTES ((__u64)(~0UL) << PAGE_CACHE_SHIFT)
34
35 extern kmem_cache_t *ll_file_data_slab;
36 struct ll_file_data {
37         struct obd_client_handle fd_mds_och;
38         struct obd_client_handle fd_ost_och;
39         __u32 fd_flags;
40 };
41
42 struct lustre_intent_data {
43         __u64 it_lock_handle[2];
44         __u32 it_disposition;
45         __u32 it_status;
46         __u32 it_lock_mode;
47 };
48
49 struct ll_dentry_data {
50         struct semaphore      lld_it_sem;
51 };
52
53 #define ll_d2d(dentry) ((struct ll_dentry_data*) dentry->d_fsdata)
54
55 extern struct file_operations ll_pgcache_seq_fops;
56
57 struct ll_inode_info {
58         struct lov_stripe_md   *lli_smd;
59         char                   *lli_symlink_name;
60         struct semaphore        lli_open_sem;
61         struct list_head        lli_read_extents;
62         loff_t                  lli_maxbytes;
63         spinlock_t              lli_read_extent_lock;
64         unsigned long           lli_flags;
65 #define LLI_F_HAVE_SIZE_LOCK    0
66
67 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
68         struct inode            lli_vfs_inode;
69 #endif
70 };
71
72 /*
73  * this lets ll_file_read tell ll_readpages how far ahead it can read
74  * and still be covered by ll_file_read's lock.  2.5 won't need this, but
75  * we have the other problem of other readpage callers making sure that
76  * they're covered by a lock..  
77  */
78 struct ll_read_extent {
79         struct list_head re_lli_item;
80         struct task_struct *re_task;
81         struct ldlm_extent re_extent;
82 };
83
84 int ll_check_dirty( struct super_block *sb );
85 int ll_batch_writepage( struct inode *inode, struct page *page );
86
87 /* interpet return codes from intent lookup */
88 #define LL_LOOKUP_POSITIVE 1
89 #define LL_LOOKUP_NEGATIVE 2
90
91 #define LL_SUPER_MAGIC 0x0BD00BD0
92
93 #define LL_COMMITCBD_STOPPING  0x1
94 #define LL_COMMITCBD_STOPPED   0x2
95 #define LL_COMMITCBD_RUNNING   0x4
96
97 #define LL_SBI_NOLCK   0x1
98
99 struct ll_sb_info {
100         struct obd_uuid           ll_sb_uuid;
101         struct lustre_handle      ll_mdc_conn;
102         struct lustre_handle      ll_osc_conn;
103         struct proc_dir_entry*    ll_proc_root;
104         obd_id                    ll_rootino; /* number of root inode */
105
106         int                       ll_flags;
107         wait_queue_head_t         ll_commitcbd_waitq;
108         wait_queue_head_t         ll_commitcbd_ctl_waitq;
109         int                       ll_commitcbd_flags;
110         struct task_struct       *ll_commitcbd_thread;
111         time_t                    ll_commitcbd_waketime;
112         time_t                    ll_commitcbd_timeout;
113         spinlock_t                ll_commitcbd_lock;
114         struct list_head          ll_conn_chain; /* per-conn chain of SBs */
115
116         struct list_head          ll_orphan_dentry_list; /*please don't ask -p*/
117
118         struct lprocfs_stats     *ll_stats; /* lprocfs stats counter */
119 };
120
121 static inline struct ll_sb_info *ll_s2sbi(struct super_block *sb)
122 {
123 #if  (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
124         return (struct ll_sb_info *)(sb->s_fs_info);
125 #else
126         return (struct ll_sb_info *)(sb->u.generic_sbp);
127 #endif
128 }
129
130 static inline struct lustre_handle *ll_s2obdconn(struct super_block *sb)
131 {
132         return &(ll_s2sbi(sb))->ll_osc_conn;
133 }
134
135 static inline struct client_obd *sbi2mdc(struct ll_sb_info *sbi)
136 {
137         struct obd_device *obd = class_conn2obd(&sbi->ll_mdc_conn);
138         if (obd == NULL)
139                 LBUG();
140         return &obd->u.cli;
141 }
142
143 // FIXME: replace the name of this with LL_SB to conform to kernel stuff
144 static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
145 {
146         return ll_s2sbi(inode->i_sb);
147 }
148
149 static inline void d_unhash_aliases(struct inode *inode)
150 {
151         struct dentry *dentry = NULL;
152         struct list_head *tmp;
153         struct ll_sb_info *sbi = ll_i2sbi(inode);
154         ENTRY;
155
156         CDEBUG(D_INODE, "marking dentries for ino %lx/%x invalid\n",
157                inode->i_ino, inode->i_generation);
158
159         spin_lock(&dcache_lock);
160         list_for_each(tmp, &inode->i_dentry) {
161                 dentry = list_entry(tmp, struct dentry, d_alias);
162
163                 list_del_init(&dentry->d_hash);
164                 dentry->d_flags |= DCACHE_LUSTRE_INVALID;
165                 list_add(&dentry->d_hash, &sbi->ll_orphan_dentry_list);
166         }
167
168         spin_unlock(&dcache_lock);
169         EXIT;
170 }
171
172 // FIXME: replace the name of this with LL_I to conform to kernel stuff
173 // static inline struct ll_inode_info *LL_I(struct inode *inode)
174 static inline struct ll_inode_info *ll_i2info(struct inode *inode)
175 {
176 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
177         return container_of(inode, struct ll_inode_info, lli_vfs_inode);
178 #else
179         return (struct ll_inode_info *)&(inode->u.generic_ip);
180 #endif
181 }
182
183 static inline struct lustre_handle *ll_i2obdconn(struct inode *inode)
184 {
185         return ll_s2obdconn(inode->i_sb);
186 }
187
188 static inline void ll_ino2fid(struct ll_fid *fid, obd_id ino, __u32 generation,
189                               int type);
190
191 static inline void ll_inode2fid(struct ll_fid *fid, struct inode *inode)
192 {
193         ll_ino2fid(fid, inode->i_ino, inode->i_generation,
194                    inode->i_mode & S_IFMT);
195 }
196
197 static inline int ll_mds_max_easize(struct super_block *sb)
198 {
199         return sbi2mdc(ll_s2sbi(sb))->cl_max_mds_easize;
200 }
201
202 static inline loff_t ll_file_maxbytes(struct inode *inode)
203 {
204         return ll_i2info(inode)->lli_maxbytes;
205 }
206
207 /* namei.c */
208 int ll_lock(struct inode *dir, struct dentry *dentry,
209             struct lookup_intent *it, struct lustre_handle *lockh);
210 int ll_unlock(__u32 mode, struct lustre_handle *lockh);
211
212 typedef int (*intent_finish_cb)(int flag, struct ptlrpc_request *,
213                                 struct inode *parent, struct dentry **, 
214                                 struct lookup_intent *, int offset, obd_id ino);
215 int ll_intent_lock(struct inode *parent, struct dentry **,
216                    struct lookup_intent *, intent_finish_cb);
217 int ll_mdc_blocking_ast(struct ldlm_lock *lock,
218                         struct ldlm_lock_desc *desc,
219                         void *data, int flag);
220 void ll_mdc_lock_set_inode(struct lustre_handle *lock, struct inode *inode);
221 void ll_prepare_mdc_op_data(struct mdc_op_data *data,
222                             struct inode *i1, struct inode *i2,
223                             const char *name, int namelen, int mode);
224
225 /* dcache.c */
226 void ll_intent_release(struct dentry *, struct lookup_intent *);
227
228 /****
229
230 I originally implmented these as functions, then realized a macro
231 would be more helpful for debugging, so the CDEBUG messages show
232 the current calling function.  The orignal functions are in llite/dcache.c
233
234 int ll_save_intent(struct dentry * de, struct lookup_intent * it);
235 struct lookup_intent * ll_get_intent(struct dentry * de);
236 ****/
237
238 #define IT_RELEASED_MAGIC 0xDEADCAFE
239
240 #define LL_SAVE_INTENT(de, it)                                                 \
241 do {                                                                           \
242         LASSERT(ll_d2d(de) != NULL);                                           \
243                                                                                \
244         down(&ll_d2d(de)->lld_it_sem);                                         \
245         LASSERT(de->d_it == NULL);                                             \
246         de->d_it = it;                                                         \
247         CDEBUG(D_DENTRY,                                                       \
248                "D_IT DOWN dentry %p fsdata %p intent: %p %s sem %d\n",         \
249                de, ll_d2d(de), de->d_it, ldlm_it2str(de->d_it->it_op),         \
250                atomic_read(&(ll_d2d(de)->lld_it_sem.count)));                  \
251 } while(0)
252
253 #define LL_GET_INTENT(de, it)                                                  \
254 do {                                                                           \
255         it = de->d_it;                                                         \
256                                                                                \
257         LASSERT(ll_d2d(de) != NULL);                                           \
258         LASSERT(it);                                                           \
259         LASSERT(it->it_op != IT_RELEASED_MAGIC);                               \
260                                                                                \
261         CDEBUG(D_DENTRY, "D_IT UP dentry %p fsdata %p intent: %p %s\n",        \
262                de, ll_d2d(de), de->d_it, ldlm_it2str(de->d_it->it_op));        \
263         de->d_it = NULL;                                                       \
264         it->it_op = IT_RELEASED_MAGIC;                                         \
265         up(&ll_d2d(de)->lld_it_sem);                                           \
266 } while(0)
267
268 #define LL_IT2STR(it) ((it) ? ldlm_it2str((it)->it_op) : "0")
269
270 enum {
271          LPROC_LL_DIRTY_HITS = 0,
272          LPROC_LL_DIRTY_MISSES,
273          LPROC_LL_WB_WRITEPAGE,
274          LPROC_LL_WB_PRESSURE,
275          LPROC_LL_WB_OK,
276          LPROC_LL_WB_FAIL,
277          LPROC_LL_READ_BYTES,
278          LPROC_LL_WRITE_BYTES,
279          LPROC_LL_BRW_READ,
280          LPROC_LL_BRW_WRITE,
281          LPROC_LL_IOCTL,
282          LPROC_LL_OPEN,
283          LPROC_LL_RELEASE,
284          LPROC_LL_MAP,
285          LPROC_LL_LLSEEK,
286          LPROC_LL_FSYNC,
287          LPROC_LL_SETATTR_RAW,
288          LPROC_LL_SETATTR,
289          LPROC_LL_TRUNC,
290
291 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
292          LPROC_LL_GETATTR,
293 #else
294          LPROC_LL_REVALIDATE,
295 #endif
296          LPROC_LL_STAFS,
297          LPROC_LL_ALLOC_INODE,
298
299          LPROC_LL_DIRECT_READ,
300          LPROC_LL_DIRECT_WRITE,
301          LPROC_LL_FILE_OPCODES
302 };
303 /* dcache.c */
304 int ll_have_md_lock(struct dentry *de);
305
306 /* dir.c */
307 extern struct file_operations ll_dir_operations;
308 extern struct inode_operations ll_dir_inode_operations;
309
310 /* file.c */
311 extern struct file_operations ll_file_operations;
312 extern struct inode_operations ll_file_inode_operations;
313 extern struct inode_operations ll_special_inode_operations;
314 struct ldlm_lock;
315 int ll_extent_lock_callback(struct ldlm_lock *, struct ldlm_lock_desc *,
316                             void *data, int flag);
317 int ll_extent_lock_no_validate(struct ll_file_data *fd, struct inode *inode,
318                    struct lov_stripe_md *lsm, int mode,
319                    struct ldlm_extent *extent, struct lustre_handle *lockh);
320 int ll_extent_lock(struct ll_file_data *fd, struct inode *inode,
321                    struct lov_stripe_md *lsm, int mode,
322                    struct ldlm_extent *extent, struct lustre_handle *lockh);
323 int ll_extent_unlock(struct ll_file_data *fd, struct inode *inode,
324                      struct lov_stripe_md *lsm, int mode,
325                      struct lustre_handle *lockh);
326 int ll_create_objects(struct super_block *sb, obd_id id, uid_t uid,
327                       gid_t gid, struct lov_stripe_md **lsmp);
328 int ll_file_open(struct inode *inode, struct file *file);
329 int ll_file_release(struct inode *inode, struct file *file);
330
331
332 /* rw.c */
333 struct page *ll_getpage(struct inode *inode, unsigned long offset,
334                         int create, int locked);
335 void ll_truncate(struct inode *inode);
336
337 /* super.c */
338 void ll_update_inode(struct inode *, struct mds_body *, struct lov_stripe_md *);
339 int ll_setattr_raw(struct inode *inode, struct iattr *attr);
340
341 /* symlink.c */
342 extern struct inode_operations ll_fast_symlink_inode_operations;
343 extern struct inode_operations ll_symlink_inode_operations;
344
345 /* sysctl.c */
346 void ll_sysctl_init(void);
347 void ll_sysctl_clean(void);
348
349 #else
350 #include <linux/lustre_idl.h>
351 #endif /* __KERNEL__ */
352
353 static inline void ll_ino2fid(struct ll_fid *fid,
354                               obd_id ino,
355                               __u32 generation,
356                               int type)
357 {
358         fid->id = ino;
359         fid->generation = generation;
360         fid->f_type = type;
361 }
362
363 struct ll_read_inode2_cookie {
364         struct mds_body      *lic_body;
365         struct lov_stripe_md *lic_lsm;
366 };
367
368 #include <asm/types.h>
369
370 #define LL_IOC_GETFLAGS                 _IOR ('f', 151, long)
371 #define LL_IOC_SETFLAGS                 _IOW ('f', 152, long)
372 #define LL_IOC_CLRFLAGS                 _IOW ('f', 153, long)
373 #define LL_IOC_LOV_SETSTRIPE            _IOW ('f', 154, long)
374 #define LL_IOC_LOV_GETSTRIPE            _IOW ('f', 155, long)
375
376 #define O_LOV_DELAY_CREATE 0100000000  /* hopefully this does not conflict */
377
378 #define LL_FILE_IGNORE_LOCK             0x00000001
379
380 #endif