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