Whamcloud - gitweb
LU-5971 llite: reorganize variable and data structures
[fs/lustre-release.git] / lustre / llite / llite_internal.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2014, Intel Corporation.
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 #include <lustre_debug.h>
40 #include <lustre_ver.h>
41 #include <lustre_disk.h>  /* for s2sbi */
42 #include <lustre_eacl.h>
43 #include <lustre_linkea.h>
44
45 /* for struct cl_lock_descr and struct cl_io */
46 #include <cl_object.h>
47 #include <lustre_lmv.h>
48 #include <lustre_mdc.h>
49 #include <lustre_intent.h>
50 #include <linux/compat.h>
51 #include <linux/aio.h>
52
53 #include "vvp_internal.h"
54 #include "range_lock.h"
55
56 #ifndef FMODE_EXEC
57 #define FMODE_EXEC 0
58 #endif
59
60 #ifndef VM_FAULT_RETRY
61 #define VM_FAULT_RETRY 0
62 #endif
63
64 /* Kernel 3.1 kills LOOKUP_CONTINUE, LOOKUP_PARENT is equivalent to it.
65  * seem kernel commit 49084c3bb2055c401f3493c13edae14d49128ca0 */
66 #ifndef LOOKUP_CONTINUE
67 #define LOOKUP_CONTINUE LOOKUP_PARENT
68 #endif
69
70 /** Only used on client-side for indicating the tail of dir hash/offset. */
71 #define LL_DIR_END_OFF          0x7fffffffffffffffULL
72 #define LL_DIR_END_OFF_32BIT    0x7fffffffUL
73
74 /* 4UL * 1024 * 1024 */
75 #define LL_MAX_BLKSIZE_BITS 22
76
77 #define LL_IT2STR(it) ((it) ? ldlm_it2str((it)->it_op) : "0")
78 #define LUSTRE_FPRIVATE(file) ((file)->private_data)
79
80 struct ll_dentry_data {
81         struct lookup_intent            *lld_it;
82         unsigned int                    lld_sa_generation;
83         unsigned int                    lld_invalid:1;
84         struct rcu_head                 lld_rcu_head;
85 };
86
87 #define ll_d2d(de) ((struct ll_dentry_data*)((de)->d_fsdata))
88
89 #define LLI_INODE_MAGIC                 0x111d0de5
90 #define LLI_INODE_DEAD                  0xdeadd00d
91
92 /* remote client permission cache */
93 #define REMOTE_PERM_HASHSIZE 16
94
95 struct ll_getname_data {
96 #ifdef HAVE_DIR_CONTEXT
97         struct dir_context      ctx;
98 #endif
99         char            *lgd_name;      /* points to a buffer with NAME_MAX+1 size */
100         struct lu_fid   lgd_fid;        /* target fid we are looking for */
101         int             lgd_found;      /* inode matched? */
102 };
103
104 /* llite setxid/access permission for user on remote client */
105 struct ll_remote_perm {
106         struct hlist_node       lrp_list;
107         uid_t                   lrp_uid;
108         gid_t                   lrp_gid;
109         uid_t                   lrp_fsuid;
110         gid_t                   lrp_fsgid;
111         int                     lrp_access_perm; /* MAY_READ/WRITE/EXEC, this
112                                                     is access permission with
113                                                     lrp_fsuid/lrp_fsgid. */
114 };
115
116 struct ll_grouplock {
117         struct lu_env   *lg_env;
118         struct cl_io    *lg_io;
119         struct cl_lock  *lg_lock;
120         unsigned long    lg_gid;
121 };
122
123 enum lli_flags {
124         /* File data is modified. */
125         LLIF_DATA_MODIFIED      = 1 << 0,
126         /* File is being restored */
127         LLIF_FILE_RESTORING     = 1 << 1,
128         /* Xattr cache is attached to the file */
129         LLIF_XATTR_CACHE        = 1 << 2,
130 };
131
132 struct ll_inode_info {
133         __u32                           lli_inode_magic;
134         __u32                           lli_flags;
135
136         spinlock_t                      lli_lock;
137         struct posix_acl                *lli_posix_acl;
138
139         struct hlist_head               *lli_remote_perms;
140         struct mutex                    lli_rmtperm_mutex;
141
142         /* identifying fields for both metadata and data stacks. */
143         struct lu_fid                   lli_fid;
144         /* master inode fid for stripe directory */
145         struct lu_fid                   lli_pfid;
146
147         struct list_head                lli_oss_capas;
148         /* open count currently used by capability only, indicate whether
149          * capability needs renewal */
150         atomic_t                        lli_open_count;
151         struct obd_capa                *lli_mds_capa;
152         cfs_time_t                      lli_rmtperm_time;
153
154         /* We need all three because every inode may be opened in different
155          * modes */
156         struct obd_client_handle       *lli_mds_read_och;
157         struct obd_client_handle       *lli_mds_write_och;
158         struct obd_client_handle       *lli_mds_exec_och;
159         __u64                           lli_open_fd_read_count;
160         __u64                           lli_open_fd_write_count;
161         __u64                           lli_open_fd_exec_count;
162         /* Protects access to och pointers and their usage counters */
163         struct mutex                    lli_och_mutex;
164
165         struct inode                    lli_vfs_inode;
166
167         /* the most recent timestamps obtained from mds */
168         s64                             lli_atime;
169         s64                             lli_mtime;
170         s64                             lli_ctime;
171         spinlock_t                      lli_agl_lock;
172
173         /* Try to make the d::member and f::member are aligned. Before using
174          * these members, make clear whether it is directory or not. */
175         union {
176                 /* for directory */
177                 struct {
178                         /* serialize normal readdir and statahead-readdir. */
179                         struct mutex                    lli_readdir_mutex;
180
181                         /* metadata statahead */
182                         /* since parent-child threads can share the same @file
183                          * struct, "opendir_key" is the token when dir close for
184                          * case of parent exit before child -- it is me should
185                          * cleanup the dir readahead. */
186                         void                           *lli_opendir_key;
187                         struct ll_statahead_info       *lli_sai;
188                         /* protect statahead stuff. */
189                         spinlock_t                      lli_sa_lock;
190                         /* "opendir_pid" is the token when lookup/revalid
191                          * -- I am the owner of dir statahead. */
192                         pid_t                           lli_opendir_pid;
193                         /* stat will try to access statahead entries or start
194                          * statahead if this flag is set, and this flag will be
195                          * set upon dir open, and cleared when dir is closed,
196                          * statahead hit ratio is too low, or start statahead
197                          * thread failed. */
198                         unsigned int                    lli_sa_enabled:1;
199                         /* generation for statahead */
200                         unsigned int                    lli_sa_generation;
201                         /* directory stripe information */
202                         struct lmv_stripe_md            *lli_lsm_md;
203                         /* default directory stripe offset.  This is extracted
204                          * from the "dmv" xattr in order to decide which MDT to
205                          * create a subdirectory on.  The MDS itself fetches
206                          * "dmv" and gets the rest of the default layout itself
207                          * (count, hash, etc). */
208                         __u32                           lli_def_stripe_offset;
209                 };
210
211                 /* for non-directory */
212                 struct {
213                         struct mutex                    lli_size_mutex;
214                         char                           *lli_symlink_name;
215                         __u64                           lli_maxbytes;
216                         /*
217                          * struct rw_semaphore {
218                          *    signed long       count;     // align d.d_def_acl
219                          *    spinlock_t        wait_lock; // align d.d_sa_lock
220                          *    struct list_head wait_list;
221                          * }
222                          */
223                         struct rw_semaphore             lli_trunc_sem;
224                         struct range_lock_tree          lli_write_tree;
225
226                         struct rw_semaphore             lli_glimpse_sem;
227                         cfs_time_t                      lli_glimpse_time;
228                         struct list_head                lli_agl_list;
229                         __u64                           lli_agl_index;
230
231                         /* for writepage() only to communicate to fsync */
232                         int                             lli_async_rc;
233
234                         /*
235                          * whenever a process try to read/write the file, the
236                          * jobid of the process will be saved here, and it'll
237                          * be packed into the write PRC when flush later.
238                          *
239                          * so the read/write statistics for jobid will not be
240                          * accurate if the file is shared by different jobs.
241                          */
242                         char                    lli_jobid[LUSTRE_JOBID_SIZE];
243                 };
244         };
245
246         /* XXX: For following frequent used members, although they maybe special
247          *      used for non-directory object, it is some time-wasting to check
248          *      whether the object is directory or not before using them. On the
249          *      other hand, currently, sizeof(f) > sizeof(d), it cannot reduce
250          *      the "ll_inode_info" size even if moving those members into u.f.
251          *      So keep them out side.
252          *
253          *      In the future, if more members are added only for directory,
254          *      some of the following members can be moved into u.f.
255          */
256         bool                            lli_has_smd;
257         struct cl_object                *lli_clob;
258
259         /* mutex to request for layout lock exclusively. */
260         struct mutex                    lli_layout_mutex;
261         /* Layout version, protected by lli_layout_lock */
262         __u32                           lli_layout_gen;
263         spinlock_t                      lli_layout_lock;
264
265         struct rw_semaphore             lli_xattrs_list_rwsem;
266         struct mutex                    lli_xattrs_enq_lock;
267         struct list_head                lli_xattrs; /* ll_xattr_entry->xe_list */
268 };
269
270 static inline __u32 ll_layout_version_get(struct ll_inode_info *lli)
271 {
272         __u32 gen;
273
274         spin_lock(&lli->lli_layout_lock);
275         gen = lli->lli_layout_gen;
276         spin_unlock(&lli->lli_layout_lock);
277
278         return gen;
279 }
280
281 static inline void ll_layout_version_set(struct ll_inode_info *lli, __u32 gen)
282 {
283         spin_lock(&lli->lli_layout_lock);
284         lli->lli_layout_gen = gen;
285         spin_unlock(&lli->lli_layout_lock);
286 }
287
288 int ll_xattr_cache_destroy(struct inode *inode);
289
290 int ll_xattr_cache_get(struct inode *inode,
291                         const char *name,
292                         char *buffer,
293                         size_t size,
294                         __u64 valid);
295
296 /*
297  * Locking to guarantee consistency of non-atomic updates to long long i_size,
298  * consistency between file size and KMS.
299  *
300  * Implemented by ->lli_size_mutex and ->lsm_lock, nested in that order.
301  */
302
303 void ll_inode_size_lock(struct inode *inode);
304 void ll_inode_size_unlock(struct inode *inode);
305
306 // FIXME: replace the name of this with LL_I to conform to kernel stuff
307 // static inline struct ll_inode_info *LL_I(struct inode *inode)
308 static inline struct ll_inode_info *ll_i2info(struct inode *inode)
309 {
310         return container_of(inode, struct ll_inode_info, lli_vfs_inode);
311 }
312
313 /* default to about 40meg of readahead on a given system.  That much tied
314  * up in 512k readahead requests serviced at 40ms each is about 1GB/s. */
315 #define SBI_DEFAULT_READAHEAD_MAX (40UL << (20 - PAGE_CACHE_SHIFT))
316
317 /* default to read-ahead full files smaller than 2MB on the second read */
318 #define SBI_DEFAULT_READAHEAD_WHOLE_MAX (2UL << (20 - PAGE_CACHE_SHIFT))
319
320 enum ra_stat {
321         RA_STAT_HIT = 0,
322         RA_STAT_MISS,
323         RA_STAT_DISTANT_READPAGE,
324         RA_STAT_MISS_IN_WINDOW,
325         RA_STAT_FAILED_GRAB_PAGE,
326         RA_STAT_FAILED_MATCH,
327         RA_STAT_DISCARDED,
328         RA_STAT_ZERO_LEN,
329         RA_STAT_ZERO_WINDOW,
330         RA_STAT_EOF,
331         RA_STAT_MAX_IN_FLIGHT,
332         RA_STAT_WRONG_GRAB_PAGE,
333         RA_STAT_FAILED_REACH_END,
334         _NR_RA_STAT,
335 };
336
337 struct ll_ra_info {
338         atomic_t        ra_cur_pages;
339         unsigned long   ra_max_pages;
340         unsigned long   ra_max_pages_per_file;
341         unsigned long   ra_max_read_ahead_whole_pages;
342 };
343
344 /* ra_io_arg will be filled in the beginning of ll_readahead with
345  * ras_lock, then the following ll_read_ahead_pages will read RA
346  * pages according to this arg, all the items in this structure are
347  * counted by page index.
348  */
349 struct ra_io_arg {
350         unsigned long ria_start;  /* start offset of read-ahead*/
351         unsigned long ria_end;    /* end offset of read-ahead*/
352         /* If stride read pattern is detected, ria_stoff means where
353          * stride read is started. Note: for normal read-ahead, the
354          * value here is meaningless, and also it will not be accessed*/
355         pgoff_t ria_stoff;
356         /* ria_length and ria_pages are the length and pages length in the
357          * stride I/O mode. And they will also be used to check whether
358          * it is stride I/O read-ahead in the read-ahead pages*/
359         unsigned long ria_length;
360         unsigned long ria_pages;
361 };
362
363 /* LL_HIST_MAX=32 causes an overflow */
364 #define LL_HIST_MAX 28
365 #define LL_HIST_START 12 /* buckets start at 2^12 = 4k */
366 #define LL_PROCESS_HIST_MAX 10
367 struct per_process_info {
368         pid_t pid;
369         struct obd_histogram pp_r_hist;
370         struct obd_histogram pp_w_hist;
371 };
372
373 /* pp_extents[LL_PROCESS_HIST_MAX] will hold the combined process info */
374 struct ll_rw_extents_info {
375         struct per_process_info pp_extents[LL_PROCESS_HIST_MAX + 1];
376 };
377
378 #define LL_OFFSET_HIST_MAX 100
379 struct ll_rw_process_info {
380         pid_t                     rw_pid;
381         int                       rw_op;
382         loff_t                    rw_range_start;
383         loff_t                    rw_range_end;
384         loff_t                    rw_last_file_pos;
385         loff_t                    rw_offset;
386         size_t                    rw_smallest_extent;
387         size_t                    rw_largest_extent;
388         struct ll_file_data      *rw_last_file;
389 };
390
391 enum stats_track_type {
392         STATS_TRACK_ALL = 0,  /* track all processes */
393         STATS_TRACK_PID,      /* track process with this pid */
394         STATS_TRACK_PPID,     /* track processes with this ppid */
395         STATS_TRACK_GID,      /* track processes with this gid */
396         STATS_TRACK_LAST,
397 };
398
399 /* flags for sbi->ll_flags */
400 #define LL_SBI_NOLCK             0x01 /* DLM locking disabled (directio-only) */
401 #define LL_SBI_CHECKSUM          0x02 /* checksum each page as it's written */
402 #define LL_SBI_FLOCK             0x04
403 #define LL_SBI_USER_XATTR        0x08 /* support user xattr */
404 #define LL_SBI_ACL               0x10 /* support ACL */
405 #define LL_SBI_RMT_CLIENT        0x40 /* remote client */
406 #define LL_SBI_MDS_CAPA          0x80 /* support mds capa */
407 #define LL_SBI_OSS_CAPA         0x100 /* support oss capa */
408 #define LL_SBI_LOCALFLOCK       0x200 /* Local flocks support by kernel */
409 #define LL_SBI_LRU_RESIZE       0x400 /* lru resize support */
410 #define LL_SBI_LAZYSTATFS       0x800 /* lazystatfs mount option */
411 /*      LL_SBI_SOM_PREVIEW     0x1000    SOM preview mount option, obsolete */
412 #define LL_SBI_32BIT_API       0x2000 /* generate 32 bit inodes. */
413 #define LL_SBI_64BIT_HASH      0x4000 /* support 64-bits dir hash/offset */
414 #define LL_SBI_AGL_ENABLED     0x8000 /* enable agl */
415 #define LL_SBI_VERBOSE        0x10000 /* verbose mount/umount */
416 #define LL_SBI_LAYOUT_LOCK    0x20000 /* layout lock support */
417 #define LL_SBI_USER_FID2PATH  0x40000 /* allow fid2path by unprivileged users */
418 #define LL_SBI_XATTR_CACHE    0x80000 /* support for xattr cache */
419 #define LL_SBI_NOROOTSQUASH  0x100000 /* do not apply root squash */
420
421 #define LL_SBI_FLAGS {  \
422         "nolck",        \
423         "checksum",     \
424         "flock",        \
425         "user_xattr",   \
426         "acl",          \
427         "???",          \
428         "rmt_client",   \
429         "mds_capa",     \
430         "oss_capa",     \
431         "flock",        \
432         "lru_resize",   \
433         "lazy_statfs",  \
434         "som",          \
435         "32bit_api",    \
436         "64bit_hash",   \
437         "agl",          \
438         "verbose",      \
439         "layout",       \
440         "user_fid2path",\
441         "xattr_cache",  \
442         "norootsquash", \
443 }
444
445 #define RCE_HASHES      32
446
447 struct rmtacl_ctl_entry {
448         struct list_head       rce_list;
449         pid_t            rce_key; /* hash key */
450         int              rce_ops; /* acl operation type */
451 };
452
453 struct rmtacl_ctl_table {
454         spinlock_t      rct_lock;
455         struct list_head        rct_entries[RCE_HASHES];
456 };
457
458 #define EE_HASHES       32
459
460 struct eacl_entry {
461         struct list_head            ee_list;
462         pid_t                 ee_key; /* hash key */
463         struct lu_fid         ee_fid;
464         int                   ee_type; /* ACL type for ACCESS or DEFAULT */
465         ext_acl_xattr_header *ee_acl;
466 };
467
468 struct eacl_table {
469         spinlock_t      et_lock;
470         struct list_head        et_entries[EE_HASHES];
471 };
472
473
474 /* This is embedded into llite super-blocks to keep track of connect
475  * flags (capabilities) supported by all imports given mount is
476  * connected to. */
477 struct lustre_client_ocd {
478         /* This is conjunction of connect_flags across all imports
479          * (LOVs) this mount is connected to. This field is updated by
480          * cl_ocd_update() under ->lco_lock. */
481         __u64                    lco_flags;
482         struct mutex             lco_lock;
483         struct obd_export       *lco_md_exp;
484         struct obd_export       *lco_dt_exp;
485 };
486
487 struct ll_sb_info {
488         struct list_head                  ll_list;
489         /* this protects pglist and ra_info.  It isn't safe to
490          * grab from interrupt contexts */
491         spinlock_t                ll_lock;
492         spinlock_t                ll_pp_extent_lock; /* pp_extent entry*/
493         spinlock_t                ll_process_lock; /* ll_rw_process_info */
494         struct obd_uuid           ll_sb_uuid;
495         struct obd_export        *ll_md_exp;
496         struct obd_export        *ll_dt_exp;
497         struct proc_dir_entry*    ll_proc_root;
498         struct lu_fid             ll_root_fid; /* root object fid */
499
500         int                       ll_flags;
501         unsigned int              ll_umounting:1,
502                                   ll_xattr_cache_enabled:1,
503                                   ll_client_common_fill_super_succeeded:1;
504
505         /* per-conn chain of SBs */
506         struct list_head                ll_conn_chain;
507         struct lustre_client_ocd  ll_lco;
508
509         /*please don't ask -p*/
510         struct list_head        ll_orphan_dentry_list;
511
512         struct lprocfs_stats     *ll_stats; /* lprocfs stats counter */
513
514         /* Used to track "unstable" pages on a client, and maintain a
515          * LRU list of clean pages. An "unstable" page is defined as
516          * any page which is sent to a server as part of a bulk request,
517          * but is uncommitted to stable storage. */
518         struct cl_client_cache   *ll_cache;
519
520         struct lprocfs_stats     *ll_ra_stats;
521
522         struct ll_ra_info         ll_ra_info;
523         unsigned int              ll_namelen;
524         struct file_operations   *ll_fop;
525
526         /* =0 - hold lock over whole read/write
527          * >0 - max. chunk to be read/written w/o lock re-acquiring */
528         unsigned long             ll_max_rw_chunk;
529         unsigned int              ll_md_brw_pages; /* readdir pages per RPC */
530
531         struct lu_site           *ll_site;
532         struct cl_device         *ll_cl;
533         /* Statistics */
534         struct ll_rw_extents_info ll_rw_extents_info;
535         int                       ll_extent_process_count;
536         struct ll_rw_process_info ll_rw_process_info[LL_PROCESS_HIST_MAX];
537         unsigned int              ll_offset_process_count;
538         struct ll_rw_process_info ll_rw_offset_info[LL_OFFSET_HIST_MAX];
539         unsigned int              ll_rw_offset_entry_count;
540         int                       ll_stats_track_id;
541         enum stats_track_type     ll_stats_track_type;
542         int                       ll_rw_stats_on;
543
544         /* metadata stat-ahead */
545         unsigned int              ll_sa_max;     /* max statahead RPCs */
546         atomic_t                  ll_sa_total;   /* statahead thread started
547                                                   * count */
548         atomic_t                  ll_sa_wrong;   /* statahead thread stopped for
549                                                   * low hit ratio */
550         atomic_t                  ll_sa_running; /* running statahead thread
551                                                   * count */
552         atomic_t                  ll_agl_total;  /* AGL thread started count */
553
554         dev_t                     ll_sdev_orig; /* save s_dev before assign for
555                                                  * clustred nfs */
556         struct rmtacl_ctl_table   ll_rct;
557         struct eacl_table         ll_et;
558
559         /* root squash */
560         struct root_squash_info   ll_squash;
561 };
562
563 #define LL_DEFAULT_MAX_RW_CHUNK      (32 * 1024 * 1024)
564
565 /*
566  * per file-descriptor read-ahead data.
567  */
568 struct ll_readahead_state {
569         spinlock_t  ras_lock;
570         /*
571          * index of the last page that read(2) needed and that wasn't in the
572          * cache. Used by ras_update() to detect seeks.
573          *
574          * XXX nikita: if access seeks into cached region, Lustre doesn't see
575          * this.
576          */
577         unsigned long   ras_last_readpage;
578         /*
579          * number of pages read after last read-ahead window reset. As window
580          * is reset on each seek, this is effectively a number of consecutive
581          * accesses. Maybe ->ras_accessed_in_window is better name.
582          *
583          * XXX nikita: window is also reset (by ras_update()) when Lustre
584          * believes that memory pressure evicts read-ahead pages. In that
585          * case, it probably doesn't make sense to expand window to
586          * PTLRPC_MAX_BRW_PAGES on the third access.
587          */
588         unsigned long   ras_consecutive_pages;
589         /*
590          * number of read requests after the last read-ahead window reset
591          * As window is reset on each seek, this is effectively the number
592          * on consecutive read request and is used to trigger read-ahead.
593          */
594         unsigned long   ras_consecutive_requests;
595         /*
596          * Parameters of current read-ahead window. Handled by
597          * ras_update(). On the initial access to the file or after a seek,
598          * window is reset to 0. After 3 consecutive accesses, window is
599          * expanded to PTLRPC_MAX_BRW_PAGES. Afterwards, window is enlarged by
600          * PTLRPC_MAX_BRW_PAGES chunks up to ->ra_max_pages.
601          */
602         unsigned long   ras_window_start, ras_window_len;
603         /*
604          * Where next read-ahead should start at. This lies within read-ahead
605          * window. Read-ahead window is read in pieces rather than at once
606          * because: 1. lustre limits total number of pages under read-ahead by
607          * ->ra_max_pages (see ll_ra_count_get()), 2. client cannot read pages
608          * not covered by DLM lock.
609          */
610         unsigned long   ras_next_readahead;
611         /*
612          * Total number of ll_file_read requests issued, reads originating
613          * due to mmap are not counted in this total.  This value is used to
614          * trigger full file read-ahead after multiple reads to a small file.
615          */
616         unsigned long   ras_requests;
617         /*
618          * Page index with respect to the current request, these value
619          * will not be accurate when dealing with reads issued via mmap.
620          */
621         unsigned long   ras_request_index;
622         /*
623          * The following 3 items are used for detecting the stride I/O
624          * mode.
625          * In stride I/O mode,
626          * ...............|-----data-----|****gap*****|--------|******|....
627          *    offset      |-stride_pages-|-stride_gap-|
628          * ras_stride_offset = offset;
629          * ras_stride_length = stride_pages + stride_gap;
630          * ras_stride_pages = stride_pages;
631          * Note: all these three items are counted by pages.
632          */
633         unsigned long   ras_stride_length;
634         unsigned long   ras_stride_pages;
635         pgoff_t         ras_stride_offset;
636         /*
637          * number of consecutive stride request count, and it is similar as
638          * ras_consecutive_requests, but used for stride I/O mode.
639          * Note: only more than 2 consecutive stride request are detected,
640          * stride read-ahead will be enable
641          */
642         unsigned long   ras_consecutive_stride_requests;
643 };
644
645 extern struct kmem_cache *ll_file_data_slab;
646 struct lustre_handle;
647 struct ll_file_data {
648         struct ll_readahead_state fd_ras;
649         struct ll_grouplock fd_grouplock;
650         __u64 lfd_pos;
651         __u32 fd_flags;
652         fmode_t fd_omode;
653         /* openhandle if lease exists for this file.
654          * Borrow lli->lli_och_mutex to protect assignment */
655         struct obd_client_handle *fd_lease_och;
656         struct obd_client_handle *fd_och;
657         struct file *fd_file;
658         /* Indicate whether need to report failure when close.
659          * true: failure is known, not report again.
660          * false: unknown failure, should report. */
661         bool fd_write_failed;
662         rwlock_t fd_lock; /* protect lcc list */
663         struct list_head fd_lccs; /* list of ll_cl_context */
664 };
665
666 struct lov_stripe_md;
667
668 extern spinlock_t inode_lock;
669
670 extern struct proc_dir_entry *proc_lustre_fs_root;
671
672 static inline struct inode *ll_info2i(struct ll_inode_info *lli)
673 {
674         return &lli->lli_vfs_inode;
675 }
676
677 __u32 ll_i2suppgid(struct inode *i);
678 void ll_i2gids(__u32 *suppgids, struct inode *i1,struct inode *i2);
679
680 static inline int ll_need_32bit_api(struct ll_sb_info *sbi)
681 {
682 #if BITS_PER_LONG == 32
683         return 1;
684 #elif defined(CONFIG_COMPAT)
685         return unlikely(is_compat_task() || (sbi->ll_flags & LL_SBI_32BIT_API));
686 #else
687         return unlikely(sbi->ll_flags & LL_SBI_32BIT_API);
688 #endif
689 }
690
691 void ll_ras_enter(struct file *f);
692
693 /* llite/lcommon_misc.c */
694 int cl_ocd_update(struct obd_device *host, struct obd_device *watched,
695                   enum obd_notify_event ev, void *owner, void *data);
696 int cl_get_grouplock(struct cl_object *obj, unsigned long gid, int nonblock,
697                      struct ll_grouplock *lg);
698 void cl_put_grouplock(struct ll_grouplock *lg);
699
700 /* llite/lproc_llite.c */
701 #ifdef CONFIG_PROC_FS
702 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
703                                 struct super_block *sb, char *osc, char *mdc);
704 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi);
705 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count);
706 extern struct lprocfs_vars lprocfs_llite_obd_vars[];
707 #else
708 static inline int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
709                         struct super_block *sb, char *osc, char *mdc){return 0;}
710 static inline void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi) {}
711 static void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count) {}
712 #endif
713
714 enum {
715         LPROC_LL_DIRTY_HITS,
716         LPROC_LL_DIRTY_MISSES,
717         LPROC_LL_READ_BYTES,
718         LPROC_LL_WRITE_BYTES,
719         LPROC_LL_BRW_READ,
720         LPROC_LL_BRW_WRITE,
721         LPROC_LL_OSC_READ,
722         LPROC_LL_OSC_WRITE,
723         LPROC_LL_IOCTL,
724         LPROC_LL_OPEN,
725         LPROC_LL_RELEASE,
726         LPROC_LL_MAP,
727         LPROC_LL_LLSEEK,
728         LPROC_LL_FSYNC,
729         LPROC_LL_READDIR,
730         LPROC_LL_SETATTR,
731         LPROC_LL_TRUNC,
732         LPROC_LL_FLOCK,
733         LPROC_LL_GETATTR,
734         LPROC_LL_CREATE,
735         LPROC_LL_LINK,
736         LPROC_LL_UNLINK,
737         LPROC_LL_SYMLINK,
738         LPROC_LL_MKDIR,
739         LPROC_LL_RMDIR,
740         LPROC_LL_MKNOD,
741         LPROC_LL_RENAME,
742         LPROC_LL_STAFS,
743         LPROC_LL_ALLOC_INODE,
744         LPROC_LL_SETXATTR,
745         LPROC_LL_GETXATTR,
746         LPROC_LL_GETXATTR_HITS,
747         LPROC_LL_LISTXATTR,
748         LPROC_LL_REMOVEXATTR,
749         LPROC_LL_INODE_PERM,
750         LPROC_LL_FILE_OPCODES
751 };
752
753 /* llite/dir.c */
754 struct ll_dir_chain {
755 };
756
757 static inline void ll_dir_chain_init(struct ll_dir_chain *chain)
758 {
759 }
760
761 static inline void ll_dir_chain_fini(struct ll_dir_chain *chain)
762 {
763 }
764
765 extern const struct file_operations ll_dir_operations;
766 extern const struct inode_operations ll_dir_inode_operations;
767 #ifdef HAVE_DIR_CONTEXT
768 int ll_dir_read(struct inode *inode, __u64 *pos, struct md_op_data *op_data,
769                 struct dir_context *ctx);
770 #else
771 int ll_dir_read(struct inode *inode, __u64 *pos, struct md_op_data *op_data,
772                 void *cookie, filldir_t filldir);
773 #endif
774 int ll_get_mdt_idx(struct inode *inode);
775 int ll_get_mdt_idx_by_fid(struct ll_sb_info *sbi, const struct lu_fid *fid);
776 struct page *ll_get_dir_page(struct inode *dir, struct md_op_data *op_data,
777                              __u64 offset, struct ll_dir_chain *chain);
778 void ll_release_page(struct inode *inode, struct page *page, bool remove);
779
780 /* llite/namei.c */
781 extern const struct inode_operations ll_special_inode_operations;
782
783 struct inode *ll_iget(struct super_block *sb, ino_t hash,
784                       struct lustre_md *lic);
785 int ll_test_inode_by_fid(struct inode *inode, void *opaque);
786 int ll_md_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
787                        void *data, int flag);
788 struct dentry *ll_splice_alias(struct inode *inode, struct dentry *de);
789 int ll_rmdir_entry(struct inode *dir, char *name, int namelen);
790 void ll_update_times(struct ptlrpc_request *request, struct inode *inode);
791
792 /* llite/rw.c */
793 int ll_writepage(struct page *page, struct writeback_control *wbc);
794 int ll_writepages(struct address_space *, struct writeback_control *wbc);
795 int ll_readpage(struct file *file, struct page *page);
796 void ll_readahead_init(struct inode *inode, struct ll_readahead_state *ras);
797 int vvp_io_write_commit(const struct lu_env *env, struct cl_io *io);
798 struct ll_cl_context *ll_cl_find(struct file *file);
799 void ll_cl_add(struct file *file, const struct lu_env *env, struct cl_io *io);
800 void ll_cl_remove(struct file *file, const struct lu_env *env);
801
802 #ifndef MS_HAS_NEW_AOPS
803 extern const struct address_space_operations ll_aops;
804 #else
805 extern const struct address_space_operations_ext ll_aops;
806 #endif
807
808 /* llite/file.c */
809 extern struct file_operations ll_file_operations;
810 extern struct file_operations ll_file_operations_flock;
811 extern struct file_operations ll_file_operations_noflock;
812 extern struct inode_operations ll_file_inode_operations;
813 extern int ll_have_md_lock(struct inode *inode, __u64 *bits,
814                            ldlm_mode_t l_req_mode);
815 extern ldlm_mode_t ll_take_md_lock(struct inode *inode, __u64 bits,
816                                    struct lustre_handle *lockh, __u64 flags,
817                                    ldlm_mode_t mode);
818
819 int ll_file_open(struct inode *inode, struct file *file);
820 int ll_file_release(struct inode *inode, struct file *file);
821 int ll_release_openhandle(struct dentry *, struct lookup_intent *);
822 int ll_md_real_close(struct inode *inode, fmode_t fmode);
823 void ll_pack_inode2opdata(struct inode *inode, struct md_op_data *op_data,
824                           struct lustre_handle *fh);
825 extern void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
826                               struct ll_file_data *file, loff_t pos,
827                               size_t count, int rw);
828 int ll_getattr(struct vfsmount *mnt, struct dentry *de, struct kstat *stat);
829 struct posix_acl *ll_get_acl(struct inode *inode, int type);
830 int ll_migrate(struct inode *parent, struct file *file, int mdtidx,
831                const char *name, int namelen);
832 int ll_get_fid_by_name(struct inode *parent, const char *name,
833                        int namelen, struct lu_fid *fid);
834 #ifdef HAVE_GENERIC_PERMISSION_4ARGS
835 int ll_inode_permission(struct inode *inode, int mask, unsigned int flags);
836 #else
837 # ifndef HAVE_INODE_PERMISION_2ARGS
838 int ll_inode_permission(struct inode *inode, int mask, struct nameidata *nd);
839 # else
840 int ll_inode_permission(struct inode *inode, int mask);
841 # endif
842 #endif
843
844 int ll_lov_setstripe_ea_info(struct inode *inode, struct file *file,
845                              __u64  flags, struct lov_user_md *lum,
846                              int lum_size);
847 int ll_lov_getstripe_ea_info(struct inode *inode, const char *filename,
848                              struct lov_mds_md **lmm, int *lmm_size,
849                              struct ptlrpc_request **request);
850 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
851                      int set_default);
852 int ll_dir_getstripe(struct inode *inode, void **lmmp,
853                      int *lmm_size, struct ptlrpc_request **request,
854                      u64 valid);
855 #ifdef HAVE_FILE_FSYNC_4ARGS
856 int ll_fsync(struct file *file, loff_t start, loff_t end, int data);
857 #elif defined(HAVE_FILE_FSYNC_2ARGS)
858 int ll_fsync(struct file *file, int data);
859 #else
860 int ll_fsync(struct file *file, struct dentry *dentry, int data);
861 #endif
862 int ll_merge_attr(const struct lu_env *env, struct inode *inode);
863 int ll_fid2path(struct inode *inode, void __user *arg);
864 int ll_data_version(struct inode *inode, __u64 *data_version, int flags);
865 int ll_hsm_release(struct inode *inode);
866
867 /* llite/dcache.c */
868
869 int ll_d_init(struct dentry *de);
870 extern const struct dentry_operations ll_d_ops;
871 void ll_intent_drop_lock(struct lookup_intent *);
872 void ll_intent_release(struct lookup_intent *);
873 void ll_invalidate_aliases(struct inode *);
874 void ll_lookup_finish_locks(struct lookup_intent *it, struct dentry *dentry);
875 int ll_revalidate_it_finish(struct ptlrpc_request *request,
876                             struct lookup_intent *it, struct dentry *de);
877
878 /* llite/llite_lib.c */
879 extern struct super_operations lustre_super_operations;
880
881 void ll_lli_init(struct ll_inode_info *lli);
882 int ll_fill_super(struct super_block *sb, struct vfsmount *mnt);
883 void ll_put_super(struct super_block *sb);
884 void ll_kill_super(struct super_block *sb);
885 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock);
886 void ll_clear_inode(struct inode *inode);
887 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr, bool hsm_import);
888 int ll_setattr(struct dentry *de, struct iattr *attr);
889 int ll_statfs(struct dentry *de, struct kstatfs *sfs);
890 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
891                        __u64 max_age, __u32 flags);
892 int ll_update_inode(struct inode *inode, struct lustre_md *md);
893 int ll_read_inode2(struct inode *inode, void *opaque);
894 void ll_delete_inode(struct inode *inode);
895 int ll_iocontrol(struct inode *inode, struct file *file,
896                  unsigned int cmd, unsigned long arg);
897 int ll_flush_ctx(struct inode *inode);
898 void ll_umount_begin(struct super_block *sb);
899 int ll_remount_fs(struct super_block *sb, int *flags, char *data);
900 #ifdef HAVE_SUPEROPS_USE_DENTRY
901 int ll_show_options(struct seq_file *seq, struct dentry *dentry);
902 #else
903 int ll_show_options(struct seq_file *seq, struct vfsmount *vfs);
904 #endif
905 void ll_dirty_page_discard_warn(struct page *page, int ioret);
906 int ll_prep_inode(struct inode **inode, struct ptlrpc_request *req,
907                   struct super_block *, struct lookup_intent *);
908 void lustre_dump_dentry(struct dentry *, int recur);
909 int ll_obd_statfs(struct inode *inode, void __user *arg);
910 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *max_mdsize);
911 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *default_mdsize);
912 int ll_set_default_mdsize(struct ll_sb_info *sbi, int default_mdsize);
913 int ll_get_max_cookiesize(struct ll_sb_info *sbi, int *max_cookiesize);
914 int ll_get_default_cookiesize(struct ll_sb_info *sbi, int *default_cookiesize);
915 int ll_process_config(struct lustre_cfg *lcfg);
916
917 enum {
918         LUSTRE_OPC_MKDIR        = 0,
919         LUSTRE_OPC_SYMLINK      = 1,
920         LUSTRE_OPC_MKNOD        = 2,
921         LUSTRE_OPC_CREATE       = 3,
922         LUSTRE_OPC_ANY          = 5,
923 };
924
925 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
926                                       struct inode *i1, struct inode *i2,
927                                       const char *name, size_t namelen,
928                                       __u32 mode, __u32 opc, void *data);
929 void ll_finish_md_op_data(struct md_op_data *op_data);
930 int ll_get_obd_name(struct inode *inode, unsigned int cmd, unsigned long arg);
931 char *ll_get_fsname(struct super_block *sb, char *buf, int buflen);
932 void ll_compute_rootsquash_state(struct ll_sb_info *sbi);
933 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
934                         struct lov_user_md **kbuf);
935 void ll_open_cleanup(struct super_block *sb, struct ptlrpc_request *open_req);
936
937 /* Compute expected user md size when passing in a md from user space */
938 static inline ssize_t ll_lov_user_md_size(const struct lov_user_md *lum)
939 {
940         switch (lum->lmm_magic) {
941         case LOV_USER_MAGIC_V1:
942                 return sizeof(struct lov_user_md_v1);
943         case LOV_USER_MAGIC_V3:
944                 return sizeof(struct lov_user_md_v3);
945         case LOV_USER_MAGIC_SPECIFIC:
946                 if (lum->lmm_stripe_count > LOV_MAX_STRIPE_COUNT)
947                         return -EINVAL;
948
949                 return lov_user_md_size(lum->lmm_stripe_count,
950                                         LOV_USER_MAGIC_SPECIFIC);
951         }
952
953         return -EINVAL;
954 }
955
956 /* llite/llite_nfs.c */
957 extern struct export_operations lustre_export_operations;
958 __u32 get_uuid2int(const char *name, int len);
959 struct inode *search_inode_for_lustre(struct super_block *sb,
960                                       const struct lu_fid *fid);
961 int ll_dir_get_parent_fid(struct inode *dir, struct lu_fid *parent_fid);
962
963 /* llite/symlink.c */
964 extern struct inode_operations ll_fast_symlink_inode_operations;
965
966 /**
967  * IO arguments for various VFS I/O interfaces.
968  */
969 struct vvp_io_args {
970         /** normal/sendfile/splice */
971         enum vvp_io_subtype via_io_subtype;
972
973         union {
974                 struct {
975                         struct kiocb      *via_iocb;
976                         struct iovec      *via_iov;
977                         unsigned long      via_nrsegs;
978                 } normal;
979                 struct {
980                         struct pipe_inode_info  *via_pipe;
981                         unsigned int       via_flags;
982                 } splice;
983         } u;
984 };
985
986 struct ll_cl_context {
987         struct list_head         lcc_list;
988         void                    *lcc_cookie;
989         const struct lu_env     *lcc_env;
990         struct cl_io            *lcc_io;
991         struct cl_page          *lcc_page;
992 };
993
994 struct ll_thread_info {
995         struct iovec            lti_local_iov;
996         struct vvp_io_args      lti_args;
997         struct ra_io_arg        lti_ria;
998         struct kiocb            lti_kiocb;
999         struct ll_cl_context    lti_io_ctx;
1000 };
1001
1002 extern struct lu_context_key ll_thread_key;
1003
1004 static inline struct ll_thread_info *ll_env_info(const struct lu_env *env)
1005 {
1006         struct ll_thread_info *lti;
1007
1008         lti = lu_context_key_get(&env->le_ctx, &ll_thread_key);
1009         LASSERT(lti != NULL);
1010
1011         return lti;
1012 }
1013
1014 static inline struct vvp_io_args *ll_env_args(const struct lu_env *env,
1015                                               enum vvp_io_subtype type)
1016 {
1017         struct vvp_io_args *via = &ll_env_info(env)->lti_args;
1018
1019         via->via_io_subtype = type;
1020
1021         return via;
1022 }
1023
1024 /* llite/llite_mmap.c */
1025
1026 int ll_teardown_mmaps(struct address_space *mapping, __u64 first, __u64 last);
1027 int ll_file_mmap(struct file * file, struct vm_area_struct * vma);
1028 void policy_from_vma(ldlm_policy_data_t *policy,
1029                 struct vm_area_struct *vma, unsigned long addr, size_t count);
1030 struct vm_area_struct *our_vma(struct mm_struct *mm, unsigned long addr,
1031                                size_t count);
1032
1033 static inline void ll_invalidate_page(struct page *vmpage)
1034 {
1035         struct address_space *mapping = vmpage->mapping;
1036         loff_t offset = vmpage->index << PAGE_CACHE_SHIFT;
1037
1038         LASSERT(PageLocked(vmpage));
1039         if (mapping == NULL)
1040                 return;
1041
1042         /*
1043          * truncate_complete_page() calls
1044          * a_ops->invalidatepage()->cl_page_delete()->vvp_page_delete().
1045          */
1046         ll_teardown_mmaps(mapping, offset, offset + PAGE_CACHE_SIZE);
1047         truncate_complete_page(mapping, vmpage);
1048 }
1049
1050 #define    ll_s2sbi(sb)        (s2lsi(sb)->lsi_llsbi)
1051
1052 /* don't need an addref as the sb_info should be holding one */
1053 static inline struct obd_export *ll_s2dtexp(struct super_block *sb)
1054 {
1055         return ll_s2sbi(sb)->ll_dt_exp;
1056 }
1057
1058 /* don't need an addref as the sb_info should be holding one */
1059 static inline struct obd_export *ll_s2mdexp(struct super_block *sb)
1060 {
1061         return ll_s2sbi(sb)->ll_md_exp;
1062 }
1063
1064 static inline struct client_obd *sbi2mdc(struct ll_sb_info *sbi)
1065 {
1066         struct obd_device *obd = sbi->ll_md_exp->exp_obd;
1067         if (obd == NULL)
1068                 LBUG();
1069         return &obd->u.cli;
1070 }
1071
1072 // FIXME: replace the name of this with LL_SB to conform to kernel stuff
1073 static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
1074 {
1075         return ll_s2sbi(inode->i_sb);
1076 }
1077
1078 static inline struct obd_export *ll_i2dtexp(struct inode *inode)
1079 {
1080         return ll_s2dtexp(inode->i_sb);
1081 }
1082
1083 static inline struct obd_export *ll_i2mdexp(struct inode *inode)
1084 {
1085         return ll_s2mdexp(inode->i_sb);
1086 }
1087
1088 static inline struct lu_fid *ll_inode2fid(struct inode *inode)
1089 {
1090         struct lu_fid *fid;
1091
1092         LASSERT(inode != NULL);
1093         fid = &ll_i2info(inode)->lli_fid;
1094
1095         return fid;
1096 }
1097
1098 static inline __u64 ll_file_maxbytes(struct inode *inode)
1099 {
1100         return ll_i2info(inode)->lli_maxbytes;
1101 }
1102
1103 /* llite/xattr.c */
1104 int ll_setxattr(struct dentry *dentry, const char *name,
1105                 const void *value, size_t size, int flags);
1106 ssize_t ll_getxattr(struct dentry *dentry, const char *name,
1107                     void *buffer, size_t size);
1108 ssize_t ll_listxattr(struct dentry *dentry, char *buffer, size_t size);
1109 int ll_removexattr(struct dentry *dentry, const char *name);
1110
1111 /* llite/remote_perm.c */
1112 extern struct kmem_cache *ll_remote_perm_cachep;
1113 extern struct kmem_cache *ll_rmtperm_hash_cachep;
1114
1115 void free_rmtperm_hash(struct hlist_head *hash);
1116 int ll_update_remote_perm(struct inode *inode, struct mdt_remote_perm *perm);
1117 int lustre_check_remote_perm(struct inode *inode, int mask);
1118
1119 /* llite/llite_capa.c */
1120 extern struct timer_list ll_capa_timer;
1121
1122 int ll_capa_thread_start(void);
1123 void ll_capa_thread_stop(void);
1124 void ll_capa_timer_callback(unsigned long unused);
1125
1126 struct obd_capa *ll_add_capa(struct inode *inode, struct obd_capa *ocapa);
1127
1128 void ll_capa_open(struct inode *inode);
1129 void ll_capa_close(struct inode *inode);
1130
1131 struct obd_capa *ll_mdscapa_get(struct inode *inode);
1132 struct obd_capa *ll_osscapa_get(struct inode *inode, __u64 opc);
1133
1134 void ll_truncate_free_capa(struct obd_capa *ocapa);
1135 void ll_clear_inode_capas(struct inode *inode);
1136 void ll_print_capa_stat(struct ll_sb_info *sbi);
1137
1138 /**
1139  * Common IO arguments for various VFS I/O interfaces.
1140  */
1141 int cl_sb_init(struct super_block *sb);
1142 int cl_sb_fini(struct super_block *sb);
1143
1144 void ll_ra_count_put(struct ll_sb_info *sbi, unsigned long len);
1145 void ll_ra_stats_inc(struct inode *inode, enum ra_stat which);
1146
1147 /* llite/llite_rmtacl.c */
1148 #ifdef CONFIG_FS_POSIX_ACL
1149 u64 rce_ops2valid(int ops);
1150 struct rmtacl_ctl_entry *rct_search(struct rmtacl_ctl_table *rct, pid_t key);
1151 int rct_add(struct rmtacl_ctl_table *rct, pid_t key, int ops);
1152 int rct_del(struct rmtacl_ctl_table *rct, pid_t key);
1153 void rct_init(struct rmtacl_ctl_table *rct);
1154 void rct_fini(struct rmtacl_ctl_table *rct);
1155
1156 void ee_free(struct eacl_entry *ee);
1157 int ee_add(struct eacl_table *et, pid_t key, struct lu_fid *fid, int type,
1158            ext_acl_xattr_header *header);
1159 struct eacl_entry *et_search_del(struct eacl_table *et, pid_t key,
1160                                  struct lu_fid *fid, int type);
1161 void et_search_free(struct eacl_table *et, pid_t key);
1162 void et_init(struct eacl_table *et);
1163 void et_fini(struct eacl_table *et);
1164 #endif
1165
1166 /* statahead.c */
1167
1168 #define LL_SA_RPC_MIN           2
1169 #define LL_SA_RPC_DEF           32
1170 #define LL_SA_RPC_MAX           8192
1171
1172 #define LL_SA_CACHE_BIT         5
1173 #define LL_SA_CACHE_SIZE        (1 << LL_SA_CACHE_BIT)
1174 #define LL_SA_CACHE_MASK        (LL_SA_CACHE_SIZE - 1)
1175
1176 /* per inode struct, for dir only */
1177 struct ll_statahead_info {
1178         struct dentry          *sai_dentry;
1179         atomic_t                sai_refcount;   /* when access this struct, hold
1180                                                  * refcount */
1181         unsigned int            sai_max;        /* max ahead of lookup */
1182         __u64                   sai_sent;       /* stat requests sent count */
1183         __u64                   sai_replied;    /* stat requests which received
1184                                                  * reply */
1185         __u64                   sai_index;      /* index of statahead entry */
1186         __u64                   sai_index_wait; /* index of entry which is the
1187                                                  * caller is waiting for */
1188         __u64                   sai_hit;        /* hit count */
1189         __u64                   sai_miss;       /* miss count:
1190                                                  * for "ls -al" case, includes
1191                                                  * hidden dentry miss;
1192                                                  * for "ls -l" case, it does not
1193                                                  * include hidden dentry miss.
1194                                                  * "sai_miss_hidden" is used for
1195                                                  * the later case.
1196                                                  */
1197         unsigned int            sai_consecutive_miss; /* consecutive miss */
1198         unsigned int            sai_miss_hidden;/* "ls -al", but first dentry
1199                                                  * is not a hidden one */
1200         unsigned int            sai_skip_hidden;/* skipped hidden dentry count
1201                                                  */
1202         unsigned int            sai_ls_all:1,   /* "ls -al", do stat-ahead for
1203                                                  * hidden entries */
1204                                 sai_agl_valid:1,/* AGL is valid for the dir */
1205                                 sai_in_readpage:1;/* statahead is in readdir()*/
1206         wait_queue_head_t       sai_waitq;      /* stat-ahead wait queue */
1207         struct ptlrpc_thread    sai_thread;     /* stat-ahead thread */
1208         struct ptlrpc_thread    sai_agl_thread; /* AGL thread */
1209         struct list_head        sai_interim_entries; /* entries which got async
1210                                                       * stat reply, but not
1211                                                       * instantiated */
1212         struct list_head        sai_entries;    /* completed entries */
1213         struct list_head        sai_agls;       /* AGLs to be sent */
1214         struct list_head        sai_cache[LL_SA_CACHE_SIZE];
1215         spinlock_t              sai_cache_lock[LL_SA_CACHE_SIZE];
1216         atomic_t                sai_cache_count; /* entry count in cache */
1217 };
1218
1219 int ll_statahead(struct inode *dir, struct dentry **dentry, bool unplug);
1220 void ll_authorize_statahead(struct inode *dir, void *key);
1221 void ll_deauthorize_statahead(struct inode *dir, void *key);
1222
1223 /* glimpse.c */
1224 blkcnt_t dirty_cnt(struct inode *inode);
1225
1226 int cl_glimpse_size0(struct inode *inode, int agl);
1227 int cl_glimpse_lock(const struct lu_env *env, struct cl_io *io,
1228                     struct inode *inode, struct cl_object *clob, int agl);
1229
1230 static inline int cl_glimpse_size(struct inode *inode)
1231 {
1232         return cl_glimpse_size0(inode, 0);
1233 }
1234
1235 static inline int cl_agl(struct inode *inode)
1236 {
1237         return cl_glimpse_size0(inode, 1);
1238 }
1239
1240 static inline int ll_glimpse_size(struct inode *inode)
1241 {
1242         struct ll_inode_info *lli = ll_i2info(inode);
1243         int rc;
1244
1245         down_read(&lli->lli_glimpse_sem);
1246         rc = cl_glimpse_size(inode);
1247         lli->lli_glimpse_time = cfs_time_current();
1248         up_read(&lli->lli_glimpse_sem);
1249         return rc;
1250 }
1251
1252 /* dentry may statahead when statahead is enabled and current process has opened
1253  * parent directory, and this dentry hasn't accessed statahead cache before */
1254 static inline bool
1255 dentry_may_statahead(struct inode *dir, struct dentry *dentry)
1256 {
1257         struct ll_inode_info  *lli;
1258         struct ll_dentry_data *ldd;
1259
1260         if (ll_i2sbi(dir)->ll_sa_max == 0)
1261                 return false;
1262
1263         lli = ll_i2info(dir);
1264
1265         /* statahead is not allowed for this dir, there may be three causes:
1266          * 1. dir is not opened.
1267          * 2. statahead hit ratio is too low.
1268          * 3. previous stat started statahead thread failed. */
1269         if (!lli->lli_sa_enabled)
1270                 return false;
1271
1272         /* not the same process, don't statahead */
1273         if (lli->lli_opendir_pid != current_pid())
1274                 return false;
1275
1276         /*
1277          * When stating a dentry, kernel may trigger 'revalidate' or 'lookup'
1278          * multiple times, eg. for 'getattr', 'getxattr' and etc.
1279          * For patchless client, lookup intent is not accurate, which may
1280          * misguide statahead. For example:
1281          * The 'revalidate' call for 'getattr' and 'getxattr' of a dentry will
1282          * have the same intent -- IT_GETATTR, while one dentry should access
1283          * statahead cache once, otherwise statahead windows is messed up.
1284          * The solution is as following:
1285          * Assign 'lld_sa_generation' with 'lli_sa_generation' when a dentry
1286          * IT_GETATTR for the first time, and subsequent IT_GETATTR will
1287          * bypass interacting with statahead cache by checking
1288          * 'lld_sa_generation == lli->lli_sa_generation'.
1289          */
1290         ldd = ll_d2d(dentry);
1291         if (ldd != NULL && ldd->lld_sa_generation == lli->lli_sa_generation)
1292                 return false;
1293
1294         return true;
1295 }
1296
1297 /* llite ioctl register support rountine */
1298 enum llioc_iter {
1299         LLIOC_CONT = 0,
1300         LLIOC_STOP
1301 };
1302
1303 #define LLIOC_MAX_CMD           256
1304
1305 /*
1306  * Rules to write a callback function:
1307  *
1308  * Parameters:
1309  *  @magic: Dynamic ioctl call routine will feed this vaule with the pointer
1310  *      returned to ll_iocontrol_register.  Callback functions should use this
1311  *      data to check the potential collasion of ioctl cmd. If collasion is
1312  *      found, callback function should return LLIOC_CONT.
1313  *  @rcp: The result of ioctl command.
1314  *
1315  *  Return values:
1316  *      If @magic matches the pointer returned by ll_iocontrol_data, the
1317  *      callback should return LLIOC_STOP; return LLIOC_STOP otherwise.
1318  */
1319 typedef enum llioc_iter (*llioc_callback_t)(struct inode *inode,
1320                 struct file *file, unsigned int cmd, unsigned long arg,
1321                 void *magic, int *rcp);
1322
1323 /* export functions */
1324 /* Register ioctl block dynamatically for a regular file.
1325  *
1326  * @cmd: the array of ioctl command set
1327  * @count: number of commands in the @cmd
1328  * @cb: callback function, it will be called if an ioctl command is found to
1329  *      belong to the command list @cmd.
1330  *
1331  * Return vaule:
1332  *      A magic pointer will be returned if success;
1333  *      otherwise, NULL will be returned.
1334  * */
1335 void *ll_iocontrol_register(llioc_callback_t cb, int count, unsigned int *cmd);
1336 void ll_iocontrol_unregister(void *magic);
1337
1338 struct obd_capa *cl_capa_lookup(struct inode *inode, enum cl_req_type crt);
1339
1340 int cl_sync_file_range(struct inode *inode, loff_t start, loff_t end,
1341                        enum cl_fsync_mode mode, int ignore_layout);
1342
1343 /** direct write pages */
1344 struct ll_dio_pages {
1345         /** page array to be written. we don't support
1346          * partial pages except the last one. */
1347         struct page **ldp_pages;
1348         /* offset of each page */
1349         loff_t       *ldp_offsets;
1350         /** if ldp_offsets is NULL, it means a sequential
1351          * pages to be written, then this is the file offset
1352          * of the * first page. */
1353         loff_t        ldp_start_offset;
1354         /** how many bytes are to be written. */
1355         size_t        ldp_size;
1356         /** # of pages in the array. */
1357         int           ldp_nr;
1358 };
1359
1360 static inline void cl_stats_tally(struct cl_device *dev, enum cl_req_type crt,
1361                                   int rc)
1362 {
1363         int opc = (crt == CRT_READ) ? LPROC_LL_OSC_READ :
1364                                       LPROC_LL_OSC_WRITE;
1365
1366         ll_stats_ops_tally(ll_s2sbi(cl2vvp_dev(dev)->vdv_sb), opc, rc);
1367 }
1368
1369 extern ssize_t ll_direct_rw_pages(const struct lu_env *env, struct cl_io *io,
1370                                   int rw, struct inode *inode,
1371                                   struct ll_dio_pages *pv);
1372
1373 static inline int ll_file_nolock(const struct file *file)
1374 {
1375         struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1376         struct inode *inode = file->f_dentry->d_inode;
1377
1378         LASSERT(fd != NULL);
1379         return ((fd->fd_flags & LL_FILE_IGNORE_LOCK) ||
1380                 (ll_i2sbi(inode)->ll_flags & LL_SBI_NOLCK));
1381 }
1382
1383 static inline void ll_set_lock_data(struct obd_export *exp, struct inode *inode,
1384                                     struct lookup_intent *it, __u64 *bits)
1385 {
1386         if (!it->d.lustre.it_lock_set) {
1387                 struct lustre_handle handle;
1388
1389                 /* If this inode is a remote object, it will get two
1390                  * separate locks in different namespaces, Master MDT,
1391                  * where the name entry is, will grant LOOKUP lock,
1392                  * remote MDT, where the object is, will grant
1393                  * UPDATE|PERM lock. The inode will be attched to both
1394                  * LOOKUP and PERM locks, so revoking either locks will
1395                  * case the dcache being cleared */
1396                 if (it->d.lustre.it_remote_lock_mode) {
1397                         handle.cookie = it->d.lustre.it_remote_lock_handle;
1398                         CDEBUG(D_DLMTRACE, "setting l_data to inode "DFID
1399                                "(%p) for remote lock "LPX64"\n",
1400                                PFID(ll_inode2fid(inode)), inode,
1401                                handle.cookie);
1402                         md_set_lock_data(exp, &handle.cookie, inode, NULL);
1403                 }
1404
1405                 handle.cookie = it->d.lustre.it_lock_handle;
1406
1407                 CDEBUG(D_DLMTRACE, "setting l_data to inode "DFID"(%p)"
1408                        " for lock "LPX64"\n",
1409                        PFID(ll_inode2fid(inode)), inode, handle.cookie);
1410
1411                 md_set_lock_data(exp, &handle.cookie, inode,
1412                                  &it->d.lustre.it_lock_bits);
1413                 it->d.lustre.it_lock_set = 1;
1414         }
1415
1416         if (bits != NULL)
1417                 *bits = it->d.lustre.it_lock_bits;
1418 }
1419
1420 static inline void ll_lock_dcache(struct inode *inode)
1421 {
1422 #ifdef HAVE_DCACHE_LOCK
1423         spin_lock(&dcache_lock);
1424 #else
1425         spin_lock(&inode->i_lock);
1426 #endif
1427 }
1428
1429 static inline void ll_unlock_dcache(struct inode *inode)
1430 {
1431 #ifdef HAVE_DCACHE_LOCK
1432         spin_unlock(&dcache_lock);
1433 #else
1434         spin_unlock(&inode->i_lock);
1435 #endif
1436 }
1437
1438 static inline int d_lustre_invalid(const struct dentry *dentry)
1439 {
1440         struct ll_dentry_data *lld = ll_d2d(dentry);
1441
1442         return (lld == NULL) || lld->lld_invalid;
1443 }
1444
1445 static inline void __d_lustre_invalidate(struct dentry *dentry)
1446 {
1447         struct ll_dentry_data *lld = ll_d2d(dentry);
1448
1449         if (lld != NULL)
1450                 lld->lld_invalid = 1;
1451 }
1452
1453 /*
1454  * Mark dentry INVALID, if dentry refcount is zero (this is normally case for
1455  * ll_md_blocking_ast), unhash this dentry, and let dcache to reclaim it later;
1456  * else dput() of the last refcount will unhash this dentry and kill it.
1457  */
1458 static inline void d_lustre_invalidate(struct dentry *dentry, int nested)
1459 {
1460         CDEBUG(D_DENTRY, "invalidate dentry %.*s (%p) parent %p inode %p "
1461                "refc %d\n", dentry->d_name.len, dentry->d_name.name, dentry,
1462                dentry->d_parent, dentry->d_inode, ll_d_count(dentry));
1463
1464         spin_lock_nested(&dentry->d_lock,
1465                          nested ? DENTRY_D_LOCK_NESTED : DENTRY_D_LOCK_NORMAL);
1466         __d_lustre_invalidate(dentry);
1467         if (ll_d_count(dentry) == 0)
1468                 __d_drop(dentry);
1469         spin_unlock(&dentry->d_lock);
1470 }
1471
1472 static inline void d_lustre_revalidate(struct dentry *dentry)
1473 {
1474         spin_lock(&dentry->d_lock);
1475         LASSERT(ll_d2d(dentry) != NULL);
1476         ll_d2d(dentry)->lld_invalid = 0;
1477         spin_unlock(&dentry->d_lock);
1478 }
1479
1480 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 53, 0)
1481 /* Compatibility for old (1.8) compiled userspace quota code */
1482 struct if_quotactl_18 {
1483         __u32                   qc_cmd;
1484         __u32                   qc_type;
1485         __u32                   qc_id;
1486         __u32                   qc_stat;
1487         struct obd_dqinfo       qc_dqinfo;
1488         struct obd_dqblk        qc_dqblk;
1489         char                    obd_type[16];
1490         struct obd_uuid         obd_uuid;
1491 };
1492 #define LL_IOC_QUOTACTL_18              _IOWR('f', 162, struct if_quotactl_18 *)
1493 /* End compatibility for old (1.8) compiled userspace quota code */
1494 #endif /* LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 53, 0) */
1495
1496 enum {
1497         LL_LAYOUT_GEN_NONE  = ((__u32)-2),      /* layout lock was cancelled */
1498         LL_LAYOUT_GEN_EMPTY = ((__u32)-1)       /* for empty layout */
1499 };
1500
1501 int ll_layout_conf(struct inode *inode, const struct cl_object_conf *conf);
1502 int ll_layout_refresh(struct inode *inode, __u32 *gen);
1503 int ll_layout_restore(struct inode *inode, loff_t start, __u64 length);
1504
1505 int ll_xattr_init(void);
1506 void ll_xattr_fini(void);
1507
1508 int ll_getxattr_common(struct inode *inode, const char *name,
1509                        void *buffer, size_t size, __u64 valid);
1510 int ll_page_sync_io(const struct lu_env *env, struct cl_io *io,
1511                     struct cl_page *page, enum cl_req_type crt);
1512
1513 int ll_getparent(struct file *file, struct getparent __user *arg);
1514
1515 /* lcommon_cl.c */
1516 int cl_setattr_ost(struct inode *inode, const struct iattr *attr,
1517                    struct obd_capa *capa);
1518
1519 extern struct lu_env *cl_inode_fini_env;
1520 extern int cl_inode_fini_refcheck;
1521
1522 int cl_file_inode_init(struct inode *inode, struct lustre_md *md);
1523 void cl_inode_fini(struct inode *inode);
1524 int cl_local_size(struct inode *inode);
1525
1526 u64 cl_fid_build_ino(const struct lu_fid *fid, int api32);
1527 u32 cl_fid_build_gen(const struct lu_fid *fid);
1528
1529 #endif /* LLITE_INTERNAL_H */