GNU Linux-libre 4.14.259-gnu1
[releases.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 <lustre_debug.h>
36 #include <uapi/linux/lustre/lustre_ver.h>
37 #include <lustre_disk.h>        /* for s2sbi */
38 #include <lustre_linkea.h>
39
40 /* for struct cl_lock_descr and struct cl_io */
41 #include <lustre_patchless_compat.h>
42 #include <lustre_compat.h>
43 #include <cl_object.h>
44 #include <lustre_lmv.h>
45 #include <lustre_mdc.h>
46 #include <lustre_intent.h>
47 #include <linux/compat.h>
48 #include <linux/namei.h>
49 #include <linux/xattr.h>
50 #include <linux/posix_acl_xattr.h>
51 #include "vvp_internal.h"
52 #include "range_lock.h"
53
54 #ifndef FMODE_EXEC
55 #define FMODE_EXEC 0
56 #endif
57
58 #ifndef VM_FAULT_RETRY
59 #define VM_FAULT_RETRY 0
60 #endif
61
62 /** Only used on client-side for indicating the tail of dir hash/offset. */
63 #define LL_DIR_END_OFF    0x7fffffffffffffffULL
64 #define LL_DIR_END_OFF_32BIT    0x7fffffffUL
65
66 /* 4UL * 1024 * 1024 */
67 #define LL_MAX_BLKSIZE_BITS 22
68
69 #define LL_IT2STR(it) ((it) ? ldlm_it2str((it)->it_op) : "0")
70 #define LUSTRE_FPRIVATE(file) ((file)->private_data)
71
72 struct ll_dentry_data {
73         struct lookup_intent            *lld_it;
74         unsigned int                    lld_sa_generation;
75         unsigned int                    lld_invalid:1;
76         unsigned int                    lld_nfs_dentry:1;
77         struct rcu_head                 lld_rcu_head;
78 };
79
80 #define ll_d2d(de) ((struct ll_dentry_data *)((de)->d_fsdata))
81
82 #define LLI_INODE_MAGIC          0x111d0de5
83 #define LLI_INODE_DEAD            0xdeadd00d
84
85 struct ll_getname_data {
86         struct dir_context ctx;
87         char        *lgd_name;      /* points to a buffer with NAME_MAX+1 size */
88         struct lu_fid    lgd_fid;       /* target fid we are looking for */
89         int           lgd_found;     /* inode matched? */
90 };
91
92 struct ll_grouplock {
93         struct lu_env   *lg_env;
94         struct cl_io    *lg_io;
95         struct cl_lock  *lg_lock;
96         unsigned long    lg_gid;
97 };
98
99 enum ll_file_flags {
100         /* File data is modified. */
101         LLIF_DATA_MODIFIED      = 0,
102         /* File is being restored */
103         LLIF_FILE_RESTORING     = 1,
104         /* Xattr cache is attached to the file */
105         LLIF_XATTR_CACHE        = 2,
106 };
107
108 struct ll_inode_info {
109         __u32                           lli_inode_magic;
110
111         spinlock_t                      lli_lock;
112         unsigned long                   lli_flags;
113         struct posix_acl                *lli_posix_acl;
114
115         /* identifying fields for both metadata and data stacks. */
116         struct lu_fid              lli_fid;
117         /* master inode fid for stripe directory */
118         struct lu_fid              lli_pfid;
119
120         /* We need all three because every inode may be opened in different
121          * modes
122          */
123         struct obd_client_handle       *lli_mds_read_och;
124         struct obd_client_handle       *lli_mds_write_och;
125         struct obd_client_handle       *lli_mds_exec_och;
126         __u64                      lli_open_fd_read_count;
127         __u64                      lli_open_fd_write_count;
128         __u64                      lli_open_fd_exec_count;
129         /* Protects access to och pointers and their usage counters */
130         struct mutex                    lli_och_mutex;
131
132         struct inode                    lli_vfs_inode;
133
134         /* the most recent timestamps obtained from mds */
135         s64                             lli_atime;
136         s64                             lli_mtime;
137         s64                             lli_ctime;
138         spinlock_t                      lli_agl_lock;
139
140         /* Try to make the d::member and f::member are aligned. Before using
141          * these members, make clear whether it is directory or not.
142          */
143         union {
144                 /* for directory */
145                 struct {
146                         /* serialize normal readdir and statahead-readdir. */
147                         struct mutex                    lli_readdir_mutex;
148
149                         /* metadata statahead */
150                         /* since parent-child threads can share the same @file
151                          * struct, "opendir_key" is the token when dir close for
152                          * case of parent exit before child -- it is me should
153                          * cleanup the dir readahead.
154                          */
155                         void                           *lli_opendir_key;
156                         struct ll_statahead_info       *lli_sai;
157                         /* protect statahead stuff. */
158                         spinlock_t                      lli_sa_lock;
159                         /* "opendir_pid" is the token when lookup/revalidate
160                          * -- I am the owner of dir statahead.
161                          */
162                         pid_t                           lli_opendir_pid;
163                         /* stat will try to access statahead entries or start
164                          * statahead if this flag is set, and this flag will be
165                          * set upon dir open, and cleared when dir is closed,
166                          * statahead hit ratio is too low, or start statahead
167                          * thread failed.
168                          */
169                         unsigned int                    lli_sa_enabled:1;
170                         /* generation for statahead */
171                         unsigned int                    lli_sa_generation;
172                         /* directory stripe information */
173                         struct lmv_stripe_md           *lli_lsm_md;
174                         /* default directory stripe offset.  This is extracted
175                          * from the "dmv" xattr in order to decide which MDT to
176                          * create a subdirectory on.  The MDS itself fetches
177                          * "dmv" and gets the rest of the default layout itself
178                          * (count, hash, etc).
179                          */
180                         __u32                           lli_def_stripe_offset;
181                 };
182
183                 /* for non-directory */
184                 struct {
185                         struct mutex                    lli_size_mutex;
186                         char                           *lli_symlink_name;
187                         /*
188                          * struct rw_semaphore {
189                          *    signed long       count;     // align d.d_def_acl
190                          *    spinlock_t        wait_lock; // align d.d_sa_lock
191                          *    struct list_head wait_list;
192                          * }
193                          */
194                         struct rw_semaphore             lli_trunc_sem;
195                         struct range_lock_tree          lli_write_tree;
196
197                         struct rw_semaphore             lli_glimpse_sem;
198                         unsigned long                   lli_glimpse_time;
199                         struct list_head                lli_agl_list;
200                         __u64                           lli_agl_index;
201
202                         /* for writepage() only to communicate to fsync */
203                         int                             lli_async_rc;
204
205                         /*
206                          * whenever a process try to read/write the file, the
207                          * jobid of the process will be saved here, and it'll
208                          * be packed into the write PRC when flush later.
209                          *
210                          * so the read/write statistics for jobid will not be
211                          * accurate if the file is shared by different jobs.
212                          */
213                         char                            lli_jobid[LUSTRE_JOBID_SIZE];
214                 };
215         };
216
217         /* XXX: For following frequent used members, although they maybe special
218          *      used for non-directory object, it is some time-wasting to check
219          *      whether the object is directory or not before using them. On the
220          *      other hand, currently, sizeof(f) > sizeof(d), it cannot reduce
221          *      the "ll_inode_info" size even if moving those members into u.f.
222          *      So keep them out side.
223          *
224          *      In the future, if more members are added only for directory,
225          *      some of the following members can be moved into u.f.
226          */
227         struct cl_object               *lli_clob;
228
229         /* mutex to request for layout lock exclusively. */
230         struct mutex                    lli_layout_mutex;
231         /* Layout version, protected by lli_layout_lock */
232         __u32                           lli_layout_gen;
233         spinlock_t                      lli_layout_lock;
234
235         struct rw_semaphore             lli_xattrs_list_rwsem;
236         struct mutex                    lli_xattrs_enq_lock;
237         struct list_head                lli_xattrs;/* ll_xattr_entry->xe_list */
238 };
239
240 static inline __u32 ll_layout_version_get(struct ll_inode_info *lli)
241 {
242         __u32 gen;
243
244         spin_lock(&lli->lli_layout_lock);
245         gen = lli->lli_layout_gen;
246         spin_unlock(&lli->lli_layout_lock);
247
248         return gen;
249 }
250
251 static inline void ll_layout_version_set(struct ll_inode_info *lli, __u32 gen)
252 {
253         spin_lock(&lli->lli_layout_lock);
254         lli->lli_layout_gen = gen;
255         spin_unlock(&lli->lli_layout_lock);
256 }
257
258 int ll_xattr_cache_destroy(struct inode *inode);
259
260 int ll_xattr_cache_get(struct inode *inode, const char *name,
261                        char *buffer, size_t size, __u64 valid);
262
263 int ll_init_security(struct dentry *dentry, struct inode *inode,
264                      struct inode *dir);
265
266 /*
267  * Locking to guarantee consistency of non-atomic updates to long long i_size,
268  * consistency between file size and KMS.
269  *
270  * Implemented by ->lli_size_mutex and ->lsm_lock, nested in that order.
271  */
272
273 void ll_inode_size_lock(struct inode *inode);
274 void ll_inode_size_unlock(struct inode *inode);
275
276 /* FIXME: replace the name of this with LL_I to conform to kernel stuff */
277 /* static inline struct ll_inode_info *LL_I(struct inode *inode) */
278 static inline struct ll_inode_info *ll_i2info(struct inode *inode)
279 {
280         return container_of(inode, struct ll_inode_info, lli_vfs_inode);
281 }
282
283 /* default to about 64M of readahead on a given system. */
284 #define SBI_DEFAULT_READAHEAD_MAX       (64UL << (20 - PAGE_SHIFT))
285
286 /* default to read-ahead full files smaller than 2MB on the second read */
287 #define SBI_DEFAULT_READAHEAD_WHOLE_MAX (2UL << (20 - PAGE_SHIFT))
288
289 enum ra_stat {
290         RA_STAT_HIT = 0,
291         RA_STAT_MISS,
292         RA_STAT_DISTANT_READPAGE,
293         RA_STAT_MISS_IN_WINDOW,
294         RA_STAT_FAILED_GRAB_PAGE,
295         RA_STAT_FAILED_MATCH,
296         RA_STAT_DISCARDED,
297         RA_STAT_ZERO_LEN,
298         RA_STAT_ZERO_WINDOW,
299         RA_STAT_EOF,
300         RA_STAT_MAX_IN_FLIGHT,
301         RA_STAT_WRONG_GRAB_PAGE,
302         RA_STAT_FAILED_REACH_END,
303         _NR_RA_STAT,
304 };
305
306 struct ll_ra_info {
307         atomic_t              ra_cur_pages;
308         unsigned long        ra_max_pages;
309         unsigned long        ra_max_pages_per_file;
310         unsigned long        ra_max_read_ahead_whole_pages;
311 };
312
313 /* ra_io_arg will be filled in the beginning of ll_readahead with
314  * ras_lock, then the following ll_read_ahead_pages will read RA
315  * pages according to this arg, all the items in this structure are
316  * counted by page index.
317  */
318 struct ra_io_arg {
319         unsigned long ria_start;  /* start offset of read-ahead*/
320         unsigned long ria_end;    /* end offset of read-ahead*/
321         unsigned long ria_reserved; /* reserved pages for read-ahead */
322         unsigned long ria_end_min;  /* minimum end to cover current read */
323         bool ria_eof;               /* reach end of file */
324         /* If stride read pattern is detected, ria_stoff means where
325          * stride read is started. Note: for normal read-ahead, the
326          * value here is meaningless, and also it will not be accessed
327          */
328         pgoff_t ria_stoff;
329         /* ria_length and ria_pages are the length and pages length in the
330          * stride I/O mode. And they will also be used to check whether
331          * it is stride I/O read-ahead in the read-ahead pages
332          */
333         unsigned long ria_length;
334         unsigned long ria_pages;
335 };
336
337 /* LL_HIST_MAX=32 causes an overflow */
338 #define LL_HIST_MAX 28
339 #define LL_HIST_START 12 /* buckets start at 2^12 = 4k */
340 #define LL_PROCESS_HIST_MAX 10
341 struct per_process_info {
342         pid_t pid;
343         struct obd_histogram pp_r_hist;
344         struct obd_histogram pp_w_hist;
345 };
346
347 /* pp_extents[LL_PROCESS_HIST_MAX] will hold the combined process info */
348 struct ll_rw_extents_info {
349         struct per_process_info pp_extents[LL_PROCESS_HIST_MAX + 1];
350 };
351
352 #define LL_OFFSET_HIST_MAX 100
353 struct ll_rw_process_info {
354         pid_t                rw_pid;
355         int                    rw_op;
356         loff_t              rw_range_start;
357         loff_t              rw_range_end;
358         loff_t              rw_last_file_pos;
359         loff_t              rw_offset;
360         size_t              rw_smallest_extent;
361         size_t              rw_largest_extent;
362         struct ll_file_data      *rw_last_file;
363 };
364
365 enum stats_track_type {
366         STATS_TRACK_ALL = 0,  /* track all processes */
367         STATS_TRACK_PID,      /* track process with this pid */
368         STATS_TRACK_PPID,     /* track processes with this ppid */
369         STATS_TRACK_GID,      /* track processes with this gid */
370         STATS_TRACK_LAST,
371 };
372
373 /* flags for sbi->ll_flags */
374 #define LL_SBI_NOLCK         0x01 /* DLM locking disabled (directio-only) */
375 #define LL_SBI_CHECKSUM   0x02 /* checksum each page as it's written */
376 #define LL_SBI_FLOCK         0x04
377 #define LL_SBI_USER_XATTR       0x08 /* support user xattr */
378 #define LL_SBI_ACL             0x10 /* support ACL */
379 /* LL_SBI_RMT_CLIENT             0x40    remote client */
380 #define LL_SBI_MDS_CAPA          0x80 /* support mds capa, obsolete */
381 #define LL_SBI_OSS_CAPA         0x100 /* support oss capa, obsolete */
382 #define LL_SBI_LOCALFLOCK       0x200 /* Local flocks support by kernel */
383 #define LL_SBI_LRU_RESIZE       0x400 /* lru resize support */
384 #define LL_SBI_LAZYSTATFS       0x800 /* lazystatfs mount option */
385 /*      LL_SBI_SOM_PREVIEW     0x1000    SOM preview mount option, obsolete */
386 #define LL_SBI_32BIT_API       0x2000 /* generate 32 bit inodes. */
387 #define LL_SBI_64BIT_HASH      0x4000 /* support 64-bits dir hash/offset */
388 #define LL_SBI_AGL_ENABLED     0x8000 /* enable agl */
389 #define LL_SBI_VERBOSE  0x10000 /* verbose mount/umount */
390 #define LL_SBI_LAYOUT_LOCK    0x20000 /* layout lock support */
391 #define LL_SBI_USER_FID2PATH  0x40000 /* allow fid2path by unprivileged users */
392 #define LL_SBI_XATTR_CACHE    0x80000 /* support for xattr cache */
393 #define LL_SBI_NOROOTSQUASH     0x100000 /* do not apply root squash */
394 #define LL_SBI_ALWAYS_PING      0x200000 /* always ping even if server
395                                           * suppress_pings */
396
397 #define LL_SBI_FLAGS {  \
398         "nolck",        \
399         "checksum",     \
400         "flock",        \
401         "user_xattr",   \
402         "acl",          \
403         "???",          \
404         "???",          \
405         "mds_capa",     \
406         "oss_capa",     \
407         "flock",        \
408         "lru_resize",   \
409         "lazy_statfs",  \
410         "som",          \
411         "32bit_api",    \
412         "64bit_hash",   \
413         "agl",          \
414         "verbose",      \
415         "layout",       \
416         "user_fid2path",\
417         "xattr_cache",  \
418         "norootsquash", \
419         "always_ping",  \
420 }
421
422 /*
423  * This is embedded into llite super-blocks to keep track of connect
424  * flags (capabilities) supported by all imports given mount is
425  * connected to.
426  */
427 struct lustre_client_ocd {
428         /*
429          * This is conjunction of connect_flags across all imports
430          * (LOVs) this mount is connected to. This field is updated by
431          * cl_ocd_update() under ->lco_lock.
432          */
433         __u64                    lco_flags;
434         struct mutex             lco_lock;
435         struct obd_export       *lco_md_exp;
436         struct obd_export       *lco_dt_exp;
437 };
438
439 struct ll_sb_info {
440         /* this protects pglist and ra_info.  It isn't safe to
441          * grab from interrupt contexts
442          */
443         spinlock_t                ll_lock;
444         spinlock_t                ll_pp_extent_lock; /* pp_extent entry*/
445         spinlock_t                ll_process_lock; /* ll_rw_process_info */
446         struct obd_uuid    ll_sb_uuid;
447         struct obd_export       *ll_md_exp;
448         struct obd_export       *ll_dt_exp;
449         struct dentry           *ll_debugfs_entry;
450         struct lu_fid        ll_root_fid; /* root object fid */
451
452         int                    ll_flags;
453         unsigned int              ll_umounting:1,
454                                   ll_xattr_cache_enabled:1,
455                                   ll_client_common_fill_super_succeeded:1;
456
457         struct lustre_client_ocd  ll_lco;
458
459         struct lprocfs_stats     *ll_stats; /* lprocfs stats counter */
460
461         /*
462          * Used to track "unstable" pages on a client, and maintain a
463          * LRU list of clean pages. An "unstable" page is defined as
464          * any page which is sent to a server as part of a bulk request,
465          * but is uncommitted to stable storage.
466          */
467         struct cl_client_cache    *ll_cache;
468
469         struct lprocfs_stats     *ll_ra_stats;
470
471         struct ll_ra_info        ll_ra_info;
472         unsigned int          ll_namelen;
473         const struct file_operations    *ll_fop;
474
475         unsigned int              ll_md_brw_pages; /* readdir pages per RPC */
476
477         struct lu_site     *ll_site;
478         struct cl_device         *ll_cl;
479         /* Statistics */
480         struct ll_rw_extents_info ll_rw_extents_info;
481         int                    ll_extent_process_count;
482         struct ll_rw_process_info ll_rw_process_info[LL_PROCESS_HIST_MAX];
483         unsigned int          ll_offset_process_count;
484         struct ll_rw_process_info ll_rw_offset_info[LL_OFFSET_HIST_MAX];
485         unsigned int          ll_rw_offset_entry_count;
486         int                    ll_stats_track_id;
487         enum stats_track_type     ll_stats_track_type;
488         int                    ll_rw_stats_on;
489
490         /* metadata stat-ahead */
491         unsigned int          ll_sa_max;     /* max statahead RPCs */
492         atomic_t                  ll_sa_total;   /* statahead thread started
493                                                   * count
494                                                   */
495         atomic_t                  ll_sa_wrong;   /* statahead thread stopped for
496                                                   * low hit ratio
497                                                   */
498         atomic_t                ll_sa_running;  /* running statahead thread
499                                                  * count
500                                                  */
501         atomic_t                  ll_agl_total;  /* AGL thread started count */
502
503         dev_t                     ll_sdev_orig; /* save s_dev before assign for
504                                                  * clustered nfs
505                                                  */
506         /* root squash */
507         struct root_squash_info   ll_squash;
508         struct path              ll_mnt;
509
510         __kernel_fsid_t           ll_fsid;
511         struct kobject           ll_kobj; /* sysfs object */
512         struct super_block      *ll_sb; /* struct super_block (for sysfs code)*/
513         struct completion        ll_kobj_unregister;
514 };
515
516 /*
517  * per file-descriptor read-ahead data.
518  */
519 struct ll_readahead_state {
520         spinlock_t  ras_lock;
521         /*
522          * index of the last page that read(2) needed and that wasn't in the
523          * cache. Used by ras_update() to detect seeks.
524          *
525          * XXX nikita: if access seeks into cached region, Lustre doesn't see
526          * this.
527          */
528         unsigned long   ras_last_readpage;
529         /*
530          * number of pages read after last read-ahead window reset. As window
531          * is reset on each seek, this is effectively a number of consecutive
532          * accesses. Maybe ->ras_accessed_in_window is better name.
533          *
534          * XXX nikita: window is also reset (by ras_update()) when Lustre
535          * believes that memory pressure evicts read-ahead pages. In that
536          * case, it probably doesn't make sense to expand window to
537          * PTLRPC_MAX_BRW_PAGES on the third access.
538          */
539         unsigned long   ras_consecutive_pages;
540         /*
541          * number of read requests after the last read-ahead window reset
542          * As window is reset on each seek, this is effectively the number
543          * on consecutive read request and is used to trigger read-ahead.
544          */
545         unsigned long   ras_consecutive_requests;
546         /*
547          * Parameters of current read-ahead window. Handled by
548          * ras_update(). On the initial access to the file or after a seek,
549          * window is reset to 0. After 3 consecutive accesses, window is
550          * expanded to PTLRPC_MAX_BRW_PAGES. Afterwards, window is enlarged by
551          * PTLRPC_MAX_BRW_PAGES chunks up to ->ra_max_pages.
552          */
553         unsigned long   ras_window_start, ras_window_len;
554         /*
555          * Optimal RPC size. It decides how many pages will be sent
556          * for each read-ahead.
557          */
558         unsigned long   ras_rpc_size;
559         /*
560          * Where next read-ahead should start at. This lies within read-ahead
561          * window. Read-ahead window is read in pieces rather than at once
562          * because: 1. lustre limits total number of pages under read-ahead by
563          * ->ra_max_pages (see ll_ra_count_get()), 2. client cannot read pages
564          * not covered by DLM lock.
565          */
566         unsigned long   ras_next_readahead;
567         /*
568          * Total number of ll_file_read requests issued, reads originating
569          * due to mmap are not counted in this total.  This value is used to
570          * trigger full file read-ahead after multiple reads to a small file.
571          */
572         unsigned long   ras_requests;
573         /*
574          * Page index with respect to the current request, these value
575          * will not be accurate when dealing with reads issued via mmap.
576          */
577         unsigned long   ras_request_index;
578         /*
579          * The following 3 items are used for detecting the stride I/O
580          * mode.
581          * In stride I/O mode,
582          * ...............|-----data-----|****gap*****|--------|******|....
583          *    offset      |-stride_pages-|-stride_gap-|
584          * ras_stride_offset = offset;
585          * ras_stride_length = stride_pages + stride_gap;
586          * ras_stride_pages = stride_pages;
587          * Note: all these three items are counted by pages.
588          */
589         unsigned long   ras_stride_length;
590         unsigned long   ras_stride_pages;
591         pgoff_t  ras_stride_offset;
592         /*
593          * number of consecutive stride request count, and it is similar as
594          * ras_consecutive_requests, but used for stride I/O mode.
595          * Note: only more than 2 consecutive stride request are detected,
596          * stride read-ahead will be enable
597          */
598         unsigned long   ras_consecutive_stride_requests;
599 };
600
601 extern struct kmem_cache *ll_file_data_slab;
602 struct lustre_handle;
603 struct ll_file_data {
604         struct ll_readahead_state fd_ras;
605         struct ll_grouplock fd_grouplock;
606         __u64 lfd_pos;
607         __u32 fd_flags;
608         fmode_t fd_omode;
609         /* openhandle if lease exists for this file.
610          * Borrow lli->lli_och_mutex to protect assignment
611          */
612         struct obd_client_handle *fd_lease_och;
613         struct obd_client_handle *fd_och;
614         struct file *fd_file;
615         /* Indicate whether need to report failure when close.
616          * true: failure is known, not report again.
617          * false: unknown failure, should report.
618          */
619         bool fd_write_failed;
620         rwlock_t fd_lock; /* protect lcc list */
621         struct list_head fd_lccs; /* list of ll_cl_context */
622 };
623
624 extern struct dentry *llite_root;
625 extern struct kset *llite_kset;
626
627 static inline struct inode *ll_info2i(struct ll_inode_info *lli)
628 {
629         return &lli->lli_vfs_inode;
630 }
631
632 __u32 ll_i2suppgid(struct inode *i);
633 void ll_i2gids(__u32 *suppgids, struct inode *i1, struct inode *i2);
634
635 static inline int ll_need_32bit_api(struct ll_sb_info *sbi)
636 {
637 #if BITS_PER_LONG == 32
638         return 1;
639 #elif defined(CONFIG_COMPAT)
640         return unlikely(in_compat_syscall() || (sbi->ll_flags & LL_SBI_32BIT_API));
641 #else
642         return unlikely(sbi->ll_flags & LL_SBI_32BIT_API);
643 #endif
644 }
645
646 void ll_ras_enter(struct file *f);
647
648 /* llite/lcommon_misc.c */
649 int cl_init_ea_size(struct obd_export *md_exp, struct obd_export *dt_exp);
650 int cl_ocd_update(struct obd_device *host,
651                   struct obd_device *watched,
652                   enum obd_notify_event ev, void *owner, void *data);
653 int cl_get_grouplock(struct cl_object *obj, unsigned long gid, int nonblock,
654                      struct ll_grouplock *cg);
655 void cl_put_grouplock(struct ll_grouplock *cg);
656
657 /* llite/lproc_llite.c */
658 int ldebugfs_register_mountpoint(struct dentry *parent,
659                                  struct super_block *sb, char *osc, char *mdc);
660 void ldebugfs_unregister_mountpoint(struct ll_sb_info *sbi);
661 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count);
662 void lprocfs_llite_init_vars(struct lprocfs_static_vars *lvars);
663 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
664                        struct ll_file_data *file, loff_t pos,
665                        size_t count, int rw);
666
667 enum {
668         LPROC_LL_DIRTY_HITS,
669         LPROC_LL_DIRTY_MISSES,
670         LPROC_LL_READ_BYTES,
671         LPROC_LL_WRITE_BYTES,
672         LPROC_LL_BRW_READ,
673         LPROC_LL_BRW_WRITE,
674         LPROC_LL_IOCTL,
675         LPROC_LL_OPEN,
676         LPROC_LL_RELEASE,
677         LPROC_LL_MAP,
678         LPROC_LL_LLSEEK,
679         LPROC_LL_FSYNC,
680         LPROC_LL_READDIR,
681         LPROC_LL_SETATTR,
682         LPROC_LL_TRUNC,
683         LPROC_LL_FLOCK,
684         LPROC_LL_GETATTR,
685         LPROC_LL_CREATE,
686         LPROC_LL_LINK,
687         LPROC_LL_UNLINK,
688         LPROC_LL_SYMLINK,
689         LPROC_LL_MKDIR,
690         LPROC_LL_RMDIR,
691         LPROC_LL_MKNOD,
692         LPROC_LL_RENAME,
693         LPROC_LL_STAFS,
694         LPROC_LL_ALLOC_INODE,
695         LPROC_LL_SETXATTR,
696         LPROC_LL_GETXATTR,
697         LPROC_LL_GETXATTR_HITS,
698         LPROC_LL_LISTXATTR,
699         LPROC_LL_REMOVEXATTR,
700         LPROC_LL_INODE_PERM,
701         LPROC_LL_FILE_OPCODES
702 };
703
704 /* llite/dir.c */
705 extern const struct file_operations ll_dir_operations;
706 extern const struct inode_operations ll_dir_inode_operations;
707 int ll_dir_read(struct inode *inode, __u64 *ppos, struct md_op_data *op_data,
708                 struct dir_context *ctx);
709 int ll_get_mdt_idx(struct inode *inode);
710 int ll_get_mdt_idx_by_fid(struct ll_sb_info *sbi, const struct lu_fid *fid);
711 struct page *ll_get_dir_page(struct inode *dir, struct md_op_data *op_data,
712                              __u64 offset);
713 void ll_release_page(struct inode *inode, struct page *page, bool remove);
714
715 /* llite/namei.c */
716 extern const struct inode_operations ll_special_inode_operations;
717
718 struct inode *ll_iget(struct super_block *sb, ino_t hash,
719                       struct lustre_md *lic);
720 int ll_test_inode_by_fid(struct inode *inode, void *opaque);
721 int ll_md_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
722                        void *data, int flag);
723 struct dentry *ll_splice_alias(struct inode *inode, struct dentry *de);
724 void ll_update_times(struct ptlrpc_request *request, struct inode *inode);
725
726 /* llite/rw.c */
727 int ll_writepage(struct page *page, struct writeback_control *wbc);
728 int ll_writepages(struct address_space *mapping, struct writeback_control *wbc);
729 int ll_readpage(struct file *file, struct page *page);
730 void ll_readahead_init(struct inode *inode, struct ll_readahead_state *ras);
731 int vvp_io_write_commit(const struct lu_env *env, struct cl_io *io);
732 struct ll_cl_context *ll_cl_find(struct file *file);
733 void ll_cl_add(struct file *file, const struct lu_env *env, struct cl_io *io);
734 void ll_cl_remove(struct file *file, const struct lu_env *env);
735
736 extern const struct address_space_operations ll_aops;
737
738 /* llite/file.c */
739 extern const struct file_operations ll_file_operations;
740 extern const struct file_operations ll_file_operations_flock;
741 extern const struct file_operations ll_file_operations_noflock;
742 extern const struct inode_operations ll_file_inode_operations;
743 int ll_have_md_lock(struct inode *inode, __u64 *bits,
744                     enum ldlm_mode l_req_mode);
745 enum ldlm_mode ll_take_md_lock(struct inode *inode, __u64 bits,
746                                struct lustre_handle *lockh, __u64 flags,
747                                enum ldlm_mode mode);
748 int ll_file_open(struct inode *inode, struct file *file);
749 int ll_file_release(struct inode *inode, struct file *file);
750 int ll_release_openhandle(struct inode *inode, struct lookup_intent *it);
751 int ll_md_real_close(struct inode *inode, fmode_t fmode);
752 int ll_getattr(const struct path *path, struct kstat *stat,
753                u32 request_mask, unsigned int flags);
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 *it);
782 void ll_intent_release(struct lookup_intent *it);
783 void ll_invalidate_aliases(struct inode *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 *sb, struct lookup_intent *it);
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 u16 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 */