Whamcloud - gitweb
Branch:HEAD
[fs/lustre-release.git] / lustre / lvfs / fsfilt_snap_smfs.c
index 2d74ae4..268db4b 100644 (file)
@@ -46,7 +46,7 @@ static struct inode* fsfilt_smfs_create_indirect(struct inode *inode,
                                                  struct inode *parent,
                                                  int del)
 {
-        struct fsfilt_operations *snap_fsfilt = I2SNAPOPS(inode);
+        struct fsfilt_operations *snap_fsfilt = I2SNAPCOPS(inode);
         struct inode *cache_inode = NULL;
         struct inode *cache_parent = NULL;
         struct inode *cache_ind_inode = NULL;
@@ -72,18 +72,20 @@ static struct inode* fsfilt_smfs_create_indirect(struct inode *inode,
                                                index, gen, cache_parent, del);
         post_smfs_inode(inode, cache_inode);
         post_smfs_inode(inode, cache_parent);
-        
+       #if 0 
         if (cache_ind_inode && !IS_ERR(cache_ind_inode)){ 
                 /*FIXME: get indirect inode set_cow flags*/ 
-                ind_inode = iget4(inode->i_sb, cache_ind_inode->i_ino, NULL, 0);
-        }    
+                ind_inode = smfs_get_inode(inode->i_sb, cache_ind_inode->i_ino, 
+                                           inode, 0);
+        }   
+        #endif 
         RETURN(ind_inode);
 }
 
 static struct inode*  fsfilt_smfs_get_indirect(struct inode *inode, 
                                                int *table, int slot)
 {
-        struct fsfilt_operations *snap_fsfilt = I2SNAPOPS(inode);
+        struct fsfilt_operations *snap_fsfilt = I2SNAPCOPS(inode);
         struct inode *cache_inode = NULL;
         struct inode *cache_ind_inode = NULL;
         struct inode *ind_inode = NULL;
@@ -102,18 +104,20 @@ static struct inode*  fsfilt_smfs_get_indirect(struct inode *inode,
                 cache_ind_inode = snap_fsfilt->fs_get_indirect(cache_inode, 
                                                                table, slot);
         post_smfs_inode(inode, cache_inode);
-      
+#if 0      
         if (cache_ind_inode && !IS_ERR(cache_ind_inode)){ 
                 /*FIXME: get indirect inode set_cow flags*/ 
-                ind_inode = iget4(inode->i_sb, cache_ind_inode->i_ino, NULL, 0);
+                ind_inode = smfs_get_inode(inode->i_sb, cache_ind_inode->i_ino,
+                                           inode, slot);
         }    
+#endif
         RETURN(ind_inode);
 }
 
 static int fsfilt_smfs_set_indirect(struct inode *inode, int index,
                                     ino_t ind_ino, ino_t parent_ino)
 {
-        struct fsfilt_operations *snap_fsfilt = I2SNAPOPS(inode);
+        struct fsfilt_operations *snap_fsfilt = I2SNAPCOPS(inode);
         struct inode *cache_inode = NULL;
         int    rc = -EIO;
         ENTRY;
@@ -137,7 +141,7 @@ static int fsfilt_smfs_set_indirect(struct inode *inode, int index,
 static int fsfilt_smfs_snap_feature(struct super_block *sb, int feature, 
                                     int op)
 {
-        struct fsfilt_operations *snap_fsfilt = S2SMI(sb)->sm_snap_fsfilt;
+        struct fsfilt_operations *snap_fsfilt = S2SNAPI(sb)->snap_cache_fsfilt;
         struct super_block       *csb = S2CSB(sb);
         int                      rc = -EIO;
         
@@ -154,7 +158,7 @@ static int fsfilt_smfs_snap_feature(struct super_block *sb, int feature,
 
 static int fsfilt_smfs_is_redirector(struct inode *inode)
 {
-        struct fsfilt_operations *snap_fsfilt = I2SNAPOPS(inode);
+        struct fsfilt_operations *snap_fsfilt = I2SNAPCOPS(inode);
         struct inode *cache_inode = NULL;
         int    rc = -EIO;
         ENTRY;
@@ -175,7 +179,7 @@ static int fsfilt_smfs_is_redirector(struct inode *inode)
 }
 static int fsfilt_smfs_is_indirect(struct inode *inode)
 {
-        struct fsfilt_operations *snap_fsfilt = I2SNAPOPS(inode);
+        struct fsfilt_operations *snap_fsfilt = I2SNAPCOPS(inode);
         struct inode *cache_inode = NULL;
         int    rc = -EIO;
         ENTRY;
@@ -194,76 +198,27 @@ static int fsfilt_smfs_is_indirect(struct inode *inode)
         
         RETURN(rc);
 }
-static ino_t fsfilt_smfs_get_indirect_ino(struct inode *inode, int index)
+static ino_t fsfilt_smfs_get_indirect_ino(struct super_block *sb, ino_t ino, 
+                                          int index)
 {
-        struct fsfilt_operations *snap_fsfilt = I2SNAPOPS(inode);
-        struct inode *cache_inode = NULL;
+        struct fsfilt_operations *snap_fsfilt = S2SNAPI(sb)->snap_cache_fsfilt;
+        struct super_block       *csb = S2CSB(sb);
         int    rc = -EIO;
         ENTRY;
 
         if (snap_fsfilt == NULL)
                 RETURN(rc);
 
-        cache_inode = I2CI(inode);
-        if (!cache_inode)
-                RETURN(rc);
-
-        pre_smfs_inode(inode, cache_inode);
         if (snap_fsfilt->fs_get_indirect_ino)
-                rc = snap_fsfilt->fs_get_indirect_ino(cache_inode, index);
-        post_smfs_inode(inode, cache_inode);
-        
-        RETURN(rc);
-}
-static int fsfilt_smfs_set_generation(struct inode *inode, 
-                                      unsigned long new_gen)
-{
-        struct fsfilt_operations *snap_fsfilt = I2SNAPOPS(inode);
-        struct inode *cache_inode = NULL;
-        int    rc = -EIO;
-        ENTRY;
-
-        if (snap_fsfilt == NULL)
-                RETURN(rc);
-
-        cache_inode = I2CI(inode);
-        if (!cache_inode)
-                RETURN(rc);
-
-        pre_smfs_inode(inode, cache_inode);
-        if (snap_fsfilt->fs_set_generation)
-                rc = snap_fsfilt->fs_set_generation(cache_inode, new_gen);
-        post_smfs_inode(inode, cache_inode);
-        
-        RETURN(rc);
-}
-
-static int fsfilt_smfs_get_generation(struct inode *inode)
-{
-        struct fsfilt_operations *snap_fsfilt = I2SNAPOPS(inode);
-        struct inode *cache_inode = NULL;
-        int    rc = -EIO;
-        ENTRY;
-
-        if (snap_fsfilt == NULL)
-                RETURN(rc);
-
-        cache_inode = I2CI(inode);
-        if (!cache_inode)
-                RETURN(rc);
-
-        pre_smfs_inode(inode, cache_inode);
-        if (snap_fsfilt->fs_get_generation)
-                rc = snap_fsfilt->fs_get_generation(cache_inode);
-        post_smfs_inode(inode, cache_inode);
-        
+                rc = snap_fsfilt->fs_get_indirect_ino(csb, ino, index);
+         
         RETURN(rc);
 }
 
 static int fsfilt_smfs_destroy_indirect(struct inode *inode, int index,
                                         struct inode *next_ind)
 {
-        struct fsfilt_operations *snap_fsfilt = I2SNAPOPS(inode);
+        struct fsfilt_operations *snap_fsfilt = I2SNAPCOPS(inode);
         struct inode *cache_inode = NULL;
         struct inode *cache_next = NULL;
         int    rc = -EIO;
@@ -293,7 +248,7 @@ static int fsfilt_smfs_destroy_indirect(struct inode *inode, int index,
 }
 static int fsfilt_smfs_restore_indirect(struct inode *inode, int index)
 {
-        struct fsfilt_operations *snap_fsfilt = I2SNAPOPS(inode);
+        struct fsfilt_operations *snap_fsfilt = I2SNAPCOPS(inode);
         struct inode *cache_inode = NULL;
         int    rc = -EIO;
         ENTRY;
@@ -318,7 +273,7 @@ static int fsfilt_smfs_iterate(struct super_block *sb,
                                int (*repeat)(struct inode *inode, void *priv),
                                struct inode **start, void *priv, int flag)
 {
-        struct fsfilt_operations *snap_fsfilt = S2SMI(sb)->sm_snap_fsfilt;
+        struct fsfilt_operations *snap_fsfilt = S2SNAPI(sb)->snap_cache_fsfilt;
         struct super_block       *csb = S2CSB(sb);
         int                      rc = -EIO;
         ENTRY;
@@ -337,7 +292,7 @@ static int fsfilt_smfs_iterate(struct super_block *sb,
 
 static int fsfilt_smfs_copy_block(struct inode *dst, struct inode *src, int blk)
 {
-        struct fsfilt_operations *snap_fsfilt = I2SNAPOPS(dst);
+        struct fsfilt_operations *snap_fsfilt = I2SNAPCOPS(dst);
         struct inode *cache_dst = NULL;
         struct inode *cache_src = NULL;
         int    rc = -EIO;
@@ -366,42 +321,88 @@ static int fsfilt_smfs_copy_block(struct inode *dst, struct inode *src, int blk)
         RETURN(rc); 
 }
 
-static int fsfilt_smfs_set_meta_attr(struct super_block *sb, char *name,
-                                     char *buf, int size)
+static int fsfilt_smfs_set_snap_info(struct inode *inode, 
+                                     void* key, __u32 keylen, void *val, 
+                                     __u32 *vallen)
 {
-        struct fsfilt_operations *snap_fsfilt = S2SMI(sb)->sm_snap_fsfilt;
-        struct super_block       *csb = S2CSB(sb);
+
+        struct fsfilt_operations *snap_fsfilt = I2SNAPCOPS(inode);
+        struct inode *cache_inode = NULL;
         int                      rc = -EIO;
-        
+                
         if (snap_fsfilt == NULL)
                 RETURN(rc);
-        if (!csb)
-                RETURN(rc);
         
-        if (snap_fsfilt->fs_set_meta_attr)
-                rc = snap_fsfilt->fs_set_meta_attr(csb, name, buf, size);
+        cache_inode = I2CI(inode);
+        if (!cache_inode)
+                RETURN(rc);
 
+        pre_smfs_inode(inode, cache_inode);
+        
+        if (snap_fsfilt->fs_set_snap_info)
+                rc = snap_fsfilt->fs_set_snap_info(cache_inode, key, 
+                                                   keylen, val, vallen);
+        post_smfs_inode(inode, cache_inode);
+        
         RETURN(rc);
 }
 
-static int fsfilt_smfs_get_meta_attr(struct super_block *sb, char *name,
-                                     char *buf, int *size)
+static int fsfilt_smfs_get_snap_info(struct inode *inode, void *key, 
+                                     __u32 keylen, void *val, __u32 *vallen)
 {
-        struct fsfilt_operations *snap_fsfilt = S2SMI(sb)->sm_snap_fsfilt;
-        struct super_block       *csb = S2CSB(sb);
+        struct fsfilt_operations *snap_fsfilt = I2SNAPCOPS(inode);
+        struct inode *cache_inode = NULL;
         int                      rc = -EIO;
         
         if (snap_fsfilt == NULL)
                 RETURN(rc);
-        if (!csb)
+        
+        cache_inode = I2CI(inode);
+        if (!cache_inode)
                 RETURN(rc);
         
-        if (snap_fsfilt->fs_get_meta_attr)
-                rc = snap_fsfilt->fs_get_meta_attr(csb, name, buf, size);
-
+        if (snap_fsfilt->fs_get_snap_info)
+                rc = snap_fsfilt->fs_get_snap_info(cache_inode, key, 
+                                                   keylen, val, vallen);
+        
         RETURN(rc);
 }
 
+static int fsfilt_smfs_read_dotsnap_dir_page(struct file *file, char *buf,
+                                             size_t count, loff_t *off)
+{
+#if 0
+        struct inode *inode = file->f_dentry->d_inode;
+        struct fsfilt_operations *snap_cops = I2SNAPCOPS(inode);
+        int    i = 0, size = 0, off_count = 0, buf_off = 0, rc = 0;
+        ENTRY;
+        /*Get the offset of dir ent*/
+        //struct snap_table *stbl = S2SNAPI(inode->i_sb)->sni_table;
+        while (size < *off && off_count < stbl->sntbl_count) {
+                char *name = stbl->sntbl_items[i].sn_name;
+                size +=snap_cops->fs_dir_ent_size(name);
+                off_count ++;
+        }
+        for (i = off_count; i < stbl->sntbl_count; i++) {
+                char *name = stbl->sntbl_items[i].sn_name;
+                rc = snap_cops->fs_set_dir_ent(inode->i_sb, name, buf, buf_off, 
+                                               rc, count);
+                if (rc < 0)
+                        break;
+
+                buf_off += rc;
+
+                if (buf_off >= count) 
+                        break;
+        }
+        if (rc > 0) 
+                rc = 0; 
+#else
+#warning "still not implement read .snap dir page for fsfilt Wangdi"
+#endif
+        RETURN(0); 
+}
+
 struct fsfilt_operations fsfilt_smfs_snap_ops = {
         .fs_type                = "smfs_snap",
         .fs_owner               = THIS_MODULE,
@@ -412,14 +413,13 @@ struct fsfilt_operations fsfilt_smfs_snap_ops = {
        .fs_is_redirector       = fsfilt_smfs_is_redirector,
        .fs_is_indirect         = fsfilt_smfs_is_indirect,
         .fs_get_indirect_ino    = fsfilt_smfs_get_indirect_ino,
-        .fs_set_generation      = fsfilt_smfs_set_generation,
-        .fs_get_generation      = fsfilt_smfs_get_generation,
         .fs_destroy_indirect    = fsfilt_smfs_destroy_indirect,
         .fs_restore_indirect    = fsfilt_smfs_restore_indirect,
         .fs_iterate             = fsfilt_smfs_iterate,
         .fs_copy_block          = fsfilt_smfs_copy_block,
-        .fs_set_meta_attr       = fsfilt_smfs_set_meta_attr,
-        .fs_get_meta_attr       = fsfilt_smfs_get_meta_attr,
+        .fs_set_snap_info       = fsfilt_smfs_set_snap_info,
+        .fs_get_snap_info       = fsfilt_smfs_get_snap_info,
+        .fs_read_dotsnap_dir_page = fsfilt_smfs_read_dotsnap_dir_page,
 };