Whamcloud - gitweb
land lustre part of b_hd_sec on 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 /* after roughly how long should we remove an inactive mount? */
38 #define GNS_MOUNT_TIMEOUT 120
39
40 /* how often should the GNS timer look for mounts to cleanup? */
41 #define GNS_TICK_TIMEOUT  1
42
43 /* how many times GNS will try to wait for 1 second for mount */
44 #define GNS_WAIT_ATTEMPTS 10
45
46 struct ll_sb_info {
47         /* this protects pglist and max_r_a_pages.  It isn't safe to grab from
48          * interrupt contexts. */
49         spinlock_t                ll_lock;
50         
51         struct obd_uuid           ll_sb_uuid;
52         struct obd_export        *ll_md_exp;
53         struct obd_export        *ll_dt_exp;
54         struct lov_desc           ll_dt_desc;
55         struct proc_dir_entry    *ll_proc_root;
56         struct lustre_id          ll_rootid;     /* root lustre id */
57
58         struct lustre_mount_data *ll_lmd;
59         char                     *ll_instance;
60
61         int                       ll_flags;
62         struct list_head          ll_conn_chain; /* per-conn chain of SBs */
63
64         struct hlist_head         ll_orphan_dentry_list; /*please don't ask -p*/
65         struct ll_close_queue    *ll_lcq;
66
67         struct lprocfs_stats     *ll_stats;      /* lprocfs stats counter */
68
69         unsigned long             ll_pglist_gen;
70         struct list_head          ll_pglist;
71
72         struct ll_ra_info         ll_ra_info;
73                                                                                                                                                                                                      
74         /* times spent waiting for locks in each call site.  These are
75          * all protected by the ll_lock */
76         struct obd_service_time   ll_read_stime;
77         struct obd_service_time   ll_write_stime;
78         struct obd_service_time   ll_grouplock_stime;
79         struct obd_service_time   ll_seek_stime;
80         struct obd_service_time   ll_setattr_stime;
81         struct obd_service_time   ll_brw_stime;
82 //      struct obd_service_time   ll_done_stime;
83
84         int                       ll_config_version; /* last-applied update */
85
86         /* list of GNS mounts; protected by the dcache_lock */
87         struct list_head          ll_mnt_list;
88
89         struct semaphore          ll_gns_sem;
90         spinlock_t                ll_gns_lock;
91         wait_queue_head_t         ll_gns_waitq;
92         int                       ll_gns_state;
93         struct timer_list         ll_gns_timer;
94         struct list_head          ll_gns_sbi_head;
95
96         unsigned long             ll_gns_tick;
97         unsigned long             ll_gns_timeout;
98         struct completion         ll_gns_mount_finished;
99
100         /* path to upcall */
101         char                      ll_gns_upcall[PATH_MAX];
102
103         /* mount object entry name */
104         char                      ll_gns_oname[PATH_MAX];
105 };
106
107 struct ll_gns_ctl {
108         struct completion gc_starting;
109         struct completion gc_finishing;
110 };
111
112 /* mounting states */
113 #define LL_GNS_IDLE               (1 << 0)
114 #define LL_GNS_MOUNTING           (1 << 1)
115 #define LL_GNS_FINISHED           (1 << 2)
116
117 /* mounts checking flags */
118 #define LL_GNS_UMOUNT             (1 << 0)
119 #define LL_GNS_CHECK              (1 << 1)
120
121 struct ll_readahead_state {
122         spinlock_t      ras_lock;
123         unsigned long   ras_last_readpage, ras_consecutive;
124         unsigned long   ras_window_start, ras_window_len;
125         unsigned long   ras_next_readahead;
126
127 };
128
129 extern kmem_cache_t *ll_file_data_slab;
130 extern kmem_cache_t *ll_intent_slab;
131 struct lustre_handle;
132 struct ll_file_data {
133         struct obd_client_handle fd_mds_och;
134         struct ll_readahead_state fd_ras;
135         __u32 fd_flags;
136         struct lustre_handle fd_cwlockh;
137         unsigned long fd_gid;
138 };
139
140 struct lov_stripe_md;
141
142 extern spinlock_t inode_lock;
143
144 extern void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi);
145 extern struct proc_dir_entry *proc_lustre_fs_root;
146
147 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
148 # define hlist_del_init list_del_init
149 #endif
150
151 static inline struct inode *ll_info2i(struct ll_inode_info *lli)
152 {
153 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
154         return &lli->lli_vfs_inode;
155 #else
156         return list_entry(lli, struct inode, u.generic_ip);
157 #endif
158 }
159
160
161 struct it_cb_data {
162         struct inode *icbd_parent;
163         struct dentry **icbd_childp;
164         obd_id hash;
165 };
166
167 #define LLAP_MAGIC 98764321
168
169 struct ll_async_page {
170         int             llap_magic;
171         void            *llap_cookie;
172         struct page     *llap_page;
173         struct list_head llap_pending_write;
174          /* only trust these if the page lock is providing exclusion */
175         unsigned         llap_write_queued:1,
176                          llap_defer_uptodate:1,
177                          llap_ra_used:1;
178
179         struct list_head llap_proc_item;
180 };
181
182 #define LL_CDEBUG_PAGE(mask, page, fmt, arg...)                         \
183         CDEBUG(mask, "page %p map %p ind %lu priv %0lx: " fmt,          \
184                page, page->mapping, page->index, page->private, ## arg)
185
186 /* llite/lproc_llite.c */
187 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
188                                 struct super_block *sb, char *lov,
189                                 char *lmv);
190 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi);
191
192 /* llite/dir.c */
193 extern struct file_operations ll_dir_operations;
194 extern struct inode_operations ll_dir_inode_operations;
195
196 /* llite/namei.c */
197 int ll_objects_destroy(struct ptlrpc_request *request, 
198                        struct inode *dir, int offset);
199 struct inode *ll_iget(struct super_block *sb, ino_t hash,
200                       struct lustre_md *lic);
201 struct dentry *ll_find_alias(struct inode *, struct dentry *);
202 int ll_mdc_cancel_unused(struct lustre_handle *, struct inode *, int flags,
203                          void *opaque);
204 int ll_mdc_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
205                         void *data, int flag);
206 /* llite/rw.c */
207 int ll_prepare_write(struct file *, struct page *, unsigned from, unsigned to);
208 int ll_commit_write(struct file *, struct page *, unsigned from, unsigned to);
209 int ll_writepage(struct page *page);
210 void ll_inode_fill_obdo(struct inode *inode, int cmd, struct obdo *oa);
211 void ll_ap_completion(void *data, int cmd, struct obdo *oa, int rc);
212 void ll_removepage(struct page *page);
213 int ll_readpage(struct file *file, struct page *page);
214 struct ll_async_page *llap_from_cookie(void *cookie);
215 struct ll_async_page *llap_from_page(struct page *page);
216 struct ll_async_page *llap_cast_private(struct page *page);
217 void ll_readahead_init(struct inode *inode, struct ll_readahead_state *ras);
218
219 void ll_ra_accounting(struct page *page, struct address_space *mapping);
220 void ll_truncate(struct inode *inode);
221
222 /* llite/file.c */
223 extern struct file_operations ll_file_operations;
224 extern struct inode_operations ll_file_inode_operations;
225 extern int ll_inode_revalidate_it(struct dentry *);
226 extern int ll_setxattr(struct dentry *, const char *, const void *,
227                        size_t, int);
228 extern int ll_getxattr(struct dentry *, const char *, void *, size_t);
229 extern int ll_listxattr(struct dentry *, char *, size_t);
230 extern int ll_removexattr(struct dentry *, const char *);
231 extern int ll_inode_permission(struct inode *, int, struct nameidata *);
232 int ll_refresh_lsm(struct inode *inode, struct lov_stripe_md *lsm);
233 int ll_extent_lock(struct ll_file_data *, struct inode *,
234                    struct lov_stripe_md *, int mode, ldlm_policy_data_t *,
235                    struct lustre_handle *, int ast_flags,
236                    struct obd_service_time *);
237 int ll_extent_unlock(struct ll_file_data *, struct inode *,
238                      struct lov_stripe_md *, int mode, struct lustre_handle *);
239 int ll_file_open(struct inode *inode, struct file *file);
240 int ll_file_release(struct inode *inode, struct file *file);
241 int ll_lsm_getattr(struct obd_export *, struct lov_stripe_md *, struct obdo *);
242 int ll_glimpse_size(struct inode *inode);
243 int ll_local_open(struct file *file, struct lookup_intent *it);
244 int ll_md_close(struct obd_export *md_exp, struct inode *inode,
245                  struct file *file);
246 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
247 int ll_getattr(struct vfsmount *mnt, struct dentry *de, struct kstat *stat);
248 #endif
249 void ll_stime_record(struct ll_sb_info *sbi, struct timeval *start,
250                      struct obd_service_time *stime);
251
252 /* llite/dcache.c */
253 void ll_intent_drop_lock(struct lookup_intent *);
254 void ll_intent_release(struct lookup_intent *);
255 int ll_intent_alloc(struct lookup_intent *);
256 void ll_intent_free(struct lookup_intent *it);
257 extern void ll_set_dd(struct dentry *de);
258 void ll_unhash_aliases(struct inode *);
259 void ll_frob_intent(struct lookup_intent **itp, struct lookup_intent *deft);
260 void ll_lookup_finish_locks(struct lookup_intent *it, struct dentry *dentry);
261 int revalidate_it_finish(struct ptlrpc_request *request, int offset,
262                          struct lookup_intent *it, struct dentry *de);
263
264
265 /* llite/llite_gns.c */
266 int ll_gns_start_thread(void);
267 void ll_gns_stop_thread(void);
268
269 int ll_gns_mount_object(struct dentry *dentry,
270                         struct vfsmount *mnt);
271 int ll_gns_umount_object(struct vfsmount *mnt);
272
273 int ll_gns_check_mounts(struct ll_sb_info *sbi,
274                         int flags);
275
276 void ll_gns_timer_callback(unsigned long data);
277 void ll_gns_add_timer(struct ll_sb_info *sbi);
278 void ll_gns_del_timer(struct ll_sb_info *sbi);
279
280 /* llite/llite_lib.c */
281 extern struct super_operations lustre_super_operations;
282
283 char *ll_read_opt(const char *opt, char *data);
284 int ll_set_opt(const char *opt, char *data, int fl);
285 void ll_options(char *options, char **ost, char **mds, char **sec, int *flags);
286 void ll_lli_init(struct ll_inode_info *lli);
287 int ll_fill_super(struct super_block *sb, void *data, int silent);
288 int lustre_fill_super(struct super_block *sb, void *data, int silent);
289 void lustre_put_super(struct super_block *sb);
290 struct inode *ll_inode_from_lock(struct ldlm_lock *lock);
291 void ll_clear_inode(struct inode *inode);
292 int ll_attr2inode(struct inode *inode, struct iattr *attr, int trunc);
293 int ll_setattr_raw(struct inode *inode, struct iattr *attr);
294 int ll_setattr(struct dentry *de, struct iattr *attr);
295 int ll_statfs(struct super_block *sb, struct kstatfs *sfs);
296 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
297                        unsigned long maxage);
298 void ll_update_inode(struct inode *inode, struct lustre_md *);
299 int it_disposition(struct lookup_intent *it, int flag);
300 void it_set_disposition(struct lookup_intent *it, int flag);
301 void ll_read_inode2(struct inode *inode, void *opaque);
302 void ll_delete_inode(struct inode *inode);
303 int ll_iocontrol(struct inode *inode, struct file *file,
304                  unsigned int cmd, unsigned long arg);
305 void ll_umount_begin(struct super_block *sb);
306 int ll_prep_inode(struct obd_export *, struct obd_export *, struct inode **inode,
307                   struct ptlrpc_request *req, int offset, struct super_block *);
308 __u32 get_uuid2int(const char *name, int len);
309 struct dentry *ll_fh_to_dentry(struct super_block *sb, __u32 *data, int len,
310                                int fhtype, int parent);
311 int ll_dentry_to_fh(struct dentry *, __u32 *datap, int *lenp, int need_parent);
312 int null_if_equal(struct ldlm_lock *lock, void *data);
313 int ll_process_config_update(struct ll_sb_info *sbi, int clean);
314
315 /* llite/special.c */
316 extern struct inode_operations ll_special_inode_operations;
317 extern struct file_operations ll_special_chr_inode_fops;
318 extern struct file_operations ll_special_chr_file_fops;
319 extern struct file_operations ll_special_blk_inode_fops;
320 extern struct file_operations ll_special_fifo_inode_fops;
321 extern struct file_operations ll_special_fifo_file_fops;
322 extern struct file_operations ll_special_sock_inode_fops;
323
324 /* llite/symlink.c */
325 extern struct inode_operations ll_fast_symlink_inode_operations;
326
327 /* llite/llite_close.c */
328 struct ll_close_queue {
329         spinlock_t              lcq_lock;
330         struct list_head        lcq_list;
331         wait_queue_head_t       lcq_waitq;
332         struct completion       lcq_comp;
333 };
334
335 void llap_write_pending(struct inode *inode, struct ll_async_page *llap);
336 void llap_write_complete(struct inode *inode, struct ll_async_page *llap);
337 void ll_open_complete(struct inode *inode);
338 int ll_is_inode_dirty(struct inode *inode);
339 void ll_try_done_writing(struct inode *inode);
340 void ll_queue_done_writing(struct inode *inode);
341 void ll_close_thread_shutdown(struct ll_close_queue *lcq);
342 int ll_close_thread_start(struct ll_close_queue **lcq_ret);
343
344
345 /* llite/llite_mmap.c */
346 #if  (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
347 typedef struct rb_root  rb_root_t;
348 typedef struct rb_node  rb_node_t;
349 #endif
350
351 struct ll_lock_tree_node;
352 struct ll_lock_tree {
353         rb_root_t                       lt_root;
354         struct list_head                lt_locked_list;
355         struct ll_file_data             *lt_fd;
356 };
357 int ll_teardown_mmaps(struct address_space *mapping, __u64 first,
358                       __u64 last);
359 int ll_file_mmap(struct file * file, struct vm_area_struct * vma);
360 struct ll_lock_tree_node * ll_node_from_inode(struct inode *inode, __u64 start,
361                                               __u64 end, ldlm_mode_t mode);
362 int ll_tree_lock(struct ll_lock_tree *tree,
363                  struct ll_lock_tree_node *first_node, struct inode *inode,
364                  const char *buf, size_t count, int ast_flags);
365 int ll_tree_unlock(struct ll_lock_tree *tree, struct inode *inode);
366
367 int ll_get_fid(struct obd_export *exp, struct lustre_id *idp,
368                char *filename, struct lustre_id *ret);
369
370 /* generic */
371 #define LL_SBI_NOLCK           0x1
372 #define LL_SBI_READAHEAD       0x2
373 #define LL_SUPER_MAGIC         0x0BD00BD0
374 #define LL_MAX_BLKSIZE         (4UL * 1024 * 1024)
375
376 #if  (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
377 #define    ll_s2sbi(sb)        ((struct ll_sb_info *)((sb)->s_fs_info))
378 #define    ll_set_sbi(sb, sbi) ((sb)->s_fs_info = sbi)
379 static inline __u64 ll_ts2u64(struct timespec *time)
380 {
381         __u64 t = time->tv_sec;
382         return t;
383 }
384 #else  /* 2.4 here */
385 #define    ll_s2sbi(sb)        ((struct ll_sb_info *)((sb)->u.generic_sbp))
386 #define    ll_set_sbi(sb, sbi) ((sb)->u.generic_sbp = sbi)
387 static inline __u64 ll_ts2u64(time_t *time)
388 {
389         return *time;
390 }
391 #endif
392
393 /* don't need an addref as the sb_info should be holding one */
394 static inline struct obd_export *ll_s2dtexp(struct super_block *sb)
395 {
396         return ll_s2sbi(sb)->ll_dt_exp;
397 }
398
399 /* don't need an addref as the sb_info should be holding one */
400 static inline struct obd_export *ll_s2mdexp(struct super_block *sb)
401 {
402         return ll_s2sbi(sb)->ll_md_exp;
403 }
404
405 static inline struct client_obd *sbi2md(struct ll_sb_info *sbi)
406 {
407         struct obd_device *obd = sbi->ll_md_exp->exp_obd;
408         if (obd == NULL)
409                 LBUG();
410         return &obd->u.cli;
411 }
412
413 // FIXME: replace the name of this with LL_SB to conform to kernel stuff
414 static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
415 {
416         return ll_s2sbi(inode->i_sb);
417 }
418
419 static inline struct obd_export *ll_i2dtexp(struct inode *inode)
420 {
421         return ll_s2dtexp(inode->i_sb);
422 }
423
424 static inline struct obd_export *ll_i2mdexp(struct inode *inode)
425 {
426         return ll_s2mdexp(inode->i_sb);
427 }
428
429 static inline int ll_mds_max_easize(struct super_block *sb)
430 {
431         return sbi2md(ll_s2sbi(sb))->cl_max_mds_easize;
432 }
433
434 static inline __u64 ll_file_maxbytes(struct inode *inode)
435 {
436         return ll_i2info(inode)->lli_maxbytes;
437 }
438
439 #endif /* LLITE_INTERNAL_H */