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