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