Merge git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-unstable
authorLinus Torvalds <torvalds@linux-foundation.org>
Thu, 2 Jul 2009 23:52:38 +0000 (16:52 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 2 Jul 2009 23:52:38 +0000 (16:52 -0700)
* git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-unstable:
  Btrfs: fix error message formatting
  Btrfs: fix use after free in btrfs_start_workers fail path
  Btrfs: honor nodatacow/sum mount options for new files
  Btrfs: update backrefs while dropping snapshot
  Btrfs: account for space we may use in fallocate
  Btrfs: fix the file clone ioctl for preallocated extents
  Btrfs: don't log the inode in file_write while growing the file

1  2 
fs/btrfs/ctree.h
fs/btrfs/inode.c

diff --combined fs/btrfs/ctree.h
@@@ -41,6 -41,8 +41,6 @@@ struct btrfs_ordered_sum
  
  #define BTRFS_MAGIC "_BHRfS_M"
  
 -#define BTRFS_ACL_NOT_CACHED    ((void *)-1)
 -
  #define BTRFS_MAX_LEVEL 8
  
  #define BTRFS_COMPAT_EXTENT_TREE_V0
@@@ -2074,8 -2076,7 +2074,7 @@@ static inline int btrfs_insert_empty_it
  int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
  int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path);
  int btrfs_leaf_free_space(struct btrfs_root *root, struct extent_buffer *leaf);
- int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
-                       *root);
+ int btrfs_drop_snapshot(struct btrfs_root *root, int update_ref);
  int btrfs_drop_subtree(struct btrfs_trans_handle *trans,
                        struct btrfs_root *root,
                        struct extent_buffer *node,
diff --combined fs/btrfs/inode.c
@@@ -2122,8 -2122,10 +2122,8 @@@ static void btrfs_read_locked_inode(str
         * any xattrs or acls
         */
        maybe_acls = acls_after_inode_item(leaf, path->slots[0], inode->i_ino);
 -      if (!maybe_acls) {
 -              BTRFS_I(inode)->i_acl = NULL;
 -              BTRFS_I(inode)->i_default_acl = NULL;
 -      }
 +      if (!maybe_acls)
 +              cache_no_acl(inode);
  
        BTRFS_I(inode)->block_group = btrfs_find_block_group(root, 0,
                                                alloc_group_block, 0);
@@@ -2320,6 -2322,7 +2320,6 @@@ err
        btrfs_update_inode(trans, root, dir);
        btrfs_drop_nlink(inode);
        ret = btrfs_update_inode(trans, root, inode);
 -      dir->i_sb->s_dirt = 1;
  out:
        return ret;
  }
@@@ -2803,6 -2806,7 +2803,6 @@@ error
                                      pending_del_nr);
        }
        btrfs_free_path(path);
 -      inode->i_sb->s_dirt = 1;
        return ret;
  }
  
