Whamcloud - gitweb
1)cleanup smfs code for 2.6 and snapfs
[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, 
134                        struct inode *dir, int offset);
135 struct inode *ll_iget(struct super_block *sb, ino_t hash,
136                       struct lustre_md *lic);
137 struct dentry *ll_find_alias(struct inode *, struct dentry *);
138 int ll_mdc_cancel_unused(struct lustre_handle *, struct inode *, int flags,
139                          void *opaque);
140 int ll_mdc_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
141                         void *data, int flag);
142 /* llite/rw.c */
143 int ll_prepare_write(struct file *, struct page *, unsigned from, unsigned to);
144 int ll_commit_write(struct file *, struct page *, unsigned from, unsigned to);
145 void ll_inode_fill_obdo(struct inode *inode, int cmd, struct obdo *oa);
146 void ll_ap_completion(void *data, int cmd, struct obdo *oa, int rc);
147 void ll_removepage(struct page *page);
148 int ll_readpage(struct file *file, struct page *page);
149 struct ll_async_page *llap_from_cookie(void *cookie);
150 struct ll_async_page *llap_from_page(struct page *page);
151 struct ll_async_page *llap_cast_private(struct page *page);
152 void ll_readahead_init(struct inode *inode, struct ll_readahead_state *ras);
153
154 void ll_truncate(struct inode *inode);
155
156 /* llite/file.c */
157 extern struct file_operations ll_file_operations;
158 extern struct inode_operations ll_file_inode_operations;
159 extern int ll_inode_revalidate_it(struct dentry *, struct lookup_intent *);
160 int ll_refresh_lsm(struct inode *inode, struct lov_stripe_md *lsm);
161 int ll_extent_lock(struct ll_file_data *, struct inode *,
162                    struct lov_stripe_md *, int mode, ldlm_policy_data_t *,
163                    struct lustre_handle *, int ast_flags);
164 int ll_extent_unlock(struct ll_file_data *, struct inode *,
165                      struct lov_stripe_md *, int mode, struct lustre_handle *);
166 int ll_file_open(struct inode *inode, struct file *file);
167 int ll_file_release(struct inode *inode, struct file *file);
168 int ll_lsm_getattr(struct obd_export *, struct lov_stripe_md *, struct obdo *);
169 int ll_glimpse_size(struct inode *inode, struct ost_lvb *lvb);
170 int ll_local_open(struct file *file, struct lookup_intent *it);
171 int ll_mdc_close(struct obd_export *mdc_exp, struct inode *inode,
172                  struct file *file);
173 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
174 int ll_getattr(struct vfsmount *mnt, struct dentry *de,
175                struct lookup_intent *it, struct kstat *stat);
176 #endif
177
178 /* llite/dcache.c */
179 void ll_intent_drop_lock(struct lookup_intent *);
180 void ll_intent_release(struct lookup_intent *);
181 extern void ll_set_dd(struct dentry *de);
182 void ll_unhash_aliases(struct inode *);
183 void ll_frob_intent(struct lookup_intent **itp, struct lookup_intent *deft);
184 void ll_lookup_finish_locks(struct lookup_intent *it, struct dentry *dentry);
185
186 /* llite/llite_gns.c */
187 int ll_finish_gns(struct ll_sb_info *sbi);
188 int fill_page_with_path(struct dentry *, struct vfsmount *, char **pagep);
189 int ll_dir_process_mount_object(struct dentry *, struct vfsmount *);
190 int ll_gns_umount_all(struct ll_sb_info *sbi, int timeout);
191 void ll_gns_timer_callback(unsigned long data);
192 void ll_gns_add_timer(struct ll_sb_info *sbi);
193 void ll_gns_del_timer(struct ll_sb_info *sbi);
194 int ll_gns_start_thread(void);
195 void ll_gns_stop_thread(void);
196
197 /* llite/llite_lib.c */
198 extern struct super_operations lustre_super_operations;
199
200 char *ll_read_opt(const char *opt, char *data);
201 int ll_set_opt(const char *opt, char *data, int fl);
202 void ll_options(char *options, char **ost, char **mds, int *flags, 
203                 char **clone_ops);
204 void ll_lli_init(struct ll_inode_info *lli);
205 int ll_fill_super(struct super_block *sb, void *data, int silent);
206 int lustre_fill_super(struct super_block *sb, void *data, int silent);
207 void lustre_put_super(struct super_block *sb);
208 struct inode *ll_inode_from_lock(struct ldlm_lock *lock);
209 void ll_clear_inode(struct inode *inode);
210 int ll_attr2inode(struct inode *inode, struct iattr *attr, int trunc);
211 int ll_setattr_raw(struct inode *inode, struct iattr *attr);
212 int ll_setattr(struct dentry *de, struct iattr *attr);
213 int ll_statfs(struct super_block *sb, struct kstatfs *sfs);
214 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
215                        unsigned long maxage);
216 void ll_update_inode(struct inode *inode, struct lustre_md *);
217 int it_disposition(struct lookup_intent *it, int flag);
218 void it_set_disposition(struct lookup_intent *it, int flag);
219 void ll_read_inode2(struct inode *inode, void *opaque);
220 void ll_delete_inode(struct inode *inode);
221 int ll_iocontrol(struct inode *inode, struct file *file,
222                  unsigned int cmd, unsigned long arg);
223 void ll_umount_begin(struct super_block *sb);
224 int ll_prep_inode(struct obd_export *, struct obd_export *, struct inode **inode,
225                   struct ptlrpc_request *req, int offset, struct super_block *);
226 __u32 get_uuid2int(const char *name, int len);
227 struct dentry *ll_fh_to_dentry(struct super_block *sb, __u32 *data, int len,
228                                int fhtype, int parent);
229 int ll_dentry_to_fh(struct dentry *, __u32 *datap, int *lenp, int need_parent);
230 int null_if_equal(struct ldlm_lock *lock, void *data);
231 int ll_process_config_update(struct ll_sb_info *sbi, int clean);
232
233 /* llite/special.c */
234 extern struct inode_operations ll_special_inode_operations;
235 extern struct file_operations ll_special_chr_inode_fops;
236 extern struct file_operations ll_special_chr_file_fops;
237 extern struct file_operations ll_special_blk_inode_fops;
238 extern struct file_operations ll_special_fifo_inode_fops;
239 extern struct file_operations ll_special_fifo_file_fops;
240 extern struct file_operations ll_special_sock_inode_fops;
241
242 /* llite/symlink.c */
243 extern struct inode_operations ll_fast_symlink_inode_operations;
244
245 /* llite/llite_close.c */
246 struct ll_close_queue {
247         spinlock_t              lcq_lock;
248         struct list_head        lcq_list;
249         wait_queue_head_t       lcq_waitq;
250         struct completion       lcq_comp;
251 };
252
253 void llap_write_pending(struct inode *inode, struct ll_async_page *llap);
254 void llap_write_complete(struct inode *inode, struct ll_async_page *llap);
255 void ll_open_complete(struct inode *inode);
256 int ll_is_inode_dirty(struct inode *inode);
257 void ll_try_done_writing(struct inode *inode);
258 void ll_queue_done_writing(struct inode *inode);
259 void ll_close_thread_shutdown(struct ll_close_queue *lcq);
260 int ll_close_thread_start(struct ll_close_queue **lcq_ret);
261
262 /* generic */
263 #define LL_SBI_NOLCK           0x1
264 #define LL_SBI_READAHEAD       0x2
265 #define LL_SUPER_MAGIC         0x0BD00BD0
266 #define LL_MAX_BLKSIZE         (4UL * 1024 * 1024)
267
268 #if  (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
269 #define    ll_s2sbi(sb)        ((struct ll_sb_info *)((sb)->s_fs_info))
270 #define    ll_set_sbi(sb, sbi) ((sb)->s_fs_info = sbi)
271 void __d_rehash(struct dentry * entry, int lock);
272 static inline __u64 ll_ts2u64(struct timespec *time)
273 {
274         __u64 t = time->tv_sec;
275         return t;
276 }
277 #else  /* 2.4 here */
278 #define    ll_s2sbi(sb)        ((struct ll_sb_info *)((sb)->u.generic_sbp))
279 #define    ll_set_sbi(sb, sbi) ((sb)->u.generic_sbp = sbi)
280 static inline __u64 ll_ts2u64(time_t *time)
281 {
282         return *time;
283 }
284 #endif
285
286 /* don't need an addref as the sb_info should be holding one */
287 static inline struct obd_export *ll_s2obdexp(struct super_block *sb)
288 {
289         return ll_s2sbi(sb)->ll_osc_exp;
290 }
291
292 /* don't need an addref as the sb_info should be holding one */
293 static inline struct obd_export *ll_s2mdcexp(struct super_block *sb)
294 {
295         return ll_s2sbi(sb)->ll_mdc_exp;
296 }
297
298 static inline struct client_obd *sbi2mdc(struct ll_sb_info *sbi)
299 {
300         struct obd_device *obd = sbi->ll_mdc_exp->exp_obd;
301         if (obd == NULL)
302                 LBUG();
303         return &obd->u.cli;
304 }
305
306 // FIXME: replace the name of this with LL_SB to conform to kernel stuff
307 static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
308 {
309         return ll_s2sbi(inode->i_sb);
310 }
311
312 static inline struct obd_export *ll_i2obdexp(struct inode *inode)
313 {
314         return ll_s2obdexp(inode->i_sb);
315 }
316
317 static inline struct obd_export *ll_i2mdcexp(struct inode *inode)
318 {
319         return ll_s2mdcexp(inode->i_sb);
320 }
321
322 static inline int ll_mds_max_easize(struct super_block *sb)
323 {
324         return sbi2mdc(ll_s2sbi(sb))->cl_max_mds_easize;
325 }
326
327 static inline __u64 ll_file_maxbytes(struct inode *inode)
328 {
329         return ll_i2info(inode)->lli_maxbytes;
330 }
331
332 #endif /* LLITE_INTERNAL_H */