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