Whamcloud - gitweb
b=4952
[fs/lustre-release.git] / lustre / llite / llite_internal.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  */
4
5 #ifndef LLITE_INTERNAL_H
6 #define LLITE_INTERNAL_H
7
8 #include <linux/lustre_debug.h>
9
10 /*
11 struct lustre_intent_data {
12         __u64 it_lock_handle[2];
13         __u32 it_disposition;
14         __u32 it_status;
15         __u32 it_lock_mode;
16         }; */
17
18 #define LL_IT2STR(it) ((it) ? ldlm_it2str((it)->it_op) : "0")
19
20 static inline struct lookup_intent *ll_nd2it(struct nameidata *nd)
21 {
22 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
23         return &nd->intent;
24 #else
25         return nd->intent;
26 #endif
27 }
28
29 struct ll_dentry_data {
30         int                      lld_cwd_count;
31         int                      lld_mnt_count;
32         struct obd_client_handle lld_cwd_och;
33         struct obd_client_handle lld_mnt_och;
34 };
35
36 #define ll_d2d(de) ((struct ll_dentry_data*) de->d_fsdata)
37
38 extern struct file_operations ll_pgcache_seq_fops;
39
40 #define LLI_INODE_MAGIC                 0x111d0de5
41 #define LLI_INODE_DEAD                  0xdeadd00d
42 #define LLI_F_HAVE_OST_SIZE_LOCK        0
43 #define LLI_F_HAVE_MDS_SIZE_LOCK        1
44 struct ll_inode_info {
45         int                     lli_inode_magic;
46         int                     lli_size_pid;
47         struct semaphore        lli_size_sem;
48         struct semaphore        lli_open_sem;
49         struct lov_stripe_md   *lli_smd;
50         char                   *lli_symlink_name;
51         __u64                   lli_maxbytes;
52         __u64                   lli_io_epoch;
53         unsigned long           lli_flags;
54
55         /* this lock protects s_d_w and p_w_ll and mmap_cnt */
56         spinlock_t              lli_lock;
57         struct list_head        lli_pending_write_llaps;
58         int                     lli_send_done_writing;
59         atomic_t                lli_mmap_cnt;
60
61         struct list_head        lli_close_item;
62
63         /* for writepage() only to communicate to fsync */
64         int                     lli_async_rc;
65
66         struct file_operations *ll_save_ifop;
67         struct file_operations *ll_save_ffop;
68         struct file_operations *ll_save_wfop;
69         struct file_operations *ll_save_wrfop;
70 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
71         struct inode            lli_vfs_inode;
72 #endif
73 };
74
75 // FIXME: replace the name of this with LL_I to conform to kernel stuff
76 // static inline struct ll_inode_info *LL_I(struct inode *inode)
77 static inline struct ll_inode_info *ll_i2info(struct inode *inode)
78 {
79 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
80         return container_of(inode, struct ll_inode_info, lli_vfs_inode);
81 #else
82         return (struct ll_inode_info *)&(inode->u.generic_ip);
83 #endif
84 }
85
86
87 /* default to about 40meg of readahead on a given system.  That much tied
88  * up in 512k readahead requests serviced at 40ms each is about 1GB/s. */
89 #define SBI_DEFAULT_READAHEAD_MAX (40UL << (20 - PAGE_CACHE_SHIFT))
90 enum ra_stat {
91         RA_STAT_HIT = 0,
92         RA_STAT_MISS,
93         RA_STAT_DISTANT_READPAGE,
94         RA_STAT_MISS_IN_WINDOW,
95         RA_STAT_FAILED_MATCH,
96         RA_STAT_DISCARDED,
97         RA_STAT_ZERO_LEN,
98         RA_STAT_ZERO_WINDOW,
99         RA_STAT_EOF,
100         RA_STAT_MAX_IN_FLIGHT,
101         _NR_RA_STAT,
102 };
103
104 struct ll_ra_info {
105         unsigned long             ra_cur_pages;
106         unsigned long             ra_max_pages;
107         unsigned long             ra_stats[_NR_RA_STAT];
108 };
109
110 struct ll_sb_info {
111         struct list_head          ll_list;
112         /* this protects pglist and ra_info.  It isn't safe to
113          * grab from interrupt contexts */
114         spinlock_t                ll_lock;
115         struct obd_uuid           ll_sb_uuid;
116         struct obd_export        *ll_mdc_exp;
117         struct obd_export        *ll_osc_exp;
118         struct proc_dir_entry*    ll_proc_root;
119         obd_id                    ll_rootino; /* number of root inode */
120
121         struct lustre_mount_data *ll_lmd;
122         char                     *ll_instance;
123
124         int                       ll_flags;
125         struct list_head          ll_conn_chain; /* per-conn chain of SBs */
126
127         struct hlist_head         ll_orphan_dentry_list; /*please don't ask -p*/
128         struct ll_close_queue    *ll_lcq;
129
130         struct lprocfs_stats     *ll_stats; /* lprocfs stats counter */
131
132         unsigned long             ll_async_page_max;
133         unsigned long             ll_async_page_count;
134         unsigned long             ll_pglist_gen;
135         struct list_head          ll_pglist; /* all pages (llap_pglist_item) */
136
137         struct ll_ra_info         ll_ra_info;
138         unsigned int              ll_namelen;
139 };
140
141 struct ll_readahead_state {
142         spinlock_t      ras_lock;
143         unsigned long   ras_last_readpage, ras_consecutive;
144         unsigned long   ras_window_start, ras_window_len;
145         unsigned long   ras_next_readahead;
146
147 };
148
149 extern kmem_cache_t *ll_file_data_slab;
150 struct ll_file_data {
151         struct obd_client_handle fd_mds_och;
152         struct ll_readahead_state fd_ras;
153         __u32 fd_flags;
154 };
155
156 struct lustre_handle;
157 struct lov_stripe_md;
158
159 extern spinlock_t inode_lock;
160
161 extern void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi);
162 extern struct proc_dir_entry *proc_lustre_fs_root;
163
164 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
165 # define hlist_del_init list_del_init
166 #endif
167
168 static inline struct inode *ll_info2i(struct ll_inode_info *lli)
169 {
170 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
171         return &lli->lli_vfs_inode;
172 #else
173         return list_entry(lli, struct inode, u.generic_ip);
174 #endif
175 }
176
177 static inline void ll_i2uctxt(struct ll_uctxt *ctxt, struct inode *i1,
178                               struct inode *i2)
179 {
180         LASSERT(i1);
181         LASSERT(ctxt);
182
183         if (in_group_p(i1->i_gid))
184                 ctxt->gid1 = i1->i_gid;
185         else
186                 ctxt->gid1 = -1;
187
188         if (i2) {
189                 if (in_group_p(i2->i_gid))
190                         ctxt->gid2 = i2->i_gid;
191                 else
192                         ctxt->gid2 = -1;
193         } else
194                 ctxt->gid2 = 0;
195 }
196
197 struct it_cb_data {
198         struct inode *icbd_parent;
199         struct dentry **icbd_childp;
200         obd_id hash;
201 };
202
203 #define LLAP_MAGIC 98764321
204
205 extern kmem_cache_t *ll_async_page_slab;
206 extern size_t ll_async_page_slab_size;
207 struct ll_async_page {
208         int             llap_magic;
209         void            *llap_cookie;
210         struct page     *llap_page;
211         struct list_head llap_pending_write;
212          /* only trust these if the page lock is providing exclusion */
213         unsigned int     llap_write_queued:1,
214                          llap_defer_uptodate:1,
215                          llap_origin:3,
216                          llap_ra_used:1;
217         struct list_head llap_pglist_item;
218 };
219
220 enum {
221         LLAP_ORIGIN_UNKNOWN = 0,
222         LLAP_ORIGIN_READPAGE,
223         LLAP_ORIGIN_READAHEAD,
224         LLAP_ORIGIN_COMMIT_WRITE,
225         LLAP_ORIGIN_WRITEPAGE,
226         LLAP__ORIGIN_MAX,
227 };
228 extern char *llap_origins[];
229
230 #ifdef HAVE_REGISTER_CACHE
231 #define ll_register_cache(cache) register_cache(cache)
232 #define ll_unregister_cache(cache) unregister_cache(cache)
233 #else
234 #define ll_register_cache(cache) do {} while (0)
235 #define ll_unregister_cache(cache) do {} while (0)
236 #endif
237
238 /* llite/lproc_llite.c */
239 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
240                                 struct super_block *sb, char *osc, char *mdc);
241 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi);
242
243 /* llite/dir.c */
244 extern struct file_operations ll_dir_operations;
245 extern struct inode_operations ll_dir_inode_operations;
246
247 /* llite/namei.c */
248 int ll_objects_destroy(struct ptlrpc_request *request, struct inode *dir);
249 struct inode *ll_iget(struct super_block *sb, ino_t hash,
250                       struct lustre_md *lic);
251 struct dentry *ll_find_alias(struct inode *, struct dentry *);
252 int ll_mdc_cancel_unused(struct lustre_handle *, struct inode *, int flags,
253                          void *opaque);
254 int ll_mdc_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
255                         void *data, int flag);
256 void ll_prepare_mdc_op_data(struct mdc_op_data *,
257                             struct inode *i1, struct inode *i2,
258                             const char *name, int namelen, int mode);
259
260 /* llite/rw.c */
261 int ll_prepare_write(struct file *, struct page *, unsigned from, unsigned to);
262 int ll_commit_write(struct file *, struct page *, unsigned from, unsigned to);
263 int ll_writepage(struct page *page);
264 void ll_inode_fill_obdo(struct inode *inode, int cmd, struct obdo *oa);
265 void ll_ap_completion(void *data, int cmd, struct obdo *oa, int rc);
266 int llap_shrink_cache(struct ll_sb_info *sbi, int shrink_fraction);
267 extern struct cache_definition ll_cache_definition;
268 void ll_removepage(struct page *page);
269 int ll_readpage(struct file *file, struct page *page);
270 struct ll_async_page *llap_from_cookie(void *cookie);
271 struct ll_async_page *llap_from_page(struct page *page, unsigned origin);
272 struct ll_async_page *llap_cast_private(struct page *page);
273 void ll_readahead_init(struct inode *inode, struct ll_readahead_state *ras);
274 void ll_ra_accounting(struct page *page, struct address_space *mapping);
275 void ll_truncate(struct inode *inode);
276
277 /* llite/file.c */
278 extern struct file_operations ll_file_operations;
279 extern struct inode_operations ll_file_inode_operations;
280 extern int ll_inode_revalidate_it(struct dentry *, struct lookup_intent *);
281 int ll_extent_lock(struct ll_file_data *, struct inode *,
282                    struct lov_stripe_md *, int mode, ldlm_policy_data_t *,
283                    struct lustre_handle *, int ast_flags);
284 int ll_extent_unlock(struct ll_file_data *, struct inode *,
285                      struct lov_stripe_md *, int mode, struct lustre_handle *);
286 int ll_file_open(struct inode *inode, struct file *file);
287 int ll_file_release(struct inode *inode, struct file *file);
288 int ll_lsm_getattr(struct obd_export *, struct lov_stripe_md *, struct obdo *);
289 int ll_glimpse_size(struct inode *inode);
290 int ll_local_open(struct file *file, struct lookup_intent *it);
291 int ll_mdc_close(struct obd_export *mdc_exp, struct inode *inode,
292                  struct file *file);
293 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
294 int ll_getattr(struct vfsmount *mnt, struct dentry *de,
295                struct lookup_intent *it, struct kstat *stat);
296 #endif
297
298 /* llite/dcache.c */
299 void ll_intent_drop_lock(struct lookup_intent *);
300 void ll_intent_release(struct lookup_intent *);
301 extern void ll_set_dd(struct dentry *de);
302 void ll_unhash_aliases(struct inode *);
303 void ll_frob_intent(struct lookup_intent **itp, struct lookup_intent *deft);
304 void ll_lookup_finish_locks(struct lookup_intent *it, struct dentry *dentry);
305
306 /* llite/llite_lib.c */
307
308 extern struct super_operations lustre_super_operations;
309
310 char *ll_read_opt(const char *opt, char *data);
311 int ll_set_opt(const char *opt, char *data, int fl);
312 void ll_options(char *options, char **ost, char **mds, int *flags);
313 void ll_lli_init(struct ll_inode_info *lli);
314 int ll_fill_super(struct super_block *sb, void *data, int silent);
315 int lustre_fill_super(struct super_block *sb, void *data, int silent);
316 void lustre_put_super(struct super_block *sb);
317 struct inode *ll_inode_from_lock(struct ldlm_lock *lock);
318 void ll_clear_inode(struct inode *inode);
319 int ll_setattr_raw(struct inode *inode, struct iattr *attr);
320 int ll_setattr(struct dentry *de, struct iattr *attr);
321 int ll_statfs(struct super_block *sb, struct kstatfs *sfs);
322 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
323                        unsigned long maxage);
324 void ll_update_inode(struct inode *inode, struct mds_body *body,
325                      struct lov_stripe_md *lsm);
326 void ll_read_inode2(struct inode *inode, void *opaque);
327 int ll_iocontrol(struct inode *inode, struct file *file,
328                  unsigned int cmd, unsigned long arg);
329 void ll_umount_begin(struct super_block *sb);
330 int lustre_remount_fs(struct super_block *sb, int *flags, char *data);
331 int ll_prep_inode(struct obd_export *exp, struct inode **inode,
332                   struct ptlrpc_request *req, int offset, struct super_block *);
333 void lustre_dump_dentry(struct dentry *, int recur);
334 void lustre_dump_inode(struct inode *);
335 struct ll_async_page *llite_pglist_next_llap(struct ll_sb_info *sbi,
336                                              struct list_head *list);
337
338 /* llite/llite_nfs.c */
339 __u32 get_uuid2int(const char *name, int len);
340 struct dentry *ll_fh_to_dentry(struct super_block *sb, __u32 *data, int len,
341                                int fhtype, int parent);
342 int ll_dentry_to_fh(struct dentry *, __u32 *datap, int *lenp, int need_parent);
343
344 /* llite/special.c */
345 extern struct inode_operations ll_special_inode_operations;
346 extern struct file_operations ll_special_chr_inode_fops;
347 extern struct file_operations ll_special_chr_file_fops;
348 extern struct file_operations ll_special_blk_inode_fops;
349 extern struct file_operations ll_special_fifo_inode_fops;
350 extern struct file_operations ll_special_fifo_file_fops;
351 extern struct file_operations ll_special_sock_inode_fops;
352
353 /* llite/symlink.c */
354 extern struct inode_operations ll_fast_symlink_inode_operations;
355
356 /* llite/llite_close.c */
357 struct ll_close_queue {
358         spinlock_t              lcq_lock;
359         struct list_head        lcq_list;
360         wait_queue_head_t       lcq_waitq;
361         struct completion       lcq_comp;
362 };
363
364 void llap_write_pending(struct inode *inode, struct ll_async_page *llap);
365 void llap_write_complete(struct inode *inode, struct ll_async_page *llap);
366 void ll_open_complete(struct inode *inode);
367 int ll_is_inode_dirty(struct inode *inode);
368 void ll_try_done_writing(struct inode *inode);
369 void ll_queue_done_writing(struct inode *inode);
370 void ll_close_thread_shutdown(struct ll_close_queue *lcq);
371 int ll_close_thread_start(struct ll_close_queue **lcq_ret);
372
373 /* llite/llite_mmap.c */
374 #if  (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
375 typedef struct rb_root  rb_root_t;
376 typedef struct rb_node  rb_node_t;
377 #endif
378
379 struct ll_lock_tree_node;
380 struct ll_lock_tree {
381         rb_root_t                       lt_root;
382         struct list_head                lt_locked_list;
383         struct ll_file_data             *lt_fd;
384 };
385
386 int ll_teardown_mmaps(struct address_space *mapping, __u64 first, __u64 last);
387 int ll_file_mmap(struct file * file, struct vm_area_struct * vma);
388 struct ll_lock_tree_node * ll_node_from_inode(struct inode *inode, __u64 start,
389                                               __u64 end, ldlm_mode_t mode);
390 int ll_tree_lock(struct ll_lock_tree *tree, 
391                  struct ll_lock_tree_node *first_node,
392                  const char *buf, size_t count, int ast_flags);
393 int ll_tree_unlock(struct ll_lock_tree *tree);
394
395
396 #define LL_SBI_NOLCK            0x1
397
398 #define LL_MAX_BLKSIZE          (4UL * 1024 * 1024)
399
400 #if  (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
401 #define    ll_s2sbi(sb)        ((struct ll_sb_info *)((sb)->s_fs_info))
402 #define    ll_s2sbi_nocast(sb) ((sb)->s_fs_info)
403 void __d_rehash(struct dentry * entry, int lock);
404 static inline __u64 ll_ts2u64(struct timespec *time)
405 {
406         __u64 t = time->tv_sec;
407         return t;
408 }
409 #else  /* 2.4 here */
410 #define    ll_s2sbi(sb)     ((struct ll_sb_info *)((sb)->u.generic_sbp))
411 #define    ll_s2sbi_nocast(sb) ((sb)->u.generic_sbp)
412 static inline __u64 ll_ts2u64(time_t *time)
413 {
414         return *time;
415 }
416 #endif
417
418 /* don't need an addref as the sb_info should be holding one */
419 static inline struct obd_export *ll_s2obdexp(struct super_block *sb)
420 {
421         return ll_s2sbi(sb)->ll_osc_exp;
422 }
423
424 /* don't need an addref as the sb_info should be holding one */
425 static inline struct obd_export *ll_s2mdcexp(struct super_block *sb)
426 {
427         return ll_s2sbi(sb)->ll_mdc_exp;
428 }
429
430 static inline struct client_obd *sbi2mdc(struct ll_sb_info *sbi)
431 {
432         struct obd_device *obd = sbi->ll_mdc_exp->exp_obd;
433         if (obd == NULL)
434                 LBUG();
435         return &obd->u.cli;
436 }
437
438 // FIXME: replace the name of this with LL_SB to conform to kernel stuff
439 static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
440 {
441         return ll_s2sbi(inode->i_sb);
442 }
443
444 static inline struct obd_export *ll_i2obdexp(struct inode *inode)
445 {
446         return ll_s2obdexp(inode->i_sb);
447 }
448
449 static inline struct obd_export *ll_i2mdcexp(struct inode *inode)
450 {
451         return ll_s2mdcexp(inode->i_sb);
452 }
453
454 static inline void ll_inode2fid(struct ll_fid *fid, struct inode *inode)
455 {
456         mdc_pack_fid(fid, inode->i_ino, inode->i_generation,
457                      inode->i_mode & S_IFMT);
458 }
459
460 static inline int ll_mds_max_easize(struct super_block *sb)
461 {
462         return sbi2mdc(ll_s2sbi(sb))->cl_max_mds_easize;
463 }
464
465 static inline __u64 ll_file_maxbytes(struct inode *inode)
466 {
467         return ll_i2info(inode)->lli_maxbytes;
468 }
469
470 #endif /* LLITE_INTERNAL_H */