switch generic_file_splice_read() to use of ->read_iter()
[linux-block.git] / drivers / staging / lustre / lustre / llite / llite_internal.h
CommitLineData
d7e09d03
PT
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
6a5b99a4 18 * http://www.gnu.org/licenses/gpl-2.0.html
d7e09d03 19 *
d7e09d03
PT
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 *
1dc563a6 26 * Copyright (c) 2011, 2015, Intel Corporation.
d7e09d03
PT
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
67a235f5
GKH
35#include "../include/lustre_debug.h"
36#include "../include/lustre_ver.h"
37#include "../include/lustre_disk.h" /* for s2sbi */
38#include "../include/lustre_eacl.h"
d7e09d03
PT
39
40/* for struct cl_lock_descr and struct cl_io */
67a235f5 41#include "../include/cl_object.h"
67a235f5 42#include "../include/lustre_mdc.h"
00d65ec8 43#include "../include/lustre_intent.h"
c7c99012 44#include <linux/compat.h>
04eb2b7f 45#include <linux/posix_acl_xattr.h>
0d345656 46#include "vvp_internal.h"
d7e09d03
PT
47
48#ifndef FMODE_EXEC
49#define FMODE_EXEC 0
50#endif
51
52#ifndef VM_FAULT_RETRY
53#define VM_FAULT_RETRY 0
54#endif
55
d7e09d03
PT
56/** Only used on client-side for indicating the tail of dir hash/offset. */
57#define LL_DIR_END_OFF 0x7fffffffffffffffULL
58#define LL_DIR_END_OFF_32BIT 0x7fffffffUL
59
60#define LL_IT2STR(it) ((it) ? ldlm_it2str((it)->it_op) : "0")
61#define LUSTRE_FPRIVATE(file) ((file)->private_data)
62
63struct ll_dentry_data {
d7e09d03
PT
64 struct lookup_intent *lld_it;
65 unsigned int lld_sa_generation;
66 unsigned int lld_invalid:1;
6dad4d89 67 unsigned int lld_nfs_dentry:1;
d7e09d03
PT
68 struct rcu_head lld_rcu_head;
69};
70
b2952d62 71#define ll_d2d(de) ((struct ll_dentry_data *)((de)->d_fsdata))
d7e09d03 72
d7e09d03
PT
73#define LLI_INODE_MAGIC 0x111d0de5
74#define LLI_INODE_DEAD 0xdeadd00d
75
d7e09d03 76struct ll_getname_data {
0b09d381 77 struct dir_context ctx;
d7e09d03
PT
78 char *lgd_name; /* points to a buffer with NAME_MAX+1 size */
79 struct lu_fid lgd_fid; /* target fid we are looking for */
80 int lgd_found; /* inode matched? */
81};
82
98eae5e7
JH
83struct ll_grouplock {
84 struct lu_env *lg_env;
85 struct cl_io *lg_io;
86 struct cl_lock *lg_lock;
87 unsigned long lg_gid;
88};
89
d7e09d03
PT
90enum lli_flags {
91 /* MDS has an authority for the Size-on-MDS attributes. */
92 LLIF_MDS_SIZE_LOCK = (1 << 0),
93 /* Epoch close is postponed. */
94 LLIF_EPOCH_PENDING = (1 << 1),
95 /* DONE WRITING is allowed. */
96 LLIF_DONE_WRITING = (1 << 2),
97 /* Sizeon-on-MDS attributes are changed. An attribute update needs to
c0894c6c
OD
98 * be sent to MDS.
99 */
d7e09d03 100 LLIF_SOM_DIRTY = (1 << 3),
d7e09d03 101 /* File data is modified. */
2d95f10e 102 LLIF_DATA_MODIFIED = (1 << 4),
5ea17d6c 103 /* File is being restored */
2d95f10e 104 LLIF_FILE_RESTORING = (1 << 5),
7fc1f831 105 /* Xattr cache is attached to the file */
2d95f10e 106 LLIF_XATTR_CACHE = (1 << 6),
d7e09d03
PT
107};
108
109struct ll_inode_info {
110 __u32 lli_inode_magic;
111 __u32 lli_flags;
112 __u64 lli_ioepoch;
113
114 spinlock_t lli_lock;
115 struct posix_acl *lli_posix_acl;
116
d7e09d03
PT
117 /* identifying fields for both metadata and data stacks. */
118 struct lu_fid lli_fid;
119 /* Parent fid for accessing default stripe data on parent directory
c0894c6c
OD
120 * for allocating OST objects after a mknod() and later open-by-FID.
121 */
d7e09d03
PT
122 struct lu_fid lli_pfid;
123
82bd9200
OD
124 struct list_head lli_close_list;
125
d7e09d03
PT
126 /* handle is to be sent to MDS later on done_writing and setattr.
127 * Open handle data are needed for the recovery to reconstruct
c0894c6c
OD
128 * the inode state on the MDS. XXX: recovery is not ready yet.
129 */
d7e09d03
PT
130 struct obd_client_handle *lli_pending_och;
131
132 /* We need all three because every inode may be opened in different
c0894c6c
OD
133 * modes
134 */
d7e09d03
PT
135 struct obd_client_handle *lli_mds_read_och;
136 struct obd_client_handle *lli_mds_write_och;
137 struct obd_client_handle *lli_mds_exec_och;
138 __u64 lli_open_fd_read_count;
139 __u64 lli_open_fd_write_count;
140 __u64 lli_open_fd_exec_count;
141 /* Protects access to och pointers and their usage counters */
142 struct mutex lli_och_mutex;
143
144 struct inode lli_vfs_inode;
145
146 /* the most recent timestamps obtained from mds */
d2995737
JH
147 s64 lli_atime;
148 s64 lli_mtime;
149 s64 lli_ctime;
d7e09d03
PT
150 spinlock_t lli_agl_lock;
151
152 /* Try to make the d::member and f::member are aligned. Before using
c0894c6c
OD
153 * these members, make clear whether it is directory or not.
154 */
d7e09d03
PT
155 union {
156 /* for directory */
157 struct {
158 /* serialize normal readdir and statahead-readdir. */
159 struct mutex d_readdir_mutex;
160
161 /* metadata statahead */
162 /* since parent-child threads can share the same @file
163 * struct, "opendir_key" is the token when dir close for
164 * case of parent exit before child -- it is me should
c0894c6c
OD
165 * cleanup the dir readahead.
166 */
d7e09d03
PT
167 void *d_opendir_key;
168 struct ll_statahead_info *d_sai;
d7e09d03
PT
169 /* protect statahead stuff. */
170 spinlock_t d_sa_lock;
c0894c6c
OD
171 /* "opendir_pid" is the token when lookup/revalidate
172 * -- I am the owner of dir statahead.
173 */
d7e09d03
PT
174 pid_t d_opendir_pid;
175 } d;
176
177#define lli_readdir_mutex u.d.d_readdir_mutex
178#define lli_opendir_key u.d.d_opendir_key
179#define lli_sai u.d.d_sai
d7e09d03
PT
180#define lli_sa_lock u.d.d_sa_lock
181#define lli_opendir_pid u.d.d_opendir_pid
182
183 /* for non-directory */
184 struct {
47a57bde 185 struct mutex f_size_mutex;
d7e09d03
PT
186 char *f_symlink_name;
187 __u64 f_maxbytes;
188 /*
189 * struct rw_semaphore {
190 * signed long count; // align d.d_def_acl
191 * spinlock_t wait_lock; // align d.d_sa_lock
192 * struct list_head wait_list;
193 * }
194 */
195 struct rw_semaphore f_trunc_sem;
196 struct mutex f_write_mutex;
197
198 struct rw_semaphore f_glimpse_sem;
a649ad1d 199 unsigned long f_glimpse_time;
d7e09d03
PT
200 struct list_head f_agl_list;
201 __u64 f_agl_index;
202
203 /* for writepage() only to communicate to fsync */
204 int f_async_rc;
205
d7e09d03
PT
206 /*
207 * whenever a process try to read/write the file, the
208 * jobid of the process will be saved here, and it'll
209 * be packed into the write PRC when flush later.
210 *
211 * so the read/write statistics for jobid will not be
212 * accurate if the file is shared by different jobs.
213 */
214 char f_jobid[JOBSTATS_JOBID_SIZE];
215 } f;
216
47a57bde 217#define lli_size_mutex u.f.f_size_mutex
d7e09d03
PT
218#define lli_symlink_name u.f.f_symlink_name
219#define lli_maxbytes u.f.f_maxbytes
220#define lli_trunc_sem u.f.f_trunc_sem
221#define lli_write_mutex u.f.f_write_mutex
222#define lli_glimpse_sem u.f.f_glimpse_sem
223#define lli_glimpse_time u.f.f_glimpse_time
224#define lli_agl_list u.f.f_agl_list
225#define lli_agl_index u.f.f_agl_index
226#define lli_async_rc u.f.f_async_rc
227#define lli_jobid u.f.f_jobid
d7e09d03
PT
228
229 } u;
230
231 /* XXX: For following frequent used members, although they maybe special
232 * used for non-directory object, it is some time-wasting to check
233 * whether the object is directory or not before using them. On the
234 * other hand, currently, sizeof(f) > sizeof(d), it cannot reduce
235 * the "ll_inode_info" size even if moving those members into u.f.
236 * So keep them out side.
237 *
238 * In the future, if more members are added only for directory,
239 * some of the following members can be moved into u.f.
240 */
241 bool lli_has_smd;
242 struct cl_object *lli_clob;
243
244 /* mutex to request for layout lock exclusively. */
245 struct mutex lli_layout_mutex;
09aed8a5 246 /* Layout version, protected by lli_layout_lock */
d7e09d03 247 __u32 lli_layout_gen;
09aed8a5 248 spinlock_t lli_layout_lock;
7fc1f831
AP
249
250 struct rw_semaphore lli_xattrs_list_rwsem;
251 struct mutex lli_xattrs_enq_lock;
252 struct list_head lli_xattrs;/* ll_xattr_entry->xe_list */
d7e09d03
PT
253};
254
09aed8a5
JX
255static inline __u32 ll_layout_version_get(struct ll_inode_info *lli)
256{
257 __u32 gen;
258
259 spin_lock(&lli->lli_layout_lock);
260 gen = lli->lli_layout_gen;
261 spin_unlock(&lli->lli_layout_lock);
262
263 return gen;
264}
265
266static inline void ll_layout_version_set(struct ll_inode_info *lli, __u32 gen)
267{
268 spin_lock(&lli->lli_layout_lock);
269 lli->lli_layout_gen = gen;
270 spin_unlock(&lli->lli_layout_lock);
271}
272
7fc1f831
AP
273int ll_xattr_cache_destroy(struct inode *inode);
274
e15ba45d
OD
275int ll_xattr_cache_get(struct inode *inode, const char *name,
276 char *buffer, size_t size, __u64 valid);
7fc1f831 277
d7e09d03
PT
278/*
279 * Locking to guarantee consistency of non-atomic updates to long long i_size,
280 * consistency between file size and KMS.
281 *
47a57bde 282 * Implemented by ->lli_size_mutex and ->lsm_lock, nested in that order.
d7e09d03
PT
283 */
284
285void ll_inode_size_lock(struct inode *inode);
286void ll_inode_size_unlock(struct inode *inode);
287
995c8b4a
GD
288/* FIXME: replace the name of this with LL_I to conform to kernel stuff */
289/* static inline struct ll_inode_info *LL_I(struct inode *inode) */
d7e09d03
PT
290static inline struct ll_inode_info *ll_i2info(struct inode *inode)
291{
292 return container_of(inode, struct ll_inode_info, lli_vfs_inode);
293}
294
295/* default to about 40meg of readahead on a given system. That much tied
c0894c6c
OD
296 * up in 512k readahead requests serviced at 40ms each is about 1GB/s.
297 */
09cbfeaf 298#define SBI_DEFAULT_READAHEAD_MAX (40UL << (20 - PAGE_SHIFT))
d7e09d03
PT
299
300/* default to read-ahead full files smaller than 2MB on the second read */
09cbfeaf 301#define SBI_DEFAULT_READAHEAD_WHOLE_MAX (2UL << (20 - PAGE_SHIFT))
d7e09d03
PT
302
303enum ra_stat {
304 RA_STAT_HIT = 0,
305 RA_STAT_MISS,
306 RA_STAT_DISTANT_READPAGE,
307 RA_STAT_MISS_IN_WINDOW,
308 RA_STAT_FAILED_GRAB_PAGE,
309 RA_STAT_FAILED_MATCH,
310 RA_STAT_DISCARDED,
311 RA_STAT_ZERO_LEN,
312 RA_STAT_ZERO_WINDOW,
313 RA_STAT_EOF,
314 RA_STAT_MAX_IN_FLIGHT,
315 RA_STAT_WRONG_GRAB_PAGE,
fd7444fe 316 RA_STAT_FAILED_REACH_END,
d7e09d03
PT
317 _NR_RA_STAT,
318};
319
320struct ll_ra_info {
321 atomic_t ra_cur_pages;
322 unsigned long ra_max_pages;
323 unsigned long ra_max_pages_per_file;
324 unsigned long ra_max_read_ahead_whole_pages;
325};
326
327/* ra_io_arg will be filled in the beginning of ll_readahead with
328 * ras_lock, then the following ll_read_ahead_pages will read RA
329 * pages according to this arg, all the items in this structure are
330 * counted by page index.
331 */
332struct ra_io_arg {
333 unsigned long ria_start; /* start offset of read-ahead*/
334 unsigned long ria_end; /* end offset of read-ahead*/
335 /* If stride read pattern is detected, ria_stoff means where
336 * stride read is started. Note: for normal read-ahead, the
c0894c6c
OD
337 * value here is meaningless, and also it will not be accessed
338 */
d7e09d03
PT
339 pgoff_t ria_stoff;
340 /* ria_length and ria_pages are the length and pages length in the
341 * stride I/O mode. And they will also be used to check whether
c0894c6c
OD
342 * it is stride I/O read-ahead in the read-ahead pages
343 */
d7e09d03
PT
344 unsigned long ria_length;
345 unsigned long ria_pages;
346};
347
348/* LL_HIST_MAX=32 causes an overflow */
349#define LL_HIST_MAX 28
350#define LL_HIST_START 12 /* buckets start at 2^12 = 4k */
351#define LL_PROCESS_HIST_MAX 10
352struct per_process_info {
353 pid_t pid;
354 struct obd_histogram pp_r_hist;
355 struct obd_histogram pp_w_hist;
356};
357
358/* pp_extents[LL_PROCESS_HIST_MAX] will hold the combined process info */
359struct ll_rw_extents_info {
360 struct per_process_info pp_extents[LL_PROCESS_HIST_MAX + 1];
361};
362
363#define LL_OFFSET_HIST_MAX 100
364struct ll_rw_process_info {
365 pid_t rw_pid;
366 int rw_op;
367 loff_t rw_range_start;
368 loff_t rw_range_end;
369 loff_t rw_last_file_pos;
370 loff_t rw_offset;
371 size_t rw_smallest_extent;
372 size_t rw_largest_extent;
373 struct ll_file_data *rw_last_file;
374};
375
376enum stats_track_type {
377 STATS_TRACK_ALL = 0, /* track all processes */
378 STATS_TRACK_PID, /* track process with this pid */
379 STATS_TRACK_PPID, /* track processes with this ppid */
380 STATS_TRACK_GID, /* track processes with this gid */
381 STATS_TRACK_LAST,
382};
383
384/* flags for sbi->ll_flags */
385#define LL_SBI_NOLCK 0x01 /* DLM locking disabled (directio-only) */
386#define LL_SBI_CHECKSUM 0x02 /* checksum each page as it's written */
387#define LL_SBI_FLOCK 0x04
388#define LL_SBI_USER_XATTR 0x08 /* support user xattr */
389#define LL_SBI_ACL 0x10 /* support ACL */
341f1f0a 390/* LL_SBI_RMT_CLIENT 0x40 remote client */
ef2e0f55
OD
391#define LL_SBI_MDS_CAPA 0x80 /* support mds capa, obsolete */
392#define LL_SBI_OSS_CAPA 0x100 /* support oss capa, obsolete */
d7e09d03
PT
393#define LL_SBI_LOCALFLOCK 0x200 /* Local flocks support by kernel */
394#define LL_SBI_LRU_RESIZE 0x400 /* lru resize support */
395#define LL_SBI_LAZYSTATFS 0x800 /* lazystatfs mount option */
396#define LL_SBI_SOM_PREVIEW 0x1000 /* SOM preview mount option */
397#define LL_SBI_32BIT_API 0x2000 /* generate 32 bit inodes. */
398#define LL_SBI_64BIT_HASH 0x4000 /* support 64-bits dir hash/offset */
399#define LL_SBI_AGL_ENABLED 0x8000 /* enable agl */
400#define LL_SBI_VERBOSE 0x10000 /* verbose mount/umount */
401#define LL_SBI_LAYOUT_LOCK 0x20000 /* layout lock support */
402#define LL_SBI_USER_FID2PATH 0x40000 /* allow fid2path by unprivileged users */
7fc1f831 403#define LL_SBI_XATTR_CACHE 0x80000 /* support for xattr cache */
d7e09d03
PT
404
405#define LL_SBI_FLAGS { \
406 "nolck", \
407 "checksum", \
408 "flock", \
409 "xattr", \
410 "acl", \
7fc1f831 411 "???", \
341f1f0a 412 "???", \
d7e09d03
PT
413 "mds_capa", \
414 "oss_capa", \
415 "flock", \
416 "lru_resize", \
417 "lazy_statfs", \
418 "som", \
419 "32bit_api", \
420 "64bit_hash", \
421 "agl", \
422 "verbose", \
423 "layout", \
7fc1f831
AP
424 "user_fid2path",\
425 "xattr", \
426}
d7e09d03 427
d7e09d03 428struct ll_sb_info {
d7e09d03 429 /* this protects pglist and ra_info. It isn't safe to
c0894c6c
OD
430 * grab from interrupt contexts
431 */
d7e09d03
PT
432 spinlock_t ll_lock;
433 spinlock_t ll_pp_extent_lock; /* pp_extent entry*/
434 spinlock_t ll_process_lock; /* ll_rw_process_info */
435 struct obd_uuid ll_sb_uuid;
436 struct obd_export *ll_md_exp;
437 struct obd_export *ll_dt_exp;
ae7c0f48 438 struct dentry *ll_debugfs_entry;
d7e09d03
PT
439 struct lu_fid ll_root_fid; /* root object fid */
440
441 int ll_flags;
7fc1f831
AP
442 unsigned int ll_umounting:1,
443 ll_xattr_cache_enabled:1;
d7e09d03
PT
444 struct lustre_client_ocd ll_lco;
445
d7e09d03
PT
446 struct ll_close_queue *ll_lcq;
447
448 struct lprocfs_stats *ll_stats; /* lprocfs stats counter */
449
ac5b1481
PS
450 /*
451 * Used to track "unstable" pages on a client, and maintain a
452 * LRU list of clean pages. An "unstable" page is defined as
453 * any page which is sent to a server as part of a bulk request,
454 * but is uncommitted to stable storage.
455 */
1b02bde3 456 struct cl_client_cache *ll_cache;
d7e09d03
PT
457
458 struct lprocfs_stats *ll_ra_stats;
459
460 struct ll_ra_info ll_ra_info;
461 unsigned int ll_namelen;
462 struct file_operations *ll_fop;
463
d7e09d03
PT
464 unsigned int ll_md_brw_size; /* used by readdir */
465
466 struct lu_site *ll_site;
467 struct cl_device *ll_cl;
468 /* Statistics */
469 struct ll_rw_extents_info ll_rw_extents_info;
470 int ll_extent_process_count;
471 struct ll_rw_process_info ll_rw_process_info[LL_PROCESS_HIST_MAX];
472 unsigned int ll_offset_process_count;
473 struct ll_rw_process_info ll_rw_offset_info[LL_OFFSET_HIST_MAX];
474 unsigned int ll_rw_offset_entry_count;
475 int ll_stats_track_id;
476 enum stats_track_type ll_stats_track_type;
477 int ll_rw_stats_on;
478
479 /* metadata stat-ahead */
480 unsigned int ll_sa_max; /* max statahead RPCs */
481 atomic_t ll_sa_total; /* statahead thread started
c0894c6c
OD
482 * count
483 */
d7e09d03 484 atomic_t ll_sa_wrong; /* statahead thread stopped for
c0894c6c
OD
485 * low hit ratio
486 */
d7e09d03
PT
487 atomic_t ll_agl_total; /* AGL thread started count */
488
c0894c6c
OD
489 dev_t ll_sdev_orig; /* save s_dev before assign for
490 * clustered nfs
491 */
bd994071 492 __kernel_fsid_t ll_fsid;
fd0d04ba
OD
493 struct kobject ll_kobj; /* sysfs object */
494 struct super_block *ll_sb; /* struct super_block (for sysfs code)*/
495 struct completion ll_kobj_unregister;
d7e09d03
PT
496};
497
d7e09d03
PT
498/*
499 * per file-descriptor read-ahead data.
500 */
501struct ll_readahead_state {
502 spinlock_t ras_lock;
503 /*
504 * index of the last page that read(2) needed and that wasn't in the
505 * cache. Used by ras_update() to detect seeks.
506 *
507 * XXX nikita: if access seeks into cached region, Lustre doesn't see
508 * this.
509 */
510 unsigned long ras_last_readpage;
511 /*
512 * number of pages read after last read-ahead window reset. As window
513 * is reset on each seek, this is effectively a number of consecutive
514 * accesses. Maybe ->ras_accessed_in_window is better name.
515 *
516 * XXX nikita: window is also reset (by ras_update()) when Lustre
517 * believes that memory pressure evicts read-ahead pages. In that
518 * case, it probably doesn't make sense to expand window to
519 * PTLRPC_MAX_BRW_PAGES on the third access.
520 */
521 unsigned long ras_consecutive_pages;
522 /*
523 * number of read requests after the last read-ahead window reset
524 * As window is reset on each seek, this is effectively the number
525 * on consecutive read request and is used to trigger read-ahead.
526 */
527 unsigned long ras_consecutive_requests;
528 /*
529 * Parameters of current read-ahead window. Handled by
530 * ras_update(). On the initial access to the file or after a seek,
531 * window is reset to 0. After 3 consecutive accesses, window is
532 * expanded to PTLRPC_MAX_BRW_PAGES. Afterwards, window is enlarged by
533 * PTLRPC_MAX_BRW_PAGES chunks up to ->ra_max_pages.
534 */
535 unsigned long ras_window_start, ras_window_len;
536 /*
537 * Where next read-ahead should start at. This lies within read-ahead
538 * window. Read-ahead window is read in pieces rather than at once
539 * because: 1. lustre limits total number of pages under read-ahead by
540 * ->ra_max_pages (see ll_ra_count_get()), 2. client cannot read pages
541 * not covered by DLM lock.
542 */
543 unsigned long ras_next_readahead;
544 /*
545 * Total number of ll_file_read requests issued, reads originating
546 * due to mmap are not counted in this total. This value is used to
547 * trigger full file read-ahead after multiple reads to a small file.
548 */
549 unsigned long ras_requests;
550 /*
551 * Page index with respect to the current request, these value
552 * will not be accurate when dealing with reads issued via mmap.
553 */
554 unsigned long ras_request_index;
d7e09d03
PT
555 /*
556 * The following 3 items are used for detecting the stride I/O
557 * mode.
558 * In stride I/O mode,
559 * ...............|-----data-----|****gap*****|--------|******|....
560 * offset |-stride_pages-|-stride_gap-|
561 * ras_stride_offset = offset;
562 * ras_stride_length = stride_pages + stride_gap;
563 * ras_stride_pages = stride_pages;
564 * Note: all these three items are counted by pages.
565 */
566 unsigned long ras_stride_length;
567 unsigned long ras_stride_pages;
568 pgoff_t ras_stride_offset;
569 /*
570 * number of consecutive stride request count, and it is similar as
571 * ras_consecutive_requests, but used for stride I/O mode.
572 * Note: only more than 2 consecutive stride request are detected,
573 * stride read-ahead will be enable
574 */
575 unsigned long ras_consecutive_stride_requests;
576};
577
578extern struct kmem_cache *ll_file_data_slab;
579struct lustre_handle;
580struct ll_file_data {
581 struct ll_readahead_state fd_ras;
98eae5e7 582 struct ll_grouplock fd_grouplock;
d7e09d03
PT
583 __u64 lfd_pos;
584 __u32 fd_flags;
d3a8a4e2
JX
585 fmode_t fd_omode;
586 /* openhandle if lease exists for this file.
c0894c6c
OD
587 * Borrow lli->lli_och_mutex to protect assignment
588 */
d3a8a4e2
JX
589 struct obd_client_handle *fd_lease_och;
590 struct obd_client_handle *fd_och;
d7e09d03
PT
591 struct file *fd_file;
592 /* Indicate whether need to report failure when close.
593 * true: failure is known, not report again.
c0894c6c
OD
594 * false: unknown failure, should report.
595 */
d7e09d03 596 bool fd_write_failed;
966c4a8f
JX
597 rwlock_t fd_lock; /* protect lcc list */
598 struct list_head fd_lccs; /* list of ll_cl_context */
d7e09d03
PT
599};
600
601struct lov_stripe_md;
602
ae7c0f48 603extern struct dentry *llite_root;
fd0d04ba 604extern struct kset *llite_kset;
d7e09d03
PT
605
606static inline struct inode *ll_info2i(struct ll_inode_info *lli)
607{
608 return &lli->lli_vfs_inode;
609}
610
d7e09d03 611__u32 ll_i2suppgid(struct inode *i);
1d8cb70c 612void ll_i2gids(__u32 *suppgids, struct inode *i1, struct inode *i2);
d7e09d03
PT
613
614static inline int ll_need_32bit_api(struct ll_sb_info *sbi)
615{
616#if BITS_PER_LONG == 32
617 return 1;
2d95f10e 618#elif defined(CONFIG_COMPAT)
6d8bedff 619 return unlikely(in_compat_syscall() || (sbi->ll_flags & LL_SBI_32BIT_API));
d7e09d03 620#else
2d95f10e 621 return unlikely(sbi->ll_flags & LL_SBI_32BIT_API);
d7e09d03
PT
622#endif
623}
624
bc4320a9 625void ll_ras_enter(struct file *f);
d7e09d03 626
98eae5e7 627/* llite/lcommon_misc.c */
5c5af0fc
JH
628int cl_init_ea_size(struct obd_export *md_exp, struct obd_export *dt_exp);
629int cl_ocd_update(struct obd_device *host,
630 struct obd_device *watched,
631 enum obd_notify_event ev, void *owner, void *data);
98eae5e7
JH
632int cl_get_grouplock(struct cl_object *obj, unsigned long gid, int nonblock,
633 struct ll_grouplock *cg);
634void cl_put_grouplock(struct ll_grouplock *cg);
d7e09d03
PT
635
636/* llite/lproc_llite.c */
ae7c0f48
OD
637int ldebugfs_register_mountpoint(struct dentry *parent,
638 struct super_block *sb, char *osc, char *mdc);
639void ldebugfs_unregister_mountpoint(struct ll_sb_info *sbi);
d7e09d03
PT
640void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count);
641void lprocfs_llite_init_vars(struct lprocfs_static_vars *lvars);
2c185ffa
PT
642void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
643 struct ll_file_data *file, loff_t pos,
644 size_t count, int rw);
d7e09d03
PT
645
646/* llite/dir.c */
647void ll_release_page(struct page *page, int remove);
2d95f10e
JH
648extern const struct file_operations ll_dir_operations;
649extern const struct inode_operations ll_dir_inode_operations;
d7e09d03
PT
650struct page *ll_get_dir_page(struct inode *dir, __u64 hash,
651 struct ll_dir_chain *chain);
0b09d381 652int ll_dir_read(struct inode *inode, struct dir_context *ctx);
d7e09d03
PT
653
654int ll_get_mdt_idx(struct inode *inode);
655/* llite/namei.c */
2d95f10e
JH
656extern const struct inode_operations ll_special_inode_operations;
657
d7e09d03
PT
658int ll_objects_destroy(struct ptlrpc_request *request,
659 struct inode *dir);
660struct inode *ll_iget(struct super_block *sb, ino_t hash,
661 struct lustre_md *lic);
662int ll_md_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
663 void *data, int flag);
664struct dentry *ll_splice_alias(struct inode *inode, struct dentry *de);
d7e09d03
PT
665
666/* llite/rw.c */
d7e09d03
PT
667int ll_writepage(struct page *page, struct writeback_control *wbc);
668int ll_writepages(struct address_space *, struct writeback_control *wbc);
d7e09d03
PT
669int ll_readpage(struct file *file, struct page *page);
670void ll_readahead_init(struct inode *inode, struct ll_readahead_state *ras);
d7e09d03 671int ll_readahead(const struct lu_env *env, struct cl_io *io,
fd7444fe
JX
672 struct cl_page_list *queue, struct ll_readahead_state *ras,
673 bool hit);
966c4a8f
JX
674struct ll_cl_context *ll_cl_find(struct file *file);
675void ll_cl_add(struct file *file, const struct lu_env *env, struct cl_io *io);
676void ll_cl_remove(struct file *file, const struct lu_env *env);
d7e09d03 677
2d95f10e 678extern const struct address_space_operations ll_aops;
2d95f10e 679
d7e09d03
PT
680/* llite/file.c */
681extern struct file_operations ll_file_operations;
682extern struct file_operations ll_file_operations_flock;
683extern struct file_operations ll_file_operations_noflock;
d2d32738 684extern const struct inode_operations ll_file_inode_operations;
8150a97f 685int ll_have_md_lock(struct inode *inode, __u64 *bits,
52ee0d20
OD
686 enum ldlm_mode l_req_mode);
687enum ldlm_mode ll_take_md_lock(struct inode *inode, __u64 bits,
688 struct lustre_handle *lockh, __u64 flags,
689 enum ldlm_mode mode);
d7e09d03
PT
690int ll_file_open(struct inode *inode, struct file *file);
691int ll_file_release(struct inode *inode, struct file *file);
692int ll_glimpse_ioctl(struct ll_sb_info *sbi,
693 struct lov_stripe_md *lsm, lstat_t *st);
694void ll_ioepoch_open(struct ll_inode_info *lli, __u64 ioepoch);
e22fdcc8 695int ll_release_openhandle(struct inode *, struct lookup_intent *);
45b2a010 696int ll_md_real_close(struct inode *inode, fmode_t fmode);
d7e09d03
PT
697void ll_ioepoch_close(struct inode *inode, struct md_op_data *op_data,
698 struct obd_client_handle **och, unsigned long flags);
699void ll_done_writing_attr(struct inode *inode, struct md_op_data *op_data);
700int ll_som_update(struct inode *inode, struct md_op_data *op_data);
701int ll_inode_getattr(struct inode *inode, struct obdo *obdo,
702 __u64 ioepoch, int sync);
d7e09d03
PT
703void ll_pack_inode2opdata(struct inode *inode, struct md_op_data *op_data,
704 struct lustre_handle *fh);
d7e09d03 705int ll_getattr(struct vfsmount *mnt, struct dentry *de, struct kstat *stat);
2d95f10e 706struct posix_acl *ll_get_acl(struct inode *inode, int type);
d7e09d03
PT
707
708int ll_inode_permission(struct inode *inode, int mask);
709
c139f3ce 710int ll_lov_setstripe_ea_info(struct inode *inode, struct dentry *dentry,
d467220e 711 __u64 flags, struct lov_user_md *lum,
d7e09d03
PT
712 int lum_size);
713int ll_lov_getstripe_ea_info(struct inode *inode, const char *filename,
714 struct lov_mds_md **lmm, int *lmm_size,
715 struct ptlrpc_request **request);
716int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
717 int set_default);
718int ll_dir_getstripe(struct inode *inode, struct lov_mds_md **lmmp,
719 int *lmm_size, struct ptlrpc_request **request);
720int ll_fsync(struct file *file, loff_t start, loff_t end, int data);
d2995737 721int ll_merge_attr(const struct lu_env *env, struct inode *inode);
2b358b4e 722int ll_fid2path(struct inode *inode, void __user *arg);
e1798006 723int ll_data_version(struct inode *inode, __u64 *data_version, int flags);
48d23e61 724int ll_hsm_release(struct inode *inode);
d7e09d03
PT
725
726/* llite/dcache.c */
727
3ea8f3bc 728int ll_d_init(struct dentry *de);
2d95f10e 729extern const struct dentry_operations ll_d_ops;
d7e09d03
PT
730void ll_intent_drop_lock(struct lookup_intent *);
731void ll_intent_release(struct lookup_intent *);
732void ll_invalidate_aliases(struct inode *);
dbca51dd 733void ll_lookup_finish_locks(struct lookup_intent *it, struct inode *inode);
d7e09d03 734int ll_revalidate_it_finish(struct ptlrpc_request *request,
dbca51dd 735 struct lookup_intent *it, struct inode *inode);
d7e09d03
PT
736
737/* llite/llite_lib.c */
738extern struct super_operations lustre_super_operations;
739
d7e09d03
PT
740void ll_lli_init(struct ll_inode_info *lli);
741int ll_fill_super(struct super_block *sb, struct vfsmount *mnt);
742void ll_put_super(struct super_block *sb);
743void ll_kill_super(struct super_block *sb);
744struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock);
d7e09d03 745void ll_clear_inode(struct inode *inode);
a720b790 746int ll_setattr_raw(struct dentry *dentry, struct iattr *attr, bool hsm_import);
d7e09d03
PT
747int ll_setattr(struct dentry *de, struct iattr *attr);
748int ll_statfs(struct dentry *de, struct kstatfs *sfs);
749int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
750 __u64 max_age, __u32 flags);
751void ll_update_inode(struct inode *inode, struct lustre_md *md);
752void ll_read_inode2(struct inode *inode, void *opaque);
753void ll_delete_inode(struct inode *inode);
754int ll_iocontrol(struct inode *inode, struct file *file,
755 unsigned int cmd, unsigned long arg);
756int ll_flush_ctx(struct inode *inode);
757void ll_umount_begin(struct super_block *sb);
758int ll_remount_fs(struct super_block *sb, int *flags, char *data);
759int ll_show_options(struct seq_file *seq, struct dentry *dentry);
760void ll_dirty_page_discard_warn(struct page *page, int ioret);
761int ll_prep_inode(struct inode **inode, struct ptlrpc_request *req,
762 struct super_block *, struct lookup_intent *);
4c6243ec 763int ll_obd_statfs(struct inode *inode, void __user *arg);
d7e09d03 764int ll_get_max_mdsize(struct ll_sb_info *sbi, int *max_mdsize);
44779340 765int ll_get_default_mdsize(struct ll_sb_info *sbi, int *default_mdsize);
d7e09d03
PT
766int ll_process_config(struct lustre_cfg *lcfg);
767struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
768 struct inode *i1, struct inode *i2,
769 const char *name, int namelen,
770 int mode, __u32 opc, void *data);
771void ll_finish_md_op_data(struct md_op_data *op_data);
772int ll_get_obd_name(struct inode *inode, unsigned int cmd, unsigned long arg);
773char *ll_get_fsname(struct super_block *sb, char *buf, int buflen);
44ecac68 774void ll_open_cleanup(struct super_block *sb, struct ptlrpc_request *open_req);
d7e09d03
PT
775
776/* llite/llite_nfs.c */
98aa7661 777extern const struct export_operations lustre_export_operations;
d7e09d03 778__u32 get_uuid2int(const char *name, int len);
bd994071 779void get_uuid2fsid(const char *name, int len, __kernel_fsid_t *fsid);
d7e09d03
PT
780struct inode *search_inode_for_lustre(struct super_block *sb,
781 const struct lu_fid *fid);
782
d7e09d03 783/* llite/symlink.c */
d2d32738 784extern const struct inode_operations ll_fast_symlink_inode_operations;
d7e09d03
PT
785
786/* llite/llite_close.c */
787struct ll_close_queue {
788 spinlock_t lcq_lock;
789 struct list_head lcq_head;
790 wait_queue_head_t lcq_waitq;
791 struct completion lcq_comp;
792 atomic_t lcq_stop;
793};
794
3a52f803
JH
795void vvp_write_pending(struct vvp_object *club, struct vvp_page *page);
796void vvp_write_complete(struct vvp_object *club, struct vvp_page *page);
d7e09d03
PT
797
798/**
799 * IO arguments for various VFS I/O interfaces.
800 */
801struct vvp_io_args {
74c0da19 802 /** normal/splice */
d7e09d03
PT
803 union {
804 struct {
805 struct kiocb *via_iocb;
b42b15fd 806 struct iov_iter *via_iter;
d7e09d03 807 } normal;
d7e09d03
PT
808 } u;
809};
810
811struct ll_cl_context {
966c4a8f 812 struct list_head lcc_list;
d7e09d03 813 void *lcc_cookie;
966c4a8f 814 const struct lu_env *lcc_env;
d7e09d03
PT
815 struct cl_io *lcc_io;
816 struct cl_page *lcc_page;
d7e09d03
PT
817};
818
9989a58e
JH
819struct ll_thread_info {
820 struct vvp_io_args lti_args;
821 struct ra_io_arg lti_ria;
822 struct ll_cl_context lti_io_ctx;
d7e09d03
PT
823};
824
9989a58e
JH
825extern struct lu_context_key ll_thread_key;
826static inline struct ll_thread_info *ll_env_info(const struct lu_env *env)
d7e09d03 827{
9989a58e 828 struct ll_thread_info *lti;
d7e09d03 829
9989a58e
JH
830 lti = lu_context_key_get(&env->le_ctx, &ll_thread_key);
831 LASSERT(lti);
832 return lti;
d7e09d03
PT
833}
834
82c156f8 835static inline struct vvp_io_args *ll_env_args(const struct lu_env *env)
d7e09d03 836{
82c156f8 837 return &ll_env_info(env)->lti_args;
d7e09d03
PT
838}
839
840void ll_queue_done_writing(struct inode *inode, unsigned long flags);
841void ll_close_thread_shutdown(struct ll_close_queue *lcq);
842int ll_close_thread_start(struct ll_close_queue **lcq_ret);
843
844/* llite/llite_mmap.c */
d7e09d03
PT
845
846int ll_teardown_mmaps(struct address_space *mapping, __u64 first, __u64 last);
aff9d8e8 847int ll_file_mmap(struct file *file, struct vm_area_struct *vma);
e15ba45d
OD
848void policy_from_vma(ldlm_policy_data_t *policy, struct vm_area_struct *vma,
849 unsigned long addr, size_t count);
d7e09d03
PT
850struct vm_area_struct *our_vma(struct mm_struct *mm, unsigned long addr,
851 size_t count);
852
853static inline void ll_invalidate_page(struct page *vmpage)
854{
855 struct address_space *mapping = vmpage->mapping;
09cbfeaf 856 loff_t offset = vmpage->index << PAGE_SHIFT;
d7e09d03
PT
857
858 LASSERT(PageLocked(vmpage));
6e16818b 859 if (!mapping)
d7e09d03
PT
860 return;
861
7addf402
JX
862 /*
863 * truncate_complete_page() calls
864 * a_ops->invalidatepage()->cl_page_delete()->vvp_page_delete().
865 */
09cbfeaf 866 ll_teardown_mmaps(mapping, offset, offset + PAGE_SIZE);
d7e09d03
PT
867 truncate_complete_page(mapping, vmpage);
868}
869
870#define ll_s2sbi(sb) (s2lsi(sb)->lsi_llsbi)
871
872/* don't need an addref as the sb_info should be holding one */
873static inline struct obd_export *ll_s2dtexp(struct super_block *sb)
874{
875 return ll_s2sbi(sb)->ll_dt_exp;
876}
877
878/* don't need an addref as the sb_info should be holding one */
879static inline struct obd_export *ll_s2mdexp(struct super_block *sb)
880{
881 return ll_s2sbi(sb)->ll_md_exp;
882}
883
884static inline struct client_obd *sbi2mdc(struct ll_sb_info *sbi)
885{
886 struct obd_device *obd = sbi->ll_md_exp->exp_obd;
50ffcb7e 887
6e16818b 888 if (!obd)
d7e09d03
PT
889 LBUG();
890 return &obd->u.cli;
891}
892
995c8b4a 893/* FIXME: replace the name of this with LL_SB to conform to kernel stuff */
d7e09d03
PT
894static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
895{
896 return ll_s2sbi(inode->i_sb);
897}
898
899static inline struct obd_export *ll_i2dtexp(struct inode *inode)
900{
901 return ll_s2dtexp(inode->i_sb);
902}
903
904static inline struct obd_export *ll_i2mdexp(struct inode *inode)
905{
906 return ll_s2mdexp(inode->i_sb);
907}
908
909static inline struct lu_fid *ll_inode2fid(struct inode *inode)
910{
911 struct lu_fid *fid;
912
6e16818b 913 LASSERT(inode);
d7e09d03
PT
914 fid = &ll_i2info(inode)->lli_fid;
915
916 return fid;
917}
918
d7e09d03
PT
919static inline __u64 ll_file_maxbytes(struct inode *inode)
920{
921 return ll_i2info(inode)->lli_maxbytes;
922}
923
924/* llite/xattr.c */
3767e255
AV
925int ll_setxattr(struct dentry *dentry, struct inode *inode,
926 const char *name, const void *value, size_t size, int flags);
ce23e640
AV
927ssize_t ll_getxattr(struct dentry *dentry, struct inode *inode,
928 const char *name, void *buffer, size_t size);
d7e09d03
PT
929ssize_t ll_listxattr(struct dentry *dentry, char *buffer, size_t size);
930int ll_removexattr(struct dentry *dentry, const char *name);
931
d7e09d03
PT
932/**
933 * Common IO arguments for various VFS I/O interfaces.
934 */
935int cl_sb_init(struct super_block *sb);
936int cl_sb_fini(struct super_block *sb);
d7e09d03
PT
937void ll_io_init(struct cl_io *io, const struct file *file, int write);
938
939void ras_update(struct ll_sb_info *sbi, struct inode *inode,
940 struct ll_readahead_state *ras, unsigned long index,
941 unsigned hit);
942void ll_ra_count_put(struct ll_sb_info *sbi, unsigned long len);
fd7444fe 943void ll_ra_stats_inc(struct inode *inode, enum ra_stat which);
d7e09d03 944
d7e09d03 945/* statahead.c */
d7e09d03
PT
946#define LL_SA_RPC_MIN 2
947#define LL_SA_RPC_DEF 32
948#define LL_SA_RPC_MAX 8192
949
950#define LL_SA_CACHE_BIT 5
951#define LL_SA_CACHE_SIZE (1 << LL_SA_CACHE_BIT)
952#define LL_SA_CACHE_MASK (LL_SA_CACHE_SIZE - 1)
953
954/* per inode struct, for dir only */
955struct ll_statahead_info {
956 struct inode *sai_inode;
957 atomic_t sai_refcount; /* when access this struct, hold
c0894c6c
OD
958 * refcount
959 */
d7e09d03
PT
960 unsigned int sai_generation; /* generation for statahead */
961 unsigned int sai_max; /* max ahead of lookup */
962 __u64 sai_sent; /* stat requests sent count */
963 __u64 sai_replied; /* stat requests which received
c0894c6c
OD
964 * reply
965 */
d7e09d03
PT
966 __u64 sai_index; /* index of statahead entry */
967 __u64 sai_index_wait; /* index of entry which is the
c0894c6c
OD
968 * caller is waiting for
969 */
d7e09d03
PT
970 __u64 sai_hit; /* hit count */
971 __u64 sai_miss; /* miss count:
c0894c6c
OD
972 * for "ls -al" case, it includes
973 * hidden dentry miss;
974 * for "ls -l" case, it does not
975 * include hidden dentry miss.
976 * "sai_miss_hidden" is used for
977 * the later case.
978 */
d7e09d03
PT
979 unsigned int sai_consecutive_miss; /* consecutive miss */
980 unsigned int sai_miss_hidden;/* "ls -al", but first dentry
c0894c6c
OD
981 * is not a hidden one
982 */
d7e09d03
PT
983 unsigned int sai_skip_hidden;/* skipped hidden dentry count */
984 unsigned int sai_ls_all:1, /* "ls -al", do stat-ahead for
c0894c6c
OD
985 * hidden entries
986 */
d7e09d03 987 sai_agl_valid:1;/* AGL is valid for the dir */
c0894c6c 988 wait_queue_head_t sai_waitq; /* stat-ahead wait queue */
d7e09d03
PT
989 struct ptlrpc_thread sai_thread; /* stat-ahead thread */
990 struct ptlrpc_thread sai_agl_thread; /* AGL thread */
c0894c6c
OD
991 struct list_head sai_entries; /* entry list */
992 struct list_head sai_entries_received; /* entries returned */
993 struct list_head sai_entries_stated; /* entries stated */
994 struct list_head sai_entries_agl; /* AGL entries to be sent */
995 struct list_head sai_cache[LL_SA_CACHE_SIZE];
d7e09d03
PT
996 spinlock_t sai_cache_lock[LL_SA_CACHE_SIZE];
997 atomic_t sai_cache_count; /* entry count in cache */
998};
999
1000int do_statahead_enter(struct inode *dir, struct dentry **dentry,
1001 int only_unplug);
1002void ll_stop_statahead(struct inode *dir, void *key);
1003
5c5af0fc
JH
1004blkcnt_t dirty_cnt(struct inode *inode);
1005
1006int cl_glimpse_size0(struct inode *inode, int agl);
1007int cl_glimpse_lock(const struct lu_env *env, struct cl_io *io,
1008 struct inode *inode, struct cl_object *clob, int agl);
1009
1010static inline int cl_glimpse_size(struct inode *inode)
1011{
1012 return cl_glimpse_size0(inode, 0);
1013}
1014
1015static inline int cl_agl(struct inode *inode)
1016{
1017 return cl_glimpse_size0(inode, 1);
1018}
1019
d7e09d03
PT
1020static inline int ll_glimpse_size(struct inode *inode)
1021{
1022 struct ll_inode_info *lli = ll_i2info(inode);
1023 int rc;
1024
1025 down_read(&lli->lli_glimpse_sem);
1026 rc = cl_glimpse_size(inode);
1027 lli->lli_glimpse_time = cfs_time_current();
1028 up_read(&lli->lli_glimpse_sem);
1029 return rc;
1030}
1031
1032static inline void
1033ll_statahead_mark(struct inode *dir, struct dentry *dentry)
1034{
1035 struct ll_inode_info *lli = ll_i2info(dir);
1036 struct ll_statahead_info *sai = lli->lli_sai;
1037 struct ll_dentry_data *ldd = ll_d2d(dentry);
1038
1039 /* not the same process, don't mark */
1040 if (lli->lli_opendir_pid != current_pid())
1041 return;
1042
6e16818b
OD
1043 LASSERT(ldd);
1044 if (sai)
d7e09d03
PT
1045 ldd->lld_sa_generation = sai->sai_generation;
1046}
1047
1048static inline int
f236f69b 1049d_need_statahead(struct inode *dir, struct dentry *dentryp)
d7e09d03
PT
1050{
1051 struct ll_inode_info *lli;
1052 struct ll_dentry_data *ldd;
1053
1054 if (ll_i2sbi(dir)->ll_sa_max == 0)
1055 return -EAGAIN;
1056
1057 lli = ll_i2info(dir);
1058 /* not the same process, don't statahead */
1059 if (lli->lli_opendir_pid != current_pid())
1060 return -EAGAIN;
1061
1062 /* statahead has been stopped */
6e16818b 1063 if (!lli->lli_opendir_key)
d7e09d03
PT
1064 return -EAGAIN;
1065
1066 ldd = ll_d2d(dentryp);
1067 /*
1068 * When stats a dentry, the system trigger more than once "revalidate"
1069 * or "lookup", for "getattr", for "getxattr", and maybe for others.
1070 * Under patchless client mode, the operation intent is not accurate,
1071 * which maybe misguide the statahead thread. For example:
1072 * The "revalidate" call for "getattr" and "getxattr" of a dentry maybe
1073 * have the same operation intent -- "IT_GETATTR".
1074 * In fact, one dentry should has only one chance to interact with the
1075 * statahead thread, otherwise the statahead windows will be confused.
1076 * The solution is as following:
1077 * Assign "lld_sa_generation" with "sai_generation" when a dentry
1078 * "IT_GETATTR" for the first time, and the subsequent "IT_GETATTR"
1079 * will bypass interacting with statahead thread for checking:
1080 * "lld_sa_generation == lli_sai->sai_generation"
1081 */
1082 if (ldd && lli->lli_sai &&
1083 ldd->lld_sa_generation == lli->lli_sai->sai_generation)
1084 return -EAGAIN;
1085
1086 return 1;
1087}
1088
1089static inline int
1090ll_statahead_enter(struct inode *dir, struct dentry **dentryp, int only_unplug)
1091{
1092 int ret;
1093
f236f69b 1094 ret = d_need_statahead(dir, *dentryp);
d7e09d03
PT
1095 if (ret <= 0)
1096 return ret;
1097
1098 return do_statahead_enter(dir, dentryp, only_unplug);
1099}
1100
d0a0acc3 1101/* llite ioctl register support routine */
d7e09d03
PT
1102enum llioc_iter {
1103 LLIOC_CONT = 0,
1104 LLIOC_STOP
1105};
1106
1107#define LLIOC_MAX_CMD 256
1108
1109/*
1110 * Rules to write a callback function:
1111 *
1112 * Parameters:
d0a0acc3 1113 * @magic: Dynamic ioctl call routine will feed this value with the pointer
d7e09d03
PT
1114 * returned to ll_iocontrol_register. Callback functions should use this
1115 * data to check the potential collasion of ioctl cmd. If collasion is
1116 * found, callback function should return LLIOC_CONT.
1117 * @rcp: The result of ioctl command.
1118 *
1119 * Return values:
1120 * If @magic matches the pointer returned by ll_iocontrol_data, the
1121 * callback should return LLIOC_STOP; return LLIOC_STOP otherwise.
1122 */
1123typedef enum llioc_iter (*llioc_callback_t)(struct inode *inode,
1124 struct file *file, unsigned int cmd, unsigned long arg,
1125 void *magic, int *rcp);
1126
d7e09d03
PT
1127/* export functions */
1128/* Register ioctl block dynamatically for a regular file.
1129 *
1130 * @cmd: the array of ioctl command set
1131 * @count: number of commands in the @cmd
1132 * @cb: callback function, it will be called if an ioctl command is found to
1133 * belong to the command list @cmd.
1134 *
d0a0acc3 1135 * Return value:
d7e09d03
PT
1136 * A magic pointer will be returned if success;
1137 * otherwise, NULL will be returned.
1138 * */
1139void *ll_iocontrol_register(llioc_callback_t cb, int count, unsigned int *cmd);
1140void ll_iocontrol_unregister(void *magic);
1141
d7e09d03 1142int cl_sync_file_range(struct inode *inode, loff_t start, loff_t end,
65fb55d1 1143 enum cl_fsync_mode mode, int ignore_layout);
d7e09d03
PT
1144
1145/** direct write pages */
1146struct ll_dio_pages {
1147 /** page array to be written. we don't support
c0894c6c
OD
1148 * partial pages except the last one.
1149 */
d7e09d03
PT
1150 struct page **ldp_pages;
1151 /* offset of each page */
1152 loff_t *ldp_offsets;
1153 /** if ldp_offsets is NULL, it means a sequential
1154 * pages to be written, then this is the file offset
c0894c6c
OD
1155 * of the first page.
1156 */
d7e09d03
PT
1157 loff_t ldp_start_offset;
1158 /** how many bytes are to be written. */
1159 size_t ldp_size;
1160 /** # of pages in the array. */
1161 int ldp_nr;
1162};
1163
1164static inline void cl_stats_tally(struct cl_device *dev, enum cl_req_type crt,
1165 int rc)
1166{
1167 int opc = (crt == CRT_READ) ? LPROC_LL_OSC_READ :
1168 LPROC_LL_OSC_WRITE;
1169
3c95b839 1170 ll_stats_ops_tally(ll_s2sbi(cl2vvp_dev(dev)->vdv_sb), opc, rc);
d7e09d03
PT
1171}
1172
8150a97f
JP
1173ssize_t ll_direct_rw_pages(const struct lu_env *env, struct cl_io *io,
1174 int rw, struct inode *inode,
1175 struct ll_dio_pages *pv);
d7e09d03
PT
1176
1177static inline int ll_file_nolock(const struct file *file)
1178{
1179 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
2a8a3597 1180 struct inode *inode = file_inode(file);
d7e09d03 1181
d7e09d03
PT
1182 return ((fd->fd_flags & LL_FILE_IGNORE_LOCK) ||
1183 (ll_i2sbi(inode)->ll_flags & LL_SBI_NOLCK));
1184}
1185
1186static inline void ll_set_lock_data(struct obd_export *exp, struct inode *inode,
1187 struct lookup_intent *it, __u64 *bits)
1188{
e476f2e5 1189 if (!it->it_lock_set) {
d7e09d03
PT
1190 struct lustre_handle handle;
1191
1192 /* If this inode is a remote object, it will get two
1193 * separate locks in different namespaces, Master MDT,
1194 * where the name entry is, will grant LOOKUP lock,
1195 * remote MDT, where the object is, will grant
d0a0acc3 1196 * UPDATE|PERM lock. The inode will be attached to both
d7e09d03 1197 * LOOKUP and PERM locks, so revoking either locks will
c0894c6c
OD
1198 * case the dcache being cleared
1199 */
e476f2e5
JH
1200 if (it->it_remote_lock_mode) {
1201 handle.cookie = it->it_remote_lock_handle;
97a075cd
JN
1202 CDEBUG(D_DLMTRACE, "setting l_data to inode "DFID"%p for remote lock %#llx\n",
1203 PFID(ll_inode2fid(inode)), inode,
d7e09d03
PT
1204 handle.cookie);
1205 md_set_lock_data(exp, &handle.cookie, inode, NULL);
1206 }
1207
e476f2e5 1208 handle.cookie = it->it_lock_handle;
d7e09d03 1209
97a075cd
JN
1210 CDEBUG(D_DLMTRACE, "setting l_data to inode "DFID"%p for lock %#llx\n",
1211 PFID(ll_inode2fid(inode)), inode, handle.cookie);
d7e09d03
PT
1212
1213 md_set_lock_data(exp, &handle.cookie, inode,
e476f2e5
JH
1214 &it->it_lock_bits);
1215 it->it_lock_set = 1;
d7e09d03
PT
1216 }
1217
6e16818b 1218 if (bits)
e476f2e5 1219 *bits = it->it_lock_bits;
d7e09d03
PT
1220}
1221
d7e09d03
PT
1222static inline int d_lustre_invalid(const struct dentry *dentry)
1223{
1224 struct ll_dentry_data *lld = ll_d2d(dentry);
1225
6e16818b 1226 return !lld || lld->lld_invalid;
d7e09d03
PT
1227}
1228
1229static inline void __d_lustre_invalidate(struct dentry *dentry)
1230{
1231 struct ll_dentry_data *lld = ll_d2d(dentry);
1232
6e16818b 1233 if (lld)
d7e09d03
PT
1234 lld->lld_invalid = 1;
1235}
1236
1237/*
1238 * Mark dentry INVALID, if dentry refcount is zero (this is normally case for
1239 * ll_md_blocking_ast), unhash this dentry, and let dcache to reclaim it later;
1240 * else dput() of the last refcount will unhash this dentry and kill it.
1241 */
b1d2a127 1242static inline void d_lustre_invalidate(struct dentry *dentry, int nested)
d7e09d03 1243{
dab363f9
LT
1244 CDEBUG(D_DENTRY, "invalidate dentry %pd (%p) parent %p inode %p refc %d\n",
1245 dentry, dentry,
2b0143b5 1246 dentry->d_parent, d_inode(dentry), d_count(dentry));
d7e09d03 1247
b1d2a127
PT
1248 spin_lock_nested(&dentry->d_lock,
1249 nested ? DENTRY_D_LOCK_NESTED : DENTRY_D_LOCK_NORMAL);
d7e09d03 1250 __d_lustre_invalidate(dentry);
7f830d8d
AP
1251 /*
1252 * We should be careful about dentries created by d_obtain_alias().
1253 * These dentries are not put in the dentry tree, instead they are
1254 * linked to sb->s_anon through dentry->d_hash.
1255 * shrink_dcache_for_umount() shrinks the tree and sb->s_anon list.
1256 * If we unhashed such a dentry, unmount would not be able to find
1257 * it and busy inodes would be reported.
1258 */
1259 if (d_count(dentry) == 0 && !(dentry->d_flags & DCACHE_DISCONNECTED))
d7e09d03
PT
1260 __d_drop(dentry);
1261 spin_unlock(&dentry->d_lock);
1262}
1263
1264static inline void d_lustre_revalidate(struct dentry *dentry)
1265{
1266 spin_lock(&dentry->d_lock);
6e16818b 1267 LASSERT(ll_d2d(dentry));
d7e09d03
PT
1268 ll_d2d(dentry)->lld_invalid = 0;
1269 spin_unlock(&dentry->d_lock);
1270}
1271
d7e09d03
PT
1272enum {
1273 LL_LAYOUT_GEN_NONE = ((__u32)-2), /* layout lock was cancelled */
1274 LL_LAYOUT_GEN_EMPTY = ((__u32)-1) /* for empty layout */
1275};
1276
1277int ll_layout_conf(struct inode *inode, const struct cl_object_conf *conf);
1278int ll_layout_refresh(struct inode *inode, __u32 *gen);
1b1594da 1279int ll_layout_restore(struct inode *inode, loff_t start, __u64 length);
d7e09d03 1280
7fc1f831
AP
1281int ll_xattr_init(void);
1282void ll_xattr_fini(void);
1283
77605e41
JX
1284int ll_page_sync_io(const struct lu_env *env, struct cl_io *io,
1285 struct cl_page *page, enum cl_req_type crt);
1286
a37bec74 1287/* lcommon_cl.c */
5c5af0fc
JH
1288int cl_setattr_ost(struct inode *inode, const struct iattr *attr);
1289
a37bec74
JH
1290extern struct lu_env *cl_inode_fini_env;
1291extern int cl_inode_fini_refcheck;
1292
5c5af0fc
JH
1293int cl_file_inode_init(struct inode *inode, struct lustre_md *md);
1294void cl_inode_fini(struct inode *inode);
1295int cl_local_size(struct inode *inode);
1296
1297__u64 cl_fid_build_ino(const struct lu_fid *fid, int api32);
1298__u32 cl_fid_build_gen(const struct lu_fid *fid);
1299
d7e09d03 1300#endif /* LLITE_INTERNAL_H */