Whamcloud - gitweb
land b_ost_amd onto 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         int                       ll_config_version; /* last-applied update */
45
46         /* list of GNS mounts; protected by the dcache_lock */
47         struct list_head          ll_mnt_list;
48
49         struct semaphore          ll_gns_sem;
50         wait_queue_head_t         ll_gns_waitq;
51         struct completion         ll_gns_completion;
52         int                       ll_gns_state;
53         struct timer_list         ll_gns_timer;
54         struct list_head          ll_gns_sbi_head;
55 };
56
57 #define LL_GNS_STATE_IDLE     1100
58 #define LL_GNS_STATE_MOUNTING 1101
59 #define LL_GNS_STATE_FINISHED 1102
60
61 struct ll_readahead_state {
62         spinlock_t      ras_lock;
63         unsigned long   ras_last_readpage, ras_consecutive;
64         unsigned long   ras_window_start, ras_window_len;
65         unsigned long   ras_next_readahead;
66
67 };
68
69 extern kmem_cache_t *ll_file_data_slab;
70 struct lustre_handle;
71 struct ll_file_data {
72         struct obd_client_handle fd_mds_och;
73         struct ll_readahead_state fd_ras;
74         __u32 fd_flags;
75         struct lustre_handle fd_cwlockh;
76         unsigned long fd_gid;
77 };
78
79 struct lov_stripe_md;
80
81 extern spinlock_t inode_lock;
82
83 extern void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi);
84 extern struct proc_dir_entry *proc_lustre_fs_root;
85
86 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
87 # define hlist_del_init list_del_init
88 #endif
89
90 static inline struct inode *ll_info2i(struct ll_inode_info *lli)
91 {
92 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
93         return &lli->lli_vfs_inode;
94 #else
95         return list_entry(lli, struct inode, u.generic_ip);
96 #endif
97 }
98
99
100 struct it_cb_data {
101         struct inode *icbd_parent;
102         struct dentry **icbd_childp;
103         obd_id hash;
104 };
105
106 #define LLAP_MAGIC 98764321
107
108 struct ll_async_page {
109         int             llap_magic;
110         void            *llap_cookie;
111         struct page     *llap_page;
112         struct list_head llap_pending_write;
113          /* only trust these if the page lock is providing exclusion */
114         int              llap_write_queued:1,
115                          llap_defer_uptodate:1;
116         struct list_head llap_proc_item;
117 };
118
119 #define LL_CDEBUG_PAGE(mask, page, fmt, arg...)                         \
120         CDEBUG(mask, "page %p map %p ind %lu priv %0lx: " fmt,          \
121                page, page->mapping, page->index, page->private, ## arg)
122
123 /* llite/lproc_llite.c */
124 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
125                                 struct super_block *sb, char *osc, char *mdc);
126 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi);
127
128 /* llite/dir.c */
129 extern struct file_operations ll_dir_operations;
130 extern struct inode_operations ll_dir_inode_operations;
131
132 /* llite/namei.c */
133 int ll_objects_destroy(struct ptlrpc_request *request, struct inode *dir);
134 struct inode *ll_iget(struct super_block *sb, ino_t hash,
135                       struct lustre_md *lic);
136 struct dentry *ll_find_alias(struct inode *, struct dentry *);
137 int ll_mdc_cancel_unused(struct lustre_handle *, struct inode *, int flags,
138                          void *opaque);
139 int ll_mdc_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
140                         void *data, int flag);
141 /* llite/rw.c */
142 int ll_prepare_write(struct file *, struct page *, unsigned from, unsigned to);
143 int ll_commit_write(struct file *, struct page *, unsigned from, unsigned to);
144 void ll_inode_fill_obdo(struct inode *inode, int cmd, struct obdo *oa);
145 void ll_ap_completion(void *data, int cmd, struct obdo *oa, int rc);
146 void ll_removepage(struct page *page);
147 int ll_readpage(struct file *file, struct page *page);
148 struct ll_async_page *llap_from_cookie(void *cookie);
149 struct ll_async_page *llap_from_page(struct page *page);
150 struct ll_async_page *llap_cast_private(struct page *page);
151 void ll_readahead_init(struct inode *inode, struct ll_readahead_state *ras);
152
153 void ll_truncate(struct inode *inode);
154
155 /* llite/file.c */
156 extern struct file_operations ll_file_operations;
157 extern struct inode_operations ll_file_inode_operations;
158 extern int ll_inode_revalidate_it(struct dentry *, struct lookup_intent *);
159 int ll_refresh_lsm(struct inode *inode, struct lov_stripe_md *lsm);
160 int ll_extent_lock(struct ll_file_data *, struct inode *,
161                    struct lov_stripe_md *, int mode, ldlm_policy_data_t *,
162                    struct lustre_handle *, int ast_flags);
163 int ll_extent_unlock(struct ll_file_data *, struct inode *,
164                      struct lov_stripe_md *, int mode, struct lustre_handle *);
165 int ll_file_open(struct inode *inode, struct file *file);
166 int ll_file_release(struct inode *inode, struct file *file);
167 int ll_lsm_getattr(struct obd_export *, struct lov_stripe_md *, struct obdo *);
168 int ll_glimpse_size(struct inode *inode, struct ost_lvb *lvb);
169 int ll_local_open(struct file *file, struct lookup_intent *it);
170 int ll_mdc_close(struct obd_export *mdc_exp, struct inode *inode,
171                  struct file *file);
172 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
173 int ll_getattr(struct vfsmount *mnt, struct dentry *de,
174                struct lookup_intent *it, struct kstat *stat);
175 #endif
176
177 /* llite/dcache.c */
178 void ll_intent_drop_lock(struct lookup_intent *);
179 void ll_intent_release(struct lookup_intent *);
180 extern void ll_set_dd(struct dentry *de);
181 void ll_unhash_aliases(struct inode *);
182 void ll_frob_intent(struct lookup_intent **itp, struct lookup_intent *deft);
183 void ll_lookup_finish_locks(struct lookup_intent *it, struct dentry *dentry);
184
185 /* llite/llite_gns.c */
186 int ll_finish_gns(struct ll_sb_info *sbi);
187 int fill_page_with_path(struct dentry *, struct vfsmount *, char **pagep);
188 int ll_dir_process_mount_object(struct dentry *, struct vfsmount *);
189 int ll_gns_umount_all(struct ll_sb_info *sbi, int timeout);
190 void ll_gns_timer_callback(unsigned long data);
191 void ll_gns_add_timer(struct ll_sb_info *sbi);
192 void ll_gns_del_timer(struct ll_sb_info *sbi);
193 int ll_gns_start_thread(void);
194 void ll_gns_stop_thread(void);
195
196 /* llite/llite_lib.c */
197 extern struct super_operations lustre_super_operations;
198
199 char *ll_read_opt(const char *opt, char *data);
200 int ll_set_opt(const char *opt, char *data, int fl);
201 void ll_options(char *options, char **ost, char **mds, int *flags);
202 void ll_lli_init(struct ll_inode_info *lli);
203 int ll_fill_super(struct super_block *sb, void *data, int silent);
204 int lustre_fill_super(struct super_block *sb, void *data, int silent);
205 void lustre_put_super(struct super_block *sb);
206 struct inode *ll_inode_from_lock(struct ldlm_lock *lock);
207 void ll_clear_inode(struct inode *inode);
208 int ll_attr2inode(struct inode *inode, struct iattr *attr, int trunc);
209 int ll_setattr_raw(struct inode *inode, struct iattr *attr);
210 int ll_setattr(struct dentry *de, struct iattr *attr);
211 int ll_statfs(struct super_block *sb, struct kstatfs *sfs);
212 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
213                        unsigned long maxage);
214 void ll_update_inode(struct inode *inode, struct lustre_md *);
215 int it_disposition(struct lookup_intent *it, int flag);
216 void it_set_disposition(struct lookup_intent *it, int flag);
217 void ll_read_inode2(struct inode *inode, void *opaque);
218 int ll_iocontrol(struct inode *inode, struct file *file,
219                  unsigned int cmd, unsigned long arg);
220 void ll_umount_begin(struct super_block *sb);
221 int ll_prep_inode(struct obd_export *, struct obd_export *, struct inode **inode,
222                   struct ptlrpc_request *req, int offset, struct super_block *);
223 __u32 get_uuid2int(const char *name, int len);
224 struct dentry *ll_fh_to_dentry(struct super_block *sb, __u32 *data, int len,
225                                int fhtype, int parent);
226 int ll_dentry_to_fh(struct dentry *, __u32 *datap, int *lenp, int need_parent);
227 int null_if_equal(struct ldlm_lock *lock, void *data);
228 int ll_process_config_update(struct ll_sb_info *sbi, int clean);
229
230 /* llite/special.c */
231 extern struct inode_operations ll_special_inode_operations;
232 extern struct file_operations ll_special_chr_inode_fops;
233 extern struct file_operations ll_special_chr_file_fops;
234 extern struct file_operations ll_special_blk_inode_fops;
235 extern struct file_operations ll_special_fifo_inode_fops;
236 extern struct file_operations ll_special_fifo_file_fops;
237 extern struct file_operations ll_special_sock_inode_fops;
238
239 /* llite/symlink.c */
240 extern struct inode_operations ll_fast_symlink_inode_operations;
241
242 /* llite/llite_close.c */
243 struct ll_close_queue {
244         spinlock_t              lcq_lock;
245         struct list_head        lcq_list;
246         wait_queue_head_t       lcq_waitq;
247         struct completion       lcq_comp;
248 };
249
250 void llap_write_pending(struct inode *inode, struct ll_async_page *llap);
251 void llap_write_complete(struct inode *inode, struct ll_async_page *llap);
252 void ll_open_complete(struct inode *inode);
253 int ll_is_inode_dirty(struct inode *inode);
254 void ll_try_done_writing(struct inode *inode);
255 void ll_queue_done_writing(struct inode *inode);
256 void ll_close_thread_shutdown(struct ll_close_queue *lcq);
257 int ll_close_thread_start(struct ll_close_queue **lcq_ret);
258
259 /* generic */
260 #define LL_SBI_NOLCK           0x1
261 #define LL_SBI_READAHEAD       0x2
262 #define LL_SUPER_MAGIC         0x0BD00BD0
263 #define LL_MAX_BLKSIZE         (4UL * 1024 * 1024)
264
265 #if  (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
266 #define    ll_s2sbi(sb)        ((struct ll_sb_info *)((sb)->s_fs_info))
267 #define    ll_set_sbi(sb, sbi) ((sb)->s_fs_info = sbi)
268 void __d_rehash(struct dentry * entry, int lock);
269 static inline __u64 ll_ts2u64(struct timespec *time)
270 {
271         __u64 t = time->tv_sec;
272         return t;
273 }
274 #else  /* 2.4 here */
275 #define    ll_s2sbi(sb)        ((struct ll_sb_info *)((sb)->u.generic_sbp))
276 #define    ll_set_sbi(sb, sbi) ((sb)->u.generic_sbp = sbi)
277 static inline __u64 ll_ts2u64(time_t *time)
278 {
279         return *time;
280 }
281 #endif
282
283 /* don't need an addref as the sb_info should be holding one */
284 static inline struct obd_export *ll_s2obdexp(struct super_block *sb)
285 {
286         return ll_s2sbi(sb)->ll_osc_exp;
287 }
288
289 /* don't need an addref as the sb_info should be holding one */
290 static inline struct obd_export *ll_s2mdcexp(struct super_block *sb)
291 {
292         return ll_s2sbi(sb)->ll_mdc_exp;
293 }
294
295 static inline struct client_obd *sbi2mdc(struct ll_sb_info *sbi)
296 {
297         struct obd_device *obd = sbi->ll_mdc_exp->exp_obd;
298         if (obd == NULL)
299                 LBUG();
300         return &obd->u.cli;
301 }
302
303 // FIXME: replace the name of this with LL_SB to conform to kernel stuff
304 static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
305 {
306         return ll_s2sbi(inode->i_sb);
307 }
308
309 static inline struct obd_export *ll_i2obdexp(struct inode *inode)
310 {
311         return ll_s2obdexp(inode->i_sb);
312 }
313
314 static inline struct obd_export *ll_i2mdcexp(struct inode *inode)
315 {
316         return ll_s2mdcexp(inode->i_sb);
317 }
318
319 static inline int ll_mds_max_easize(struct super_block *sb)
320 {
321         return sbi2mdc(ll_s2sbi(sb))->cl_max_mds_easize;
322 }
323
324 static inline __u64 ll_file_maxbytes(struct inode *inode)
325 {
326         return ll_i2info(inode)->lli_maxbytes;
327 }
328
329 #endif /* LLITE_INTERNAL_H */