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