Whamcloud - gitweb
Land b1_4_smallfix onto b1_4 (20041216_1438)
[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  * Copyright (C) 2003 Cluster File Systems, Inc.
5  *
6  * This code is issued under the GNU General Public License.
7  * See the file COPYING in this distribution
8  */
9
10 #ifndef LLITE_INTERNAL_H
11 #define LLITE_INTERNAL_H
12
13 #include <linux/lustre_debug.h>
14
15 extern struct list_head ll_super_blocks;
16 extern spinlock_t ll_sb_lock;
17
18 /* default to about 40meg of readahead on a given system.  That much tied
19  * up in 512k readahead requests serviced at 40ms each is about 1GB/s. */
20 #define SBI_DEFAULT_READAHEAD_MAX (40UL << (20 - PAGE_CACHE_SHIFT))
21 enum ra_stat {
22         RA_STAT_HIT = 0,
23         RA_STAT_MISS,
24         RA_STAT_DISTANT_READPAGE,
25         RA_STAT_MISS_IN_WINDOW,
26         RA_STAT_FAILED_MATCH,
27         RA_STAT_DISCARDED,
28         RA_STAT_ZERO_LEN,
29         RA_STAT_ZERO_WINDOW,
30         RA_STAT_EOF,
31         RA_STAT_MAX_IN_FLIGHT,
32         _NR_RA_STAT,
33 };
34
35 struct ll_ra_info {
36         unsigned long             ra_cur_pages;
37         unsigned long             ra_max_pages;
38         unsigned long             ra_stats[_NR_RA_STAT];
39 };
40
41 struct ll_sb_info {
42         struct list_head          ll_list;
43         /* this protects pglist and ra_info.  It isn't safe to
44          * grab from interrupt contexts */
45         spinlock_t                ll_lock;
46         struct obd_uuid           ll_sb_uuid;
47         struct obd_export        *ll_mdc_exp;
48         struct obd_export        *ll_osc_exp;
49         struct proc_dir_entry*    ll_proc_root;
50         obd_id                    ll_rootino; /* number of root inode */
51
52         struct lustre_mount_data *ll_lmd;
53         char                     *ll_instance;
54
55         int                       ll_flags;
56         struct list_head          ll_conn_chain; /* per-conn chain of SBs */
57
58         struct hlist_head         ll_orphan_dentry_list; /*please don't ask -p*/
59         struct ll_close_queue    *ll_lcq;
60
61         struct lprocfs_stats     *ll_stats; /* lprocfs stats counter */
62
63         unsigned long             ll_async_page_max;
64         unsigned long             ll_async_page_count;
65         unsigned long             ll_pglist_gen;
66         struct list_head          ll_pglist; /* all pages (llap_pglist_item) */
67
68         struct ll_ra_info         ll_ra_info;
69         unsigned int              ll_namelen;
70 };
71
72 struct ll_readahead_state {
73         spinlock_t      ras_lock;
74         unsigned long   ras_last_readpage, ras_consecutive;
75         unsigned long   ras_window_start, ras_window_len;
76         unsigned long   ras_next_readahead;
77
78 };
79
80 extern kmem_cache_t *ll_file_data_slab;
81 struct ll_file_data {
82         struct obd_client_handle fd_mds_och;
83         struct ll_readahead_state fd_ras;
84         __u32 fd_flags;
85 };
86
87 struct lustre_handle;
88 struct lov_stripe_md;
89
90 extern spinlock_t inode_lock;
91
92 extern void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi);
93 extern struct proc_dir_entry *proc_lustre_fs_root;
94
95 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
96 # define hlist_del_init list_del_init
97 #endif
98
99 static inline struct inode *ll_info2i(struct ll_inode_info *lli)
100 {
101 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
102         return &lli->lli_vfs_inode;
103 #else
104         return list_entry(lli, struct inode, u.generic_ip);
105 #endif
106 }
107
108 static inline void ll_i2uctxt(struct ll_uctxt *ctxt, struct inode *i1,
109                               struct inode *i2)
110 {
111         LASSERT(i1);
112         LASSERT(ctxt);
113
114         if (in_group_p(i1->i_gid))
115                 ctxt->gid1 = i1->i_gid;
116         else
117                 ctxt->gid1 = -1;
118
119         if (i2) {
120                 if (in_group_p(i2->i_gid))
121                         ctxt->gid2 = i2->i_gid;
122                 else
123                         ctxt->gid2 = -1;
124         } else
125                 ctxt->gid2 = 0;
126 }
127
128 struct it_cb_data {
129         struct inode *icbd_parent;
130         struct dentry **icbd_childp;
131         obd_id hash;
132 };
133
134 #define LLAP_MAGIC 98764321
135
136 extern kmem_cache_t *ll_async_page_slab;
137 extern size_t ll_async_page_slab_size;
138 struct ll_async_page {
139         int             llap_magic;
140         void            *llap_cookie;
141         struct page     *llap_page;
142         struct list_head llap_pending_write;
143          /* only trust these if the page lock is providing exclusion */
144         unsigned int     llap_write_queued:1,
145                          llap_defer_uptodate:1,
146                          llap_origin:3,
147                          llap_ra_used:1;
148         struct list_head llap_pglist_item;
149 };
150
151 enum {
152         LLAP_ORIGIN_UNKNOWN = 0,
153         LLAP_ORIGIN_READPAGE,
154         LLAP_ORIGIN_READAHEAD,
155         LLAP_ORIGIN_COMMIT_WRITE,
156         LLAP_ORIGIN_WRITEPAGE,
157         LLAP__ORIGIN_MAX,
158 };
159 extern char *llap_origins[];
160
161 /* llite/lproc_llite.c */
162 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
163                                 struct super_block *sb, char *osc, char *mdc);
164 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi);
165
166 /* llite/dir.c */
167 extern struct file_operations ll_dir_operations;
168 extern struct inode_operations ll_dir_inode_operations;
169
170 /* llite/namei.c */
171 int ll_objects_destroy(struct ptlrpc_request *request, struct inode *dir);
172 struct inode *ll_iget(struct super_block *sb, ino_t hash,
173                       struct lustre_md *lic);
174 struct dentry *ll_find_alias(struct inode *, struct dentry *);
175 int ll_mdc_cancel_unused(struct lustre_handle *, struct inode *, int flags,
176                          void *opaque);
177 int ll_mdc_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
178                         void *data, int flag);
179 void ll_prepare_mdc_op_data(struct mdc_op_data *,
180                             struct inode *i1, struct inode *i2,
181                             const char *name, int namelen, int mode);
182
183 /* llite/rw.c */
184 int ll_prepare_write(struct file *, struct page *, unsigned from, unsigned to);
185 int ll_commit_write(struct file *, struct page *, unsigned from, unsigned to);
186 int ll_writepage(struct page *page);
187 void ll_inode_fill_obdo(struct inode *inode, int cmd, struct obdo *oa);
188 void ll_ap_completion(void *data, int cmd, struct obdo *oa, int rc);
189 int llap_shrink_cache(struct ll_sb_info *sbi, int shrink_fraction);
190 void ll_shrink_cache(int priority, unsigned int gfp_mask);
191 void ll_removepage(struct page *page);
192 int ll_readpage(struct file *file, struct page *page);
193 struct ll_async_page *llap_from_cookie(void *cookie);
194 struct ll_async_page *llap_from_page(struct page *page, unsigned origin);
195 struct ll_async_page *llap_cast_private(struct page *page);
196 void ll_readahead_init(struct inode *inode, struct ll_readahead_state *ras);
197 void ll_ra_accounting(struct page *page, struct address_space *mapping);
198 void ll_truncate(struct inode *inode);
199
200 /* llite/file.c */
201 extern struct file_operations ll_file_operations;
202 extern struct inode_operations ll_file_inode_operations;
203 extern int ll_inode_revalidate_it(struct dentry *, struct lookup_intent *);
204 int ll_extent_lock(struct ll_file_data *, struct inode *,
205                    struct lov_stripe_md *, int mode, ldlm_policy_data_t *,
206                    struct lustre_handle *, int ast_flags);
207 int ll_extent_unlock(struct ll_file_data *, struct inode *,
208                      struct lov_stripe_md *, int mode, struct lustre_handle *);
209 int ll_file_open(struct inode *inode, struct file *file);
210 int ll_file_release(struct inode *inode, struct file *file);
211 int ll_lsm_getattr(struct obd_export *, struct lov_stripe_md *, struct obdo *);
212 int ll_glimpse_size(struct inode *inode);
213 int ll_local_open(struct file *file, struct lookup_intent *it);
214 int ll_mdc_close(struct obd_export *mdc_exp, struct inode *inode,
215                  struct file *file);
216 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
217 int ll_getattr(struct vfsmount *mnt, struct dentry *de,
218                struct lookup_intent *it, struct kstat *stat);
219 #endif
220
221 /* llite/dcache.c */
222 void ll_intent_drop_lock(struct lookup_intent *);
223 void ll_intent_release(struct lookup_intent *);
224 extern void ll_set_dd(struct dentry *de);
225 void ll_unhash_aliases(struct inode *);
226 void ll_frob_intent(struct lookup_intent **itp, struct lookup_intent *deft);
227 void ll_lookup_finish_locks(struct lookup_intent *it, struct dentry *dentry);
228
229 /* llite/llite_lib.c */
230
231 extern struct super_operations lustre_super_operations;
232
233 char *ll_read_opt(const char *opt, char *data);
234 int ll_set_opt(const char *opt, char *data, int fl);
235 void ll_options(char *options, char **ost, char **mds, int *flags);
236 void ll_lli_init(struct ll_inode_info *lli);
237 int ll_fill_super(struct super_block *sb, void *data, int silent);
238 int lustre_fill_super(struct super_block *sb, void *data, int silent);
239 void lustre_put_super(struct super_block *sb);
240 struct inode *ll_inode_from_lock(struct ldlm_lock *lock);
241 void ll_clear_inode(struct inode *inode);
242 int ll_setattr_raw(struct inode *inode, struct iattr *attr);
243 int ll_setattr(struct dentry *de, struct iattr *attr);
244 int ll_statfs(struct super_block *sb, struct kstatfs *sfs);
245 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
246                        unsigned long maxage);
247 void ll_update_inode(struct inode *inode, struct mds_body *body,
248                      struct lov_stripe_md *lsm);
249 void ll_read_inode2(struct inode *inode, void *opaque);
250 int ll_iocontrol(struct inode *inode, struct file *file,
251                  unsigned int cmd, unsigned long arg);
252 void ll_umount_begin(struct super_block *sb);
253 int ll_prep_inode(struct obd_export *exp, struct inode **inode,
254                   struct ptlrpc_request *req, int offset, struct super_block *);
255 void lustre_dump_dentry(struct dentry *, int recur);
256 void lustre_dump_inode(struct inode *);
257 struct ll_async_page *llite_pglist_next_llap(struct ll_sb_info *sbi,
258                                              struct list_head *list);
259
260 /* llite/llite_nfs.c */
261 __u32 get_uuid2int(const char *name, int len);
262 struct dentry *ll_fh_to_dentry(struct super_block *sb, __u32 *data, int len,
263                                int fhtype, int parent);
264 int ll_dentry_to_fh(struct dentry *, __u32 *datap, int *lenp, int need_parent);
265
266 /* llite/special.c */
267 extern struct inode_operations ll_special_inode_operations;
268 extern struct file_operations ll_special_chr_inode_fops;
269 extern struct file_operations ll_special_chr_file_fops;
270 extern struct file_operations ll_special_blk_inode_fops;
271 extern struct file_operations ll_special_fifo_inode_fops;
272 extern struct file_operations ll_special_fifo_file_fops;
273 extern struct file_operations ll_special_sock_inode_fops;
274
275 /* llite/symlink.c */
276 extern struct inode_operations ll_fast_symlink_inode_operations;
277
278 /* llite/llite_close.c */
279 struct ll_close_queue {
280         spinlock_t              lcq_lock;
281         struct list_head        lcq_list;
282         wait_queue_head_t       lcq_waitq;
283         struct completion       lcq_comp;
284 };
285
286 void llap_write_pending(struct inode *inode, struct ll_async_page *llap);
287 void llap_write_complete(struct inode *inode, struct ll_async_page *llap);
288 void ll_open_complete(struct inode *inode);
289 int ll_is_inode_dirty(struct inode *inode);
290 void ll_try_done_writing(struct inode *inode);
291 void ll_queue_done_writing(struct inode *inode);
292 void ll_close_thread_shutdown(struct ll_close_queue *lcq);
293 int ll_close_thread_start(struct ll_close_queue **lcq_ret);
294
295 #define LL_SBI_NOLCK            0x1
296
297 #define LL_MAX_BLKSIZE          (4UL * 1024 * 1024)
298
299 #if  (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
300 #define    ll_s2sbi(sb)     ((struct ll_sb_info *)((sb)->s_fs_info))
301 void __d_rehash(struct dentry * entry, int lock);
302 static inline __u64 ll_ts2u64(struct timespec *time)
303 {
304         __u64 t = time->tv_sec;
305         return t;
306 }
307 #else  /* 2.4 here */
308 #define    ll_s2sbi(sb)     ((struct ll_sb_info *)((sb)->u.generic_sbp))
309 static inline __u64 ll_ts2u64(time_t *time)
310 {
311         return *time;
312 }
313 #endif
314
315 /* don't need an addref as the sb_info should be holding one */
316 static inline struct obd_export *ll_s2obdexp(struct super_block *sb)
317 {
318         return ll_s2sbi(sb)->ll_osc_exp;
319 }
320
321 /* don't need an addref as the sb_info should be holding one */
322 static inline struct obd_export *ll_s2mdcexp(struct super_block *sb)
323 {
324         return ll_s2sbi(sb)->ll_mdc_exp;
325 }
326
327 static inline struct client_obd *sbi2mdc(struct ll_sb_info *sbi)
328 {
329         struct obd_device *obd = sbi->ll_mdc_exp->exp_obd;
330         if (obd == NULL)
331                 LBUG();
332         return &obd->u.cli;
333 }
334
335 // FIXME: replace the name of this with LL_SB to conform to kernel stuff
336 static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
337 {
338         return ll_s2sbi(inode->i_sb);
339 }
340
341 static inline struct obd_export *ll_i2obdexp(struct inode *inode)
342 {
343         return ll_s2obdexp(inode->i_sb);
344 }
345
346 static inline struct obd_export *ll_i2mdcexp(struct inode *inode)
347 {
348         return ll_s2mdcexp(inode->i_sb);
349 }
350
351 static inline void ll_inode2fid(struct ll_fid *fid, struct inode *inode)
352 {
353         mdc_pack_fid(fid, inode->i_ino, inode->i_generation,
354                      inode->i_mode & S_IFMT);
355 }
356
357 static inline int ll_mds_max_easize(struct super_block *sb)
358 {
359         return sbi2mdc(ll_s2sbi(sb))->cl_max_mds_easize;
360 }
361
362 static inline __u64 ll_file_maxbytes(struct inode *inode)
363 {
364         return ll_i2info(inode)->lli_maxbytes;
365 }
366
367 #endif /* LLITE_INTERNAL_H */