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