1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001-2003 Cluster File Systems, Inc. <info@clusterfs.com>
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * smfs data structures.
22 * See also lustre_idl.h for wire formats of requests.
26 #ifndef __LUSTRE_SMFS_H
27 #define __LUSTRE_SMFS_H
29 #include <linux/namei.h>
30 struct snap_inode_info {
31 int sn_flags; /*the flags indicated inode type */
32 int sn_gen; /*the inode generation*/
33 int sn_index; /*the inode snap_index*/
34 ino_t sn_root_ino; /*the root ino of this snap*/
36 struct smfs_inode_info {
37 /* this first part of struct should be the same as in mds_info_info */
38 struct lustre_id smi_id;
41 struct inode *smi_inode;
43 struct snap_inode_info sm_sninfo;
46 struct journal_operations {
47 void *(*tr_start)(struct inode *, int op);
48 void (*tr_commit)(void *handle);
51 struct sm_operations {
52 /* operations on the file store */
53 struct super_operations sm_sb_ops;
54 struct inode_operations sm_dir_iops;
55 struct inode_operations sm_file_iops;
56 struct inode_operations sm_sym_iops;
57 struct file_operations sm_dir_fops;
58 struct file_operations sm_file_fops;
59 struct file_operations sm_sym_fops;
60 struct dentry_operations sm_dentry_ops;
61 struct journal_operations sm_journal_ops;
65 typedef int (*smfs_pack_rec_func)(char *buffer, struct dentry *dentry,
66 struct inode *dir, void *data1,
75 struct mds_kml_pack_info {
80 typedef int (*smfs_hook_func)(struct inode *inode, void *dentry,
81 void *data1, void *data2, int op, void *handle);
82 struct smfs_hook_ops {
83 struct list_head smh_list;
85 smfs_hook_func smh_post_op;
86 smfs_hook_func smh_pre_op;
88 struct smfs_super_info {
89 struct super_block *smsi_sb;
90 struct vfsmount *smsi_mnt; /* mount the cache kern */
91 struct fsfilt_operations *sm_cache_fsfilt; /* fsfilt operations */
92 struct fsfilt_operations *sm_fsfilt; /* fsfilt operations */
93 struct sm_operations *sm_ops; /* cache ops */
94 struct lvfs_run_ctxt *smsi_ctxt;
95 struct llog_ctxt *smsi_rec_log; /* smfs kml llog */
96 struct dentry *smsi_logs_dir;
97 struct dentry *smsi_objects_dir;
98 struct dentry *smsi_delete_dir; /* for delete inode dir */
99 char *smsi_cache_ftype; /* cache file system type */
100 char *smsi_ftype; /* file system type */
101 struct obd_export *smsi_exp; /* file system obd exp */
102 struct snap_super_info *smsi_snap_info; /* snap table cow */
103 smfs_pack_rec_func smsi_pack_rec[PACK_MAX]; /* sm_pack_rec type ops */
104 __u32 smsi_flags; /* flags */
105 __u32 smsi_ops_check;
106 struct list_head smsi_plg_list;
107 struct list_head smsi_hook_list;
108 kmem_cache_t * smsi_inode_cachep; /*inode_cachep*/
112 #define SMFS_FILE_TYPE "smfs"
113 #define SMFS_FILE_MAGIC 0x19760218
115 struct smfs_file_info {
120 struct smfs_proc_args {
121 struct super_block *sr_sb;
127 __u32 e_block; /* first logical block extent covers */
128 __u32 e_start; /* first physical block extents lives */
129 __u32 e_num; /* number of blocks covered by extent */
132 #define I2SMI(inode) ((struct smfs_inode_info *) ((inode->u.generic_ip)))
133 #define I2FSI(inode) (((inode->u.generic_ip)))
135 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
136 #define S2FSI(sb) (((sb->u.generic_sbp)))
137 #define S2SMI(sb) ((struct smfs_super_info *) ((sb->u.generic_sbp)))
138 #define S2CSB(sb) (((struct smfs_super_info *)((sb->u.generic_sbp)))->smsi_sb)
140 #define S2FSI(sb) ((sb->s_fs_info))
141 #define S2SMI(sb) ((struct smfs_super_info *) (sb->s_fs_info))
142 #define S2CSB(sb) (((struct smfs_super_info *) (sb->s_fs_info))->smsi_sb)
145 #define I2CI(inode) (((struct smfs_inode_info*) ((inode->u.generic_ip)))->smi_inode)
147 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
148 #define I2CSB(inode) ((struct smfs_super_info *) ((inode->i_sb->u.generic_sbp)))
150 #define I2CSB(inode) ((struct smfs_super_info *) (inode->i_sb->s_fs_info))
153 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
154 #define I2FOPS(inode) (((struct smfs_super_info *) \
155 ((inode->i_sb->u.generic_sbp)))->sm_cache_fsfilt)
157 #define I2FOPS(inode) (((struct smfs_super_info *) \
158 (inode->i_sb->s_fs_info))->sm_cache_fsfilt)
161 #define I2SNAPI(inode) (&(I2SMI(inode)->sm_sninfo))
162 #define I2SNAPCOPS(inode) ((S2SMI(inode->i_sb))->smsi_snap_info->snap_cache_fsfilt)
163 #define I2SNAPOPS(inode) ((S2SMI(inode->i_sb))->smsi_snap_info->snap_fsfilt)
165 #define S2SNAPI(sb) (S2SMI(sb)->smsi_snap_info)
166 #define F2SMFI(file) ((struct smfs_file_info *)((file->private_data)))
167 #define F2CF(file) (((struct smfs_file_info *) ((file->private_data)))->c_file)
168 #define SIZE2BLKS(size, inode) ((size + (I2CI(inode)->i_blksize)) >> (I2CI(inode)->i_blkbits))
169 #define OFF2BLKS(off, inode) (off >> (I2CI(inode)->i_blkbits))
171 #define SM_DO_REC 0x1
172 #define SM_INIT_REC 0x2
173 #define SM_CACHE_HOOK 0x4
174 #define SM_OVER_WRITE 0x8
175 #define SM_DIRTY_WRITE 0x10
176 #define SM_DO_COW 0x20
177 #define SM_DO_COWED 0x40
179 #define SMFS_DO_REC(smfs_info) (smfs_info->smsi_flags & SM_DO_REC)
180 #define SMFS_SET_REC(smfs_info) (smfs_info->smsi_flags |= SM_DO_REC)
181 #define SMFS_CLEAN_REC(smfs_info) (smfs_info->smsi_flags &= ~SM_DO_REC)
183 #define SMFS_INIT_REC(smfs_info) (smfs_info->smsi_flags & SM_INIT_REC)
184 #define SMFS_SET_INIT_REC(smfs_info) (smfs_info->smsi_flags |= SM_INIT_REC)
185 #define SMFS_CLEAN_INIT_REC(smfs_info) (smfs_info->smsi_flags &= ~SM_INIT_REC)
187 #define SMFS_SET_INODE_REC(inode) (I2SMI(inode)->smi_flags |= SM_DO_REC)
188 #define SMFS_DO_INODE_REC(inode) (I2SMI(inode)->smi_flags & SM_DO_REC)
189 #define SMFS_CLEAN_INODE_REC(inode) (I2SMI(inode)->smi_flags &= ~SM_DO_REC)
191 #define SMFS_CACHE_HOOK(smfs_info) (smfs_info->smsi_flags & SM_CACHE_HOOK)
192 #define SMFS_SET_CACHE_HOOK(smfs_info) (smfs_info->smsi_flags |= SM_CACHE_HOOK)
193 #define SMFS_CLEAN_CACHE_HOOK(smfs_info) (smfs_info->smsi_flags &= ~SM_CACHE_HOOK)
195 #define SMFS_INODE_CACHE_HOOK(inode) (I2SMI(inode)->smi_flags & SM_CACHE_HOOK)
196 #define SMFS_SET_INODE_CACHE_HOOK(inode) (I2SMI(inode)->smi_flags |= SM_CACHE_HOOK)
197 #define SMFS_CLEAN_INODE_CACHE_HOOK(inode) (I2SMI(inode)->smi_flags &= ~SM_CACHE_HOOK)
199 #define SMFS_INODE_OVER_WRITE(inode) (I2SMI(inode)->smi_flags & SM_OVER_WRITE)
200 #define SMFS_SET_INODE_OVER_WRITE(inode) (I2SMI(inode)->smi_flags |= SM_OVER_WRITE)
201 #define SMFS_CLEAN_INODE_OVER_WRITE(inode) (I2SMI(inode)->smi_flags &= ~SM_OVER_WRITE)
203 #define SMFS_INODE_DIRTY_WRITE(inode) (I2SMI(inode)->smi_flags & SM_DIRTY_WRITE)
204 #define SMFS_SET_INODE_DIRTY_WRITE(inode) (I2SMI(inode)->smi_flags |= SM_DIRTY_WRITE)
205 #define SMFS_CLEAN_INODE_DIRTY_WRITE(inode) (I2SMI(inode)->smi_flags &= ~SM_DIRTY_WRITE)
207 #define SMFS_DO_COW(smfs_info) (smfs_info->smsi_flags & SM_DO_COW)
208 #define SMFS_SET_COW(smfs_info) (smfs_info->smsi_flags |= SM_DO_COW)
209 #define SMFS_CLEAN_COW(smfs_info) (smfs_info->smsi_flags &= ~SM_DO_COW)
211 #define SMFS_SET_INODE_COW(inode) (I2SMI(inode)->smi_flags |= SM_DO_COW)
212 #define SMFS_DO_INODE_COW(inode) (I2SMI(inode)->smi_flags & SM_DO_COW)
213 #define SMFS_CLEAN_INODE_COW(inode) (I2SMI(inode)->smi_flags &= ~SM_DO_COW)
215 #define SMFS_SET_INODE_COWED(inode) (I2SMI(inode)->smi_flags |= SM_DO_COWED)
216 #define SMFS_DO_INODE_COWED(inode) (I2SMI(inode)->smi_flags & SM_DO_COWED)
217 #define SMFS_CLEAN_INODE_COWED(inode) (I2SMI(inode)->smi_flags &= ~SM_DO_COWED)
220 #define LVFS_SMFS_BACK_ATTR "lvfs_back_attr"
223 #define REC_COUNT_BIT 0
224 #define REC_COUNT_MASK 0x01 /*0001*/
226 #define REC_OP_MASK 0x06 /*0110*/
227 #define REC_WRITE_KML_BIT 3
228 #define REC_WRITE_KML_MASK 0x08 /*1000*/
229 #define REC_DEC_LINK_BIT 4
230 #define REC_DEC_LINK_MASK 0x10 /*10000* different with unlink*/
231 #define REC_GET_OID_BIT 5
232 #define REC_GET_OID_MASK 0x20 /*100000*/
234 #define REC_PACK_TYPE_BIT 6
235 #define REC_PACK_TYPE_MASK 0x1C0 /*111000000*/
237 #define SET_REC_COUNT_FLAGS(flag, count_flag) \
238 (flag |= count_flag << REC_COUNT_BIT)
239 #define GET_REC_COUNT_FLAGS(flag) \
240 ((flag & REC_COUNT_MASK) >> REC_COUNT_BIT)
242 #define SET_REC_OP_FLAGS(flag, op_flag) \
243 (flag |= op_flag << REC_OP_BIT)
244 #define GET_REC_OP_FLAGS(flag) \
245 ((flag & REC_OP_MASK) >> REC_OP_BIT)
247 #define SET_REC_WRITE_KML_FLAGS(flag, op_flag) \
248 (flag |= op_flag << REC_OP_BIT)
249 #define GET_REC_WRITE_KML_FLAGS(flag) \
250 ((flag & REC_WRITE_KML_MASK) >> REC_WRITE_KML_BIT)
252 #define SET_REC_DEC_LINK_FLAGS(flag, op_flag) \
253 (flag |= op_flag << REC_DEC_LINK_BIT)
254 #define GET_REC_DEC_LINK_FLAGS(flag) \
255 ((flag & REC_DEC_LINK_MASK) >> REC_DEC_LINK_BIT)
257 #define SET_REC_GET_ID_FLAGS(flag, op_flag) \
258 (flag |= op_flag << REC_GET_OID_BIT)
259 #define GET_REC_GET_OID_FLAGS(flag) \
260 ((flag & REC_GET_OID_MASK) >> REC_GET_OID_BIT)
262 #define SET_REC_PACK_TYPE_INDEX(flag, op_flag) \
263 (flag |= op_flag << REC_PACK_TYPE_BIT)
264 #define GET_REC_PACK_TYPE_INDEX(flag) \
265 ((flag & REC_PACK_TYPE_MASK) >> REC_PACK_TYPE_BIT)
267 #define SMFS_REC_ALL 0x1
268 #define SMFS_REC_BY_COUNT 0x0
270 #define SMFS_REINT_REC 0x1
271 #define SMFS_UNDO_REC 0x2
273 #define SMFS_WRITE_KML 0x1
274 #define SMFS_DEC_LINK 0x1
275 #define SMFS_GET_OID 0x1
277 #define SMFS_DO_REINT_REC(flag) \
278 (GET_REC_OP_FLAGS(flag) == SMFS_REINT_REC)
279 #define SMFS_DO_UNDO_REC(flag) \
280 (GET_REC_OP_FLAGS(flag) == SMFS_UNDO_REC)
281 #define SMFS_DO_REC_ALL(flag) \
282 (GET_REC_COUNT_FLAGS(flag) == SMFS_REC_ALL)
283 #define SMFS_DO_REC_BY_COUNT(flag) \
284 (GET_REC_COUNT_FLAGS(flag) == SMFS_REC_BY_COUNT)
285 #define SMFS_DO_WRITE_KML(flag) \
286 (GET_REC_WRITE_KML_FLAGS(flag) == SMFS_WRITE_KML)
287 #define SMFS_DO_DEC_LINK(flag) \
288 (GET_REC_DEC_LINK_FLAGS(flag) == SMFS_DEC_LINK)
290 #define SMFS_DO_GET_OID(flag) \
291 (GET_REC_GET_OID_FLAGS(flag) == SMFS_GET_OID)
293 /*DIRTY flags of write ops*/
294 #define REINT_EXTENTS_FLAGS "replay_flags"
295 #define SMFS_DIRTY_WRITE 0x01
296 #define SMFS_OVER_WRITE 0x02
299 static inline void duplicate_inode(struct inode *dst_inode,
300 struct inode *src_inode)
302 dst_inode->i_mode = src_inode->i_mode;
303 dst_inode->i_uid = src_inode->i_uid;
304 dst_inode->i_gid = src_inode->i_gid;
305 dst_inode->i_nlink = src_inode->i_nlink;
306 dst_inode->i_size = src_inode->i_size;
307 dst_inode->i_atime = src_inode->i_atime;
308 dst_inode->i_ctime = src_inode->i_ctime;
309 dst_inode->i_mtime = src_inode->i_mtime;
310 dst_inode->i_blksize = src_inode->i_blksize;
311 dst_inode->i_version = src_inode->i_version;
312 //dst_inode->i_state = src_inode->i_state;
313 dst_inode->i_generation = src_inode->i_generation;
314 dst_inode->i_flags = src_inode->i_flags;
316 /* This is to make creating special files working. */
317 dst_inode->i_rdev = src_inode->i_rdev;
320 static inline void post_smfs_inode(struct inode *inode,
321 struct inode *cache_inode)
323 if (inode && cache_inode) {
324 duplicate_inode(inode, cache_inode);
327 * here we must release the cache_inode, otherwise we will have
328 * no chance to do it later.
330 //cache_inode->i_state &=~I_LOCK;
331 inode->i_blocks = cache_inode->i_blocks;
335 static inline void pre_smfs_inode(struct inode *inode,
336 struct inode *cache_inode)
338 //if (inode && cache_inode) {
339 //cache_inode->i_state = inode->i_state;
343 /* instantiate a file handle to the cache file */
344 static inline void duplicate_file(struct file *dst_file, struct file *src_file)
346 if (dst_file && src_file) {
347 dst_file->f_pos = src_file->f_pos;
348 dst_file->f_mode = src_file->f_mode;
349 dst_file->f_flags = src_file->f_flags;
350 dst_file->f_owner = src_file->f_owner;
351 dst_file->f_vfsmnt = src_file->f_vfsmnt;
353 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
354 dst_file->f_reada = src_file->f_reada;
355 dst_file->f_ramax = src_file->f_ramax;
356 dst_file->f_raend = src_file->f_raend;
357 dst_file->f_ralen = src_file->f_ralen;
358 dst_file->f_rawin = src_file->f_rawin;
360 dst_file->f_ra = src_file->f_ra;
365 static inline void duplicate_sb(struct super_block *dst_sb,
366 struct super_block *src_sb)
368 dst_sb->s_blocksize = src_sb->s_blocksize;
369 dst_sb->s_magic = src_sb->s_magic;
370 dst_sb->s_blocksize_bits = src_sb->s_blocksize_bits;
371 dst_sb->s_maxbytes = src_sb->s_maxbytes;
372 dst_sb->s_flags = src_sb->s_flags;
375 static inline int smfs_get_dentry_name_index(struct dentry *dentry,
379 char *name = (char *)dentry->d_name.name;
383 int len = 0, name_len = 0;
385 name_len = dentry->d_name.len;
388 hash = init_name_hash();
390 c = *(const unsigned char *)name++;
391 if (c == ':' || c == '\0')
393 hash = partial_name_hash(c, hash);
396 str->hash = end_name_hash(hash);
397 OBD_ALLOC(str_name, len + 1);
398 memcpy(str_name, dentry->d_name.name, len);
400 str->name = str_name;
401 if (index && c == ':') {
402 *index = simple_strtoul(name, 0, 0);
407 static inline void smfs_free_dentry_name(struct qstr *str)
409 char *name = (char*)str->name;
410 OBD_FREE(name, str->len + 1);
413 static int smfs_d_delete(struct dentry * dentry)
418 static inline void d_unalloc(struct dentry *dentry)
420 struct dentry_operations dop = {
421 .d_delete = smfs_d_delete,
423 //this will invoke unhash and kill for dentry
425 dput(dentry); /* this will free the dentry memory */
428 static inline struct dentry *pre_smfs_dentry(struct dentry *parent_dentry,
429 struct inode *cache_inode,
430 struct dentry *dentry)
432 struct dentry *cache_dentry = NULL;
435 if (!parent_dentry) {
436 cache_dentry = d_find_alias(cache_inode);
438 RETURN(cache_dentry);
441 cache_dentry = d_alloc(parent_dentry, &dentry->d_name);
446 cache_dentry->d_parent = cache_dentry;
449 atomic_inc(&cache_inode->i_count); //d_instantiate suppose that
450 d_add(cache_dentry, cache_inode);
453 RETURN(cache_dentry);
456 static inline void post_smfs_dentry(struct dentry *cache_dentry)
459 d_unalloc(cache_dentry);
463 /*FIXME there should be more conditions in this check*/
464 static inline int smfs_do_rec(struct inode *inode)
466 struct super_block *sb = inode->i_sb;
467 struct smfs_super_info *smfs_info = S2SMI(sb);
469 if (SMFS_DO_REC(smfs_info) && SMFS_INIT_REC(smfs_info) &&
470 SMFS_DO_INODE_REC(inode))
475 static inline int smfs_cache_hook(struct inode *inode)
477 struct smfs_super_info *smfs_info = I2CSB(inode);
479 if (SMFS_CACHE_HOOK(smfs_info) && SMFS_INIT_REC(smfs_info) &&
480 SMFS_INODE_CACHE_HOOK(inode))
486 static inline int smfs_do_cow(struct inode *inode)
488 struct super_block *sb = inode->i_sb;
489 struct smfs_super_info *smfs_info = S2SMI(sb);
491 if (SMFS_DO_COW(smfs_info) && SMFS_DO_INODE_COW(inode))
497 /* XXX BUG 3188 -- must return to one set of opcodes */
498 #define SMFS_TRANS_OP(inode, op) \
500 if (smfs_do_rec(inode)) \
502 if (smfs_cache_hook(inode)) \
506 extern int smfs_start_rec(struct super_block *sb, struct vfsmount *mnt);
507 extern int smfs_stop_rec(struct super_block *sb);
508 extern int smfs_write_extents(struct inode *dir, struct dentry *dentry,
509 unsigned long from, unsigned long num);
510 extern int smfs_rec_setattr(struct inode *dir, struct dentry *dentry,
512 extern int smfs_rec_precreate(struct dentry *dentry, int *num, struct obdo *oa);
513 extern int smfs_rec_md(struct inode *inode, void * lmm, int lmm_size);
514 extern int smfs_rec_unpack(struct smfs_proc_args *args, char *record,
515 char **pbuf, int *opcode);
518 extern int smfs_post_setup(struct super_block *sb, struct vfsmount *mnt);
519 extern int smfs_post_cleanup(struct super_block *sb);
520 extern struct inode *smfs_get_inode (struct super_block *sb, ino_t hash,
521 struct inode *dir, int index);
523 extern int is_smfs_sb(struct super_block *sb);
524 #endif /* _LUSTRE_SMFS_H */