Whamcloud - gitweb
LU-1358 kernel: Kernel update [RHEL6.2 2.6.32-220.13.1.el6]
[fs/lustre-release.git] / lustre / llite / llite_internal.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #ifndef LLITE_INTERNAL_H
38 #define LLITE_INTERNAL_H
39
40 #ifdef CONFIG_FS_POSIX_ACL
41 # include <linux/fs.h>
42 #ifdef HAVE_XATTR_ACL
43 # include <linux/xattr_acl.h>
44 #endif
45 #ifdef HAVE_LINUX_POSIX_ACL_XATTR_H
46 # include <linux/posix_acl_xattr.h>
47 #endif
48 #endif
49
50 #include <lustre_debug.h>
51 #include <lustre_ver.h>
52 #include <linux/lustre_version.h>
53 #include <lustre_disk.h>  /* for s2sbi */
54
55 #ifndef HAVE_LE_TYPES
56 typedef __u16 __le16;
57 typedef __u32 __le32;
58 #endif
59
60 /*
61 struct lustre_intent_data {
62         __u64 it_lock_handle[2];
63         __u32 it_disposition;
64         __u32 it_status;
65         __u32 it_lock_mode;
66         }; */
67
68 /* If there is no FMODE_EXEC defined, make it to match nothing */
69 #ifndef FMODE_EXEC
70 #define FMODE_EXEC 0
71 #endif
72
73 /** Only used on client-side for indicating the tail of dir hash/offset. */
74 #define LL_DIR_END_OFF          0x7fffffffffffffffULL
75 #define LL_DIR_END_OFF_32BIT    0x7fffffffUL
76
77 #ifndef DCACHE_LUSTRE_INVALID
78 #define DCACHE_LUSTRE_INVALID 0x100
79 #endif
80
81 #define LL_IT2STR(it) ((it) ? ldlm_it2str((it)->it_op) : "0")
82 #define LUSTRE_FPRIVATE(file) ((file)->private_data)
83
84 #ifdef HAVE_VFS_INTENT_PATCHES
85 static inline struct lookup_intent *ll_nd2it(struct nameidata *nd)
86 {
87         return &nd->intent;
88 }
89 #endif
90
91 /*
92  * Directory entries are currently in the same format as ext2/ext3, but will
93  * be changed in the future to accomodate FIDs
94  */
95 #define LL_DIR_NAME_LEN (255)
96 #define LL_DIR_PAD      (4)
97
98 struct ll_dir_entry {
99         /* number of inode, referenced by this entry */
100         __le32  lde_inode;
101         /* total record length, multiple of LL_DIR_PAD */
102         __le16  lde_rec_len;
103         /* length of name */
104         __u8    lde_name_len;
105         /* file type: regular, directory, device, etc. */
106         __u8    lde_file_type;
107         /* name. NOT NUL-terminated */
108         char    lde_name[LL_DIR_NAME_LEN];
109 };
110
111 struct ll_dentry_data {
112         int                      lld_cwd_count;
113         int                      lld_mnt_count;
114         struct obd_client_handle lld_cwd_och;
115         struct obd_client_handle lld_mnt_och;
116 #ifndef HAVE_VFS_INTENT_PATCHES
117         struct lookup_intent    *lld_it;
118 #endif
119         unsigned int             lld_sa_generation;
120 };
121
122 #define ll_d2d(de) ((struct ll_dentry_data*)((de)->d_fsdata))
123
124 extern struct file_operations ll_pgcache_seq_fops;
125
126 #define LLI_INODE_MAGIC                 0x111d0de5
127 #define LLI_INODE_DEAD                  0xdeadd00d
128 #define LLI_F_HAVE_OST_SIZE_LOCK        0
129 #define LLI_F_HAVE_MDS_SIZE_LOCK        1
130 #define LLI_F_CONTENDED                 2
131 #define LLI_F_SRVLOCK                   3
132
133 struct ll_inode_info {
134         int                     lli_inode_magic;
135         struct semaphore        lli_size_sem;           /* protect open and change size */
136         void                   *lli_size_sem_owner;
137         struct semaphore        lli_write_sem;
138         struct lov_stripe_md   *lli_smd;
139         char                   *lli_symlink_name;
140         __u64                   lli_maxbytes;
141         __u64                   lli_io_epoch;
142         unsigned long           lli_flags;
143         cfs_time_t              lli_contention_time;
144
145         /* this lock protects s_d_w and p_w_ll and mmap_cnt;
146          * atomic check-update of lli_smd */
147         spinlock_t              lli_lock;
148 #ifdef HAVE_CLOSE_THREAD
149         struct list_head        lli_pending_write_llaps;
150         struct list_head        lli_close_item;
151         int                     lli_send_done_writing;
152 #endif
153         atomic_t                lli_mmap_cnt;
154
155         /* for writepage() only to communicate to fsync */
156         int                     lli_async_rc;
157
158         struct posix_acl       *lli_posix_acl;
159
160         struct list_head        lli_dead_list;
161
162         struct semaphore        lli_och_sem; /* Protects access to och pointers
163                                                 and their usage counters */
164         /* We need all three because every inode may be opened in different
165            modes */
166         struct obd_client_handle *lli_mds_read_och;
167         __u64                   lli_open_fd_read_count;
168         struct obd_client_handle *lli_mds_write_och;
169         __u64                   lli_open_fd_write_count;
170         struct obd_client_handle *lli_mds_exec_och;
171         __u64                   lli_open_fd_exec_count;
172
173         /** fid of this object. */
174         union {
175                 struct lu_fid f20;
176                 struct ll_fid f16;
177         } lli_fid;
178
179         /* metadata stat-ahead */
180         /*
181          * "opendir_pid" is the token when lookup/revalid -- I am the owner of
182          * dir statahead.
183          */
184         pid_t                   lli_opendir_pid;
185         /*
186          * since parent-child threads can share the same @file struct,
187          * "opendir_key" is the token when dir close for case of parent exit
188          * before child -- it is me should cleanup the dir readahead. */
189         void                   *lli_opendir_key;
190         struct ll_statahead_info *lli_sai;
191         struct rw_semaphore     lli_truncate_rwsem;
192         /* the most recent attributes from mds, it is used for timestamps
193          * only so far */
194         struct ost_lvb         lli_lvb;
195         struct inode            lli_vfs_inode;
196 };
197
198 /*
199  * Locking to guarantee consistency of non-atomic updates to long long i_size,
200  * consistency between file size and KMS, and consistency within
201  * ->lli_smd->lsm_oinfo[]'s.
202  *
203  * Implemented by ->lli_size_sem and ->lsm_sem, nested in that order.
204  */
205
206 void ll_inode_size_lock(struct inode *inode, int lock_lsm);
207 void ll_inode_size_unlock(struct inode *inode, int unlock_lsm);
208
209 // FIXME: replace the name of this with LL_I to conform to kernel stuff
210 // static inline struct ll_inode_info *LL_I(struct inode *inode)
211 static inline struct ll_inode_info *ll_i2info(struct inode *inode)
212 {
213         return container_of(inode, struct ll_inode_info, lli_vfs_inode);
214 }
215
216 /* default to about 40meg of readahead on a given system.  That much tied
217  * up in 512k readahead requests serviced at 40ms each is about 1GB/s. */
218 #define SBI_DEFAULT_READAHEAD_MAX (40UL << (20 - CFS_PAGE_SHIFT))
219
220 /* default to read-ahead full files smaller than 2MB on the second read */
221 #define SBI_DEFAULT_READAHEAD_WHOLE_MAX (2UL << (20 - CFS_PAGE_SHIFT))
222
223 enum ra_stat {
224         RA_STAT_HIT = 0,
225         RA_STAT_MISS,
226         RA_STAT_DISTANT_READPAGE,
227         RA_STAT_MISS_IN_WINDOW,
228         RA_STAT_FAILED_GRAB_PAGE,
229         RA_STAT_FAILED_MATCH,
230         RA_STAT_DISCARDED,
231         RA_STAT_ZERO_LEN,
232         RA_STAT_ZERO_WINDOW,
233         RA_STAT_EOF,
234         RA_STAT_MAX_IN_FLIGHT,
235         RA_STAT_WRONG_GRAB_PAGE,
236         _NR_RA_STAT,
237 };
238
239 #define LL_RA_STAT      _NR_RA_STAT
240 #define LL_RA_STAT_STRINGS           {                                  \
241         [RA_STAT_HIT]               = "hits",                           \
242         [RA_STAT_MISS]              = "misses",                         \
243         [RA_STAT_DISTANT_READPAGE]  = "readpage not consecutive",       \
244         [RA_STAT_MISS_IN_WINDOW]    = "miss inside window",             \
245         [RA_STAT_FAILED_GRAB_PAGE]  = "failed grab_cache_page",         \
246         [RA_STAT_FAILED_MATCH]      = "failed lock match",              \
247         [RA_STAT_DISCARDED]         = "read but discarded",             \
248         [RA_STAT_ZERO_LEN]          = "zero length file",               \
249         [RA_STAT_ZERO_WINDOW]       = "zero size window",               \
250         [RA_STAT_EOF]               = "read-ahead to EOF",              \
251         [RA_STAT_MAX_IN_FLIGHT]     = "hit max r-a issue",              \
252         [RA_STAT_WRONG_GRAB_PAGE]   = "wrong page from grab_cache_page",\
253 }
254
255 struct ll_ra_info {
256         atomic_t                  ra_cur_pages;
257         unsigned long             ra_max_pages;
258         unsigned long             ra_max_pages_per_file;
259         unsigned long             ra_max_read_ahead_whole_pages;
260 };
261
262 /* LL_HIST_MAX=32 causes an overflow */
263 #define LL_HIST_MAX 28
264 #define LL_HIST_START 12 /* buckets start at 2^12 = 4k */
265 #define LL_PROCESS_HIST_MAX 10
266 struct per_process_info {
267         pid_t pid;
268         struct obd_histogram pp_r_hist;
269         struct obd_histogram pp_w_hist;
270 };
271
272 /* pp_extents[LL_PROCESS_HIST_MAX] will hold the combined process info */
273 struct ll_rw_extents_info {
274         struct per_process_info pp_extents[LL_PROCESS_HIST_MAX + 1];
275 };
276
277 #define LL_OFFSET_HIST_MAX 100
278 struct ll_rw_process_info {
279         pid_t                     rw_pid;
280         int                       rw_op;
281         loff_t                    rw_range_start;
282         loff_t                    rw_range_end;
283         loff_t                    rw_last_file_pos;
284         loff_t                    rw_offset;
285         size_t                    rw_smallest_extent;
286         size_t                    rw_largest_extent;
287         struct file               *rw_last_file;
288 };
289
290
291 enum stats_track_type {
292         STATS_TRACK_ALL = 0,  /* track all processes */
293         STATS_TRACK_PID,      /* track process with this pid */
294         STATS_TRACK_PPID,     /* track processes with this ppid */
295         STATS_TRACK_GID,      /* track processes with this gid */
296         STATS_TRACK_LAST,
297 };
298
299 /* flags for sbi->ll_flags */
300 #define LL_SBI_NOLCK            0x01 /* DLM locking disabled (directio-only) */
301 #define LL_SBI_DATA_CHECKSUM    0x02 /* checksum each page on the wire */
302 #define LL_SBI_FLOCK            0x04
303 #define LL_SBI_USER_XATTR       0x08 /* support user xattr */
304 #define LL_SBI_ACL              0x10 /* support ACL */
305 #define LL_SBI_JOIN             0x20 /* support JOIN */
306 #define LL_SBI_LOCALFLOCK       0x40 /* Local flocks support by kernel */
307 #define LL_SBI_LRU_RESIZE       0x80 /* support lru resize */
308 #define LL_SBI_LLITE_CHECKSUM  0x100 /* checksum each page in memory */
309 #define LL_SBI_LAZYSTATFS      0x200 /* lazystatfs mount option */
310 #define LL_SBI_32BIT_API       0x400 /* generate 32 bit inodes. */
311 #define LL_SBI_64BIT_HASH      0x800 /* support 64-bits dir hash/offset */
312
313 /* default value for ll_sb_info->contention_time */
314 #define SBI_DEFAULT_CONTENTION_SECONDS     60
315 /* default value for lockless_truncate_enable */
316 #define SBI_DEFAULT_LOCKLESS_TRUNCATE_ENABLE 0 /* see bug 23175 */
317 /* default value for ll_direct_io_default */
318 #define SBI_DEFAULT_DIRECT_IO_DEFAULT 0
319 #define SBI_DEFAULT_LOCKLESS_DIRECT_IO 1
320
321 /* percpu data structure for lustre lru page list */
322 struct ll_pglist_data {
323         spinlock_t                llpd_lock; /* lock to protect llpg_list */
324         struct list_head          llpd_list; /* all pages (llap_pglist_item) */
325         unsigned long             llpd_gen;  /* generation # of this list */
326         unsigned long             llpd_count; /* How many pages in this list */
327         atomic_t                  llpd_sample_count;
328         unsigned long             llpd_reblnc_count;
329         /* the pages in this list shouldn't be over this number */
330         unsigned long             llpd_budget;
331         int                       llpd_cpu;
332         /* which page the pglist data is in */
333         struct page              *llpd_page;
334
335         /* stats */
336         unsigned long             llpd_hit;
337         unsigned long             llpd_miss;
338         unsigned long             llpd_cross;
339 };
340
341 struct ll_sb_info {
342         struct list_head          ll_list;
343         /* this protects pglist(only ll_async_page_max) and ra_info.
344          * It isn't safe to grab from interrupt contexts. */
345         spinlock_t                ll_lock;
346         spinlock_t                ll_pp_extent_lock; /* Lock for pp_extent entries */
347         spinlock_t                ll_process_lock; /* Lock for ll_rw_process_info */
348         struct obd_uuid           ll_sb_uuid;
349         struct obd_export        *ll_mdc_exp;
350         struct obd_export        *ll_osc_exp;
351         struct proc_dir_entry    *ll_proc_root;
352         obd_id                    ll_rootino; /* number of root inode */
353
354         int                       ll_flags;
355         struct list_head          ll_conn_chain; /* per-conn chain of SBs */
356         struct lustre_client_ocd  ll_lco;
357
358         struct list_head          ll_orphan_dentry_list; /*please don't ask -p*/
359         struct ll_close_queue    *ll_lcq;
360
361         struct lprocfs_stats     *ll_stats; /* lprocfs stats counter */
362
363         /* reblnc lock protects llpd_budget */
364         spinlock_t                ll_async_page_reblnc_lock;
365         unsigned long             ll_async_page_reblnc_count;
366         unsigned long             ll_async_page_sample_max;
367         /* I defined this array here rather than in ll_pglist_data
368          * because it is always accessed by only one cpu. -jay */
369         unsigned long            *ll_async_page_sample;
370         unsigned long             ll_async_page_max;
371         unsigned long             ll_async_page_clock_hand;
372         lcounter_t                ll_async_page_count;
373         struct ll_pglist_data   **ll_pglist;
374
375         struct lprocfs_stats     *ll_ra_stats;
376
377         unsigned                  ll_contention_time; /* seconds */
378         unsigned                  ll_lockless_truncate_enable; /* true/false */
379         unsigned                  ll_lockless_direct_io; /* true/false */
380         unsigned                  ll_direct_io_default; /* true/false */
381
382         struct ll_ra_info         ll_ra_info;
383         unsigned int              ll_namelen;
384         struct file_operations   *ll_fop;
385
386         /* =0 - hold lock over whole read/write
387          * >0 - max. chunk to be read/written w/o lock re-acquiring */
388         unsigned long             ll_max_rw_chunk;
389
390         /* Statistics */
391         struct ll_rw_extents_info ll_rw_extents_info;
392         int                       ll_extent_process_count;
393         struct ll_rw_process_info ll_rw_process_info[LL_PROCESS_HIST_MAX];
394         unsigned int              ll_offset_process_count;
395         struct ll_rw_process_info ll_rw_offset_info[LL_OFFSET_HIST_MAX];
396         unsigned int              ll_rw_offset_entry_count;
397         enum stats_track_type     ll_stats_track_type;
398         int                       ll_stats_track_id;
399         int                       ll_rw_stats_on;
400         dev_t                     ll_sdev_orig; /* save s_dev before assign for
401                                                  * clustred nfs */
402
403         /* metadata stat-ahead */
404         unsigned int              ll_sa_max;     /* max statahead RPCs */
405         unsigned int              ll_sa_wrong;   /* statahead thread stopped for
406                                                   * low hit ratio */
407         unsigned int              ll_sa_total;   /* statahead thread started
408                                                   * count */
409         unsigned long long        ll_sa_blocked; /* ls count waiting for
410                                                   * statahead */
411         unsigned long long        ll_sa_cached;  /* ls count got in cache */
412         unsigned long long        ll_sa_hit;     /* hit count */
413         unsigned long long        ll_sa_miss;    /* miss count */
414 };
415
416 #define LL_DEFAULT_MAX_RW_CHUNK      (32 * 1024 * 1024)
417
418 #define LL_PGLIST_DATA_CPU(sbi, cpu) ((sbi)->ll_pglist[cpu])
419 #define LL_PGLIST_DATA(sbi)          LL_PGLIST_DATA_CPU(sbi, smp_processor_id())
420
421 static inline struct ll_pglist_data *ll_pglist_cpu_lock(
422                 struct ll_sb_info *sbi,
423                 int cpu)
424 {
425         spin_lock(&sbi->ll_pglist[cpu]->llpd_lock);
426         return LL_PGLIST_DATA_CPU(sbi, cpu);
427 }
428
429 static inline void ll_pglist_cpu_unlock(struct ll_sb_info *sbi, int cpu)
430 {
431         spin_unlock(&sbi->ll_pglist[cpu]->llpd_lock);
432 }
433
434 static inline struct ll_pglist_data *ll_pglist_double_lock(
435                 struct ll_sb_info *sbi,
436                 int cpu, struct ll_pglist_data **pd_cpu)
437 {
438         int current_cpu = cfs_get_cpu();
439
440         if (cpu == current_cpu) {
441                 ll_pglist_cpu_lock(sbi, cpu);
442         } else if (current_cpu < cpu) {
443                 ll_pglist_cpu_lock(sbi, current_cpu);
444                 ll_pglist_cpu_lock(sbi, cpu);
445         } else {
446                 ll_pglist_cpu_lock(sbi, cpu);
447                 ll_pglist_cpu_lock(sbi, current_cpu);
448         }
449
450         if (pd_cpu)
451                 *pd_cpu = LL_PGLIST_DATA_CPU(sbi, cpu);
452
453         return LL_PGLIST_DATA(sbi);
454 }
455
456 static inline void ll_pglist_double_unlock(struct ll_sb_info *sbi, int cpu)
457 {
458         int current_cpu = smp_processor_id();
459         if (cpu == current_cpu) {
460                 ll_pglist_cpu_unlock(sbi, cpu);
461         } else {
462                 ll_pglist_cpu_unlock(sbi, cpu);
463                 ll_pglist_cpu_unlock(sbi, current_cpu);
464         }
465         cfs_put_cpu();
466 }
467
468 static inline struct ll_pglist_data *ll_pglist_lock(struct ll_sb_info *sbi)
469 {
470         ll_pglist_cpu_lock(sbi, cfs_get_cpu());
471         return LL_PGLIST_DATA(sbi);
472 }
473
474 static inline void ll_pglist_unlock(struct ll_sb_info *sbi)
475 {
476         ll_pglist_cpu_unlock(sbi, smp_processor_id());
477         cfs_put_cpu();
478 }
479
480 struct ll_ra_read {
481         pgoff_t             lrr_start;
482         pgoff_t             lrr_count;
483         struct task_struct *lrr_reader;
484         struct list_head    lrr_linkage;
485 };
486
487 /*
488  * per file-descriptor read-ahead data.
489  */
490 struct ll_readahead_state {
491         spinlock_t      ras_lock;
492         /*
493          * index of the last page that read(2) needed and that wasn't in the
494          * cache. Used by ras_update() to detect seeks.
495          *
496          * XXX nikita: if access seeks into cached region, Lustre doesn't see
497          * this.
498          */
499         unsigned long   ras_last_readpage;
500         /*
501          * number of pages read after last read-ahead window reset. As window
502          * is reset on each seek, this is effectively a number of consecutive
503          * accesses. Maybe ->ras_accessed_in_window is better name.
504          *
505          * XXX nikita: window is also reset (by ras_update()) when Lustre
506          * believes that memory pressure evicts read-ahead pages. In that
507          * case, it probably doesn't make sense to expand window to
508          * PTLRPC_MAX_BRW_PAGES on the third access.
509          */
510         unsigned long   ras_consecutive_pages;
511         /*
512          * number of read requests after the last read-ahead window reset
513          * As window is reset on each seek, this is effectively the number
514          * on consecutive read request and is used to trigger read-ahead.
515          */
516         unsigned long   ras_consecutive_requests;
517         /*
518          * Parameters of current read-ahead window. Handled by
519          * ras_update(). On the initial access to the file or after a seek,
520          * window is reset to 0. After 3 consecutive accesses, window is
521          * expanded to PTLRPC_MAX_BRW_PAGES. Afterwards, window is enlarged by
522          * PTLRPC_MAX_BRW_PAGES chunks up to ->ra_max_pages.
523          */
524         unsigned long   ras_window_start, ras_window_len;
525         /*
526          * Where next read-ahead should start at. This lies within read-ahead
527          * window. Read-ahead window is read in pieces rather than at once
528          * because: 1. lustre limits total number of pages under read-ahead by
529          * ->ra_max_pages (see ll_ra_count_get()), 2. client cannot read pages
530          * not covered by DLM lock.
531          */
532         unsigned long   ras_next_readahead;
533         /*
534          * Total number of ll_file_read requests issued, reads originating
535          * due to mmap are not counted in this total.  This value is used to
536          * trigger full file read-ahead after multiple reads to a small file.
537          */
538         unsigned long   ras_requests;
539         /*
540          * Page index with respect to the current request, these value
541          * will not be accurate when dealing with reads issued via mmap.
542          */
543         unsigned long   ras_request_index;
544         /*
545          * list of struct ll_ra_read's one per read(2) call current in
546          * progress against this file descriptor. Used by read-ahead code,
547          * protected by ->ras_lock.
548          */
549         struct list_head ras_read_beads;
550         /*
551          * The following 3 items are used for detecting the stride I/O
552          * mode.
553          * In stride I/O mode,
554          * ...............|-----data-----|****gap*****|--------|******|....
555          *    offset      |-stride_pages-|-stride_gap-|
556          * ras_stride_offset = offset;
557          * ras_stride_length = stride_pages + stride_gap;
558          * ras_stride_pages = stride_pages;
559          * Note: all these three items are counted by pages.
560          */
561         unsigned long ras_stride_length;
562         unsigned long ras_stride_pages;
563         pgoff_t ras_stride_offset;
564         /*
565          * number of consecutive stride request count, and it is similar as
566          * ras_consecutive_requests, but used for stride I/O mode.
567          * Note: only more than 2 consecutive stride request are detected,
568          * stride read-ahead will be enable
569          */
570         unsigned long ras_consecutive_stride_requests;
571 };
572
573 struct ll_file_dir {
574         __u64 lfd_pos;
575         __u64 lfd_next;
576 };
577
578 extern cfs_mem_cache_t *ll_file_data_slab;
579 extern struct rw_semaphore ll_sb_sem;
580 struct lustre_handle;
581 struct ll_file_data {
582         struct ll_readahead_state fd_ras;
583         int fd_omode;
584         struct lustre_handle fd_cwlockh;
585         unsigned long fd_gid;
586         struct ll_file_dir fd_dir;
587         __u32 fd_flags;
588 };
589
590 struct lov_stripe_md;
591
592 extern spinlock_t inode_lock;
593
594 extern struct proc_dir_entry *proc_lustre_fs_root;
595
596 static inline struct inode *ll_info2i(struct ll_inode_info *lli)
597 {
598         return &lli->lli_vfs_inode;
599 }
600
601 struct it_cb_data {
602         struct inode *icbd_parent;
603         struct dentry **icbd_childp;
604         obd_id hash;
605 };
606
607 void ll_i2gids(__u32 *suppgids, struct inode *i1,struct inode *i2);
608
609 #define LLAP_MAGIC 98764321
610
611 extern cfs_mem_cache_t *ll_async_page_slab;
612 extern size_t ll_async_page_slab_size;
613 struct ll_async_page {
614         int              llap_magic;
615          /* only trust these if the page lock is providing exclusion */
616         unsigned int     llap_write_queued:1,
617                          llap_defer_uptodate:1,
618                          llap_origin:3,
619                          llap_ra_used:1,
620                          llap_ignore_quota:1,
621                          llap_reserved:7;
622         unsigned int     llap_pglist_cpu:16;
623         void            *llap_cookie;
624         struct page     *llap_page;
625         struct list_head llap_pending_write;
626         struct list_head llap_pglist_item;
627         /* checksum for paranoid I/O debugging */
628         __u32 llap_checksum;
629         struct lustre_handle llap_lockh_granted;
630 };
631
632 /*
633  * enumeration of llap_from_page() call-sites. Used to export statistics in
634  * /proc/fs/lustre/llite/fsN/dump_page_cache.
635  */
636 enum {
637         LLAP_ORIGIN_UNKNOWN = 0,
638         LLAP_ORIGIN_READPAGE,
639         LLAP_ORIGIN_READAHEAD,
640         LLAP_ORIGIN_COMMIT_WRITE,
641         LLAP_ORIGIN_WRITEPAGE,
642         LLAP_ORIGIN_REMOVEPAGE,
643         LLAP__ORIGIN_MAX,
644 };
645 extern char *llap_origins[];
646
647 void ll_ra_read_init(struct file *f, struct ll_ra_read *rar,
648                      loff_t offset, size_t count);
649 void ll_ra_read_ex(struct file *f, struct ll_ra_read *rar);
650 struct ll_ra_read *ll_ra_read_get(struct file *f);
651
652 static inline int ll_need_32bit_api(struct ll_sb_info *sbi)
653 {
654 #if BITS_PER_LONG == 32
655         return 1;
656 #else
657         return unlikely(cfs_curproc_is_32bit() || (sbi->ll_flags & LL_SBI_32BIT_API));
658 #endif
659 }
660
661 /* llite/lproc_llite.c */
662 #ifdef LPROCFS
663 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
664                                 struct super_block *sb, char *osc, char *mdc);
665 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi);
666 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count);
667 void lprocfs_llite_init_vars(struct lprocfs_static_vars *lvars);
668 #else
669 static inline int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
670                         struct super_block *sb, char *osc, char *mdc){return 0;}
671 static inline void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi) {}
672 static void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count) {}
673 static void lprocfs_llite_init_vars(struct lprocfs_static_vars *lvars)
674 {
675         memset(lvars, 0, sizeof(*lvars));
676 }
677 #endif
678
679
680 /* llite/dir.c */
681 extern struct file_operations ll_dir_operations;
682 extern struct inode_operations ll_dir_inode_operations;
683
684 struct page *ll_get_dir_page(struct inode *dir, unsigned long n);
685
686 static inline unsigned ll_dir_rec_len(unsigned name_len)
687 {
688         return (name_len + 8 + LL_DIR_PAD - 1) & ~(LL_DIR_PAD - 1);
689 }
690
691 static inline struct ll_dir_entry *ll_entry_at(void *base, unsigned offset)
692 {
693         return (struct ll_dir_entry *)((char *)base + offset);
694 }
695
696 /*
697  * p is at least 6 bytes before the end of page
698  */
699 static inline struct ll_dir_entry *ll_dir_next_entry(struct ll_dir_entry *p)
700 {
701         return ll_entry_at(p, le16_to_cpu(p->lde_rec_len));
702 }
703
704 static inline void ll_put_page(struct page *page)
705 {
706         kunmap(page);
707         page_cache_release(page);
708 }
709
710 static inline unsigned long dir_pages(struct inode *inode)
711 {
712         return (inode->i_size + CFS_PAGE_SIZE - 1) >> CFS_PAGE_SHIFT;
713 }
714
715 int ll_objects_destroy(struct ptlrpc_request *request, struct inode *dir);
716 struct inode *ll_iget(struct super_block *sb, ino_t hash,
717                       struct lustre_md *lic);
718 int ll_mdc_cancel_unused(struct lustre_handle *, struct inode *, int flags,
719                          void *opaque);
720 int ll_mdc_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
721                         void *data, int flag);
722 int ll_prepare_mdc_op_data(struct mdc_op_data *,
723                            struct inode *i1, struct inode *i2,
724                            const char *name, int namelen, int mode, void *data);
725 #ifndef HAVE_VFS_INTENT_PATCHES
726 struct lookup_intent *ll_convert_intent(struct open_intent *oit,
727                                         int lookup_flags);
728 #endif
729 void ll_pin_extent_cb(void *data);
730 int ll_page_removal_cb(void *data, int discard);
731 int ll_extent_lock_cancel_cb(struct ldlm_lock *lock, struct ldlm_lock_desc *new,
732                              void *data, int flag);
733 int lookup_it_finish(struct ptlrpc_request *request, int offset,
734                      struct lookup_intent *it, void *data);
735 void ll_lookup_finish_locks(struct lookup_intent *it, struct dentry *dentry);
736
737 /* llite/rw.c */
738 int ll_prepare_write(struct file *, struct page *, unsigned from, unsigned to);
739 int ll_commit_write(struct file *, struct page *, unsigned from, unsigned to);
740 int ll_writepage(struct page *page);
741 void ll_inode_fill_obdo(struct inode *inode, int cmd, struct obdo *oa);
742 int ll_ap_completion(void *data, int cmd, struct obdo *oa, int rc);
743 int llap_shrink_cache(struct ll_sb_info *sbi, int shrink_fraction);
744 extern struct cache_definition ll_cache_definition;
745 void ll_removepage(struct page *page);
746 int ll_readpage(struct file *file, struct page *page);
747 struct ll_async_page *llap_cast_private(struct page *page);
748 void ll_readahead_init(struct inode *inode, struct ll_readahead_state *ras);
749 void ll_ra_accounting(struct ll_async_page *llap,struct address_space *mapping);
750 void ll_truncate(struct inode *inode);
751 int ll_file_punch(struct inode *, loff_t, int);
752 ssize_t ll_file_lockless_io(struct file *, const struct iovec *,
753                             unsigned long, loff_t *, int, ssize_t);
754 ssize_t ll_direct_IO(int rw, struct file *file,const struct iovec *iov,
755                      loff_t file_offset, unsigned long nr_segs, int locked);
756 void ll_clear_file_contended(struct inode*);
757 int ll_sync_page_range(struct inode *, struct address_space *, loff_t, size_t);
758
759 /* llite/file.c */
760 extern struct file_operations ll_file_operations;
761 extern struct file_operations ll_file_operations_flock;
762 extern struct file_operations ll_file_operations_noflock;
763 extern struct inode_operations ll_file_inode_operations;
764 extern int ll_inode_revalidate_it(struct dentry *, struct lookup_intent *);
765 extern int ll_have_md_lock(struct inode *inode, __u64 bits, ldlm_mode_t l_req_mode);
766 int ll_region_mapped(unsigned long addr, size_t count);
767 int ll_extent_lock(struct ll_file_data *, struct inode *,
768                    struct lov_stripe_md *, int mode, ldlm_policy_data_t *,
769                    struct lustre_handle *, int ast_flags);
770 int ll_extent_unlock(struct ll_file_data *, struct inode *,
771                      struct lov_stripe_md *, int mode, struct lustre_handle *);
772 int __ll_inode_revalidate_it(struct dentry *, struct lookup_intent *,  __u64 bits);
773 int ll_revalidate_nd(struct dentry *dentry, struct nameidata *nd);
774 int ll_file_open(struct inode *inode, struct file *file);
775 int ll_file_release(struct inode *inode, struct file *file);
776 int ll_lsm_getattr(struct obd_export *, struct lov_stripe_md *, struct obdo *);
777 int ll_glimpse_ioctl(struct ll_sb_info *sbi,
778                      struct lov_stripe_md *lsm, lstat_t *st);
779 int ll_glimpse_size(struct inode *inode, int ast_flags);
780 int ll_local_open(struct file *file,
781                   struct lookup_intent *it, struct ll_file_data *fd,
782                   struct obd_client_handle *och);
783 int ll_release_openhandle(struct dentry *, struct lookup_intent *);
784 int ll_mdc_close(struct obd_export *mdc_exp, struct inode *inode,
785                  struct file *file);
786 int ll_mdc_real_close(struct inode *inode, int flags);
787 extern void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid, struct file
788                                *file, size_t count, int rw);
789 int ll_getattr_it(struct vfsmount *mnt, struct dentry *de,
790                struct lookup_intent *it, struct kstat *stat);
791 int ll_getattr(struct vfsmount *mnt, struct dentry *de, struct kstat *stat);
792 struct ll_file_data *ll_file_data_get(void);
793 #ifndef HAVE_INODE_PERMISION_2ARGS
794 int ll_inode_permission(struct inode *inode, int mask, struct nameidata *nd);
795 #else
796 int ll_inode_permission(struct inode *inode, int mask);
797 #endif
798 int ll_lov_setstripe_ea_info(struct inode *inode, struct file *file,
799                              int flags, struct lov_user_md *lum,
800                              int lum_size);
801 int ll_lov_getstripe_ea_info(struct inode *inode, const char *filename,
802                              struct lov_mds_md **lmm, int *lmm_size,
803                              struct ptlrpc_request **request);
804 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
805                      int set_default);
806 int ll_dir_getstripe(struct inode *inode, struct lov_mds_md **lmm,
807                      int *lmm_size, struct ptlrpc_request **request);
808 int ll_fsync(struct file *file, struct dentry *dentry, int data);
809 int ll_do_fiemap(struct inode *inode, struct ll_user_fiemap *fiemap,
810               int num_bytes);
811
812 /* llite/dcache.c */
813 /* llite/namei.c */
814 /**
815  * protect race ll_find_aliases vs ll_revalidate_it vs ll_unhash_aliases
816  */
817 extern spinlock_t ll_lookup_lock;
818 extern struct dentry_operations ll_d_ops;
819 void ll_intent_drop_lock(struct lookup_intent *);
820 void ll_intent_release(struct lookup_intent *);
821 extern void ll_set_dd(struct dentry *de);
822 int ll_drop_dentry(struct dentry *dentry);
823 void ll_unhash_aliases(struct inode *);
824 void ll_frob_intent(struct lookup_intent **itp, struct lookup_intent *deft);
825 void ll_lookup_finish_locks(struct lookup_intent *it, struct dentry *dentry);
826 int ll_dcompare(struct dentry *parent, struct qstr *d_name, struct qstr *name);
827 int revalidate_it_finish(struct ptlrpc_request *request, int offset,
828                          struct lookup_intent *it, struct dentry *de);
829
830 /* llite/llite_lib.c */
831 extern struct super_operations lustre_super_operations;
832
833 char *ll_read_opt(const char *opt, char *data);
834 void ll_lli_init(struct ll_inode_info *lli);
835 int ll_fill_super(struct super_block *sb);
836 void ll_put_super(struct super_block *sb);
837 void ll_kill_super(struct super_block *sb);
838 int ll_cache_shrink(SHRINKER_FIRST_ARG int nr_to_scan, gfp_t gfp_mask);
839 struct inode *ll_inode_from_lock(struct ldlm_lock *lock);
840 void ll_clear_inode(struct inode *inode);
841 void ll_delete_inode(struct inode *inode);
842 int ll_setattr_raw(struct inode *inode, struct iattr *attr);
843 int ll_setattr(struct dentry *de, struct iattr *attr);
844 #ifndef HAVE_STATFS_DENTRY_PARAM
845 int ll_statfs(struct super_block *sb, struct kstatfs *sfs);
846 #else
847 int ll_statfs(struct dentry *de, struct kstatfs *sfs);
848 #endif
849 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
850                        __u64 max_age, __u32 flags);
851 void ll_update_inode(struct inode *inode, struct lustre_md *md);
852 void ll_read_inode2(struct inode *inode, void *opaque);
853 int ll_iocontrol(struct inode *inode, struct file *file,
854                  unsigned int cmd, unsigned long arg);
855 #ifdef HAVE_UMOUNTBEGIN_VFSMOUNT
856 void ll_umount_begin(struct vfsmount *vfsmnt, int flags);
857 #else
858 void ll_umount_begin(struct super_block *sb);
859 #endif
860 int ll_remount_fs(struct super_block *sb, int *flags, char *data);
861 int ll_show_options(struct seq_file *seq, struct vfsmount *vfs);
862 int ll_prep_inode(struct obd_export *exp, struct inode **inode,
863                   struct ptlrpc_request *req, int offset, struct super_block *);
864 void lustre_dump_dentry(struct dentry *, int recur);
865 void lustre_dump_inode(struct inode *);
866 struct ll_async_page *llite_pglist_next_llap(struct list_head *head,
867                                              struct list_head *list);
868 int ll_obd_statfs(struct inode *inode, void *arg);
869 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *max_mdsize);
870 int ll_process_config(struct lustre_cfg *lcfg);
871
872 /* llite/llite_nfs.c */
873 extern struct export_operations lustre_export_operations;
874 __u32 get_uuid2int(const char *name, int len);
875
876 /* llite/special.c */
877 extern struct inode_operations ll_special_inode_operations;
878 extern struct file_operations ll_special_chr_inode_fops;
879 extern struct file_operations ll_special_chr_file_fops;
880 extern struct file_operations ll_special_blk_inode_fops;
881 extern struct file_operations ll_special_fifo_inode_fops;
882 extern struct file_operations ll_special_fifo_file_fops;
883 extern struct file_operations ll_special_sock_inode_fops;
884
885 /* llite/symlink.c */
886 extern struct inode_operations ll_fast_symlink_inode_operations;
887
888 /* llite/llite_close.c */
889 struct ll_close_queue {
890         spinlock_t              lcq_lock;
891         struct list_head        lcq_list;
892         wait_queue_head_t       lcq_waitq;
893         struct completion       lcq_comp;
894 };
895
896 #ifdef HAVE_CLOSE_THREAD
897 void llap_write_pending(struct inode *inode, struct ll_async_page *llap);
898 void llap_write_complete(struct inode *inode, struct ll_async_page *llap);
899 void ll_open_complete(struct inode *inode);
900 int ll_is_inode_dirty(struct inode *inode);
901 void ll_try_done_writing(struct inode *inode);
902 void ll_queue_done_writing(struct inode *inode);
903 #else
904 static inline void llap_write_pending(struct inode *inode,
905                                       struct ll_async_page *llap) { return; };
906 static inline void llap_write_complete(struct inode *inode,
907                                        struct ll_async_page *llap) { return; };
908 static inline void ll_open_complete(struct inode *inode) { return; };
909 static inline int ll_is_inode_dirty(struct inode *inode) { return 0; };
910 static inline void ll_try_done_writing(struct inode *inode) { return; };
911 static inline void ll_queue_done_writing(struct inode *inode) { return; };
912 //static inline void ll_close_thread_shutdown(struct ll_close_queue *lcq) { return; };
913 //static inline int ll_close_thread_start(struct ll_close_queue **lcq_ret) { return 0; };
914 #endif
915 void ll_close_thread_shutdown(struct ll_close_queue *lcq);
916 int ll_close_thread_start(struct ll_close_queue **lcq_ret);
917
918 /* llite/llite_mmap.c */
919 typedef struct rb_root  rb_root_t;
920 typedef struct rb_node  rb_node_t;
921
922 struct ll_lock_tree_node;
923 struct ll_lock_tree {
924         rb_root_t                       lt_root;
925         struct list_head                lt_locked_list;
926         struct ll_file_data             *lt_fd;
927 };
928
929 int ll_teardown_mmaps(struct address_space *mapping, __u64 first, __u64 last);
930 int ll_file_mmap(struct file * file, struct vm_area_struct * vma);
931 struct ll_lock_tree_node * ll_node_from_inode(struct inode *inode, __u64 start,
932                                               __u64 end, ldlm_mode_t mode);
933 int ll_tree_lock(struct ll_lock_tree *tree,
934                  struct ll_lock_tree_node *first_node,
935                  const char *buf, size_t count, int ast_flags);
936 int ll_tree_lock_iov(struct ll_lock_tree *tree,
937                      struct ll_lock_tree_node *first_node,
938                      const struct iovec *iov, unsigned long nr_segs,
939                      int ast_flags);
940 int ll_tree_unlock(struct ll_lock_tree *tree);
941
942 enum ll_lock_style {
943         LL_LOCK_STYLE_NOLOCK   = 0,
944         LL_LOCK_STYLE_FASTLOCK = 1,
945         LL_LOCK_STYLE_TREELOCK = 2
946 };
947
948 struct ll_thread_data {
949         int ltd_magic;
950         int lock_style;
951         struct list_head *tree_list;
952         union {
953                 struct ll_lock_tree tree;
954                 struct lustre_handle lockh;
955         } u;
956 };
957 struct ll_thread_data *ll_td_get(void);
958 void ll_td_set(struct ll_thread_data *ltd);
959 struct lustre_handle *ltd2lockh(struct ll_thread_data *ltd, __u64 start,
960                                 __u64 end);
961
962 #define    ll_s2sbi(sb)        (s2lsi(sb)->lsi_llsbi)
963
964 static inline __u64 ll_ts2u64(struct timespec *time)
965 {
966         __u64 t = time->tv_sec;
967         return t;
968 }
969
970 /* don't need an addref as the sb_info should be holding one */
971 static inline struct obd_export *ll_s2obdexp(struct super_block *sb)
972 {
973         return ll_s2sbi(sb)->ll_osc_exp;
974 }
975
976 /* don't need an addref as the sb_info should be holding one */
977 static inline struct obd_export *ll_s2mdcexp(struct super_block *sb)
978 {
979         return ll_s2sbi(sb)->ll_mdc_exp;
980 }
981
982 static inline struct client_obd *sbi2mdc(struct ll_sb_info *sbi)
983 {
984         struct obd_device *obd = sbi->ll_mdc_exp->exp_obd;
985         if (obd == NULL)
986                 LBUG();
987         return &obd->u.cli;
988 }
989
990 // FIXME: replace the name of this with LL_SB to conform to kernel stuff
991 static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
992 {
993         return ll_s2sbi(inode->i_sb);
994 }
995
996 static inline struct obd_export *ll_i2obdexp(struct inode *inode)
997 {
998         return ll_s2obdexp(inode->i_sb);
999 }
1000
1001 static inline struct obd_export *ll_i2mdcexp(struct inode *inode)
1002 {
1003         return ll_s2mdcexp(inode->i_sb);
1004 }
1005
1006 /** get lu_fid from inode. */
1007 static inline struct lu_fid *ll_inode_lu_fid(struct inode *inode)
1008 {
1009         return &ll_i2info(inode)->lli_fid.f20;
1010 }
1011
1012 /** get ll_fid from inode. */
1013 static inline struct ll_fid *ll_inode_ll_fid(struct inode *inode)
1014 {
1015         return &ll_i2info(inode)->lli_fid.f16;
1016 }
1017
1018 static inline void ll_inode2fid(struct ll_fid *fid, struct inode *inode)
1019 {
1020         *fid = *ll_inode_ll_fid(inode);
1021 }
1022
1023 static inline int ll_mds_max_easize(struct super_block *sb)
1024 {
1025         return sbi2mdc(ll_s2sbi(sb))->cl_max_mds_easize;
1026 }
1027
1028 static inline __u64 ll_file_maxbytes(struct inode *inode)
1029 {
1030         return ll_i2info(inode)->lli_maxbytes;
1031 }
1032
1033 /* llite/xattr.c */
1034 int ll_setxattr(struct dentry *dentry, const char *name,
1035                 const void *value, size_t size, int flags);
1036 ssize_t ll_getxattr(struct dentry *dentry, const char *name,
1037                     void *buffer, size_t size);
1038 ssize_t ll_listxattr(struct dentry *dentry, char *buffer, size_t size);
1039 int ll_removexattr(struct dentry *dentry, const char *name);
1040
1041 /* statahead.c */
1042
1043 #define LL_SA_RPC_MIN   2
1044 #define LL_SA_RPC_DEF   32
1045 #define LL_SA_RPC_MAX   8192
1046
1047 /* per inode struct, for dir only */
1048 struct ll_statahead_info {
1049         struct inode           *sai_inode;
1050         unsigned int            sai_generation; /* generation for statahead */
1051         atomic_t                sai_refcount;   /* when access this struct, hold
1052                                                  * refcount */
1053         unsigned int            sai_sent;       /* stat requests sent count */
1054         unsigned int            sai_replied;    /* stat requests which received
1055                                                  * reply */
1056         unsigned int            sai_max;        /* max ahead of lookup */
1057         unsigned int            sai_index;      /* index of statahead entry */
1058         unsigned int            sai_index_next; /* index for the next statahead
1059                                                  * entry to be stated */
1060         unsigned int            sai_hit;        /* hit count */
1061         unsigned int            sai_miss;       /* miss count:
1062                                                  * for "ls -al" case, it includes
1063                                                  * hidden dentry miss;
1064                                                  * for "ls -l" case, it does not
1065                                                  * include hidden dentry miss.
1066                                                  * "sai_miss_hidden" is used for
1067                                                  * the later case.
1068                                                  */
1069         unsigned int            sai_consecutive_miss; /* consecutive miss */
1070         unsigned int            sai_miss_hidden;/* "ls -al", but first dentry
1071                                                  * is not a hidden one */
1072         unsigned int            sai_skip_hidden;/* skipped hidden dentry count */
1073         unsigned int            sai_ls_all:1;   /* "ls -al", do stat-ahead for
1074                                                  * hidden entries */
1075         cfs_waitq_t             sai_waitq;      /* stat-ahead wait queue */
1076         struct ptlrpc_thread    sai_thread;     /* stat-ahead thread */
1077         struct list_head        sai_entries_sent;     /* entries sent out */
1078         struct list_head        sai_entries_received; /* entries returned */
1079         struct list_head        sai_entries_stated;   /* entries stated */
1080 };
1081
1082 int do_statahead_enter(struct inode *dir, struct dentry **dentry, int lookup);
1083 void ll_statahead_exit(struct inode *dir, struct dentry *dentry, int result);
1084 void ll_stop_statahead(struct inode *inode, void *key);
1085
1086 static inline
1087 void ll_statahead_mark(struct inode *dir, struct dentry *dentry)
1088 {
1089         struct ll_inode_info  *lli;
1090         struct ll_dentry_data *ldd = ll_d2d(dentry);
1091
1092         /* dentry has been move to other directory, no need mark */
1093         if (unlikely(dir != dentry->d_parent->d_inode))
1094                 return;
1095
1096         lli = ll_i2info(dir);
1097         /* not the same process, don't mark */
1098         if (lli->lli_opendir_pid != cfs_curproc_pid())
1099                 return;
1100
1101         spin_lock(&lli->lli_lock);
1102         if (likely(lli->lli_sai != NULL && ldd != NULL))
1103                 ldd->lld_sa_generation = lli->lli_sai->sai_generation;
1104         spin_unlock(&lli->lli_lock);
1105 }
1106
1107 static inline
1108 int ll_statahead_enter(struct inode *dir, struct dentry **dentryp, int lookup)
1109 {
1110         struct ll_inode_info  *lli;
1111         struct ll_sb_info     *sbi;
1112         struct ll_dentry_data *ldd = ll_d2d(*dentryp);
1113
1114         if (unlikely(dir == NULL))
1115                 return -EAGAIN;
1116
1117         sbi = ll_i2sbi(dir);
1118         /* temporarily disable dir stat ahead in interoperability mode */
1119         if (sbi->ll_mdc_exp->exp_connect_flags & OBD_CONNECT_FID)
1120                 return -ENOTSUPP;
1121
1122         if (sbi->ll_sa_max == 0)
1123                 return -ENOTSUPP;
1124
1125         lli = ll_i2info(dir);
1126         /* not the same process, don't statahead */
1127         if (lli->lli_opendir_pid != cfs_curproc_pid())
1128                 return -EAGAIN;
1129
1130         /*
1131          * When "ls" a dentry, the system trigger more than once "revalidate" or
1132          * "lookup", for "getattr", for "getxattr", and maybe for others.
1133          * Under patchless client mode, the operation intent is not accurate,
1134          * it maybe misguide the statahead thread. For example:
1135          * The "revalidate" call for "getattr" and "getxattr" of a dentry maybe
1136          * have the same operation intent -- "IT_GETATTR".
1137          * In fact, one dentry should has only one chance to interact with the
1138          * statahead thread, otherwise the statahead windows will be confused.
1139          * The solution is as following:
1140          * Assign "lld_sa_generation" with "sai_generation" when a dentry
1141          * "IT_GETATTR" for the first time, and the subsequent "IT_GETATTR"
1142          * will bypass interacting with statahead thread for checking:
1143          * "lld_sa_generation == lli_sai->sai_generation"
1144          */
1145         if (ldd && lli->lli_sai &&
1146             ldd->lld_sa_generation == lli->lli_sai->sai_generation)
1147                 return -EAGAIN;
1148
1149         return do_statahead_enter(dir, dentryp, lookup);
1150 }
1151
1152 static void inline ll_dops_init(struct dentry *de, int block, int init_sa)
1153 {
1154         struct ll_dentry_data *lld = ll_d2d(de);
1155
1156         if (lld == NULL && block != 0) {
1157                 ll_set_dd(de);
1158                 lld = ll_d2d(de);
1159         }
1160
1161         if (lld != NULL && init_sa != 0)
1162                 lld->lld_sa_generation = 0;
1163
1164         de->d_op = &ll_d_ops;
1165 }
1166
1167 /* llite ioctl register support rountine */
1168 #ifdef __KERNEL__
1169 enum llioc_iter {
1170         LLIOC_CONT = 0,
1171         LLIOC_STOP
1172 };
1173
1174 #define LLIOC_MAX_CMD           256
1175
1176 /*
1177  * Rules to write a callback function:
1178  *
1179  * Parameters:
1180  *  @magic: Dynamic ioctl call routine will feed this vaule with the pointer
1181  *      returned to ll_iocontrol_register.  Callback functions should use this
1182  *      data to check the potential collasion of ioctl cmd. If collasion is
1183  *      found, callback function should return LLIOC_CONT.
1184  *  @rcp: The result of ioctl command.
1185  *
1186  *  Return values:
1187  *      If @magic matches the pointer returned by ll_iocontrol_data, the
1188  *      callback should return LLIOC_STOP; return LLIOC_STOP otherwise.
1189  */
1190 typedef enum llioc_iter (*llioc_callback_t)(struct inode *inode,
1191                 struct file *file, unsigned int cmd, unsigned long arg,
1192                 void *magic, int *rcp);
1193
1194 enum llioc_iter ll_iocontrol_call(struct inode *inode, struct file *file,
1195                 unsigned int cmd, unsigned long arg, int *rcp);
1196
1197 /* export functions */
1198 /* Register ioctl block dynamatically for a regular file.
1199  *
1200  * @cmd: the array of ioctl command set
1201  * @count: number of commands in the @cmd
1202  * @cb: callback function, it will be called if an ioctl command is found to
1203  *      belong to the command list @cmd.
1204  *
1205  * Return vaule:
1206  *      A magic pointer will be returned if success;
1207  *      otherwise, NULL will be returned.
1208  * */
1209 void *ll_iocontrol_register(llioc_callback_t cb, int count, unsigned int *cmd);
1210 void ll_iocontrol_unregister(void *magic);
1211
1212 __u64 ll_fid_build_ino(const struct ll_fid *fid, int api32);
1213 __u32 ll_fid_build_gen(struct ll_sb_info *sbi,
1214                        struct ll_fid *fid);
1215
1216 #endif
1217
1218 #endif /* LLITE_INTERNAL_H */