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
11 # include <linux/xattr_acl.h>
13 #ifdef HAVE_LINUX_POSIX_ACL_XATTR_H
14 # include <linux/posix_acl_xattr.h>
18 #include <lustre_debug.h>
19 #include <lustre_ver.h>
20 #include <linux/lustre_version.h>
21 #include <lustre_disk.h> /* for s2sbi */
24 struct lustre_intent_data {
25 __u64 it_lock_handle[2];
31 /* If there is no FMODE_EXEC defined, make it to match nothing */
36 #define LL_IT2STR(it) ((it) ? ldlm_it2str((it)->it_op) : "0")
37 #define LUSTRE_FPRIVATE(file) ((file)->private_data)
39 #ifdef HAVE_VFS_INTENT_PATCHES
40 static inline struct lookup_intent *ll_nd2it(struct nameidata *nd)
42 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
51 * Directory entries are currently in the same format as ext2/ext3, but will
52 * be changed in the future to accomodate FIDs
54 #define LL_DIR_NAME_LEN (255)
55 #define LL_DIR_PAD (4)
58 /* number of inode, referenced by this entry */
60 /* total record length, multiple of LL_DIR_PAD */
64 /* file type: regular, directory, device, etc. */
66 /* name. NOT NUL-terminated */
67 char lde_name[LL_DIR_NAME_LEN];
70 struct ll_dentry_data {
73 struct obd_client_handle lld_cwd_och;
74 struct obd_client_handle lld_mnt_och;
75 #ifndef HAVE_VFS_INTENT_PATCHES
76 struct lookup_intent *lld_it;
78 unsigned int lld_sa_generation;
79 cfs_waitq_t lld_waitq;
82 #define ll_d2d(de) ((struct ll_dentry_data*)((de)->d_fsdata))
84 extern struct file_operations ll_pgcache_seq_fops;
86 #define LLI_INODE_MAGIC 0x111d0de5
87 #define LLI_INODE_DEAD 0xdeadd00d
88 #define LLI_F_HAVE_OST_SIZE_LOCK 0
89 #define LLI_F_HAVE_MDS_SIZE_LOCK 1
90 #define LLI_F_CONTENDED 2
91 #define LLI_F_SRVLOCK 3
93 struct ll_inode_info {
95 struct semaphore lli_size_sem; /* protect open and change size */
96 void *lli_size_sem_owner;
97 struct semaphore lli_write_sem;
98 struct lov_stripe_md *lli_smd;
99 char *lli_symlink_name;
102 unsigned long lli_flags;
103 cfs_time_t lli_contention_time;
105 /* this lock protects s_d_w and p_w_ll and mmap_cnt */
107 #ifdef HAVE_CLOSE_THREAD
108 struct list_head lli_pending_write_llaps;
109 struct list_head lli_close_item;
110 int lli_send_done_writing;
112 atomic_t lli_mmap_cnt;
114 /* for writepage() only to communicate to fsync */
117 struct posix_acl *lli_posix_acl;
119 struct list_head lli_dead_list;
121 struct semaphore lli_och_sem; /* Protects access to och pointers
122 and their usage counters */
123 /* We need all three because every inode may be opened in different
125 struct obd_client_handle *lli_mds_read_och;
126 __u64 lli_open_fd_read_count;
127 struct obd_client_handle *lli_mds_write_och;
128 __u64 lli_open_fd_write_count;
129 struct obd_client_handle *lli_mds_exec_och;
130 __u64 lli_open_fd_exec_count;
132 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
133 struct inode lli_vfs_inode;
136 /* metadata stat-ahead */
138 * "opendir_pid" is the token when lookup/revalid -- I am the owner of
141 pid_t lli_opendir_pid;
143 * since parent-child threads can share the same @file struct,
144 * "opendir_key" is the token when dir close for case of parent exit
145 * before child -- it is me should cleanup the dir readahead. */
146 void *lli_opendir_key;
147 struct ll_statahead_info *lli_sai;
151 * Locking to guarantee consistency of non-atomic updates to long long i_size,
152 * consistency between file size and KMS, and consistency within
153 * ->lli_smd->lsm_oinfo[]'s.
155 * Implemented by ->lli_size_sem and ->lsm_sem, nested in that order.
158 void ll_inode_size_lock(struct inode *inode, int lock_lsm);
159 void ll_inode_size_unlock(struct inode *inode, int unlock_lsm);
161 // FIXME: replace the name of this with LL_I to conform to kernel stuff
162 // static inline struct ll_inode_info *LL_I(struct inode *inode)
163 static inline struct ll_inode_info *ll_i2info(struct inode *inode)
165 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
166 return container_of(inode, struct ll_inode_info, lli_vfs_inode);
168 CLASSERT(sizeof(inode->u) >= sizeof(struct ll_inode_info));
169 return (struct ll_inode_info *)&(inode->u.generic_ip);
173 /* default to about 40meg of readahead on a given system. That much tied
174 * up in 512k readahead requests serviced at 40ms each is about 1GB/s. */
175 #define SBI_DEFAULT_READAHEAD_MAX (40UL << (20 - CFS_PAGE_SHIFT))
177 /* default to read-ahead full files smaller than 2MB on the second read */
178 #define SBI_DEFAULT_READAHEAD_WHOLE_MAX (2UL << (20 - CFS_PAGE_SHIFT))
183 RA_STAT_DISTANT_READPAGE,
184 RA_STAT_MISS_IN_WINDOW,
185 RA_STAT_FAILED_GRAB_PAGE,
186 RA_STAT_FAILED_MATCH,
191 RA_STAT_MAX_IN_FLIGHT,
192 RA_STAT_WRONG_GRAB_PAGE,
197 unsigned long ra_cur_pages;
198 unsigned long ra_max_pages;
199 unsigned long ra_max_read_ahead_whole_pages;
200 unsigned long ra_stats[_NR_RA_STAT];
203 /* LL_HIST_MAX=32 causes an overflow */
204 #define LL_HIST_MAX 28
205 #define LL_HIST_START 12 /* buckets start at 2^12 = 4k */
206 #define LL_PROCESS_HIST_MAX 10
207 struct per_process_info {
209 struct obd_histogram pp_r_hist;
210 struct obd_histogram pp_w_hist;
213 /* pp_extents[LL_PROCESS_HIST_MAX] will hold the combined process info */
214 struct ll_rw_extents_info {
215 struct per_process_info pp_extents[LL_PROCESS_HIST_MAX + 1];
218 #define LL_OFFSET_HIST_MAX 100
219 struct ll_rw_process_info {
222 loff_t rw_range_start;
224 loff_t rw_last_file_pos;
226 size_t rw_smallest_extent;
227 size_t rw_largest_extent;
228 struct file *rw_last_file;
232 enum stats_track_type {
233 STATS_TRACK_ALL = 0, /* track all processes */
234 STATS_TRACK_PID, /* track process with this pid */
235 STATS_TRACK_PPID, /* track processes with this ppid */
236 STATS_TRACK_GID, /* track processes with this gid */
240 /* flags for sbi->ll_flags */
241 #define LL_SBI_NOLCK 0x01 /* DLM locking disabled (directio-only) */
242 #define LL_SBI_DATA_CHECKSUM 0x02 /* checksum each page on the wire */
243 #define LL_SBI_FLOCK 0x04
244 #define LL_SBI_USER_XATTR 0x08 /* support user xattr */
245 #define LL_SBI_ACL 0x10 /* support ACL */
246 #define LL_SBI_JOIN 0x20 /* support JOIN */
247 #define LL_SBI_LOCALFLOCK 0x40 /* Local flocks support by kernel */
248 #define LL_SBI_LRU_RESIZE 0x80 /* support lru resize */
249 #define LL_SBI_LLITE_CHECKSUM 0x100 /* checksum each page in memory */
251 /* default value for ll_sb_info->contention_time */
252 #define SBI_DEFAULT_CONTENTION_SECONDS 60
253 /* default value for lockless_truncate_enable */
254 #define SBI_DEFAULT_LOCKLESS_TRUNCATE_ENABLE 1
257 struct list_head ll_list;
258 /* this protects pglist and ra_info. It isn't safe to
259 * grab from interrupt contexts */
261 spinlock_t ll_pp_extent_lock; /* Lock for pp_extent entries */
262 spinlock_t ll_process_lock; /* Lock for ll_rw_process_info */
263 struct obd_uuid ll_sb_uuid;
264 struct obd_export *ll_mdc_exp;
265 struct obd_export *ll_osc_exp;
266 struct proc_dir_entry *ll_proc_root;
267 obd_id ll_rootino; /* number of root inode */
270 struct list_head ll_conn_chain; /* per-conn chain of SBs */
271 struct lustre_client_ocd ll_lco;
273 struct list_head ll_orphan_dentry_list; /*please don't ask -p*/
274 struct ll_close_queue *ll_lcq;
276 struct lprocfs_stats *ll_stats; /* lprocfs stats counter */
278 unsigned long ll_async_page_max;
279 unsigned long ll_async_page_count;
280 unsigned long ll_pglist_gen;
281 struct list_head ll_pglist; /* all pages (llap_pglist_item) */
283 unsigned ll_contention_time; /* seconds */
284 unsigned ll_lockless_truncate_enable; /* true/false */
286 struct ll_ra_info ll_ra_info;
287 unsigned int ll_namelen;
288 struct file_operations *ll_fop;
290 #ifdef HAVE_EXPORT___IGET
291 struct list_head ll_deathrow; /* inodes to be destroyed (b1443) */
292 spinlock_t ll_deathrow_lock;
294 /* =0 - hold lock over whole read/write
295 * >0 - max. chunk to be read/written w/o lock re-acquiring */
296 unsigned long ll_max_rw_chunk;
299 struct ll_rw_extents_info ll_rw_extents_info;
300 int ll_extent_process_count;
301 struct ll_rw_process_info ll_rw_process_info[LL_PROCESS_HIST_MAX];
302 unsigned int ll_offset_process_count;
303 struct ll_rw_process_info ll_rw_offset_info[LL_OFFSET_HIST_MAX];
304 unsigned int ll_rw_offset_entry_count;
305 enum stats_track_type ll_stats_track_type;
306 int ll_stats_track_id;
308 dev_t ll_sdev_orig; /* save s_dev before assign for
311 /* metadata stat-ahead */
312 unsigned int ll_sa_max; /* max statahead RPCs */
313 unsigned int ll_sa_wrong; /* statahead thread stopped for
315 unsigned int ll_sa_total; /* statahead thread started
317 unsigned long long ll_sa_blocked; /* ls count waiting for
319 unsigned long long ll_sa_cached; /* ls count got in cache */
320 unsigned long long ll_sa_hit; /* hit count */
321 unsigned long long ll_sa_miss; /* miss count */
324 #define LL_DEFAULT_MAX_RW_CHUNK (32 * 1024 * 1024)
329 struct task_struct *lrr_reader;
330 struct list_head lrr_linkage;
334 * per file-descriptor read-ahead data.
336 struct ll_readahead_state {
339 * index of the last page that read(2) needed and that wasn't in the
340 * cache. Used by ras_update() to detect seeks.
342 * XXX nikita: if access seeks into cached region, Lustre doesn't see
345 unsigned long ras_last_readpage;
347 * number of pages read after last read-ahead window reset. As window
348 * is reset on each seek, this is effectively a number of consecutive
349 * accesses. Maybe ->ras_accessed_in_window is better name.
351 * XXX nikita: window is also reset (by ras_update()) when Lustre
352 * believes that memory pressure evicts read-ahead pages. In that
353 * case, it probably doesn't make sense to expand window to
354 * PTLRPC_MAX_BRW_PAGES on the third access.
356 unsigned long ras_consecutive_pages;
358 * number of read requests after the last read-ahead window reset
359 * As window is reset on each seek, this is effectively the number
360 * on consecutive read request and is used to trigger read-ahead.
362 unsigned long ras_consecutive_requests;
364 * Parameters of current read-ahead window. Handled by
365 * ras_update(). On the initial access to the file or after a seek,
366 * window is reset to 0. After 3 consecutive accesses, window is
367 * expanded to PTLRPC_MAX_BRW_PAGES. Afterwards, window is enlarged by
368 * PTLRPC_MAX_BRW_PAGES chunks up to ->ra_max_pages.
370 unsigned long ras_window_start, ras_window_len;
372 * Where next read-ahead should start at. This lies within read-ahead
373 * window. Read-ahead window is read in pieces rather than at once
374 * because: 1. lustre limits total number of pages under read-ahead by
375 * ->ra_max_pages (see ll_ra_count_get()), 2. client cannot read pages
376 * not covered by DLM lock.
378 unsigned long ras_next_readahead;
380 * Total number of ll_file_read requests issued, reads originating
381 * due to mmap are not counted in this total. This value is used to
382 * trigger full file read-ahead after multiple reads to a small file.
384 unsigned long ras_requests;
386 * Page index with respect to the current request, these value
387 * will not be accurate when dealing with reads issued via mmap.
389 unsigned long ras_request_index;
391 * list of struct ll_ra_read's one per read(2) call current in
392 * progress against this file descriptor. Used by read-ahead code,
393 * protected by ->ras_lock.
395 struct list_head ras_read_beads;
397 * The following 3 items are used for detecting the stride I/O
399 * In stride I/O mode,
400 * ...............|-----data-----|****gap*****|--------|******|....
401 * offset |-stride_pages-|-stride_gap-|
402 * ras_stride_offset = offset;
403 * ras_stride_length = stride_pages + stride_gap;
404 * ras_stride_pages = stride_pages;
405 * Note: all these three items are counted by pages.
407 unsigned long ras_stride_length;
408 unsigned long ras_stride_pages;
409 pgoff_t ras_stride_offset;
411 * number of consecutive stride request count, and it is similar as
412 * ras_consecutive_requests, but used for stride I/O mode.
413 * Note: only more than 2 consecutive stride request are detected,
414 * stride read-ahead will be enable
416 unsigned long ras_consecutive_stride_requests;
419 extern cfs_mem_cache_t *ll_file_data_slab;
420 struct lustre_handle;
421 struct ll_file_data {
422 struct ll_readahead_state fd_ras;
424 struct lustre_handle fd_cwlockh;
425 unsigned long fd_gid;
429 struct lov_stripe_md;
431 extern spinlock_t inode_lock;
433 extern struct proc_dir_entry *proc_lustre_fs_root;
435 static inline struct inode *ll_info2i(struct ll_inode_info *lli)
437 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
438 return &lli->lli_vfs_inode;
440 return list_entry(lli, struct inode, u.generic_ip);
445 struct inode *icbd_parent;
446 struct dentry **icbd_childp;
450 void ll_i2gids(__u32 *suppgids, struct inode *i1,struct inode *i2);
452 #define LLAP_MAGIC 98764321
454 extern cfs_mem_cache_t *ll_async_page_slab;
455 extern size_t ll_async_page_slab_size;
456 struct ll_async_page {
458 /* only trust these if the page lock is providing exclusion */
459 unsigned int llap_write_queued:1,
460 llap_defer_uptodate:1,
465 llap_lockless_io_page:1;
467 struct page *llap_page;
468 struct list_head llap_pending_write;
469 struct list_head llap_pglist_item;
470 /* checksum for paranoid I/O debugging */
475 * enumeration of llap_from_page() call-sites. Used to export statistics in
476 * /proc/fs/lustre/llite/fsN/dump_page_cache.
479 LLAP_ORIGIN_UNKNOWN = 0,
480 LLAP_ORIGIN_READPAGE,
481 LLAP_ORIGIN_READAHEAD,
482 LLAP_ORIGIN_COMMIT_WRITE,
483 LLAP_ORIGIN_WRITEPAGE,
484 LLAP_ORIGIN_REMOVEPAGE,
485 LLAP_ORIGIN_LOCKLESS_IO,
488 extern char *llap_origins[];
490 #ifdef HAVE_REGISTER_CACHE
491 #define ll_register_cache(cache) register_cache(cache)
492 #define ll_unregister_cache(cache) unregister_cache(cache)
494 #define ll_register_cache(cache) do {} while (0)
495 #define ll_unregister_cache(cache) do {} while (0)
498 void ll_ra_read_in(struct file *f, struct ll_ra_read *rar);
499 void ll_ra_read_ex(struct file *f, struct ll_ra_read *rar);
500 struct ll_ra_read *ll_ra_read_get(struct file *f);
502 /* llite/lproc_llite.c */
504 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
505 struct super_block *sb, char *osc, char *mdc);
506 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi);
507 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count);
508 void lprocfs_llite_init_vars(struct lprocfs_static_vars *lvars);
510 static inline int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
511 struct super_block *sb, char *osc, char *mdc){return 0;}
512 static inline void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi) {}
513 static void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count) {}
514 static void lprocfs_llite_init_vars(struct lprocfs_static_vars *lvars)
516 memset(lvars, 0, sizeof(*lvars));
522 extern struct file_operations ll_dir_operations;
523 extern struct inode_operations ll_dir_inode_operations;
525 struct page *ll_get_dir_page(struct inode *dir, unsigned long n);
527 static inline unsigned ll_dir_rec_len(unsigned name_len)
529 return (name_len + 8 + LL_DIR_PAD - 1) & ~(LL_DIR_PAD - 1);
532 static inline struct ll_dir_entry *ll_entry_at(void *base, unsigned offset)
534 return (struct ll_dir_entry *)((char *)base + offset);
538 * p is at least 6 bytes before the end of page
540 static inline struct ll_dir_entry *ll_dir_next_entry(struct ll_dir_entry *p)
542 return ll_entry_at(p, le16_to_cpu(p->lde_rec_len));
545 static inline void ll_put_page(struct page *page)
548 page_cache_release(page);
551 static inline unsigned long dir_pages(struct inode *inode)
553 return (inode->i_size + CFS_PAGE_SIZE - 1) >> CFS_PAGE_SHIFT;
557 int ll_objects_destroy(struct ptlrpc_request *request, struct inode *dir);
558 struct inode *ll_iget(struct super_block *sb, ino_t hash,
559 struct lustre_md *lic);
560 int ll_mdc_cancel_unused(struct lustre_handle *, struct inode *, int flags,
562 int ll_mdc_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
563 void *data, int flag);
564 int ll_prepare_mdc_op_data(struct mdc_op_data *,
565 struct inode *i1, struct inode *i2,
566 const char *name, int namelen, int mode, void *data);
567 #ifndef HAVE_VFS_INTENT_PATCHES
568 struct lookup_intent *ll_convert_intent(struct open_intent *oit,
571 void ll_pin_extent_cb(void *data);
572 int ll_page_removal_cb(void *data, int discard);
573 int ll_extent_lock_cancel_cb(struct ldlm_lock *lock, struct ldlm_lock_desc *new,
574 void *data, int flag);
575 int lookup_it_finish(struct ptlrpc_request *request, int offset,
576 struct lookup_intent *it, void *data);
577 void ll_lookup_finish_locks(struct lookup_intent *it, struct dentry *dentry);
580 int ll_prepare_write(struct file *, struct page *, unsigned from, unsigned to);
581 int ll_commit_write(struct file *, struct page *, unsigned from, unsigned to);
582 int ll_writepage(struct page *page);
583 void ll_inode_fill_obdo(struct inode *inode, int cmd, struct obdo *oa);
584 int ll_ap_completion(void *data, int cmd, struct obdo *oa, int rc);
585 int llap_shrink_cache(struct ll_sb_info *sbi, int shrink_fraction);
586 extern struct cache_definition ll_cache_definition;
587 void ll_removepage(struct page *page);
588 int ll_readpage(struct file *file, struct page *page);
589 struct ll_async_page *llap_cast_private(struct page *page);
590 void ll_readahead_init(struct inode *inode, struct ll_readahead_state *ras);
591 void ll_ra_accounting(struct ll_async_page *llap,struct address_space *mapping);
592 void ll_truncate(struct inode *inode);
593 int ll_file_punch(struct inode *, loff_t, int);
594 ssize_t ll_file_lockless_io(struct file *, const struct iovec *,
595 unsigned long, loff_t *, int, ssize_t);
596 void ll_clear_file_contended(struct inode*);
597 int ll_sync_page_range(struct inode *, struct address_space *, loff_t, size_t);
600 extern struct file_operations ll_file_operations;
601 extern struct file_operations ll_file_operations_flock;
602 extern struct file_operations ll_file_operations_noflock;
603 extern struct inode_operations ll_file_inode_operations;
604 extern int ll_inode_revalidate_it(struct dentry *, struct lookup_intent *);
605 extern int ll_have_md_lock(struct inode *inode, __u64 bits);
606 int ll_region_mapped(unsigned long addr, size_t count);
607 int ll_extent_lock(struct ll_file_data *, struct inode *,
608 struct lov_stripe_md *, int mode, ldlm_policy_data_t *,
609 struct lustre_handle *, int ast_flags);
610 int ll_extent_unlock(struct ll_file_data *, struct inode *,
611 struct lov_stripe_md *, int mode, struct lustre_handle *);
612 int ll_file_open(struct inode *inode, struct file *file);
613 int ll_file_release(struct inode *inode, struct file *file);
614 int ll_lsm_getattr(struct obd_export *, struct lov_stripe_md *, struct obdo *);
615 int ll_glimpse_ioctl(struct ll_sb_info *sbi,
616 struct lov_stripe_md *lsm, lstat_t *st);
617 int ll_glimpse_size(struct inode *inode, int ast_flags);
618 int ll_local_open(struct file *file,
619 struct lookup_intent *it, struct ll_file_data *fd,
620 struct obd_client_handle *och);
621 int ll_release_openhandle(struct dentry *, struct lookup_intent *);
622 int ll_mdc_close(struct obd_export *mdc_exp, struct inode *inode,
624 int ll_mdc_real_close(struct inode *inode, int flags);
625 extern void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid, struct file
626 *file, size_t count, int rw);
627 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
628 int ll_getattr_it(struct vfsmount *mnt, struct dentry *de,
629 struct lookup_intent *it, struct kstat *stat);
630 int ll_getattr(struct vfsmount *mnt, struct dentry *de, struct kstat *stat);
632 struct ll_file_data *ll_file_data_get(void);
633 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
634 int ll_inode_permission(struct inode *inode, int mask, struct nameidata *nd);
636 int ll_inode_permission(struct inode *inode, int mask);
638 int ll_lov_setstripe_ea_info(struct inode *inode, struct file *file,
639 int flags, struct lov_user_md *lum,
641 int ll_lov_getstripe_ea_info(struct inode *inode, const char *filename,
642 struct lov_mds_md **lmm, int *lmm_size,
643 struct ptlrpc_request **request);
644 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
646 int ll_dir_getstripe(struct inode *inode, struct lov_mds_md **lmm,
647 int *lmm_size, struct ptlrpc_request **request);
650 extern struct dentry_operations ll_init_d_ops;
651 extern struct dentry_operations ll_d_ops;
652 extern struct dentry_operations ll_fini_d_ops;
653 void ll_release(struct dentry *de);
654 void ll_intent_drop_lock(struct lookup_intent *);
655 void ll_intent_release(struct lookup_intent *);
656 extern void ll_set_dd(struct dentry *de);
657 int ll_drop_dentry(struct dentry *dentry);
658 void ll_unhash_aliases(struct inode *);
659 void ll_frob_intent(struct lookup_intent **itp, struct lookup_intent *deft);
660 void ll_lookup_finish_locks(struct lookup_intent *it, struct dentry *dentry);
661 int ll_dcompare(struct dentry *parent, struct qstr *d_name, struct qstr *name);
662 int revalidate_it_finish(struct ptlrpc_request *request, int offset,
663 struct lookup_intent *it, struct dentry *de);
665 /* llite/llite_lib.c */
666 extern struct super_operations lustre_super_operations;
668 char *ll_read_opt(const char *opt, char *data);
669 void ll_lli_init(struct ll_inode_info *lli);
670 int ll_fill_super(struct super_block *sb);
671 void ll_put_super(struct super_block *sb);
672 void ll_kill_super(struct super_block *sb);
673 struct inode *ll_inode_from_lock(struct ldlm_lock *lock);
674 void ll_clear_inode(struct inode *inode);
675 int ll_setattr_raw(struct inode *inode, struct iattr *attr);
676 int ll_setattr(struct dentry *de, struct iattr *attr);
677 #ifndef HAVE_STATFS_DENTRY_PARAM
678 int ll_statfs(struct super_block *sb, struct kstatfs *sfs);
680 int ll_statfs(struct dentry *de, struct kstatfs *sfs);
682 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
683 __u64 max_age, __u32 flags);
684 void ll_update_inode(struct inode *inode, struct lustre_md *md);
685 void ll_read_inode2(struct inode *inode, void *opaque);
686 int ll_iocontrol(struct inode *inode, struct file *file,
687 unsigned int cmd, unsigned long arg);
688 #ifdef HAVE_UMOUNTBEGIN_VFSMOUNT
689 void ll_umount_begin(struct vfsmount *vfsmnt, int flags);
691 void ll_umount_begin(struct super_block *sb);
693 int ll_remount_fs(struct super_block *sb, int *flags, char *data);
694 int ll_prep_inode(struct obd_export *exp, struct inode **inode,
695 struct ptlrpc_request *req, int offset, struct super_block *);
696 void lustre_dump_dentry(struct dentry *, int recur);
697 void lustre_dump_inode(struct inode *);
698 struct ll_async_page *llite_pglist_next_llap(struct ll_sb_info *sbi,
699 struct list_head *list);
700 int ll_obd_statfs(struct inode *inode, void *arg);
701 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *max_mdsize);
702 int ll_process_config(struct lustre_cfg *lcfg);
704 /* llite/llite_nfs.c */
705 extern struct export_operations lustre_export_operations;
706 __u32 get_uuid2int(const char *name, int len);
707 struct dentry *ll_fh_to_dentry(struct super_block *sb, __u32 *data, int len,
708 int fhtype, int parent);
709 int ll_dentry_to_fh(struct dentry *, __u32 *datap, int *lenp, int need_parent);
711 /* llite/special.c */
712 extern struct inode_operations ll_special_inode_operations;
713 extern struct file_operations ll_special_chr_inode_fops;
714 extern struct file_operations ll_special_chr_file_fops;
715 extern struct file_operations ll_special_blk_inode_fops;
716 extern struct file_operations ll_special_fifo_inode_fops;
717 extern struct file_operations ll_special_fifo_file_fops;
718 extern struct file_operations ll_special_sock_inode_fops;
720 /* llite/symlink.c */
721 extern struct inode_operations ll_fast_symlink_inode_operations;
723 /* llite/llite_close.c */
724 struct ll_close_queue {
726 struct list_head lcq_list;
727 wait_queue_head_t lcq_waitq;
728 struct completion lcq_comp;
731 #ifdef HAVE_CLOSE_THREAD
732 void llap_write_pending(struct inode *inode, struct ll_async_page *llap);
733 void llap_write_complete(struct inode *inode, struct ll_async_page *llap);
734 void ll_open_complete(struct inode *inode);
735 int ll_is_inode_dirty(struct inode *inode);
736 void ll_try_done_writing(struct inode *inode);
737 void ll_queue_done_writing(struct inode *inode);
739 static inline void llap_write_pending(struct inode *inode,
740 struct ll_async_page *llap) { return; };
741 static inline void llap_write_complete(struct inode *inode,
742 struct ll_async_page *llap) { return; };
743 static inline void ll_open_complete(struct inode *inode) { return; };
744 static inline int ll_is_inode_dirty(struct inode *inode) { return 0; };
745 static inline void ll_try_done_writing(struct inode *inode) { return; };
746 static inline void ll_queue_done_writing(struct inode *inode) { return; };
747 //static inline void ll_close_thread_shutdown(struct ll_close_queue *lcq) { return; };
748 //static inline int ll_close_thread_start(struct ll_close_queue **lcq_ret) { return 0; };
750 void ll_close_thread_shutdown(struct ll_close_queue *lcq);
751 int ll_close_thread_start(struct ll_close_queue **lcq_ret);
753 /* llite/llite_mmap.c */
754 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
755 typedef struct rb_root rb_root_t;
756 typedef struct rb_node rb_node_t;
759 struct ll_lock_tree_node;
760 struct ll_lock_tree {
762 struct list_head lt_locked_list;
763 struct ll_file_data *lt_fd;
766 int ll_teardown_mmaps(struct address_space *mapping, __u64 first, __u64 last);
767 int ll_file_mmap(struct file * file, struct vm_area_struct * vma);
768 struct ll_lock_tree_node * ll_node_from_inode(struct inode *inode, __u64 start,
769 __u64 end, ldlm_mode_t mode);
770 int ll_tree_lock(struct ll_lock_tree *tree,
771 struct ll_lock_tree_node *first_node,
772 const char *buf, size_t count, int ast_flags);
773 int ll_tree_lock_iov(struct ll_lock_tree *tree,
774 struct ll_lock_tree_node *first_node,
775 const struct iovec *iov, unsigned long nr_segs,
777 int ll_tree_unlock(struct ll_lock_tree *tree);
779 #define ll_s2sbi(sb) (s2lsi(sb)->lsi_llsbi)
781 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
782 static inline __u64 ll_ts2u64(struct timespec *time)
784 __u64 t = time->tv_sec;
788 static inline __u64 ll_ts2u64(time_t *time)
794 /* don't need an addref as the sb_info should be holding one */
795 static inline struct obd_export *ll_s2obdexp(struct super_block *sb)
797 return ll_s2sbi(sb)->ll_osc_exp;
800 /* don't need an addref as the sb_info should be holding one */
801 static inline struct obd_export *ll_s2mdcexp(struct super_block *sb)
803 return ll_s2sbi(sb)->ll_mdc_exp;
806 static inline struct client_obd *sbi2mdc(struct ll_sb_info *sbi)
808 struct obd_device *obd = sbi->ll_mdc_exp->exp_obd;
814 // FIXME: replace the name of this with LL_SB to conform to kernel stuff
815 static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
817 return ll_s2sbi(inode->i_sb);
820 static inline struct obd_export *ll_i2obdexp(struct inode *inode)
822 return ll_s2obdexp(inode->i_sb);
825 static inline struct obd_export *ll_i2mdcexp(struct inode *inode)
827 return ll_s2mdcexp(inode->i_sb);
830 static inline void ll_inode2fid(struct ll_fid *fid, struct inode *inode)
832 mdc_pack_fid(fid, inode->i_ino, inode->i_generation,
833 inode->i_mode & S_IFMT);
836 static inline int ll_mds_max_easize(struct super_block *sb)
838 return sbi2mdc(ll_s2sbi(sb))->cl_max_mds_easize;
841 static inline __u64 ll_file_maxbytes(struct inode *inode)
843 return ll_i2info(inode)->lli_maxbytes;
847 int ll_setxattr(struct dentry *dentry, const char *name,
848 const void *value, size_t size, int flags);
849 ssize_t ll_getxattr(struct dentry *dentry, const char *name,
850 void *buffer, size_t size);
851 ssize_t ll_listxattr(struct dentry *dentry, char *buffer, size_t size);
852 int ll_removexattr(struct dentry *dentry, const char *name);
856 #define LL_SA_RPC_MIN 2
857 #define LL_SA_RPC_DEF 32
858 #define LL_SA_RPC_MAX 8192
860 /* per inode struct, for dir only */
861 struct ll_statahead_info {
862 struct inode *sai_inode;
863 struct dentry *sai_first; /* first dentry item */
864 unsigned int sai_generation; /* generation for statahead */
865 atomic_t sai_refcount; /* when access this struct, hold
867 unsigned int sai_sent; /* stat requests sent count */
868 unsigned int sai_replied; /* stat requests which received
870 unsigned int sai_max; /* max ahead of lookup */
871 unsigned int sai_index; /* index of statahead entry */
872 unsigned int sai_index_next; /* index for the next statahead
873 * entry to be stated */
874 unsigned int sai_hit; /* hit count */
875 unsigned int sai_miss; /* miss count:
876 * for "ls -al" case, it includes
877 * hidden dentry miss;
878 * for "ls -l" case, it does not
879 * include hidden dentry miss.
880 * "sai_miss_hidden" is used for
883 unsigned int sai_consecutive_miss; /* consecutive miss */
884 unsigned int sai_miss_hidden;/* "ls -al", but first dentry
885 * is not a hidden one */
886 unsigned int sai_skip_hidden;/* skipped hidden dentry count */
887 unsigned int sai_ls_all:1; /* "ls -al", do stat-ahead for
889 cfs_waitq_t sai_waitq; /* stat-ahead wait queue */
890 struct ptlrpc_thread sai_thread; /* stat-ahead thread */
891 struct list_head sai_entries_sent; /* entries sent out */
892 struct list_head sai_entries_received; /* entries returned */
893 struct list_head sai_entries_stated; /* entries stated */
896 int do_statahead_enter(struct inode *dir, struct dentry **dentry, int lookup);
897 int ll_statahead_exit(struct dentry *dentry, int result);
898 void ll_stop_statahead(struct inode *inode, void *key);
901 void ll_d_wakeup(struct dentry *dentry)
903 struct ll_dentry_data *lld = ll_d2d(dentry);
905 LASSERT(dentry->d_op != &ll_init_d_ops);
907 cfs_waitq_broadcast(&lld->lld_waitq);
911 int ll_statahead_enter(struct inode *dir, struct dentry **dentryp, int lookup)
913 struct ll_sb_info *sbi = ll_i2sbi(dir);
914 struct ll_inode_info *lli = ll_i2info(dir);
915 struct ll_dentry_data *ldd = ll_d2d(*dentryp);
917 if (sbi->ll_sa_max == 0)
920 /* not the same process, don't statahead */
921 if (lli->lli_opendir_pid != cfs_curproc_pid())
925 * When "ls" a dentry, the system trigger more than once "revalidate" or
926 * "lookup", for "getattr", for "getxattr", and maybe for others.
927 * Under patchless client mode, the operation intent is not accurate,
928 * it maybe misguide the statahead thread. For example:
929 * The "revalidate" call for "getattr" and "getxattr" of a dentry maybe
930 * have the same operation intent -- "IT_GETATTR".
931 * In fact, one dentry should has only one chance to interact with the
932 * statahead thread, otherwise the statahead windows will be confused.
933 * The solution is as following:
934 * Assign "lld_sa_generation" with "sai_generation" when a dentry
935 * "IT_GETATTR" for the first time, and the subsequent "IT_GETATTR"
936 * will bypass interacting with statahead thread for checking:
937 * "lld_sa_generation == lli_sai->sai_generation"
939 if (ldd && lli->lli_sai &&
940 ldd->lld_sa_generation == lli->lli_sai->sai_generation)
943 return do_statahead_enter(dir, dentryp, lookup);
946 /* llite ioctl register support rountine */
953 #define LLIOC_MAX_CMD 256
956 * Rules to write a callback function:
959 * @magic: Dynamic ioctl call routine will feed this vaule with the pointer
960 * returned to ll_iocontrol_register. Callback functions should use this
961 * data to check the potential collasion of ioctl cmd. If collasion is
962 * found, callback function should return LLIOC_CONT.
963 * @rcp: The result of ioctl command.
966 * If @magic matches the pointer returned by ll_iocontrol_data, the
967 * callback should return LLIOC_STOP; return LLIOC_STOP otherwise.
969 typedef enum llioc_iter (*llioc_callback_t)(struct inode *inode,
970 struct file *file, unsigned int cmd, unsigned long arg,
971 void *magic, int *rcp);
973 enum llioc_iter ll_iocontrol_call(struct inode *inode, struct file *file,
974 unsigned int cmd, unsigned long arg, int *rcp);
976 /* export functions */
977 /* Register ioctl block dynamatically for a regular file.
979 * @cmd: the array of ioctl command set
980 * @count: number of commands in the @cmd
981 * @cb: callback function, it will be called if an ioctl command is found to
982 * belong to the command list @cmd.
985 * A magic pointer will be returned if success;
986 * otherwise, NULL will be returned.
988 void *ll_iocontrol_register(llioc_callback_t cb, int count, unsigned int *cmd);
989 void ll_iocontrol_unregister(void *magic);
993 #endif /* LLITE_INTERNAL_H */