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