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