1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #ifndef LLITE_INTERNAL_H
38 #define LLITE_INTERNAL_H
40 #include <linux/lustre_acl.h>
42 #ifdef CONFIG_FS_POSIX_ACL
43 # include <linux/fs.h>
45 # include <linux/xattr_acl.h>
46 #endif /* HAVE_XATTR_ACL */
47 #ifdef HAVE_LINUX_POSIX_ACL_XATTR_H
48 # include <linux/posix_acl_xattr.h>
49 #endif /* HAVE_LINUX_POSIX_ACL_XATTR_H */
50 #endif /* CONFIG_FS_POSIX_ACL */
52 #include <lustre_debug.h>
53 #include <lustre_ver.h>
54 #include <lustre_disk.h> /* for s2sbi */
55 #include <lustre_eacl.h>
61 #define LL_IT2STR(it) ((it) ? ldlm_it2str((it)->it_op) : "0")
62 #define LUSTRE_FPRIVATE(file) ((file)->private_data)
64 #ifdef HAVE_VFS_INTENT_PATCHES
65 static inline struct lookup_intent *ll_nd2it(struct nameidata *nd)
71 struct ll_dentry_data {
74 struct obd_client_handle lld_cwd_och;
75 struct obd_client_handle lld_mnt_och;
76 #ifndef HAVE_VFS_INTENT_PATCHES
77 struct lookup_intent *lld_it;
79 unsigned int lld_sa_generation;
80 cfs_waitq_t lld_waitq;
83 #define ll_d2d(de) ((struct ll_dentry_data*)((de)->d_fsdata))
85 extern struct file_operations ll_pgcache_seq_fops;
87 #define LLI_INODE_MAGIC 0x111d0de5
88 #define LLI_INODE_DEAD 0xdeadd00d
90 /* remote client permission cache */
91 #define REMOTE_PERM_HASHSIZE 16
93 /* llite setxid/access permission for user on remote client */
94 struct ll_remote_perm {
95 struct hlist_node lrp_list;
100 int lrp_access_perm; /* MAY_READ/WRITE/EXEC, this
101 is access permission with
102 lrp_fsuid/lrp_fsgid. */
106 /* MDS has an authority for the Size-on-MDS attributes. */
107 LLIF_MDS_SIZE_LOCK = (1 << 0),
108 /* Epoch close is postponed. */
109 LLIF_EPOCH_PENDING = (1 << 1),
110 /* DONE WRITING is allowed. */
111 LLIF_DONE_WRITING = (1 << 2),
112 /* Sizeon-on-MDS attributes are changed. An attribute update needs to
114 LLIF_SOM_DIRTY = (1 << 3),
115 /* File is contented */
116 LLIF_CONTENDED = (1 << 4),
117 /* Truncate uses server lock for this file */
118 LLIF_SRVLOCK = (1 << 5)
122 struct ll_inode_info {
124 struct semaphore lli_size_sem; /* protect open and change size */
125 void *lli_size_sem_owner;
126 struct semaphore lli_write_sem;
127 char *lli_symlink_name;
130 unsigned long lli_flags;
131 cfs_time_t lli_contention_time;
133 /* this lock protects posix_acl, pending_write_llaps, mmap_cnt */
135 struct list_head lli_pending_write_llaps;
136 struct list_head lli_close_list;
137 /* handle is to be sent to MDS later on done_writing and setattr.
138 * Open handle data are needed for the recovery to reconstruct
139 * the inode state on the MDS. XXX: recovery is not ready yet. */
140 struct obd_client_handle *lli_pending_och;
141 atomic_t lli_mmap_cnt;
143 /* for writepage() only to communicate to fsync */
146 struct posix_acl *lli_posix_acl;
148 /* remote permission hash */
149 struct hlist_head *lli_remote_perms;
150 unsigned long lli_rmtperm_utime;
151 struct semaphore lli_rmtperm_sem;
153 struct list_head lli_dead_list;
155 struct semaphore lli_och_sem; /* Protects access to och pointers
156 and their usage counters */
157 /* We need all three because every inode may be opened in different
159 struct obd_client_handle *lli_mds_read_och;
160 __u64 lli_open_fd_read_count;
161 struct obd_client_handle *lli_mds_write_och;
162 __u64 lli_open_fd_write_count;
163 struct obd_client_handle *lli_mds_exec_och;
164 __u64 lli_open_fd_exec_count;
166 struct inode lli_vfs_inode;
168 /* identifying fields for both metadata and data stacks. */
169 struct lu_fid lli_fid;
170 struct lov_stripe_md *lli_smd;
173 /* open count currently used by capability only, indicate whether
174 * capability needs renewal */
175 atomic_t lli_open_count;
176 struct obd_capa *lli_mds_capa;
177 struct list_head lli_oss_capas;
179 /* metadata stat-ahead */
181 * "opendir_pid" is the token when lookup/revalid -- I am the owner of
184 pid_t lli_opendir_pid;
186 * since parent-child threads can share the same @file struct,
187 * "opendir_key" is the token when dir close for case of parent exit
188 * before child -- it is me should cleanup the dir readahead. */
189 void *lli_opendir_key;
190 struct ll_statahead_info *lli_sai;
194 * Locking to guarantee consistency of non-atomic updates to long long i_size,
195 * consistency between file size and KMS, and consistency within
196 * ->lli_smd->lsm_oinfo[]'s.
198 * Implemented by ->lli_size_sem and ->lsm_sem, nested in that order.
201 void ll_inode_size_lock(struct inode *inode, int lock_lsm);
202 void ll_inode_size_unlock(struct inode *inode, int unlock_lsm);
204 // FIXME: replace the name of this with LL_I to conform to kernel stuff
205 // static inline struct ll_inode_info *LL_I(struct inode *inode)
206 static inline struct ll_inode_info *ll_i2info(struct inode *inode)
208 return container_of(inode, struct ll_inode_info, lli_vfs_inode);
211 /* default to about 40meg of readahead on a given system. That much tied
212 * up in 512k readahead requests serviced at 40ms each is about 1GB/s. */
213 #define SBI_DEFAULT_READAHEAD_MAX (40UL << (20 - CFS_PAGE_SHIFT))
215 /* default to read-ahead full files smaller than 2MB on the second read */
216 #define SBI_DEFAULT_READAHEAD_WHOLE_MAX (2UL << (20 - CFS_PAGE_SHIFT))
221 RA_STAT_DISTANT_READPAGE,
222 RA_STAT_MISS_IN_WINDOW,
223 RA_STAT_FAILED_GRAB_PAGE,
224 RA_STAT_FAILED_MATCH,
229 RA_STAT_MAX_IN_FLIGHT,
230 RA_STAT_WRONG_GRAB_PAGE,
234 #define LL_RA_STAT _NR_RA_STAT
235 #define LL_RA_STAT_STRINGS { \
236 [RA_STAT_HIT] = "hits", \
237 [RA_STAT_MISS] = "misses", \
238 [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive", \
239 [RA_STAT_MISS_IN_WINDOW] = "miss inside window", \
240 [RA_STAT_FAILED_GRAB_PAGE] = "failed grab_cache_page", \
241 [RA_STAT_FAILED_MATCH] = "failed lock match", \
242 [RA_STAT_DISCARDED] = "read but discarded", \
243 [RA_STAT_ZERO_LEN] = "zero length file", \
244 [RA_STAT_ZERO_WINDOW] = "zero size window", \
245 [RA_STAT_EOF] = "read-ahead to EOF", \
246 [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue", \
247 [RA_STAT_WRONG_GRAB_PAGE] = "wrong page from grab_cache_page",\
251 atomic_t ra_cur_pages;
252 unsigned long ra_max_pages;
253 unsigned long ra_max_read_ahead_whole_pages;
256 /* LL_HIST_MAX=32 causes an overflow */
257 #define LL_HIST_MAX 28
258 #define LL_HIST_START 12 /* buckets start at 2^12 = 4k */
259 #define LL_PROCESS_HIST_MAX 10
260 struct per_process_info {
262 struct obd_histogram pp_r_hist;
263 struct obd_histogram pp_w_hist;
266 /* pp_extents[LL_PROCESS_HIST_MAX] will hold the combined process info */
267 struct ll_rw_extents_info {
268 struct per_process_info pp_extents[LL_PROCESS_HIST_MAX + 1];
271 #define LL_OFFSET_HIST_MAX 100
272 struct ll_rw_process_info {
275 loff_t rw_range_start;
277 loff_t rw_last_file_pos;
279 size_t rw_smallest_extent;
280 size_t rw_largest_extent;
281 struct file *rw_last_file;
284 enum stats_track_type {
285 STATS_TRACK_ALL = 0, /* track all processes */
286 STATS_TRACK_PID, /* track process with this pid */
287 STATS_TRACK_PPID, /* track processes with this ppid */
288 STATS_TRACK_GID, /* track processes with this gid */
292 /* flags for sbi->ll_flags */
293 #define LL_SBI_NOLCK 0x01 /* DLM locking disabled (directio-only) */
294 #define LL_SBI_CHECKSUM 0x02 /* checksum each page as it's written */
295 #define LL_SBI_FLOCK 0x04
296 #define LL_SBI_USER_XATTR 0x08 /* support user xattr */
297 #define LL_SBI_ACL 0x10 /* support ACL */
298 #define LL_SBI_JOIN 0x20 /* support JOIN */
299 #define LL_SBI_RMT_CLIENT 0x40 /* remote client */
300 #define LL_SBI_MDS_CAPA 0x80 /* support mds capa */
301 #define LL_SBI_OSS_CAPA 0x100 /* support oss capa */
302 #define LL_SBI_LOCALFLOCK 0x200 /* Local flocks support by kernel */
303 #define LL_SBI_LRU_RESIZE 0x400 /* lru resize support */
305 /* default value for ll_sb_info->contention_time */
306 #define SBI_DEFAULT_CONTENTION_SECONDS 60
307 /* default value for lockless_truncate_enable */
308 #define SBI_DEFAULT_LOCKLESS_TRUNCATE_ENABLE 1
309 #define RCE_HASHES 32
311 struct rmtacl_ctl_entry {
312 struct list_head rce_list;
313 pid_t rce_key; /* hash key */
314 int rce_ops; /* acl operation type */
317 struct rmtacl_ctl_table {
319 struct list_head rct_entries[RCE_HASHES];
325 struct list_head ee_list;
326 pid_t ee_key; /* hash key */
327 struct lu_fid ee_fid;
328 int ee_type; /* ACL type for ACCESS or DEFAULT */
329 ext_acl_xattr_header *ee_acl;
334 struct list_head et_entries[EE_HASHES];
337 /* percpu data structure for lustre lru page list */
338 struct ll_pglist_data {
339 spinlock_t llpd_lock; /* lock to protect llpg_list */
340 struct list_head llpd_list; /* all pages (llap_pglist_item) */
341 unsigned long llpd_gen; /* generation # of this list */
342 unsigned long llpd_count; /* How many pages in this list */
343 atomic_t llpd_sample_count;
344 unsigned long llpd_reblnc_count;
345 /* the pages in this list shouldn't be over this number */
346 unsigned long llpd_budget;
348 /* which page the pglist data is in */
349 struct page *llpd_page;
352 unsigned long llpd_hit;
353 unsigned long llpd_miss;
354 unsigned long llpd_cross;
358 struct list_head ll_list;
359 /* this protects pglist(only ll_async_page_max) and ra_info.
360 * It isn't safe to grab from interrupt contexts. */
362 spinlock_t ll_pp_extent_lock; /* Lock for pp_extent entries */
363 spinlock_t ll_process_lock; /* Lock for ll_rw_process_info */
364 struct obd_uuid ll_sb_uuid;
365 struct obd_export *ll_md_exp;
366 struct obd_export *ll_dt_exp;
367 struct proc_dir_entry* ll_proc_root;
368 struct lu_fid ll_root_fid; /* root object fid */
371 struct list_head ll_conn_chain; /* per-conn chain of SBs */
372 struct lustre_client_ocd ll_lco;
374 struct list_head ll_orphan_dentry_list; /*please don't ask -p*/
375 struct ll_close_queue *ll_lcq;
377 struct lprocfs_stats *ll_stats; /* lprocfs stats counter */
379 /* reblnc lock protects llpd_budget */
380 spinlock_t ll_async_page_reblnc_lock;
381 unsigned long ll_async_page_reblnc_count;
382 unsigned long ll_async_page_sample_max;
383 /* I defined this array here rather than in ll_pglist_data
384 * because it is always accessed by only one cpu. -jay */
385 unsigned long *ll_async_page_sample;
386 unsigned long ll_async_page_max;
387 unsigned long ll_async_page_clock_hand;
388 lcounter_t ll_async_page_count;
389 struct ll_pglist_data **ll_pglist;
391 struct lprocfs_stats *ll_ra_stats;
393 unsigned ll_contention_time; /* seconds */
394 unsigned ll_lockless_truncate_enable; /* true/false */
396 struct ll_ra_info ll_ra_info;
397 unsigned int ll_namelen;
398 struct file_operations *ll_fop;
400 #ifdef HAVE_EXPORT___IGET
401 struct list_head ll_deathrow; /* inodes to be destroyed (b1443) */
402 spinlock_t ll_deathrow_lock;
404 /* =0 - hold lock over whole read/write
405 * >0 - max. chunk to be read/written w/o lock re-acquiring */
406 unsigned long ll_max_rw_chunk;
409 struct ll_rw_extents_info ll_rw_extents_info;
410 int ll_extent_process_count;
411 struct ll_rw_process_info ll_rw_process_info[LL_PROCESS_HIST_MAX];
412 unsigned int ll_offset_process_count;
413 struct ll_rw_process_info ll_rw_offset_info[LL_OFFSET_HIST_MAX];
414 unsigned int ll_rw_offset_entry_count;
415 enum stats_track_type ll_stats_track_type;
416 int ll_stats_track_id;
419 /* metadata stat-ahead */
420 unsigned int ll_sa_max; /* max statahead RPCs */
421 unsigned int ll_sa_wrong; /* statahead thread stopped for
423 unsigned int ll_sa_total; /* statahead thread started
425 unsigned long long ll_sa_blocked; /* ls count waiting for
427 unsigned long long ll_sa_cached; /* ls count got in cache */
428 unsigned long long ll_sa_hit; /* hit count */
429 unsigned long long ll_sa_miss; /* miss count */
431 dev_t ll_sdev_orig; /* save s_dev before assign for
433 struct rmtacl_ctl_table ll_rct;
434 struct eacl_table ll_et;
437 #define LL_DEFAULT_MAX_RW_CHUNK (32 * 1024 * 1024)
439 #define LL_PGLIST_DATA_CPU(sbi, cpu) ((sbi)->ll_pglist[cpu])
440 #define LL_PGLIST_DATA(sbi) LL_PGLIST_DATA_CPU(sbi, smp_processor_id())
442 static inline struct ll_pglist_data *ll_pglist_cpu_lock(
443 struct ll_sb_info *sbi,
446 spin_lock(&sbi->ll_pglist[cpu]->llpd_lock);
447 return LL_PGLIST_DATA_CPU(sbi, cpu);
450 static inline void ll_pglist_cpu_unlock(struct ll_sb_info *sbi, int cpu)
452 spin_unlock(&sbi->ll_pglist[cpu]->llpd_lock);
455 static inline struct ll_pglist_data *ll_pglist_double_lock(
456 struct ll_sb_info *sbi,
457 int cpu, struct ll_pglist_data **pd_cpu)
459 int current_cpu = get_cpu();
461 if (cpu == current_cpu) {
462 ll_pglist_cpu_lock(sbi, cpu);
463 } else if (current_cpu < cpu) {
464 ll_pglist_cpu_lock(sbi, current_cpu);
465 ll_pglist_cpu_lock(sbi, cpu);
467 ll_pglist_cpu_lock(sbi, cpu);
468 ll_pglist_cpu_lock(sbi, current_cpu);
472 *pd_cpu = LL_PGLIST_DATA_CPU(sbi, cpu);
474 return LL_PGLIST_DATA(sbi);
477 static inline void ll_pglist_double_unlock(struct ll_sb_info *sbi, int cpu)
479 int current_cpu = smp_processor_id();
480 if (cpu == current_cpu) {
481 ll_pglist_cpu_unlock(sbi, cpu);
483 ll_pglist_cpu_unlock(sbi, cpu);
484 ll_pglist_cpu_unlock(sbi, current_cpu);
489 static inline struct ll_pglist_data *ll_pglist_lock(struct ll_sb_info *sbi)
491 ll_pglist_cpu_lock(sbi, get_cpu());
492 return LL_PGLIST_DATA(sbi);
495 static inline void ll_pglist_unlock(struct ll_sb_info *sbi)
497 ll_pglist_cpu_unlock(sbi, smp_processor_id());
504 struct task_struct *lrr_reader;
505 struct list_head lrr_linkage;
509 * per file-descriptor read-ahead data.
511 struct ll_readahead_state {
514 * index of the last page that read(2) needed and that wasn't in the
515 * cache. Used by ras_update() to detect seeks.
517 * XXX nikita: if access seeks into cached region, Lustre doesn't see
520 unsigned long ras_last_readpage;
522 * number of pages read after last read-ahead window reset. As window
523 * is reset on each seek, this is effectively a number of consecutive
524 * accesses. Maybe ->ras_accessed_in_window is better name.
526 * XXX nikita: window is also reset (by ras_update()) when Lustre
527 * believes that memory pressure evicts read-ahead pages. In that
528 * case, it probably doesn't make sense to expand window to
529 * PTLRPC_MAX_BRW_PAGES on the third access.
531 unsigned long ras_consecutive_pages;
533 * number of read requests after the last read-ahead window reset
534 * As window is reset on each seek, this is effectively the number
535 * on consecutive read request and is used to trigger read-ahead.
537 unsigned long ras_consecutive_requests;
539 * Parameters of current read-ahead window. Handled by
540 * ras_update(). On the initial access to the file or after a seek,
541 * window is reset to 0. After 3 consecutive accesses, window is
542 * expanded to PTLRPC_MAX_BRW_PAGES. Afterwards, window is enlarged by
543 * PTLRPC_MAX_BRW_PAGES chunks up to ->ra_max_pages.
545 unsigned long ras_window_start, ras_window_len;
547 * Where next read-ahead should start at. This lies within read-ahead
548 * window. Read-ahead window is read in pieces rather than at once
549 * because: 1. lustre limits total number of pages under read-ahead by
550 * ->ra_max_pages (see ll_ra_count_get()), 2. client cannot read pages
551 * not covered by DLM lock.
553 unsigned long ras_next_readahead;
555 * Total number of ll_file_read requests issued, reads originating
556 * due to mmap are not counted in this total. This value is used to
557 * trigger full file read-ahead after multiple reads to a small file.
559 unsigned long ras_requests;
561 * Page index with respect to the current request, these value
562 * will not be accurate when dealing with reads issued via mmap.
564 unsigned long ras_request_index;
566 * list of struct ll_ra_read's one per read(2) call current in
567 * progress against this file descriptor. Used by read-ahead code,
568 * protected by ->ras_lock.
570 struct list_head ras_read_beads;
572 * The following 3 items are used for detecting the stride I/O
574 * In stride I/O mode,
575 * ...............|-----data-----|****gap*****|--------|******|....
576 * offset |-stride_pages-|-stride_gap-|
577 * ras_stride_offset = offset;
578 * ras_stride_length = stride_pages + stride_gap;
579 * ras_stride_pages = stride_pages;
580 * Note: all these three items are counted by pages.
582 unsigned long ras_stride_length;
583 unsigned long ras_stride_pages;
584 pgoff_t ras_stride_offset;
586 * number of consecutive stride request count, and it is similar as
587 * ras_consecutive_requests, but used for stride I/O mode.
588 * Note: only more than 2 consecutive stride request are detected,
589 * stride read-ahead will be enable
591 unsigned long ras_consecutive_stride_requests;
597 extern cfs_mem_cache_t *ll_file_data_slab;
598 struct lustre_handle;
599 struct ll_file_data {
600 struct ll_readahead_state fd_ras;
602 struct lustre_handle fd_cwlockh;
603 unsigned long fd_gid;
604 struct ll_file_dir fd_dir;
608 struct lov_stripe_md;
610 extern spinlock_t inode_lock;
612 extern struct proc_dir_entry *proc_lustre_fs_root;
614 static inline struct inode *ll_info2i(struct ll_inode_info *lli)
616 return &lli->lli_vfs_inode;
620 struct inode *icbd_parent;
621 struct dentry **icbd_childp;
625 __u32 ll_i2suppgid(struct inode *i);
626 void ll_i2gids(__u32 *suppgids, struct inode *i1,struct inode *i2);
628 #define LLAP_MAGIC 98764321
630 extern cfs_mem_cache_t *ll_async_page_slab;
631 extern size_t ll_async_page_slab_size;
632 struct ll_async_page {
634 /* only trust these if the page lock is providing exclusion */
635 unsigned int llap_write_queued:1,
636 llap_defer_uptodate:1,
641 llap_lockless_io_page:1,
643 unsigned int llap_pglist_cpu:16;
645 struct page *llap_page;
646 struct list_head llap_pending_write;
647 struct list_head llap_pglist_item;
648 /* checksum for paranoid I/O debugging */
653 * enumeration of llap_from_page() call-sites. Used to export statistics in
654 * /proc/fs/lustre/llite/fsN/dump_page_cache.
657 LLAP_ORIGIN_UNKNOWN = 0,
658 LLAP_ORIGIN_READPAGE,
659 LLAP_ORIGIN_READAHEAD,
660 LLAP_ORIGIN_COMMIT_WRITE,
661 LLAP_ORIGIN_WRITEPAGE,
662 LLAP_ORIGIN_REMOVEPAGE,
663 LLAP_ORIGIN_LOCKLESS_IO,
666 extern char *llap_origins[];
668 #ifdef HAVE_REGISTER_CACHE
669 #include <linux/cache_def.h>
670 #define ll_register_cache(cache) register_cache(cache)
671 #define ll_unregister_cache(cache) unregister_cache(cache)
672 #elif defined(HAVE_SHRINKER_CACHE)
673 struct cache_definition {
676 struct shrinker *shrinker;
679 #define ll_register_cache(cache) do { \
680 struct cache_definition *c = (cache); \
681 c->shrinker = set_shrinker(DEFAULT_SEEKS, c->shrink); \
684 #define ll_unregister_cache(cache) do { \
685 remove_shrinker((cache)->shrinker); \
686 (cache)->shrinker = NULL; \
689 #define ll_register_cache(cache) do {} while (0)
690 #define ll_unregister_cache(cache) do {} while (0)
693 void ll_ra_read_in(struct file *f, struct ll_ra_read *rar);
694 void ll_ra_read_ex(struct file *f, struct ll_ra_read *rar);
695 struct ll_ra_read *ll_ra_read_get(struct file *f);
697 /* llite/lproc_llite.c */
699 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
700 struct super_block *sb, char *osc, char *mdc);
701 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi);
702 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count);
703 void lprocfs_llite_init_vars(struct lprocfs_static_vars *lvars);
705 static inline int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
706 struct super_block *sb, char *osc, char *mdc){return 0;}
707 static inline void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi) {}
708 static void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count) {}
709 static void lprocfs_llite_init_vars(struct lprocfs_static_vars *lvars)
711 memset(lvars, 0, sizeof(*lvars));
717 static inline void ll_put_page(struct page *page)
720 page_cache_release(page);
723 extern struct file_operations ll_dir_operations;
724 extern struct inode_operations ll_dir_inode_operations;
725 struct page *ll_get_dir_page(struct inode *dir, __u64 hash, int exact,
726 struct ll_dir_chain *chain);
728 int ll_objects_destroy(struct ptlrpc_request *request,
730 struct inode *ll_iget(struct super_block *sb, ino_t hash,
731 struct lustre_md *lic);
732 int ll_md_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
733 void *data, int flag);
734 #ifndef HAVE_VFS_INTENT_PATCHES
735 struct lookup_intent *ll_convert_intent(struct open_intent *oit,
738 int ll_lookup_it_finish(struct ptlrpc_request *request,
739 struct lookup_intent *it, void *data);
740 void ll_lookup_finish_locks(struct lookup_intent *it, struct dentry *dentry);
743 int ll_prepare_write(struct file *, struct page *, unsigned from, unsigned to);
744 int ll_commit_write(struct file *, struct page *, unsigned from, unsigned to);
745 int ll_writepage(struct page *page);
746 void ll_inode_fill_obdo(struct inode *inode, int cmd, struct obdo *oa);
747 int ll_ap_completion(void *data, int cmd, struct obdo *oa, int rc);
748 int llap_shrink_cache(struct ll_sb_info *sbi, int shrink_fraction);
749 struct ll_async_page *llap_from_page(struct page *page, unsigned origin);
750 extern struct cache_definition ll_cache_definition;
751 void ll_removepage(struct page *page);
752 int ll_readpage(struct file *file, struct page *page);
753 struct ll_async_page *llap_cast_private(struct page *page);
754 void ll_readahead_init(struct inode *inode, struct ll_readahead_state *ras);
755 void ll_ra_accounting(struct ll_async_page *llap,struct address_space *mapping);
756 void ll_truncate(struct inode *inode);
757 int ll_file_punch(struct inode *, loff_t, int);
758 ssize_t ll_file_lockless_io(struct file *, char *, size_t, loff_t *, int);
759 void ll_clear_file_contended(struct inode*);
760 int ll_sync_page_range(struct inode *, struct address_space *, loff_t, size_t);
763 extern struct file_operations ll_file_operations;
764 extern struct file_operations ll_file_operations_flock;
765 extern struct file_operations ll_file_operations_noflock;
766 extern struct inode_operations ll_file_inode_operations;
767 extern int ll_inode_revalidate_it(struct dentry *, struct lookup_intent *);
768 extern int ll_have_md_lock(struct inode *inode, __u64 bits);
769 extern ldlm_mode_t ll_take_md_lock(struct inode *inode, __u64 bits,
770 struct lustre_handle *lockh);
771 int ll_region_mapped(unsigned long addr, size_t count);
772 int ll_extent_lock(struct ll_file_data *, struct inode *,
773 struct lov_stripe_md *, int mode, ldlm_policy_data_t *,
774 struct lustre_handle *, int ast_flags);
775 int ll_extent_unlock(struct ll_file_data *, struct inode *,
776 struct lov_stripe_md *, int mode, struct lustre_handle *);
777 int ll_file_open(struct inode *inode, struct file *file);
778 int ll_file_release(struct inode *inode, struct file *file);
779 int ll_lsm_getattr(struct obd_export *, struct lov_stripe_md *, struct obdo *);
780 int ll_local_size(struct inode *inode);
781 int ll_glimpse_ioctl(struct ll_sb_info *sbi,
782 struct lov_stripe_md *lsm, lstat_t *st);
783 int ll_glimpse_size(struct inode *inode, int ast_flags);
784 int ll_local_open(struct file *file,
785 struct lookup_intent *it, struct ll_file_data *fd,
786 struct obd_client_handle *och);
787 int ll_release_openhandle(struct dentry *, struct lookup_intent *);
788 int ll_md_close(struct obd_export *md_exp, struct inode *inode,
790 int ll_md_real_close(struct inode *inode, int flags);
791 void ll_epoch_close(struct inode *inode, struct md_op_data *op_data,
792 struct obd_client_handle **och, unsigned long flags);
793 int ll_sizeonmds_update(struct inode *inode, struct md_open_data *data,
794 struct lustre_handle *fh, __u64 ioepoch);
795 int ll_inode_getattr(struct inode *inode, struct obdo *obdo);
796 int ll_md_setattr(struct inode *inode, struct md_op_data *op_data,
797 struct md_open_data **mod);
798 void ll_pack_inode2opdata(struct inode *inode, struct md_op_data *op_data,
799 struct lustre_handle *fh);
800 extern void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid, struct file
801 *file, size_t count, int rw);
802 int ll_getattr_it(struct vfsmount *mnt, struct dentry *de,
803 struct lookup_intent *it, struct kstat *stat);
804 int ll_getattr(struct vfsmount *mnt, struct dentry *de, struct kstat *stat);
805 struct ll_file_data *ll_file_data_get(void);
806 int ll_inode_permission(struct inode *inode, int mask, struct nameidata *nd);
807 int ll_lov_setstripe_ea_info(struct inode *inode, struct file *file,
808 int flags, struct lov_user_md *lum,
810 int ll_lov_getstripe_ea_info(struct inode *inode, const char *filename,
811 struct lov_mds_md **lmm, int *lmm_size,
812 struct ptlrpc_request **request);
813 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
815 int ll_dir_getstripe(struct inode *inode, struct lov_mds_md **lmm,
816 int *lmm_size, struct ptlrpc_request **request);
817 void ll_pin_extent_cb(void *data);
818 int ll_page_removal_cb(void *data, int discard);
819 int ll_extent_lock_cancel_cb(struct ldlm_lock *lock, struct ldlm_lock_desc *new,
820 void *data, int flag);
823 extern struct dentry_operations ll_init_d_ops;
824 extern struct dentry_operations ll_d_ops;
825 extern struct dentry_operations ll_fini_d_ops;
826 void ll_release(struct dentry *de);
827 void ll_intent_drop_lock(struct lookup_intent *);
828 void ll_intent_release(struct lookup_intent *);
829 int ll_drop_dentry(struct dentry *dentry);
830 extern void ll_set_dd(struct dentry *de);
831 int ll_drop_dentry(struct dentry *dentry);
832 void ll_unhash_aliases(struct inode *);
833 void ll_frob_intent(struct lookup_intent **itp, struct lookup_intent *deft);
834 void ll_lookup_finish_locks(struct lookup_intent *it, struct dentry *dentry);
835 int ll_dcompare(struct dentry *parent, struct qstr *d_name, struct qstr *name);
836 int ll_revalidate_it_finish(struct ptlrpc_request *request,
837 struct lookup_intent *it, struct dentry *de);
839 /* llite/llite_lib.c */
840 extern struct super_operations lustre_super_operations;
842 char *ll_read_opt(const char *opt, char *data);
843 void ll_lli_init(struct ll_inode_info *lli);
844 int ll_fill_super(struct super_block *sb);
845 void ll_put_super(struct super_block *sb);
846 void ll_kill_super(struct super_block *sb);
847 struct inode *ll_inode_from_lock(struct ldlm_lock *lock);
848 void ll_clear_inode(struct inode *inode);
849 int ll_setattr_raw(struct inode *inode, struct iattr *attr);
850 int ll_setattr(struct dentry *de, struct iattr *attr);
851 #ifndef HAVE_STATFS_DENTRY_PARAM
852 int ll_statfs(struct super_block *sb, struct kstatfs *sfs);
854 int ll_statfs(struct dentry *de, struct kstatfs *sfs);
856 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
857 __u64 max_age, __u32 flags);
858 void ll_update_inode(struct inode *inode, struct lustre_md *md);
859 void ll_read_inode2(struct inode *inode, void *opaque);
860 void ll_delete_inode(struct inode *inode);
861 int ll_iocontrol(struct inode *inode, struct file *file,
862 unsigned int cmd, unsigned long arg);
863 int ll_flush_ctx(struct inode *inode);
864 #ifdef HAVE_UMOUNTBEGIN_VFSMOUNT
865 void ll_umount_begin(struct vfsmount *vfsmnt, int flags);
867 void ll_umount_begin(struct super_block *sb);
869 int ll_remount_fs(struct super_block *sb, int *flags, char *data);
870 int ll_prep_inode(struct inode **inode, struct ptlrpc_request *req,
871 struct super_block *);
872 void lustre_dump_dentry(struct dentry *, int recur);
873 void lustre_dump_inode(struct inode *);
874 struct ll_async_page *llite_pglist_next_llap(struct list_head *head,
875 struct list_head *list);
876 int ll_obd_statfs(struct inode *inode, void *arg);
877 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *max_mdsize);
878 int ll_process_config(struct lustre_cfg *lcfg);
879 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
880 struct inode *i1, struct inode *i2,
881 const char *name, int namelen,
882 int mode, __u32 opc, void *data);
883 void ll_finish_md_op_data(struct md_op_data *op_data);
885 /* llite/llite_nfs.c */
886 extern struct export_operations lustre_export_operations;
887 __u32 get_uuid2int(const char *name, int len);
888 struct dentry *ll_fh_to_dentry(struct super_block *sb, __u32 *data, int len,
889 int fhtype, int parent);
890 int ll_dentry_to_fh(struct dentry *, __u32 *datap, int *lenp, int need_parent);
892 /* llite/special.c */
893 extern struct inode_operations ll_special_inode_operations;
894 extern struct file_operations ll_special_chr_inode_fops;
895 extern struct file_operations ll_special_chr_file_fops;
896 extern struct file_operations ll_special_blk_inode_fops;
897 extern struct file_operations ll_special_fifo_inode_fops;
898 extern struct file_operations ll_special_fifo_file_fops;
899 extern struct file_operations ll_special_sock_inode_fops;
901 /* llite/symlink.c */
902 extern struct inode_operations ll_fast_symlink_inode_operations;
904 /* llite/llite_close.c */
905 struct ll_close_queue {
907 struct list_head lcq_head;
908 wait_queue_head_t lcq_waitq;
909 struct completion lcq_comp;
913 void llap_write_pending(struct inode *inode, struct ll_async_page *llap);
914 int llap_write_complete(struct inode *inode, struct ll_async_page *llap);
915 int ll_inode_dirty(struct inode *inode, unsigned long flags);
916 void ll_queue_done_writing(struct inode *inode, unsigned long flags);
917 void ll_close_thread_shutdown(struct ll_close_queue *lcq);
918 int ll_close_thread_start(struct ll_close_queue **lcq_ret);
920 /* llite/llite_mmap.c */
921 typedef struct rb_root rb_root_t;
922 typedef struct rb_node rb_node_t;
924 struct ll_lock_tree_node;
925 struct ll_lock_tree {
927 struct list_head lt_locked_list;
928 struct ll_file_data *lt_fd;
931 int ll_teardown_mmaps(struct address_space *mapping, __u64 first, __u64 last);
932 int ll_file_mmap(struct file * file, struct vm_area_struct * vma);
933 struct ll_lock_tree_node * ll_node_from_inode(struct inode *inode, __u64 start,
934 __u64 end, ldlm_mode_t mode);
935 int ll_tree_lock(struct ll_lock_tree *tree,
936 struct ll_lock_tree_node *first_node,
937 const char *buf, size_t count, int ast_flags);
938 int ll_tree_unlock(struct ll_lock_tree *tree);
940 #define ll_s2sbi(sb) (s2lsi(sb)->lsi_llsbi)
942 static inline __u64 ll_ts2u64(struct timespec *time)
944 __u64 t = time->tv_sec;
948 /* don't need an addref as the sb_info should be holding one */
949 static inline struct obd_export *ll_s2dtexp(struct super_block *sb)
951 return ll_s2sbi(sb)->ll_dt_exp;
954 /* don't need an addref as the sb_info should be holding one */
955 static inline struct obd_export *ll_s2mdexp(struct super_block *sb)
957 return ll_s2sbi(sb)->ll_md_exp;
960 static inline struct client_obd *sbi2mdc(struct ll_sb_info *sbi)
962 struct obd_device *obd = sbi->ll_md_exp->exp_obd;
968 // FIXME: replace the name of this with LL_SB to conform to kernel stuff
969 static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
971 return ll_s2sbi(inode->i_sb);
974 static inline struct obd_export *ll_i2dtexp(struct inode *inode)
976 return ll_s2dtexp(inode->i_sb);
979 static inline struct obd_export *ll_i2mdexp(struct inode *inode)
981 return ll_s2mdexp(inode->i_sb);
984 static inline struct lu_fid *ll_inode2fid(struct inode *inode)
987 LASSERT(inode != NULL);
988 fid = &ll_i2info(inode)->lli_fid;
989 LASSERT(fid_is_igif(fid) || fid_ver(fid) == 0);
993 static inline int ll_mds_max_easize(struct super_block *sb)
995 return sbi2mdc(ll_s2sbi(sb))->cl_max_mds_easize;
998 static inline __u64 ll_file_maxbytes(struct inode *inode)
1000 return ll_i2info(inode)->lli_maxbytes;
1004 int ll_setxattr(struct dentry *dentry, const char *name,
1005 const void *value, size_t size, int flags);
1006 ssize_t ll_getxattr(struct dentry *dentry, const char *name,
1007 void *buffer, size_t size);
1008 ssize_t ll_listxattr(struct dentry *dentry, char *buffer, size_t size);
1009 int ll_removexattr(struct dentry *dentry, const char *name);
1011 /* llite/remote_perm.c */
1012 extern cfs_mem_cache_t *ll_remote_perm_cachep;
1013 extern cfs_mem_cache_t *ll_rmtperm_hash_cachep;
1015 struct hlist_head *alloc_rmtperm_hash(void);
1016 void free_rmtperm_hash(struct hlist_head *hash);
1017 int ll_update_remote_perm(struct inode *inode, struct mdt_remote_perm *perm);
1018 int lustre_check_remote_perm(struct inode *inode, int mask);
1020 /* llite/llite_fid.c */
1021 ino_t ll_fid_build_ino(struct ll_sb_info *sbi, struct lu_fid *fid);
1023 /* llite/llite_capa.c */
1024 extern cfs_timer_t ll_capa_timer;
1026 int ll_capa_thread_start(void);
1027 void ll_capa_thread_stop(void);
1028 void ll_capa_timer_callback(unsigned long unused);
1030 struct obd_capa *ll_add_capa(struct inode *inode, struct obd_capa *ocapa);
1031 int ll_update_capa(struct obd_capa *ocapa, struct lustre_capa *capa);
1033 void ll_capa_open(struct inode *inode);
1034 void ll_capa_close(struct inode *inode);
1036 struct obd_capa *ll_mdscapa_get(struct inode *inode);
1037 struct obd_capa *ll_osscapa_get(struct inode *inode, __u64 opc);
1039 void ll_truncate_free_capa(struct obd_capa *ocapa);
1040 void ll_clear_inode_capas(struct inode *inode);
1041 void ll_print_capa_stat(struct ll_sb_info *sbi);
1043 /* llite/llite_rmtacl.c */
1044 #ifdef CONFIG_FS_POSIX_ACL
1045 obd_valid rce_ops2valid(int ops);
1046 struct rmtacl_ctl_entry *rct_search(struct rmtacl_ctl_table *rct, pid_t key);
1047 int rct_add(struct rmtacl_ctl_table *rct, pid_t key, int ops);
1048 int rct_del(struct rmtacl_ctl_table *rct, pid_t key);
1049 void rct_init(struct rmtacl_ctl_table *rct);
1050 void rct_fini(struct rmtacl_ctl_table *rct);
1052 void ee_free(struct eacl_entry *ee);
1053 int ee_add(struct eacl_table *et, pid_t key, struct lu_fid *fid, int type,
1054 ext_acl_xattr_header *header);
1055 struct eacl_entry *et_search_del(struct eacl_table *et, pid_t key,
1056 struct lu_fid *fid, int type);
1057 void et_search_free(struct eacl_table *et, pid_t key);
1058 void et_init(struct eacl_table *et);
1059 void et_fini(struct eacl_table *et);
1064 #define LL_SA_RPC_MIN 2
1065 #define LL_SA_RPC_DEF 32
1066 #define LL_SA_RPC_MAX 8192
1068 /* per inode struct, for dir only */
1069 struct ll_statahead_info {
1070 struct inode *sai_inode;
1071 struct dentry *sai_first; /* first dentry item */
1072 unsigned int sai_generation; /* generation for statahead */
1073 atomic_t sai_refcount; /* when access this struct, hold
1075 unsigned int sai_sent; /* stat requests sent count */
1076 unsigned int sai_replied; /* stat requests which received
1078 unsigned int sai_max; /* max ahead of lookup */
1079 unsigned int sai_index; /* index of statahead entry */
1080 unsigned int sai_index_next; /* index for the next statahead
1081 * entry to be stated */
1082 unsigned int sai_hit; /* hit count */
1083 unsigned int sai_miss; /* miss count:
1084 * for "ls -al" case, it includes
1085 * hidden dentry miss;
1086 * for "ls -l" case, it does not
1087 * include hidden dentry miss.
1088 * "sai_miss_hidden" is used for
1091 unsigned int sai_consecutive_miss; /* consecutive miss */
1092 unsigned int sai_miss_hidden;/* "ls -al", but first dentry
1093 * is not a hidden one */
1094 unsigned int sai_skip_hidden;/* skipped hidden dentry count */
1095 unsigned int sai_ls_all:1; /* "ls -al", do stat-ahead for
1097 cfs_waitq_t sai_waitq; /* stat-ahead wait queue */
1098 struct ptlrpc_thread sai_thread; /* stat-ahead thread */
1099 struct list_head sai_entries_sent; /* entries sent out */
1100 struct list_head sai_entries_received; /* entries returned */
1101 struct list_head sai_entries_stated; /* entries stated */
1104 int do_statahead_enter(struct inode *dir, struct dentry **dentry, int lookup);
1105 int ll_statahead_exit(struct dentry *dentry, int result);
1106 void ll_stop_statahead(struct inode *inode, void *key);
1109 void ll_d_wakeup(struct dentry *dentry)
1111 struct ll_dentry_data *lld = ll_d2d(dentry);
1113 LASSERT(dentry->d_op != &ll_init_d_ops);
1115 cfs_waitq_broadcast(&lld->lld_waitq);
1119 int ll_statahead_enter(struct inode *dir, struct dentry **dentryp, int lookup)
1121 struct ll_sb_info *sbi = ll_i2sbi(dir);
1122 struct ll_inode_info *lli = ll_i2info(dir);
1123 struct ll_dentry_data *ldd = ll_d2d(*dentryp);
1125 if (sbi->ll_sa_max == 0)
1128 /* not the same process, don't statahead */
1129 if (lli->lli_opendir_pid != cfs_curproc_pid())
1133 * When "ls" a dentry, the system trigger more than once "revalidate" or
1134 * "lookup", for "getattr", for "getxattr", and maybe for others.
1135 * Under patchless client mode, the operation intent is not accurate,
1136 * it maybe misguide the statahead thread. For example:
1137 * The "revalidate" call for "getattr" and "getxattr" of a dentry maybe
1138 * have the same operation intent -- "IT_GETATTR".
1139 * In fact, one dentry should has only one chance to interact with the
1140 * statahead thread, otherwise the statahead windows will be confused.
1141 * The solution is as following:
1142 * Assign "lld_sa_generation" with "sai_generation" when a dentry
1143 * "IT_GETATTR" for the first time, and the subsequent "IT_GETATTR"
1144 * will bypass interacting with statahead thread for checking:
1145 * "lld_sa_generation == lli_sai->sai_generation"
1147 if (ldd && lli->lli_sai &&
1148 ldd->lld_sa_generation == lli->lli_sai->sai_generation)
1151 return do_statahead_enter(dir, dentryp, lookup);
1154 /* llite ioctl register support rountine */
1161 #define LLIOC_MAX_CMD 256
1164 * Rules to write a callback function:
1167 * @magic: Dynamic ioctl call routine will feed this vaule with the pointer
1168 * returned to ll_iocontrol_register. Callback functions should use this
1169 * data to check the potential collasion of ioctl cmd. If collasion is
1170 * found, callback function should return LLIOC_CONT.
1171 * @rcp: The result of ioctl command.
1174 * If @magic matches the pointer returned by ll_iocontrol_data, the
1175 * callback should return LLIOC_STOP; return LLIOC_STOP otherwise.
1177 typedef enum llioc_iter (*llioc_callback_t)(struct inode *inode,
1178 struct file *file, unsigned int cmd, unsigned long arg,
1179 void *magic, int *rcp);
1181 enum llioc_iter ll_iocontrol_call(struct inode *inode, struct file *file,
1182 unsigned int cmd, unsigned long arg, int *rcp);
1184 /* export functions */
1185 /* Register ioctl block dynamatically for a regular file.
1187 * @cmd: the array of ioctl command set
1188 * @count: number of commands in the @cmd
1189 * @cb: callback function, it will be called if an ioctl command is found to
1190 * belong to the command list @cmd.
1193 * A magic pointer will be returned if success;
1194 * otherwise, NULL will be returned.
1196 void *ll_iocontrol_register(llioc_callback_t cb, int count, unsigned int *cmd);
1197 void ll_iocontrol_unregister(void *magic);
1201 #endif /* LLITE_INTERNAL_H */