Whamcloud - gitweb
landing b_cmobd_merge on HEAD
[fs/lustre-release.git] / lustre / llite / llite_internal.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2003 Cluster File Systems, Inc.
5  *
6  * This code is issued under the GNU General Public License.
7  * See the file COPYING in this distribution
8  */
9
10 #ifndef LLITE_INTERNAL_H
11 #define LLITE_INTERNAL_H
12
13 /* default to about 40meg of readahead on a given system.  That much tied
14  * up in 512k readahead requests serviced at 40ms each is about 1GB/s. */
15 #define SBI_DEFAULT_RA_MAX ((40 << 20) >> PAGE_CACHE_SHIFT)
16
17 struct ll_sb_info {
18         /* this protects pglist and max_r_a_pages.  It isn't safe to
19          * grab from interrupt contexts */
20         spinlock_t                ll_lock;
21         struct obd_uuid           ll_sb_uuid;
22         struct obd_export        *ll_mdc_exp;
23         struct obd_export        *ll_osc_exp;
24         struct proc_dir_entry*    ll_proc_root;
25         obd_id                    ll_rootino; /* number of root inode */
26
27         struct lustre_mount_data *ll_lmd;
28         char                     *ll_instance;
29
30         int                       ll_flags;
31         struct list_head          ll_conn_chain; /* per-conn chain of SBs */
32
33         struct hlist_head         ll_orphan_dentry_list; /*please don't ask -p*/
34         struct ll_close_queue    *ll_lcq;
35
36         struct lprocfs_stats     *ll_stats; /* lprocfs stats counter */
37
38         unsigned long             ll_pglist_gen;
39         struct list_head          ll_pglist;
40
41         unsigned long             ll_read_ahead_pages;
42         unsigned long             ll_max_read_ahead_pages;
43
44 };
45
46 struct ll_readahead_state {
47         spinlock_t      ras_lock;
48         unsigned long   ras_last_readpage, ras_consecutive;
49         unsigned long   ras_window_start, ras_window_len;
50         unsigned long   ras_next_readahead;
51
52 };
53
54 extern kmem_cache_t *ll_file_data_slab;
55 struct lustre_handle;
56 struct ll_file_data {
57         struct obd_client_handle fd_mds_och;
58         struct ll_readahead_state fd_ras;
59         __u32 fd_flags;
60         struct lustre_handle fd_cwlockh;
61         unsigned long fd_gid;
62 };
63
64 struct lov_stripe_md;
65
66 extern spinlock_t inode_lock;
67
68 extern void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi);
69 extern struct proc_dir_entry *proc_lustre_fs_root;
70
71 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
72 # define hlist_del_init list_del_init
73 #endif
74
75 static inline struct inode *ll_info2i(struct ll_inode_info *lli)
76 {
77 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
78         return &lli->lli_vfs_inode;
79 #else
80         return list_entry(lli, struct inode, u.generic_ip);
81 #endif
82 }
83
84
85 struct it_cb_data {
86         struct inode *icbd_parent;
87         struct dentry **icbd_childp;
88         obd_id hash;
89 };
90
91 #define LLAP_MAGIC 98764321
92
93 struct ll_async_page {
94         int             llap_magic;
95         void            *llap_cookie;
96         struct page     *llap_page;
97         struct list_head llap_pending_write;
98          /* only trust these if the page lock is providing exclusion */
99         int              llap_write_queued:1,
100                          llap_defer_uptodate:1;
101         struct list_head llap_proc_item;
102 };
103
104 #define LL_CDEBUG_PAGE(mask, page, fmt, arg...)                         \
105         CDEBUG(mask, "page %p map %p ind %lu priv %0lx: " fmt,          \
106                page, page->mapping, page->index, page->private, ## arg)
107
108 /* llite/lproc_llite.c */
109 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
110                                 struct super_block *sb, char *osc, char *mdc);
111 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi);
112
113 /* llite/dir.c */
114 extern struct file_operations ll_dir_operations;
115 extern struct inode_operations ll_dir_inode_operations;
116
117 /* llite/namei.c */
118 int ll_objects_destroy(struct ptlrpc_request *request, struct inode *dir);
119 struct inode *ll_iget(struct super_block *sb, ino_t hash,
120                       struct lustre_md *lic);
121 struct dentry *ll_find_alias(struct inode *, struct dentry *);
122 int ll_mdc_cancel_unused(struct lustre_handle *, struct inode *, int flags,
123                          void *opaque);
124 int ll_mdc_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
125                         void *data, int flag);
126 /* llite/rw.c */
127 int ll_prepare_write(struct file *, struct page *, unsigned from, unsigned to);
128 int ll_commit_write(struct file *, struct page *, unsigned from, unsigned to);
129 void ll_inode_fill_obdo(struct inode *inode, int cmd, struct obdo *oa);
130 void ll_ap_completion(void *data, int cmd, struct obdo *oa, int rc);
131 void ll_removepage(struct page *page);
132 int ll_readpage(struct file *file, struct page *page);
133 struct ll_async_page *llap_from_cookie(void *cookie);
134 struct ll_async_page *llap_from_page(struct page *page);
135 struct ll_async_page *llap_cast_private(struct page *page);
136 void ll_readahead_init(struct inode *inode, struct ll_readahead_state *ras);
137
138 void ll_truncate(struct inode *inode);
139
140 /* llite/file.c */
141 extern struct file_operations ll_file_operations;
142 extern struct inode_operations ll_file_inode_operations;
143 extern int ll_inode_revalidate_it(struct dentry *, struct lookup_intent *);
144 int ll_extent_lock(struct ll_file_data *, struct inode *,
145                    struct lov_stripe_md *, int mode, ldlm_policy_data_t *,
146                    struct lustre_handle *, int ast_flags);
147 int ll_extent_unlock(struct ll_file_data *, struct inode *,
148                      struct lov_stripe_md *, int mode, struct lustre_handle *);
149 int ll_file_open(struct inode *inode, struct file *file);
150 int ll_file_release(struct inode *inode, struct file *file);
151 int ll_lsm_getattr(struct obd_export *, struct lov_stripe_md *, struct obdo *);
152 int ll_glimpse_size(struct inode *inode, struct ost_lvb *lvb);
153 int ll_local_open(struct file *file, struct lookup_intent *it);
154 int ll_mdc_close(struct obd_export *mdc_exp, struct inode *inode,
155                  struct file *file);
156 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
157 int ll_getattr(struct vfsmount *mnt, struct dentry *de,
158                struct lookup_intent *it, struct kstat *stat);
159 #endif
160
161 /* llite/dcache.c */
162 void ll_intent_drop_lock(struct lookup_intent *);
163 void ll_intent_release(struct lookup_intent *);
164 extern void ll_set_dd(struct dentry *de);
165 void ll_unhash_aliases(struct inode *);
166 void ll_frob_intent(struct lookup_intent **itp, struct lookup_intent *deft);
167 void ll_lookup_finish_locks(struct lookup_intent *it, struct dentry *dentry);
168
169 /* llite/llite_lib.c */
170
171 extern struct super_operations lustre_super_operations;
172
173 char *ll_read_opt(const char *opt, char *data);
174 int ll_set_opt(const char *opt, char *data, int fl);
175 void ll_options(char *options, char **ost, char **mds, int *flags);
176 void ll_lli_init(struct ll_inode_info *lli);
177 int ll_fill_super(struct super_block *sb, void *data, int silent);
178 int lustre_fill_super(struct super_block *sb, void *data, int silent);
179 void lustre_put_super(struct super_block *sb);
180 struct inode *ll_inode_from_lock(struct ldlm_lock *lock);
181 void ll_clear_inode(struct inode *inode);
182 int ll_attr2inode(struct inode *inode, struct iattr *attr, int trunc);
183 int ll_setattr_raw(struct inode *inode, struct iattr *attr);
184 int ll_setattr(struct dentry *de, struct iattr *attr);
185 int ll_statfs(struct super_block *sb, struct kstatfs *sfs);
186 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
187                        unsigned long maxage);
188 void ll_update_inode(struct inode *inode, struct lustre_md *);
189 int it_disposition(struct lookup_intent *it, int flag);
190 void it_set_disposition(struct lookup_intent *it, int flag);
191 void ll_read_inode2(struct inode *inode, void *opaque);
192 int ll_iocontrol(struct inode *inode, struct file *file,
193                  unsigned int cmd, unsigned long arg);
194 void ll_umount_begin(struct super_block *sb);
195 int ll_prep_inode(struct obd_export *, struct obd_export *, struct inode **inode,
196                   struct ptlrpc_request *req, int offset, struct super_block *);
197 __u32 get_uuid2int(const char *name, int len);
198 struct dentry *ll_fh_to_dentry(struct super_block *sb, __u32 *data, int len,
199                                int fhtype, int parent);
200 int ll_dentry_to_fh(struct dentry *, __u32 *datap, int *lenp, int need_parent);
201 int null_if_equal(struct ldlm_lock *lock, void *data);
202
203 /* llite/special.c */
204 extern struct inode_operations ll_special_inode_operations;
205 extern struct file_operations ll_special_chr_inode_fops;
206 extern struct file_operations ll_special_chr_file_fops;
207 extern struct file_operations ll_special_blk_inode_fops;
208 extern struct file_operations ll_special_fifo_inode_fops;
209 extern struct file_operations ll_special_fifo_file_fops;
210 extern struct file_operations ll_special_sock_inode_fops;
211
212 /* llite/symlink.c */
213 extern struct inode_operations ll_fast_symlink_inode_operations;
214
215 /* llite/llite_close.c */
216 struct ll_close_queue {
217         spinlock_t              lcq_lock;
218         struct list_head        lcq_list;
219         wait_queue_head_t       lcq_waitq;
220         struct completion       lcq_comp;
221 };
222
223 void llap_write_pending(struct inode *inode, struct ll_async_page *llap);
224 void llap_write_complete(struct inode *inode, struct ll_async_page *llap);
225 void ll_open_complete(struct inode *inode);
226 int ll_is_inode_dirty(struct inode *inode);
227 void ll_try_done_writing(struct inode *inode);
228 void ll_queue_done_writing(struct inode *inode);
229 void ll_close_thread_shutdown(struct ll_close_queue *lcq);
230 int ll_close_thread_start(struct ll_close_queue **lcq_ret);
231
232 /* generic */
233 #define LL_SBI_NOLCK           0x1
234 #define LL_SBI_READAHEAD       0x2
235 #define LL_SUPER_MAGIC         0x0BD00BD0
236 #define LL_MAX_BLKSIZE         (4UL * 1024 * 1024)
237
238 #if  (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
239 #define    ll_s2sbi(sb)        ((struct ll_sb_info *)((sb)->s_fs_info))
240 #define    ll_set_sbi(sb, sbi) ((sb)->s_fs_info = sbi)
241 void __d_rehash(struct dentry * entry, int lock);
242 static inline __u64 ll_ts2u64(struct timespec *time)
243 {
244         __u64 t = time->tv_sec;
245         return t;
246 }
247 #else  /* 2.4 here */
248 #define    ll_s2sbi(sb)        ((struct ll_sb_info *)((sb)->u.generic_sbp))
249 #define    ll_set_sbi(sb, sbi) ((sb)->u.generic_sbp = sbi)
250 static inline __u64 ll_ts2u64(time_t *time)
251 {
252         return *time;
253 }
254 #endif
255
256 /* don't need an addref as the sb_info should be holding one */
257 static inline struct obd_export *ll_s2obdexp(struct super_block *sb)
258 {
259         return ll_s2sbi(sb)->ll_osc_exp;
260 }
261
262 /* don't need an addref as the sb_info should be holding one */
263 static inline struct obd_export *ll_s2mdcexp(struct super_block *sb)
264 {
265         return ll_s2sbi(sb)->ll_mdc_exp;
266 }
267
268 static inline struct client_obd *sbi2mdc(struct ll_sb_info *sbi)
269 {
270         struct obd_device *obd = sbi->ll_mdc_exp->exp_obd;
271         if (obd == NULL)
272                 LBUG();
273         return &obd->u.cli;
274 }
275
276 // FIXME: replace the name of this with LL_SB to conform to kernel stuff
277 static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
278 {
279         return ll_s2sbi(inode->i_sb);
280 }
281
282 static inline struct obd_export *ll_i2obdexp(struct inode *inode)
283 {
284         return ll_s2obdexp(inode->i_sb);
285 }
286
287 static inline struct obd_export *ll_i2mdcexp(struct inode *inode)
288 {
289         return ll_s2mdcexp(inode->i_sb);
290 }
291
292 static inline int ll_mds_max_easize(struct super_block *sb)
293 {
294         return sbi2mdc(ll_s2sbi(sb))->cl_max_mds_easize;
295 }
296
297 static inline __u64 ll_file_maxbytes(struct inode *inode)
298 {
299         return ll_i2info(inode)->lli_maxbytes;
300 }
301
302 #endif /* LLITE_INTERNAL_H */