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