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