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