Whamcloud - gitweb
landing smfs.
[fs/lustre-release.git] / lustre / include / linux / lustre_smfs.h
1 #ifndef __LUSTRE_SMFS_H
2 #define __LUSTRE_SMFS_H
3
4 struct smfs_inode_info {
5         struct inode *smi_inode;
6         __u32  smi_flags;
7 };
8
9 struct journal_operations {
10         void *(*tr_start)(struct inode *, int op);
11         void (*tr_commit)(void *handle);
12 };
13
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;
25 };
26
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
34                                                      * inode ops */
35
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 */
44         __u32                    ops_check;
45 };
46
47 #define SMFS_FILE_TYPE "smfs"
48 #define SMFS_FILE_MAGIC 0x19760218
49
50 struct smfs_file_info {
51         struct file     *c_file;
52         int             magic;
53 };
54
55 struct smfs_record_extents {
56         size_t  sre_count;
57         loff_t  sre_off; 
58 };
59
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)
64 #else
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)
67 #endif
68
69 #define I2CI(inode) (((struct smfs_inode_info*) (&(inode->u.generic_ip)))->smi_inode)
70
71 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
72 #define I2CSB(inode) ((struct smfs_super_info *) (&(inode->i_sb->u.generic_sbp)))
73 #else
74 #define I2CSB(inode) ((struct smfs_super_info *) (inode->i_sb->s_fs_info))
75 #endif
76
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)
80 #else
81 #define I2FOPS(inode) (((struct smfs_super_info *) \
82                         (inode->i_sb->s_fs_info))->sm_cache_fsfilt)
83 #endif
84
85 #define F2SMFI(file) ((struct smfs_file_info *)((file->private_data)))
86 #define F2CF(file) (((struct smfs_file_info *) ((file->private_data)))->c_file)
87
88 #define SM_DO_REC               0x1
89 #define SM_INIT_REC             0x2
90 #define SM_CACHE_HOOK           0x4
91
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)
95
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)
99
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)
103
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)
107
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)
111
112 #define LVFS_SMFS_BACK_ATTR "lvfs_back_attr"
113
114
115 #define REC_COUNT_BIT 0
116 #define REC_COUNT_MASK 0x01 /*0001*/
117 #define REC_OP_BIT  1
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*/
123
124
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)
129
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)
134
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)
139
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)
144
145 #define SMFS_REC_ALL            0x1
146 #define SMFS_REC_BY_COUNT       0x0
147
148 #define SMFS_REINT_REC          0x1
149 #define SMFS_UNDO_REC           0x2
150
151 #define SMFS_WRITE_KML          0x1
152
153 #define SMFS_DEC_LINK           0x1
154
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)
167
168 static inline void duplicate_inode(struct inode *dst_inode, 
169                                    struct inode *src_inode) 
170 {
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;
183
184         /* This is to make creating special files working. */
185         dst_inode->i_rdev = src_inode->i_rdev;
186 }
187
188 static inline void post_smfs_inode(struct inode *inode, 
189                                    struct inode *cache_inode)
190 {
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
195                  *do it
196                  */
197                 cache_inode->i_state &=~I_LOCK; 
198                 inode->i_blocks = cache_inode->i_blocks;
199         }
200 }
201
202 static inline void pre_smfs_inode(struct inode *inode,
203                                   struct inode *cache_inode)
204 {
205         if (inode && cache_inode)
206                 duplicate_inode(cache_inode, inode);
207 }
208
209 /* instantiate a file handle to the cache file */
210 static inline void duplicate_file(struct file *dst_file,
211                                   struct file *src_file) 
212 {
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;
218         
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;
225 #else
226         dst_file->f_ra = src_file->f_ra;
227 #endif
228 }
229
230 static inline void duplicate_sb(struct super_block *dst_sb, 
231                                 struct super_block *src_sb)
232 {
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;
237 }
238
239 static inline void d_unalloc(struct dentry *dentry)
240 {
241 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
242         list_del(&dentry->d_hash);
243         INIT_LIST_HEAD(&dentry->d_hash);
244 #else
245         hlist_del_init(&dentry->d_hash);
246 #endif
247         dput(dentry); /* this will free the dentry memory */
248 }
249
250 static inline struct dentry *pre_smfs_dentry(struct dentry *parent_dentry, 
251                                              struct inode *cache_inode,
252                                              struct dentry *dentry)
253 {
254         struct dentry *cache_dentry = NULL;
255
256         cache_dentry = d_alloc(parent_dentry, &dentry->d_name); 
257         if (!cache_dentry)
258                 RETURN(NULL);
259         if (!parent_dentry)
260                 cache_dentry->d_parent = cache_dentry;
261         if (cache_inode)
262                 d_add(cache_dentry, cache_inode);
263         RETURN(cache_dentry);
264 }
265
266 static inline void post_smfs_dentry(struct dentry *cache_dentry)
267 {
268         if (!cache_dentry)
269                 return;
270         if (cache_dentry->d_inode)
271                 igrab(cache_dentry->d_inode);
272         d_unalloc(cache_dentry);        
273 }
274 #endif /* _LUSTRE_SMFS_H */