@@@ -3139,6 -3143,9 +3139,6 @@@ static noinline void init_btrfs_i(struc
  {
        struct btrfs_inode *bi = BTRFS_I(inode);
  
 -      bi->i_acl = BTRFS_ACL_NOT_CACHED;
 -      bi->i_default_acl = BTRFS_ACL_NOT_CACHED;
 -
        bi->generation = 0;
        bi->sequence = 0;
        bi->last_trans = 0;
@@@ -3580,12 -3587,6 +3580,6 @@@ static struct inode *btrfs_new_inode(st
                owner = 1;
        BTRFS_I(inode)->block_group =
                        btrfs_find_block_group(root, 0, alloc_hint, owner);
-       if ((mode & S_IFREG)) {
-               if (btrfs_test_opt(root, NODATASUM))
-                       BTRFS_I(inode)->flags |= BTRFS_INODE_NODATASUM;
-               if (btrfs_test_opt(root, NODATACOW))
-                       BTRFS_I(inode)->flags |= BTRFS_INODE_NODATACOW;
-       }
  
        key[0].objectid = objectid;
        btrfs_set_key_type(&key[0], BTRFS_INODE_ITEM_KEY);
  
        btrfs_inherit_iflags(inode, dir);
  
+       if ((mode & S_IFREG)) {
+               if (btrfs_test_opt(root, NODATASUM))
+                       BTRFS_I(inode)->flags |= BTRFS_INODE_NODATASUM;
+               if (btrfs_test_opt(root, NODATACOW))
+                       BTRFS_I(inode)->flags |= BTRFS_INODE_NODATACOW;
+       }
        insert_inode_hash(inode);
        inode_tree_add(inode);
        return inode;
@@@ -3761,6 -3769,7 +3762,6 @@@ static int btrfs_mknod(struct inode *di
                init_special_inode(inode, inode->i_mode, rdev);
                btrfs_update_inode(trans, root, inode);
        }
 -      dir->i_sb->s_dirt = 1;
        btrfs_update_inode_block_group(trans, inode);
        btrfs_update_inode_block_group(trans, dir);
  out_unlock:
@@@ -3825,6 -3834,7 +3826,6 @@@ static int btrfs_create(struct inode *d
                inode->i_op = &btrfs_file_inode_operations;
                BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops;
        }
 -      dir->i_sb->s_dirt = 1;
        btrfs_update_inode_block_group(trans, inode);
        btrfs_update_inode_block_group(trans, dir);
  out_unlock:
@@@ -3871,6 -3881,7 +3872,6 @@@ static int btrfs_link(struct dentry *ol
        if (err)
                drop_inode = 1;
  
 -      dir->i_sb->s_dirt = 1;
        btrfs_update_inode_block_group(trans, dir);
        err = btrfs_update_inode(trans, root, inode);
  
@@@ -3952,6 -3963,7 +3953,6 @@@ static int btrfs_mkdir(struct inode *di
  
        d_instantiate(dentry, inode);
        drop_on_err = 0;
 -      dir->i_sb->s_dirt = 1;
        btrfs_update_inode_block_group(trans, inode);
        btrfs_update_inode_block_group(trans, dir);
  
@@@ -4635,6 -4647,8 +4636,6 @@@ struct inode *btrfs_alloc_inode(struct 
        ei->last_trans = 0;
        ei->logged_trans = 0;
        btrfs_ordered_inode_tree_init(&ei->ordered_tree);
 -      ei->i_acl = BTRFS_ACL_NOT_CACHED;
 -      ei->i_default_acl = BTRFS_ACL_NOT_CACHED;
        INIT_LIST_HEAD(&ei->i_orphan);
        INIT_LIST_HEAD(&ei->ordered_operations);
        return &ei->vfs_inode;
@@@ -4648,6 -4662,13 +4649,6 @@@ void btrfs_destroy_inode(struct inode *
        WARN_ON(!list_empty(&inode->i_dentry));
        WARN_ON(inode->i_data.nrpages);
  
 -      if (BTRFS_I(inode)->i_acl &&
 -          BTRFS_I(inode)->i_acl != BTRFS_ACL_NOT_CACHED)
 -              posix_acl_release(BTRFS_I(inode)->i_acl);
 -      if (BTRFS_I(inode)->i_default_acl &&
 -          BTRFS_I(inode)->i_default_acl != BTRFS_ACL_NOT_CACHED)
 -              posix_acl_release(BTRFS_I(inode)->i_default_acl);
 -
        /*
         * Make sure we're properly removed from the ordered operation
         * lists.
@@@ -4971,6 -4992,7 +4972,6 @@@ static int btrfs_symlink(struct inode *
                inode->i_op = &btrfs_file_inode_operations;
                BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops;
        }
 -      dir->i_sb->s_dirt = 1;
        btrfs_update_inode_block_group(trans, inode);
        btrfs_update_inode_block_group(trans, dir);
        if (drop_inode)
@@@ -5082,6 -5104,7 +5083,7 @@@ static long btrfs_fallocate(struct inod
        u64 mask = BTRFS_I(inode)->root->sectorsize - 1;
        struct extent_map *em;
        struct btrfs_trans_handle *trans;
+       struct btrfs_root *root;
        int ret;
  
        alloc_start = offset & ~mask;
                        goto out;
        }
  
+       root = BTRFS_I(inode)->root;
+       ret = btrfs_check_data_free_space(root, inode,
+                                         alloc_end - alloc_start);
+       if (ret)
+               goto out;
        locked_end = alloc_end - 1;
        while (1) {
                struct btrfs_ordered_extent *ordered;
                trans = btrfs_start_transaction(BTRFS_I(inode)->root, 1);
                if (!trans) {
                        ret = -EIO;
-                       goto out;
+                       goto out_free;
                }
  
                /* the extent lock is ordered inside the running
                      GFP_NOFS);
  
        btrfs_end_transaction(trans, BTRFS_I(inode)->root);
+ out_free:
+       btrfs_free_reserved_data_space(root, inode, alloc_end - alloc_start);
  out:
        mutex_unlock(&inode->i_mutex);
        return ret;