Whamcloud - gitweb
- fixes and improvements in GNS:
[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 /* default to about 40meg of readahead on a given system.  That much tied
16  * up in 512k readahead requests serviced at 40ms each is about 1GB/s. */
17 #define SBI_DEFAULT_RA_MAX ((40 << 20) >> PAGE_CACHE_SHIFT)
18
19 enum ra_stat {
20         RA_STAT_HIT = 0,
21         RA_STAT_MISS,
22         RA_STAT_DISTANT_READPAGE,
23         RA_STAT_MISS_IN_WINDOW,
24         RA_STAT_FAILED_MATCH,
25         RA_STAT_DISCARDED,
26         RA_STAT_ZERO_LEN,
27         RA_STAT_ZERO_WINDOW,
28         RA_STAT_EOF,
29         RA_STAT_MAX_IN_FLIGHT,
30         _NR_RA_STAT,
31 };
32
33 struct ll_ra_info {
34         unsigned long             ra_cur_pages;
35         unsigned long             ra_max_pages;
36         unsigned long             ra_stats[_NR_RA_STAT];
37 };
38
39 /* after roughly how long should we remove an inactive mount? */
40 #define GNS_MOUNT_TIMEOUT 120
41
42 /* how often should the GNS timer look for mounts to cleanup? */
43 #define GNS_TICK_TIMEOUT  1
44
45 /* how many times GNS will try to wait for 1 second for mount */
46 #define GNS_WAIT_ATTEMPTS 10
47
48 struct ll_sb_info {
49         /* this protects pglist and max_r_a_pages.  It isn't safe to grab from
50          * interrupt contexts. */
51         spinlock_t                ll_lock;
52         
53         struct obd_uuid           ll_sb_uuid;
54         struct obd_export        *ll_md_exp;
55         struct obd_export        *ll_dt_exp;
56         struct lov_desc           ll_dt_desc;
57         struct proc_dir_entry    *ll_proc_root;
58         struct lustre_id          ll_rootid;     /* root lustre id */
59
60         struct lustre_mount_data *ll_lmd;
61         char                     *ll_instance;
62
63         int                       ll_flags;
64         struct list_head          ll_conn_chain; /* per-conn chain of SBs */
65
66         struct hlist_head         ll_orphan_dentry_list; /*please don't ask -p*/
67         struct ll_close_queue    *ll_lcq;
68
69         struct lprocfs_stats     *ll_stats;      /* lprocfs stats counter */
70
71         unsigned long             ll_pglist_gen;
72         struct list_head          ll_pglist;
73
74         struct ll_ra_info         ll_ra_info;
75
76         unsigned int              ll_remote;    /* remote client? */
77
78         /* times spent waiting for locks in each call site.  These are
79          * all protected by the ll_lock */
80         struct obd_service_time   ll_read_stime;
81         struct obd_service_time   ll_write_stime;
82         struct obd_service_time   ll_grouplock_stime;
83         struct obd_service_time   ll_seek_stime;
84         struct obd_service_time   ll_setattr_stime;
85         struct obd_service_time   ll_brw_stime;
86 //      struct obd_service_time   ll_done_stime;
87
88         int                       ll_config_version; /* last-applied update */
89
90         /* list of GNS mounts; protected by the dcache_lock */
91         struct list_head          ll_mnt_list;
92
93         struct semaphore          ll_gns_sem;
94         spinlock_t                ll_gns_lock;
95         wait_queue_head_t         ll_gns_waitq;
96         atomic_t                  ll_gns_enabled;
97         int                       ll_gns_state;
98         struct timer_list         ll_gns_timer;
99         struct list_head          ll_gns_sbi_head;
100         struct completion         ll_gns_mount_finished;
101         struct dentry            *ll_gns_pending_dentry;
102
103         unsigned long             ll_gns_tick;
104         unsigned long             ll_gns_timeout;
105
106         /* path to upcall */
107         char                      ll_gns_upcall[PATH_MAX];
108
109         /* mount object entry name */
110         char                      ll_gns_oname[PATH_MAX];
111 };
112
113 struct ll_gns_ctl {
114         struct completion gc_starting;
115         struct completion gc_finishing;
116 };
117
118 /* mounting states */
119 #define LL_GNS_IDLE               (1 << 0)
120 #define LL_GNS_MOUNTING           (1 << 1)
121 #define LL_GNS_FINISHED           (1 << 2)
122
123 /* mounts checking flags */
124 #define LL_GNS_UMOUNT             (1 << 0)
125 #define LL_GNS_CHECK              (1 << 1)
126
127 struct ll_readahead_state {
128         spinlock_t      ras_lock;
129         unsigned long   ras_last_readpage, ras_consecutive;
130         unsigned long   ras_window_start, ras_window_len;
131         unsigned long   ras_next_readahead;
132
133 };
134
135 extern kmem_cache_t *ll_file_data_slab;
136 extern kmem_cache_t *ll_intent_slab;
137 struct lustre_handle;
138
139 struct ll_file_data {
140         struct ll_readahead_state fd_ras;
141         __u32 fd_flags;
142         int fd_omode;
143         struct lustre_handle fd_cwlockh;
144         unsigned long fd_gid;
145 };
146
147 struct lov_stripe_md;
148
149 extern spinlock_t inode_lock;
150
151 extern void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi);
152 extern struct proc_dir_entry *proc_lustre_fs_root;
153
154 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
155 # define hlist_del_init list_del_init
156 #endif
157
158 static inline struct inode *ll_info2i(struct ll_inode_info *lli)
159 {
160 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
161         return &lli->lli_vfs_inode;
162 #else
163         return list_entry(lli, struct inode, u.generic_ip);
164 #endif
165 }
166
167
168 struct it_cb_data {
169         struct inode *icbd_parent;
170         struct dentry **icbd_childp;
171         obd_id hash;
172 };
173
174 #define LLAP_MAGIC 98764321
175
176 struct ll_async_page {
177         int             llap_magic;
178         void            *llap_cookie;
179         struct page     *llap_page;
180         struct list_head llap_pending_write;
181          /* only trust these if the page lock is providing exclusion */
182         unsigned         llap_write_queued:1,
183                          llap_defer_uptodate:1,
184                          llap_origin:3,
185                          llap_ra_used:1;
186
187         struct list_head llap_proc_item;
188 };
189
190 enum {
191         LLAP_ORIGIN_UNKNOWN = 0,
192         LLAP_ORIGIN_READPAGE,
193         LLAP_ORIGIN_READAHEAD,
194         LLAP_ORIGIN_COMMIT_WRITE,
195         LLAP_ORIGIN_WRITEPAGE,
196         LLAP__ORIGIN_MAX,
197 };
198
199 /* llite/lproc_llite.c */
200 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
201                                 struct super_block *sb, char *lov,
202                                 char *lmv);
203 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi);
204
205 /* llite/dir.c */
206 extern struct file_operations ll_dir_operations;
207 extern struct inode_operations ll_dir_inode_operations;
208
209 /* llite/namei.c */
210 int ll_objects_destroy(struct ptlrpc_request *request, 
211                        struct inode *dir, int offset);
212 struct inode *ll_iget(struct super_block *sb, ino_t hash,
213                       struct lustre_md *lic);
214 struct dentry *ll_find_alias(struct inode *, struct dentry *);
215 int ll_mdc_cancel_unused(struct lustre_handle *, struct inode *, int flags,
216                          void *opaque);
217 int ll_mdc_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
218                         void *data, int flag);
219 /* llite/rw.c */
220 int ll_prepare_write(struct file *, struct page *, unsigned from, unsigned to);
221 int ll_commit_write(struct file *, struct page *, unsigned from, unsigned to);
222 int ll_writepage(struct page *page);
223 void ll_inode_fill_obdo(struct inode *inode, int cmd, struct obdo *oa);
224 void ll_ap_completion(void *data, int cmd, struct obdo *oa, int rc);
225 void ll_removepage(struct page *page);
226 int ll_readpage(struct file *file, struct page *page);
227 struct ll_async_page *llap_from_cookie(void *cookie);
228 struct ll_async_page *llap_from_page(struct page *page, unsigned origin);
229 struct ll_async_page *llap_cast_private(struct page *page);
230 void ll_readahead_init(struct inode *inode, struct ll_readahead_state *ras);
231
232 void ll_ra_accounting(struct page *page, struct address_space *mapping);
233 void ll_truncate(struct inode *inode);
234
235 /* llite/file.c */
236 extern struct file_operations ll_file_operations;
237 extern struct inode_operations ll_file_inode_operations;
238 int ll_md_real_close(struct obd_export *md_exp,
239                      struct inode *inode, int flags);
240 extern int ll_inode_revalidate_it(struct dentry *);
241 extern int ll_setxattr(struct dentry *, const char *, const void *,
242                        size_t, int);
243 extern int ll_getxattr(struct dentry *, const char *, void *, size_t);
244 extern int ll_listxattr(struct dentry *, char *, size_t);
245 extern int ll_removexattr(struct dentry *, const char *);
246 extern int ll_inode_permission(struct inode *, int, struct nameidata *);
247 int ll_refresh_lsm(struct inode *inode, struct lov_stripe_md *lsm);
248 int ll_extent_lock(struct ll_file_data *, struct inode *,
249                    struct lov_stripe_md *, int mode, ldlm_policy_data_t *,
250                    struct lustre_handle *, int ast_flags,
251                    struct obd_service_time *);
252 int ll_extent_unlock(struct ll_file_data *, struct inode *,
253                      struct lov_stripe_md *, int mode, struct lustre_handle *);
254 int ll_file_open(struct inode *inode, struct file *file);
255 int ll_file_release(struct inode *inode, struct file *file);
256 int ll_lsm_getattr(struct obd_export *, struct lov_stripe_md *, struct obdo *);
257 int ll_glimpse_size(struct inode *inode);
258 int ll_local_open(struct file *file, struct lookup_intent *it,
259                   struct obd_client_handle *och);
260 int ll_md_close(struct obd_export *md_exp, struct inode *inode,
261                 struct file *file);
262 int ll_md_och_close(struct obd_export *md_exp, struct inode *inode,
263                     struct obd_client_handle *och);
264 void ll_och_fill(struct inode *inode, struct lookup_intent *it,
265                  struct obd_client_handle *och);
266
267 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
268 int ll_getattr(struct vfsmount *mnt, struct dentry *de, struct kstat *stat);
269 #endif
270 void ll_stime_record(struct ll_sb_info *sbi, struct timeval *start,
271                      struct obd_service_time *stime);
272
273 /* llite/dcache.c */
274 void ll_intent_drop_lock(struct lookup_intent *);
275 void ll_intent_release(struct lookup_intent *);
276 int ll_intent_alloc(struct lookup_intent *);
277 void ll_intent_free(struct lookup_intent *it);
278 extern void ll_set_dd(struct dentry *de);
279 void ll_unhash_aliases(struct inode *);
280 void ll_frob_intent(struct lookup_intent **itp, struct lookup_intent *deft);
281 void ll_lookup_finish_locks(struct lookup_intent *it, struct dentry *dentry);
282 int revalidate_it_finish(struct ptlrpc_request *request, int offset,
283                          struct lookup_intent *it, struct dentry *de);
284
285
286 /* llite/llite_gns.c */
287 int ll_gns_start_thread(void);
288 void ll_gns_stop_thread(void);
289
290 int ll_gns_mount_object(struct dentry *dentry,
291                         struct vfsmount *mnt);
292 int ll_gns_umount_object(struct vfsmount *mnt);
293
294 int ll_gns_check_mounts(struct ll_sb_info *sbi,
295                         int flags);
296
297 void ll_gns_timer_callback(unsigned long data);
298 void ll_gns_add_timer(struct ll_sb_info *sbi);
299 void ll_gns_del_timer(struct ll_sb_info *sbi);
300
301 /* llite/llite_lib.c */
302 extern struct super_operations lustre_super_operations;
303
304 char *ll_read_opt(const char *opt, char *data);
305 int ll_set_opt(const char *opt, char *data, int fl);
306 void ll_options(char *options, char **ost, char **mds, char **sec, 
307                 int *async, int *flags);
308 void ll_lli_init(struct ll_inode_info *lli);
309 int ll_fill_super(struct super_block *sb, void *data, int silent);
310 int lustre_fill_super(struct super_block *sb, void *data, int silent);
311 void lustre_put_super(struct super_block *sb);
312 struct inode *ll_inode_from_lock(struct ldlm_lock *lock);
313 void ll_clear_inode(struct inode *inode);
314 int ll_attr2inode(struct inode *inode, struct iattr *attr, int trunc);
315 int ll_setattr_raw(struct inode *inode, struct iattr *attr);
316 int ll_setattr(struct dentry *de, struct iattr *attr);
317 int ll_statfs(struct super_block *sb, struct kstatfs *sfs);
318 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
319                        unsigned long maxage);
320 void ll_update_inode(struct inode *inode, struct lustre_md *);
321 int it_disposition(struct lookup_intent *it, int flag);
322 void it_set_disposition(struct lookup_intent *it, int flag);
323 void ll_read_inode2(struct inode *inode, void *opaque);
324 void ll_delete_inode(struct inode *inode);
325 int ll_iocontrol(struct inode *inode, struct file *file,
326                  unsigned int cmd, unsigned long arg);
327 void ll_umount_begin(struct super_block *sb);
328 int ll_prep_inode(struct obd_export *, struct obd_export *, struct inode **inode,
329                   struct ptlrpc_request *req, int offset, struct super_block *);
330 __u32 get_uuid2int(const char *name, int len);
331 struct dentry *ll_fh_to_dentry(struct super_block *sb, __u32 *data, int len,
332                                int fhtype, int parent);
333 int ll_dentry_to_fh(struct dentry *, __u32 *datap, int *lenp, int need_parent);
334 int null_if_equal(struct ldlm_lock *lock, void *data);
335 int ll_process_config_update(struct ll_sb_info *sbi, int clean);
336
337 /* llite/special.c */
338 extern struct inode_operations ll_special_inode_operations;
339 extern struct file_operations ll_special_chr_inode_fops;
340 extern struct file_operations ll_special_chr_file_fops;
341 extern struct file_operations ll_special_blk_inode_fops;
342 extern struct file_operations ll_special_fifo_inode_fops;
343 extern struct file_operations ll_special_fifo_file_fops;
344 extern struct file_operations ll_special_sock_inode_fops;
345
346 /* llite/symlink.c */
347 extern struct inode_operations ll_fast_symlink_inode_operations;
348
349 /* llite/llite_close.c */
350 struct ll_close_queue {
351         spinlock_t              lcq_lock;
352         struct list_head        lcq_list;
353         wait_queue_head_t       lcq_waitq;
354         struct completion       lcq_comp;
355 };
356
357 void llap_write_pending(struct inode *inode, struct ll_async_page *llap);
358 void llap_write_complete(struct inode *inode, struct ll_async_page *llap);
359 void ll_open_complete(struct inode *inode);
360 int ll_is_inode_dirty(struct inode *inode);
361 void ll_try_done_writing(struct inode *inode);
362 void ll_queue_done_writing(struct inode *inode);
363 void ll_close_thread_shutdown(struct ll_close_queue *lcq);
364 int ll_close_thread_start(struct ll_close_queue **lcq_ret);
365
366
367 /* llite/llite_mmap.c */
368 #if  (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
369 typedef struct rb_root  rb_root_t;
370 typedef struct rb_node  rb_node_t;
371 #endif
372
373 struct ll_lock_tree_node;
374 struct ll_lock_tree {
375         rb_root_t                       lt_root;
376         struct list_head                lt_locked_list;
377         struct ll_file_data             *lt_fd;
378 };
379 int ll_teardown_mmaps(struct address_space *mapping, __u64 first,
380                       __u64 last);
381 int ll_file_mmap(struct file * file, struct vm_area_struct * vma);
382 struct ll_lock_tree_node * ll_node_from_inode(struct inode *inode, __u64 start,
383                                               __u64 end, ldlm_mode_t mode);
384 int ll_tree_lock(struct ll_lock_tree *tree,
385                  struct ll_lock_tree_node *first_node, struct inode *inode,
386                  const char *buf, size_t count, int ast_flags);
387 int ll_tree_unlock(struct ll_lock_tree *tree, struct inode *inode);
388
389 int ll_get_fid(struct obd_export *exp, struct lustre_id *idp,
390                char *filename, struct lustre_id *ret);
391
392 /* generic */
393 #define LL_SBI_NOLCK           0x1
394 #define LL_SBI_READAHEAD       0x2
395 #define LL_SUPER_MAGIC         0x0BD00BD0
396 #define LL_MAX_BLKSIZE         (4UL * 1024 * 1024)
397
398 #if  (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
399 #define    ll_s2sbi(sb)        ((struct ll_sb_info *)((sb)->s_fs_info))
400 #define    ll_set_sbi(sb, sbi) ((sb)->s_fs_info = sbi)
401 static inline __u64 ll_ts2u64(struct timespec *time)
402 {
403         __u64 t = time->tv_sec;
404         return t;
405 }
406 #else  /* 2.4 here */
407 #define    ll_s2sbi(sb)        ((struct ll_sb_info *)((sb)->u.generic_sbp))
408 #define    ll_set_sbi(sb, sbi) ((sb)->u.generic_sbp = sbi)
409 static inline __u64 ll_ts2u64(time_t *time)
410 {
411         return *time;
412 }
413 #endif
414
415 /* don't need an addref as the sb_info should be holding one */
416 static inline struct obd_export *ll_s2dtexp(struct super_block *sb)
417 {
418         return ll_s2sbi(sb)->ll_dt_exp;
419 }
420
421 /* don't need an addref as the sb_info should be holding one */
422 static inline struct obd_export *ll_s2mdexp(struct super_block *sb)
423 {
424         return ll_s2sbi(sb)->ll_md_exp;
425 }
426
427 static inline struct client_obd *sbi2md(struct ll_sb_info *sbi)
428 {
429         struct obd_device *obd = sbi->ll_md_exp->exp_obd;
430         if (obd == NULL)
431                 LBUG();
432         return &obd->u.cli;
433 }
434
435 // FIXME: replace the name of this with LL_SB to conform to kernel stuff
436 static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
437 {
438         return ll_s2sbi(inode->i_sb);
439 }
440
441 static inline struct obd_export *ll_i2dtexp(struct inode *inode)
442 {
443         return ll_s2dtexp(inode->i_sb);
444 }
445
446 static inline struct obd_export *ll_i2mdexp(struct inode *inode)
447 {
448         return ll_s2mdexp(inode->i_sb);
449 }
450
451 static inline int ll_mds_max_easize(struct super_block *sb)
452 {
453         return sbi2md(ll_s2sbi(sb))->cl_max_mds_easize;
454 }
455
456 static inline __u64 ll_file_maxbytes(struct inode *inode)
457 {
458         return ll_i2info(inode)->lli_maxbytes;
459 }
460
461 static inline void
462 ll_inode2id(struct lustre_id *id, struct inode *inode)
463 {
464         struct lustre_id *lid = &ll_i2info(inode)->lli_id;
465
466         mdc_pack_id(id, inode->i_ino, inode->i_generation,
467                     (inode->i_mode & S_IFMT), id_group(lid),
468                     id_fid(lid));
469 }
470
471 static inline void 
472 ll_prepare_mdc_data(struct mdc_op_data *data, struct inode *i1,
473                     struct inode *i2, const char *name, int namelen,
474                     int mode)
475 {
476         LASSERT(i1);
477         ll_inode2id(&data->id1, i1);
478
479         /* it could be directory with mea */
480         data->mea1 = ll_i2info(i1)->lli_mea;
481
482         if (i2) {
483                 ll_inode2id(&data->id2, i2);
484                 data->mea2 = ll_i2info(i2)->lli_mea;
485         }
486
487         data->valid = 0;
488         data->name = name;
489         data->namelen = namelen;
490         data->create_mode = mode;
491         data->mod_time = LTIME_S(CURRENT_TIME);
492 }
493
494 #if 0
495 /* 
496  * this was needed for catching correct calling place of ll_intent_alloc() with
497  * missed ll_intent_free() causing memory leak. --umka
498  */
499 #define ll_intent_alloc(it)                                             \
500         ({                                                              \
501                 int err;                                                \
502                 OBD_SLAB_ALLOC((it)->d.fs_data, ll_intent_slab, SLAB_KERNEL, \
503                                sizeof(struct lustre_intent_data));      \
504                 if (!(it)->d.fs_data) {                                 \
505                         err = -ENOMEM;                                  \
506                 } else {                                                \
507                         err = 0;                                        \
508                 }                                                       \
509                 (it)->it_op_release = ll_intent_release;                \
510                 err;                                                    \
511         })
512
513 #define ll_intent_free(it)                                      \
514         do {                                                    \
515                 if ((it)->d.fs_data) {                                  \
516                         OBD_SLAB_FREE((it)->d.fs_data, ll_intent_slab,  \
517                                       sizeof(struct lustre_intent_data)); \
518                         (it)->d.fs_data = NULL;                         \
519                 }                                                       \
520         } while (0)
521 #endif
522
523 #endif /* LLITE_INTERNAL_H */