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