Whamcloud - gitweb
- unland b_fid to HEAD
[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 /* default to about 40meg of readahead on a given system.  That much tied
14  * up in 512k readahead requests serviced at 40ms each is about 1GB/s. */
15 #define SBI_DEFAULT_RA_MAX ((40 << 20) >> PAGE_CACHE_SHIFT)
16
17 enum ra_stat {
18         RA_STAT_HIT = 0,
19         RA_STAT_MISS,
20         RA_STAT_DISTANT_READPAGE,
21         RA_STAT_MISS_IN_WINDOW,
22         RA_STAT_FAILED_MATCH,
23         RA_STAT_DISCARDED,
24         RA_STAT_ZERO_LEN,
25         RA_STAT_ZERO_WINDOW,
26         RA_STAT_EOF,
27         RA_STAT_MAX_IN_FLIGHT,
28         _NR_RA_STAT,
29 };
30
31 struct ll_ra_info {
32         unsigned long             ra_cur_pages;
33         unsigned long             ra_max_pages;
34         unsigned long             ra_stats[_NR_RA_STAT];
35 };
36
37 struct ll_sb_info {
38         /* this protects pglist and ra_info.  It isn't safe to 
39         * grab from interrupt contexts */
40         spinlock_t                ll_lock;
41         struct obd_uuid           ll_sb_uuid;
42         struct obd_export        *ll_mdc_exp;
43         struct obd_export        *ll_osc_exp;
44         struct proc_dir_entry*    ll_proc_root;
45         obd_id                    ll_rootino; /* number of root inode */
46
47         struct lustre_mount_data *ll_lmd;
48         char                     *ll_instance;
49
50         int                       ll_flags;
51         struct list_head          ll_conn_chain; /* per-conn chain of SBs */
52
53         struct hlist_head         ll_orphan_dentry_list; /*please don't ask -p*/
54         struct ll_close_queue    *ll_lcq;
55
56         struct lprocfs_stats     *ll_stats; /* lprocfs stats counter */
57
58         unsigned long             ll_pglist_gen;
59         struct list_head          ll_pglist;
60
61         struct ll_ra_info         ll_ra_info;
62                                                                                                                                                                                                      
63         /* times spent waiting for locks in each call site.  These are
64          * all protected by the ll_lock */
65         struct obd_service_time   ll_read_stime;
66         struct obd_service_time   ll_write_stime;
67         struct obd_service_time   ll_grouplock_stime;
68         struct obd_service_time   ll_seek_stime;
69         struct obd_service_time   ll_setattr_stime;
70         struct obd_service_time   ll_brw_stime;
71 //      struct obd_service_time   ll_done_stime;
72
73         int                       ll_config_version; /* last-applied update */
74
75         /* list of GNS mounts; protected by the dcache_lock */
76         struct list_head          ll_mnt_list;
77
78         struct semaphore          ll_gns_sem;
79         wait_queue_head_t         ll_gns_waitq;
80         struct completion         ll_gns_completion;
81         int                       ll_gns_state;
82         struct timer_list         ll_gns_timer;
83         struct list_head          ll_gns_sbi_head;
84 };
85
86 #define LL_GNS_STATE_IDLE     1100
87 #define LL_GNS_STATE_MOUNTING 1101
88 #define LL_GNS_STATE_FINISHED 1102
89
90 struct ll_readahead_state {
91         spinlock_t      ras_lock;
92         unsigned long   ras_last_readpage, ras_consecutive;
93         unsigned long   ras_window_start, ras_window_len;
94         unsigned long   ras_next_readahead;
95
96 };
97
98 extern kmem_cache_t *ll_file_data_slab;
99 struct lustre_handle;
100 struct ll_file_data {
101         struct obd_client_handle fd_mds_och;
102         struct ll_readahead_state fd_ras;
103         __u32 fd_flags;
104         struct lustre_handle fd_cwlockh;
105         unsigned long fd_gid;
106 };
107
108 struct lov_stripe_md;
109
110 extern spinlock_t inode_lock;
111
112 extern void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi);
113 extern struct proc_dir_entry *proc_lustre_fs_root;
114
115 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
116 # define hlist_del_init list_del_init
117 #endif
118
119 static inline struct inode *ll_info2i(struct ll_inode_info *lli)
120 {
121 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
122         return &lli->lli_vfs_inode;
123 #else
124         return list_entry(lli, struct inode, u.generic_ip);
125 #endif
126 }
127
128
129 struct it_cb_data {
130         struct inode *icbd_parent;
131         struct dentry **icbd_childp;
132         obd_id hash;
133 };
134
135 #define LLAP_MAGIC 98764321
136
137 struct ll_async_page {
138         int             llap_magic;
139         void            *llap_cookie;
140         struct page     *llap_page;
141         struct list_head llap_pending_write;
142          /* only trust these if the page lock is providing exclusion */
143         unsigned         llap_write_queued:1,
144                          llap_defer_uptodate:1,
145                          llap_ra_used:1;
146
147         struct list_head llap_proc_item;
148 };
149
150 #define LL_CDEBUG_PAGE(mask, page, fmt, arg...)                         \
151         CDEBUG(mask, "page %p map %p ind %lu priv %0lx: " fmt,          \
152                page, page->mapping, page->index, page->private, ## arg)
153
154 /* llite/lproc_llite.c */
155 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
156                                 struct super_block *sb, char *osc, char *mdc);
157 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi);
158
159 /* llite/dir.c */
160 extern struct file_operations ll_dir_operations;
161 extern struct inode_operations ll_dir_inode_operations;
162
163 /* llite/namei.c */
164 int ll_objects_destroy(struct ptlrpc_request *request, 
165                        struct inode *dir, int offset);
166 struct inode *ll_iget(struct super_block *sb, ino_t hash,
167                       struct lustre_md *lic);
168 struct dentry *ll_find_alias(struct inode *, struct dentry *);
169 int ll_mdc_cancel_unused(struct lustre_handle *, struct inode *, int flags,
170                          void *opaque);
171 int ll_mdc_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
172                         void *data, int flag);
173 /* llite/rw.c */
174 int ll_prepare_write(struct file *, struct page *, unsigned from, unsigned to);
175 int ll_commit_write(struct file *, struct page *, unsigned from, unsigned to);
176 int ll_writepage(struct page *page);
177 void ll_inode_fill_obdo(struct inode *inode, int cmd, struct obdo *oa);
178 void ll_ap_completion(void *data, int cmd, struct obdo *oa, int rc);
179 void ll_removepage(struct page *page);
180 int ll_readpage(struct file *file, struct page *page);
181 struct ll_async_page *llap_from_cookie(void *cookie);
182 struct ll_async_page *llap_from_page(struct page *page);
183 struct ll_async_page *llap_cast_private(struct page *page);
184 void ll_readahead_init(struct inode *inode, struct ll_readahead_state *ras);
185
186 void ll_ra_accounting(struct page *page, struct address_space *mapping);
187 void ll_truncate(struct inode *inode);
188
189 /* llite/file.c */
190 extern struct file_operations ll_file_operations;
191 extern struct inode_operations ll_file_inode_operations;
192 extern int ll_inode_revalidate_it(struct dentry *, struct lookup_intent *);
193 int ll_refresh_lsm(struct inode *inode, struct lov_stripe_md *lsm);
194 int ll_extent_lock(struct ll_file_data *, struct inode *,
195                    struct lov_stripe_md *, int mode, ldlm_policy_data_t *,
196                    struct lustre_handle *, int ast_flags,
197                    struct obd_service_time *);
198 int ll_extent_unlock(struct ll_file_data *, struct inode *,
199                      struct lov_stripe_md *, int mode, struct lustre_handle *);
200 int ll_file_open(struct inode *inode, struct file *file);
201 int ll_file_release(struct inode *inode, struct file *file);
202 int ll_lsm_getattr(struct obd_export *, struct lov_stripe_md *, struct obdo *);
203 int ll_glimpse_size(struct inode *inode);
204 int ll_local_open(struct file *file, struct lookup_intent *it);
205 int ll_mdc_close(struct obd_export *mdc_exp, struct inode *inode,
206                  struct file *file);
207 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
208 int ll_getattr(struct vfsmount *mnt, struct dentry *de,
209                struct lookup_intent *it, struct kstat *stat);
210 #endif
211 void ll_stime_record(struct ll_sb_info *sbi, struct timeval *start,
212                      struct obd_service_time *stime);
213
214 /* llite/dcache.c */
215 void ll_intent_drop_lock(struct lookup_intent *);
216 void ll_intent_release(struct lookup_intent *);
217 extern void ll_set_dd(struct dentry *de);
218 void ll_unhash_aliases(struct inode *);
219 void ll_frob_intent(struct lookup_intent **itp, struct lookup_intent *deft);
220 void ll_lookup_finish_locks(struct lookup_intent *it, struct dentry *dentry);
221 int revalidate_it_finish(struct ptlrpc_request *request, int offset,
222                          struct lookup_intent *it, struct dentry *de);
223
224
225 /* llite/llite_gns.c */
226 int ll_finish_gns(struct ll_sb_info *sbi);
227 int fill_page_with_path(struct dentry *, struct vfsmount *, char **pagep);
228 int ll_dir_process_mount_object(struct dentry *, struct vfsmount *);
229 int ll_gns_umount_all(struct ll_sb_info *sbi, int timeout);
230 void ll_gns_timer_callback(unsigned long data);
231 void ll_gns_add_timer(struct ll_sb_info *sbi);
232 void ll_gns_del_timer(struct ll_sb_info *sbi);
233 int ll_gns_start_thread(void);
234 void ll_gns_stop_thread(void);
235
236 /* llite/llite_lib.c */
237 extern struct super_operations lustre_super_operations;
238
239 char *ll_read_opt(const char *opt, char *data);
240 int ll_set_opt(const char *opt, char *data, int fl);
241 void ll_options(char *options, char **ost, char **mds, int *flags);
242 void ll_lli_init(struct ll_inode_info *lli);
243 int ll_fill_super(struct super_block *sb, void *data, int silent);
244 int lustre_fill_super(struct super_block *sb, void *data, int silent);
245 void lustre_put_super(struct super_block *sb);
246 struct inode *ll_inode_from_lock(struct ldlm_lock *lock);
247 void ll_clear_inode(struct inode *inode);
248 int ll_attr2inode(struct inode *inode, struct iattr *attr, int trunc);
249 int ll_setattr_raw(struct inode *inode, struct iattr *attr);
250 int ll_setattr(struct dentry *de, struct iattr *attr);
251 int ll_statfs(struct super_block *sb, struct kstatfs *sfs);
252 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
253                        unsigned long maxage);
254 void ll_update_inode(struct inode *inode, struct lustre_md *);
255 int it_disposition(struct lookup_intent *it, int flag);
256 void it_set_disposition(struct lookup_intent *it, int flag);
257 void ll_read_inode2(struct inode *inode, void *opaque);
258 void ll_delete_inode(struct inode *inode);
259 int ll_iocontrol(struct inode *inode, struct file *file,
260                  unsigned int cmd, unsigned long arg);
261 void ll_umount_begin(struct super_block *sb);
262 int ll_prep_inode(struct obd_export *, struct obd_export *, struct inode **inode,
263                   struct ptlrpc_request *req, int offset, struct super_block *);
264 __u32 get_uuid2int(const char *name, int len);
265 struct dentry *ll_fh_to_dentry(struct super_block *sb, __u32 *data, int len,
266                                int fhtype, int parent);
267 int ll_dentry_to_fh(struct dentry *, __u32 *datap, int *lenp, int need_parent);
268 int null_if_equal(struct ldlm_lock *lock, void *data);
269 int ll_process_config_update(struct ll_sb_info *sbi, int clean);
270
271 /* llite/special.c */
272 extern struct inode_operations ll_special_inode_operations;
273 extern struct file_operations ll_special_chr_inode_fops;
274 extern struct file_operations ll_special_chr_file_fops;
275 extern struct file_operations ll_special_blk_inode_fops;
276 extern struct file_operations ll_special_fifo_inode_fops;
277 extern struct file_operations ll_special_fifo_file_fops;
278 extern struct file_operations ll_special_sock_inode_fops;
279
280 /* llite/symlink.c */
281 extern struct inode_operations ll_fast_symlink_inode_operations;
282
283 /* llite/llite_close.c */
284 struct ll_close_queue {
285         spinlock_t              lcq_lock;
286         struct list_head        lcq_list;
287         wait_queue_head_t       lcq_waitq;
288         struct completion       lcq_comp;
289 };
290
291 void llap_write_pending(struct inode *inode, struct ll_async_page *llap);
292 void llap_write_complete(struct inode *inode, struct ll_async_page *llap);
293 void ll_open_complete(struct inode *inode);
294 int ll_is_inode_dirty(struct inode *inode);
295 void ll_try_done_writing(struct inode *inode);
296 void ll_queue_done_writing(struct inode *inode);
297 void ll_close_thread_shutdown(struct ll_close_queue *lcq);
298 int ll_close_thread_start(struct ll_close_queue **lcq_ret);
299
300
301 /* llite/llite_mmap.c */
302 #if  (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
303 typedef struct rb_root  rb_root_t;
304 typedef struct rb_node  rb_node_t;
305 #endif
306
307 struct ll_lock_tree_node;
308 struct ll_lock_tree {
309         rb_root_t                       lt_root;
310         struct list_head                lt_locked_list;
311         struct ll_file_data             *lt_fd;
312 };
313 int ll_teardown_mmaps(struct address_space *mapping, __u64 first,
314                       __u64 last);
315 int ll_file_mmap(struct file * file, struct vm_area_struct * vma);
316 struct ll_lock_tree_node * ll_node_from_inode(struct inode *inode, __u64 start,
317                                               __u64 end, ldlm_mode_t mode);
318 int ll_tree_lock(struct ll_lock_tree *tree,
319                  struct ll_lock_tree_node *first_node, struct inode *inode,
320                  const char *buf, size_t count, int ast_flags);
321 int ll_tree_unlock(struct ll_lock_tree *tree, struct inode *inode);
322
323
324
325
326
327 /* generic */
328 #define LL_SBI_NOLCK           0x1
329 #define LL_SBI_READAHEAD       0x2
330 #define LL_SUPER_MAGIC         0x0BD00BD0
331 #define LL_MAX_BLKSIZE         (4UL * 1024 * 1024)
332
333 #if  (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
334 #define    ll_s2sbi(sb)        ((struct ll_sb_info *)((sb)->s_fs_info))
335 #define    ll_set_sbi(sb, sbi) ((sb)->s_fs_info = sbi)
336 void __d_rehash(struct dentry * entry, int lock);
337 static inline __u64 ll_ts2u64(struct timespec *time)
338 {
339         __u64 t = time->tv_sec;
340         return t;
341 }
342 #else  /* 2.4 here */
343 #define    ll_s2sbi(sb)        ((struct ll_sb_info *)((sb)->u.generic_sbp))
344 #define    ll_set_sbi(sb, sbi) ((sb)->u.generic_sbp = sbi)
345 static inline __u64 ll_ts2u64(time_t *time)
346 {
347         return *time;
348 }
349 #endif
350
351 /* don't need an addref as the sb_info should be holding one */
352 static inline struct obd_export *ll_s2obdexp(struct super_block *sb)
353 {
354         return ll_s2sbi(sb)->ll_osc_exp;
355 }
356
357 /* don't need an addref as the sb_info should be holding one */
358 static inline struct obd_export *ll_s2mdcexp(struct super_block *sb)
359 {
360         return ll_s2sbi(sb)->ll_mdc_exp;
361 }
362
363 static inline struct client_obd *sbi2mdc(struct ll_sb_info *sbi)
364 {
365         struct obd_device *obd = sbi->ll_mdc_exp->exp_obd;
366         if (obd == NULL)
367                 LBUG();
368         return &obd->u.cli;
369 }
370
371 // FIXME: replace the name of this with LL_SB to conform to kernel stuff
372 static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
373 {
374         return ll_s2sbi(inode->i_sb);
375 }
376
377 static inline struct obd_export *ll_i2obdexp(struct inode *inode)
378 {
379         return ll_s2obdexp(inode->i_sb);
380 }
381
382 static inline struct obd_export *ll_i2mdcexp(struct inode *inode)
383 {
384         return ll_s2mdcexp(inode->i_sb);
385 }
386
387 static inline int ll_mds_max_easize(struct super_block *sb)
388 {
389         return sbi2mdc(ll_s2sbi(sb))->cl_max_mds_easize;
390 }
391
392 static inline __u64 ll_file_maxbytes(struct inode *inode)
393 {
394         return ll_i2info(inode)->lli_maxbytes;
395 }
396
397 #endif /* LLITE_INTERNAL_H */