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 extern struct file_operations ll_pgcache_seq_fops;
57 struct ll_inode_info {
58 struct lov_stripe_md *lli_smd;
59 char *lli_symlink_name;
60 struct semaphore lli_open_sem;
61 struct list_head lli_read_extents;
63 spinlock_t lli_read_extent_lock;
64 unsigned long lli_flags;
65 #define LLI_F_HAVE_SIZE_LOCK 0
67 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
68 struct inode lli_vfs_inode;
73 * this lets ll_file_read tell ll_readpages how far ahead it can read
74 * and still be covered by ll_file_read's lock. 2.5 won't need this, but
75 * we have the other problem of other readpage callers making sure that
76 * they're covered by a lock..
78 struct ll_read_extent {
79 struct list_head re_lli_item;
80 struct task_struct *re_task;
81 struct ldlm_extent re_extent;
84 int ll_check_dirty( struct super_block *sb );
85 int ll_batch_writepage( struct inode *inode, struct page *page );
87 /* interpet return codes from intent lookup */
88 #define LL_LOOKUP_POSITIVE 1
89 #define LL_LOOKUP_NEGATIVE 2
91 #define LL_SUPER_MAGIC 0x0BD00BD0
93 #define LL_COMMITCBD_STOPPING 0x1
94 #define LL_COMMITCBD_STOPPED 0x2
95 #define LL_COMMITCBD_RUNNING 0x4
97 #define LL_SBI_NOLCK 0x1
100 struct obd_uuid ll_sb_uuid;
101 struct lustre_handle ll_mdc_conn;
102 struct lustre_handle ll_osc_conn;
103 struct proc_dir_entry* ll_proc_root;
104 obd_id ll_rootino; /* number of root inode */
107 wait_queue_head_t ll_commitcbd_waitq;
108 wait_queue_head_t ll_commitcbd_ctl_waitq;
109 int ll_commitcbd_flags;
110 struct task_struct *ll_commitcbd_thread;
111 time_t ll_commitcbd_waketime;
112 time_t ll_commitcbd_timeout;
113 spinlock_t ll_commitcbd_lock;
114 struct list_head ll_conn_chain; /* per-conn chain of SBs */
116 struct list_head ll_orphan_dentry_list; /*please don't ask -p*/
118 struct lprocfs_stats *ll_stats; /* lprocfs stats counter */
121 static inline struct ll_sb_info *ll_s2sbi(struct super_block *sb)
123 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
124 return (struct ll_sb_info *)(sb->s_fs_info);
126 return (struct ll_sb_info *)(sb->u.generic_sbp);
130 static inline struct lustre_handle *ll_s2obdconn(struct super_block *sb)
132 return &(ll_s2sbi(sb))->ll_osc_conn;
135 static inline struct client_obd *sbi2mdc(struct ll_sb_info *sbi)
137 struct obd_device *obd = class_conn2obd(&sbi->ll_mdc_conn);
143 // FIXME: replace the name of this with LL_SB to conform to kernel stuff
144 static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
146 return ll_s2sbi(inode->i_sb);
149 static inline void d_unhash_aliases(struct inode *inode)
151 struct dentry *dentry = NULL;
152 struct list_head *tmp;
153 struct ll_sb_info *sbi = ll_i2sbi(inode);
156 CDEBUG(D_INODE, "marking dentries for ino %lx/%x invalid\n",
157 inode->i_ino, inode->i_generation);
159 spin_lock(&dcache_lock);
160 list_for_each(tmp, &inode->i_dentry) {
161 dentry = list_entry(tmp, struct dentry, d_alias);
163 list_del_init(&dentry->d_hash);
164 dentry->d_flags |= DCACHE_LUSTRE_INVALID;
165 list_add(&dentry->d_hash, &sbi->ll_orphan_dentry_list);
168 spin_unlock(&dcache_lock);
172 // FIXME: replace the name of this with LL_I to conform to kernel stuff
173 // static inline struct ll_inode_info *LL_I(struct inode *inode)
174 static inline struct ll_inode_info *ll_i2info(struct inode *inode)
176 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
177 return container_of(inode, struct ll_inode_info, lli_vfs_inode);
179 return (struct ll_inode_info *)&(inode->u.generic_ip);
183 static inline struct lustre_handle *ll_i2obdconn(struct inode *inode)
185 return ll_s2obdconn(inode->i_sb);
188 static inline void ll_ino2fid(struct ll_fid *fid, obd_id ino, __u32 generation,
191 static inline void ll_inode2fid(struct ll_fid *fid, struct inode *inode)
193 ll_ino2fid(fid, inode->i_ino, inode->i_generation,
194 inode->i_mode & S_IFMT);
197 static inline int ll_mds_max_easize(struct super_block *sb)
199 return sbi2mdc(ll_s2sbi(sb))->cl_max_mds_easize;
202 static inline loff_t ll_file_maxbytes(struct inode *inode)
204 return ll_i2info(inode)->lli_maxbytes;
208 int ll_lock(struct inode *dir, struct dentry *dentry,
209 struct lookup_intent *it, struct lustre_handle *lockh);
210 int ll_unlock(__u32 mode, struct lustre_handle *lockh);
212 typedef int (*intent_finish_cb)(int flag, struct ptlrpc_request *,
213 struct inode *parent, struct dentry **,
214 struct lookup_intent *, int offset, obd_id ino);
215 int ll_intent_lock(struct inode *parent, struct dentry **,
216 struct lookup_intent *, intent_finish_cb);
217 int ll_mdc_blocking_ast(struct ldlm_lock *lock,
218 struct ldlm_lock_desc *desc,
219 void *data, int flag);
220 void ll_mdc_lock_set_inode(struct lustre_handle *lock, struct inode *inode);
221 void ll_prepare_mdc_op_data(struct mdc_op_data *data,
222 struct inode *i1, struct inode *i2,
223 const char *name, int namelen, int mode);
226 void ll_intent_release(struct dentry *, struct lookup_intent *);
230 I originally implmented these as functions, then realized a macro
231 would be more helpful for debugging, so the CDEBUG messages show
232 the current calling function. The orignal functions are in llite/dcache.c
234 int ll_save_intent(struct dentry * de, struct lookup_intent * it);
235 struct lookup_intent * ll_get_intent(struct dentry * de);
238 #define IT_RELEASED_MAGIC 0xDEADCAFE
240 #define LL_SAVE_INTENT(de, it) \
242 LASSERT(ll_d2d(de) != NULL); \
244 down(&ll_d2d(de)->lld_it_sem); \
245 LASSERT(de->d_it == NULL); \
248 "D_IT DOWN dentry %p fsdata %p intent: %p %s sem %d\n", \
249 de, ll_d2d(de), de->d_it, ldlm_it2str(de->d_it->it_op), \
250 atomic_read(&(ll_d2d(de)->lld_it_sem.count))); \
253 #define LL_GET_INTENT(de, it) \
257 LASSERT(ll_d2d(de) != NULL); \
259 LASSERT(it->it_op != IT_RELEASED_MAGIC); \
261 CDEBUG(D_DENTRY, "D_IT UP dentry %p fsdata %p intent: %p %s\n", \
262 de, ll_d2d(de), de->d_it, ldlm_it2str(de->d_it->it_op)); \
264 it->it_op = IT_RELEASED_MAGIC; \
265 up(&ll_d2d(de)->lld_it_sem); \
268 #define LL_IT2STR(it) ((it) ? ldlm_it2str((it)->it_op) : "0")
271 LPROC_LL_DIRTY_HITS = 0,
272 LPROC_LL_DIRTY_MISSES,
273 LPROC_LL_WB_WRITEPAGE,
274 LPROC_LL_WB_PRESSURE,
278 LPROC_LL_WRITE_BYTES,
287 LPROC_LL_SETATTR_RAW,
291 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
297 LPROC_LL_ALLOC_INODE,
299 LPROC_LL_DIRECT_READ,
300 LPROC_LL_DIRECT_WRITE,
301 LPROC_LL_FILE_OPCODES
304 int ll_have_md_lock(struct dentry *de);
307 extern struct file_operations ll_dir_operations;
308 extern struct inode_operations ll_dir_inode_operations;
311 extern struct file_operations ll_file_operations;
312 extern struct inode_operations ll_file_inode_operations;
313 extern struct inode_operations ll_special_inode_operations;
315 int ll_extent_lock_callback(struct ldlm_lock *, struct ldlm_lock_desc *,
316 void *data, int flag);
317 int ll_extent_lock_no_validate(struct ll_file_data *fd, struct inode *inode,
318 struct lov_stripe_md *lsm, int mode,
319 struct ldlm_extent *extent, struct lustre_handle *lockh);
320 int ll_extent_lock(struct ll_file_data *fd, struct inode *inode,
321 struct lov_stripe_md *lsm, int mode,
322 struct ldlm_extent *extent, struct lustre_handle *lockh);
323 int ll_extent_unlock(struct ll_file_data *fd, struct inode *inode,
324 struct lov_stripe_md *lsm, int mode,
325 struct lustre_handle *lockh);
326 int ll_create_objects(struct super_block *sb, obd_id id, uid_t uid,
327 gid_t gid, struct lov_stripe_md **lsmp);
328 int ll_file_open(struct inode *inode, struct file *file);
329 int ll_file_release(struct inode *inode, struct file *file);
333 struct page *ll_getpage(struct inode *inode, unsigned long offset,
334 int create, int locked);
335 void ll_truncate(struct inode *inode);
338 void ll_update_inode(struct inode *, struct mds_body *, struct lov_stripe_md *);
339 int ll_setattr_raw(struct inode *inode, struct iattr *attr);
342 extern struct inode_operations ll_fast_symlink_inode_operations;
343 extern struct inode_operations ll_symlink_inode_operations;
346 void ll_sysctl_init(void);
347 void ll_sysctl_clean(void);
350 #include <linux/lustre_idl.h>
351 #endif /* __KERNEL__ */
353 static inline void ll_ino2fid(struct ll_fid *fid,
359 fid->generation = generation;
363 struct ll_read_inode2_cookie {
364 struct mds_body *lic_body;
365 struct lov_stripe_md *lic_lsm;
368 #include <asm/types.h>
370 #define LL_IOC_GETFLAGS _IOR ('f', 151, long)
371 #define LL_IOC_SETFLAGS _IOW ('f', 152, long)
372 #define LL_IOC_CLRFLAGS _IOW ('f', 153, long)
373 #define LL_IOC_LOV_SETSTRIPE _IOW ('f', 154, long)
374 #define LL_IOC_LOV_GETSTRIPE _IOW ('f', 155, long)
376 #define O_LOV_DELAY_CREATE 0100000000 /* hopefully this does not conflict */
378 #define LL_FILE_IGNORE_LOCK 0x00000001