Whamcloud - gitweb
1 add snap read in fsfilt_getpage
[fs/lustre-release.git] / lustre / smfs / smfs_cow.c
index 5b4f579..3c68a24 100644 (file)
@@ -46,7 +46,7 @@ static int smfs_init_snaptabe(struct super_block *sb)
         struct snap_info         *snap_info = S2SNAPI(sb);     
         struct snap_table        *snap_table = NULL;       
        struct fsfilt_operations *snapops = snap_info->snap_fsfilt;
-        int                      rc = 0, size, table_size, vallen;
+        int                      rc = 0, size, table_size, vallen, i;
  
         ENTRY;
 
@@ -74,8 +74,11 @@ static int smfs_init_snaptabe(struct super_block *sb)
          
         snap_table->sntbl_magic = cpu_to_le32((__u32)SNAPTABLE_MAGIC); 
         snap_table->sntbl_max_count = size;
+        for (i = 0; i < snap_table->sntbl_max_count; i++) {
+                /*init sn_index to -1*/ 
+                snap_table->sntbl_items[i].sn_index = -1;
+        }
         /*get snaptable info*/
-
         rc = snapops->fs_get_snap_info(sb, NULL, SNAPTABLE_INFO, 
                                        strlen(SNAPTABLE_INFO), 
                                        snap_table, &table_size);       
@@ -575,13 +578,16 @@ int smfs_cow_write(struct inode *inode, struct dentry *dentry, void *data1,
         struct snap_table *table = snap_info->sntbl; 
        long   blocks[2]={-1,-1};
                int  index = 0, i, rc = 0;
-        size_t count = *(size_t *)data1;
-       loff_t pos = *(loff_t*)data2;
+        size_t count;
+       loff_t pos;
 
         ENTRY;
 
-        LASSERT(count);
-        LASSERT(pos);
+        LASSERT(data1);
+        LASSERT(data2);
+        
+        count = *(size_t *)data1;
+       pos = *(loff_t*)data2;
  
        down(&inode->i_sem);
         
@@ -640,6 +646,33 @@ exit:
 }
 EXPORT_SYMBOL(smfs_cow_write);
 
+struct inode *smfs_cow_get_ind(struct inode *inode, int index)
+{
+        struct snap_info *snap_info = S2SNAPI(inode->i_sb);
+        struct fsfilt_operations *snapops = snap_info->snap_fsfilt; 
+        struct snap_table *table = snap_info->sntbl;
+        long block=(index << PAGE_CACHE_SHIFT) >> inode->i_sb->s_blocksize_bits;
+        int slot;
+
+        ENTRY; 
+        for (slot = table->sntbl_count - 1; slot >= 0; slot--) {
+                struct address_space_operations *aops = inode->i_mapping->a_ops;
+                struct inode *cache_inode = NULL;
+                int index = 0;
+
+                index = table->sntbl_items[slot].sn_index;
+                cache_inode = snapops->fs_get_indirect(inode, NULL, index);
+                                                                                                                                                                                                     
+                if (!cache_inode )  continue;
+                                                                                                                                                                                                     
+                if (aops->bmap(cache_inode->i_mapping, block))
+                       RETURN(cache_inode); 
+                iput(cache_inode);
+        }
+
+        RETURN(NULL);
+}
+EXPORT_SYMBOL(smfs_cow_get_ind);
 typedef int (*cow_funcs)(struct inode *dir, struct dentry *dentry, 
                          void *new_dir, void *new_dentry);