1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * lustre lite cluster file system
6 * This code is issued under the GNU General Public License.
7 * See the file COPYING in this distribution
9 * Copyright (C) 2002 Cluster File Systems, Inc. <info@clusterfs.com>
20 #include <linux/ext2_fs.h>
21 #include <linux/proc_fs.h>
23 #include <linux/obd_class.h>
24 #include <linux/lustre_net.h>
25 #include <linux/lustre_mds.h>
26 #include <linux/lustre_ha.h>
28 #include <linux/rbtree.h>
29 #include <linux/lustre_compat25.h>
30 #include <linux/pagemap.h>
32 /* careful, this is easy to screw up */
33 #define PAGE_CACHE_MAXBYTES ((__u64)(~0UL) << PAGE_CACHE_SHIFT)
35 extern kmem_cache_t *ll_file_data_slab;
37 struct obd_client_handle fd_mds_och;
38 struct obd_client_handle fd_ost_och;
42 struct lustre_intent_data {
43 __u64 it_lock_handle[2];
49 struct ll_dentry_data {
50 struct semaphore lld_it_sem;
53 #define ll_d2d(dentry) ((struct ll_dentry_data*) dentry->d_fsdata)
55 struct ll_dirty_offsets {
58 unsigned long do_num_dirty;
61 void ll_lldo_init(struct ll_dirty_offsets *lldo);
62 void ll_record_dirty(struct inode *inode, unsigned long offset);
63 void ll_remove_dirty(struct inode *inode, unsigned long start,
65 int ll_find_dirty(struct ll_dirty_offsets *lldo, unsigned long *start,
67 int ll_farthest_dirty(struct ll_dirty_offsets *lldo, unsigned long *farthest);
68 extern struct file_operations ll_pgcache_seq_fops;
70 struct ll_inode_info {
71 struct lov_stripe_md *lli_smd;
72 char *lli_symlink_name;
73 struct semaphore lli_open_sem;
74 struct list_head lli_read_extents;
76 spinlock_t lli_read_extent_lock;
77 struct ll_dirty_offsets lli_dirty;
78 unsigned long lli_flags;
79 #define LLI_F_HAVE_SIZE_LOCK 0
81 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
82 struct inode lli_vfs_inode;
87 * this lets ll_file_read tell ll_readpages how far ahead it can read
88 * and still be covered by ll_file_read's lock. 2.5 won't need this, but
89 * we have the other problem of other readpage callers making sure that
90 * they're covered by a lock..
92 struct ll_read_extent {
93 struct list_head re_lli_item;
94 struct task_struct *re_task;
95 struct ldlm_extent re_extent;
98 int ll_check_dirty( struct super_block *sb );
99 int ll_batch_writepage( struct inode *inode, struct page *page );
101 struct file_io_stats {
103 __u64 fis_dirty_pages;
104 __u64 fis_dirty_hits;
105 __u64 fis_dirty_misses;
106 __u64 fis_forced_pages;
107 __u64 fis_writepage_pages;
110 __u64 fis_wb_from_writepage;
111 __u64 fis_wb_from_pressure;
114 #define IO_STAT_ADD(FIS, STAT, VAL) do { \
115 struct file_io_stats *_fis_ = (FIS); \
116 spin_lock(&_fis_->fis_lock); \
117 _fis_->fis_##STAT += VAL; \
118 spin_unlock(&_fis_->fis_lock); \
121 #define INODE_IO_STAT_ADD(INODE, STAT, VAL) \
122 IO_STAT_ADD(&ll_i2sbi(INODE)->ll_iostats, STAT, VAL)
124 #define PAGE_IO_STAT_ADD(PAGE, STAT, VAL) \
125 INODE_IO_STAT_ADD((PAGE)->mapping, STAT, VAL)
127 /* interpet return codes from intent lookup */
128 #define LL_LOOKUP_POSITIVE 1
129 #define LL_LOOKUP_NEGATIVE 2
131 #define LL_SUPER_MAGIC 0x0BD00BD0
133 #define LL_COMMITCBD_STOPPING 0x1
134 #define LL_COMMITCBD_STOPPED 0x2
135 #define LL_COMMITCBD_RUNNING 0x4
137 #define LL_SBI_NOLCK 0x1
140 struct obd_uuid ll_sb_uuid;
141 struct lustre_handle ll_mdc_conn;
142 struct lustre_handle ll_osc_conn;
143 struct proc_dir_entry* ll_proc_root;
144 obd_id ll_rootino; /* number of root inode */
147 wait_queue_head_t ll_commitcbd_waitq;
148 wait_queue_head_t ll_commitcbd_ctl_waitq;
149 int ll_commitcbd_flags;
150 struct task_struct *ll_commitcbd_thread;
151 time_t ll_commitcbd_waketime;
152 time_t ll_commitcbd_timeout;
153 spinlock_t ll_commitcbd_lock;
154 struct list_head ll_conn_chain; /* per-conn chain of SBs */
156 struct list_head ll_orphan_dentry_list; /*please don't ask -p*/
158 struct file_io_stats ll_iostats;
161 static inline struct ll_sb_info *ll_s2sbi(struct super_block *sb)
163 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
164 return (struct ll_sb_info *)(sb->s_fs_info);
166 return (struct ll_sb_info *)(sb->u.generic_sbp);
170 static inline struct lustre_handle *ll_s2obdconn(struct super_block *sb)
172 return &(ll_s2sbi(sb))->ll_osc_conn;
175 static inline struct client_obd *sbi2mdc(struct ll_sb_info *sbi)
177 struct obd_device *obd = class_conn2obd(&sbi->ll_mdc_conn);
183 // FIXME: replace the name of this with LL_SB to conform to kernel stuff
184 static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
186 return ll_s2sbi(inode->i_sb);
189 static inline void d_unhash_aliases(struct inode *inode)
191 struct dentry *dentry = NULL;
192 struct list_head *tmp;
193 struct ll_sb_info *sbi = ll_i2sbi(inode);
196 CDEBUG(D_INODE, "marking dentries for ino %lx/%x invalid\n",
197 inode->i_ino, inode->i_generation);
199 spin_lock(&dcache_lock);
200 list_for_each(tmp, &inode->i_dentry) {
201 dentry = list_entry(tmp, struct dentry, d_alias);
203 list_del_init(&dentry->d_hash);
204 dentry->d_flags |= DCACHE_LUSTRE_INVALID;
205 list_add(&dentry->d_hash, &sbi->ll_orphan_dentry_list);
208 spin_unlock(&dcache_lock);
212 // FIXME: replace the name of this with LL_I to conform to kernel stuff
213 // static inline struct ll_inode_info *LL_I(struct inode *inode)
214 static inline struct ll_inode_info *ll_i2info(struct inode *inode)
216 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
217 return container_of(inode, struct ll_inode_info, lli_vfs_inode);
219 return (struct ll_inode_info *)&(inode->u.generic_ip);
223 static inline struct lustre_handle *ll_i2obdconn(struct inode *inode)
225 return ll_s2obdconn(inode->i_sb);
228 static inline void ll_ino2fid(struct ll_fid *fid, obd_id ino, __u32 generation,
231 static inline void ll_inode2fid(struct ll_fid *fid, struct inode *inode)
233 ll_ino2fid(fid, inode->i_ino, inode->i_generation,
234 inode->i_mode & S_IFMT);
237 static inline int ll_mds_max_easize(struct super_block *sb)
239 return sbi2mdc(ll_s2sbi(sb))->cl_max_mds_easize;
242 static inline loff_t ll_file_maxbytes(struct inode *inode)
244 return ll_i2info(inode)->lli_maxbytes;
248 int ll_lock(struct inode *dir, struct dentry *dentry,
249 struct lookup_intent *it, struct lustre_handle *lockh);
250 int ll_unlock(__u32 mode, struct lustre_handle *lockh);
252 typedef int (*intent_finish_cb)(int flag, struct ptlrpc_request *,
253 struct inode *parent, struct dentry **,
254 struct lookup_intent *, int offset, obd_id ino);
255 int ll_intent_lock(struct inode *parent, struct dentry **,
256 struct lookup_intent *, intent_finish_cb);
257 int ll_mdc_blocking_ast(struct ldlm_lock *lock,
258 struct ldlm_lock_desc *desc,
259 void *data, int flag);
260 void ll_mdc_lock_set_inode(struct lustre_handle *lock, struct inode *inode);
261 void ll_prepare_mdc_op_data(struct mdc_op_data *data,
262 struct inode *i1, struct inode *i2,
263 const char *name, int namelen, int mode);
266 void ll_intent_release(struct dentry *, struct lookup_intent *);
270 I originally implmented these as functions, then realized a macro
271 would be more helpful for debugging, so the CDEBUG messages show
272 the current calling function. The orignal functions are in llite/dcache.c
274 int ll_save_intent(struct dentry * de, struct lookup_intent * it);
275 struct lookup_intent * ll_get_intent(struct dentry * de);
278 #define IT_RELEASED_MAGIC 0xDEADCAFE
280 #define LL_SAVE_INTENT(de, it) \
282 LASSERT(ll_d2d(de) != NULL); \
284 down(&ll_d2d(de)->lld_it_sem); \
285 LASSERT(de->d_it == NULL); \
287 CDEBUG(D_DENTRY, "D_IT DOWN dentry %p fsdata %p intent: %s sem %d\n", \
288 de, ll_d2d(de), ldlm_it2str(de->d_it->it_op), \
289 atomic_read(&(ll_d2d(de)->lld_it_sem.count))); \
292 #define LL_GET_INTENT(de, it) \
296 LASSERT(ll_d2d(de) != NULL); \
298 LASSERT(it->it_op != IT_RELEASED_MAGIC); \
300 CDEBUG(D_DENTRY, "D_IT UP dentry %p fsdata %p intent: %s\n", \
301 de, ll_d2d(de), ldlm_it2str(de->d_it->it_op)); \
303 it->it_op = IT_RELEASED_MAGIC; \
304 up(&ll_d2d(de)->lld_it_sem); \
307 #define LL_IT2STR(it) ((it) ? ldlm_it2str((it)->it_op) : "0")
310 int ll_have_md_lock(struct dentry *de);
313 extern struct file_operations ll_dir_operations;
314 extern struct inode_operations ll_dir_inode_operations;
317 extern struct file_operations ll_file_operations;
318 extern struct inode_operations ll_file_inode_operations;
319 extern struct inode_operations ll_special_inode_operations;
321 int ll_lock_callback(struct ldlm_lock *, struct ldlm_lock_desc *, void *data,
323 int ll_extent_lock_no_validate(struct ll_file_data *fd, struct inode *inode,
324 struct lov_stripe_md *lsm, int mode,
325 struct ldlm_extent *extent, struct lustre_handle *lockh);
326 int ll_extent_lock(struct ll_file_data *fd, struct inode *inode,
327 struct lov_stripe_md *lsm, int mode,
328 struct ldlm_extent *extent, struct lustre_handle *lockh);
329 int ll_extent_unlock(struct ll_file_data *fd, struct inode *inode,
330 struct lov_stripe_md *lsm, int mode,
331 struct lustre_handle *lockh);
332 int ll_create_objects(struct super_block *sb, obd_id id, uid_t uid,
333 gid_t gid, struct lov_stripe_md **lsmp);
334 int ll_file_open(struct inode *inode, struct file *file);
335 int ll_file_release(struct inode *inode, struct file *file);
339 struct page *ll_getpage(struct inode *inode, unsigned long offset,
340 int create, int locked);
341 void ll_truncate(struct inode *inode);
344 void ll_update_inode(struct inode *, struct mds_body *, struct lov_stripe_md *);
345 int ll_setattr_raw(struct inode *inode, struct iattr *attr);
348 extern struct inode_operations ll_fast_symlink_inode_operations;
349 extern struct inode_operations ll_symlink_inode_operations;
352 void ll_sysctl_init(void);
353 void ll_sysctl_clean(void);
356 #include <linux/lustre_idl.h>
357 #endif /* __KERNEL__ */
359 static inline void ll_ino2fid(struct ll_fid *fid,
365 fid->generation = generation;
369 struct ll_read_inode2_cookie {
370 struct mds_body *lic_body;
371 struct lov_stripe_md *lic_lsm;
374 #include <asm/types.h>
376 #define LL_IOC_GETFLAGS _IOR ('f', 151, long)
377 #define LL_IOC_SETFLAGS _IOW ('f', 152, long)
378 #define LL_IOC_CLRFLAGS _IOW ('f', 153, long)
379 #define LL_IOC_LOV_SETSTRIPE _IOW ('f', 154, long)
380 #define LL_IOC_LOV_GETSTRIPE _IOW ('f', 155, long)
382 #define O_LOV_DELAY_CREATE 0100000000 /* hopefully this does not conflict */
384 #define LL_FILE_IGNORE_LOCK 0x00000001