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