Whamcloud - gitweb
Branch b1_6
[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/ext2_fs.h>
9 #ifdef CONFIG_FS_POSIX_ACL
10 # include <linux/fs.h>
11 #ifdef HAVE_XATTR_ACL
12 # include <linux/xattr_acl.h>
13 #endif
14 #ifdef HAVE_LINUX_POSIX_ACL_XATTR_H
15 # include <linux/posix_acl_xattr.h>
16 #endif
17 #endif
18
19 #include <lustre_debug.h>
20 #include <lustre_ver.h>
21 #include <linux/lustre_version.h>
22 #include <lustre_disk.h>  /* for s2sbi */
23  
24 /*
25 struct lustre_intent_data {
26         __u64 it_lock_handle[2];
27         __u32 it_disposition;
28         __u32 it_status;
29         __u32 it_lock_mode;
30         }; */
31
32 /* If there is no FMODE_EXEC defined, make it to match nothing */
33 #ifndef FMODE_EXEC
34 #define FMODE_EXEC 0
35 #endif
36
37 #define LL_IT2STR(it) ((it) ? ldlm_it2str((it)->it_op) : "0")
38 #define LUSTRE_FPRIVATE(file) ((file)->private_data)
39
40 #ifdef HAVE_VFS_INTENT_PATCHES
41 static inline struct lookup_intent *ll_nd2it(struct nameidata *nd)
42 {
43 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
44         return &nd->intent;
45 #else
46         return nd->intent;
47 #endif
48 }
49 #endif
50
51 struct ll_dentry_data {
52         int                      lld_cwd_count;
53         int                      lld_mnt_count;
54         struct obd_client_handle lld_cwd_och;
55         struct obd_client_handle lld_mnt_och;
56 #ifndef HAVE_VFS_INTENT_PATCHES
57         struct lookup_intent     *lld_it;
58 #endif
59 };
60
61 #define ll_d2d(de) ((struct ll_dentry_data*) de->d_fsdata)
62
63 extern struct file_operations ll_pgcache_seq_fops;
64
65 #define LLI_INODE_MAGIC                 0x111d0de5
66 #define LLI_INODE_DEAD                  0xdeadd00d
67 #define LLI_F_HAVE_OST_SIZE_LOCK        0
68 #define LLI_F_HAVE_MDS_SIZE_LOCK        1
69 #define LLI_F_CONTENDED                 2
70 #define LLI_F_SRVLOCK                   3
71
72 struct ll_inode_info {
73         int                     lli_inode_magic;
74         struct semaphore        lli_size_sem;           /* protect open and change size */
75         void                   *lli_size_sem_owner;
76         struct semaphore        lli_write_sem;
77         struct lov_stripe_md   *lli_smd;
78         char                   *lli_symlink_name;
79         __u64                   lli_maxbytes;
80         __u64                   lli_io_epoch;
81         unsigned long           lli_flags;
82         cfs_time_t              lli_contention_time;
83
84         /* this lock protects s_d_w and p_w_ll and mmap_cnt */
85         spinlock_t              lli_lock;
86 #ifdef HAVE_CLOSE_THREAD
87         struct list_head        lli_pending_write_llaps;
88         struct list_head        lli_close_item;
89         int                     lli_send_done_writing;
90 #endif
91         atomic_t                lli_mmap_cnt;
92
93         /* for writepage() only to communicate to fsync */
94         int                     lli_async_rc;
95
96         struct posix_acl       *lli_posix_acl;
97
98         struct list_head        lli_dead_list;
99
100         struct semaphore        lli_och_sem; /* Protects access to och pointers
101                                                 and their usage counters */
102         /* We need all three because every inode may be opened in different
103            modes */
104         struct obd_client_handle *lli_mds_read_och;
105         __u64                   lli_open_fd_read_count;
106         struct obd_client_handle *lli_mds_write_och;
107         __u64                   lli_open_fd_write_count;
108         struct obd_client_handle *lli_mds_exec_och;
109         __u64                   lli_open_fd_exec_count;
110
111 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
112         struct inode            lli_vfs_inode;
113 #endif
114
115         /* metadata stat-ahead */
116         pid_t                   lli_opendir_pid;
117         struct ll_statahead_info *lli_sai;
118 };
119
120 /*
121  * Locking to guarantee consistency of non-atomic updates to long long i_size,
122  * consistency between file size and KMS, and consistency within
123  * ->lli_smd->lsm_oinfo[]'s.
124  *
125  * Implemented by ->lli_size_sem and ->lsm_sem, nested in that order.
126  */
127
128 void ll_inode_size_lock(struct inode *inode, int lock_lsm);
129 void ll_inode_size_unlock(struct inode *inode, int unlock_lsm);
130
131 // FIXME: replace the name of this with LL_I to conform to kernel stuff
132 // static inline struct ll_inode_info *LL_I(struct inode *inode)
133 static inline struct ll_inode_info *ll_i2info(struct inode *inode)
134 {
135 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
136         return container_of(inode, struct ll_inode_info, lli_vfs_inode);
137 #else
138         CLASSERT(sizeof(inode->u) >= sizeof(struct ll_inode_info));
139         return (struct ll_inode_info *)&(inode->u.generic_ip);
140 #endif
141 }
142
143 /* default to about 40meg of readahead on a given system.  That much tied
144  * up in 512k readahead requests serviced at 40ms each is about 1GB/s. */
145 #define SBI_DEFAULT_READAHEAD_MAX (40UL << (20 - CFS_PAGE_SHIFT))
146
147 /* default to read-ahead full files smaller than 2MB on the second read */
148 #define SBI_DEFAULT_READAHEAD_WHOLE_MAX (2UL << (20 - CFS_PAGE_SHIFT))
149
150 enum ra_stat {
151         RA_STAT_HIT = 0,
152         RA_STAT_MISS,
153         RA_STAT_DISTANT_READPAGE,
154         RA_STAT_MISS_IN_WINDOW,
155         RA_STAT_FAILED_GRAB_PAGE,
156         RA_STAT_FAILED_MATCH,
157         RA_STAT_DISCARDED,
158         RA_STAT_ZERO_LEN,
159         RA_STAT_ZERO_WINDOW,
160         RA_STAT_EOF,
161         RA_STAT_MAX_IN_FLIGHT,
162         RA_STAT_WRONG_GRAB_PAGE,
163         _NR_RA_STAT,
164 };
165
166 struct ll_ra_info {
167         unsigned long             ra_cur_pages;
168         unsigned long             ra_max_pages;
169         unsigned long             ra_max_read_ahead_whole_pages;
170         unsigned long             ra_stats[_NR_RA_STAT];
171 };
172
173 /* LL_HIST_MAX=32 causes an overflow */
174 #define LL_HIST_MAX 28
175 #define LL_HIST_START 12 /* buckets start at 2^12 = 4k */
176 #define LL_PROCESS_HIST_MAX 10
177 struct per_process_info {
178         pid_t pid;
179         struct obd_histogram pp_r_hist;
180         struct obd_histogram pp_w_hist;
181 };
182
183 /* pp_extents[LL_PROCESS_HIST_MAX] will hold the combined process info */
184 struct ll_rw_extents_info {
185         struct per_process_info pp_extents[LL_PROCESS_HIST_MAX + 1];
186 };
187
188 #define LL_OFFSET_HIST_MAX 100
189 struct ll_rw_process_info {
190         pid_t                     rw_pid;
191         int                       rw_op;
192         loff_t                    rw_range_start;
193         loff_t                    rw_range_end;
194         loff_t                    rw_last_file_pos;
195         loff_t                    rw_offset;
196         size_t                    rw_smallest_extent;
197         size_t                    rw_largest_extent;
198         struct file               *rw_last_file;
199 };
200
201
202 enum stats_track_type {
203         STATS_TRACK_ALL = 0,  /* track all processes */
204         STATS_TRACK_PID,      /* track process with this pid */
205         STATS_TRACK_PPID,     /* track processes with this ppid */
206         STATS_TRACK_GID,      /* track processes with this gid */
207         STATS_TRACK_LAST,
208 };
209
210 /* flags for sbi->ll_flags */
211 #define LL_SBI_NOLCK            0x01 /* DLM locking disabled (directio-only) */
212 #define LL_SBI_DATA_CHECKSUM    0x02 /* checksum each page on the wire */
213 #define LL_SBI_FLOCK            0x04
214 #define LL_SBI_USER_XATTR       0x08 /* support user xattr */
215 #define LL_SBI_ACL              0x10 /* support ACL */
216 #define LL_SBI_JOIN             0x20 /* support JOIN */
217 #define LL_SBI_LOCALFLOCK       0x40 /* Local flocks support by kernel */
218 #define LL_SBI_LRU_RESIZE       0x80 /* support lru resize */
219 #define LL_SBI_LLITE_CHECKSUM  0x100 /* checksum each page in memory */
220
221 /* default value for ll_sb_info->contention_time */
222 #define SBI_DEFAULT_CONTENTION_SECONDS     60
223
224 struct ll_sb_info {
225         struct list_head          ll_list;
226         /* this protects pglist and ra_info.  It isn't safe to
227          * grab from interrupt contexts */
228         spinlock_t                ll_lock;
229         spinlock_t                ll_pp_extent_lock; /* Lock for pp_extent entries */
230         spinlock_t                ll_process_lock; /* Lock for ll_rw_process_info */
231         struct obd_uuid           ll_sb_uuid;
232         struct obd_export        *ll_mdc_exp;
233         struct obd_export        *ll_osc_exp;
234         struct proc_dir_entry    *ll_proc_root;
235         obd_id                    ll_rootino; /* number of root inode */
236
237         int                       ll_flags;
238         struct list_head          ll_conn_chain; /* per-conn chain of SBs */
239         struct lustre_client_ocd  ll_lco;
240
241         struct list_head          ll_orphan_dentry_list; /*please don't ask -p*/
242         struct ll_close_queue    *ll_lcq;
243
244         struct lprocfs_stats     *ll_stats; /* lprocfs stats counter */
245
246         unsigned long             ll_async_page_max;
247         unsigned long             ll_async_page_count;
248         unsigned long             ll_pglist_gen;
249         struct list_head          ll_pglist; /* all pages (llap_pglist_item) */
250
251         unsigned                  ll_contention_time; /* seconds */
252
253         struct ll_ra_info         ll_ra_info;
254         unsigned int              ll_namelen;
255         struct file_operations   *ll_fop;
256
257 #ifdef HAVE_EXPORT___IGET
258         struct list_head          ll_deathrow; /* inodes to be destroyed (b1443) */
259         spinlock_t                ll_deathrow_lock;
260 #endif
261         /* =0 - hold lock over whole read/write
262          * >0 - max. chunk to be read/written w/o lock re-acquiring */
263         unsigned long             ll_max_rw_chunk;
264
265         /* Statistics */
266         struct ll_rw_extents_info ll_rw_extents_info;
267         int                       ll_extent_process_count;
268         struct ll_rw_process_info ll_rw_process_info[LL_PROCESS_HIST_MAX];
269         unsigned int              ll_offset_process_count;
270         struct ll_rw_process_info ll_rw_offset_info[LL_OFFSET_HIST_MAX];
271         unsigned int              ll_rw_offset_entry_count;
272         enum stats_track_type     ll_stats_track_type;
273         int                       ll_stats_track_id;
274         int                       ll_rw_stats_on;
275         dev_t                     ll_sdev_orig; /* save s_dev before assign for
276                                                  * clustred nfs */
277
278         /* metadata stat-ahead */
279         unsigned int              ll_sa_count; /* current statahead RPCs */
280         unsigned int              ll_sa_max;   /* max statahead RPCs */
281         unsigned int              ll_sa_wrong; /* statahead thread stopped for
282                                                 * low hit ratio */
283         unsigned int              ll_sa_total; /* statahead thread started
284                                                 * count */
285         unsigned long long        ll_sa_blocked; /* ls count waiting for
286                                                   * statahead */
287         unsigned long long        ll_sa_cached;  /* ls count got in cache */
288 };
289
290 #define LL_DEFAULT_MAX_RW_CHUNK         (32 * 1024 * 1024)
291
292 struct ll_ra_read {
293         pgoff_t             lrr_start;
294         pgoff_t             lrr_count;
295         struct task_struct *lrr_reader;
296         struct list_head    lrr_linkage;
297 };
298
299 /*
300  * per file-descriptor read-ahead data.
301  */
302 struct ll_readahead_state {
303         spinlock_t      ras_lock;
304         /*
305          * index of the last page that read(2) needed and that wasn't in the
306          * cache. Used by ras_update() to detect seeks.
307          *
308          * XXX nikita: if access seeks into cached region, Lustre doesn't see
309          * this.
310          */
311         unsigned long   ras_last_readpage;
312         /*
313          * number of pages read after last read-ahead window reset. As window
314          * is reset on each seek, this is effectively a number of consecutive
315          * accesses. Maybe ->ras_accessed_in_window is better name.
316          *
317          * XXX nikita: window is also reset (by ras_update()) when Lustre
318          * believes that memory pressure evicts read-ahead pages. In that
319          * case, it probably doesn't make sense to expand window to
320          * PTLRPC_MAX_BRW_PAGES on the third access.
321          */
322         unsigned long   ras_consecutive_pages;
323         /*
324          * number of read requests after the last read-ahead window reset
325          * As window is reset on each seek, this is effectively the number 
326          * on consecutive read request and is used to trigger read-ahead.
327          */
328         unsigned long   ras_consecutive_requests;
329         /*
330          * Parameters of current read-ahead window. Handled by
331          * ras_update(). On the initial access to the file or after a seek,
332          * window is reset to 0. After 3 consecutive accesses, window is
333          * expanded to PTLRPC_MAX_BRW_PAGES. Afterwards, window is enlarged by
334          * PTLRPC_MAX_BRW_PAGES chunks up to ->ra_max_pages.
335          */
336         unsigned long   ras_window_start, ras_window_len;
337         /*
338          * Where next read-ahead should start at. This lies within read-ahead
339          * window. Read-ahead window is read in pieces rather than at once
340          * because: 1. lustre limits total number of pages under read-ahead by
341          * ->ra_max_pages (see ll_ra_count_get()), 2. client cannot read pages
342          * not covered by DLM lock.
343          */
344         unsigned long   ras_next_readahead;
345         /*
346          * Total number of ll_file_read requests issued, reads originating
347          * due to mmap are not counted in this total.  This value is used to
348          * trigger full file read-ahead after multiple reads to a small file.
349          */
350         unsigned long   ras_requests;
351         /*
352          * Page index with respect to the current request, these value 
353          * will not be accurate when dealing with reads issued via mmap.
354          */
355         unsigned long   ras_request_index;
356         /*
357          * list of struct ll_ra_read's one per read(2) call current in
358          * progress against this file descriptor. Used by read-ahead code,
359          * protected by ->ras_lock.
360          */
361         struct list_head ras_read_beads;
362 };
363
364 extern cfs_mem_cache_t *ll_file_data_slab;
365 struct lustre_handle;
366 struct ll_file_data {
367         struct ll_readahead_state fd_ras;
368         int fd_omode;
369         struct lustre_handle fd_cwlockh;
370         unsigned long fd_gid;
371         __u32 fd_flags;
372 };
373
374 struct lov_stripe_md;
375
376 extern spinlock_t inode_lock;
377
378 extern struct proc_dir_entry *proc_lustre_fs_root;
379
380 static inline struct inode *ll_info2i(struct ll_inode_info *lli)
381 {
382 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
383         return &lli->lli_vfs_inode;
384 #else
385         return list_entry(lli, struct inode, u.generic_ip);
386 #endif
387 }
388
389 struct it_cb_data {
390         struct inode *icbd_parent;
391         struct dentry **icbd_childp;
392         obd_id hash;
393 };
394
395 void ll_i2gids(__u32 *suppgids, struct inode *i1,struct inode *i2);
396
397 #define LLAP_MAGIC 98764321
398
399 extern cfs_mem_cache_t *ll_async_page_slab;
400 extern size_t ll_async_page_slab_size;
401 struct ll_async_page {
402         int              llap_magic;
403          /* only trust these if the page lock is providing exclusion */
404         unsigned int     llap_write_queued:1,
405                          llap_defer_uptodate:1,
406                          llap_origin:3,
407                          llap_ra_used:1,
408                          llap_ignore_quota:1,
409                          llap_nocache:1,
410                          llap_lockless_io_page:1;
411         void            *llap_cookie;
412         struct page     *llap_page;
413         struct list_head llap_pending_write;
414         struct list_head llap_pglist_item;
415         /* checksum for paranoid I/O debugging */
416         __u32 llap_checksum;
417 };
418
419 /*
420  * enumeration of llap_from_page() call-sites. Used to export statistics in
421  * /proc/fs/lustre/llite/fsN/dump_page_cache.
422  */
423 enum {
424         LLAP_ORIGIN_UNKNOWN = 0,
425         LLAP_ORIGIN_READPAGE,
426         LLAP_ORIGIN_READAHEAD,
427         LLAP_ORIGIN_COMMIT_WRITE,
428         LLAP_ORIGIN_WRITEPAGE,
429         LLAP_ORIGIN_REMOVEPAGE,
430         LLAP_ORIGIN_LOCKLESS_IO,
431         LLAP__ORIGIN_MAX,
432 };
433 extern char *llap_origins[];
434
435 #ifdef HAVE_REGISTER_CACHE
436 #define ll_register_cache(cache) register_cache(cache)
437 #define ll_unregister_cache(cache) unregister_cache(cache)
438 #else
439 #define ll_register_cache(cache) do {} while (0)
440 #define ll_unregister_cache(cache) do {} while (0)
441 #endif
442
443 void ll_ra_read_in(struct file *f, struct ll_ra_read *rar);
444 void ll_ra_read_ex(struct file *f, struct ll_ra_read *rar);
445 struct ll_ra_read *ll_ra_read_get(struct file *f);
446
447 /* llite/lproc_llite.c */
448 #ifdef LPROCFS
449 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
450                                 struct super_block *sb, char *osc, char *mdc);
451 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi);
452 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count);
453 void lprocfs_llite_init_vars(struct lprocfs_static_vars *lvars);
454 #else
455 static inline int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
456                         struct super_block *sb, char *osc, char *mdc){return 0;}
457 static inline void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi) {}
458 static void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count) {}
459 static void lprocfs_llite_init_vars(struct lprocfs_static_vars *lvars)
460 {
461         memset(lvars, 0, sizeof(*lvars));
462 }
463 #endif
464
465
466 /* llite/dir.c */
467 extern struct file_operations ll_dir_operations;
468 extern struct inode_operations ll_dir_inode_operations;
469
470 struct page *ll_get_dir_page(struct inode *dir, unsigned long n);
471 /*
472  * p is at least 6 bytes before the end of page
473  */
474 typedef struct ext2_dir_entry_2 ext2_dirent;
475
476 static inline ext2_dirent *ext2_next_entry(ext2_dirent *p)
477 {
478         return (ext2_dirent *)((char*)p + le16_to_cpu(p->rec_len));
479 }
480
481 static inline unsigned
482 ext2_validate_entry(char *base, unsigned offset, unsigned mask)
483 {
484         ext2_dirent *de = (ext2_dirent*)(base + offset);
485         ext2_dirent *p = (ext2_dirent*)(base + (offset&mask));
486         while ((char*)p < (char*)de)
487                 p = ext2_next_entry(p);
488         return (char *)p - base;
489 }
490
491 static inline void ext2_put_page(struct page *page)
492 {
493         kunmap(page);
494         page_cache_release(page);
495 }
496
497 static inline unsigned long dir_pages(struct inode *inode)
498 {
499         return (inode->i_size + CFS_PAGE_SIZE - 1) >> CFS_PAGE_SHIFT;
500 }
501
502 /* llite/namei.c */
503 int ll_objects_destroy(struct ptlrpc_request *request, struct inode *dir);
504 struct inode *ll_iget(struct super_block *sb, ino_t hash,
505                       struct lustre_md *lic);
506 int ll_mdc_cancel_unused(struct lustre_handle *, struct inode *, int flags,
507                          void *opaque);
508 int ll_mdc_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
509                         void *data, int flag);
510 int ll_prepare_mdc_op_data(struct mdc_op_data *,
511                            struct inode *i1, struct inode *i2,
512                            const char *name, int namelen, int mode, void *data);
513 #ifndef HAVE_VFS_INTENT_PATCHES
514 struct lookup_intent *ll_convert_intent(struct open_intent *oit,
515                                         int lookup_flags);
516 #endif
517 void ll_pin_extent_cb(void *data);
518 int ll_page_removal_cb(void *data, int discard);
519 int ll_extent_lock_cancel_cb(struct ldlm_lock *lock, struct ldlm_lock_desc *new,
520                              void *data, int flag);
521 int lookup_it_finish(struct ptlrpc_request *request, int offset,
522                      struct lookup_intent *it, void *data);
523 void ll_lookup_finish_locks(struct lookup_intent *it, struct dentry *dentry);
524
525 /* llite/rw.c */
526 int ll_prepare_write(struct file *, struct page *, unsigned from, unsigned to);
527 int ll_commit_write(struct file *, struct page *, unsigned from, unsigned to);
528 int ll_writepage(struct page *page);
529 void ll_inode_fill_obdo(struct inode *inode, int cmd, struct obdo *oa);
530 int ll_ap_completion(void *data, int cmd, struct obdo *oa, int rc);
531 int llap_shrink_cache(struct ll_sb_info *sbi, int shrink_fraction);
532 extern struct cache_definition ll_cache_definition;
533 void ll_removepage(struct page *page);
534 int ll_readpage(struct file *file, struct page *page);
535 struct ll_async_page *llap_cast_private(struct page *page);
536 void ll_readahead_init(struct inode *inode, struct ll_readahead_state *ras);
537 void ll_ra_accounting(struct ll_async_page *llap,struct address_space *mapping);
538 void ll_truncate(struct inode *inode);
539 int ll_file_punch(struct inode *, loff_t, int);
540 ssize_t ll_file_lockless_io(struct file *, char *, size_t, loff_t *, int);
541 void ll_clear_file_contended(struct inode*);
542 int ll_sync_page_range(struct inode *, struct address_space *, loff_t, size_t);
543
544 /* llite/file.c */
545 extern struct file_operations ll_file_operations;
546 extern struct file_operations ll_file_operations_flock;
547 extern struct file_operations ll_file_operations_noflock;
548 extern struct inode_operations ll_file_inode_operations;
549 extern int ll_inode_revalidate_it(struct dentry *, struct lookup_intent *);
550 extern int ll_have_md_lock(struct inode *inode, __u64 bits);
551 int ll_extent_lock(struct ll_file_data *, struct inode *,
552                    struct lov_stripe_md *, int mode, ldlm_policy_data_t *,
553                    struct lustre_handle *, int ast_flags);
554 int ll_extent_unlock(struct ll_file_data *, struct inode *,
555                      struct lov_stripe_md *, int mode, struct lustre_handle *);
556 int ll_file_open(struct inode *inode, struct file *file);
557 int ll_file_release(struct inode *inode, struct file *file);
558 int ll_lsm_getattr(struct obd_export *, struct lov_stripe_md *, struct obdo *);
559 int ll_glimpse_ioctl(struct ll_sb_info *sbi, 
560                      struct lov_stripe_md *lsm, lstat_t *st);
561 int ll_glimpse_size(struct inode *inode, int ast_flags);
562 int ll_local_open(struct file *file,
563                   struct lookup_intent *it, struct ll_file_data *fd,
564                   struct obd_client_handle *och);
565 int ll_release_openhandle(struct dentry *, struct lookup_intent *);
566 int ll_mdc_close(struct obd_export *mdc_exp, struct inode *inode,
567                  struct file *file);
568 int ll_mdc_real_close(struct inode *inode, int flags);
569 extern void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid, struct file
570                                *file, size_t count, int rw);
571 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
572 int ll_getattr_it(struct vfsmount *mnt, struct dentry *de,
573                struct lookup_intent *it, struct kstat *stat);
574 int ll_getattr(struct vfsmount *mnt, struct dentry *de, struct kstat *stat);
575 #endif
576 struct ll_file_data *ll_file_data_get(void);
577 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
578 int ll_inode_permission(struct inode *inode, int mask, struct nameidata *nd);
579 #else
580 int ll_inode_permission(struct inode *inode, int mask);
581 #endif
582 int ll_lov_setstripe_ea_info(struct inode *inode, struct file *file,
583                              int flags, struct lov_user_md *lum,
584                              int lum_size);
585 int ll_lov_getstripe_ea_info(struct inode *inode, const char *filename,
586                              struct lov_mds_md **lmm, int *lmm_size,
587                              struct ptlrpc_request **request);
588 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
589                      int set_default);
590 int ll_dir_getstripe(struct inode *inode, struct lov_mds_md **lmm, 
591                      int *lmm_size, struct ptlrpc_request **request);
592
593 /* llite/dcache.c */
594 void ll_intent_drop_lock(struct lookup_intent *);
595 void ll_intent_release(struct lookup_intent *);
596 extern void ll_set_dd(struct dentry *de);
597 int ll_drop_dentry(struct dentry *dentry);
598 void ll_unhash_aliases(struct inode *);
599 void ll_frob_intent(struct lookup_intent **itp, struct lookup_intent *deft);
600 void ll_lookup_finish_locks(struct lookup_intent *it, struct dentry *dentry);
601 int ll_dcompare(struct dentry *parent, struct qstr *d_name, struct qstr *name);
602 int revalidate_it_finish(struct ptlrpc_request *request, int offset,
603                          struct lookup_intent *it, struct dentry *de);
604
605 /* llite/llite_lib.c */
606 extern struct super_operations lustre_super_operations;
607
608 char *ll_read_opt(const char *opt, char *data);
609 void ll_lli_init(struct ll_inode_info *lli);
610 int ll_fill_super(struct super_block *sb);
611 void ll_put_super(struct super_block *sb);
612 void ll_kill_super(struct super_block *sb);
613 struct inode *ll_inode_from_lock(struct ldlm_lock *lock);
614 void ll_clear_inode(struct inode *inode);
615 int ll_setattr_raw(struct inode *inode, struct iattr *attr);
616 int ll_setattr(struct dentry *de, struct iattr *attr);
617 #ifndef HAVE_STATFS_DENTRY_PARAM
618 int ll_statfs(struct super_block *sb, struct kstatfs *sfs);
619 #else
620 int ll_statfs(struct dentry *de, struct kstatfs *sfs);
621 #endif
622 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
623                        __u64 max_age);
624 void ll_update_inode(struct inode *inode, struct lustre_md *md);
625 void ll_read_inode2(struct inode *inode, void *opaque);
626 int ll_iocontrol(struct inode *inode, struct file *file,
627                  unsigned int cmd, unsigned long arg);
628 #ifdef HAVE_UMOUNTBEGIN_VFSMOUNT
629 void ll_umount_begin(struct vfsmount *vfsmnt, int flags);
630 #else
631 void ll_umount_begin(struct super_block *sb);
632 #endif
633 int ll_remount_fs(struct super_block *sb, int *flags, char *data);
634 int ll_prep_inode(struct obd_export *exp, struct inode **inode,
635                   struct ptlrpc_request *req, int offset, struct super_block *);
636 void lustre_dump_dentry(struct dentry *, int recur);
637 void lustre_dump_inode(struct inode *);
638 struct ll_async_page *llite_pglist_next_llap(struct ll_sb_info *sbi,
639                                              struct list_head *list);
640 int ll_obd_statfs(struct inode *inode, void *arg);
641 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *max_mdsize);
642 int ll_process_config(struct lustre_cfg *lcfg);
643
644 /* llite/llite_nfs.c */
645 extern struct export_operations lustre_export_operations;
646 __u32 get_uuid2int(const char *name, int len);
647 struct dentry *ll_fh_to_dentry(struct super_block *sb, __u32 *data, int len,
648                                int fhtype, int parent);
649 int ll_dentry_to_fh(struct dentry *, __u32 *datap, int *lenp, int need_parent);
650
651 /* llite/special.c */
652 extern struct inode_operations ll_special_inode_operations;
653 extern struct file_operations ll_special_chr_inode_fops;
654 extern struct file_operations ll_special_chr_file_fops;
655 extern struct file_operations ll_special_blk_inode_fops;
656 extern struct file_operations ll_special_fifo_inode_fops;
657 extern struct file_operations ll_special_fifo_file_fops;
658 extern struct file_operations ll_special_sock_inode_fops;
659
660 /* llite/symlink.c */
661 extern struct inode_operations ll_fast_symlink_inode_operations;
662
663 /* llite/llite_close.c */
664 struct ll_close_queue {
665         spinlock_t              lcq_lock;
666         struct list_head        lcq_list;
667         wait_queue_head_t       lcq_waitq;
668         struct completion       lcq_comp;
669 };
670
671 #ifdef HAVE_CLOSE_THREAD
672 void llap_write_pending(struct inode *inode, struct ll_async_page *llap);
673 void llap_write_complete(struct inode *inode, struct ll_async_page *llap);
674 void ll_open_complete(struct inode *inode);
675 int ll_is_inode_dirty(struct inode *inode);
676 void ll_try_done_writing(struct inode *inode);
677 void ll_queue_done_writing(struct inode *inode);
678 #else
679 static inline void llap_write_pending(struct inode *inode,
680                                       struct ll_async_page *llap) { return; };
681 static inline void llap_write_complete(struct inode *inode,
682                                        struct ll_async_page *llap) { return; };
683 static inline void ll_open_complete(struct inode *inode) { return; };
684 static inline int ll_is_inode_dirty(struct inode *inode) { return 0; };
685 static inline void ll_try_done_writing(struct inode *inode) { return; };
686 static inline void ll_queue_done_writing(struct inode *inode) { return; };
687 //static inline void ll_close_thread_shutdown(struct ll_close_queue *lcq) { return; };
688 //static inline int ll_close_thread_start(struct ll_close_queue **lcq_ret) { return 0; };
689 #endif
690 void ll_close_thread_shutdown(struct ll_close_queue *lcq);
691 int ll_close_thread_start(struct ll_close_queue **lcq_ret);
692
693 /* llite/llite_mmap.c */
694 #if  (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
695 typedef struct rb_root  rb_root_t;
696 typedef struct rb_node  rb_node_t;
697 #endif
698
699 struct ll_lock_tree_node;
700 struct ll_lock_tree {
701         rb_root_t                       lt_root;
702         struct list_head                lt_locked_list;
703         struct ll_file_data             *lt_fd;
704 };
705
706 int ll_teardown_mmaps(struct address_space *mapping, __u64 first, __u64 last);
707 int ll_file_mmap(struct file * file, struct vm_area_struct * vma);
708 struct ll_lock_tree_node * ll_node_from_inode(struct inode *inode, __u64 start,
709                                               __u64 end, ldlm_mode_t mode);
710 int ll_tree_lock(struct ll_lock_tree *tree,
711                  struct ll_lock_tree_node *first_node,
712                  const char *buf, size_t count, int ast_flags);
713 int ll_tree_unlock(struct ll_lock_tree *tree);
714
715 #define    ll_s2sbi(sb)        (s2lsi(sb)->lsi_llsbi)
716
717 #if  (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
718 static inline __u64 ll_ts2u64(struct timespec *time)
719 {
720         __u64 t = time->tv_sec;
721         return t;
722 }
723 #else  /* 2.4 here */
724 static inline __u64 ll_ts2u64(time_t *time)
725 {
726         return *time;
727 }
728 #endif
729
730 /* don't need an addref as the sb_info should be holding one */
731 static inline struct obd_export *ll_s2obdexp(struct super_block *sb)
732 {
733         return ll_s2sbi(sb)->ll_osc_exp;
734 }
735
736 /* don't need an addref as the sb_info should be holding one */
737 static inline struct obd_export *ll_s2mdcexp(struct super_block *sb)
738 {
739         return ll_s2sbi(sb)->ll_mdc_exp;
740 }
741
742 static inline struct client_obd *sbi2mdc(struct ll_sb_info *sbi)
743 {
744         struct obd_device *obd = sbi->ll_mdc_exp->exp_obd;
745         if (obd == NULL)
746                 LBUG();
747         return &obd->u.cli;
748 }
749
750 // FIXME: replace the name of this with LL_SB to conform to kernel stuff
751 static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
752 {
753         return ll_s2sbi(inode->i_sb);
754 }
755
756 static inline struct obd_export *ll_i2obdexp(struct inode *inode)
757 {
758         return ll_s2obdexp(inode->i_sb);
759 }
760
761 static inline struct obd_export *ll_i2mdcexp(struct inode *inode)
762 {
763         return ll_s2mdcexp(inode->i_sb);
764 }
765
766 static inline void ll_inode2fid(struct ll_fid *fid, struct inode *inode)
767 {
768         mdc_pack_fid(fid, inode->i_ino, inode->i_generation,
769                      inode->i_mode & S_IFMT);
770 }
771
772 static inline int ll_mds_max_easize(struct super_block *sb)
773 {
774         return sbi2mdc(ll_s2sbi(sb))->cl_max_mds_easize;
775 }
776
777 static inline __u64 ll_file_maxbytes(struct inode *inode)
778 {
779         return ll_i2info(inode)->lli_maxbytes;
780 }
781
782 /* llite/xattr.c */
783 int ll_setxattr(struct dentry *dentry, const char *name,
784                 const void *value, size_t size, int flags);
785 ssize_t ll_getxattr(struct dentry *dentry, const char *name,
786                     void *buffer, size_t size);
787 ssize_t ll_listxattr(struct dentry *dentry, char *buffer, size_t size);
788 int ll_removexattr(struct dentry *dentry, const char *name);
789
790 /* statahead.c */
791
792 #define LL_STATAHEAD_MIN  1
793 #define LL_STATAHEAD_DEF  32
794 #define LL_STATAHEAD_MAX  10000
795
796 /* per inode struct, for dir only */
797 struct ll_statahead_info {
798         struct inode           *sai_inode;
799         atomic_t                sai_refc;       /* when access this struct, hold
800                                                  * refcount */
801         unsigned int            sai_max;        /* max ahead of lookup */
802         unsigned int            sai_sent;       /* stat requests sent count */
803         unsigned int            sai_replied;    /* stat requests which received
804                                                  * reply */
805         unsigned int            sai_cached;     /* UPDATE lock cached locally
806                                                  * already */
807         unsigned int            sai_hit;        /* hit count */
808         unsigned int            sai_miss;       /* miss count */
809         unsigned int            sai_consecutive_miss; /* consecutive miss */
810         unsigned                sai_ls_all:1;   /* ls -al, do stat-ahead for
811                                                  * hidden entries */
812         struct ptlrpc_thread    sai_thread;     /* stat-ahead thread */
813         struct list_head        sai_entries;    /* stat-ahead entries */
814         unsigned int            sai_entries_nr; /* stat-ahead entries count */
815 };
816
817 int ll_statahead_enter(struct inode *dir, struct dentry **dentry, int lookup);
818 void ll_statahead_exit(struct dentry *dentry, int result);
819 void ll_stop_statahead(struct inode *inode);
820
821 /* llite ioctl register support rountine */
822 #ifdef __KERNEL__
823 enum llioc_iter {
824         LLIOC_CONT = 0,
825         LLIOC_STOP
826 };
827
828 #define LLIOC_MAX_CMD           256
829
830 /*
831  * Rules to write a callback function:
832  *
833  * Parameters:
834  *  @magic: Dynamic ioctl call routine will feed this vaule with the pointer
835  *      returned to ll_iocontrol_register.  Callback functions should use this
836  *      data to check the potential collasion of ioctl cmd. If collasion is 
837  *      found, callback function should return LLIOC_CONT.
838  *  @rcp: The result of ioctl command.
839  *
840  *  Return values:
841  *      If @magic matches the pointer returned by ll_iocontrol_data, the 
842  *      callback should return LLIOC_STOP; return LLIOC_STOP otherwise.
843  */
844 typedef enum llioc_iter (*llioc_callback_t)(struct inode *inode, 
845                 struct file *file, unsigned int cmd, unsigned long arg,
846                 void *magic, int *rcp);
847
848 enum llioc_iter ll_iocontrol_call(struct inode *inode, struct file *file, 
849                 unsigned int cmd, unsigned long arg, int *rcp);
850
851 /* export functions */
852 /* Register ioctl block dynamatically for a regular file. 
853  *
854  * @cmd: the array of ioctl command set
855  * @count: number of commands in the @cmd
856  * @cb: callback function, it will be called if an ioctl command is found to 
857  *      belong to the command list @cmd.
858  *
859  * Return vaule:
860  *      A magic pointer will be returned if success; 
861  *      otherwise, NULL will be returned. 
862  * */
863 void *ll_iocontrol_register(llioc_callback_t cb, int count, unsigned int *cmd);
864 void ll_iocontrol_unregister(void *magic);
865
866 #endif
867
868 #endif /* LLITE_INTERNAL_H */