Whamcloud - gitweb
update snapfs 1)add mntget and mntput for snap_current when mount snap_clone 2)get...
authorwangdi <wangdi>
Fri, 16 Jan 2004 13:03:05 +0000 (13:03 +0000)
committerwangdi <wangdi>
Fri, 16 Jan 2004 13:03:05 +0000 (13:03 +0000)
lustre/snapfs/clonefs.c
lustre/snapfs/file.c
lustre/snapfs/psdev.c
lustre/snapfs/snapfs_internal.h
lustre/snapfs/super.c
lustre/snapfs/sysctl.c

index 71a0735..b4f136c 100644 (file)
@@ -142,6 +142,8 @@ static void clonefs_put_super(struct super_block *sb)
        clone_sb = (struct snap_clone_info *)&sb->u.generic_sbp;
        dput(clone_sb->clone_cache->cache_sb->s_root);
        list_del(&clone_sb->clone_list_entry);
+       
+       put_snap_current_mnt(clone_sb->clone_cache->cache_sb);
 
        EXIT;
 }
index 78cc9ab..dee3eaa 100644 (file)
@@ -41,22 +41,20 @@ static void currentfs_restore_snapfile(struct inode *cache_inode,
         cache_file->f_pos = clone_file->f_pos;
 }
 
-
 static ssize_t currentfs_write (struct file *filp, const char *buf, 
                                size_t count, loff_t *ppos)
 {
         struct snap_cache *cache;
        struct inode *inode = filp->f_dentry->d_inode;
-        ssize_t rc;
         struct file_operations *fops;
-       loff_t pos;
-       long block[2]={-1,-1}, mask, i;
+       long block[2]={-1,-1};
        struct snap_table *table;
-       int slot = 0;
-       int index = 0;
-       struct address_space_operations *aops;
        struct inode *cache_inode = NULL;
        struct snapshot_operations *snapops;
+       int slot = 0, index = 0, result = 0;
+       long mask, i;
+        ssize_t rc;
+       loff_t pos;
   
        ENTRY;
 
@@ -96,36 +94,42 @@ static ssize_t currentfs_write (struct file *filp, const char *buf,
        if( block[0] == block[1] )
                block[1] = -1;
        
-       aops = filter_c2cfaops(cache->cache_filter);
        snapops = filter_c2csnapops(cache->cache_filter);
 
-       for( i=0; i<2; i++ ){
-               if(block[i]!=-1 && aops->bmap(inode->i_mapping, block[i])) {
-                       table = &snap_tables[cache->cache_snap_tableno];
-                       for (slot = table->tbl_count - 1; slot >= 1; slot--) {
-                               struct address_space_operations *c_aops = 
-                                       cache_inode->i_mapping->a_ops;
-                               cache_inode = NULL;
-                               index = table->snap_items[slot].index;
-                               cache_inode = snap_get_indirect(inode, NULL, index);
-
-                               if ( !cache_inode )  continue;
-
-                               if (c_aops->bmap(cache_inode->i_mapping, block[i])) {
-                                       CDEBUG(D_SNAP, "find cache_ino %lu\n",
-                                               cache_inode->i_ino);
-                                       if( snapops && snapops->copy_block) {
-                                               snapops->copy_block(inode, 
-                                                               cache_inode, block[i]);
-                                       }
+       for (i = 0; i < 2; i++) {
+               if (block[i] == -1) 
+                       continue;
+               table = &snap_tables[cache->cache_snap_tableno];
+               /*Find the nearest block in snaptable and copy back it*/
+               for (slot = table->tbl_count - 1; slot >= 1; slot--) {
+                       cache_inode = NULL;
+                               index = table->snap_items[slot].index;
+                       cache_inode = snap_get_indirect(inode, NULL, index);
+
+                       if (!cache_inode)  continue;
+
+                       CDEBUG(D_SNAP, "find cache_ino %lu\n", cache_inode->i_ino);
+               
+                       if (snapops && snapops->copy_block) {
+                               result = snapops->copy_block(inode, cache_inode, block[i]);
+                               if (result == 1) {
+                                       CDEBUG(D_SNAP, "copy block %lu back from ind %lu to %lu\n", 
+                                              block[i], cache_inode->i_ino, inode->i_ino);
+                                               iput(cache_inode);
+                                       result = 0;
+                                       break;
+                               }
+                               if (result < 0) {
                                        iput(cache_inode);
-                                       break;
-                               }
-                                       iput(cache_inode);
-                       }
-               }
+                                       rc = result;
+                                       goto exit;
+                               }
+                       }
+                               iput(cache_inode);
+               }
        }
         rc = fops->write(filp, buf, count, ppos);
+exit:
         RETURN(rc);
 }
 
@@ -179,10 +183,7 @@ static int currentfs_readpage(struct file *file, struct page *page)
 
        table = &snap_tables[cache->cache_snap_tableno];
 
-        for (slot = table->tbl_count - 1; slot >= 1; slot--)
-        {
-               struct address_space_operations *c_aops = 
-                                       cache_inode->i_mapping->a_ops;
+        for (slot = table->tbl_count - 1; slot >= 1; slot--) {
                cache_inode = NULL;
                 index = table->snap_items[slot].index;
                cache_inode = snap_get_indirect(inode, NULL, index);
index 764adcc..33b7608 100644 (file)
@@ -29,8 +29,6 @@
 #include "snapfs_internal.h" 
 
 
-int snap_print_entry = 1;
-int snap_debug_level = 0;
 int snap_inodes = 0;
 long snap_kmemory = 0;
 int snap_stack = 0;
index 1ac04d7..6ce3e3e 100644 (file)
@@ -278,6 +278,9 @@ int snap_migrate_data(struct inode *dst, struct inode *src);
 int snap_set_indirect(struct inode *pri, ino_t ind_ino, 
                        int index, ino_t parent_ino);
 
+/*super.c */
+void put_snap_current_mnt(struct super_block *sb);
+void get_snap_current_mnt(struct super_block *sb);
 /* inode.c */
 extern struct super_operations currentfs_super_ops;
 void cleanup_filter_info_cache(void);
@@ -403,7 +406,7 @@ static inline void snapfs_cpy_attrs(struct inode *dst, struct inode *src)
        dst->i_gid = src->i_gid;
        dst->i_mode = src->i_mode;
 }
-#ifdef SNAP_DEBUG
+#if 0
 extern unsigned int snap_debug_failcode;
 #ifdef CONFIG_LOOP_DISCARD
 #define BLKDEV_FAIL(dev,fail) loop_discard_io(dev,fail)
index 587075b..bfeecde 100644 (file)
@@ -44,6 +44,42 @@ static void put_filesystem(struct file_system_type *fs)
                __MOD_DEC_USE_COUNT(fs->owner);
 }
 
+static struct vfsmount* get_vfsmount(struct super_block *sb)
+{
+       struct vfsmount *rootmnt, *mnt, *ret = NULL;
+       struct list_head *end, *list;
+
+       rootmnt = mntget(current->fs->rootmnt);
+       end = list = &rootmnt->mnt_list;
+       do {
+               mnt = list_entry(list, struct vfsmount, mnt_list);
+               if (mnt->mnt_sb == sb) {
+                       ret = mnt;
+                       break;
+               }
+               list = list->next;
+       } while (end != list);
+       mntput(current->fs->rootmnt);
+       return ret;
+}
+
+void get_snap_current_mnt(struct super_block *sb)
+{
+       struct vfsmount *mnt;
+
+       mnt = get_vfsmount(sb);
+       if (mnt) 
+               mntget(mnt);
+}
+void put_snap_current_mnt(struct super_block *sb)
+{
+       struct vfsmount *mnt;
+
+       mnt = get_vfsmount(sb);
+       if (mnt) 
+               mntput(mnt);
+}
+
 /* In get_opt we get options in opt, value in opt_value
  * we must remember to free opt and opt_value*/
 static char * snapfs_options(char *options, char **cache_type, 
@@ -423,6 +459,8 @@ clone_read_super(
 
        CDEBUG(D_SUPER, "sb %lx, &sb->u.generic_sbp: %lx\n",
                 (ulong) sb, (ulong) &sb->u.generic_sbp);
+       
+       get_snap_current_mnt(snap_cache->cache_sb);
  out_err:
        cleanup_option();
        if (err)
index 1969081..b9d40d6 100644 (file)
@@ -40,12 +40,13 @@ static struct ctl_table_header *snapfs_table_header = NULL;
 /* These are global control options */
 #define ENTRY_CNT 3
 
+int snap_print_entry = 1;
+int snap_debug_level = 0;
+
 /* XXX - doesn't seem to be working in 2.2.15 */
 static struct ctl_table snapfs_ctltable[] =
 {
-#ifdef SNAP_DEBUG
        {PSDEV_DEBUG, "debug", &snap_debug_level, sizeof(int), 0644, NULL, &proc_dointvec},
-#endif
        {PSDEV_TRACE, "trace", &snap_print_entry, sizeof(int), 0644, NULL, &proc_dointvec},
        {0}
 };