4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
27 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2015, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #ifndef LLITE_INTERNAL_H
38 #define LLITE_INTERNAL_H
39 #include <lustre_debug.h>
40 #include <lustre_ver.h>
41 #include <lustre_disk.h> /* for s2sbi */
42 #include <lustre_eacl.h>
43 #include <lustre_linkea.h>
45 /* for struct cl_lock_descr and struct cl_io */
46 #include <cl_object.h>
47 #include <lustre_lmv.h>
48 #include <lustre_mdc.h>
49 #include <lustre_intent.h>
50 #include <linux/compat.h>
51 #include <linux/aio.h>
53 #include "vvp_internal.h"
54 #include "range_lock.h"
60 #ifndef VM_FAULT_RETRY
61 #define VM_FAULT_RETRY 0
64 /* Kernel 3.1 kills LOOKUP_CONTINUE, LOOKUP_PARENT is equivalent to it.
65 * seem kernel commit 49084c3bb2055c401f3493c13edae14d49128ca0 */
66 #ifndef LOOKUP_CONTINUE
67 #define LOOKUP_CONTINUE LOOKUP_PARENT
70 /** Only used on client-side for indicating the tail of dir hash/offset. */
71 #define LL_DIR_END_OFF 0x7fffffffffffffffULL
72 #define LL_DIR_END_OFF_32BIT 0x7fffffffUL
74 /* 4UL * 1024 * 1024 */
75 #define LL_MAX_BLKSIZE_BITS 22
77 #define LL_IT2STR(it) ((it) ? ldlm_it2str((it)->it_op) : "0")
78 #define LUSTRE_FPRIVATE(file) ((file)->private_data)
80 struct ll_dentry_data {
81 struct lookup_intent *lld_it;
82 unsigned int lld_sa_generation;
83 unsigned int lld_invalid:1;
84 unsigned int lld_nfs_dentry:1;
85 struct rcu_head lld_rcu_head;
88 #define ll_d2d(de) ((struct ll_dentry_data*)((de)->d_fsdata))
90 #define LLI_INODE_MAGIC 0x111d0de5
91 #define LLI_INODE_DEAD 0xdeadd00d
93 /* remote client permission cache */
94 #define REMOTE_PERM_HASHSIZE 16
96 struct ll_getname_data {
97 #ifdef HAVE_DIR_CONTEXT
98 struct dir_context ctx;
100 char *lgd_name; /* points to a buffer with NAME_MAX+1 size */
101 struct lu_fid lgd_fid; /* target fid we are looking for */
102 int lgd_found; /* inode matched? */
105 /* llite setxid/access permission for user on remote client */
106 struct ll_remote_perm {
107 struct hlist_node lrp_list;
112 int lrp_access_perm; /* MAY_READ/WRITE/EXEC, this
113 is access permission with
114 lrp_fsuid/lrp_fsgid. */
117 struct ll_grouplock {
118 struct lu_env *lg_env;
120 struct cl_lock *lg_lock;
121 unsigned long lg_gid;
124 struct ll_inode_info {
125 __u32 lli_inode_magic;
128 volatile unsigned long lli_flags;
129 struct posix_acl *lli_posix_acl;
131 struct hlist_head *lli_remote_perms;
132 struct mutex lli_rmtperm_mutex;
134 /* identifying fields for both metadata and data stacks. */
135 struct lu_fid lli_fid;
136 /* master inode fid for stripe directory */
137 struct lu_fid lli_pfid;
139 /* open count currently used by capability only, indicate whether
140 * capability needs renewal */
141 atomic_t lli_open_count;
142 cfs_time_t lli_rmtperm_time;
144 /* We need all three because every inode may be opened in different
146 struct obd_client_handle *lli_mds_read_och;
147 struct obd_client_handle *lli_mds_write_och;
148 struct obd_client_handle *lli_mds_exec_och;
149 __u64 lli_open_fd_read_count;
150 __u64 lli_open_fd_write_count;
151 __u64 lli_open_fd_exec_count;
152 /* Protects access to och pointers and their usage counters */
153 struct mutex lli_och_mutex;
155 struct inode lli_vfs_inode;
157 /* the most recent timestamps obtained from mds */
161 spinlock_t lli_agl_lock;
163 /* Try to make the d::member and f::member are aligned. Before using
164 * these members, make clear whether it is directory or not. */
168 /* serialize normal readdir and statahead-readdir. */
169 struct mutex lli_readdir_mutex;
171 /* metadata statahead */
172 /* since parent-child threads can share the same @file
173 * struct, "opendir_key" is the token when dir close for
174 * case of parent exit before child -- it is me should
175 * cleanup the dir readahead. */
176 void *lli_opendir_key;
177 struct ll_statahead_info *lli_sai;
178 /* protect statahead stuff. */
179 spinlock_t lli_sa_lock;
180 /* "opendir_pid" is the token when lookup/revalid
181 * -- I am the owner of dir statahead. */
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
188 unsigned int lli_sa_enabled:1;
189 /* generation for statahead */
190 unsigned int lli_sa_generation;
191 /* directory stripe information */
192 struct lmv_stripe_md *lli_lsm_md;
193 /* default directory stripe offset. This is extracted
194 * from the "dmv" xattr in order to decide which MDT to
195 * create a subdirectory on. The MDS itself fetches
196 * "dmv" and gets the rest of the default layout itself
197 * (count, hash, etc). */
198 __u32 lli_def_stripe_offset;
201 /* for non-directory */
203 struct mutex lli_size_mutex;
204 char *lli_symlink_name;
206 * struct rw_semaphore {
207 * signed long count; // align d.d_def_acl
208 * spinlock_t wait_lock; // align d.d_sa_lock
209 * struct list_head wait_list;
212 struct rw_semaphore lli_trunc_sem;
213 struct range_lock_tree lli_write_tree;
215 struct rw_semaphore lli_glimpse_sem;
216 cfs_time_t lli_glimpse_time;
217 struct list_head lli_agl_list;
220 /* for writepage() only to communicate to fsync */
224 * whenever a process try to read/write the file, the
225 * jobid of the process will be saved here, and it'll
226 * be packed into the write PRC when flush later.
228 * so the read/write statistics for jobid will not be
229 * accurate if the file is shared by different jobs.
231 char lli_jobid[LUSTRE_JOBID_SIZE];
235 /* XXX: For following frequent used members, although they maybe special
236 * used for non-directory object, it is some time-wasting to check
237 * whether the object is directory or not before using them. On the
238 * other hand, currently, sizeof(f) > sizeof(d), it cannot reduce
239 * the "ll_inode_info" size even if moving those members into u.f.
240 * So keep them out side.
242 * In the future, if more members are added only for directory,
243 * some of the following members can be moved into u.f.
245 struct cl_object *lli_clob;
247 /* mutex to request for layout lock exclusively. */
248 struct mutex lli_layout_mutex;
249 /* Layout version, protected by lli_layout_lock */
250 __u32 lli_layout_gen;
251 spinlock_t lli_layout_lock;
253 struct rw_semaphore lli_xattrs_list_rwsem;
254 struct mutex lli_xattrs_enq_lock;
255 struct list_head lli_xattrs; /* ll_xattr_entry->xe_list */
258 static inline __u32 ll_layout_version_get(struct ll_inode_info *lli)
262 spin_lock(&lli->lli_layout_lock);
263 gen = lli->lli_layout_gen;
264 spin_unlock(&lli->lli_layout_lock);
269 static inline void ll_layout_version_set(struct ll_inode_info *lli, __u32 gen)
271 spin_lock(&lli->lli_layout_lock);
272 lli->lli_layout_gen = gen;
273 spin_unlock(&lli->lli_layout_lock);
277 /* File data is modified. */
278 LLIF_DATA_MODIFIED = 0,
279 /* File is being restored */
280 LLIF_FILE_RESTORING = 1,
281 /* Xattr cache is attached to the file */
282 LLIF_XATTR_CACHE = 2,
285 static inline void ll_file_set_flag(struct ll_inode_info *lli,
286 enum ll_file_flags flag)
288 set_bit(flag, &lli->lli_flags);
291 static inline void ll_file_clear_flag(struct ll_inode_info *lli,
292 enum ll_file_flags flag)
294 clear_bit(flag, &lli->lli_flags);
297 static inline bool ll_file_test_flag(struct ll_inode_info *lli,
298 enum ll_file_flags flag)
300 return test_bit(flag, &lli->lli_flags);
303 static inline bool ll_file_test_and_clear_flag(struct ll_inode_info *lli,
304 enum ll_file_flags flag)
306 return test_and_clear_bit(flag, &lli->lli_flags);
309 int ll_xattr_cache_destroy(struct inode *inode);
311 int ll_xattr_cache_get(struct inode *inode,
317 int ll_init_security(struct dentry *dentry,
322 * Locking to guarantee consistency of non-atomic updates to long long i_size,
323 * consistency between file size and KMS.
325 * Implemented by ->lli_size_mutex and ->lsm_lock, nested in that order.
328 void ll_inode_size_lock(struct inode *inode);
329 void ll_inode_size_unlock(struct inode *inode);
331 // FIXME: replace the name of this with LL_I to conform to kernel stuff
332 // static inline struct ll_inode_info *LL_I(struct inode *inode)
333 static inline struct ll_inode_info *ll_i2info(struct inode *inode)
335 return container_of(inode, struct ll_inode_info, lli_vfs_inode);
338 /* default to about 64M of readahead on a given system. */
339 #define SBI_DEFAULT_READAHEAD_MAX (64UL << (20 - PAGE_CACHE_SHIFT))
341 /* default to read-ahead full files smaller than 2MB on the second read */
342 #define SBI_DEFAULT_READAHEAD_WHOLE_MAX (2UL << (20 - PAGE_CACHE_SHIFT))
347 RA_STAT_DISTANT_READPAGE,
348 RA_STAT_MISS_IN_WINDOW,
349 RA_STAT_FAILED_GRAB_PAGE,
350 RA_STAT_FAILED_MATCH,
355 RA_STAT_MAX_IN_FLIGHT,
356 RA_STAT_WRONG_GRAB_PAGE,
357 RA_STAT_FAILED_REACH_END,
362 atomic_t ra_cur_pages;
363 unsigned long ra_max_pages;
364 unsigned long ra_max_pages_per_file;
365 unsigned long ra_max_read_ahead_whole_pages;
368 /* ra_io_arg will be filled in the beginning of ll_readahead with
369 * ras_lock, then the following ll_read_ahead_pages will read RA
370 * pages according to this arg, all the items in this structure are
371 * counted by page index.
374 unsigned long ria_start; /* start offset of read-ahead*/
375 unsigned long ria_end; /* end offset of read-ahead*/
376 unsigned long ria_reserved; /* reserved pages for read-ahead */
377 unsigned long ria_end_min; /* minimum end to cover current read */
378 bool ria_eof; /* reach end of file */
379 /* If stride read pattern is detected, ria_stoff means where
380 * stride read is started. Note: for normal read-ahead, the
381 * value here is meaningless, and also it will not be accessed*/
383 /* ria_length and ria_pages are the length and pages length in the
384 * stride I/O mode. And they will also be used to check whether
385 * it is stride I/O read-ahead in the read-ahead pages*/
386 unsigned long ria_length;
387 unsigned long ria_pages;
390 /* LL_HIST_MAX=32 causes an overflow */
391 #define LL_HIST_MAX 28
392 #define LL_HIST_START 12 /* buckets start at 2^12 = 4k */
393 #define LL_PROCESS_HIST_MAX 10
394 struct per_process_info {
396 struct obd_histogram pp_r_hist;
397 struct obd_histogram pp_w_hist;
400 /* pp_extents[LL_PROCESS_HIST_MAX] will hold the combined process info */
401 struct ll_rw_extents_info {
402 struct per_process_info pp_extents[LL_PROCESS_HIST_MAX + 1];
405 #define LL_OFFSET_HIST_MAX 100
406 struct ll_rw_process_info {
409 loff_t rw_range_start;
411 loff_t rw_last_file_pos;
413 size_t rw_smallest_extent;
414 size_t rw_largest_extent;
415 struct ll_file_data *rw_last_file;
418 enum stats_track_type {
419 STATS_TRACK_ALL = 0, /* track all processes */
420 STATS_TRACK_PID, /* track process with this pid */
421 STATS_TRACK_PPID, /* track processes with this ppid */
422 STATS_TRACK_GID, /* track processes with this gid */
426 /* flags for sbi->ll_flags */
427 #define LL_SBI_NOLCK 0x01 /* DLM locking disabled (directio-only) */
428 #define LL_SBI_CHECKSUM 0x02 /* checksum each page as it's written */
429 #define LL_SBI_FLOCK 0x04
430 #define LL_SBI_USER_XATTR 0x08 /* support user xattr */
431 #define LL_SBI_ACL 0x10 /* support ACL */
432 #define LL_SBI_RMT_CLIENT 0x40 /* remote client */
433 #define LL_SBI_MDS_CAPA 0x80 /* support mds capa, obsolete */
434 #define LL_SBI_OSS_CAPA 0x100 /* support oss capa, obsolete */
435 #define LL_SBI_LOCALFLOCK 0x200 /* Local flocks support by kernel */
436 #define LL_SBI_LRU_RESIZE 0x400 /* lru resize support */
437 #define LL_SBI_LAZYSTATFS 0x800 /* lazystatfs mount option */
438 /* LL_SBI_SOM_PREVIEW 0x1000 SOM preview mount option, obsolete */
439 #define LL_SBI_32BIT_API 0x2000 /* generate 32 bit inodes. */
440 #define LL_SBI_64BIT_HASH 0x4000 /* support 64-bits dir hash/offset */
441 #define LL_SBI_AGL_ENABLED 0x8000 /* enable agl */
442 #define LL_SBI_VERBOSE 0x10000 /* verbose mount/umount */
443 #define LL_SBI_LAYOUT_LOCK 0x20000 /* layout lock support */
444 #define LL_SBI_USER_FID2PATH 0x40000 /* allow fid2path by unprivileged users */
445 #define LL_SBI_XATTR_CACHE 0x80000 /* support for xattr cache */
446 #define LL_SBI_NOROOTSQUASH 0x100000 /* do not apply root squash */
447 #define LL_SBI_ALWAYS_PING 0x200000 /* always ping even if server
449 #define LL_SBI_FAST_READ 0x400000 /* fast read support */
451 #define LL_SBI_FLAGS { \
477 #define RCE_HASHES 32
479 struct rmtacl_ctl_entry {
480 struct list_head rce_list;
481 pid_t rce_key; /* hash key */
482 int rce_ops; /* acl operation type */
485 struct rmtacl_ctl_table {
487 struct list_head rct_entries[RCE_HASHES];
493 struct list_head ee_list;
494 pid_t ee_key; /* hash key */
495 struct lu_fid ee_fid;
496 int ee_type; /* ACL type for ACCESS or DEFAULT */
497 ext_acl_xattr_header *ee_acl;
502 struct list_head et_entries[EE_HASHES];
506 /* This is embedded into llite super-blocks to keep track of connect
507 * flags (capabilities) supported by all imports given mount is
509 struct lustre_client_ocd {
510 /* This is conjunction of connect_flags across all imports
511 * (LOVs) this mount is connected to. This field is updated by
512 * cl_ocd_update() under ->lco_lock. */
514 struct mutex lco_lock;
515 struct obd_export *lco_md_exp;
516 struct obd_export *lco_dt_exp;
520 /* this protects pglist and ra_info. It isn't safe to
521 * grab from interrupt contexts */
523 spinlock_t ll_pp_extent_lock; /* pp_extent entry*/
524 spinlock_t ll_process_lock; /* ll_rw_process_info */
525 struct obd_uuid ll_sb_uuid;
526 struct obd_export *ll_md_exp;
527 struct obd_export *ll_dt_exp;
528 struct proc_dir_entry* ll_proc_root;
529 struct lu_fid ll_root_fid; /* root object fid */
532 unsigned int ll_umounting:1,
533 ll_xattr_cache_enabled:1,
534 ll_client_common_fill_super_succeeded:1;
536 struct lustre_client_ocd ll_lco;
538 struct lprocfs_stats *ll_stats; /* lprocfs stats counter */
540 /* Used to track "unstable" pages on a client, and maintain a
541 * LRU list of clean pages. An "unstable" page is defined as
542 * any page which is sent to a server as part of a bulk request,
543 * but is uncommitted to stable storage. */
544 struct cl_client_cache *ll_cache;
546 struct lprocfs_stats *ll_ra_stats;
548 struct ll_ra_info ll_ra_info;
549 unsigned int ll_namelen;
550 struct file_operations *ll_fop;
552 unsigned int ll_md_brw_pages; /* readdir pages per RPC */
554 struct lu_site *ll_site;
555 struct cl_device *ll_cl;
557 struct ll_rw_extents_info ll_rw_extents_info;
558 int ll_extent_process_count;
559 struct ll_rw_process_info ll_rw_process_info[LL_PROCESS_HIST_MAX];
560 unsigned int ll_offset_process_count;
561 struct ll_rw_process_info ll_rw_offset_info[LL_OFFSET_HIST_MAX];
562 unsigned int ll_rw_offset_entry_count;
563 int ll_stats_track_id;
564 enum stats_track_type ll_stats_track_type;
567 /* metadata stat-ahead */
568 unsigned int ll_sa_max; /* max statahead RPCs */
569 atomic_t ll_sa_total; /* statahead thread started
571 atomic_t ll_sa_wrong; /* statahead thread stopped for
573 atomic_t ll_sa_running; /* running statahead thread
575 atomic_t ll_agl_total; /* AGL thread started count */
577 dev_t ll_sdev_orig; /* save s_dev before assign for
579 struct rmtacl_ctl_table ll_rct;
580 struct eacl_table ll_et;
583 struct root_squash_info ll_squash;
587 * per file-descriptor read-ahead data.
589 struct ll_readahead_state {
592 * index of the last page that read(2) needed and that wasn't in the
593 * cache. Used by ras_update() to detect seeks.
595 * XXX nikita: if access seeks into cached region, Lustre doesn't see
598 unsigned long ras_last_readpage;
600 * number of pages read after last read-ahead window reset. As window
601 * is reset on each seek, this is effectively a number of consecutive
602 * accesses. Maybe ->ras_accessed_in_window is better name.
604 * XXX nikita: window is also reset (by ras_update()) when Lustre
605 * believes that memory pressure evicts read-ahead pages. In that
606 * case, it probably doesn't make sense to expand window to
607 * PTLRPC_MAX_BRW_PAGES on the third access.
609 unsigned long ras_consecutive_pages;
611 * number of read requests after the last read-ahead window reset
612 * As window is reset on each seek, this is effectively the number
613 * on consecutive read request and is used to trigger read-ahead.
615 unsigned long ras_consecutive_requests;
617 * Parameters of current read-ahead window. Handled by
618 * ras_update(). On the initial access to the file or after a seek,
619 * window is reset to 0. After 3 consecutive accesses, window is
620 * expanded to PTLRPC_MAX_BRW_PAGES. Afterwards, window is enlarged by
621 * PTLRPC_MAX_BRW_PAGES chunks up to ->ra_max_pages.
623 unsigned long ras_window_start, ras_window_len;
625 * Optimal RPC size. It decides how many pages will be sent
626 * for each read-ahead.
628 unsigned long ras_rpc_size;
630 * Where next read-ahead should start at. This lies within read-ahead
631 * window. Read-ahead window is read in pieces rather than at once
632 * because: 1. lustre limits total number of pages under read-ahead by
633 * ->ra_max_pages (see ll_ra_count_get()), 2. client cannot read pages
634 * not covered by DLM lock.
636 unsigned long ras_next_readahead;
638 * Total number of ll_file_read requests issued, reads originating
639 * due to mmap are not counted in this total. This value is used to
640 * trigger full file read-ahead after multiple reads to a small file.
642 unsigned long ras_requests;
644 * Page index with respect to the current request, these value
645 * will not be accurate when dealing with reads issued via mmap.
647 unsigned long ras_request_index;
649 * The following 3 items are used for detecting the stride I/O
651 * In stride I/O mode,
652 * ...............|-----data-----|****gap*****|--------|******|....
653 * offset |-stride_pages-|-stride_gap-|
654 * ras_stride_offset = offset;
655 * ras_stride_length = stride_pages + stride_gap;
656 * ras_stride_pages = stride_pages;
657 * Note: all these three items are counted by pages.
659 unsigned long ras_stride_length;
660 unsigned long ras_stride_pages;
661 pgoff_t ras_stride_offset;
663 * number of consecutive stride request count, and it is similar as
664 * ras_consecutive_requests, but used for stride I/O mode.
665 * Note: only more than 2 consecutive stride request are detected,
666 * stride read-ahead will be enable
668 unsigned long ras_consecutive_stride_requests;
671 extern struct kmem_cache *ll_file_data_slab;
672 struct lustre_handle;
673 struct ll_file_data {
674 struct ll_readahead_state fd_ras;
675 struct ll_grouplock fd_grouplock;
679 /* openhandle if lease exists for this file.
680 * Borrow lli->lli_och_mutex to protect assignment */
681 struct obd_client_handle *fd_lease_och;
682 struct obd_client_handle *fd_och;
683 struct file *fd_file;
684 /* Indicate whether need to report failure when close.
685 * true: failure is known, not report again.
686 * false: unknown failure, should report. */
687 bool fd_write_failed;
688 rwlock_t fd_lock; /* protect lcc list */
689 struct list_head fd_lccs; /* list of ll_cl_context */
692 extern spinlock_t inode_lock;
694 extern struct proc_dir_entry *proc_lustre_fs_root;
696 static inline struct inode *ll_info2i(struct ll_inode_info *lli)
698 return &lli->lli_vfs_inode;
701 __u32 ll_i2suppgid(struct inode *i);
702 void ll_i2gids(__u32 *suppgids, struct inode *i1,struct inode *i2);
704 static inline int ll_need_32bit_api(struct ll_sb_info *sbi)
706 #if BITS_PER_LONG == 32
708 #elif defined(CONFIG_COMPAT)
709 return unlikely(is_compat_task() || (sbi->ll_flags & LL_SBI_32BIT_API));
711 return unlikely(sbi->ll_flags & LL_SBI_32BIT_API);
715 static inline bool ll_sbi_has_fast_read(struct ll_sb_info *sbi)
717 return !!(sbi->ll_flags & LL_SBI_FAST_READ);
720 void ll_ras_enter(struct file *f);
722 /* llite/lcommon_misc.c */
723 int cl_ocd_update(struct obd_device *host, struct obd_device *watched,
724 enum obd_notify_event ev, void *owner, void *data);
725 int cl_get_grouplock(struct cl_object *obj, unsigned long gid, int nonblock,
726 struct ll_grouplock *lg);
727 void cl_put_grouplock(struct ll_grouplock *lg);
729 /* llite/lproc_llite.c */
730 #ifdef CONFIG_PROC_FS
731 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
732 struct super_block *sb, char *osc, char *mdc);
733 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi);
734 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count);
735 extern struct lprocfs_vars lprocfs_llite_obd_vars[];
737 static inline int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
738 struct super_block *sb, char *osc, char *mdc){return 0;}
739 static inline void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi) {}
740 static void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count) {}
745 LPROC_LL_DIRTY_MISSES,
747 LPROC_LL_WRITE_BYTES,
772 LPROC_LL_ALLOC_INODE,
775 LPROC_LL_GETXATTR_HITS,
777 LPROC_LL_REMOVEXATTR,
779 LPROC_LL_FILE_OPCODES
783 struct ll_dir_chain {
786 static inline void ll_dir_chain_init(struct ll_dir_chain *chain)
790 static inline void ll_dir_chain_fini(struct ll_dir_chain *chain)
794 extern const struct file_operations ll_dir_operations;
795 extern const struct inode_operations ll_dir_inode_operations;
796 #ifdef HAVE_DIR_CONTEXT
797 int ll_dir_read(struct inode *inode, __u64 *pos, struct md_op_data *op_data,
798 struct dir_context *ctx);
800 int ll_dir_read(struct inode *inode, __u64 *pos, struct md_op_data *op_data,
801 void *cookie, filldir_t filldir);
803 int ll_get_mdt_idx(struct inode *inode);
804 int ll_get_mdt_idx_by_fid(struct ll_sb_info *sbi, const struct lu_fid *fid);
805 struct page *ll_get_dir_page(struct inode *dir, struct md_op_data *op_data,
806 __u64 offset, struct ll_dir_chain *chain);
807 void ll_release_page(struct inode *inode, struct page *page, bool remove);
810 extern const struct inode_operations ll_special_inode_operations;
812 struct inode *ll_iget(struct super_block *sb, ino_t hash,
813 struct lustre_md *lic);
814 int ll_test_inode_by_fid(struct inode *inode, void *opaque);
815 int ll_md_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
816 void *data, int flag);
817 struct dentry *ll_splice_alias(struct inode *inode, struct dentry *de);
818 int ll_rmdir_entry(struct inode *dir, char *name, int namelen);
819 void ll_update_times(struct ptlrpc_request *request, struct inode *inode);
822 int ll_writepage(struct page *page, struct writeback_control *wbc);
823 int ll_writepages(struct address_space *, struct writeback_control *wbc);
824 int ll_readpage(struct file *file, struct page *page);
825 void ll_readahead_init(struct inode *inode, struct ll_readahead_state *ras);
826 int vvp_io_write_commit(const struct lu_env *env, struct cl_io *io);
829 void ll_cl_add(struct file *file, const struct lu_env *env, struct cl_io *io,
831 void ll_cl_remove(struct file *file, const struct lu_env *env);
832 struct ll_cl_context *ll_cl_find(struct file *file);
834 extern const struct address_space_operations ll_aops;
837 extern struct file_operations ll_file_operations;
838 extern struct file_operations ll_file_operations_flock;
839 extern struct file_operations ll_file_operations_noflock;
840 extern struct inode_operations ll_file_inode_operations;
841 extern int ll_have_md_lock(struct inode *inode, __u64 *bits,
842 enum ldlm_mode l_req_mode);
843 extern enum ldlm_mode ll_take_md_lock(struct inode *inode, __u64 bits,
844 struct lustre_handle *lockh, __u64 flags,
845 enum ldlm_mode mode);
847 int ll_file_open(struct inode *inode, struct file *file);
848 int ll_file_release(struct inode *inode, struct file *file);
849 int ll_release_openhandle(struct dentry *, struct lookup_intent *);
850 int ll_md_real_close(struct inode *inode, fmode_t fmode);
851 extern void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
852 struct ll_file_data *file, loff_t pos,
853 size_t count, int rw);
854 int ll_getattr(struct vfsmount *mnt, struct dentry *de, struct kstat *stat);
855 struct posix_acl *ll_get_acl(struct inode *inode, int type);
856 int ll_migrate(struct inode *parent, struct file *file, int mdtidx,
857 const char *name, int namelen);
858 int ll_get_fid_by_name(struct inode *parent, const char *name,
859 int namelen, struct lu_fid *fid, struct inode **inode);
860 #ifdef HAVE_GENERIC_PERMISSION_4ARGS
861 int ll_inode_permission(struct inode *inode, int mask, unsigned int flags);
863 # ifndef HAVE_INODE_PERMISION_2ARGS
864 int ll_inode_permission(struct inode *inode, int mask, struct nameidata *nd);
866 int ll_inode_permission(struct inode *inode, int mask);
870 int ll_lov_setstripe_ea_info(struct inode *inode, struct file *file,
871 __u64 flags, struct lov_user_md *lum,
873 int ll_lov_getstripe_ea_info(struct inode *inode, const char *filename,
874 struct lov_mds_md **lmm, int *lmm_size,
875 struct ptlrpc_request **request);
876 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
878 int ll_dir_getstripe(struct inode *inode, void **lmmp,
879 int *lmm_size, struct ptlrpc_request **request,
881 #ifdef HAVE_FILE_FSYNC_4ARGS
882 int ll_fsync(struct file *file, loff_t start, loff_t end, int data);
883 #elif defined(HAVE_FILE_FSYNC_2ARGS)
884 int ll_fsync(struct file *file, int data);
886 int ll_fsync(struct file *file, struct dentry *dentry, int data);
888 int ll_merge_attr(const struct lu_env *env, struct inode *inode);
889 int ll_fid2path(struct inode *inode, void __user *arg);
890 int ll_data_version(struct inode *inode, __u64 *data_version, int flags);
891 int ll_hsm_release(struct inode *inode);
892 int ll_hsm_state_set(struct inode *inode, struct hsm_state_set *hss);
896 int ll_d_init(struct dentry *de);
897 extern const struct dentry_operations ll_d_ops;
898 void ll_intent_drop_lock(struct lookup_intent *);
899 void ll_intent_release(struct lookup_intent *);
900 void ll_invalidate_aliases(struct inode *);
901 void ll_lookup_finish_locks(struct lookup_intent *it, struct dentry *dentry);
902 int ll_revalidate_it_finish(struct ptlrpc_request *request,
903 struct lookup_intent *it, struct dentry *de);
905 /* llite/llite_lib.c */
906 extern struct super_operations lustre_super_operations;
908 void ll_lli_init(struct ll_inode_info *lli);
909 int ll_fill_super(struct super_block *sb, struct vfsmount *mnt);
910 void ll_put_super(struct super_block *sb);
911 void ll_kill_super(struct super_block *sb);
912 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock);
913 void ll_dir_clear_lsm_md(struct inode *inode);
914 void ll_clear_inode(struct inode *inode);
915 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr, bool hsm_import);
916 int ll_setattr(struct dentry *de, struct iattr *attr);
917 int ll_statfs(struct dentry *de, struct kstatfs *sfs);
918 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
919 __u64 max_age, __u32 flags);
920 int ll_update_inode(struct inode *inode, struct lustre_md *md);
921 int ll_read_inode2(struct inode *inode, void *opaque);
922 void ll_delete_inode(struct inode *inode);
923 int ll_iocontrol(struct inode *inode, struct file *file,
924 unsigned int cmd, unsigned long arg);
925 int ll_flush_ctx(struct inode *inode);
926 void ll_umount_begin(struct super_block *sb);
927 int ll_remount_fs(struct super_block *sb, int *flags, char *data);
928 #ifdef HAVE_SUPEROPS_USE_DENTRY
929 int ll_show_options(struct seq_file *seq, struct dentry *dentry);
931 int ll_show_options(struct seq_file *seq, struct vfsmount *vfs);
933 void ll_dirty_page_discard_warn(struct page *page, int ioret);
934 int ll_prep_inode(struct inode **inode, struct ptlrpc_request *req,
935 struct super_block *, struct lookup_intent *);
936 void lustre_dump_dentry(struct dentry *, int recur);
937 int ll_obd_statfs(struct inode *inode, void __user *arg);
938 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *max_mdsize);
939 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *default_mdsize);
940 int ll_set_default_mdsize(struct ll_sb_info *sbi, int default_mdsize);
941 int ll_process_config(struct lustre_cfg *lcfg);
944 LUSTRE_OPC_MKDIR = 0,
945 LUSTRE_OPC_SYMLINK = 1,
946 LUSTRE_OPC_MKNOD = 2,
947 LUSTRE_OPC_CREATE = 3,
951 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
952 struct inode *i1, struct inode *i2,
953 const char *name, size_t namelen,
954 __u32 mode, __u32 opc, void *data);
955 void ll_finish_md_op_data(struct md_op_data *op_data);
956 int ll_get_obd_name(struct inode *inode, unsigned int cmd, unsigned long arg);
957 char *ll_get_fsname(struct super_block *sb, char *buf, int buflen);
958 void ll_compute_rootsquash_state(struct ll_sb_info *sbi);
959 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
960 struct lov_user_md **kbuf);
961 void ll_open_cleanup(struct super_block *sb, struct ptlrpc_request *open_req);
963 /* Compute expected user md size when passing in a md from user space */
964 static inline ssize_t ll_lov_user_md_size(const struct lov_user_md *lum)
966 switch (lum->lmm_magic) {
967 case LOV_USER_MAGIC_V1:
968 return sizeof(struct lov_user_md_v1);
969 case LOV_USER_MAGIC_V3:
970 return sizeof(struct lov_user_md_v3);
971 case LOV_USER_MAGIC_SPECIFIC:
972 if (lum->lmm_stripe_count > LOV_MAX_STRIPE_COUNT)
975 return lov_user_md_size(lum->lmm_stripe_count,
976 LOV_USER_MAGIC_SPECIFIC);
982 /* llite/llite_nfs.c */
983 extern struct export_operations lustre_export_operations;
984 __u32 get_uuid2int(const char *name, int len);
985 struct inode *search_inode_for_lustre(struct super_block *sb,
986 const struct lu_fid *fid);
987 int ll_dir_get_parent_fid(struct inode *dir, struct lu_fid *parent_fid);
989 /* llite/symlink.c */
990 extern struct inode_operations ll_fast_symlink_inode_operations;
993 * IO arguments for various VFS I/O interfaces.
996 /** normal/sendfile/splice */
997 enum vvp_io_subtype via_io_subtype;
1001 struct kiocb *via_iocb;
1002 struct iov_iter *via_iter;
1005 struct pipe_inode_info *via_pipe;
1006 unsigned int via_flags;
1016 struct ll_cl_context {
1017 struct list_head lcc_list;
1019 const struct lu_env *lcc_env;
1020 struct cl_io *lcc_io;
1021 struct cl_page *lcc_page;
1022 enum lcc_type lcc_type;
1025 struct ll_thread_info {
1026 struct iov_iter lti_iter;
1027 struct vvp_io_args lti_args;
1028 struct ra_io_arg lti_ria;
1029 struct kiocb lti_kiocb;
1030 struct ll_cl_context lti_io_ctx;
1033 extern struct lu_context_key ll_thread_key;
1035 static inline struct ll_thread_info *ll_env_info(const struct lu_env *env)
1037 struct ll_thread_info *lti;
1039 lti = lu_context_key_get(&env->le_ctx, &ll_thread_key);
1040 LASSERT(lti != NULL);
1045 static inline struct vvp_io_args *ll_env_args(const struct lu_env *env,
1046 enum vvp_io_subtype type)
1048 struct vvp_io_args *via = &ll_env_info(env)->lti_args;
1050 via->via_io_subtype = type;
1055 /* llite/llite_mmap.c */
1057 int ll_teardown_mmaps(struct address_space *mapping, __u64 first, __u64 last);
1058 int ll_file_mmap(struct file * file, struct vm_area_struct * vma);
1059 void policy_from_vma(union ldlm_policy_data *policy, struct vm_area_struct *vma,
1060 unsigned long addr, size_t count);
1061 struct vm_area_struct *our_vma(struct mm_struct *mm, unsigned long addr,
1064 static inline void ll_invalidate_page(struct page *vmpage)
1066 struct address_space *mapping = vmpage->mapping;
1067 loff_t offset = vmpage->index << PAGE_CACHE_SHIFT;
1069 LASSERT(PageLocked(vmpage));
1070 if (mapping == NULL)
1074 * truncate_complete_page() calls
1075 * a_ops->invalidatepage()->cl_page_delete()->vvp_page_delete().
1077 ll_teardown_mmaps(mapping, offset, offset + PAGE_CACHE_SIZE);
1078 truncate_complete_page(mapping, vmpage);
1081 #define ll_s2sbi(sb) (s2lsi(sb)->lsi_llsbi)
1083 /* don't need an addref as the sb_info should be holding one */
1084 static inline struct obd_export *ll_s2dtexp(struct super_block *sb)
1086 return ll_s2sbi(sb)->ll_dt_exp;
1089 /* don't need an addref as the sb_info should be holding one */
1090 static inline struct obd_export *ll_s2mdexp(struct super_block *sb)
1092 return ll_s2sbi(sb)->ll_md_exp;
1095 static inline struct client_obd *sbi2mdc(struct ll_sb_info *sbi)
1097 struct obd_device *obd = sbi->ll_md_exp->exp_obd;
1103 // FIXME: replace the name of this with LL_SB to conform to kernel stuff
1104 static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
1106 return ll_s2sbi(inode->i_sb);
1109 static inline struct obd_export *ll_i2dtexp(struct inode *inode)
1111 return ll_s2dtexp(inode->i_sb);
1114 static inline struct obd_export *ll_i2mdexp(struct inode *inode)
1116 return ll_s2mdexp(inode->i_sb);
1119 static inline struct lu_fid *ll_inode2fid(struct inode *inode)
1123 LASSERT(inode != NULL);
1124 fid = &ll_i2info(inode)->lli_fid;
1129 static inline loff_t ll_file_maxbytes(struct inode *inode)
1131 struct cl_object *obj = ll_i2info(inode)->lli_clob;
1134 return MAX_LFS_FILESIZE;
1136 return min_t(loff_t, cl_object_maxbytes(obj), MAX_LFS_FILESIZE);
1140 int ll_setxattr(struct dentry *dentry, const char *name,
1141 const void *value, size_t size, int flags);
1142 ssize_t ll_getxattr(struct dentry *dentry, const char *name,
1143 void *buffer, size_t size);
1144 ssize_t ll_listxattr(struct dentry *dentry, char *buffer, size_t size);
1145 int ll_removexattr(struct dentry *dentry, const char *name);
1147 /* llite/remote_perm.c */
1148 extern struct kmem_cache *ll_remote_perm_cachep;
1149 extern struct kmem_cache *ll_rmtperm_hash_cachep;
1151 void free_rmtperm_hash(struct hlist_head *hash);
1152 int ll_update_remote_perm(struct inode *inode, struct mdt_remote_perm *perm);
1153 int lustre_check_remote_perm(struct inode *inode, int mask);
1156 * Common IO arguments for various VFS I/O interfaces.
1158 int cl_sb_init(struct super_block *sb);
1159 int cl_sb_fini(struct super_block *sb);
1161 enum ras_update_flags {
1165 void ll_ra_count_put(struct ll_sb_info *sbi, unsigned long len);
1166 void ll_ra_stats_inc(struct inode *inode, enum ra_stat which);
1168 /* llite/llite_rmtacl.c */
1169 #ifdef CONFIG_FS_POSIX_ACL
1170 u64 rce_ops2valid(int ops);
1171 struct rmtacl_ctl_entry *rct_search(struct rmtacl_ctl_table *rct, pid_t key);
1172 int rct_add(struct rmtacl_ctl_table *rct, pid_t key, int ops);
1173 int rct_del(struct rmtacl_ctl_table *rct, pid_t key);
1174 void rct_init(struct rmtacl_ctl_table *rct);
1175 void rct_fini(struct rmtacl_ctl_table *rct);
1177 void ee_free(struct eacl_entry *ee);
1178 int ee_add(struct eacl_table *et, pid_t key, struct lu_fid *fid, int type,
1179 ext_acl_xattr_header *header);
1180 struct eacl_entry *et_search_del(struct eacl_table *et, pid_t key,
1181 struct lu_fid *fid, int type);
1182 void et_search_free(struct eacl_table *et, pid_t key);
1183 void et_init(struct eacl_table *et);
1184 void et_fini(struct eacl_table *et);
1189 #define LL_SA_RPC_MIN 2
1190 #define LL_SA_RPC_DEF 32
1191 #define LL_SA_RPC_MAX 8192
1193 #define LL_SA_CACHE_BIT 5
1194 #define LL_SA_CACHE_SIZE (1 << LL_SA_CACHE_BIT)
1195 #define LL_SA_CACHE_MASK (LL_SA_CACHE_SIZE - 1)
1197 /* per inode struct, for dir only */
1198 struct ll_statahead_info {
1199 struct dentry *sai_dentry;
1200 atomic_t sai_refcount; /* when access this struct, hold
1202 unsigned int sai_max; /* max ahead of lookup */
1203 __u64 sai_sent; /* stat requests sent count */
1204 __u64 sai_replied; /* stat requests which received
1206 __u64 sai_index; /* index of statahead entry */
1207 __u64 sai_index_wait; /* index of entry which is the
1208 * caller is waiting for */
1209 __u64 sai_hit; /* hit count */
1210 __u64 sai_miss; /* miss count:
1211 * for "ls -al" case, includes
1212 * hidden dentry miss;
1213 * for "ls -l" case, it does not
1214 * include hidden dentry miss.
1215 * "sai_miss_hidden" is used for
1218 unsigned int sai_consecutive_miss; /* consecutive miss */
1219 unsigned int sai_miss_hidden;/* "ls -al", but first dentry
1220 * is not a hidden one */
1221 unsigned int sai_skip_hidden;/* skipped hidden dentry count
1223 unsigned int sai_ls_all:1, /* "ls -al", do stat-ahead for
1225 sai_agl_valid:1,/* AGL is valid for the dir */
1226 sai_in_readpage:1;/* statahead is in readdir()*/
1227 wait_queue_head_t sai_waitq; /* stat-ahead wait queue */
1228 struct ptlrpc_thread sai_thread; /* stat-ahead thread */
1229 struct ptlrpc_thread sai_agl_thread; /* AGL thread */
1230 struct list_head sai_interim_entries; /* entries which got async
1231 * stat reply, but not
1233 struct list_head sai_entries; /* completed entries */
1234 struct list_head sai_agls; /* AGLs to be sent */
1235 struct list_head sai_cache[LL_SA_CACHE_SIZE];
1236 spinlock_t sai_cache_lock[LL_SA_CACHE_SIZE];
1237 atomic_t sai_cache_count; /* entry count in cache */
1240 int ll_statahead(struct inode *dir, struct dentry **dentry, bool unplug);
1241 void ll_authorize_statahead(struct inode *dir, void *key);
1242 void ll_deauthorize_statahead(struct inode *dir, void *key);
1245 blkcnt_t dirty_cnt(struct inode *inode);
1247 int cl_glimpse_size0(struct inode *inode, int agl);
1248 int cl_glimpse_lock(const struct lu_env *env, struct cl_io *io,
1249 struct inode *inode, struct cl_object *clob, int agl);
1251 static inline int cl_glimpse_size(struct inode *inode)
1253 return cl_glimpse_size0(inode, 0);
1256 static inline int cl_agl(struct inode *inode)
1258 return cl_glimpse_size0(inode, 1);
1261 static inline int ll_glimpse_size(struct inode *inode)
1263 struct ll_inode_info *lli = ll_i2info(inode);
1266 down_read(&lli->lli_glimpse_sem);
1267 rc = cl_glimpse_size(inode);
1268 lli->lli_glimpse_time = cfs_time_current();
1269 up_read(&lli->lli_glimpse_sem);
1273 /* dentry may statahead when statahead is enabled and current process has opened
1274 * parent directory, and this dentry hasn't accessed statahead cache before */
1276 dentry_may_statahead(struct inode *dir, struct dentry *dentry)
1278 struct ll_inode_info *lli;
1279 struct ll_dentry_data *ldd;
1281 if (ll_i2sbi(dir)->ll_sa_max == 0)
1284 lli = ll_i2info(dir);
1286 /* statahead is not allowed for this dir, there may be three causes:
1287 * 1. dir is not opened.
1288 * 2. statahead hit ratio is too low.
1289 * 3. previous stat started statahead thread failed. */
1290 if (!lli->lli_sa_enabled)
1293 /* not the same process, don't statahead */
1294 if (lli->lli_opendir_pid != current_pid())
1298 * When stating a dentry, kernel may trigger 'revalidate' or 'lookup'
1299 * multiple times, eg. for 'getattr', 'getxattr' and etc.
1300 * For patchless client, lookup intent is not accurate, which may
1301 * misguide statahead. For example:
1302 * The 'revalidate' call for 'getattr' and 'getxattr' of a dentry will
1303 * have the same intent -- IT_GETATTR, while one dentry should access
1304 * statahead cache once, otherwise statahead windows is messed up.
1305 * The solution is as following:
1306 * Assign 'lld_sa_generation' with 'lli_sa_generation' when a dentry
1307 * IT_GETATTR for the first time, and subsequent IT_GETATTR will
1308 * bypass interacting with statahead cache by checking
1309 * 'lld_sa_generation == lli->lli_sa_generation'.
1311 ldd = ll_d2d(dentry);
1312 if (ldd != NULL && ldd->lld_sa_generation == lli->lli_sa_generation)
1318 /* llite ioctl register support rountine */
1324 #define LLIOC_MAX_CMD 256
1327 * Rules to write a callback function:
1330 * @magic: Dynamic ioctl call routine will feed this vaule with the pointer
1331 * returned to ll_iocontrol_register. Callback functions should use this
1332 * data to check the potential collasion of ioctl cmd. If collasion is
1333 * found, callback function should return LLIOC_CONT.
1334 * @rcp: The result of ioctl command.
1337 * If @magic matches the pointer returned by ll_iocontrol_data, the
1338 * callback should return LLIOC_STOP; return LLIOC_STOP otherwise.
1340 typedef enum llioc_iter (*llioc_callback_t)(struct inode *inode,
1341 struct file *file, unsigned int cmd, unsigned long arg,
1342 void *magic, int *rcp);
1344 /* export functions */
1345 /* Register ioctl block dynamatically for a regular file.
1347 * @cmd: the array of ioctl command set
1348 * @count: number of commands in the @cmd
1349 * @cb: callback function, it will be called if an ioctl command is found to
1350 * belong to the command list @cmd.
1353 * A magic pointer will be returned if success;
1354 * otherwise, NULL will be returned.
1356 void *ll_iocontrol_register(llioc_callback_t cb, int count, unsigned int *cmd);
1357 void ll_iocontrol_unregister(void *magic);
1359 int cl_sync_file_range(struct inode *inode, loff_t start, loff_t end,
1360 enum cl_fsync_mode mode, int ignore_layout);
1362 /** direct write pages */
1363 struct ll_dio_pages {
1364 /** page array to be written. we don't support
1365 * partial pages except the last one. */
1366 struct page **ldp_pages;
1367 /* offset of each page */
1368 loff_t *ldp_offsets;
1369 /** if ldp_offsets is NULL, it means a sequential
1370 * pages to be written, then this is the file offset
1371 * of the * first page. */
1372 loff_t ldp_start_offset;
1373 /** how many bytes are to be written. */
1375 /** # of pages in the array. */
1379 extern ssize_t ll_direct_rw_pages(const struct lu_env *env, struct cl_io *io,
1380 int rw, struct inode *inode,
1381 struct ll_dio_pages *pv);
1383 static inline int ll_file_nolock(const struct file *file)
1385 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1386 struct inode *inode = file->f_path.dentry->d_inode;
1388 LASSERT(fd != NULL);
1389 return ((fd->fd_flags & LL_FILE_IGNORE_LOCK) ||
1390 (ll_i2sbi(inode)->ll_flags & LL_SBI_NOLCK));
1393 static inline void ll_set_lock_data(struct obd_export *exp, struct inode *inode,
1394 struct lookup_intent *it, __u64 *bits)
1396 if (!it->it_lock_set) {
1397 struct lustre_handle handle;
1399 /* If this inode is a remote object, it will get two
1400 * separate locks in different namespaces, Master MDT,
1401 * where the name entry is, will grant LOOKUP lock,
1402 * remote MDT, where the object is, will grant
1403 * UPDATE|PERM lock. The inode will be attched to both
1404 * LOOKUP and PERM locks, so revoking either locks will
1405 * case the dcache being cleared */
1406 if (it->it_remote_lock_mode) {
1407 handle.cookie = it->it_remote_lock_handle;
1408 CDEBUG(D_DLMTRACE, "setting l_data to inode "DFID
1409 "(%p) for remote lock "LPX64"\n",
1410 PFID(ll_inode2fid(inode)), inode,
1412 md_set_lock_data(exp, &handle.cookie, inode, NULL);
1415 handle.cookie = it->it_lock_handle;
1417 CDEBUG(D_DLMTRACE, "setting l_data to inode "DFID"(%p)"
1418 " for lock "LPX64"\n",
1419 PFID(ll_inode2fid(inode)), inode, handle.cookie);
1421 md_set_lock_data(exp, &handle.cookie, inode,
1423 it->it_lock_set = 1;
1427 *bits = it->it_lock_bits;
1430 static inline void ll_lock_dcache(struct inode *inode)
1432 #ifdef HAVE_DCACHE_LOCK
1433 spin_lock(&dcache_lock);
1435 spin_lock(&inode->i_lock);
1439 static inline void ll_unlock_dcache(struct inode *inode)
1441 #ifdef HAVE_DCACHE_LOCK
1442 spin_unlock(&dcache_lock);
1444 spin_unlock(&inode->i_lock);
1448 static inline int d_lustre_invalid(const struct dentry *dentry)
1450 struct ll_dentry_data *lld = ll_d2d(dentry);
1452 return (lld == NULL) || lld->lld_invalid;
1455 static inline void __d_lustre_invalidate(struct dentry *dentry)
1457 struct ll_dentry_data *lld = ll_d2d(dentry);
1460 lld->lld_invalid = 1;
1464 * Mark dentry INVALID, if dentry refcount is zero (this is normally case for
1465 * ll_md_blocking_ast), unhash this dentry, and let dcache to reclaim it later;
1466 * else dput() of the last refcount will unhash this dentry and kill it.
1468 static inline void d_lustre_invalidate(struct dentry *dentry, int nested)
1470 CDEBUG(D_DENTRY, "invalidate dentry %.*s (%p) parent %p inode %p "
1471 "refc %d\n", dentry->d_name.len, dentry->d_name.name, dentry,
1472 dentry->d_parent, dentry->d_inode, ll_d_count(dentry));
1474 spin_lock_nested(&dentry->d_lock,
1475 nested ? DENTRY_D_LOCK_NESTED : DENTRY_D_LOCK_NORMAL);
1476 __d_lustre_invalidate(dentry);
1478 * We should be careful about dentries created by d_obtain_alias().
1479 * These dentries are not put in the dentry tree, instead they are
1480 * linked to sb->s_anon through dentry->d_hash.
1481 * shrink_dcache_for_umount() shrinks the tree and sb->s_anon list.
1482 * If we unhashed such a dentry, unmount would not be able to find
1483 * it and busy inodes would be reported.
1485 if (ll_d_count(dentry) == 0 && !(dentry->d_flags & DCACHE_DISCONNECTED))
1487 spin_unlock(&dentry->d_lock);
1490 static inline void d_lustre_revalidate(struct dentry *dentry)
1492 spin_lock(&dentry->d_lock);
1493 LASSERT(ll_d2d(dentry) != NULL);
1494 ll_d2d(dentry)->lld_invalid = 0;
1495 spin_unlock(&dentry->d_lock);
1498 int ll_layout_conf(struct inode *inode, const struct cl_object_conf *conf);
1499 int ll_layout_refresh(struct inode *inode, __u32 *gen);
1500 int ll_layout_restore(struct inode *inode, loff_t start, __u64 length);
1502 int ll_xattr_init(void);
1503 void ll_xattr_fini(void);
1505 int ll_getxattr_common(struct inode *inode, const char *name,
1506 void *buffer, size_t size, __u64 valid);
1507 int ll_page_sync_io(const struct lu_env *env, struct cl_io *io,
1508 struct cl_page *page, enum cl_req_type crt);
1510 int ll_getparent(struct file *file, struct getparent __user *arg);
1513 int cl_setattr_ost(struct cl_object *obj, const struct iattr *attr,
1514 unsigned int attr_flags);
1516 extern struct lu_env *cl_inode_fini_env;
1517 extern __u16 cl_inode_fini_refcheck;
1519 int cl_file_inode_init(struct inode *inode, struct lustre_md *md);
1520 void cl_inode_fini(struct inode *inode);
1522 u64 cl_fid_build_ino(const struct lu_fid *fid, int api32);
1523 u32 cl_fid_build_gen(const struct lu_fid *fid);
1525 #ifndef HAVE_FILE_INODE
1526 static inline struct inode *file_inode(struct file *file)
1528 return file->f_path.dentry->d_inode;
1532 #ifndef HAVE_IOV_ITER_TRUNCATE
1533 static inline void iov_iter_truncate(struct iov_iter *i, u64 count)
1535 if (i->count > count)
1540 #ifndef HAVE_FILE_OPERATIONS_READ_WRITE_ITER
1541 static inline void iov_iter_reexpand(struct iov_iter *i, size_t count)
1546 static inline struct iovec iov_iter_iovec(const struct iov_iter *iter)
1548 return (struct iovec) {
1549 .iov_base = iter->iov->iov_base + iter->iov_offset,
1550 .iov_len = min(iter->count,
1551 iter->iov->iov_len - iter->iov_offset),
1555 #define iov_for_each(iov, iter, start) \
1556 for (iter = (start); \
1557 (iter).count && ((iov = iov_iter_iovec(&(iter))), 1); \
1558 iov_iter_advance(&(iter), (iov).iov_len))
1560 static inline ssize_t
1561 generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
1567 iov_for_each(iov, i, *iter) {
1570 res = generic_file_aio_read(iocb, &iov, 1, iocb->ki_pos);
1578 if (res < iov.iov_len)
1583 iov_iter_advance(iter, bytes);
1587 static inline ssize_t
1588 generic_file_write_iter(struct kiocb *iocb, struct iov_iter *iter)
1594 iov_for_each(iov, i, *iter) {
1597 res = __generic_file_aio_write(iocb, &iov, 1, &iocb->ki_pos);
1605 if (res < iov.iov_len)
1610 iov_iter_advance(iter, bytes);
1613 #endif /* HAVE_FILE_OPERATIONS_READ_WRITE_ITER */
1614 #endif /* LLITE_INTERNAL_H */