Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs...
authorLinus Torvalds <torvalds@linux-foundation.org>
Tue, 5 Apr 2011 19:29:25 +0000 (12:29 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 5 Apr 2011 19:29:25 +0000 (12:29 -0700)
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-unstable:
  Btrfs: don't warn in btrfs_add_orphan
  Btrfs: fix free space cache when there are pinned extents and clusters V2
  Btrfs: Fix uninitialized root flags for subvolumes
  btrfs: clear __GFP_FS flag in the space cache inode
  Btrfs: fix memory leak in start_transaction()
  Btrfs: fix memory leak in btrfs_ioctl_start_sync()
  Btrfs: fix subvol_sem leak in btrfs_rename()
  Btrfs: Fix oops for defrag with compression turned on
  Btrfs: fix /proc/mounts info.
  Btrfs: fix compiler warning in file.c

1  2 
fs/btrfs/disk-io.c
fs/btrfs/inode.c
fs/btrfs/ioctl.c

diff --combined fs/btrfs/disk-io.c
index d7a7315bd031a095c4f9f405afbb2b096a1e6f3e,a272bfd74ea083f1ee13cde42012dac8d28dc8cc..8f1d44ba332f487aa42e3291daa63e45b04d44e0
@@@ -936,6 -936,7 +936,6 @@@ static const struct address_space_opera
        .writepages     = btree_writepages,
        .releasepage    = btree_releasepage,
        .invalidatepage = btree_invalidatepage,
 -      .sync_page      = block_sync_page,
  #ifdef CONFIG_MIGRATION
        .migratepage    = btree_migratepage,
  #endif
@@@ -1275,8 -1276,10 +1275,10 @@@ struct btrfs_root *btrfs_read_fs_root_n
        root->commit_root = btrfs_root_node(root);
        BUG_ON(!root->node);
  out:
-       if (location->objectid != BTRFS_TREE_LOG_OBJECTID)
+       if (location->objectid != BTRFS_TREE_LOG_OBJECTID) {
                root->ref_cows = 1;
+               btrfs_check_and_init_root_item(&root->root_item);
+       }
  
        return root;
  }
@@@ -1421,6 -1424,82 +1423,6 @@@ static int btrfs_congested_fn(void *con
        return ret;
  }
  
 -/*
 - * this unplugs every device on the box, and it is only used when page
 - * is null
 - */
 -static void __unplug_io_fn(struct backing_dev_info *bdi, struct page *page)
 -{
 -      struct btrfs_device *device;
 -      struct btrfs_fs_info *info;
 -
 -      info = (struct btrfs_fs_info *)bdi->unplug_io_data;
 -      list_for_each_entry(device, &info->fs_devices->devices, dev_list) {
 -              if (!device->bdev)
 -                      continue;
 -
 -              bdi = blk_get_backing_dev_info(device->bdev);
 -              if (bdi->unplug_io_fn)
 -                      bdi->unplug_io_fn(bdi, page);
 -      }
 -}
 -
 -static void btrfs_unplug_io_fn(struct backing_dev_info *bdi, struct page *page)
 -{
 -      struct inode *inode;
 -      struct extent_map_tree *em_tree;
 -      struct extent_map *em;
 -      struct address_space *mapping;
 -      u64 offset;
 -
 -      /* the generic O_DIRECT read code does this */
 -      if (1 || !page) {
 -              __unplug_io_fn(bdi, page);
 -              return;
 -      }
 -
 -      /*
 -       * page->mapping may change at any time.  Get a consistent copy
 -       * and use that for everything below
 -       */
 -      smp_mb();
 -      mapping = page->mapping;
 -      if (!mapping)
 -              return;
 -
 -      inode = mapping->host;
 -
 -      /*
 -       * don't do the expensive searching for a small number of
 -       * devices
 -       */
 -      if (BTRFS_I(inode)->root->fs_info->fs_devices->open_devices <= 2) {
 -              __unplug_io_fn(bdi, page);
 -              return;
 -      }
 -
 -      offset = page_offset(page);
 -
 -      em_tree = &BTRFS_I(inode)->extent_tree;
 -      read_lock(&em_tree->lock);
 -      em = lookup_extent_mapping(em_tree, offset, PAGE_CACHE_SIZE);
 -      read_unlock(&em_tree->lock);
 -      if (!em) {
 -              __unplug_io_fn(bdi, page);
 -              return;
 -      }
 -
 -      if (em->block_start >= EXTENT_MAP_LAST_BYTE) {
 -              free_extent_map(em);
 -              __unplug_io_fn(bdi, page);
 -              return;
 -      }
 -      offset = offset - em->start;
 -      btrfs_unplug_page(&BTRFS_I(inode)->root->fs_info->mapping_tree,
 -                        em->block_start + offset, page);
 -      free_extent_map(em);
 -}
 -
  /*
   * If this fails, caller must call bdi_destroy() to get rid of the
   * bdi again.
@@@ -1435,6 -1514,8 +1437,6 @@@ static int setup_bdi(struct btrfs_fs_in
                return err;
  
        bdi->ra_pages   = default_backing_dev_info.ra_pages;
 -      bdi->unplug_io_fn       = btrfs_unplug_io_fn;
 -      bdi->unplug_io_data     = info;
        bdi->congested_fn       = btrfs_congested_fn;
        bdi->congested_data     = info;
        return 0;
@@@ -2529,7 -2610,7 +2531,7 @@@ int close_ctree(struct btrfs_root *root
         * ERROR state on disk.
         *
         * 2. when btrfs flips readonly just in btrfs_commit_super,
 -       * and in such case, btrfs cannnot write sb via btrfs_commit_super,
 +       * and in such case, btrfs cannot write sb via btrfs_commit_super,
         * and since fs_state has been set BTRFS_SUPER_FLAG_ERROR flag,
         * btrfs will cleanup all FS resources first and write sb then.
         */
