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