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