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