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