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