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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2015, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
33 #ifndef LLITE_INTERNAL_H
34 #define LLITE_INTERNAL_H
35 #include "../include/lustre_debug.h"
36 #include "../include/lustre_ver.h"
37 #include "../include/lustre_disk.h" /* for s2sbi */
38 #include "../include/lustre_eacl.h"
40 /* for struct cl_lock_descr and struct cl_io */
41 #include "../include/cl_object.h"
42 #include "../include/lustre_mdc.h"
43 #include "../include/lustre_intent.h"
44 #include <linux/compat.h>
45 #include <linux/posix_acl_xattr.h>
46 #include "vvp_internal.h"
52 #ifndef VM_FAULT_RETRY
53 #define VM_FAULT_RETRY 0
56 /** Only used on client-side for indicating the tail of dir hash/offset. */
57 #define LL_DIR_END_OFF 0x7fffffffffffffffULL
58 #define LL_DIR_END_OFF_32BIT 0x7fffffffUL
60 #define LL_IT2STR(it) ((it) ? ldlm_it2str((it)->it_op) : "0")
61 #define LUSTRE_FPRIVATE(file) ((file)->private_data)
63 struct ll_dentry_data {
64 struct lookup_intent *lld_it;
65 unsigned int lld_sa_generation;
66 unsigned int lld_invalid:1;
67 unsigned int lld_nfs_dentry:1;
68 struct rcu_head lld_rcu_head;
71 #define ll_d2d(de) ((struct ll_dentry_data *)((de)->d_fsdata))
73 #define LLI_INODE_MAGIC 0x111d0de5
74 #define LLI_INODE_DEAD 0xdeadd00d
76 struct ll_getname_data {
77 struct dir_context ctx;
78 char *lgd_name; /* points to a buffer with NAME_MAX+1 size */
79 struct lu_fid lgd_fid; /* target fid we are looking for */
80 int lgd_found; /* inode matched? */
84 struct lu_env *lg_env;
86 struct cl_lock *lg_lock;
91 /* MDS has an authority for the Size-on-MDS attributes. */
92 LLIF_MDS_SIZE_LOCK = (1 << 0),
93 /* Epoch close is postponed. */
94 LLIF_EPOCH_PENDING = (1 << 1),
95 /* DONE WRITING is allowed. */
96 LLIF_DONE_WRITING = (1 << 2),
97 /* Sizeon-on-MDS attributes are changed. An attribute update needs to
100 LLIF_SOM_DIRTY = (1 << 3),
101 /* File data is modified. */
102 LLIF_DATA_MODIFIED = (1 << 4),
103 /* File is being restored */
104 LLIF_FILE_RESTORING = (1 << 5),
105 /* Xattr cache is attached to the file */
106 LLIF_XATTR_CACHE = (1 << 6),
109 struct ll_inode_info {
110 __u32 lli_inode_magic;
115 struct posix_acl *lli_posix_acl;
117 /* identifying fields for both metadata and data stacks. */
118 struct lu_fid lli_fid;
119 /* Parent fid for accessing default stripe data on parent directory
120 * for allocating OST objects after a mknod() and later open-by-FID.
122 struct lu_fid lli_pfid;
124 struct list_head lli_close_list;
126 /* handle is to be sent to MDS later on done_writing and setattr.
127 * Open handle data are needed for the recovery to reconstruct
128 * the inode state on the MDS. XXX: recovery is not ready yet.
130 struct obd_client_handle *lli_pending_och;
132 /* We need all three because every inode may be opened in different
135 struct obd_client_handle *lli_mds_read_och;
136 struct obd_client_handle *lli_mds_write_och;
137 struct obd_client_handle *lli_mds_exec_och;
138 __u64 lli_open_fd_read_count;
139 __u64 lli_open_fd_write_count;
140 __u64 lli_open_fd_exec_count;
141 /* Protects access to och pointers and their usage counters */
142 struct mutex lli_och_mutex;
144 struct inode lli_vfs_inode;
146 /* the most recent timestamps obtained from mds */
150 spinlock_t lli_agl_lock;
152 /* Try to make the d::member and f::member are aligned. Before using
153 * these members, make clear whether it is directory or not.
158 /* serialize normal readdir and statahead-readdir. */
159 struct mutex d_readdir_mutex;
161 /* metadata statahead */
162 /* since parent-child threads can share the same @file
163 * struct, "opendir_key" is the token when dir close for
164 * case of parent exit before child -- it is me should
165 * cleanup the dir readahead.
168 struct ll_statahead_info *d_sai;
169 /* protect statahead stuff. */
170 spinlock_t d_sa_lock;
171 /* "opendir_pid" is the token when lookup/revalidate
172 * -- I am the owner of dir statahead.
177 #define lli_readdir_mutex u.d.d_readdir_mutex
178 #define lli_opendir_key u.d.d_opendir_key
179 #define lli_sai u.d.d_sai
180 #define lli_sa_lock u.d.d_sa_lock
181 #define lli_opendir_pid u.d.d_opendir_pid
183 /* for non-directory */
185 struct mutex f_size_mutex;
186 char *f_symlink_name;
189 * struct rw_semaphore {
190 * signed long count; // align d.d_def_acl
191 * spinlock_t wait_lock; // align d.d_sa_lock
192 * struct list_head wait_list;
195 struct rw_semaphore f_trunc_sem;
196 struct mutex f_write_mutex;
198 struct rw_semaphore f_glimpse_sem;
199 unsigned long f_glimpse_time;
200 struct list_head f_agl_list;
203 /* for writepage() only to communicate to fsync */
207 * whenever a process try to read/write the file, the
208 * jobid of the process will be saved here, and it'll
209 * be packed into the write PRC when flush later.
211 * so the read/write statistics for jobid will not be
212 * accurate if the file is shared by different jobs.
214 char f_jobid[JOBSTATS_JOBID_SIZE];
217 #define lli_size_mutex u.f.f_size_mutex
218 #define lli_symlink_name u.f.f_symlink_name
219 #define lli_maxbytes u.f.f_maxbytes
220 #define lli_trunc_sem u.f.f_trunc_sem
221 #define lli_write_mutex u.f.f_write_mutex
222 #define lli_glimpse_sem u.f.f_glimpse_sem
223 #define lli_glimpse_time u.f.f_glimpse_time
224 #define lli_agl_list u.f.f_agl_list
225 #define lli_agl_index u.f.f_agl_index
226 #define lli_async_rc u.f.f_async_rc
227 #define lli_jobid u.f.f_jobid
231 /* XXX: For following frequent used members, although they maybe special
232 * used for non-directory object, it is some time-wasting to check
233 * whether the object is directory or not before using them. On the
234 * other hand, currently, sizeof(f) > sizeof(d), it cannot reduce
235 * the "ll_inode_info" size even if moving those members into u.f.
236 * So keep them out side.
238 * In the future, if more members are added only for directory,
239 * some of the following members can be moved into u.f.
242 struct cl_object *lli_clob;
244 /* mutex to request for layout lock exclusively. */
245 struct mutex lli_layout_mutex;
246 /* Layout version, protected by lli_layout_lock */
247 __u32 lli_layout_gen;
248 spinlock_t lli_layout_lock;
250 struct rw_semaphore lli_xattrs_list_rwsem;
251 struct mutex lli_xattrs_enq_lock;
252 struct list_head lli_xattrs;/* ll_xattr_entry->xe_list */
255 static inline __u32 ll_layout_version_get(struct ll_inode_info *lli)
259 spin_lock(&lli->lli_layout_lock);
260 gen = lli->lli_layout_gen;
261 spin_unlock(&lli->lli_layout_lock);
266 static inline void ll_layout_version_set(struct ll_inode_info *lli, __u32 gen)
268 spin_lock(&lli->lli_layout_lock);
269 lli->lli_layout_gen = gen;
270 spin_unlock(&lli->lli_layout_lock);
273 int ll_xattr_cache_destroy(struct inode *inode);
275 int ll_xattr_cache_get(struct inode *inode, const char *name,
276 char *buffer, size_t size, __u64 valid);
279 * Locking to guarantee consistency of non-atomic updates to long long i_size,
280 * consistency between file size and KMS.
282 * Implemented by ->lli_size_mutex and ->lsm_lock, nested in that order.
285 void ll_inode_size_lock(struct inode *inode);
286 void ll_inode_size_unlock(struct inode *inode);
288 /* FIXME: replace the name of this with LL_I to conform to kernel stuff */
289 /* static inline struct ll_inode_info *LL_I(struct inode *inode) */
290 static inline struct ll_inode_info *ll_i2info(struct inode *inode)
292 return container_of(inode, struct ll_inode_info, lli_vfs_inode);
295 /* default to about 40meg of readahead on a given system. That much tied
296 * up in 512k readahead requests serviced at 40ms each is about 1GB/s.
298 #define SBI_DEFAULT_READAHEAD_MAX (40UL << (20 - PAGE_SHIFT))
300 /* default to read-ahead full files smaller than 2MB on the second read */
301 #define SBI_DEFAULT_READAHEAD_WHOLE_MAX (2UL << (20 - PAGE_SHIFT))
306 RA_STAT_DISTANT_READPAGE,
307 RA_STAT_MISS_IN_WINDOW,
308 RA_STAT_FAILED_GRAB_PAGE,
309 RA_STAT_FAILED_MATCH,
314 RA_STAT_MAX_IN_FLIGHT,
315 RA_STAT_WRONG_GRAB_PAGE,
316 RA_STAT_FAILED_REACH_END,
321 atomic_t ra_cur_pages;
322 unsigned long ra_max_pages;
323 unsigned long ra_max_pages_per_file;
324 unsigned long ra_max_read_ahead_whole_pages;
327 /* ra_io_arg will be filled in the beginning of ll_readahead with
328 * ras_lock, then the following ll_read_ahead_pages will read RA
329 * pages according to this arg, all the items in this structure are
330 * counted by page index.
333 unsigned long ria_start; /* start offset of read-ahead*/
334 unsigned long ria_end; /* end offset of read-ahead*/
335 /* If stride read pattern is detected, ria_stoff means where
336 * stride read is started. Note: for normal read-ahead, the
337 * value here is meaningless, and also it will not be accessed
340 /* ria_length and ria_pages are the length and pages length in the
341 * stride I/O mode. And they will also be used to check whether
342 * it is stride I/O read-ahead in the read-ahead pages
344 unsigned long ria_length;
345 unsigned long ria_pages;
348 /* LL_HIST_MAX=32 causes an overflow */
349 #define LL_HIST_MAX 28
350 #define LL_HIST_START 12 /* buckets start at 2^12 = 4k */
351 #define LL_PROCESS_HIST_MAX 10
352 struct per_process_info {
354 struct obd_histogram pp_r_hist;
355 struct obd_histogram pp_w_hist;
358 /* pp_extents[LL_PROCESS_HIST_MAX] will hold the combined process info */
359 struct ll_rw_extents_info {
360 struct per_process_info pp_extents[LL_PROCESS_HIST_MAX + 1];
363 #define LL_OFFSET_HIST_MAX 100
364 struct ll_rw_process_info {
367 loff_t rw_range_start;
369 loff_t rw_last_file_pos;
371 size_t rw_smallest_extent;
372 size_t rw_largest_extent;
373 struct ll_file_data *rw_last_file;
376 enum stats_track_type {
377 STATS_TRACK_ALL = 0, /* track all processes */
378 STATS_TRACK_PID, /* track process with this pid */
379 STATS_TRACK_PPID, /* track processes with this ppid */
380 STATS_TRACK_GID, /* track processes with this gid */
384 /* flags for sbi->ll_flags */
385 #define LL_SBI_NOLCK 0x01 /* DLM locking disabled (directio-only) */
386 #define LL_SBI_CHECKSUM 0x02 /* checksum each page as it's written */
387 #define LL_SBI_FLOCK 0x04
388 #define LL_SBI_USER_XATTR 0x08 /* support user xattr */
389 #define LL_SBI_ACL 0x10 /* support ACL */
390 /* LL_SBI_RMT_CLIENT 0x40 remote client */
391 #define LL_SBI_MDS_CAPA 0x80 /* support mds capa, obsolete */
392 #define LL_SBI_OSS_CAPA 0x100 /* support oss capa, obsolete */
393 #define LL_SBI_LOCALFLOCK 0x200 /* Local flocks support by kernel */
394 #define LL_SBI_LRU_RESIZE 0x400 /* lru resize support */
395 #define LL_SBI_LAZYSTATFS 0x800 /* lazystatfs mount option */
396 #define LL_SBI_SOM_PREVIEW 0x1000 /* SOM preview mount option */
397 #define LL_SBI_32BIT_API 0x2000 /* generate 32 bit inodes. */
398 #define LL_SBI_64BIT_HASH 0x4000 /* support 64-bits dir hash/offset */
399 #define LL_SBI_AGL_ENABLED 0x8000 /* enable agl */
400 #define LL_SBI_VERBOSE 0x10000 /* verbose mount/umount */
401 #define LL_SBI_LAYOUT_LOCK 0x20000 /* layout lock support */
402 #define LL_SBI_USER_FID2PATH 0x40000 /* allow fid2path by unprivileged users */
403 #define LL_SBI_XATTR_CACHE 0x80000 /* support for xattr cache */
405 #define LL_SBI_FLAGS { \
429 /* this protects pglist and ra_info. It isn't safe to
430 * grab from interrupt contexts
433 spinlock_t ll_pp_extent_lock; /* pp_extent entry*/
434 spinlock_t ll_process_lock; /* ll_rw_process_info */
435 struct obd_uuid ll_sb_uuid;
436 struct obd_export *ll_md_exp;
437 struct obd_export *ll_dt_exp;
438 struct dentry *ll_debugfs_entry;
439 struct lu_fid ll_root_fid; /* root object fid */
442 unsigned int ll_umounting:1,
443 ll_xattr_cache_enabled:1;
444 struct lustre_client_ocd ll_lco;
446 struct ll_close_queue *ll_lcq;
448 struct lprocfs_stats *ll_stats; /* lprocfs stats counter */
451 * Used to track "unstable" pages on a client, and maintain a
452 * LRU list of clean pages. An "unstable" page is defined as
453 * any page which is sent to a server as part of a bulk request,
454 * but is uncommitted to stable storage.
456 struct cl_client_cache *ll_cache;
458 struct lprocfs_stats *ll_ra_stats;
460 struct ll_ra_info ll_ra_info;
461 unsigned int ll_namelen;
462 struct file_operations *ll_fop;
464 unsigned int ll_md_brw_size; /* used by readdir */
466 struct lu_site *ll_site;
467 struct cl_device *ll_cl;
469 struct ll_rw_extents_info ll_rw_extents_info;
470 int ll_extent_process_count;
471 struct ll_rw_process_info ll_rw_process_info[LL_PROCESS_HIST_MAX];
472 unsigned int ll_offset_process_count;
473 struct ll_rw_process_info ll_rw_offset_info[LL_OFFSET_HIST_MAX];
474 unsigned int ll_rw_offset_entry_count;
475 int ll_stats_track_id;
476 enum stats_track_type ll_stats_track_type;
479 /* metadata stat-ahead */
480 unsigned int ll_sa_max; /* max statahead RPCs */
481 atomic_t ll_sa_total; /* statahead thread started
484 atomic_t ll_sa_wrong; /* statahead thread stopped for
487 atomic_t ll_agl_total; /* AGL thread started count */
489 dev_t ll_sdev_orig; /* save s_dev before assign for
492 __kernel_fsid_t ll_fsid;
493 struct kobject ll_kobj; /* sysfs object */
494 struct super_block *ll_sb; /* struct super_block (for sysfs code)*/
495 struct completion ll_kobj_unregister;
499 * per file-descriptor read-ahead data.
501 struct ll_readahead_state {
504 * index of the last page that read(2) needed and that wasn't in the
505 * cache. Used by ras_update() to detect seeks.
507 * XXX nikita: if access seeks into cached region, Lustre doesn't see
510 unsigned long ras_last_readpage;
512 * number of pages read after last read-ahead window reset. As window
513 * is reset on each seek, this is effectively a number of consecutive
514 * accesses. Maybe ->ras_accessed_in_window is better name.
516 * XXX nikita: window is also reset (by ras_update()) when Lustre
517 * believes that memory pressure evicts read-ahead pages. In that
518 * case, it probably doesn't make sense to expand window to
519 * PTLRPC_MAX_BRW_PAGES on the third access.
521 unsigned long ras_consecutive_pages;
523 * number of read requests after the last read-ahead window reset
524 * As window is reset on each seek, this is effectively the number
525 * on consecutive read request and is used to trigger read-ahead.
527 unsigned long ras_consecutive_requests;
529 * Parameters of current read-ahead window. Handled by
530 * ras_update(). On the initial access to the file or after a seek,
531 * window is reset to 0. After 3 consecutive accesses, window is
532 * expanded to PTLRPC_MAX_BRW_PAGES. Afterwards, window is enlarged by
533 * PTLRPC_MAX_BRW_PAGES chunks up to ->ra_max_pages.
535 unsigned long ras_window_start, ras_window_len;
537 * Where next read-ahead should start at. This lies within read-ahead
538 * window. Read-ahead window is read in pieces rather than at once
539 * because: 1. lustre limits total number of pages under read-ahead by
540 * ->ra_max_pages (see ll_ra_count_get()), 2. client cannot read pages
541 * not covered by DLM lock.
543 unsigned long ras_next_readahead;
545 * Total number of ll_file_read requests issued, reads originating
546 * due to mmap are not counted in this total. This value is used to
547 * trigger full file read-ahead after multiple reads to a small file.
549 unsigned long ras_requests;
551 * Page index with respect to the current request, these value
552 * will not be accurate when dealing with reads issued via mmap.
554 unsigned long ras_request_index;
556 * The following 3 items are used for detecting the stride I/O
558 * In stride I/O mode,
559 * ...............|-----data-----|****gap*****|--------|******|....
560 * offset |-stride_pages-|-stride_gap-|
561 * ras_stride_offset = offset;
562 * ras_stride_length = stride_pages + stride_gap;
563 * ras_stride_pages = stride_pages;
564 * Note: all these three items are counted by pages.
566 unsigned long ras_stride_length;
567 unsigned long ras_stride_pages;
568 pgoff_t ras_stride_offset;
570 * number of consecutive stride request count, and it is similar as
571 * ras_consecutive_requests, but used for stride I/O mode.
572 * Note: only more than 2 consecutive stride request are detected,
573 * stride read-ahead will be enable
575 unsigned long ras_consecutive_stride_requests;
578 extern struct kmem_cache *ll_file_data_slab;
579 struct lustre_handle;
580 struct ll_file_data {
581 struct ll_readahead_state fd_ras;
582 struct ll_grouplock fd_grouplock;
586 /* openhandle if lease exists for this file.
587 * Borrow lli->lli_och_mutex to protect assignment
589 struct obd_client_handle *fd_lease_och;
590 struct obd_client_handle *fd_och;
591 struct file *fd_file;
592 /* Indicate whether need to report failure when close.
593 * true: failure is known, not report again.
594 * false: unknown failure, should report.
596 bool fd_write_failed;
597 rwlock_t fd_lock; /* protect lcc list */
598 struct list_head fd_lccs; /* list of ll_cl_context */
601 struct lov_stripe_md;
603 extern struct dentry *llite_root;
604 extern struct kset *llite_kset;
606 static inline struct inode *ll_info2i(struct ll_inode_info *lli)
608 return &lli->lli_vfs_inode;
611 __u32 ll_i2suppgid(struct inode *i);
612 void ll_i2gids(__u32 *suppgids, struct inode *i1, struct inode *i2);
614 static inline int ll_need_32bit_api(struct ll_sb_info *sbi)
616 #if BITS_PER_LONG == 32
618 #elif defined(CONFIG_COMPAT)
619 return unlikely(in_compat_syscall() || (sbi->ll_flags & LL_SBI_32BIT_API));
621 return unlikely(sbi->ll_flags & LL_SBI_32BIT_API);
625 void ll_ras_enter(struct file *f);
627 /* llite/lcommon_misc.c */
628 int cl_init_ea_size(struct obd_export *md_exp, struct obd_export *dt_exp);
629 int cl_ocd_update(struct obd_device *host,
630 struct obd_device *watched,
631 enum obd_notify_event ev, void *owner, void *data);
632 int cl_get_grouplock(struct cl_object *obj, unsigned long gid, int nonblock,
633 struct ll_grouplock *cg);
634 void cl_put_grouplock(struct ll_grouplock *cg);
636 /* llite/lproc_llite.c */
637 int ldebugfs_register_mountpoint(struct dentry *parent,
638 struct super_block *sb, char *osc, char *mdc);
639 void ldebugfs_unregister_mountpoint(struct ll_sb_info *sbi);
640 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count);
641 void lprocfs_llite_init_vars(struct lprocfs_static_vars *lvars);
642 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
643 struct ll_file_data *file, loff_t pos,
644 size_t count, int rw);
647 void ll_release_page(struct page *page, int remove);
648 extern const struct file_operations ll_dir_operations;
649 extern const struct inode_operations ll_dir_inode_operations;
650 struct page *ll_get_dir_page(struct inode *dir, __u64 hash,
651 struct ll_dir_chain *chain);
652 int ll_dir_read(struct inode *inode, struct dir_context *ctx);
654 int ll_get_mdt_idx(struct inode *inode);
656 extern const struct inode_operations ll_special_inode_operations;
658 int ll_objects_destroy(struct ptlrpc_request *request,
660 struct inode *ll_iget(struct super_block *sb, ino_t hash,
661 struct lustre_md *lic);
662 int ll_md_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
663 void *data, int flag);
664 struct dentry *ll_splice_alias(struct inode *inode, struct dentry *de);
667 int ll_writepage(struct page *page, struct writeback_control *wbc);
668 int ll_writepages(struct address_space *, struct writeback_control *wbc);
669 int ll_readpage(struct file *file, struct page *page);
670 void ll_readahead_init(struct inode *inode, struct ll_readahead_state *ras);
671 int ll_readahead(const struct lu_env *env, struct cl_io *io,
672 struct cl_page_list *queue, struct ll_readahead_state *ras,
674 struct ll_cl_context *ll_cl_find(struct file *file);
675 void ll_cl_add(struct file *file, const struct lu_env *env, struct cl_io *io);
676 void ll_cl_remove(struct file *file, const struct lu_env *env);
678 extern const struct address_space_operations ll_aops;
681 extern struct file_operations ll_file_operations;
682 extern struct file_operations ll_file_operations_flock;
683 extern struct file_operations ll_file_operations_noflock;
684 extern const struct inode_operations ll_file_inode_operations;
685 int ll_have_md_lock(struct inode *inode, __u64 *bits,
686 enum ldlm_mode l_req_mode);
687 enum ldlm_mode ll_take_md_lock(struct inode *inode, __u64 bits,
688 struct lustre_handle *lockh, __u64 flags,
689 enum ldlm_mode mode);
690 int ll_file_open(struct inode *inode, struct file *file);
691 int ll_file_release(struct inode *inode, struct file *file);
692 int ll_glimpse_ioctl(struct ll_sb_info *sbi,
693 struct lov_stripe_md *lsm, lstat_t *st);
694 void ll_ioepoch_open(struct ll_inode_info *lli, __u64 ioepoch);
695 int ll_release_openhandle(struct inode *, struct lookup_intent *);
696 int ll_md_real_close(struct inode *inode, fmode_t fmode);
697 void ll_ioepoch_close(struct inode *inode, struct md_op_data *op_data,
698 struct obd_client_handle **och, unsigned long flags);
699 void ll_done_writing_attr(struct inode *inode, struct md_op_data *op_data);
700 int ll_som_update(struct inode *inode, struct md_op_data *op_data);
701 int ll_inode_getattr(struct inode *inode, struct obdo *obdo,
702 __u64 ioepoch, int sync);
703 void ll_pack_inode2opdata(struct inode *inode, struct md_op_data *op_data,
704 struct lustre_handle *fh);
705 int ll_getattr(struct vfsmount *mnt, struct dentry *de, struct kstat *stat);
706 struct posix_acl *ll_get_acl(struct inode *inode, int type);
708 int ll_inode_permission(struct inode *inode, int mask);
710 int ll_lov_setstripe_ea_info(struct inode *inode, struct dentry *dentry,
711 __u64 flags, struct lov_user_md *lum,
713 int ll_lov_getstripe_ea_info(struct inode *inode, const char *filename,
714 struct lov_mds_md **lmm, int *lmm_size,
715 struct ptlrpc_request **request);
716 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
718 int ll_dir_getstripe(struct inode *inode, struct lov_mds_md **lmmp,
719 int *lmm_size, struct ptlrpc_request **request);
720 int ll_fsync(struct file *file, loff_t start, loff_t end, int data);
721 int ll_merge_attr(const struct lu_env *env, struct inode *inode);
722 int ll_fid2path(struct inode *inode, void __user *arg);
723 int ll_data_version(struct inode *inode, __u64 *data_version, int flags);
724 int ll_hsm_release(struct inode *inode);
728 int ll_d_init(struct dentry *de);
729 extern const struct dentry_operations ll_d_ops;
730 void ll_intent_drop_lock(struct lookup_intent *);
731 void ll_intent_release(struct lookup_intent *);
732 void ll_invalidate_aliases(struct inode *);
733 void ll_lookup_finish_locks(struct lookup_intent *it, struct inode *inode);
734 int ll_revalidate_it_finish(struct ptlrpc_request *request,
735 struct lookup_intent *it, struct inode *inode);
737 /* llite/llite_lib.c */
738 extern struct super_operations lustre_super_operations;
740 void ll_lli_init(struct ll_inode_info *lli);
741 int ll_fill_super(struct super_block *sb, struct vfsmount *mnt);
742 void ll_put_super(struct super_block *sb);
743 void ll_kill_super(struct super_block *sb);
744 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock);
745 void ll_clear_inode(struct inode *inode);
746 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr, bool hsm_import);
747 int ll_setattr(struct dentry *de, struct iattr *attr);
748 int ll_statfs(struct dentry *de, struct kstatfs *sfs);
749 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
750 __u64 max_age, __u32 flags);
751 void ll_update_inode(struct inode *inode, struct lustre_md *md);
752 void ll_read_inode2(struct inode *inode, void *opaque);
753 void ll_delete_inode(struct inode *inode);
754 int ll_iocontrol(struct inode *inode, struct file *file,
755 unsigned int cmd, unsigned long arg);
756 int ll_flush_ctx(struct inode *inode);
757 void ll_umount_begin(struct super_block *sb);
758 int ll_remount_fs(struct super_block *sb, int *flags, char *data);
759 int ll_show_options(struct seq_file *seq, struct dentry *dentry);
760 void ll_dirty_page_discard_warn(struct page *page, int ioret);
761 int ll_prep_inode(struct inode **inode, struct ptlrpc_request *req,
762 struct super_block *, struct lookup_intent *);
763 int ll_obd_statfs(struct inode *inode, void __user *arg);
764 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *max_mdsize);
765 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *default_mdsize);
766 int ll_process_config(struct lustre_cfg *lcfg);
767 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
768 struct inode *i1, struct inode *i2,
769 const char *name, int namelen,
770 int mode, __u32 opc, void *data);
771 void ll_finish_md_op_data(struct md_op_data *op_data);
772 int ll_get_obd_name(struct inode *inode, unsigned int cmd, unsigned long arg);
773 char *ll_get_fsname(struct super_block *sb, char *buf, int buflen);
774 void ll_open_cleanup(struct super_block *sb, struct ptlrpc_request *open_req);
776 /* llite/llite_nfs.c */
777 extern const struct export_operations lustre_export_operations;
778 __u32 get_uuid2int(const char *name, int len);
779 void get_uuid2fsid(const char *name, int len, __kernel_fsid_t *fsid);
780 struct inode *search_inode_for_lustre(struct super_block *sb,
781 const struct lu_fid *fid);
783 /* llite/symlink.c */
784 extern const struct inode_operations ll_fast_symlink_inode_operations;
786 /* llite/llite_close.c */
787 struct ll_close_queue {
789 struct list_head lcq_head;
790 wait_queue_head_t lcq_waitq;
791 struct completion lcq_comp;
795 void vvp_write_pending(struct vvp_object *club, struct vvp_page *page);
796 void vvp_write_complete(struct vvp_object *club, struct vvp_page *page);
799 * IO arguments for various VFS I/O interfaces.
805 struct kiocb *via_iocb;
806 struct iov_iter *via_iter;
811 struct ll_cl_context {
812 struct list_head lcc_list;
814 const struct lu_env *lcc_env;
815 struct cl_io *lcc_io;
816 struct cl_page *lcc_page;
819 struct ll_thread_info {
820 struct vvp_io_args lti_args;
821 struct ra_io_arg lti_ria;
822 struct ll_cl_context lti_io_ctx;
825 extern struct lu_context_key ll_thread_key;
826 static inline struct ll_thread_info *ll_env_info(const struct lu_env *env)
828 struct ll_thread_info *lti;
830 lti = lu_context_key_get(&env->le_ctx, &ll_thread_key);
835 static inline struct vvp_io_args *ll_env_args(const struct lu_env *env)
837 return &ll_env_info(env)->lti_args;
840 void ll_queue_done_writing(struct inode *inode, unsigned long flags);
841 void ll_close_thread_shutdown(struct ll_close_queue *lcq);
842 int ll_close_thread_start(struct ll_close_queue **lcq_ret);
844 /* llite/llite_mmap.c */
846 int ll_teardown_mmaps(struct address_space *mapping, __u64 first, __u64 last);
847 int ll_file_mmap(struct file *file, struct vm_area_struct *vma);
848 void policy_from_vma(ldlm_policy_data_t *policy, struct vm_area_struct *vma,
849 unsigned long addr, size_t count);
850 struct vm_area_struct *our_vma(struct mm_struct *mm, unsigned long addr,
853 static inline void ll_invalidate_page(struct page *vmpage)
855 struct address_space *mapping = vmpage->mapping;
856 loff_t offset = vmpage->index << PAGE_SHIFT;
858 LASSERT(PageLocked(vmpage));
863 * truncate_complete_page() calls
864 * a_ops->invalidatepage()->cl_page_delete()->vvp_page_delete().
866 ll_teardown_mmaps(mapping, offset, offset + PAGE_SIZE);
867 truncate_complete_page(mapping, vmpage);
870 #define ll_s2sbi(sb) (s2lsi(sb)->lsi_llsbi)
872 /* don't need an addref as the sb_info should be holding one */
873 static inline struct obd_export *ll_s2dtexp(struct super_block *sb)
875 return ll_s2sbi(sb)->ll_dt_exp;
878 /* don't need an addref as the sb_info should be holding one */
879 static inline struct obd_export *ll_s2mdexp(struct super_block *sb)
881 return ll_s2sbi(sb)->ll_md_exp;
884 static inline struct client_obd *sbi2mdc(struct ll_sb_info *sbi)
886 struct obd_device *obd = sbi->ll_md_exp->exp_obd;
893 /* FIXME: replace the name of this with LL_SB to conform to kernel stuff */
894 static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
896 return ll_s2sbi(inode->i_sb);
899 static inline struct obd_export *ll_i2dtexp(struct inode *inode)
901 return ll_s2dtexp(inode->i_sb);
904 static inline struct obd_export *ll_i2mdexp(struct inode *inode)
906 return ll_s2mdexp(inode->i_sb);
909 static inline struct lu_fid *ll_inode2fid(struct inode *inode)
914 fid = &ll_i2info(inode)->lli_fid;
919 static inline __u64 ll_file_maxbytes(struct inode *inode)
921 return ll_i2info(inode)->lli_maxbytes;
925 int ll_setxattr(struct dentry *dentry, struct inode *inode,
926 const char *name, const void *value, size_t size, int flags);
927 ssize_t ll_getxattr(struct dentry *dentry, struct inode *inode,
928 const char *name, void *buffer, size_t size);
929 ssize_t ll_listxattr(struct dentry *dentry, char *buffer, size_t size);
930 int ll_removexattr(struct dentry *dentry, const char *name);
933 * Common IO arguments for various VFS I/O interfaces.
935 int cl_sb_init(struct super_block *sb);
936 int cl_sb_fini(struct super_block *sb);
937 void ll_io_init(struct cl_io *io, const struct file *file, int write);
939 void ras_update(struct ll_sb_info *sbi, struct inode *inode,
940 struct ll_readahead_state *ras, unsigned long index,
942 void ll_ra_count_put(struct ll_sb_info *sbi, unsigned long len);
943 void ll_ra_stats_inc(struct inode *inode, enum ra_stat which);
946 #define LL_SA_RPC_MIN 2
947 #define LL_SA_RPC_DEF 32
948 #define LL_SA_RPC_MAX 8192
950 #define LL_SA_CACHE_BIT 5
951 #define LL_SA_CACHE_SIZE (1 << LL_SA_CACHE_BIT)
952 #define LL_SA_CACHE_MASK (LL_SA_CACHE_SIZE - 1)
954 /* per inode struct, for dir only */
955 struct ll_statahead_info {
956 struct inode *sai_inode;
957 atomic_t sai_refcount; /* when access this struct, hold
960 unsigned int sai_generation; /* generation for statahead */
961 unsigned int sai_max; /* max ahead of lookup */
962 __u64 sai_sent; /* stat requests sent count */
963 __u64 sai_replied; /* stat requests which received
966 __u64 sai_index; /* index of statahead entry */
967 __u64 sai_index_wait; /* index of entry which is the
968 * caller is waiting for
970 __u64 sai_hit; /* hit count */
971 __u64 sai_miss; /* miss count:
972 * for "ls -al" case, it includes
973 * hidden dentry miss;
974 * for "ls -l" case, it does not
975 * include hidden dentry miss.
976 * "sai_miss_hidden" is used for
979 unsigned int sai_consecutive_miss; /* consecutive miss */
980 unsigned int sai_miss_hidden;/* "ls -al", but first dentry
981 * is not a hidden one
983 unsigned int sai_skip_hidden;/* skipped hidden dentry count */
984 unsigned int sai_ls_all:1, /* "ls -al", do stat-ahead for
987 sai_agl_valid:1;/* AGL is valid for the dir */
988 wait_queue_head_t sai_waitq; /* stat-ahead wait queue */
989 struct ptlrpc_thread sai_thread; /* stat-ahead thread */
990 struct ptlrpc_thread sai_agl_thread; /* AGL thread */
991 struct list_head sai_entries; /* entry list */
992 struct list_head sai_entries_received; /* entries returned */
993 struct list_head sai_entries_stated; /* entries stated */
994 struct list_head sai_entries_agl; /* AGL entries to be sent */
995 struct list_head sai_cache[LL_SA_CACHE_SIZE];
996 spinlock_t sai_cache_lock[LL_SA_CACHE_SIZE];
997 atomic_t sai_cache_count; /* entry count in cache */
1000 int do_statahead_enter(struct inode *dir, struct dentry **dentry,
1002 void ll_stop_statahead(struct inode *dir, void *key);
1004 blkcnt_t dirty_cnt(struct inode *inode);
1006 int cl_glimpse_size0(struct inode *inode, int agl);
1007 int cl_glimpse_lock(const struct lu_env *env, struct cl_io *io,
1008 struct inode *inode, struct cl_object *clob, int agl);
1010 static inline int cl_glimpse_size(struct inode *inode)
1012 return cl_glimpse_size0(inode, 0);
1015 static inline int cl_agl(struct inode *inode)
1017 return cl_glimpse_size0(inode, 1);
1020 static inline int ll_glimpse_size(struct inode *inode)
1022 struct ll_inode_info *lli = ll_i2info(inode);
1025 down_read(&lli->lli_glimpse_sem);
1026 rc = cl_glimpse_size(inode);
1027 lli->lli_glimpse_time = cfs_time_current();
1028 up_read(&lli->lli_glimpse_sem);
1033 ll_statahead_mark(struct inode *dir, struct dentry *dentry)
1035 struct ll_inode_info *lli = ll_i2info(dir);
1036 struct ll_statahead_info *sai = lli->lli_sai;
1037 struct ll_dentry_data *ldd = ll_d2d(dentry);
1039 /* not the same process, don't mark */
1040 if (lli->lli_opendir_pid != current_pid())
1045 ldd->lld_sa_generation = sai->sai_generation;
1049 d_need_statahead(struct inode *dir, struct dentry *dentryp)
1051 struct ll_inode_info *lli;
1052 struct ll_dentry_data *ldd;
1054 if (ll_i2sbi(dir)->ll_sa_max == 0)
1057 lli = ll_i2info(dir);
1058 /* not the same process, don't statahead */
1059 if (lli->lli_opendir_pid != current_pid())
1062 /* statahead has been stopped */
1063 if (!lli->lli_opendir_key)
1066 ldd = ll_d2d(dentryp);
1068 * When stats a dentry, the system trigger more than once "revalidate"
1069 * or "lookup", for "getattr", for "getxattr", and maybe for others.
1070 * Under patchless client mode, the operation intent is not accurate,
1071 * which maybe misguide the statahead thread. For example:
1072 * The "revalidate" call for "getattr" and "getxattr" of a dentry maybe
1073 * have the same operation intent -- "IT_GETATTR".
1074 * In fact, one dentry should has only one chance to interact with the
1075 * statahead thread, otherwise the statahead windows will be confused.
1076 * The solution is as following:
1077 * Assign "lld_sa_generation" with "sai_generation" when a dentry
1078 * "IT_GETATTR" for the first time, and the subsequent "IT_GETATTR"
1079 * will bypass interacting with statahead thread for checking:
1080 * "lld_sa_generation == lli_sai->sai_generation"
1082 if (ldd && lli->lli_sai &&
1083 ldd->lld_sa_generation == lli->lli_sai->sai_generation)
1090 ll_statahead_enter(struct inode *dir, struct dentry **dentryp, int only_unplug)
1094 ret = d_need_statahead(dir, *dentryp);
1098 return do_statahead_enter(dir, dentryp, only_unplug);
1101 /* llite ioctl register support routine */
1107 #define LLIOC_MAX_CMD 256
1110 * Rules to write a callback function:
1113 * @magic: Dynamic ioctl call routine will feed this value with the pointer
1114 * returned to ll_iocontrol_register. Callback functions should use this
1115 * data to check the potential collasion of ioctl cmd. If collasion is
1116 * found, callback function should return LLIOC_CONT.
1117 * @rcp: The result of ioctl command.
1120 * If @magic matches the pointer returned by ll_iocontrol_data, the
1121 * callback should return LLIOC_STOP; return LLIOC_STOP otherwise.
1123 typedef enum llioc_iter (*llioc_callback_t)(struct inode *inode,
1124 struct file *file, unsigned int cmd, unsigned long arg,
1125 void *magic, int *rcp);
1127 /* export functions */
1128 /* Register ioctl block dynamatically for a regular file.
1130 * @cmd: the array of ioctl command set
1131 * @count: number of commands in the @cmd
1132 * @cb: callback function, it will be called if an ioctl command is found to
1133 * belong to the command list @cmd.
1136 * A magic pointer will be returned if success;
1137 * otherwise, NULL will be returned.
1139 void *ll_iocontrol_register(llioc_callback_t cb, int count, unsigned int *cmd);
1140 void ll_iocontrol_unregister(void *magic);
1142 int cl_sync_file_range(struct inode *inode, loff_t start, loff_t end,
1143 enum cl_fsync_mode mode, int ignore_layout);
1145 /** direct write pages */
1146 struct ll_dio_pages {
1147 /** page array to be written. we don't support
1148 * partial pages except the last one.
1150 struct page **ldp_pages;
1151 /* offset of each page */
1152 loff_t *ldp_offsets;
1153 /** if ldp_offsets is NULL, it means a sequential
1154 * pages to be written, then this is the file offset
1155 * of the first page.
1157 loff_t ldp_start_offset;
1158 /** how many bytes are to be written. */
1160 /** # of pages in the array. */
1164 static inline void cl_stats_tally(struct cl_device *dev, enum cl_req_type crt,
1167 int opc = (crt == CRT_READ) ? LPROC_LL_OSC_READ :
1170 ll_stats_ops_tally(ll_s2sbi(cl2vvp_dev(dev)->vdv_sb), opc, rc);
1173 ssize_t ll_direct_rw_pages(const struct lu_env *env, struct cl_io *io,
1174 int rw, struct inode *inode,
1175 struct ll_dio_pages *pv);
1177 static inline int ll_file_nolock(const struct file *file)
1179 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1180 struct inode *inode = file_inode(file);
1182 return ((fd->fd_flags & LL_FILE_IGNORE_LOCK) ||
1183 (ll_i2sbi(inode)->ll_flags & LL_SBI_NOLCK));
1186 static inline void ll_set_lock_data(struct obd_export *exp, struct inode *inode,
1187 struct lookup_intent *it, __u64 *bits)
1189 if (!it->it_lock_set) {
1190 struct lustre_handle handle;
1192 /* If this inode is a remote object, it will get two
1193 * separate locks in different namespaces, Master MDT,
1194 * where the name entry is, will grant LOOKUP lock,
1195 * remote MDT, where the object is, will grant
1196 * UPDATE|PERM lock. The inode will be attached to both
1197 * LOOKUP and PERM locks, so revoking either locks will
1198 * case the dcache being cleared
1200 if (it->it_remote_lock_mode) {
1201 handle.cookie = it->it_remote_lock_handle;
1202 CDEBUG(D_DLMTRACE, "setting l_data to inode "DFID"%p for remote lock %#llx\n",
1203 PFID(ll_inode2fid(inode)), inode,
1205 md_set_lock_data(exp, &handle.cookie, inode, NULL);
1208 handle.cookie = it->it_lock_handle;
1210 CDEBUG(D_DLMTRACE, "setting l_data to inode "DFID"%p for lock %#llx\n",
1211 PFID(ll_inode2fid(inode)), inode, handle.cookie);
1213 md_set_lock_data(exp, &handle.cookie, inode,
1215 it->it_lock_set = 1;
1219 *bits = it->it_lock_bits;
1222 static inline int d_lustre_invalid(const struct dentry *dentry)
1224 struct ll_dentry_data *lld = ll_d2d(dentry);
1226 return !lld || lld->lld_invalid;
1229 static inline void __d_lustre_invalidate(struct dentry *dentry)
1231 struct ll_dentry_data *lld = ll_d2d(dentry);
1234 lld->lld_invalid = 1;
1238 * Mark dentry INVALID, if dentry refcount is zero (this is normally case for
1239 * ll_md_blocking_ast), unhash this dentry, and let dcache to reclaim it later;
1240 * else dput() of the last refcount will unhash this dentry and kill it.
1242 static inline void d_lustre_invalidate(struct dentry *dentry, int nested)
1244 CDEBUG(D_DENTRY, "invalidate dentry %pd (%p) parent %p inode %p refc %d\n",
1246 dentry->d_parent, d_inode(dentry), d_count(dentry));
1248 spin_lock_nested(&dentry->d_lock,
1249 nested ? DENTRY_D_LOCK_NESTED : DENTRY_D_LOCK_NORMAL);
1250 __d_lustre_invalidate(dentry);
1252 * We should be careful about dentries created by d_obtain_alias().
1253 * These dentries are not put in the dentry tree, instead they are
1254 * linked to sb->s_anon through dentry->d_hash.
1255 * shrink_dcache_for_umount() shrinks the tree and sb->s_anon list.
1256 * If we unhashed such a dentry, unmount would not be able to find
1257 * it and busy inodes would be reported.
1259 if (d_count(dentry) == 0 && !(dentry->d_flags & DCACHE_DISCONNECTED))
1261 spin_unlock(&dentry->d_lock);
1264 static inline void d_lustre_revalidate(struct dentry *dentry)
1266 spin_lock(&dentry->d_lock);
1267 LASSERT(ll_d2d(dentry));
1268 ll_d2d(dentry)->lld_invalid = 0;
1269 spin_unlock(&dentry->d_lock);
1273 LL_LAYOUT_GEN_NONE = ((__u32)-2), /* layout lock was cancelled */
1274 LL_LAYOUT_GEN_EMPTY = ((__u32)-1) /* for empty layout */
1277 int ll_layout_conf(struct inode *inode, const struct cl_object_conf *conf);
1278 int ll_layout_refresh(struct inode *inode, __u32 *gen);
1279 int ll_layout_restore(struct inode *inode, loff_t start, __u64 length);
1281 int ll_xattr_init(void);
1282 void ll_xattr_fini(void);
1284 int ll_page_sync_io(const struct lu_env *env, struct cl_io *io,
1285 struct cl_page *page, enum cl_req_type crt);
1288 int cl_setattr_ost(struct inode *inode, const struct iattr *attr);
1290 extern struct lu_env *cl_inode_fini_env;
1291 extern int cl_inode_fini_refcheck;
1293 int cl_file_inode_init(struct inode *inode, struct lustre_md *md);
1294 void cl_inode_fini(struct inode *inode);
1295 int cl_local_size(struct inode *inode);
1297 __u64 cl_fid_build_ino(const struct lu_fid *fid, int api32);
1298 __u32 cl_fid_build_gen(const struct lu_fid *fid);
1300 #endif /* LLITE_INTERNAL_H */