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