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