1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
5 #ifndef LLITE_INTERNAL_H
6 #define LLITE_INTERNAL_H
8 #ifdef CONFIG_FS_POSIX_ACL
10 # include <linux/xattr_acl.h>
13 #include <linux/lustre_debug.h>
14 #include <linux/lustre_version.h>
15 #include <linux/lustre_disk.h> /* for s2sbi */
18 struct lustre_intent_data {
19 __u64 it_lock_handle[2];
25 #define LL_IT2STR(it) ((it) ? ldlm_it2str((it)->it_op) : "0")
27 #if (LUSTRE_KERNEL_VERSION < 46)
28 #define LUSTRE_FPRIVATE(file) ((file)->private_data)
30 #define LUSTRE_FPRIVATE(file) ((file)->fs_private)
34 static inline struct lookup_intent *ll_nd2it(struct nameidata *nd)
36 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
43 struct ll_dentry_data {
46 struct obd_client_handle lld_cwd_och;
47 struct obd_client_handle lld_mnt_och;
50 #define ll_d2d(de) ((struct ll_dentry_data*) de->d_fsdata)
52 extern struct file_operations ll_pgcache_seq_fops;
54 #define LLI_INODE_MAGIC 0x111d0de5
55 #define LLI_INODE_DEAD 0xdeadd00d
56 #define LLI_F_HAVE_OST_SIZE_LOCK 0
57 #define LLI_F_HAVE_MDS_SIZE_LOCK 1
59 struct ll_inode_info {
61 struct semaphore lli_size_sem;
62 void *lli_size_sem_owner;
63 struct semaphore lli_open_sem;
64 struct lov_stripe_md *lli_smd;
65 char *lli_symlink_name;
68 unsigned long lli_flags;
70 /* this lock protects s_d_w and p_w_ll and mmap_cnt */
72 struct list_head lli_pending_write_llaps;
73 int lli_send_done_writing;
74 atomic_t lli_mmap_cnt;
76 struct list_head lli_close_item;
78 /* for writepage() only to communicate to fsync */
81 struct file_operations *ll_save_ifop;
82 struct file_operations *ll_save_ffop;
83 struct file_operations *ll_save_wfop;
84 struct file_operations *ll_save_wrfop;
86 struct posix_acl *lli_posix_acl;
88 struct list_head lli_dead_list;
90 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
91 struct inode lli_vfs_inode;
95 struct lu_fid lli_fid;
99 * Locking to guarantee consistency of non-atomic updates to long long i_size,
100 * consistency between file size and KMS, and consistency within
101 * ->lli_smd->lsm_oinfo[]'s.
103 * Implemented by ->lli_size_sem and ->lsm_sem, nested in that order.
106 void ll_inode_size_lock(struct inode *inode, int lock_lsm);
107 void ll_inode_size_unlock(struct inode *inode, int unlock_lsm);
109 // FIXME: replace the name of this with LL_I to conform to kernel stuff
110 // static inline struct ll_inode_info *LL_I(struct inode *inode)
111 static inline struct ll_inode_info *ll_i2info(struct inode *inode)
113 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
114 return container_of(inode, struct ll_inode_info, lli_vfs_inode);
116 return (struct ll_inode_info *)&(inode->u.generic_ip);
120 /* default to about 40meg of readahead on a given system. That much tied
121 * up in 512k readahead requests serviced at 40ms each is about 1GB/s. */
122 #define SBI_DEFAULT_READAHEAD_MAX (40UL << (20 - PAGE_CACHE_SHIFT))
126 RA_STAT_DISTANT_READPAGE,
127 RA_STAT_MISS_IN_WINDOW,
128 RA_STAT_FAILED_GRAB_PAGE,
129 RA_STAT_FAILED_MATCH,
134 RA_STAT_MAX_IN_FLIGHT,
139 unsigned long ra_cur_pages;
140 unsigned long ra_max_pages;
141 unsigned long ra_stats[_NR_RA_STAT];
144 /* flags for sbi->ll_flags */
145 #define LL_SBI_NOLCK 0x01 /* DLM locking disabled (directio-only) */
146 #define LL_SBI_CHECKSUM 0x02 /* checksum each page as it's written */
147 #define LL_SBI_FLOCK 0x04
148 #define LL_SBI_USER_XATTR 0x08 /* support user xattr */
149 #define LL_SBI_ACL 0x10 /* support ACL */
150 #define LL_SBI_JOIN 0x20 /* support JOIN */
153 struct list_head ll_list;
154 /* this protects pglist and ra_info. It isn't safe to
155 * grab from interrupt contexts */
157 struct obd_uuid ll_sb_uuid;
158 struct obd_export *ll_mdc_exp;
159 struct obd_export *ll_osc_exp;
160 struct proc_dir_entry* ll_proc_root;
161 struct lu_fid ll_root_fid; /* root object fid */
164 struct list_head ll_conn_chain; /* per-conn chain of SBs */
165 struct lustre_client_ocd ll_lco;
167 struct hlist_head ll_orphan_dentry_list; /*please don't ask -p*/
168 struct ll_close_queue *ll_lcq;
170 struct lprocfs_stats *ll_stats; /* lprocfs stats counter */
172 unsigned long ll_async_page_max;
173 unsigned long ll_async_page_count;
174 unsigned long ll_pglist_gen;
175 struct list_head ll_pglist; /* all pages (llap_pglist_item) */
177 struct ll_ra_info ll_ra_info;
178 unsigned int ll_namelen;
179 struct file_operations *ll_fop;
181 struct list_head ll_deathrow; /* inodes to be destroyed (b1443) */
182 spinlock_t ll_deathrow_lock;
184 struct lu_fid ll_fid;
190 struct task_struct *lrr_reader;
191 struct list_head lrr_linkage;
195 * per file-descriptor read-ahead data.
197 struct ll_readahead_state {
200 * index of the last page that read(2) needed and that wasn't in the
201 * cache. Used by ras_update() to detect seeks.
203 * XXX nikita: if access seeks into cached region, Lustre doesn't see
206 unsigned long ras_last_readpage;
208 * number of pages read after last read-ahead window reset. As window
209 * is reset on each seek, this is effectively a number of consecutive
210 * accesses. Maybe ->ras_accessed_in_window is better name.
212 * XXX nikita: window is also reset (by ras_update()) when Lustre
213 * believes that memory pressure evicts read-ahead pages. In that
214 * case, it probably doesn't make sense to expand window to
215 * PTLRPC_MAX_BRW_PAGES on the third access.
217 unsigned long ras_consecutive;
219 * Parameters of current read-ahead window. Handled by
220 * ras_update(). On the initial access to the file or after a seek,
221 * window is reset to 0. After 3 consecutive accesses, window is
222 * expanded to PTLRPC_MAX_BRW_PAGES. Afterwards, window is enlarged by
223 * PTLRPC_MAX_BRW_PAGES chunks up to ->ra_max_pages.
225 unsigned long ras_window_start, ras_window_len;
227 * Where next read-ahead should start at. This lies within read-ahead
228 * window. Read-ahead window is read in pieces rather than at once
229 * because: 1. lustre limits total number of pages under read-ahead by
230 * ->ra_max_pages (see ll_ra_count_get()), 2. client cannot read pages
231 * not covered by DLM lock.
233 unsigned long ras_next_readahead;
235 * list of struct ll_ra_read's one per read(2) call current in
236 * progress against this file descriptor. Used by read-ahead code,
237 * protected by ->ras_lock.
239 struct list_head ras_read_beads;
242 extern kmem_cache_t *ll_file_data_slab;
243 struct lustre_handle;
244 struct ll_file_data {
245 struct obd_client_handle fd_mds_och;
246 struct ll_readahead_state fd_ras;
248 struct lustre_handle fd_cwlockh;
249 unsigned long fd_gid;
252 struct lov_stripe_md;
254 extern spinlock_t inode_lock;
256 extern struct proc_dir_entry *proc_lustre_fs_root;
258 static inline struct inode *ll_info2i(struct ll_inode_info *lli)
260 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
261 return &lli->lli_vfs_inode;
263 return list_entry(lli, struct inode, u.generic_ip);
268 struct inode *icbd_parent;
269 struct dentry **icbd_childp;
273 void ll_i2gids(__u32 *suppgids, struct inode *i1,struct inode *i2);
275 #define LLAP_MAGIC 98764321
277 extern kmem_cache_t *ll_async_page_slab;
278 extern size_t ll_async_page_slab_size;
279 struct ll_async_page {
281 /* only trust these if the page lock is providing exclusion */
282 unsigned int llap_write_queued:1,
283 llap_defer_uptodate:1,
288 struct page *llap_page;
289 struct list_head llap_pending_write;
290 struct list_head llap_pglist_item;
291 /* checksum for paranoid I/O debugging */
296 * enumeration of llap_from_page() call-sites. Used to export statistics in
297 * /proc/fs/lustre/llite/fsN/dump_page_cache.
300 LLAP_ORIGIN_UNKNOWN = 0,
301 LLAP_ORIGIN_READPAGE,
302 LLAP_ORIGIN_READAHEAD,
303 LLAP_ORIGIN_COMMIT_WRITE,
304 LLAP_ORIGIN_WRITEPAGE,
305 LLAP_ORIGIN_REMOVEPAGE,
308 extern char *llap_origins[];
310 #ifdef HAVE_REGISTER_CACHE
311 #define ll_register_cache(cache) register_cache(cache)
312 #define ll_unregister_cache(cache) unregister_cache(cache)
314 #define ll_register_cache(cache) do {} while (0)
315 #define ll_unregister_cache(cache) do {} while (0)
318 void ll_ra_read_in(struct file *f, struct ll_ra_read *rar);
319 void ll_ra_read_ex(struct file *f, struct ll_ra_read *rar);
320 struct ll_ra_read *ll_ra_read_get(struct file *f);
322 /* llite/lproc_llite.c */
324 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
325 struct super_block *sb, char *osc, char *mdc);
326 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi);
328 static inline int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
329 struct super_block *sb, char *osc, char *mdc){return 0;}
330 static inline void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi) {}
335 extern struct file_operations ll_dir_operations;
336 extern struct inode_operations ll_dir_inode_operations;
339 int ll_objects_destroy(struct ptlrpc_request *request, struct inode *dir);
340 struct inode *ll_iget(struct super_block *sb, ino_t hash,
341 struct lustre_md *lic);
342 struct dentry *ll_find_alias(struct inode *, struct dentry *);
343 int ll_mdc_cancel_unused(struct lustre_handle *, struct inode *, int flags,
345 int ll_mdc_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
346 void *data, int flag);
347 void ll_prepare_mdc_op_data(struct mdc_op_data *,
348 struct inode *i1, struct inode *i2,
349 const char *name, int namelen, int mode);
352 int ll_prepare_write(struct file *, struct page *, unsigned from, unsigned to);
353 int ll_commit_write(struct file *, struct page *, unsigned from, unsigned to);
354 int ll_writepage(struct page *page);
355 void ll_inode_fill_obdo(struct inode *inode, int cmd, struct obdo *oa);
356 void ll_ap_completion(void *data, int cmd, struct obdo *oa, int rc);
357 int llap_shrink_cache(struct ll_sb_info *sbi, int shrink_fraction);
358 extern struct cache_definition ll_cache_definition;
359 void ll_removepage(struct page *page);
360 int ll_readpage(struct file *file, struct page *page);
361 struct ll_async_page *llap_from_cookie(void *cookie);
362 struct ll_async_page *llap_cast_private(struct page *page);
363 void ll_readahead_init(struct inode *inode, struct ll_readahead_state *ras);
364 void ll_ra_accounting(struct ll_async_page *llap,struct address_space *mapping);
365 void ll_truncate(struct inode *inode);
368 extern struct file_operations ll_file_operations;
369 extern struct file_operations ll_file_operations_flock;
370 extern struct inode_operations ll_file_inode_operations;
371 extern int ll_inode_revalidate_it(struct dentry *, struct lookup_intent *);
372 int ll_extent_lock(struct ll_file_data *, struct inode *,
373 struct lov_stripe_md *, int mode, ldlm_policy_data_t *,
374 struct lustre_handle *, int ast_flags);
375 int ll_extent_unlock(struct ll_file_data *, struct inode *,
376 struct lov_stripe_md *, int mode, struct lustre_handle *);
377 int ll_file_open(struct inode *inode, struct file *file);
378 int ll_file_release(struct inode *inode, struct file *file);
379 int ll_lsm_getattr(struct obd_export *, struct lov_stripe_md *, struct obdo *);
380 int ll_glimpse_size(struct inode *inode, int ast_flags);
381 int ll_local_open(struct file *file,
382 struct lookup_intent *it, struct ll_file_data *fd);
383 int ll_mdc_close(struct obd_export *mdc_exp, struct inode *inode,
385 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
386 int ll_getattr(struct vfsmount *mnt, struct dentry *de,
387 struct lookup_intent *it, struct kstat *stat);
389 struct ll_file_data *ll_file_data_get(void);
390 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
391 int ll_inode_permission(struct inode *inode, int mask, struct nameidata *nd);
393 int ll_inode_permission(struct inode *inode, int mask);
397 void ll_intent_drop_lock(struct lookup_intent *);
398 void ll_intent_release(struct lookup_intent *);
399 extern void ll_set_dd(struct dentry *de);
400 void ll_unhash_aliases(struct inode *);
401 void ll_frob_intent(struct lookup_intent **itp, struct lookup_intent *deft);
402 void ll_lookup_finish_locks(struct lookup_intent *it, struct dentry *dentry);
403 int ll_dcompare(struct dentry *parent, struct qstr *d_name, struct qstr *name);
405 /* llite/llite_lib.c */
407 extern struct super_operations lustre_super_operations;
409 char *ll_read_opt(const char *opt, char *data);
410 void ll_options(char *options, int *flags);
411 void ll_lli_init(struct ll_inode_info *lli);
412 int ll_fill_super(struct super_block *sb);
413 void ll_put_super(struct super_block *sb);
414 struct inode *ll_inode_from_lock(struct ldlm_lock *lock);
415 void ll_clear_inode(struct inode *inode);
416 int ll_setattr_raw(struct inode *inode, struct iattr *attr);
417 int ll_setattr(struct dentry *de, struct iattr *attr);
418 int ll_statfs(struct super_block *sb, struct kstatfs *sfs);
419 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
420 unsigned long maxage);
421 void ll_update_inode(struct inode *inode, struct lustre_md *md);
422 void ll_read_inode2(struct inode *inode, void *opaque);
423 int ll_iocontrol(struct inode *inode, struct file *file,
424 unsigned int cmd, unsigned long arg);
425 void ll_umount_begin(struct super_block *sb);
426 int ll_remount_fs(struct super_block *sb, int *flags, char *data);
427 int ll_prep_inode(struct obd_export *exp, struct inode **inode,
428 struct ptlrpc_request *req, int offset, struct super_block *);
429 void lustre_dump_dentry(struct dentry *, int recur);
430 void lustre_dump_inode(struct inode *);
431 struct ll_async_page *llite_pglist_next_llap(struct ll_sb_info *sbi,
432 struct list_head *list);
433 int ll_obd_statfs(struct inode *inode, void *arg);
434 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *max_mdsize);
436 /* llite/llite_nfs.c */
437 __u32 get_uuid2int(const char *name, int len);
438 struct dentry *ll_fh_to_dentry(struct super_block *sb, __u32 *data, int len,
439 int fhtype, int parent);
440 int ll_dentry_to_fh(struct dentry *, __u32 *datap, int *lenp, int need_parent);
442 /* llite/special.c */
443 extern struct inode_operations ll_special_inode_operations;
444 extern struct file_operations ll_special_chr_inode_fops;
445 extern struct file_operations ll_special_chr_file_fops;
446 extern struct file_operations ll_special_blk_inode_fops;
447 extern struct file_operations ll_special_fifo_inode_fops;
448 extern struct file_operations ll_special_fifo_file_fops;
449 extern struct file_operations ll_special_sock_inode_fops;
451 /* llite/symlink.c */
452 extern struct inode_operations ll_fast_symlink_inode_operations;
454 /* llite/llite_close.c */
455 struct ll_close_queue {
457 struct list_head lcq_list;
458 wait_queue_head_t lcq_waitq;
459 struct completion lcq_comp;
462 void llap_write_pending(struct inode *inode, struct ll_async_page *llap);
463 void llap_write_complete(struct inode *inode, struct ll_async_page *llap);
464 void ll_open_complete(struct inode *inode);
465 int ll_is_inode_dirty(struct inode *inode);
466 void ll_try_done_writing(struct inode *inode);
467 void ll_queue_done_writing(struct inode *inode);
468 void ll_close_thread_shutdown(struct ll_close_queue *lcq);
469 int ll_close_thread_start(struct ll_close_queue **lcq_ret);
471 /* llite/llite_mmap.c */
472 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
473 typedef struct rb_root rb_root_t;
474 typedef struct rb_node rb_node_t;
477 struct ll_lock_tree_node;
478 struct ll_lock_tree {
480 struct list_head lt_locked_list;
481 struct ll_file_data *lt_fd;
484 int ll_teardown_mmaps(struct address_space *mapping, __u64 first, __u64 last);
485 int ll_file_mmap(struct file * file, struct vm_area_struct * vma);
486 struct ll_lock_tree_node * ll_node_from_inode(struct inode *inode, __u64 start,
487 __u64 end, ldlm_mode_t mode);
488 int ll_tree_lock(struct ll_lock_tree *tree,
489 struct ll_lock_tree_node *first_node,
490 const char *buf, size_t count, int ast_flags);
491 int ll_tree_unlock(struct ll_lock_tree *tree);
494 #define LL_MAX_BLKSIZE (4UL * 1024 * 1024)
496 #define ll_s2sbi(sb) (s2lsi(sb)->lsi_llsbi)
498 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
499 void __d_rehash(struct dentry * entry, int lock);
500 static inline __u64 ll_ts2u64(struct timespec *time)
502 __u64 t = time->tv_sec;
506 static inline __u64 ll_ts2u64(time_t *time)
512 /* don't need an addref as the sb_info should be holding one */
513 static inline struct obd_export *ll_s2obdexp(struct super_block *sb)
515 return ll_s2sbi(sb)->ll_osc_exp;
518 /* don't need an addref as the sb_info should be holding one */
519 static inline struct obd_export *ll_s2mdcexp(struct super_block *sb)
521 return ll_s2sbi(sb)->ll_mdc_exp;
524 static inline struct client_obd *sbi2mdc(struct ll_sb_info *sbi)
526 struct obd_device *obd = sbi->ll_mdc_exp->exp_obd;
532 // FIXME: replace the name of this with LL_SB to conform to kernel stuff
533 static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
535 return ll_s2sbi(inode->i_sb);
538 static inline struct obd_export *ll_i2obdexp(struct inode *inode)
540 return ll_s2obdexp(inode->i_sb);
543 static inline struct obd_export *ll_i2mdcexp(struct inode *inode)
545 return ll_s2mdcexp(inode->i_sb);
548 static inline void ll_inode2fid(struct lu_fid *fid, struct inode *inode)
550 LASSERT(fid != NULL);
551 LASSERT(inode != NULL);
552 *fid = ll_i2info(inode)->lli_fid;
555 static inline int ll_mds_max_easize(struct super_block *sb)
557 return sbi2mdc(ll_s2sbi(sb))->cl_max_mds_easize;
560 static inline __u64 ll_file_maxbytes(struct inode *inode)
562 return ll_i2info(inode)->lli_maxbytes;
566 int ll_setxattr(struct dentry *dentry, const char *name,
567 const void *value, size_t size, int flags);
568 ssize_t ll_getxattr(struct dentry *dentry, const char *name,
569 void *buffer, size_t size);
570 ssize_t ll_listxattr(struct dentry *dentry, char *buffer, size_t size);
571 int ll_removexattr(struct dentry *dentry, const char *name);
573 /* llite/llite_fid.c*/
574 int ll_fid_alloc(struct ll_sb_info *sbi, struct lu_fid *fid);
575 unsigned long ll_fid2ino(struct ll_sb_info *sbi, struct lu_fid *fid);
577 #endif /* LLITE_INTERNAL_H */