diff --combined fs/btrfs/inode.c
index 93c28a1d6bdc758b5270e6b8c7b448d106f1ab7b,cc6022842e0c490911782d8122f1b052a5d5808f..65413394daefd3ec9787e7fe1c77709324e3f4ea
@@@ -93,14 -93,13 +93,14 @@@ static noinline int cow_file_range(stru
                                   unsigned long *nr_written, int unlock);
  
  static int btrfs_init_inode_security(struct btrfs_trans_handle *trans,
 -                                   struct inode *inode,  struct inode *dir)
 +                                   struct inode *inode,  struct inode *dir,
 +                                   const struct qstr *qstr)
  {
        int err;
  
        err = btrfs_init_acl(trans, inode, dir);
        if (!err)
 -              err = btrfs_xattr_security_init(trans, inode, dir);
 +              err = btrfs_xattr_security_init(trans, inode, dir, qstr);
        return err;
  }
  
  static noinline int insert_inline_extent(struct btrfs_trans_handle *trans,
                                struct btrfs_root *root, struct inode *inode,
                                u64 start, size_t size, size_t compressed_size,
+                               int compress_type,
                                struct page **compressed_pages)
  {
        struct btrfs_key key;
        size_t cur_size = size;
        size_t datasize;
        unsigned long offset;
-       int compress_type = BTRFS_COMPRESS_NONE;
  
-       if (compressed_size && compressed_pages) {
-               compress_type = root->fs_info->compress_type;
+       if (compressed_size && compressed_pages)
                cur_size = compressed_size;
-       }
  
        path = btrfs_alloc_path();
        if (!path)
@@@ -221,7 -218,7 +219,7 @@@ fail
  static noinline int cow_file_range_inline(struct btrfs_trans_handle *trans,
                                 struct btrfs_root *root,
                                 struct inode *inode, u64 start, u64 end,
-                                size_t compressed_size,
+                                size_t compressed_size, int compress_type,
                                 struct page **compressed_pages)
  {
        u64 isize = i_size_read(inode);
                inline_len = min_t(u64, isize, actual_end);
        ret = insert_inline_extent(trans, root, inode, start,
                                   inline_len, compressed_size,
-                                  compressed_pages);
+                                  compress_type, compressed_pages);
        BUG_ON(ret);
        btrfs_delalloc_release_metadata(inode, end + 1 - start);
        btrfs_drop_extent_cache(inode, start, aligned_end - 1, 0);
@@@ -433,12 -430,13 +431,13 @@@ again
                         * to make an uncompressed inline extent.
                         */
                        ret = cow_file_range_inline(trans, root, inode,
-                                                   start, end, 0, NULL);
+                                                   start, end, 0, 0, NULL);
                } else {
                        /* try making a compressed inline extent */
                        ret = cow_file_range_inline(trans, root, inode,
                                                    start, end,
-                                                   total_compressed, pages);
+                                                   total_compressed,
+                                                   compress_type, pages);
                }
                if (ret == 0) {
                        /*
@@@ -792,7 -790,7 +791,7 @@@ static noinline int cow_file_range(stru
        if (start == 0) {
                /* lets try to make an inline extent */
                ret = cow_file_range_inline(trans, root, inode,
-                                           start, end, 0, NULL);
+                                           start, end, 0, 0, NULL);
                if (ret == 0) {
                        extent_clear_unlock_delalloc(inode,
                                     &BTRFS_I(inode)->io_tree,
@@@ -2222,8 -2220,6 +2221,6 @@@ int btrfs_orphan_add(struct btrfs_trans
                        insert = 1;
  #endif
                insert = 1;
-       } else {
-               WARN_ON(!BTRFS_I(inode)->orphan_meta_reserved);
        }
  
        if (!BTRFS_I(inode)->orphan_meta_reserved) {
@@@ -2537,8 -2533,6 +2534,6 @@@ static void btrfs_read_locked_inode(str
        BTRFS_I(inode)->flags = btrfs_inode_flags(leaf, inode_item);
  
        alloc_group_block = btrfs_inode_block_group(leaf, inode_item);
-       if (location.objectid == BTRFS_FREE_SPACE_OBJECTID)
-               inode->i_mapping->flags &= ~__GFP_FS;
  
        /*
         * try to precache a NULL acl entry for files that don't have
@@@ -4730,7 -4724,7 +4725,7 @@@ static int btrfs_mknod(struct inode *di
        if (IS_ERR(inode))
                goto out_unlock;
  
 -      err = btrfs_init_inode_security(trans, inode, dir);
 +      err = btrfs_init_inode_security(trans, inode, dir, &dentry->d_name);
        if (err) {
                drop_inode = 1;
                goto out_unlock;
@@@ -4791,7 -4785,7 +4786,7 @@@ static int btrfs_create(struct inode *d
        if (IS_ERR(inode))
                goto out_unlock;
  
 -      err = btrfs_init_inode_security(trans, inode, dir);
 +      err = btrfs_init_inode_security(trans, inode, dir, &dentry->d_name);
        if (err) {
                drop_inode = 1;
                goto out_unlock;
@@@ -4832,6 -4826,9 +4827,6 @@@ static int btrfs_link(struct dentry *ol
        int err;
        int drop_inode = 0;
  
 -      if (inode->i_nlink == 0)
 -              return -ENOENT;
 -
        /* do not allow sys_link's with other subvols of the same device */
        if (root->objectid != BTRFS_I(inode)->root->objectid)
                return -EXDEV;
@@@ -4920,7 -4917,7 +4915,7 @@@ static int btrfs_mkdir(struct inode *di
  
        drop_on_err = 1;
  
 -      err = btrfs_init_inode_security(trans, inode, dir);
 +      err = btrfs_init_inode_security(trans, inode, dir, &dentry->d_name);
        if (err)
                goto out_fail;
  
@@@ -6960,8 -6957,10 +6955,10 @@@ static int btrfs_rename(struct inode *o
         * should cover the worst case number of items we'll modify.
         */
        trans = btrfs_start_transaction(root, 20);
-       if (IS_ERR(trans))
-               return PTR_ERR(trans);
+       if (IS_ERR(trans)) {
+                 ret = PTR_ERR(trans);
+                 goto out_notrans;
+         }
  
        btrfs_set_trans_block_group(trans, new_dir);
  
        }
  out_fail:
        btrfs_end_transaction_throttle(trans, root);
+ out_notrans:
        if (old_inode->i_ino == BTRFS_FIRST_FREE_OBJECTID)
                up_read(&root->fs_info->subvol_sem);
  
@@@ -7213,7 -7212,7 +7210,7 @@@ static int btrfs_symlink(struct inode *
        if (IS_ERR(inode))
                goto out_unlock;
  
 -      err = btrfs_init_inode_security(trans, inode, dir);
 +      err = btrfs_init_inode_security(trans, inode, dir, &dentry->d_name);
        if (err) {
                drop_inode = 1;
                goto out_unlock;
@@@ -7449,6 -7448,7 +7446,6 @@@ static const struct address_space_opera
        .writepage      = btrfs_writepage,
        .writepages     = btrfs_writepages,
        .readpages      = btrfs_readpages,
 -      .sync_page      = block_sync_page,
        .direct_IO      = btrfs_direct_IO,
        .invalidatepage = btrfs_invalidatepage,
        .releasepage    = btrfs_releasepage,
diff --combined fs/btrfs/ioctl.c
index 7c07fe26b7cfcf7e7872686da07f5676e87549c4,f9c93a9ed4a762158df6ae4d494a1b016d10ff5a..cfc264fefdb0e61d419673205304bf54ca285179
@@@ -176,7 -176,7 +176,7 @@@ static int btrfs_ioctl_setflags(struct 
        if (ret)
                return ret;
  
 -      if (!is_owner_or_cap(inode))
 +      if (!inode_owner_or_capable(inode))
                return -EACCES;
  
        mutex_lock(&inode->i_mutex);
@@@ -373,6 -373,10 +373,10 @@@ static noinline int create_subvol(struc
        inode_item->nbytes = cpu_to_le64(root->leafsize);
        inode_item->mode = cpu_to_le32(S_IFDIR | 0755);
  
+       root_item.flags = 0;
+       root_item.byte_limit = 0;
+       inode_item->flags = cpu_to_le64(BTRFS_INODE_ROOT_ITEM_INIT);
        btrfs_set_root_bytenr(&root_item, leaf->start);
        btrfs_set_root_generation(&root_item, trans->transid);
        btrfs_set_root_level(&root_item, 0);
@@@ -1158,7 -1162,7 +1162,7 @@@ static noinline int btrfs_ioctl_subvol_
        if (flags & ~BTRFS_SUBVOL_RDONLY)
                return -EOPNOTSUPP;
  
 -      if (!is_owner_or_cap(inode))
 +      if (!inode_owner_or_capable(inode))
                return -EACCES;
  
        down_write(&root->fs_info->subvol_sem);
@@@ -2436,8 -2440,10 +2440,10 @@@ static noinline long btrfs_ioctl_start_
                return PTR_ERR(trans);
        transid = trans->transid;
        ret = btrfs_commit_transaction_async(trans, root, 0);
-       if (ret)
+       if (ret) {
+               btrfs_end_transaction(trans, root);
                return ret;
+       }
  
        if (argp)
                if (copy_to_user(argp, &transid, sizeof(transid)))