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