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;
27 struct smfs_super_info {
28 struct super_block *smsi_sb;
29 struct vfsmount *smsi_mnt; /* mount the cache kern with
30 * kern_do_mount (like MDS) */
31 struct fsfilt_operations *sm_cache_fsfilt; /* fsfilt operations */
32 struct fsfilt_operations *sm_fsfilt; /* fsfilt operations */
33 struct sm_operations *sm_ops; /* cache ops for set cache
36 struct lvfs_run_ctxt *smsi_ctxt;
37 struct llog_ctxt *smsi_rec_log; /* smfs kml llog */
38 struct dentry *smsi_logs_dir;
39 struct dentry *smsi_objects_dir;
40 struct dentry *smsi_delete_dir; /* for delete inode dir */
41 char *cache_fs_type; /* cache file system type */
42 char *fs_type; /* file system type */
43 __u32 flags; /* flags */
47 #define SMFS_FILE_TYPE "smfs"
48 #define SMFS_FILE_MAGIC 0x19760218
50 struct smfs_file_info {
55 struct smfs_record_extents {
60 #define I2SMI(inode) ((struct smfs_inode_info *) (&(inode->u.generic_ip)))
61 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
62 #define S2SMI(sb) ((struct smfs_super_info *) (&(sb->u.generic_sbp)))
63 #define S2CSB(sb) (((struct smfs_super_info *) (&(sb->u.generic_sbp)))->smsi_sb)
65 #define S2SMI(sb) ((struct smfs_super_info *) (sb->s_fs_info))
66 #define S2CSB(sb) (((struct smfs_super_info *) (sb->s_fs_info))->smsi_sb)
69 #define I2CI(inode) (((struct smfs_inode_info*) (&(inode->u.generic_ip)))->smi_inode)
71 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
72 #define I2CSB(inode) ((struct smfs_super_info *) (&(inode->i_sb->u.generic_sbp)))
74 #define I2CSB(inode) ((struct smfs_super_info *) (inode->i_sb->s_fs_info))
77 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
78 #define I2FOPS(inode) (((struct smfs_super_info *) \
79 (&(inode->i_sb->u.generic_sbp)))->sm_cache_fsfilt)
81 #define I2FOPS(inode) (((struct smfs_super_info *) \
82 (inode->i_sb->s_fs_info))->sm_cache_fsfilt)
85 #define F2SMFI(file) ((struct smfs_file_info *)((file->private_data)))
86 #define F2CF(file) (((struct smfs_file_info *) ((file->private_data)))->c_file)
89 #define SM_INIT_REC 0x2
90 #define SM_CACHE_HOOK 0x4
92 #define SMFS_DO_REC(smfs_info) (smfs_info->flags & SM_DO_REC)
93 #define SMFS_SET_REC(smfs_info) (smfs_info->flags |= SM_DO_REC)
94 #define SMFS_CLEAN_REC(smfs_info) (smfs_info->flags &= ~SM_DO_REC)
96 #define SMFS_INIT_REC(smfs_info) (smfs_info->flags & SM_INIT_REC)
97 #define SMFS_SET_INIT_REC(smfs_info) (smfs_info->flags |= SM_INIT_REC)
98 #define SMFS_CLEAN_INIT_REC(smfs_info) (smfs_info->flags &= ~SM_INIT_REC)
100 #define SMFS_SET_INODE_REC(inode) (I2SMI(inode)->smi_flags |= SM_DO_REC)
101 #define SMFS_DO_INODE_REC(inode) (I2SMI(inode)->smi_flags & SM_DO_REC)
102 #define SMFS_CLEAN_INODE_REC(inode) (I2SMI(inode)->smi_flags &= ~SM_DO_REC)
104 #define SMFS_CACHE_HOOK(smfs_info) (smfs_info->flags & SM_CACHE_HOOK)
105 #define SMFS_SET_CACHE_HOOK(smfs_info) (smfs_info->flags |= SM_CACHE_HOOK)
106 #define SMFS_CLEAN_CACHE_HOOK(smfs_info) (smfs_info->flags &= ~SM_CACHE_HOOK)
108 #define SMFS_INODE_CACHE_HOOK(inode) (I2SMI(inode)->smi_flags & SM_CACHE_HOOK)
109 #define SMFS_SET_INODE_CACHE_HOOK(inode) (I2SMI(inode)->smi_flags |= SM_CACHE_HOOK)
110 #define SMFS_CLEAN_INODE_CACHE_HOOK(inode) (I2SMI(inode)->smi_flags &= ~SM_CACHE_HOOK)
112 #define LVFS_SMFS_BACK_ATTR "lvfs_back_attr"
115 #define REC_COUNT_BIT 0
116 #define REC_COUNT_MASK 0x01 /*0001*/
118 #define REC_OP_MASK 0x06 /*0110*/
119 #define REC_WRITE_KML_BIT 3
120 #define REC_WRITE_KML_MASK 0x08 /*1000*/
121 #define REC_DEC_LINK_BIT 4
122 #define REC_DEC_LINK_MASK 0x10 /*10000* different with unlink*/
125 #define SET_REC_COUNT_FLAGS(flag, count_flag) \
126 (flag |= count_flag << REC_COUNT_BIT)
127 #define GET_REC_COUNT_FLAGS(flag) \
128 ((flag & REC_COUNT_MASK) >> REC_COUNT_BIT)
130 #define SET_REC_OP_FLAGS(flag, op_flag) \
131 (flag |= op_flag << REC_OP_BIT)
132 #define GET_REC_OP_FLAGS(flag) \
133 ((flag & REC_OP_MASK) >> REC_OP_BIT)
135 #define SET_REC_WRITE_KML_FLAGS(flag, op_flag) \
136 (flag |= op_flag << REC_OP_BIT)
137 #define GET_REC_WRITE_KML_FLAGS(flag) \
138 ((flag & REC_WRITE_KML_MASK) >> REC_WRITE_KML_BIT)
140 #define SET_REC_DEC_LINK_FLAGS(flag, op_flag) \
141 (flag |= op_flag << REC_DEC_LINK_BIT)
142 #define GET_REC_DEC_LINK_FLAGS(flag) \
143 ((flag & REC_DEC_LINK_MASK) >> REC_DEC_LINK_BIT)
145 #define SMFS_REC_ALL 0x1
146 #define SMFS_REC_BY_COUNT 0x0
148 #define SMFS_REINT_REC 0x1
149 #define SMFS_UNDO_REC 0x2
151 #define SMFS_WRITE_KML 0x1
153 #define SMFS_DEC_LINK 0x1
155 #define SMFS_DO_REINT_REC(flag) \
156 (GET_REC_OP_FLAGS(flag) == SMFS_REINT_REC)
157 #define SMFS_DO_UNDO_REC(flag) \
158 (GET_REC_OP_FLAGS(flag) == SMFS_UNDO_REC)
159 #define SMFS_DO_REC_ALL(flag) \
160 (GET_REC_COUNT_FLAGS(flag) == SMFS_REC_ALL)
161 #define SMFS_DO_REC_BY_COUNT(flag) \
162 (GET_REC_COUNT_FLAGS(flag) == SMFS_REC_BY_COUNT)
163 #define SMFS_DO_WRITE_KML(flag) \
164 (GET_REC_WRITE_KML_FLAGS(flag) == SMFS_WRITE_KML)
165 #define SMFS_DO_DEC_LINK(flag) \
166 (GET_REC_DEC_LINK_FLAGS(flag) == SMFS_DEC_LINK)
168 static inline void duplicate_inode(struct inode *dst_inode,
169 struct inode *src_inode)
171 dst_inode->i_mode = src_inode->i_mode;
172 dst_inode->i_uid = src_inode->i_uid;
173 dst_inode->i_gid = src_inode->i_gid;
174 dst_inode->i_nlink = src_inode->i_nlink;
175 dst_inode->i_size = src_inode->i_size;
176 dst_inode->i_atime = src_inode->i_atime;
177 dst_inode->i_ctime = src_inode->i_ctime;
178 dst_inode->i_mtime = src_inode->i_mtime;
179 dst_inode->i_blksize = src_inode->i_blksize;
180 dst_inode->i_version = src_inode->i_version;
181 dst_inode->i_state = src_inode->i_state;
182 dst_inode->i_generation = src_inode->i_generation;
184 /* This is to make creating special files working. */
185 dst_inode->i_rdev = src_inode->i_rdev;
188 static inline void post_smfs_inode(struct inode *inode,
189 struct inode *cache_inode)
191 if (inode && cache_inode) {
192 duplicate_inode(inode, cache_inode);
193 /*Here we must release the cache_inode,
194 *Otherwise we will have no chance to
197 cache_inode->i_state &=~I_LOCK;
198 inode->i_blocks = cache_inode->i_blocks;
202 static inline void pre_smfs_inode(struct inode *inode,
203 struct inode *cache_inode)
205 if (inode && cache_inode)
206 duplicate_inode(cache_inode, inode);
209 /* instantiate a file handle to the cache file */
210 static inline void duplicate_file(struct file *dst_file,
211 struct file *src_file)
213 dst_file->f_pos = src_file->f_pos;
214 dst_file->f_mode = src_file->f_mode;
215 dst_file->f_flags = src_file->f_flags;
216 dst_file->f_owner = src_file->f_owner;
217 dst_file->f_vfsmnt = src_file->f_vfsmnt;
219 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
220 dst_file->f_reada = src_file->f_reada;
221 dst_file->f_ramax = src_file->f_ramax;
222 dst_file->f_raend = src_file->f_raend;
223 dst_file->f_ralen = src_file->f_ralen;
224 dst_file->f_rawin = src_file->f_rawin;
226 dst_file->f_ra = src_file->f_ra;
230 static inline void duplicate_sb(struct super_block *dst_sb,
231 struct super_block *src_sb)
233 dst_sb->s_blocksize = src_sb->s_blocksize;
234 dst_sb->s_magic = src_sb->s_magic;
235 dst_sb->s_blocksize_bits = src_sb->s_blocksize_bits;
236 dst_sb->s_maxbytes = src_sb->s_maxbytes;
239 static inline void d_unalloc(struct dentry *dentry)
241 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
242 list_del(&dentry->d_hash);
243 INIT_LIST_HEAD(&dentry->d_hash);
245 hlist_del_init(&dentry->d_hash);
247 dput(dentry); /* this will free the dentry memory */
250 static inline struct dentry *pre_smfs_dentry(struct dentry *parent_dentry,
251 struct inode *cache_inode,
252 struct dentry *dentry)
254 struct dentry *cache_dentry = NULL;
256 cache_dentry = d_alloc(parent_dentry, &dentry->d_name);
260 cache_dentry->d_parent = cache_dentry;
262 d_add(cache_dentry, cache_inode);
263 RETURN(cache_dentry);
266 static inline void post_smfs_dentry(struct dentry *cache_dentry)
270 if (cache_dentry->d_inode)
271 igrab(cache_dentry->d_inode);
272 d_unalloc(cache_dentry);
274 #endif /* _LUSTRE_SMFS_H */