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