Whamcloud - gitweb
- landing of b_fid after merge with b_hd_cleanup_merge.
[fs/lustre-release.git] / lustre / include / linux / lustre_smfs.h
index ba33548..b6fd845 100644 (file)
@@ -1,9 +1,45 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
+ *  Copyright (C) 2001-2003 Cluster File Systems, Inc. <info@clusterfs.com>
+ *
+ *   This file is part of Lustre, http://www.lustre.org.
+ *
+ *   Lustre is free software; you can redistribute it and/or
+ *   modify it under the terms of version 2 of the GNU General Public
+ *   License as published by the Free Software Foundation.
+ *
+ *   Lustre is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Lustre; if not, write to the Free Software
+ *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *   smfs data structures.
+ *   See also lustre_idl.h for wire formats of requests.
+ *
+ */
+
 #ifndef __LUSTRE_SMFS_H
 #define __LUSTRE_SMFS_H
 
+struct snap_inode_info {
+       int sn_flags;           /*the flags indicated inode type */
+       int sn_gen;             /*the inode generation*/
+        int sn_index;           /*the inode snap_index*/
+        ino_t sn_root_ino;        /*the root ino of this snap*/
+};
 struct smfs_inode_info {
+        /* this first part of struct should be the same as in mds_info_info */
+        struct lustre_id smi_id;
+        
+        /* smfs part. */
         struct inode *smi_inode;
         __u32  smi_flags;
+       struct snap_inode_info sm_sninfo;
 };
 
 struct journal_operations {
@@ -40,6 +76,14 @@ struct mds_kml_pack_info {
         int mpi_size[4];
         int mpi_total_size;
 };
+typedef int (*smfs_hook_func)(struct inode *inode, void *dentry,
+                             void *data1, void *data2, int op, void *handle);
+struct smfs_hook_ops {
+        struct list_head smh_list;
+        char *           smh_name;
+        smfs_hook_func   smh_post_op;
+        smfs_hook_func   smh_pre_op;
+};
 struct smfs_super_info {
         struct super_block       *smsi_sb;
         struct vfsmount          *smsi_mnt;         /* mount the cache kern */
@@ -54,12 +98,16 @@ struct smfs_super_info {
         char                     *smsi_cache_ftype; /* cache file system type */
         char                     *smsi_ftype;       /* file system type */
        struct obd_export        *smsi_exp;         /* file system obd exp */
-        smfs_pack_rec_func   smsi_pack_rec[PACK_MAX]; /* sm_pack_rec type ops */
-        __u32                     smsi_flags;       /* flags */
-        __u32                     smsi_ops_check;
+       struct snap_super_info   *smsi_snap_info;   /* snap table cow */
+        smfs_pack_rec_func      smsi_pack_rec[PACK_MAX]; /* sm_pack_rec type ops */
+        __u32                    smsi_flags;        /* flags */
+        __u32                    smsi_ops_check;
+        struct list_head         smsi_hook_list;
+        kmem_cache_t *           smsi_inode_cachep;  /*inode_cachep*/
 };
 
-#define SMFS_FILE_TYPE "smfs"
+
+#define SMFS_FILE_TYPE         "smfs"
 #define SMFS_FILE_MAGIC        0x19760218
 
 struct smfs_file_info {
@@ -79,31 +127,40 @@ struct fs_extent{
         __u32   e_num;          /* number of blocks covered by extent */
 };
 
-#define I2SMI(inode)  ((struct smfs_inode_info *) (&(inode->u.generic_ip)))
+#define I2SMI(inode)  ((struct smfs_inode_info *) ((inode->u.generic_ip)))
+#define I2FSI(inode)  (((inode->u.generic_ip)))
+
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
-#define S2SMI(sb)   ((struct smfs_super_info *) (&(sb->u.generic_sbp)))
-#define S2CSB(sb)   (((struct smfs_super_info *) (&(sb->u.generic_sbp)))->smsi_sb)
+#define S2FSI(sb)   (((sb->u.generic_sbp)))
+#define S2SMI(sb)   ((struct smfs_super_info *) ((sb->u.generic_sbp)))
+#define S2CSB(sb)   (((struct smfs_super_info *)((sb->u.generic_sbp)))->smsi_sb)
 #else
+#define S2FSI(sb)   ((sb->s_fs_info))
 #define S2SMI(sb)   ((struct smfs_super_info *) (sb->s_fs_info))
 #define S2CSB(sb)   (((struct smfs_super_info *) (sb->s_fs_info))->smsi_sb)
 #endif
 
-#define I2CI(inode) (((struct smfs_inode_info*) (&(inode->u.generic_ip)))->smi_inode)
+#define I2CI(inode) (((struct smfs_inode_info*) ((inode->u.generic_ip)))->smi_inode)
 
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
-#define I2CSB(inode) ((struct smfs_super_info *) (&(inode->i_sb->u.generic_sbp)))
+#define I2CSB(inode) ((struct smfs_super_info *) ((inode->i_sb->u.generic_sbp)))
 #else
 #define I2CSB(inode) ((struct smfs_super_info *) (inode->i_sb->s_fs_info))
 #endif
 
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
 #define I2FOPS(inode) (((struct smfs_super_info *) \
-                        (&(inode->i_sb->u.generic_sbp)))->sm_cache_fsfilt)
+                        ((inode->i_sb->u.generic_sbp)))->sm_cache_fsfilt)
 #else
 #define I2FOPS(inode) (((struct smfs_super_info *) \
                         (inode->i_sb->s_fs_info))->sm_cache_fsfilt)
 #endif
 
