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 struct rcu_head lld_rcu_head;
87 #define ll_d2d(de) ((struct ll_dentry_data*)((de)->d_fsdata))
89 #define LLI_INODE_MAGIC 0x111d0de5
90 #define LLI_INODE_DEAD 0xdeadd00d
92 /* remote client permission cache */
93 #define REMOTE_PERM_HASHSIZE 16
95 struct ll_getname_data {
96 #ifdef HAVE_DIR_CONTEXT
97 struct dir_context ctx;
99 char *lgd_name; /* points to a buffer with NAME_MAX+1 size */
100 struct lu_fid lgd_fid; /* target fid we are looking for */
101 int lgd_found; /* inode matched? */
104 /* llite setxid/access permission for user on remote client */
105 struct ll_remote_perm {
106 struct hlist_node lrp_list;
111 int lrp_access_perm; /* MAY_READ/WRITE/EXEC, this
112 is access permission with
113 lrp_fsuid/lrp_fsgid. */
116 struct ll_grouplock {
117 struct lu_env *lg_env;
119 struct cl_lock *lg_lock;
120 unsigned long lg_gid;
123 struct ll_inode_info {
124 __u32 lli_inode_magic;
127 volatile unsigned long lli_flags;
128 struct posix_acl *lli_posix_acl;
130 struct hlist_head *lli_remote_perms;
131 struct mutex lli_rmtperm_mutex;
133 /* identifying fields for both metadata and data stacks. */
134 struct lu_fid lli_fid;
135 /* master inode fid for stripe directory */
136 struct lu_fid lli_pfid;
138 /* open count currently used by capability only, indicate whether
139 * capability needs renewal */
140 atomic_t lli_open_count;
141 cfs_time_t lli_rmtperm_time;
143 /* We need all three because every inode may be opened in different
145 struct obd_client_handle *lli_mds_read_och;
146 struct obd_client_handle *lli_mds_write_och;
147 struct obd_client_handle *lli_mds_exec_och;
148 __u64 lli_open_fd_read_count;
149 __u64 lli_open_fd_write_count;
150 __u64 lli_open_fd_exec_count;
151 /* Protects access to och pointers and their usage counters */
152 struct mutex lli_och_mutex;
154 struct inode lli_vfs_inode;
156 /* the most recent timestamps obtained from mds */
160 spinlock_t lli_agl_lock;
162 /* Try to make the d::member and f::member are aligned. Before using
163 * these members, make clear whether it is directory or not. */
167 /* serialize normal readdir and statahead-readdir. */
168 struct mutex lli_readdir_mutex;
170 /* metadata statahead */
171 /* since parent-child threads can share the same @file
172 * struct, "opendir_key" is the token when dir close for
173 * case of parent exit before child -- it is me should
174 * cleanup the dir readahead. */
175 void *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/revalid
180 * -- I am the owner of dir statahead. */
181 pid_t lli_opendir_pid;
182 /* stat will try to access statahead entries or start
183 * statahead if this flag is set, and this flag will be
184 * set upon dir open, and cleared when dir is closed,
185 * statahead hit ratio is too low, or start statahead
187 unsigned int lli_sa_enabled:1;
188 /* generation for statahead */
189 unsigned int lli_sa_generation;
190 /* directory stripe information */
191 struct lmv_stripe_md *lli_lsm_md;
192 /* default directory stripe offset. This is extracted
193 * from the "dmv" xattr in order to decide which MDT to
194 * create a subdirectory on. The MDS itself fetches
195 * "dmv" and gets the rest of the default layout itself
196 * (count, hash, etc). */
197 __u32 lli_def_stripe_offset;
200 /* for non-directory */
202 struct mutex lli_size_mutex;
203 char *lli_symlink_name;
205 * struct rw_semaphore {
206 * signed long count; // align d.d_def_acl
207 * spinlock_t wait_lock; // align d.d_sa_lock
208 * struct list_head wait_list;
211 struct rw_semaphore lli_trunc_sem;
212 struct range_lock_tree lli_write_tree;
214 struct rw_semaphore lli_glimpse_sem;
215 cfs_time_t lli_glimpse_time;
216 struct list_head lli_agl_list;
219 /* for writepage() only to communicate to fsync */
223 * whenever a process try to read/write the file, the
224 * jobid of the process will be saved here, and it'll
225 * be packed into the write PRC when flush later.
227 * so the read/write statistics for jobid will not be
228 * accurate if the file is shared by different jobs.
230 char lli_jobid[LUSTRE_JOBID_SIZE];
234 /* XXX: For following frequent used members, although they maybe special
235 * used for non-directory object, it is some time-wasting to check
236 * whether the object is directory or not before using them. On the
237 * other hand, currently, sizeof(f) > sizeof(d), it cannot reduce
238 * the "ll_inode_info" size even if moving those members into u.f.
239 * So keep them out side.
241 * In the future, if more members are added only for directory,
242 * some of the following members can be moved into u.f.
244 struct cl_object *lli_clob;
246 /* mutex to request for layout lock exclusively. */
247 struct mutex lli_layout_mutex;
248 /* Layout version, protected by lli_layout_lock */
249 __u32 lli_layout_gen;
250 spinlock_t lli_layout_lock;
252 struct rw_semaphore lli_xattrs_list_rwsem;
253 struct mutex lli_xattrs_enq_lock;
254 struct list_head lli_xattrs; /* ll_xattr_entry->xe_list */
257 static inline __u32 ll_layout_version_get(struct ll_inode_info *lli)
261 spin_lock(&lli->lli_layout_lock);
262 gen = lli->lli_layout_gen;
263 spin_unlock(&lli->lli_layout_lock);
268 static inline void ll_layout_version_set(struct ll_inode_info *lli, __u32 gen)
270 spin_lock(&lli->lli_layout_lock);
271 lli->lli_layout_gen = gen;
272 spin_unlock(&lli->lli_layout_lock);
276 /* File data is modified. */
277 LLIF_DATA_MODIFIED = 0,
278 /* File is being restored */
279 LLIF_FILE_RESTORING = 1,
280 /* Xattr cache is attached to the file */
281 LLIF_XATTR_CACHE = 2,
284 static inline void ll_file_set_flag(struct ll_inode_info *lli,
285 enum ll_file_flags flag)
287 set_bit(flag, &lli->lli_flags);
290 static inline void ll_file_clear_flag(struct ll_inode_info *lli,
291 enum ll_file_flags flag)
293 clear_bit(flag, &lli->lli_flags);
296 static inline bool ll_file_test_flag(struct ll_inode_info *lli,
297 enum ll_file_flags flag)
299 return test_bit(flag, &lli->lli_flags);
302 static inline bool ll_file_test_and_clear_flag(struct ll_inode_info *lli,
303 enum ll_file_flags flag)
305 return test_and_clear_bit(flag, &lli->lli_flags);
308 int ll_xattr_cache_destroy(struct inode *inode);
310 int ll_xattr_cache_get(struct inode *inode,
316 int ll_init_security(struct dentry *dentry,
321 * Locking to guarantee consistency of non-atomic updates to long long i_size,
322 * consistency between file size and KMS.
324 * Implemented by ->lli_size_mutex and ->lsm_lock, nested in that order.
327 void ll_inode_size_lock(struct inode *inode);
328 void ll_inode_size_unlock(struct inode *inode);
330 // FIXME: replace the name of this with LL_I to conform to kernel stuff
331 // static inline struct ll_inode_info *LL_I(struct inode *inode)
332 static inline struct ll_inode_info *ll_i2info(struct inode *inode)
334 return container_of(inode, struct ll_inode_info, lli_vfs_inode);
337 /* default to about 64M of readahead on a given system. */
338 #define SBI_DEFAULT_READAHEAD_MAX (64UL << (20 - PAGE_CACHE_SHIFT))
340 /* default to read-ahead full files smaller than 2MB on the second read */
341 #define SBI_DEFAULT_READAHEAD_WHOLE_MAX (2UL << (20 - PAGE_CACHE_SHIFT))
346 RA_STAT_DISTANT_READPAGE,
347 RA_STAT_MISS_IN_WINDOW,
348 RA_STAT_FAILED_GRAB_PAGE,
349 RA_STAT_FAILED_MATCH,
354 RA_STAT_MAX_IN_FLIGHT,
355 RA_STAT_WRONG_GRAB_PAGE,
356 RA_STAT_FAILED_REACH_END,
361 atomic_t ra_cur_pages;
362 unsigned long ra_max_pages;
363 unsigned long ra_max_pages_per_file;
364 unsigned long ra_max_read_ahead_whole_pages;
367 /* ra_io_arg will be filled in the beginning of ll_readahead with
368 * ras_lock, then the following ll_read_ahead_pages will read RA
369 * pages according to this arg, all the items in this structure are
370 * counted by page index.
373 unsigned long ria_start; /* start offset of read-ahead*/
374 unsigned long ria_end; /* end offset of read-ahead*/
375 unsigned long ria_reserved; /* reserved pages for read-ahead */
376 unsigned long ria_end_min; /* minimum end to cover current read */
377 bool ria_eof; /* reach end of file */
378 /* If stride read pattern is detected, ria_stoff means where
379 * stride read is started. Note: for normal read-ahead, the
380 * value here is meaningless, and also it will not be accessed*/
382 /* ria_length and ria_pages are the length and pages length in the
383 * stride I/O mode. And they will also be used to check whether
384 * it is stride I/O read-ahead in the read-ahead pages*/
385 unsigned long ria_length;
386 unsigned long ria_pages;
389 /* LL_HIST_MAX=32 causes an overflow */
390 #define LL_HIST_MAX 28
391 #define LL_HIST_START 12 /* buckets start at 2^12 = 4k */
392 #define LL_PROCESS_HIST_MAX 10
393 struct per_process_info {
395 struct obd_histogram pp_r_hist;
396 struct obd_histogram pp_w_hist;
399 /* pp_extents[LL_PROCESS_HIST_MAX] will hold the combined process info */
400 struct ll_rw_extents_info {
401 struct per_process_info pp_extents[LL_PROCESS_HIST_MAX + 1];
404 #define LL_OFFSET_HIST_MAX 100
405 struct ll_rw_process_info {
408 loff_t rw_range_start;
410 loff_t rw_last_file_pos;
412 size_t rw_smallest_extent;
413 size_t rw_largest_extent;
414 struct ll_file_data *rw_last_file;
417 enum stats_track_type {
418 STATS_TRACK_ALL = 0, /* track all processes */
419 STATS_TRACK_PID, /* track process with this pid */
420 STATS_TRACK_PPID, /* track processes with this ppid */
421 STATS_TRACK_GID, /* track processes with this gid */
425 /* flags for sbi->ll_flags */
426 #define LL_SBI_NOLCK 0x01 /* DLM locking disabled (directio-only) */
427 #define LL_SBI_CHECKSUM 0x02 /* checksum each page as it's written */
428 #define LL_SBI_FLOCK 0x04
429 #define LL_SBI_USER_XATTR 0x08 /* support user xattr */
430 #define LL_SBI_ACL 0x10 /* support ACL */
431 #define LL_SBI_RMT_CLIENT 0x40 /* remote client */
432 #define LL_SBI_MDS_CAPA 0x80 /* support mds capa, obsolete */
433 #define LL_SBI_OSS_CAPA 0x100 /* support oss capa, obsolete */
434 #define LL_SBI_LOCALFLOCK 0x200 /* Local flocks support by kernel */
435 #define LL_SBI_LRU_RESIZE 0x400 /* lru resize support */
436 #define LL_SBI_LAZYSTATFS 0x800 /* lazystatfs mount option */
437 /* LL_SBI_SOM_PREVIEW 0x1000 SOM preview mount option, obsolete */
438 #define LL_SBI_32BIT_API 0x2000 /* generate 32 bit inodes. */
439 #define LL_SBI_64BIT_HASH 0x4000 /* support 64-bits dir hash/offset */
440 #define LL_SBI_AGL_ENABLED 0x8000 /* enable agl */
441 #define LL_SBI_VERBOSE 0x10000 /* verbose mount/umount */
442 #define LL_SBI_LAYOUT_LOCK 0x20000 /* layout lock support */
443 #define LL_SBI_USER_FID2PATH 0x40000 /* allow fid2path by unprivileged users */
444 #define LL_SBI_XATTR_CACHE 0x80000 /* support for xattr cache */
445 #define LL_SBI_NOROOTSQUASH 0x100000 /* do not apply root squash */
446 #define LL_SBI_ALWAYS_PING 0x200000 /* always ping even if server
448 #define LL_SBI_FAST_READ 0x400000 /* fast read support */
450 #define LL_SBI_FLAGS { \
476 #define RCE_HASHES 32
478 struct rmtacl_ctl_entry {
479 struct list_head rce_list;
480 pid_t rce_key; /* hash key */
481 int rce_ops; /* acl operation type */
484 struct rmtacl_ctl_table {
486 struct list_head rct_entries[RCE_HASHES];
492 struct list_head ee_list;
493 pid_t ee_key; /* hash key */
494 struct lu_fid ee_fid;
495 int ee_type; /* ACL type for ACCESS or DEFAULT */
496 ext_acl_xattr_header *ee_acl;
501 struct list_head et_entries[EE_HASHES];
505 /* This is embedded into llite super-blocks to keep track of connect
506 * flags (capabilities) supported by all imports given mount is
508 struct lustre_client_ocd {
509 /* This is conjunction of connect_flags across all imports
510 * (LOVs) this mount is connected to. This field is updated by
511 * cl_ocd_update() under ->lco_lock. */
513 struct mutex lco_lock;
514 struct obd_export *lco_md_exp;
515 struct obd_export *lco_dt_exp;
519 /* this protects pglist and ra_info. It isn't safe to
520 * grab from interrupt contexts */
522 spinlock_t ll_pp_extent_lock; /* pp_extent entry*/
523 spinlock_t ll_process_lock; /* ll_rw_process_info */
524 struct obd_uuid ll_sb_uuid;
525 struct obd_export *ll_md_exp;
526 struct obd_export *ll_dt_exp;
527 struct proc_dir_entry* ll_proc_root;
528 struct lu_fid ll_root_fid; /* root object fid */
531 unsigned int ll_umounting:1,
532 ll_xattr_cache_enabled:1,
533 ll_client_common_fill_super_succeeded:1;
535 /* per-conn chain of SBs */
536 struct list_head ll_conn_chain;
537 struct lustre_client_ocd ll_lco;
539 /*please don't ask -p*/
540 struct list_head ll_orphan_dentry_list;
542 struct lprocfs_stats *ll_stats; /* lprocfs stats counter */
544 /* Used to track "unstable" pages on a client, and maintain a
545 * LRU list of clean pages. An "unstable" page is defined as
546 * any page which is sent to a server as part of a bulk request,
547 * but is uncommitted to stable storage. */
548 struct cl_client_cache *ll_cache;
550 struct lprocfs_stats *ll_ra_stats;
552 struct ll_ra_info ll_ra_info;
553 unsigned int ll_namelen;
554 struct file_operations *ll_fop;
556 unsigned int ll_md_brw_pages; /* readdir pages per RPC */
558 struct lu_site *ll_site;
559 struct cl_device *ll_cl;
561 struct ll_rw_extents_info ll_rw_extents_info;
562 int ll_extent_process_count;
563 struct ll_rw_process_info ll_rw_process_info[LL_PROCESS_HIST_MAX];
564 unsigned int ll_offset_process_count;
565 struct ll_rw_process_info ll_rw_offset_info[LL_OFFSET_HIST_MAX];
566 unsigned int ll_rw_offset_entry_count;
567 int ll_stats_track_id;
568 enum stats_track_type ll_stats_track_type;
571 /* metadata stat-ahead */
572 unsigned int ll_sa_max; /* max statahead RPCs */
573 atomic_t ll_sa_total; /* statahead thread started
575 atomic_t ll_sa_wrong; /* statahead thread stopped for
577 atomic_t ll_sa_running; /* running statahead thread
579 atomic_t ll_agl_total; /* AGL thread started count */
581 dev_t ll_sdev_orig; /* save s_dev before assign for
583 struct rmtacl_ctl_table ll_rct;
584 struct eacl_table ll_et;
587 struct root_squash_info ll_squash;
591 * per file-descriptor read-ahead data.
593 struct ll_readahead_state {
596 * index of the last page that read(2) needed and that wasn't in the
597 * cache. Used by ras_update() to detect seeks.
599 * XXX nikita: if access seeks into cached region, Lustre doesn't see
602 unsigned long ras_last_readpage;
604 * number of pages read after last read-ahead window reset. As window
605 * is reset on each seek, this is effectively a number of consecutive
606 * accesses. Maybe ->ras_accessed_in_window is better name.
608 * XXX nikita: window is also reset (by ras_update()) when Lustre
609 * believes that memory pressure evicts read-ahead pages. In that
610 * case, it probably doesn't make sense to expand window to
611 * PTLRPC_MAX_BRW_PAGES on the third access.
613 unsigned long ras_consecutive_pages;
615 * number of read requests after the last read-ahead window reset
616 * As window is reset on each seek, this is effectively the number
617 * on consecutive read request and is used to trigger read-ahead.
619 unsigned long ras_consecutive_requests;
621 * Parameters of current read-ahead window. Handled by
622 * ras_update(). On the initial access to the file or after a seek,
623 * window is reset to 0. After 3 consecutive accesses, window is
624 * expanded to PTLRPC_MAX_BRW_PAGES. Afterwards, window is enlarged by
625 * PTLRPC_MAX_BRW_PAGES chunks up to ->ra_max_pages.
627 unsigned long ras_window_start, ras_window_len;
629 * Optimal RPC size. It decides how many pages will be sent
630 * for each read-ahead.
632 unsigned long ras_rpc_size;
634 * Where next read-ahead should start at. This lies within read-ahead
635 * window. Read-ahead window is read in pieces rather than at once
636 * because: 1. lustre limits total number of pages under read-ahead by
637 * ->ra_max_pages (see ll_ra_count_get()), 2. client cannot read pages
638 * not covered by DLM lock.
640 unsigned long ras_next_readahead;
642 * Total number of ll_file_read requests issued, reads originating
643 * due to mmap are not counted in this total. This value is used to
644 * trigger full file read-ahead after multiple reads to a small file.
646 unsigned long ras_requests;
648 * Page index with respect to the current request, these value
649 * will not be accurate when dealing with reads issued via mmap.
651 unsigned long ras_request_index;
653 * The following 3 items are used for detecting the stride I/O
655 * In stride I/O mode,
656 * ...............|-----data-----|****gap*****|--------|******|....
657 * offset |-stride_pages-|-stride_gap-|
658 * ras_stride_offset = offset;
659 * ras_stride_length = stride_pages + stride_gap;
660 * ras_stride_pages = stride_pages;
661 * Note: all these three items are counted by pages.
663 unsigned long ras_stride_length;
664 unsigned long ras_stride_pages;
665 pgoff_t ras_stride_offset;
667 * number of consecutive stride request count, and it is similar as
668 * ras_consecutive_requests, but used for stride I/O mode.
669 * Note: only more than 2 consecutive stride request are detected,
670 * stride read-ahead will be enable
672 unsigned long ras_consecutive_stride_requests;
675 extern struct kmem_cache *ll_file_data_slab;
676 struct lustre_handle;
677 struct ll_file_data {
678 struct ll_readahead_state fd_ras;
679 struct ll_grouplock fd_grouplock;
683 /* openhandle if lease exists for this file.
684 * Borrow lli->lli_och_mutex to protect assignment */
685 struct obd_client_handle *fd_lease_och;
686 struct obd_client_handle *fd_och;
687 struct file *fd_file;
688 /* Indicate whether need to report failure when close.
689 * true: failure is known, not report again.
690 * false: unknown failure, should report. */
691 bool fd_write_failed;
692 rwlock_t fd_lock; /* protect lcc list */
693 struct list_head fd_lccs; /* list of ll_cl_context */
696 extern spinlock_t inode_lock;
698 extern struct proc_dir_entry *proc_lustre_fs_root;
700 static inline struct inode *ll_info2i(struct ll_inode_info *lli)
702 return &lli->lli_vfs_inode;
705 __u32 ll_i2suppgid(struct inode *i);
706 void ll_i2gids(__u32 *suppgids, struct inode *i1,struct inode *i2);
708 static inline int ll_need_32bit_api(struct ll_sb_info *sbi)
710 #if BITS_PER_LONG == 32
712 #elif defined(CONFIG_COMPAT)
713 return unlikely(is_compat_task() || (sbi->ll_flags & LL_SBI_32BIT_API));
715 return unlikely(sbi->ll_flags & LL_SBI_32BIT_API);
719 static inline bool ll_sbi_has_fast_read(struct ll_sb_info *sbi)
721 return !!(sbi->ll_flags & LL_SBI_FAST_READ);
724 void ll_ras_enter(struct file *f);
726 /* llite/lcommon_misc.c */
727 int cl_ocd_update(struct obd_device *host, struct obd_device *watched,
728 enum obd_notify_event ev, void *owner, void *data);
729 int cl_get_grouplock(struct cl_object *obj, unsigned long gid, int nonblock,
730 struct ll_grouplock *lg);
731 void cl_put_grouplock(struct ll_grouplock *lg);
733 /* llite/lproc_llite.c */
734 #ifdef CONFIG_PROC_FS
735 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
736 struct super_block *sb, char *osc, char *mdc);
737 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi);
738 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count);
739 extern struct lprocfs_vars lprocfs_llite_obd_vars[];
741 static inline int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
742 struct super_block *sb, char *osc, char *mdc){return 0;}
743 static inline void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi) {}
744 static void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count) {}
749 LPROC_LL_DIRTY_MISSES,
751 LPROC_LL_WRITE_BYTES,
776 LPROC_LL_ALLOC_INODE,
779 LPROC_LL_GETXATTR_HITS,
781 LPROC_LL_REMOVEXATTR,
783 LPROC_LL_FILE_OPCODES
787 struct ll_dir_chain {
790 static inline void ll_dir_chain_init(struct ll_dir_chain *chain)
794 static inline void ll_dir_chain_fini(struct ll_dir_chain *chain)
798 extern const struct file_operations ll_dir_operations;
799 extern const struct inode_operations ll_dir_inode_operations;
800 #ifdef HAVE_DIR_CONTEXT
801 int ll_dir_read(struct inode *inode, __u64 *pos, struct md_op_data *op_data,
802 struct dir_context *ctx);
804 int ll_dir_read(struct inode *inode, __u64 *pos, struct md_op_data *op_data,
805 void *cookie, filldir_t filldir);
807 int ll_get_mdt_idx(struct inode *inode);
808 int ll_get_mdt_idx_by_fid(struct ll_sb_info *sbi, const struct lu_fid *fid);
809 struct page *ll_get_dir_page(struct inode *dir, struct md_op_data *op_data,
810 __u64 offset, struct ll_dir_chain *chain);
811 void ll_release_page(struct inode *inode, struct page *page, bool remove);
814 extern const struct inode_operations ll_special_inode_operations;
816 struct inode *ll_iget(struct super_block *sb, ino_t hash,
817 struct lustre_md *lic);
818 int ll_test_inode_by_fid(struct inode *inode, void *opaque);
819 int ll_md_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
820 void *data, int flag);
821 struct dentry *ll_splice_alias(struct inode *inode, struct dentry *de);
822 int ll_rmdir_entry(struct inode *dir, char *name, int namelen);
823 void ll_update_times(struct ptlrpc_request *request, struct inode *inode);
826 int ll_writepage(struct page *page, struct writeback_control *wbc);
827 int ll_writepages(struct address_space *, struct writeback_control *wbc);
828 int ll_readpage(struct file *file, struct page *page);
829 void ll_readahead_init(struct inode *inode, struct ll_readahead_state *ras);
830 int vvp_io_write_commit(const struct lu_env *env, struct cl_io *io);
833 void ll_cl_add(struct file *file, const struct lu_env *env, struct cl_io *io,
835 void ll_cl_remove(struct file *file, const struct lu_env *env);
836 struct ll_cl_context *ll_cl_find(struct file *file);
838 extern const struct address_space_operations ll_aops;
841 extern struct file_operations ll_file_operations;
842 extern struct file_operations ll_file_operations_flock;
843 extern struct file_operations ll_file_operations_noflock;
844 extern struct inode_operations ll_file_inode_operations;
845 extern int ll_have_md_lock(struct inode *inode, __u64 *bits,
846 enum ldlm_mode l_req_mode);
847 extern enum ldlm_mode ll_take_md_lock(struct inode *inode, __u64 bits,
848 struct lustre_handle *lockh, __u64 flags,
849 enum ldlm_mode mode);
851 int ll_file_open(struct inode *inode, struct file *file);
852 int ll_file_release(struct inode *inode, struct file *file);
853 int ll_release_openhandle(struct dentry *, struct lookup_intent *);
854 int ll_md_real_close(struct inode *inode, fmode_t fmode);
855 extern void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
856 struct ll_file_data *file, loff_t pos,
857 size_t count, int rw);
858 int ll_getattr(struct vfsmount *mnt, struct dentry *de, struct kstat *stat);
859 struct posix_acl *ll_get_acl(struct inode *inode, int type);
860 int ll_migrate(struct inode *parent, struct file *file, int mdtidx,
861 const char *name, int namelen);
862 int ll_get_fid_by_name(struct inode *parent, const char *name,
863 int namelen, struct lu_fid *fid, struct inode **inode);
864 #ifdef HAVE_GENERIC_PERMISSION_4ARGS
865 int ll_inode_permission(struct inode *inode, int mask, unsigned int flags);
867 # ifndef HAVE_INODE_PERMISION_2ARGS
868 int ll_inode_permission(struct inode *inode, int mask, struct nameidata *nd);
870 int ll_inode_permission(struct inode *inode, int mask);
874 int ll_lov_setstripe_ea_info(struct inode *inode, struct file *file,
875 __u64 flags, struct lov_user_md *lum,
877 int ll_lov_getstripe_ea_info(struct inode *inode, const char *filename,
878 struct lov_mds_md **lmm, int *lmm_size,
879 struct ptlrpc_request **request);
880 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
882 int ll_dir_getstripe(struct inode *inode, void **lmmp,
883 int *lmm_size, struct ptlrpc_request **request,
885 #ifdef HAVE_FILE_FSYNC_4ARGS
886 int ll_fsync(struct file *file, loff_t start, loff_t end, int data);
887 #elif defined(HAVE_FILE_FSYNC_2ARGS)
888 int ll_fsync(struct file *file, int data);
890 int ll_fsync(struct file *file, struct dentry *dentry, int data);
892 int ll_merge_attr(const struct lu_env *env, struct inode *inode);
893 int ll_fid2path(struct inode *inode, void __user *arg);
894 int ll_data_version(struct inode *inode, __u64 *data_version, int flags);
895 int ll_hsm_release(struct inode *inode);
896 int ll_hsm_state_set(struct inode *inode, struct hsm_state_set *hss);
900 int ll_d_init(struct dentry *de);
901 extern const struct dentry_operations ll_d_ops;
902 void ll_intent_drop_lock(struct lookup_intent *);
903 void ll_intent_release(struct lookup_intent *);
904 void ll_invalidate_aliases(struct inode *);
905 void ll_lookup_finish_locks(struct lookup_intent *it, struct dentry *dentry);
906 int ll_revalidate_it_finish(struct ptlrpc_request *request,
907 struct lookup_intent *it, struct dentry *de);
909 /* llite/llite_lib.c */
910 extern struct super_operations lustre_super_operations;
912 void ll_lli_init(struct ll_inode_info *lli);
913 int ll_fill_super(struct super_block *sb, struct vfsmount *mnt);
914 void ll_put_super(struct super_block *sb);
915 void ll_kill_super(struct super_block *sb);
916 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock);
917 void ll_dir_clear_lsm_md(struct inode *inode);
918 void ll_clear_inode(struct inode *inode);
919 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr, bool hsm_import);
920 int ll_setattr(struct dentry *de, struct iattr *attr);
921 int ll_statfs(struct dentry *de, struct kstatfs *sfs);
922 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
923 __u64 max_age, __u32 flags);
924 int ll_update_inode(struct inode *inode, struct lustre_md *md);
925 int ll_read_inode2(struct inode *inode, void *opaque);
926 void ll_delete_inode(struct inode *inode);
927 int ll_iocontrol(struct inode *inode, struct file *file,
928 unsigned int cmd, unsigned long arg);
929 int ll_flush_ctx(struct inode *inode);
930 void ll_umount_begin(struct super_block *sb);
931 int ll_remount_fs(struct super_block *sb, int *flags, char *data);
932 #ifdef HAVE_SUPEROPS_USE_DENTRY
933 int ll_show_options(struct seq_file *seq, struct dentry *dentry);
935 int ll_show_options(struct seq_file *seq, struct vfsmount *vfs);
937 void ll_dirty_page_discard_warn(struct page *page, int ioret);
938 int ll_prep_inode(struct inode **inode, struct ptlrpc_request *req,
939 struct super_block *, struct lookup_intent *);
940 void lustre_dump_dentry(struct dentry *, int recur);
941 int ll_obd_statfs(struct inode *inode, void __user *arg);
942 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *max_mdsize);
943 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *default_mdsize);
944 int ll_set_default_mdsize(struct ll_sb_info *sbi, int default_mdsize);
945 int ll_process_config(struct lustre_cfg *lcfg);
948 LUSTRE_OPC_MKDIR = 0,
949 LUSTRE_OPC_SYMLINK = 1,
950 LUSTRE_OPC_MKNOD = 2,
951 LUSTRE_OPC_CREATE = 3,
955 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
956 struct inode *i1, struct inode *i2,
957 const char *name, size_t namelen,
958 __u32 mode, __u32 opc, void *data);
959 void ll_finish_md_op_data(struct md_op_data *op_data);
960 int ll_get_obd_name(struct inode *inode, unsigned int cmd, unsigned long arg);
961 char *ll_get_fsname(struct super_block *sb, char *buf, int buflen);
962 void ll_compute_rootsquash_state(struct ll_sb_info *sbi);
963 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
964 struct lov_user_md **kbuf);
965 void ll_open_cleanup(struct super_block *sb, struct ptlrpc_request *open_req);
967 /* Compute expected user md size when passing in a md from user space */
968 static inline ssize_t ll_lov_user_md_size(const struct lov_user_md *lum)
970 switch (lum->lmm_magic) {
971 case LOV_USER_MAGIC_V1:
972 return sizeof(struct lov_user_md_v1);
973 case LOV_USER_MAGIC_V3:
974 return sizeof(struct lov_user_md_v3);
975 case LOV_USER_MAGIC_SPECIFIC:
976 if (lum->lmm_stripe_count > LOV_MAX_STRIPE_COUNT)
979 return lov_user_md_size(lum->lmm_stripe_count,
980 LOV_USER_MAGIC_SPECIFIC);
986 /* llite/llite_nfs.c */
987 extern struct export_operations lustre_export_operations;
988 __u32 get_uuid2int(const char *name, int len);
989 struct inode *search_inode_for_lustre(struct super_block *sb,
990 const struct lu_fid *fid);
991 int ll_dir_get_parent_fid(struct inode *dir, struct lu_fid *parent_fid);
993 /* llite/symlink.c */
994 extern struct inode_operations ll_fast_symlink_inode_operations;
997 * IO arguments for various VFS I/O interfaces.
1000 /** normal/sendfile/splice */
1001 enum vvp_io_subtype via_io_subtype;
1005 struct kiocb *via_iocb;
1006 struct iov_iter *via_iter;
1009 struct pipe_inode_info *via_pipe;
1010 unsigned int via_flags;
1020 struct ll_cl_context {
1021 struct list_head lcc_list;
1023 const struct lu_env *lcc_env;
1024 struct cl_io *lcc_io;
1025 struct cl_page *lcc_page;
1026 enum lcc_type lcc_type;
1029 struct ll_thread_info {
1030 struct iov_iter lti_iter;
1031 struct vvp_io_args lti_args;
1032 struct ra_io_arg lti_ria;
1033 struct kiocb lti_kiocb;
1034 struct ll_cl_context lti_io_ctx;
1037 extern struct lu_context_key ll_thread_key;
1039 static inline struct ll_thread_info *ll_env_info(const struct lu_env *env)
1041 struct ll_thread_info *lti;
1043 lti = lu_context_key_get(&env->le_ctx, &ll_thread_key);
1044 LASSERT(lti != NULL);
1049 static inline struct vvp_io_args *ll_env_args(const struct lu_env *env,
1050 enum vvp_io_subtype type)
1052 struct vvp_io_args *via = &ll_env_info(env)->lti_args;
1054 via->via_io_subtype = type;
1059 /* llite/llite_mmap.c */
1061 int ll_teardown_mmaps(struct address_space *mapping, __u64 first, __u64 last);
1062 int ll_file_mmap(struct file * file, struct vm_area_struct * vma);
1063 void policy_from_vma(union ldlm_policy_data *policy, struct vm_area_struct *vma,
1064 unsigned long addr, size_t count);
1065 struct vm_area_struct *our_vma(struct mm_struct *mm, unsigned long addr,
1068 static inline void ll_invalidate_page(struct page *vmpage)
1070 struct address_space *mapping = vmpage->mapping;
1071 loff_t offset = vmpage->index << PAGE_CACHE_SHIFT;
1073 LASSERT(PageLocked(vmpage));
1074 if (mapping == NULL)
1078 * truncate_complete_page() calls
1079 * a_ops->invalidatepage()->cl_page_delete()->vvp_page_delete().
1081 ll_teardown_mmaps(mapping, offset, offset + PAGE_CACHE_SIZE);
1082 truncate_complete_page(mapping, vmpage);
1085 #define ll_s2sbi(sb) (s2lsi(sb)->lsi_llsbi)
1087 /* don't need an addref as the sb_info should be holding one */
1088 static inline struct obd_export *ll_s2dtexp(struct super_block *sb)
1090 return ll_s2sbi(sb)->ll_dt_exp;
1093 /* don't need an addref as the sb_info should be holding one */
1094 static inline struct obd_export *ll_s2mdexp(struct super_block *sb)
1096 return ll_s2sbi(sb)->ll_md_exp;
1099 static inline struct client_obd *sbi2mdc(struct ll_sb_info *sbi)
1101 struct obd_device *obd = sbi->ll_md_exp->exp_obd;
1107 // FIXME: replace the name of this with LL_SB to conform to kernel stuff
1108 static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
1110 return ll_s2sbi(inode->i_sb);
1113 static inline struct obd_export *ll_i2dtexp(struct inode *inode)
1115 return ll_s2dtexp(inode->i_sb);
1118 static inline struct obd_export *ll_i2mdexp(struct inode *inode)
1120 return ll_s2mdexp(inode->i_sb);
1123 static inline struct lu_fid *ll_inode2fid(struct inode *inode)
1127 LASSERT(inode != NULL);
1128 fid = &ll_i2info(inode)->lli_fid;
1133 static inline loff_t ll_file_maxbytes(struct inode *inode)
1135 struct cl_object *obj = ll_i2info(inode)->lli_clob;
1138 return MAX_LFS_FILESIZE;
1140 return min_t(loff_t, cl_object_maxbytes(obj), MAX_LFS_FILESIZE);
1144 int ll_setxattr(struct dentry *dentry, const char *name,
1145 const void *value, size_t size, int flags);
1146 ssize_t ll_getxattr(struct dentry *dentry, const char *name,
1147 void *buffer, size_t size);
1148 ssize_t ll_listxattr(struct dentry *dentry, char *buffer, size_t size);
1149 int ll_removexattr(struct dentry *dentry, const char *name);
1151 /* llite/remote_perm.c */
1152 extern struct kmem_cache *ll_remote_perm_cachep;
1153 extern struct kmem_cache *ll_rmtperm_hash_cachep;
1155 void free_rmtperm_hash(struct hlist_head *hash);
1156 int ll_update_remote_perm(struct inode *inode, struct mdt_remote_perm *perm);
1157 int lustre_check_remote_perm(struct inode *inode, int mask);
1160 * Common IO arguments for various VFS I/O interfaces.
1162 int cl_sb_init(struct super_block *sb);
1163 int cl_sb_fini(struct super_block *sb);
1165 enum ras_update_flags {
1169 void ll_ra_count_put(struct ll_sb_info *sbi, unsigned long len);
1170 void ll_ra_stats_inc(struct inode *inode, enum ra_stat which);
1172 /* llite/llite_rmtacl.c */
1173 #ifdef CONFIG_FS_POSIX_ACL
1174 u64 rce_ops2valid(int ops);
1175 struct rmtacl_ctl_entry *rct_search(struct rmtacl_ctl_table *rct, pid_t key);
1176 int rct_add(struct rmtacl_ctl_table *rct, pid_t key, int ops);
1177 int rct_del(struct rmtacl_ctl_table *rct, pid_t key);
1178 void rct_init(struct rmtacl_ctl_table *rct);
1179 void rct_fini(struct rmtacl_ctl_table *rct);
1181 void ee_free(struct eacl_entry *ee);
1182 int ee_add(struct eacl_table *et, pid_t key, struct lu_fid *fid, int type,
1183 ext_acl_xattr_header *header);
1184 struct eacl_entry *et_search_del(struct eacl_table *et, pid_t key,
1185 struct lu_fid *fid, int type);
1186 void et_search_free(struct eacl_table *et, pid_t key);
1187 void et_init(struct eacl_table *et);
1188 void et_fini(struct eacl_table *et);
1193 #define LL_SA_RPC_MIN 2
1194 #define LL_SA_RPC_DEF 32
1195 #define LL_SA_RPC_MAX 8192
1197 #define LL_SA_CACHE_BIT 5
1198 #define LL_SA_CACHE_SIZE (1 << LL_SA_CACHE_BIT)
1199 #define LL_SA_CACHE_MASK (LL_SA_CACHE_SIZE - 1)
1201 /* per inode struct, for dir only */
1202 struct ll_statahead_info {
1203 struct dentry *sai_dentry;
1204 atomic_t sai_refcount; /* when access this struct, hold
1206 unsigned int sai_max; /* max ahead of lookup */
1207 __u64 sai_sent; /* stat requests sent count */
1208 __u64 sai_replied; /* stat requests which received
1210 __u64 sai_index; /* index of statahead entry */
1211 __u64 sai_index_wait; /* index of entry which is the
1212 * caller is waiting for */
1213 __u64 sai_hit; /* hit count */
1214 __u64 sai_miss; /* miss count:
1215 * for "ls -al" case, includes
1216 * hidden dentry miss;
1217 * for "ls -l" case, it does not
1218 * include hidden dentry miss.
1219 * "sai_miss_hidden" is used for
1222 unsigned int sai_consecutive_miss; /* consecutive miss */
1223 unsigned int sai_miss_hidden;/* "ls -al", but first dentry
1224 * is not a hidden one */
1225 unsigned int sai_skip_hidden;/* skipped hidden dentry count
1227 unsigned int sai_ls_all:1, /* "ls -al", do stat-ahead for
1229 sai_agl_valid:1,/* AGL is valid for the dir */
1230 sai_in_readpage:1;/* statahead is in readdir()*/
1231 wait_queue_head_t sai_waitq; /* stat-ahead wait queue */
1232 struct ptlrpc_thread sai_thread; /* stat-ahead thread */
1233 struct ptlrpc_thread sai_agl_thread; /* AGL thread */
1234 struct list_head sai_interim_entries; /* entries which got async
1235 * stat reply, but not
1237 struct list_head sai_entries; /* completed entries */
1238 struct list_head sai_agls; /* AGLs to be sent */
1239 struct list_head sai_cache[LL_SA_CACHE_SIZE];
1240 spinlock_t sai_cache_lock[LL_SA_CACHE_SIZE];
1241 atomic_t sai_cache_count; /* entry count in cache */
1244 int ll_statahead(struct inode *dir, struct dentry **dentry, bool unplug);
1245 void ll_authorize_statahead(struct inode *dir, void *key);
1246 void ll_deauthorize_statahead(struct inode *dir, void *key);
1249 blkcnt_t dirty_cnt(struct inode *inode);
1251 int cl_glimpse_size0(struct inode *inode, int agl);
1252 int cl_glimpse_lock(const struct lu_env *env, struct cl_io *io,
1253 struct inode *inode, struct cl_object *clob, int agl);
1255 static inline int cl_glimpse_size(struct inode *inode)
1257 return cl_glimpse_size0(inode, 0);
1260 static inline int cl_agl(struct inode *inode)
1262 return cl_glimpse_size0(inode, 1);
1265 static inline int ll_glimpse_size(struct inode *inode)
1267 struct ll_inode_info *lli = ll_i2info(inode);
1270 down_read(&lli->lli_glimpse_sem);
1271 rc = cl_glimpse_size(inode);
1272 lli->lli_glimpse_time = cfs_time_current();
1273 up_read(&lli->lli_glimpse_sem);
1277 /* dentry may statahead when statahead is enabled and current process has opened
1278 * parent directory, and this dentry hasn't accessed statahead cache before */
1280 dentry_may_statahead(struct inode *dir, struct dentry *dentry)
1282 struct ll_inode_info *lli;
1283 struct ll_dentry_data *ldd;
1285 if (ll_i2sbi(dir)->ll_sa_max == 0)
1288 lli = ll_i2info(dir);
1290 /* statahead is not allowed for this dir, there may be three causes:
1291 * 1. dir is not opened.
1292 * 2. statahead hit ratio is too low.
1293 * 3. previous stat started statahead thread failed. */
1294 if (!lli->lli_sa_enabled)
1297 /* not the same process, don't statahead */
1298 if (lli->lli_opendir_pid != current_pid())
1302 * When stating a dentry, kernel may trigger 'revalidate' or 'lookup'
1303 * multiple times, eg. for 'getattr', 'getxattr' and etc.
1304 * For patchless client, lookup intent is not accurate, which may
1305 * misguide statahead. For example:
1306 * The 'revalidate' call for 'getattr' and 'getxattr' of a dentry will
1307 * have the same intent -- IT_GETATTR, while one dentry should access
1308 * statahead cache once, otherwise statahead windows is messed up.
1309 * The solution is as following:
1310 * Assign 'lld_sa_generation' with 'lli_sa_generation' when a dentry
1311 * IT_GETATTR for the first time, and subsequent IT_GETATTR will
1312 * bypass interacting with statahead cache by checking
1313 * 'lld_sa_generation == lli->lli_sa_generation'.
1315 ldd = ll_d2d(dentry);
1316 if (ldd != NULL && ldd->lld_sa_generation == lli->lli_sa_generation)
1322 /* llite ioctl register support rountine */
1328 #define LLIOC_MAX_CMD 256
1331 * Rules to write a callback function:
1334 * @magic: Dynamic ioctl call routine will feed this vaule with the pointer
1335 * returned to ll_iocontrol_register. Callback functions should use this
1336 * data to check the potential collasion of ioctl cmd. If collasion is
1337 * found, callback function should return LLIOC_CONT.
1338 * @rcp: The result of ioctl command.
1341 * If @magic matches the pointer returned by ll_iocontrol_data, the
1342 * callback should return LLIOC_STOP; return LLIOC_STOP otherwise.
1344 typedef enum llioc_iter (*llioc_callback_t)(struct inode *inode,
1345 struct file *file, unsigned int cmd, unsigned long arg,
1346 void *magic, int *rcp);
1348 /* export functions */
1349 /* Register ioctl block dynamatically for a regular file.
1351 * @cmd: the array of ioctl command set
1352 * @count: number of commands in the @cmd
1353 * @cb: callback function, it will be called if an ioctl command is found to
1354 * belong to the command list @cmd.
1357 * A magic pointer will be returned if success;
1358 * otherwise, NULL will be returned.
1360 void *ll_iocontrol_register(llioc_callback_t cb, int count, unsigned int *cmd);
1361 void ll_iocontrol_unregister(void *magic);
1363 int cl_sync_file_range(struct inode *inode, loff_t start, loff_t end,
1364 enum cl_fsync_mode mode, int ignore_layout);
1366 /** direct write pages */
1367 struct ll_dio_pages {
1368 /** page array to be written. we don't support
1369 * partial pages except the last one. */
1370 struct page **ldp_pages;
1371 /* offset of each page */
1372 loff_t *ldp_offsets;
1373 /** if ldp_offsets is NULL, it means a sequential
1374 * pages to be written, then this is the file offset
1375 * of the * first page. */
1376 loff_t ldp_start_offset;
1377 /** how many bytes are to be written. */
1379 /** # of pages in the array. */
1383 extern ssize_t ll_direct_rw_pages(const struct lu_env *env, struct cl_io *io,
1384 int rw, struct inode *inode,
1385 struct ll_dio_pages *pv);
1387 static inline int ll_file_nolock(const struct file *file)
1389 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1390 struct inode *inode = file->f_path.dentry->d_inode;
1392 LASSERT(fd != NULL);
1393 return ((fd->fd_flags & LL_FILE_IGNORE_LOCK) ||
1394 (ll_i2sbi(inode)->ll_flags & LL_SBI_NOLCK));
1397 static inline void ll_set_lock_data(struct obd_export *exp, struct inode *inode,
1398 struct lookup_intent *it, __u64 *bits)
1400 if (!it->it_lock_set) {
1401 struct lustre_handle handle;
1403 /* If this inode is a remote object, it will get two
1404 * separate locks in different namespaces, Master MDT,
1405 * where the name entry is, will grant LOOKUP lock,
1406 * remote MDT, where the object is, will grant
1407 * UPDATE|PERM lock. The inode will be attched to both
1408 * LOOKUP and PERM locks, so revoking either locks will
1409 * case the dcache being cleared */
1410 if (it->it_remote_lock_mode) {
1411 handle.cookie = it->it_remote_lock_handle;
1412 CDEBUG(D_DLMTRACE, "setting l_data to inode "DFID
1413 "(%p) for remote lock "LPX64"\n",
1414 PFID(ll_inode2fid(inode)), inode,
1416 md_set_lock_data(exp, &handle.cookie, inode, NULL);
1419 handle.cookie = it->it_lock_handle;
1421 CDEBUG(D_DLMTRACE, "setting l_data to inode "DFID"(%p)"
1422 " for lock "LPX64"\n",
1423 PFID(ll_inode2fid(inode)), inode, handle.cookie);
1425 md_set_lock_data(exp, &handle.cookie, inode,
1427 it->it_lock_set = 1;
1431 *bits = it->it_lock_bits;
1434 static inline void ll_lock_dcache(struct inode *inode)
1436 #ifdef HAVE_DCACHE_LOCK
1437 spin_lock(&dcache_lock);
1439 spin_lock(&inode->i_lock);
1443 static inline void ll_unlock_dcache(struct inode *inode)
1445 #ifdef HAVE_DCACHE_LOCK
1446 spin_unlock(&dcache_lock);
1448 spin_unlock(&inode->i_lock);
1452 static inline int d_lustre_invalid(const struct dentry *dentry)
1454 struct ll_dentry_data *lld = ll_d2d(dentry);
1456 return (lld == NULL) || lld->lld_invalid;
1459 static inline void __d_lustre_invalidate(struct dentry *dentry)
1461 struct ll_dentry_data *lld = ll_d2d(dentry);
1464 lld->lld_invalid = 1;
1468 * Mark dentry INVALID, if dentry refcount is zero (this is normally case for
1469 * ll_md_blocking_ast), unhash this dentry, and let dcache to reclaim it later;
1470 * else dput() of the last refcount will unhash this dentry and kill it.
1472 static inline void d_lustre_invalidate(struct dentry *dentry, int nested)
1474 CDEBUG(D_DENTRY, "invalidate dentry %.*s (%p) parent %p inode %p "
1475 "refc %d\n", dentry->d_name.len, dentry->d_name.name, dentry,
1476 dentry->d_parent, dentry->d_inode, ll_d_count(dentry));
1478 spin_lock_nested(&dentry->d_lock,
1479 nested ? DENTRY_D_LOCK_NESTED : DENTRY_D_LOCK_NORMAL);
1480 __d_lustre_invalidate(dentry);
1482 * We should be careful about dentries created by d_obtain_alias().
1483 * These dentries are not put in the dentry tree, instead they are
1484 * linked to sb->s_anon through dentry->d_hash.
1485 * shrink_dcache_for_umount() shrinks the tree and sb->s_anon list.
1486 * If we unhashed such a dentry, unmount would not be able to find
1487 * it and busy inodes would be reported.
1489 if (ll_d_count(dentry) == 0 && !(dentry->d_flags & DCACHE_DISCONNECTED))
1491 spin_unlock(&dentry->d_lock);
1494 static inline void d_lustre_revalidate(struct dentry *dentry)
1496 spin_lock(&dentry->d_lock);
1497 LASSERT(ll_d2d(dentry) != NULL);
1498 ll_d2d(dentry)->lld_invalid = 0;
1499 spin_unlock(&dentry->d_lock);
1502 int ll_layout_conf(struct inode *inode, const struct cl_object_conf *conf);
1503 int ll_layout_refresh(struct inode *inode, __u32 *gen);
1504 int ll_layout_restore(struct inode *inode, loff_t start, __u64 length);
1506 int ll_xattr_init(void);
1507 void ll_xattr_fini(void);
1509 int ll_getxattr_common(struct inode *inode, const char *name,
1510 void *buffer, size_t size, __u64 valid);
1511 int ll_page_sync_io(const struct lu_env *env, struct cl_io *io,
1512 struct cl_page *page, enum cl_req_type crt);
1514 int ll_getparent(struct file *file, struct getparent __user *arg);
1517 int cl_setattr_ost(struct cl_object *obj, const struct iattr *attr,
1518 unsigned int attr_flags);
1520 extern struct lu_env *cl_inode_fini_env;
1521 extern __u16 cl_inode_fini_refcheck;
1523 int cl_file_inode_init(struct inode *inode, struct lustre_md *md);
1524 void cl_inode_fini(struct inode *inode);
1526 u64 cl_fid_build_ino(const struct lu_fid *fid, int api32);
1527 u32 cl_fid_build_gen(const struct lu_fid *fid);
1529 #ifndef HAVE_FILE_INODE
1530 static inline struct inode *file_inode(struct file *file)
1532 return file->f_path.dentry->d_inode;
1536 #ifndef HAVE_IOV_ITER_TRUNCATE
1537 static inline void iov_iter_truncate(struct iov_iter *i, u64 count)
1539 if (i->count > count)
1544 #ifndef HAVE_FILE_OPERATIONS_READ_WRITE_ITER
1545 static inline void iov_iter_reexpand(struct iov_iter *i, size_t count)
1550 static inline struct iovec iov_iter_iovec(const struct iov_iter *iter)
1552 return (struct iovec) {
1553 .iov_base = iter->iov->iov_base + iter->iov_offset,
1554 .iov_len = min(iter->count,
1555 iter->iov->iov_len - iter->iov_offset),
1559 #define iov_for_each(iov, iter, start) \
1560 for (iter = (start); \
1561 (iter).count && ((iov = iov_iter_iovec(&(iter))), 1); \
1562 iov_iter_advance(&(iter), (iov).iov_len))
1564 static inline ssize_t
1565 generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
1571 iov_for_each(iov, i, *iter) {
1574 res = generic_file_aio_read(iocb, &iov, 1, iocb->ki_pos);
1582 if (res < iov.iov_len)
1587 iov_iter_advance(iter, bytes);
1591 static inline ssize_t
1592 generic_file_write_iter(struct kiocb *iocb, struct iov_iter *iter)
1598 iov_for_each(iov, i, *iter) {
1601 res = __generic_file_aio_write(iocb, &iov, 1, &iocb->ki_pos);
1609 if (res < iov.iov_len)
1614 iov_iter_advance(iter, bytes);
1617 #endif /* HAVE_FILE_OPERATIONS_READ_WRITE_ITER */
1618 #endif /* LLITE_INTERNAL_H */