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