Whamcloud - gitweb
LU-653 i_version shouldn't be used for VBR
[fs/lustre-release.git] / lustre / lvfs / fsfilt_ext3.c
index a3b3380..271f194 100644 (file)
@@ -28,6 +28,9 @@
 /*
  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2011 Whamcloud, Inc.
+ *
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -213,20 +216,12 @@ static char *fsfilt_ext3_uuid(struct super_block *sb)
 
 static __u64 get_i_version(struct inode *inode)
 {
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)) && defined(HAVE_EXT4_LDISKFS)
-        return inode->i_version;
-#else
         return EXT3_I(inode)->i_fs_version;
-#endif
 }
 
 static void set_i_version(struct inode *inode, __u64 new_version)
 {
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)) && defined(HAVE_EXT4_LDISKFS)
-        inode->i_version = new_version;
-#else
         (EXT3_I(inode))->i_fs_version = new_version;
-#endif
 }
 
 /*
@@ -304,7 +299,7 @@ static void *fsfilt_ext3_start(struct inode *inode, int op, void *desc_private,
                               cpu_to_le32(EXT3_EXTENTS_FL | EXT3_INDEX_FL))) {
                                 CWARN("extent-mapped directory found with "
                                       "ext3-based ldiskfs - contact "
-                                      "http://bugzilla.lustre.org/\n");
+                                      "http://bugs.whamcloud.com/\n");
                                 warned = 1;
                         }
                 }
@@ -996,13 +991,17 @@ static int ext3_ext_new_extent_cb(struct ext3_ext_base *base,
 #endif
         struct inode *inode = ext3_ext_base2inode(base);
         struct ext3_extent nex;
+#if defined(HAVE_EXT4_LDISKFS) && defined(WALK_SPACE_HAS_DATA_SEM)
+        struct ext4_ext_path *tmppath = NULL;
+        struct ext4_extent *tmpex;
+#endif
         unsigned long pblock;
         unsigned long tgen;
-        int err, i;
+        int err, i, depth;
         unsigned long count;
         handle_t *handle;
 
-        i = EXT_DEPTH(base);
+        i = depth = EXT_DEPTH(base);
         EXT_ASSERT(i == path->p_depth);
         EXT_ASSERT(path[i].p_hdr);
 
@@ -1047,6 +1046,29 @@ static int ext3_ext_new_extent_cb(struct ext3_ext_base *base,
                 return EXT_REPEAT;
         }
 
+#if defined(HAVE_EXT4_LDISKFS) && defined(WALK_SPACE_HAS_DATA_SEM)
+        /* In 2.6.32 kernel, ext4_ext_walk_space()'s callback func is not
+         * protected by i_data_sem, we need revalidate extent to be created */
+        down_write((&EXT4_I(inode)->i_data_sem));
+
+        /* validate extent, make sure the extent tree does not changed */
+        tmppath = ext4_ext_find_extent(inode, cex->ec_block, NULL);
+        if (IS_ERR(tmppath)) {
+                up_write(&EXT4_I(inode)->i_data_sem);
+                ext3_journal_stop(handle);
+                return PTR_ERR(tmppath);
+        }
+        tmpex = tmppath[depth].p_ext;
+        if (tmpex != ex) {
+                /* cex is invalid, try again */
+                ext4_ext_drop_refs(tmppath);
+                kfree(tmppath);
+                up_write(&EXT4_I(inode)->i_data_sem);
+                ext3_journal_stop(handle);
+                return EXT_REPEAT;
+        }
+#endif
+
         count = cex->ec_len;
         pblock = new_blocks(handle, base, path, cex->ec_block, &count, &err);
         if (!pblock)
@@ -1081,6 +1103,11 @@ static int ext3_ext_new_extent_cb(struct ext3_ext_base *base,
         BUG_ON(le32_to_cpu(nex.ee_block) != cex->ec_block);
 
 out:
+#if defined(HAVE_EXT4_LDISKFS) && defined(WALK_SPACE_HAS_DATA_SEM)
+        ext4_ext_drop_refs(tmppath);
+        kfree(tmppath);
+        up_write((&EXT4_I(inode)->i_data_sem));
+#endif
         ext3_journal_stop(handle);
 map:
         if (err >= 0) {