+#define I2SNAPI(inode) (&(I2SMI(inode)->sm_sninfo))
+#define I2SNAPCOPS(inode) ((S2SMI(inode->i_sb))->smsi_snap_info->snap_cache_fsfilt) 
+#define I2SNAPOPS(inode) ((S2SMI(inode->i_sb))->smsi_snap_info->snap_fsfilt) 
+
+#define S2SNAPI(sb) (S2SMI(sb)->smsi_snap_info)
 #define F2SMFI(file) ((struct smfs_file_info *)((file->private_data)))
 #define F2CF(file) (((struct smfs_file_info *) ((file->private_data)))->c_file)
 #define SIZE2BLKS(size, inode) ((size + (I2CI(inode)->i_blksize)) >> (I2CI(inode)->i_blkbits))
@@ -113,7 +170,9 @@ struct fs_extent{
 #define SM_INIT_REC             0x2
 #define SM_CACHE_HOOK           0x4
 #define SM_OVER_WRITE           0x8
-#define SM_DIRTY_WRITE         0x10
+#define SM_DIRTY_WRITE          0x10
+#define SM_DO_COW              0x20
+#define SM_DO_COWED            0x40
 
 #define SMFS_DO_REC(smfs_info) (smfs_info->smsi_flags & SM_DO_REC)
 #define SMFS_SET_REC(smfs_info) (smfs_info->smsi_flags |= SM_DO_REC)
@@ -143,6 +202,18 @@ struct fs_extent{
 #define SMFS_SET_INODE_DIRTY_WRITE(inode) (I2SMI(inode)->smi_flags |= SM_DIRTY_WRITE)
 #define SMFS_CLEAN_INODE_DIRTY_WRITE(inode) (I2SMI(inode)->smi_flags &= ~SM_DIRTY_WRITE)
 
+#define SMFS_DO_COW(smfs_info) (smfs_info->smsi_flags & SM_DO_COW)
+#define SMFS_SET_COW(smfs_info) (smfs_info->smsi_flags |= SM_DO_COW)
+#define SMFS_CLEAN_COW(smfs_info) (smfs_info->smsi_flags &= ~SM_DO_COW)
+
+#define SMFS_SET_INODE_COW(inode) (I2SMI(inode)->smi_flags |= SM_DO_COW)
+#define SMFS_DO_INODE_COW(inode) (I2SMI(inode)->smi_flags & SM_DO_COW)
+#define SMFS_CLEAN_INODE_COW(inode) (I2SMI(inode)->smi_flags &= ~SM_DO_COW)
+
+#define SMFS_SET_INODE_COWED(inode) (I2SMI(inode)->smi_flags |= SM_DO_COWED)
+#define SMFS_DO_INODE_COWED(inode) (I2SMI(inode)->smi_flags & SM_DO_COWED)
+#define SMFS_CLEAN_INODE_COWED(inode) (I2SMI(inode)->smi_flags &= ~SM_DO_COWED)
+
 
 #define LVFS_SMFS_BACK_ATTR "lvfs_back_attr"
 
@@ -238,6 +309,7 @@ static inline void duplicate_inode(struct inode *dst_inode,
         dst_inode->i_version = src_inode->i_version;
         dst_inode->i_state = src_inode->i_state;
         dst_inode->i_generation = src_inode->i_generation;
+        dst_inode->i_flags = src_inode->i_flags;
 
         /* This is to make creating special files working. */
         dst_inode->i_rdev = src_inode->i_rdev;
@@ -248,9 +320,10 @@ static inline void post_smfs_inode(struct inode *inode,
 {
         if (inode && cache_inode) {
                 duplicate_inode(inode, cache_inode);
-                /*Here we must release the cache_inode,
-                 *Otherwise we will have no chance to
-                 *do it
+                
+                /*
+                 * here we must release the cache_inode, otherwise we will have
+                 * no chance to do it later.
                  */
                 cache_inode->i_state &=~I_LOCK;
                 inode->i_blocks = cache_inode->i_blocks;
@@ -260,28 +333,32 @@ static inline void post_smfs_inode(struct inode *inode,
 static inline void pre_smfs_inode(struct inode *inode,
                                   struct inode *cache_inode)
 {
-        if (inode && cache_inode)
-                duplicate_inode(cache_inode, inode);
+        if (inode && cache_inode) {
+                cache_inode->i_state = inode->i_state;
+        //      duplicate_inode(cache_inode, inode);
+        }
 }
 
 /* instantiate a file handle to the cache file */
 static inline void duplicate_file(struct file *dst_file, struct file *src_file)
 {
-        dst_file->f_pos = src_file->f_pos;
-        dst_file->f_mode = src_file->f_mode;
-        dst_file->f_flags = src_file->f_flags;
-        dst_file->f_owner  = src_file->f_owner;
-        dst_file->f_vfsmnt = src_file->f_vfsmnt;
-
-#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
-        dst_file->f_reada = src_file->f_reada;
-        dst_file->f_ramax = src_file->f_ramax;
-        dst_file->f_raend = src_file->f_raend;
-        dst_file->f_ralen = src_file->f_ralen;
-        dst_file->f_rawin = src_file->f_rawin;
-#else
-        dst_file->f_ra = src_file->f_ra;
-#endif
+       if (dst_file && src_file) {
+               dst_file->f_pos = src_file->f_pos;
+               dst_file->f_mode = src_file->f_mode;
+               dst_file->f_flags = src_file->f_flags;
+               dst_file->f_owner  = src_file->f_owner;
+               dst_file->f_vfsmnt = src_file->f_vfsmnt;
+
+       #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+               dst_file->f_reada = src_file->f_reada;
+               dst_file->f_ramax = src_file->f_ramax;
+               dst_file->f_raend = src_file->f_raend;
+               dst_file->f_ralen = src_file->f_ralen;
+               dst_file->f_rawin = src_file->f_rawin;
+       #else
+               dst_file->f_ra = src_file->f_ra;
+       #endif
+       }
 }
 
 static inline void duplicate_sb(struct super_block *dst_sb,
@@ -291,6 +368,7 @@ static inline void duplicate_sb(struct super_block *dst_sb,
         dst_sb->s_magic = src_sb->s_magic;
         dst_sb->s_blocksize_bits = src_sb->s_blocksize_bits;
         dst_sb->s_maxbytes = src_sb->s_maxbytes;
+        dst_sb->s_flags = src_sb->s_flags;
 }
 
 static inline void d_unalloc(struct dentry *dentry)
@@ -300,16 +378,55 @@ static inline void d_unalloc(struct dentry *dentry)
         INIT_LIST_HEAD(&dentry->d_hash);
 #else
         hlist_del_init(&dentry->d_hash);
+        dentry->d_flags |= DCACHE_UNHASHED;
 #endif
         dput(dentry); /* this will free the dentry memory */
 }
 
+static inline int smfs_get_dentry_name_index(struct dentry *dentry,
+                                             struct qstr  *str,
+                                             int *index)
+{
+        char *name = (char *)dentry->d_name.name;
+        unsigned long hash;
+        unsigned char c;
+        char *str_name;
+        int len = 0, name_len = 0;
+
+        name_len = dentry->d_name.len;
+        if (!name_len)
+                return 0;
+        hash = init_name_hash();
+        while (name_len--) {
+                c = *(const unsigned char *)name++;
+                if (c == ':' || c == '\0')
+                        break;
+                hash = partial_name_hash(c, hash);
+                len ++;
+        }
+        str->hash = end_name_hash(hash);
+        OBD_ALLOC(str_name, len + 1);
+        memcpy(str_name, dentry->d_name.name, len);
+        str->len = len; 
+        str->name = str_name;
+        if (index && c == ':') {
+                *index = simple_strtoul(name, 0, 0);         
+        }
+        return 0;
+}
+
+static inline void smfs_free_dentry_name(struct qstr *str)
+{
+        char *name = (char*)str->name;
+        OBD_FREE(name, str->len + 1);
+}
+
 static inline struct dentry *pre_smfs_dentry(struct dentry *parent_dentry,
                                              struct inode *cache_inode,
                                              struct dentry *dentry)
 {
         struct dentry *cache_dentry = NULL;
-
+        
         cache_dentry = d_alloc(parent_dentry, &dentry->d_name);
         if (!cache_dentry)
                 RETURN(NULL);
@@ -324,6 +441,11 @@ static inline void post_smfs_dentry(struct dentry *cache_dentry)
 {
         if (!cache_dentry)
                 return;
+
+        /* 
+         * this is needed because d_unalloc() calls dput(), which in turn calls
+         * iput() on dentry inode.
+         */
         if (cache_dentry->d_inode)
                 igrab(cache_dentry->d_inode);
         d_unalloc(cache_dentry);
@@ -356,7 +478,6 @@ static inline int lookup_by_path(char *path, int flags, struct nameidata *nd)
 }
 
 /*FIXME there should be more conditions in this check*/
-
 static inline int smfs_do_rec(struct inode *inode)
 {
         struct super_block *sb = inode->i_sb;
@@ -367,6 +488,7 @@ static inline int smfs_do_rec(struct inode *inode)
                 return 1;
         return 0;
 }
+
 static inline int smfs_cache_hook(struct inode *inode)
 {
         struct smfs_super_info  *smfs_info = I2CSB(inode);
@@ -377,6 +499,18 @@ static inline int smfs_cache_hook(struct inode *inode)
         else
                 return 0;
 }
+
+static inline int smfs_do_cow(struct inode *inode)
+{
+        struct super_block *sb = inode->i_sb;
+        struct smfs_super_info *smfs_info = S2SMI(sb);
+
+        if (SMFS_DO_COW(smfs_info) && SMFS_DO_INODE_COW(inode))
+                return 1;
+        return 0;
+}
+
+
 /* XXX BUG 3188 -- must return to one set of opcodes */
 #define SMFS_TRANS_OP(inode, op)                \
 {                                               \
@@ -396,5 +530,12 @@ extern int smfs_rec_precreate(struct dentry *dentry, int *num, struct obdo *oa);
 extern int smfs_rec_md(struct inode *inode, void * lmm, int lmm_size);
 extern int smfs_rec_unpack(struct smfs_proc_args *args, char *record,
                            char **pbuf, int *opcode);
+       
+
+extern int smfs_post_setup(struct super_block *sb, struct vfsmount *mnt);
+extern int smfs_post_cleanup(struct super_block *sb);
+extern struct inode *smfs_get_inode (struct super_block *sb, ino_t hash,
+                                     struct inode *dir, int index);
 
+extern int is_smfs_sb(struct super_block *sb);
 #endif /* _LUSTRE_SMFS_H */