Whamcloud - gitweb
update snapfs 1. fix bug in write table_count in write snap_table 2. fixbug in repla...
authorwangdi <wangdi>
Wed, 14 Jan 2004 14:17:56 +0000 (14:17 +0000)
committerwangdi <wangdi>
Wed, 14 Jan 2004 14:17:56 +0000 (14:17 +0000)
lustre/snapfs/clonefs.c
lustre/snapfs/dir.c
lustre/snapfs/filter.c
lustre/snapfs/snap.c
lustre/snapfs/snaptable.c

index ed378f2..71a0735 100644 (file)
@@ -183,6 +183,20 @@ static void d_unalloc(struct dentry *dentry)
        dput(dentry); /* this will free the dentry memory */
 }
 
+static void prepare_parent_dentry(struct dentry *dentry, struct inode *inode)
+{
+       atomic_set(&dentry->d_count, 1);
+       dentry->d_vfs_flags = 0;
+       dentry->d_flags = 0;
+       dentry->d_inode = inode;
+       dentry->d_op = NULL;
+       dentry->d_fsdata = NULL;
+       dentry->d_mounted = 0;
+       INIT_LIST_HEAD(&dentry->d_hash);
+       INIT_LIST_HEAD(&dentry->d_lru);
+       INIT_LIST_HEAD(&dentry->d_subdirs);
+       INIT_LIST_HEAD(&dentry->d_alias);
+}
 /*
  * Return the underlying fs dentry with name in 'dentry' that points
  * to the right inode. 'dir' is the clone fs directory to search for
@@ -191,9 +205,10 @@ static void d_unalloc(struct dentry *dentry)
 struct dentry *clonefs_lookup(struct inode *dir,  struct dentry *dentry)
 {
        struct inode            *cache_dir = NULL;
-       struct dentry           *cache_dentry = NULL, *tmp = NULL;
+       struct dentry           *cache_dentry = NULL
        struct inode            *cache_inode;
        struct dentry           *result;
+       struct dentry           tmp;
        struct inode            *inode;
        struct snap_clone_info  *clone_sb;
 
@@ -202,20 +217,19 @@ struct dentry *clonefs_lookup(struct inode *dir,  struct dentry *dentry)
        cache_dir = clonefs_get_inode(dir); 
        if (!cache_dir) 
                RETURN(ERR_PTR(-ENOENT));
-               
-       tmp = dget(list_entry(cache_dir->i_dentry.next, struct dentry, d_alias));
-
-       cache_dentry = d_alloc(tmp->d_parent, &dentry->d_name);
+       /*FIXME later, we make parent dentry here
+        *there may some problems in lookup
+        */      
+       prepare_parent_dentry(&tmp, cache_dir);
+       cache_dentry = d_alloc(&tmp, &dentry->d_name);
        
        if (!cache_dentry) {
                 iput(cache_dir);
-               dput(tmp);
                RETURN(ERR_PTR(-ENOENT));
        }
 
         /* Lock cache directory inode. */
        down(&cache_dir->i_sem);
-       dput(tmp);
         /*
          * Call underlying fs lookup function to set the 'd_inode' pointer
          * to the corresponding directory inode.
@@ -378,13 +392,14 @@ static int clonefs_readpage(struct file *file, struct page *page)
                              &open_dentry);
        /* tell currentfs_readpage the primary inode number */
        open_dentry.d_fsdata = (void*)inode->i_ino;
-
+       page->mapping->host = cache_inode;
        /* potemkin case: we are handed a directory inode */
        down(&cache_inode->i_sem);
         /* XXX - readpage NULL on directories... */
         result = cache_inode->i_mapping->a_ops->readpage(&open_file, page);
 
        up(&cache_inode->i_sem);
+       page->mapping->host = inode;
        clonefs_restore_snapfile(inode, file, cache_inode, &open_file);
        iput(cache_inode);
        RETURN(result);
index f34f28d..4db0908 100644 (file)
@@ -187,17 +187,7 @@ static int currentfs_create(struct inode *dir, struct dentry *dentry, int mode)
                 CERROR("Error in currentfs_create, dentry->d_inode is NULL\n");
                 GOTO(exit, 0);
         }
-
-       if (S_ISDIR(dentry->d_inode->i_mode))
-                dentry->d_inode->i_op = filter_c2udiops(cache->cache_filter);
-        else if (S_ISREG(dentry->d_inode->i_mode)) {
-                if (!filter_c2cfiops(cache->cache_filter)) {
-                        filter_setup_file_ops(cache->cache_filter, dentry->d_inode,
-                                             &currentfs_file_iops, &currentfs_file_fops,
-                                             &currentfs_file_aops);
-                }
-                dentry->d_inode->i_op = filter_c2ufiops(cache->cache_filter);
-        }
+       set_filter_ops(cache, dentry->d_inode);
        CDEBUG(D_INODE, "inode %lu, i_op %p\n", dentry->d_inode->i_ino, dentry->d_inode->i_op);
        snap_debug_device_fail(dir->i_dev, SNAP_OP_CREATE, 3);
        init_filter_data(dentry->d_inode, 0); 
index 3497df4..c17a499 100644 (file)
@@ -294,6 +294,8 @@ void filter_setup_file_ops(struct filter_fs            *cache,
        if (filter_fops) {
                if (filter_fops->read)
                        u_fops->read = filter_fops->read;
+               if (filter_fops->write)
+                       u_fops->write = filter_fops->write;
        }
        if (filter_aops) {
                if (filter_aops->readpage)
index 8fcaeaf..afb4ddb 100644 (file)
@@ -70,16 +70,18 @@ struct inode *snap_redirect(struct inode *cache_inode,
 
        /* first find if there are indirected at the clone_index */
        redirected = snapops->get_indirect(cache_inode, NULL, 
-                                       clone_info->clone_index);
+                                          clone_info->clone_index);
        /* if not found, get the FIRST index after this and before NOW */
        /* XXX fix this later, now use tbl_count, not NOW */
        if (!redirected) {
                int index;
+
+               memset(my_table, 0, sizeof(my_table));
                clone_slot = snap_index2slot(table, clone_info->clone_index);
                for (slot = table->tbl_count-1; slot >= clone_slot; slot --) {
-                       my_table[slot-clone_slot+1] = table->snap_items[slot].index;
+                       my_table[slot - clone_slot + 1] = table->snap_items[slot].index;
                }
-               index = table->tbl_count - clone_slot + 1;
+               index = table->tbl_count - clone_slot;
                redirected = snapops->get_indirect(cache_inode, my_table, index);
        }
 
index 12c212a..c16a5f0 100644 (file)
@@ -222,8 +222,8 @@ static int snaptable_add_item(struct ioc_snap_tbl_data *data)
        if (!disk_snap_table)
                GOTO(exit, rc = -ENOMEM);
        disk_snap_table->magic = cpu_to_le32((__u32)DISK_SNAP_TABLE_MAGIC);
-       disk_snap_table->count = cpu_to_le32((__u32)table->tbl_count) - 1;
-       disk_snap_table->generation = cpu_to_le32((__u32)table->generation);
+       disk_snap_table->count = cpu_to_le32((__u32)table->tbl_count);
+       disk_snap_table->generation = cpu_to_le32((__u32)table->generation + 1);
        memset(&disk_snap_table->snap_items[0], 0, 
               SNAP_MAX * sizeof(struct snap_disk));