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