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