Whamcloud - gitweb
1)do precreate record in obdfilter
[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 /*smfs rec*/
28 typedef int (*smfs_pack_rec_func)(char *buffer, struct dentry *dentry,
29                                   struct inode *dir, void *data1,
30                                   void *data2, int op);
31 typedef enum {
32         PACK_NORMAL = 0,
33         PACK_OST = 1,
34         PACK_MDS = 2,
35         PACK_MAX = 3,
36 } pack_func_t;
37
38 struct mds_kml_pack_info {
39         int mpi_bufcount;
40         int mpi_size[4];
41         int mpi_total_size;
42 };
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 */
59         __u32                     smsi_ops_check;
60 };
61
62 #define SMFS_FILE_TYPE "smfs"
63 #define SMFS_FILE_MAGIC        0x19760218
64
65 struct smfs_file_info {
66         struct file        *c_file;
67         int                 magic;
68 };
69
70 struct smfs_proc_args {
71         struct super_block *sr_sb;
72         int                 sr_count;
73         int                 sr_flags;
74         void               *sr_data;
75 };
76 struct fs_extent{
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 */
80 };
81
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)
86 #else
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)
89 #endif
90
91 #define I2CI(inode) (((struct smfs_inode_info*) (&(inode->u.generic_ip)))->smi_inode)
92
93 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
94 #define I2CSB(inode) ((struct smfs_super_info *) (&(inode->i_sb->u.generic_sbp)))
95 #else
96 #define I2CSB(inode) ((struct smfs_super_info *) (inode->i_sb->s_fs_info))
97 #endif
98
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)
102 #else
103 #define I2FOPS(inode) (((struct smfs_super_info *) \
104                         (inode->i_sb->s_fs_info))->sm_cache_fsfilt)
105 #endif
106
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))
111
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
117
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)
121
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)
125
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)
129
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)
133
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)
137
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)
141
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)
145
146
147 #define LVFS_SMFS_BACK_ATTR "lvfs_back_attr"
148
149
150 #define REC_COUNT_BIT       0
151 #define REC_COUNT_MASK      0x01 /*0001*/
152 #define REC_OP_BIT          1
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*/
160
161 #define REC_PACK_TYPE_BIT   6
162 #define REC_PACK_TYPE_MASK  0x1C0 /*111000000*/
163
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)
168
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)
173
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)
178
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)
183
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)
188
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)
193
194 #define SMFS_REC_ALL             0x1
195 #define SMFS_REC_BY_COUNT        0x0
196
197 #define SMFS_REINT_REC           0x1
198 #define SMFS_UNDO_REC            0x2
199
200 #define SMFS_WRITE_KML           0x1
201 #define SMFS_DEC_LINK            0x1
202 #define SMFS_GET_OID             0x1
203
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)
216
217 #define SMFS_DO_GET_OID(flag) \
218         (GET_REC_GET_OID_FLAGS(flag) == SMFS_GET_OID)
219
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
224
225
226 static inline void duplicate_inode(struct inode *dst_inode,
227                                    struct inode *src_inode)
228 {
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;
241
242         /* This is to make creating special files working. */
243         dst_inode->i_rdev = src_inode->i_rdev;
244 }
245
246 static inline void post_smfs_inode(struct inode *inode,
247                                    struct inode *cache_inode)
248 {
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
253                  *do it
254                  */
255                 cache_inode->i_state &=~I_LOCK;
256                 inode->i_blocks = cache_inode->i_blocks;
257         }
258 }
259
260 static inline void pre_smfs_inode(struct inode *inode,
261                                   struct inode *cache_inode)
262 {
263         if (inode && cache_inode)
264                 duplicate_inode(cache_inode, inode);
265 }
266
267 /* instantiate a file handle to the cache file */
268 static inline void duplicate_file(struct file *dst_file, struct file *src_file)
269 {
270         dst_file->f_pos = src_file->f_pos;
271         dst_file->f_mode = src_file->f_mode;
272         dst_file->f_flags = src_file->f_flags;
273         dst_file->f_owner  = src_file->f_owner;
274         dst_file->f_vfsmnt = src_file->f_vfsmnt;
275
276 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
277         dst_file->f_reada = src_file->f_reada;
278         dst_file->f_ramax = src_file->f_ramax;
279         dst_file->f_raend = src_file->f_raend;
280         dst_file->f_ralen = src_file->f_ralen;
281         dst_file->f_rawin = src_file->f_rawin;
282 #else
283         dst_file->f_ra = src_file->f_ra;
284 #endif
285 }
286
287 static inline void duplicate_sb(struct super_block *dst_sb,
288                                 struct super_block *src_sb)
289 {
290         dst_sb->s_blocksize = src_sb->s_blocksize;
291         dst_sb->s_magic = src_sb->s_magic;
292         dst_sb->s_blocksize_bits = src_sb->s_blocksize_bits;
293         dst_sb->s_maxbytes = src_sb->s_maxbytes;
294 }
295
296 static inline void d_unalloc(struct dentry *dentry)
297 {
298 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
299         list_del(&dentry->d_hash);
300         INIT_LIST_HEAD(&dentry->d_hash);
301 #else
302         hlist_del_init(&dentry->d_hash);
303 #endif
304         dput(dentry); /* this will free the dentry memory */
305 }
306
307 static inline struct dentry *pre_smfs_dentry(struct dentry *parent_dentry,
308                                              struct inode *cache_inode,
309                                              struct dentry *dentry)
310 {
311         struct dentry *cache_dentry = NULL;
312
313         cache_dentry = d_alloc(parent_dentry, &dentry->d_name);
314         if (!cache_dentry)
315                 RETURN(NULL);
316         if (!parent_dentry)
317                 cache_dentry->d_parent = cache_dentry;
318         if (cache_inode)
319                 d_add(cache_dentry, cache_inode);
320         RETURN(cache_dentry);
321 }
322
323 static inline void post_smfs_dentry(struct dentry *cache_dentry)
324 {
325         if (!cache_dentry)
326                 return;
327         if (cache_dentry->d_inode)
328                 igrab(cache_dentry->d_inode);
329         d_unalloc(cache_dentry);
330 }
331
332 static inline int lookup_by_path(char *path, int flags, struct nameidata *nd)
333 {
334         struct dentry *dentry = NULL;
335         int rc = 0;
336
337 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
338         if (path_init(path, flags, nd)) {
339 #else
340         if (path_lookup(path, flags, nd)) {
341 #endif
342                 rc = path_walk(path, nd);
343                 if (rc)
344                         RETURN(rc);
345         } else {
346                 RETURN(-EINVAL);
347         }
348
349         dentry = nd->dentry;
350
351         if (!dentry->d_inode || is_bad_inode(dentry->d_inode)) {
352                 path_release(nd);
353                 RETURN(-ENODEV);
354         }
355         RETURN(rc);
356 }
357
358 /*FIXME there should be more conditions in this check*/
359
360 static inline int smfs_do_rec(struct inode *inode)
361 {
362         struct super_block *sb = inode->i_sb;
363         struct smfs_super_info *smfs_info = S2SMI(sb);
364
365         if (SMFS_DO_REC(smfs_info) && SMFS_INIT_REC(smfs_info) &&
366             SMFS_DO_INODE_REC(inode))
367                 return 1;
368         return 0;
369 }
370 static inline int smfs_cache_hook(struct inode *inode)
371 {
372         struct smfs_super_info  *smfs_info = I2CSB(inode);
373
374         if (SMFS_CACHE_HOOK(smfs_info) && SMFS_INIT_REC(smfs_info) &&
375             SMFS_INODE_CACHE_HOOK(inode))
376                 return 1;
377         else
378                 return 0;
379 }
380 /* XXX BUG 3188 -- must return to one set of opcodes */
381 #define SMFS_TRANS_OP(inode, op)                \
382 {                                               \
383         if (smfs_do_rec(inode))                 \
384                 op = op | 0x10;                 \
385         if (smfs_cache_hook(inode))             \
386                 op = op | 0x20;                 \
387 }
388
389 extern int smfs_start_rec(struct super_block *sb, struct vfsmount *mnt);
390 extern int smfs_stop_rec(struct super_block *sb);
391 extern int smfs_write_extents(struct inode *dir, struct dentry *dentry,
392                               unsigned long from, unsigned long num);
393 extern int smfs_rec_setattr(struct inode *dir, struct dentry *dentry,
394                             struct iattr *attr);
395 extern int smfs_rec_precreate(struct dentry *dentry, int *num, struct obdo *oa);
396 extern int smfs_rec_md(struct inode *inode, void * lmm, int lmm_size);
397 extern int smfs_rec_unpack(struct smfs_proc_args *args, char *record,
398                            char **pbuf, int *opcode);
399
400 #endif /* _LUSTRE_SMFS_H */