1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2003 Cluster File Systems, Inc.
6 * This code is issued under the GNU General Public License.
7 * See the file COPYING in this distribution
10 #ifndef LLITE_INTERNAL_H
11 #define LLITE_INTERNAL_H
13 #include <linux/lustre_debug.h>
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)
22 RA_STAT_DISTANT_READPAGE,
23 RA_STAT_MISS_IN_WINDOW,
29 RA_STAT_MAX_IN_FLIGHT,
34 unsigned long ra_cur_pages;
35 unsigned long ra_max_pages;
36 unsigned long ra_stats[_NR_RA_STAT];
39 /* after roughly how long should we remove an inactive mount? */
40 #define GNS_MOUNT_TIMEOUT 120
42 /* how often should the GNS timer look for mounts to cleanup? */
43 #define GNS_TICK_TIMEOUT 1
45 /* how many times GNS will try to wait for 1 second for mount */
46 #define GNS_WAIT_ATTEMPTS 10
49 /* this protects pglist and max_r_a_pages. It isn't safe to grab from
50 * interrupt contexts. */
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 */
60 struct lustre_mount_data *ll_lmd;
64 struct list_head ll_conn_chain; /* per-conn chain of SBs */
66 struct hlist_head ll_orphan_dentry_list; /*please don't ask -p*/
67 struct ll_close_queue *ll_lcq;
69 struct lprocfs_stats *ll_stats; /* lprocfs stats counter */
71 unsigned long ll_pglist_gen;
72 struct list_head ll_pglist;
74 struct ll_ra_info ll_ra_info;
76 /* times spent waiting for locks in each call site. These are
77 * all protected by the ll_lock */
78 struct obd_service_time ll_read_stime;
79 struct obd_service_time ll_write_stime;
80 struct obd_service_time ll_grouplock_stime;
81 struct obd_service_time ll_seek_stime;
82 struct obd_service_time ll_setattr_stime;
83 struct obd_service_time ll_brw_stime;
84 // struct obd_service_time ll_done_stime;
86 int ll_config_version; /* last-applied update */
88 /* list of GNS mounts; protected by the dcache_lock */
89 struct list_head ll_mnt_list;
91 struct semaphore ll_gns_sem;
92 spinlock_t ll_gns_lock;
93 wait_queue_head_t ll_gns_waitq;
95 struct timer_list ll_gns_timer;
96 struct list_head ll_gns_sbi_head;
98 unsigned long ll_gns_tick;
99 unsigned long ll_gns_timeout;
100 struct completion ll_gns_mount_finished;
103 char ll_gns_upcall[PATH_MAX];
105 /* mount object entry name */
106 char ll_gns_oname[PATH_MAX];
110 struct completion gc_starting;
111 struct completion gc_finishing;
114 /* mounting states */
115 #define LL_GNS_IDLE (1 << 0)
116 #define LL_GNS_MOUNTING (1 << 1)
117 #define LL_GNS_FINISHED (1 << 2)
119 /* mounts checking flags */
120 #define LL_GNS_UMOUNT (1 << 0)
121 #define LL_GNS_CHECK (1 << 1)
123 struct ll_readahead_state {
125 unsigned long ras_last_readpage, ras_consecutive;
126 unsigned long ras_window_start, ras_window_len;
127 unsigned long ras_next_readahead;
131 extern kmem_cache_t *ll_file_data_slab;
132 extern kmem_cache_t *ll_intent_slab;
133 struct lustre_handle;
134 struct ll_file_data {
135 struct ll_readahead_state fd_ras;
138 struct lustre_handle fd_cwlockh;
139 unsigned long fd_gid;
142 struct lov_stripe_md;
144 extern spinlock_t inode_lock;
146 extern void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi);
147 extern struct proc_dir_entry *proc_lustre_fs_root;
149 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
150 # define hlist_del_init list_del_init
153 static inline struct inode *ll_info2i(struct ll_inode_info *lli)
155 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
156 return &lli->lli_vfs_inode;
158 return list_entry(lli, struct inode, u.generic_ip);
164 struct inode *icbd_parent;
165 struct dentry **icbd_childp;
169 #define LLAP_MAGIC 98764321
171 struct ll_async_page {
174 struct page *llap_page;
175 struct list_head llap_pending_write;
176 /* only trust these if the page lock is providing exclusion */
177 unsigned llap_write_queued:1,
178 llap_defer_uptodate:1,
182 struct list_head llap_proc_item;
186 LLAP_ORIGIN_UNKNOWN = 0,
187 LLAP_ORIGIN_READPAGE,
188 LLAP_ORIGIN_READAHEAD,
189 LLAP_ORIGIN_COMMIT_WRITE,
190 LLAP_ORIGIN_WRITEPAGE,
194 /* llite/lproc_llite.c */
195 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
196 struct super_block *sb, char *lov,
198 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi);
201 extern struct file_operations ll_dir_operations;
202 extern struct inode_operations ll_dir_inode_operations;
205 int ll_objects_destroy(struct ptlrpc_request *request,
206 struct inode *dir, int offset);
207 struct inode *ll_iget(struct super_block *sb, ino_t hash,
208 struct lustre_md *lic);
209 struct dentry *ll_find_alias(struct inode *, struct dentry *);
210 int ll_mdc_cancel_unused(struct lustre_handle *, struct inode *, int flags,
212 int ll_mdc_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
213 void *data, int flag);
215 int ll_prepare_write(struct file *, struct page *, unsigned from, unsigned to);
216 int ll_commit_write(struct file *, struct page *, unsigned from, unsigned to);
217 int ll_writepage(struct page *page);
218 void ll_inode_fill_obdo(struct inode *inode, int cmd, struct obdo *oa);
219 void ll_ap_completion(void *data, int cmd, struct obdo *oa, int rc);
220 void ll_removepage(struct page *page);
221 int ll_readpage(struct file *file, struct page *page);
222 struct ll_async_page *llap_from_cookie(void *cookie);
223 struct ll_async_page *llap_from_page(struct page *page, unsigned origin);
224 struct ll_async_page *llap_cast_private(struct page *page);
225 void ll_readahead_init(struct inode *inode, struct ll_readahead_state *ras);
227 void ll_ra_accounting(struct page *page, struct address_space *mapping);
228 void ll_truncate(struct inode *inode);
231 extern struct file_operations ll_file_operations;
232 extern struct inode_operations ll_file_inode_operations;
233 int ll_md_real_close(struct obd_export *md_exp,
234 struct inode *inode, int flags);
235 extern int ll_inode_revalidate_it(struct dentry *);
236 extern int ll_setxattr(struct dentry *, const char *, const void *,
238 extern int ll_getxattr(struct dentry *, const char *, void *, size_t);
239 extern int ll_listxattr(struct dentry *, char *, size_t);
240 extern int ll_removexattr(struct dentry *, const char *);
241 extern int ll_inode_permission(struct inode *, int, struct nameidata *);
242 int ll_refresh_lsm(struct inode *inode, struct lov_stripe_md *lsm);
243 int ll_extent_lock(struct ll_file_data *, struct inode *,
244 struct lov_stripe_md *, int mode, ldlm_policy_data_t *,
245 struct lustre_handle *, int ast_flags,
246 struct obd_service_time *);
247 int ll_extent_unlock(struct ll_file_data *, struct inode *,
248 struct lov_stripe_md *, int mode, struct lustre_handle *);
249 int ll_file_open(struct inode *inode, struct file *file);
250 int ll_file_release(struct inode *inode, struct file *file);
251 int ll_lsm_getattr(struct obd_export *, struct lov_stripe_md *, struct obdo *);
252 int ll_glimpse_size(struct inode *inode);
253 int ll_local_open(struct file *file, struct lookup_intent *it,
254 struct obd_client_handle *och);
255 int ll_md_close(struct obd_export *md_exp, struct inode *inode,
257 int ll_md_och_close(struct obd_export *md_exp, struct inode *inode,
258 struct obd_client_handle *och);
259 void ll_och_fill(struct inode *inode, struct lookup_intent *it,
260 struct obd_client_handle *och);
262 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
263 int ll_getattr(struct vfsmount *mnt, struct dentry *de, struct kstat *stat);
265 void ll_stime_record(struct ll_sb_info *sbi, struct timeval *start,
266 struct obd_service_time *stime);
269 void ll_intent_drop_lock(struct lookup_intent *);
270 void ll_intent_release(struct lookup_intent *);
271 int ll_intent_alloc(struct lookup_intent *);
272 void ll_intent_free(struct lookup_intent *it);
273 extern void ll_set_dd(struct dentry *de);
274 void ll_unhash_aliases(struct inode *);
275 void ll_frob_intent(struct lookup_intent **itp, struct lookup_intent *deft);
276 void ll_lookup_finish_locks(struct lookup_intent *it, struct dentry *dentry);
277 int revalidate_it_finish(struct ptlrpc_request *request, int offset,
278 struct lookup_intent *it, struct dentry *de);
281 /* llite/llite_gns.c */
282 int ll_gns_start_thread(void);
283 void ll_gns_stop_thread(void);
285 int ll_gns_mount_object(struct dentry *dentry,
286 struct vfsmount *mnt);
287 int ll_gns_umount_object(struct vfsmount *mnt);
289 int ll_gns_check_mounts(struct ll_sb_info *sbi,
292 void ll_gns_timer_callback(unsigned long data);
293 void ll_gns_add_timer(struct ll_sb_info *sbi);
294 void ll_gns_del_timer(struct ll_sb_info *sbi);
296 /* llite/llite_lib.c */
297 extern struct super_operations lustre_super_operations;
299 char *ll_read_opt(const char *opt, char *data);
300 int ll_set_opt(const char *opt, char *data, int fl);
301 void ll_options(char *options, char **ost, char **mds, char **sec,
302 int *async, int *flags);
303 void ll_lli_init(struct ll_inode_info *lli);
304 int ll_fill_super(struct super_block *sb, void *data, int silent);
305 int lustre_fill_super(struct super_block *sb, void *data, int silent);
306 void lustre_put_super(struct super_block *sb);
307 struct inode *ll_inode_from_lock(struct ldlm_lock *lock);
308 void ll_clear_inode(struct inode *inode);
309 int ll_attr2inode(struct inode *inode, struct iattr *attr, int trunc);
310 int ll_setattr_raw(struct inode *inode, struct iattr *attr);
311 int ll_setattr(struct dentry *de, struct iattr *attr);
312 int ll_statfs(struct super_block *sb, struct kstatfs *sfs);
313 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
314 unsigned long maxage);
315 void ll_update_inode(struct inode *inode, struct lustre_md *);
316 int it_disposition(struct lookup_intent *it, int flag);
317 void it_set_disposition(struct lookup_intent *it, int flag);
318 void ll_read_inode2(struct inode *inode, void *opaque);
319 void ll_delete_inode(struct inode *inode);
320 int ll_iocontrol(struct inode *inode, struct file *file,
321 unsigned int cmd, unsigned long arg);
322 void ll_umount_begin(struct super_block *sb);
323 int ll_prep_inode(struct obd_export *, struct obd_export *, struct inode **inode,
324 struct ptlrpc_request *req, int offset, struct super_block *);
325 __u32 get_uuid2int(const char *name, int len);
326 struct dentry *ll_fh_to_dentry(struct super_block *sb, __u32 *data, int len,
327 int fhtype, int parent);
328 int ll_dentry_to_fh(struct dentry *, __u32 *datap, int *lenp, int need_parent);
329 int null_if_equal(struct ldlm_lock *lock, void *data);
330 int ll_process_config_update(struct ll_sb_info *sbi, int clean);
332 /* llite/special.c */
333 extern struct inode_operations ll_special_inode_operations;
334 extern struct file_operations ll_special_chr_inode_fops;
335 extern struct file_operations ll_special_chr_file_fops;
336 extern struct file_operations ll_special_blk_inode_fops;
337 extern struct file_operations ll_special_fifo_inode_fops;
338 extern struct file_operations ll_special_fifo_file_fops;
339 extern struct file_operations ll_special_sock_inode_fops;
341 /* llite/symlink.c */
342 extern struct inode_operations ll_fast_symlink_inode_operations;
344 /* llite/llite_close.c */
345 struct ll_close_queue {
347 struct list_head lcq_list;
348 wait_queue_head_t lcq_waitq;
349 struct completion lcq_comp;
352 void llap_write_pending(struct inode *inode, struct ll_async_page *llap);
353 void llap_write_complete(struct inode *inode, struct ll_async_page *llap);
354 void ll_open_complete(struct inode *inode);
355 int ll_is_inode_dirty(struct inode *inode);
356 void ll_try_done_writing(struct inode *inode);
357 void ll_queue_done_writing(struct inode *inode);
358 void ll_close_thread_shutdown(struct ll_close_queue *lcq);
359 int ll_close_thread_start(struct ll_close_queue **lcq_ret);
362 /* llite/llite_mmap.c */
363 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
364 typedef struct rb_root rb_root_t;
365 typedef struct rb_node rb_node_t;
368 struct ll_lock_tree_node;
369 struct ll_lock_tree {
371 struct list_head lt_locked_list;
372 struct ll_file_data *lt_fd;
374 int ll_teardown_mmaps(struct address_space *mapping, __u64 first,
376 int ll_file_mmap(struct file * file, struct vm_area_struct * vma);
377 struct ll_lock_tree_node * ll_node_from_inode(struct inode *inode, __u64 start,
378 __u64 end, ldlm_mode_t mode);
379 int ll_tree_lock(struct ll_lock_tree *tree,
380 struct ll_lock_tree_node *first_node, struct inode *inode,
381 const char *buf, size_t count, int ast_flags);
382 int ll_tree_unlock(struct ll_lock_tree *tree, struct inode *inode);
384 int ll_get_fid(struct obd_export *exp, struct lustre_id *idp,
385 char *filename, struct lustre_id *ret);
388 #define LL_SBI_NOLCK 0x1
389 #define LL_SBI_READAHEAD 0x2
390 #define LL_SUPER_MAGIC 0x0BD00BD0
391 #define LL_MAX_BLKSIZE (4UL * 1024 * 1024)
393 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
394 #define ll_s2sbi(sb) ((struct ll_sb_info *)((sb)->s_fs_info))
395 #define ll_set_sbi(sb, sbi) ((sb)->s_fs_info = sbi)
396 static inline __u64 ll_ts2u64(struct timespec *time)
398 __u64 t = time->tv_sec;
402 #define ll_s2sbi(sb) ((struct ll_sb_info *)((sb)->u.generic_sbp))
403 #define ll_set_sbi(sb, sbi) ((sb)->u.generic_sbp = sbi)
404 static inline __u64 ll_ts2u64(time_t *time)
410 /* don't need an addref as the sb_info should be holding one */
411 static inline struct obd_export *ll_s2dtexp(struct super_block *sb)
413 return ll_s2sbi(sb)->ll_dt_exp;
416 /* don't need an addref as the sb_info should be holding one */
417 static inline struct obd_export *ll_s2mdexp(struct super_block *sb)
419 return ll_s2sbi(sb)->ll_md_exp;
422 static inline struct client_obd *sbi2md(struct ll_sb_info *sbi)
424 struct obd_device *obd = sbi->ll_md_exp->exp_obd;
430 // FIXME: replace the name of this with LL_SB to conform to kernel stuff
431 static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
433 return ll_s2sbi(inode->i_sb);
436 static inline struct obd_export *ll_i2dtexp(struct inode *inode)
438 return ll_s2dtexp(inode->i_sb);
441 static inline struct obd_export *ll_i2mdexp(struct inode *inode)
443 return ll_s2mdexp(inode->i_sb);
446 static inline int ll_mds_max_easize(struct super_block *sb)
448 return sbi2md(ll_s2sbi(sb))->cl_max_mds_easize;
451 static inline __u64 ll_file_maxbytes(struct inode *inode)
453 return ll_i2info(inode)->lli_maxbytes;
457 ll_inode2id(struct lustre_id *id, struct inode *inode)
459 struct lustre_id *lid = &ll_i2info(inode)->lli_id;
461 mdc_pack_id(id, inode->i_ino, inode->i_generation,
462 (inode->i_mode & S_IFMT), id_group(lid),
467 ll_prepare_mdc_data(struct mdc_op_data *data, struct inode *i1,
468 struct inode *i2, const char *name, int namelen,
472 ll_inode2id(&data->id1, i1);
474 /* it could be directory with mea */
475 data->mea1 = ll_i2info(i1)->lli_mea;
478 ll_inode2id(&data->id2, i2);
479 data->mea2 = ll_i2info(i2)->lli_mea;
484 data->namelen = namelen;
485 data->create_mode = mode;
486 data->mod_time = LTIME_S(CURRENT_TIME);
489 #endif /* LLITE_INTERNAL_H */