1 #ifndef __LUSTRE_SMFS_H
2 #define __LUSTRE_SMFS_H
4 struct smfs_inode_info {
5 struct inode *smi_inode;
9 struct journal_operations {
10 void *(*tr_start)(struct inode *, int op);
11 void (*tr_commit)(void *handle);
14 struct sm_operations {
15 /* operations on the file store */
16 struct super_operations sm_sb_ops;
17 struct inode_operations sm_dir_iops;
18 struct inode_operations sm_file_iops;
19 struct inode_operations sm_sym_iops;
20 struct file_operations sm_dir_fops;
21 struct file_operations sm_file_fops;
22 struct file_operations sm_sym_fops;
23 struct dentry_operations sm_dentry_ops;
24 struct journal_operations sm_journal_ops;
28 typedef int (*smfs_pack_rec_func)(char *buffer, struct dentry *dentry,
29 struct inode *dir, void *data1,
38 struct mds_kml_pack_info {
43 struct smfs_super_info {
44 struct super_block *smsi_sb;
45 struct vfsmount *smsi_mnt; /* mount the cache kern */
46 struct fsfilt_operations *sm_cache_fsfilt; /* fsfilt operations */
47 struct fsfilt_operations *sm_fsfilt; /* fsfilt operations */
48 struct sm_operations *sm_ops; /* cache ops */
49 struct lvfs_run_ctxt *smsi_ctxt;
50 struct llog_ctxt *smsi_rec_log; /* smfs kml llog */
51 struct dentry *smsi_logs_dir;
52 struct dentry *smsi_objects_dir;
53 struct dentry *smsi_delete_dir; /* for delete inode dir */
54 char *smsi_cache_ftype; /* cache file system type */
55 char *smsi_ftype; /* file system type */
56 struct obd_export *smsi_exp; /* file system obd exp */
57 smfs_pack_rec_func smsi_pack_rec[PACK_MAX]; /* sm_pack_rec type ops */
58 __u32 smsi_flags; /* flags */
62 #define SMFS_FILE_TYPE "smfs"
63 #define SMFS_FILE_MAGIC 0x19760218
65 struct smfs_file_info {
70 struct smfs_proc_args {
71 struct super_block *sr_sb;
77 __u32 e_block; /* first logical block extent covers */
78 __u32 e_start; /* first physical block extents lives */
79 __u32 e_num; /* number of blocks covered by extent */
82 #define I2SMI(inode) ((struct smfs_inode_info *) (&(inode->u.generic_ip)))
83 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
84 #define S2SMI(sb) ((struct smfs_super_info *) (&(sb->u.generic_sbp)))
85 #define S2CSB(sb) (((struct smfs_super_info *) (&(sb->u.generic_sbp)))->smsi_sb)
87 #define S2SMI(sb) ((struct smfs_super_info *) (sb->s_fs_info))
88 #define S2CSB(sb) (((struct smfs_super_info *) (sb->s_fs_info))->smsi_sb)
91 #define I2CI(inode) (((struct smfs_inode_info*) (&(inode->u.generic_ip)))->smi_inode)
93 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
94 #define I2CSB(inode) ((struct smfs_super_info *) (&(inode->i_sb->u.generic_sbp)))
96 #define I2CSB(inode) ((struct smfs_super_info *) (inode->i_sb->s_fs_info))
99 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
100 #define I2FOPS(inode) (((struct smfs_super_info *) \
101 (&(inode->i_sb->u.generic_sbp)))->sm_cache_fsfilt)
103 #define I2FOPS(inode) (((struct smfs_super_info *) \
104 (inode->i_sb->s_fs_info))->sm_cache_fsfilt)
107 #define F2SMFI(file) ((struct smfs_file_info *)((file->private_data)))
108 #define F2CF(file) (((struct smfs_file_info *) ((file->private_data)))->c_file)
109 #define SIZE2BLKS(size, inode) ((size + (I2CI(inode)->i_blksize)) >> (I2CI(inode)->i_blkbits))
110 #define OFF2BLKS(off, inode) (off >> (I2CI(inode)->i_blkbits))
112 #define SM_DO_REC 0x1
113 #define SM_INIT_REC 0x2
114 #define SM_CACHE_HOOK 0x4
115 #define SM_OVER_WRITE 0x8
116 #define SM_DIRTY_WRITE 0x10
118 #define SMFS_DO_REC(smfs_info) (smfs_info->smsi_flags & SM_DO_REC)
119 #define SMFS_SET_REC(smfs_info) (smfs_info->smsi_flags |= SM_DO_REC)
120 #define SMFS_CLEAN_REC(smfs_info) (smfs_info->smsi_flags &= ~SM_DO_REC)
122 #define SMFS_INIT_REC(smfs_info) (smfs_info->smsi_flags & SM_INIT_REC)
123 #define SMFS_SET_INIT_REC(smfs_info) (smfs_info->smsi_flags |= SM_INIT_REC)
124 #define SMFS_CLEAN_INIT_REC(smfs_info) (smfs_info->smsi_flags &= ~SM_INIT_REC)
126 #define SMFS_SET_INODE_REC(inode) (I2SMI(inode)->smi_flags |= SM_DO_REC)
127 #define SMFS_DO_INODE_REC(inode) (I2SMI(inode)->smi_flags & SM_DO_REC)
128 #define SMFS_CLEAN_INODE_REC(inode) (I2SMI(inode)->smi_flags &= ~SM_DO_REC)
130 #define SMFS_CACHE_HOOK(smfs_info) (smfs_info->smsi_flags & SM_CACHE_HOOK)
131 #define SMFS_SET_CACHE_HOOK(smfs_info) (smfs_info->smsi_flags |= SM_CACHE_HOOK)
132 #define SMFS_CLEAN_CACHE_HOOK(smfs_info) (smfs_info->smsi_flags &= ~SM_CACHE_HOOK)
134 #define SMFS_INODE_CACHE_HOOK(inode) (I2SMI(inode)->smi_flags & SM_CACHE_HOOK)
135 #define SMFS_SET_INODE_CACHE_HOOK(inode) (I2SMI(inode)->smi_flags |= SM_CACHE_HOOK)
136 #define SMFS_CLEAN_INODE_CACHE_HOOK(inode) (I2SMI(inode)->smi_flags &= ~SM_CACHE_HOOK)
138 #define SMFS_INODE_OVER_WRITE(inode) (I2SMI(inode)->smi_flags & SM_OVER_WRITE)
139 #define SMFS_SET_INODE_OVER_WRITE(inode) (I2SMI(inode)->smi_flags |= SM_OVER_WRITE)
140 #define SMFS_CLEAN_INODE_OVER_WRITE(inode) (I2SMI(inode)->smi_flags &= ~SM_OVER_WRITE)
142 #define SMFS_INODE_DIRTY_WRITE(inode) (I2SMI(inode)->smi_flags & SM_DIRTY_WRITE)
143 #define SMFS_SET_INODE_DIRTY_WRITE(inode) (I2SMI(inode)->smi_flags |= SM_DIRTY_WRITE)
144 #define SMFS_CLEAN_INODE_DIRTY_WRITE(inode) (I2SMI(inode)->smi_flags &= ~SM_DIRTY_WRITE)
147 #define LVFS_SMFS_BACK_ATTR "lvfs_back_attr"
150 #define REC_COUNT_BIT 0
151 #define REC_COUNT_MASK 0x01 /*0001*/
153 #define REC_OP_MASK 0x06 /*0110*/
154 #define REC_WRITE_KML_BIT 3
155 #define REC_WRITE_KML_MASK 0x08 /*1000*/
156 #define REC_DEC_LINK_BIT 4
157 #define REC_DEC_LINK_MASK 0x10 /*10000* different with unlink*/
158 #define REC_GET_OID_BIT 5
159 #define REC_GET_OID_MASK 0x20 /*100000*/
161 #define REC_PACK_TYPE_BIT 6
162 #define REC_PACK_TYPE_MASK 0x1C0 /*111000000*/
164 #define SET_REC_COUNT_FLAGS(flag, count_flag) \
165 (flag |= count_flag << REC_COUNT_BIT)
166 #define GET_REC_COUNT_FLAGS(flag) \
167 ((flag & REC_COUNT_MASK) >> REC_COUNT_BIT)
169 #define SET_REC_OP_FLAGS(flag, op_flag) \
170 (flag |= op_flag << REC_OP_BIT)
171 #define GET_REC_OP_FLAGS(flag) \
172 ((flag & REC_OP_MASK) >> REC_OP_BIT)
174 #define SET_REC_WRITE_KML_FLAGS(flag, op_flag) \
175 (flag |= op_flag << REC_OP_BIT)
176 #define GET_REC_WRITE_KML_FLAGS(flag) \
177 ((flag & REC_WRITE_KML_MASK) >> REC_WRITE_KML_BIT)
179 #define SET_REC_DEC_LINK_FLAGS(flag, op_flag) \
180 (flag |= op_flag << REC_DEC_LINK_BIT)
181 #define GET_REC_DEC_LINK_FLAGS(flag) \
182 ((flag & REC_DEC_LINK_MASK) >> REC_DEC_LINK_BIT)
184 #define SET_REC_GET_ID_FLAGS(flag, op_flag) \
185 (flag |= op_flag << REC_GET_OID_BIT)
186 #define GET_REC_GET_OID_FLAGS(flag) \
187 ((flag & REC_GET_OID_MASK) >> REC_GET_OID_BIT)
189 #define SET_REC_PACK_TYPE_INDEX(flag, op_flag) \
190 (flag |= op_flag << REC_PACK_TYPE_BIT)
191 #define GET_REC_PACK_TYPE_INDEX(flag) \
192 ((flag & REC_PACK_TYPE_MASK) >> REC_PACK_TYPE_BIT)
194 #define SMFS_REC_ALL 0x1
195 #define SMFS_REC_BY_COUNT 0x0
197 #define SMFS_REINT_REC 0x1
198 #define SMFS_UNDO_REC 0x2
200 #define SMFS_WRITE_KML 0x1
201 #define SMFS_DEC_LINK 0x1
202 #define SMFS_GET_OID 0x1
204 #define SMFS_DO_REINT_REC(flag) \
205 (GET_REC_OP_FLAGS(flag) == SMFS_REINT_REC)
206 #define SMFS_DO_UNDO_REC(flag) \
207 (GET_REC_OP_FLAGS(flag) == SMFS_UNDO_REC)
208 #define SMFS_DO_REC_ALL(flag) \
209 (GET_REC_COUNT_FLAGS(flag) == SMFS_REC_ALL)
210 #define SMFS_DO_REC_BY_COUNT(flag) \
211 (GET_REC_COUNT_FLAGS(flag) == SMFS_REC_BY_COUNT)
212 #define SMFS_DO_WRITE_KML(flag) \
213 (GET_REC_WRITE_KML_FLAGS(flag) == SMFS_WRITE_KML)
214 #define SMFS_DO_DEC_LINK(flag) \
215 (GET_REC_DEC_LINK_FLAGS(flag) == SMFS_DEC_LINK)
217 #define SMFS_DO_GET_OID(flag) \
218 (GET_REC_GET_OID_FLAGS(flag) == SMFS_GET_OID)
220 /*DIRTY flags of write ops*/
221 #define REINT_EXTENTS_FLAGS "replay_flags"
222 #define SMFS_DIRTY_WRITE 0x01
223 #define SMFS_OVER_WRITE 0x02
226 static inline void duplicate_inode(struct inode *dst_inode,
227 struct inode *src_inode)
229 dst_inode->i_mode = src_inode->i_mode;
230 dst_inode->i_uid = src_inode->i_uid;
231 dst_inode->i_gid = src_inode->i_gid;
232 dst_inode->i_nlink = src_inode->i_nlink;
233 dst_inode->i_size = src_inode->i_size;
234 dst_inode->i_atime = src_inode->i_atime;
235 dst_inode->i_ctime = src_inode->i_ctime;
236 dst_inode->i_mtime = src_inode->i_mtime;
237 dst_inode->i_blksize = src_inode->i_blksize;
238 dst_inode->i_version = src_inode->i_version;
239 dst_inode->i_state = src_inode->i_state;
240 dst_inode->i_generation = src_inode->i_generation;
242 /* This is to make creating special files working. */
243 dst_inode->i_rdev = src_inode->i_rdev;
246 static inline void post_smfs_inode(struct inode *inode,
247 struct inode *cache_inode)
249 if (inode && cache_inode) {
250 duplicate_inode(inode, cache_inode);
251 /*Here we must release the cache_inode,
252 *Otherwise we will have no chance to
255 cache_inode->i_state &=~I_LOCK;
256 inode->i_blocks = cache_inode->i_blocks;
260 static inline void pre_smfs_inode(struct inode *inode,
261 struct inode *cache_inode)
263 if (inode && cache_inode)
264 duplicate_inode(cache_inode, inode);
267 /* instantiate a file handle to the cache file */
268 static inline void duplicate_file(struct file *dst_file, struct file *src_file)
270 if (dst_file && src_file) {
271 dst_file->f_pos = src_file->f_pos;
272 dst_file->f_mode = src_file->f_mode;
273 dst_file->f_flags = src_file->f_flags;
274 dst_file->f_owner = src_file->f_owner;
275 dst_file->f_vfsmnt = src_file->f_vfsmnt;
277 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
278 dst_file->f_reada = src_file->f_reada;
279 dst_file->f_ramax = src_file->f_ramax;
280 dst_file->f_raend = src_file->f_raend;
281 dst_file->f_ralen = src_file->f_ralen;
282 dst_file->f_rawin = src_file->f_rawin;
284 dst_file->f_ra = src_file->f_ra;
289 static inline void duplicate_sb(struct super_block *dst_sb,
290 struct super_block *src_sb)
292 dst_sb->s_blocksize = src_sb->s_blocksize;
293 dst_sb->s_magic = src_sb->s_magic;
294 dst_sb->s_blocksize_bits = src_sb->s_blocksize_bits;
295 dst_sb->s_maxbytes = src_sb->s_maxbytes;
298 static inline void d_unalloc(struct dentry *dentry)
300 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
301 list_del(&dentry->d_hash);
302 INIT_LIST_HEAD(&dentry->d_hash);
304 hlist_del_init(&dentry->d_hash);
306 dput(dentry); /* this will free the dentry memory */
309 static inline struct dentry *pre_smfs_dentry(struct dentry *parent_dentry,
310 struct inode *cache_inode,
311 struct dentry *dentry)
313 struct dentry *cache_dentry = NULL;
315 cache_dentry = d_alloc(parent_dentry, &dentry->d_name);
319 cache_dentry->d_parent = cache_dentry;
321 d_add(cache_dentry, cache_inode);
322 RETURN(cache_dentry);
325 static inline void post_smfs_dentry(struct dentry *cache_dentry)
329 if (cache_dentry->d_inode)
330 igrab(cache_dentry->d_inode);
331 d_unalloc(cache_dentry);
334 static inline int lookup_by_path(char *path, int flags, struct nameidata *nd)
336 struct dentry *dentry = NULL;
339 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
340 if (path_init(path, flags, nd)) {
342 if (path_lookup(path, flags, nd)) {
344 rc = path_walk(path, nd);
353 if (!dentry->d_inode || is_bad_inode(dentry->d_inode)) {
360 /*FIXME there should be more conditions in this check*/
362 static inline int smfs_do_rec(struct inode *inode)
364 struct super_block *sb = inode->i_sb;
365 struct smfs_super_info *smfs_info = S2SMI(sb);
367 if (SMFS_DO_REC(smfs_info) && SMFS_INIT_REC(smfs_info) &&
368 SMFS_DO_INODE_REC(inode))
372 static inline int smfs_cache_hook(struct inode *inode)
374 struct smfs_super_info *smfs_info = I2CSB(inode);
376 if (SMFS_CACHE_HOOK(smfs_info) && SMFS_INIT_REC(smfs_info) &&
377 SMFS_INODE_CACHE_HOOK(inode))
382 /* XXX BUG 3188 -- must return to one set of opcodes */
383 #define SMFS_TRANS_OP(inode, op) \
385 if (smfs_do_rec(inode)) \
387 if (smfs_cache_hook(inode)) \
391 extern int smfs_start_rec(struct super_block *sb, struct vfsmount *mnt);
392 extern int smfs_stop_rec(struct super_block *sb);
393 extern int smfs_write_extents(struct inode *dir, struct dentry *dentry,
394 unsigned long from, unsigned long num);
395 extern int smfs_rec_setattr(struct inode *dir, struct dentry *dentry,
397 extern int smfs_rec_precreate(struct dentry *dentry, int *num, struct obdo *oa);
398 extern int smfs_rec_md(struct inode *inode, void * lmm, int lmm_size);
399 extern int smfs_rec_unpack(struct smfs_proc_args *args, char *record,
400 char **pbuf, int *opcode);
402 #endif /* _LUSTRE_SMFS_H */