]> www.infradead.org Git - users/jedix/linux-maple.git/log
users/jedix/linux-maple.git
13 years agobe2iscsi 4.1.239.0 [PATCH 09/10] Move driver Version to 4.1.239.0
Chuck Anderson [Sat, 17 Dec 2011 04:08:48 +0000 (20:08 -0800)]
be2iscsi 4.1.239.0 [PATCH 09/10]  Move driver Version to 4.1.239.0

Dec. 16, 2011
Oracle bugzilla 13257
Oracle bug 13465921
be2iscsi HBA driver v4.1.239.0 patch set for UEK R2(2.6.39)
jayamohan.kallickal@emulex.com

Ported driver version 4.1.239.0 to UEK2 2.6.39-100.0.17 (was 2.103.298.0)

Comments from the patch headers:

 Commit ID : 1379c254ec5f9152a6d8c2026142b926d4c6b24c
 [SCSI] be2iscsi: Move driver Version to 4.1.239.0
---
 be_main.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Signed-off-by: Chuck Anderson <chuck.anderson@oracle.com>
13 years agobe2iscsi 4.1.239.0 [PATCH 08/10] memset wrb for ring create
Chuck Anderson [Sat, 17 Dec 2011 04:08:02 +0000 (20:08 -0800)]
be2iscsi 4.1.239.0 [PATCH 08/10]   memset wrb for ring create

Dec. 16, 2011
Oracle bugzilla 13257
Oracle bug 13465921
be2iscsi HBA driver v4.1.239.0 patch set for UEK R2(2.6.39)
jayamohan.kallickal@emulex.com

Ported driver version 4.1.239.0 to UEK2 2.6.39-100.0.17 (was 2.103.298.0)

Comments from the patch headers:

  Commit ID : 37609766bf0f84b65b2181c17a7490eef139cdd1
  [SCSI] be2iscsi: memset wrb for ring create

     This patch fixes a situation when  wrb was not being memset to zero
 before being used
---
 be_cmds.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

Signed-off-by: Chuck Anderson <chuck.anderson@oracle.com>
13 years agobe2iscsi 4.1.239.0 [PATCH 07/10] Fix for case where task->sc was cleanedup earlier
Chuck Anderson [Sat, 17 Dec 2011 04:07:40 +0000 (20:07 -0800)]
be2iscsi 4.1.239.0 [PATCH 07/10]  Fix for case where task->sc was cleanedup earlier

Dec. 16, 2011
Oracle bugzilla 13257
Oracle bug 13465921
be2iscsi HBA driver v4.1.239.0 patch set for UEK R2(2.6.39)
jayamohan.kallickal@emulex.com

Ported driver version 4.1.239.0 to UEK2 2.6.39-100.0.17 (was 2.103.298.0)

Comments from the patch headers:

 Commit ID : bd5354511d00cb9c81c64b0544786807a2209488
 [SCSI] be2iscsi: Fix for case where task->sc was cleanedup earlier

 This patch fixes a bug where the task->sc was cleaned up earlier on a
 different thread, possibly abort, and the completion comes later.

 This was causing a crash which has been reported in multiple places
---
 be_main.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

Signed-off-by: Chuck Anderson <chuck.anderson@oracle.com>
13 years agobe2iscsi 4.1.239.0 [PATCH 06/10] Fix for wrong dmsg setting in wrb
Chuck Anderson [Sat, 17 Dec 2011 04:06:31 +0000 (20:06 -0800)]
be2iscsi 4.1.239.0 [PATCH 06/10]  Fix for wrong dmsg setting in wrb

Dec. 16, 2011
Oracle bugzilla 13257
Oracle bug 13465921
be2iscsi HBA driver v4.1.239.0 patch set for UEK R2(2.6.39)
jayamohan.kallickal@emulex.com

Ported driver version 4.1.239.0 to UEK2 2.6.39-100.0.17 (was 2.103.298.0)

Comments from the patch headers:

 Commit ID : 685e16fdcf4324fe75ff28940311598f01704eaa
 [SCSI] be2iscsi: Fix for wrong dmsg setting in wrb

    This patch fixes wrong dmsg setting when we send out wrb.

If the ttt is not ISCSI_RESERVED_TAG then we should be setting
dmsg=1 so that the completion is done without waiting for a
iscsi level response from the target
---
 be_main.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

Signed-off-by: Chuck Anderson <chuck.anderson@oracle.com>
13 years agobe2iscsi 4.1.239.0 [PATCH 05/10] Fix for kdump failure
Chuck Anderson [Sat, 17 Dec 2011 04:05:53 +0000 (20:05 -0800)]
be2iscsi 4.1.239.0 [PATCH 05/10]  Fix for kdump failure

Dec. 16, 2011
Oracle bugzilla 13257
Oracle bug 13465921
be2iscsi HBA driver v4.1.239.0 patch set for UEK R2(2.6.39)
jayamohan.kallickal@emulex.com

Ported driver version 4.1.239.0 to UEK2 2.6.39-100.0.17 (was 2.103.298.0)

Comments from the patch headers:

 Commit ID : e528586079a20c3d28a490ec8e3271bb4348fc3e
 [SCSI] be2iscsi: Fix for kdump failure

 This patch fixes the Kdump failure reported by Redhat wich was caused by
 be2iscsi resetting the Chip when be2iscsi detects it is in crashdump mode. If
 be2net was loaded before be2iscsi then this leaves be2net driver hanging on to
 resources that the chip stopped recognising after the reset.

 This patch replaces  chip reset with Function reset so that only the
 particular function and not the whole chip is affected
---
 be_cmds.c |   19 +++++++++++++++++++
 be_cmds.h |    2 ++
 be_main.c |    2 +-
 3 files changed, 22 insertions(+), 1 deletions(-)

Signed-off-by: Chuck Anderson <chuck.anderson@oracle.com>
13 years agobe2iscsi 4.1.239.0 [PATCH 04/10] Add pci_disable device
Chuck Anderson [Sat, 17 Dec 2011 04:04:56 +0000 (20:04 -0800)]
be2iscsi 4.1.239.0 [PATCH 04/10]  Add pci_disable device

Dec. 16, 2011
Oracle bugzilla 13257
Oracle bug 13465921
be2iscsi HBA driver v4.1.239.0 patch set for UEK R2(2.6.39)
jayamohan.kallickal@emulex.com

Ported driver version 4.1.239.0 to UEK2 2.6.39-100.0.17 (was 2.103.298.0)

Comments from the patch headers:

 Commit ID : 8dce69ff481a8d17a7d1027f23595083f28b4556
 [SCSI] be2iscsi: Add pci_disable device

   This patch adds call to pci_disable_device during
   rmmod and shutdown. The lack of this call was causing hang in
   insmod - rmmod loop test
---
 be_main.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

Signed-off-by: Chuck Anderson <chuck.anderson@oracle.com>
13 years agobe2iscsi 4.1.239.0 [PATCH 03/10] Adding a shutdown Routine
Chuck Anderson [Sat, 17 Dec 2011 04:04:19 +0000 (20:04 -0800)]
be2iscsi 4.1.239.0 [PATCH 03/10]  Adding a shutdown Routine

Dec. 16, 2011
Oracle bugzilla 13257
Oracle bug 13465921
be2iscsi HBA driver v4.1.239.0 patch set for UEK R2(2.6.39)
jayamohan.kallickal@emulex.com

Ported driver version 4.1.239.0 to UEK2 2.6.39-100.0.17 (was 2.103.298.0)

Comments from the patch headers:

 Commit ID : 25602c97f50e4b7fea84d2c81326dc5e372ca868
 [SCSI] be2iscsi: Adding a shutdown Routine

 This patch adds a shutdown routine. It fixes a bug where when be2net
 and be2iscsi are both used be2iscsi was not cleaning up its resources
 properly causing be2net to fail to get loaded when the system is
 rebooted.
---
 be_main.c |   38 ++++++++++++++++++++++++++++++--------
 1 files changed, 30 insertions(+), 8 deletions(-)

Signed-off-by: Chuck Anderson <chuck.anderson@oracle.com>
13 years agobe2iscsi 4.1.239.0 [PATCH 02/10] Fixing the /proc/interrupts problem V3
Chuck Anderson [Sat, 17 Dec 2011 04:03:30 +0000 (20:03 -0800)]
be2iscsi 4.1.239.0 [PATCH 02/10]  Fixing the /proc/interrupts problem V3

Dec. 16, 2011
Oracle bugzilla 13257
Oracle bug 13465921
be2iscsi HBA driver v4.1.239.0 patch set for UEK R2(2.6.39)
jayamohan.kallickal@emulex.com

Ported driver version 4.1.239.0 to UEK2 2.6.39-100.0.17 (was 2.103.298.0)

Comments from the patch headers:

 Commit ID : 8fcfb21073ea4f4261c8ee3ccd2fde8e281a4f28

 [SCSI] be2iscsi: Fixing the /proc/interrupts problem V3

 Fix be2iscsi driver to use a separate pointer for each irq action->name
 field and avoid display corruption in /proc/interrupts. The be2iscsi driver
 was using a single static array in a function for the irq action->name field.
 This results in garbage output from  /proc/interrupts

 The pointer for action->name is garbage and scribbles the output on the screen.

 This patch fixes the problem:

 156:          0          0          0          0          0          0
 0          0          0          0          0          0          0
 0          0          0          0          0          0          0
 0          0          0          0       PCI-MSI-X  beiscsi_msix_0017
---
 be_main.c |   34 ++++++++++++++++++++++++++--------
 be_main.h |    3 +++
 2 files changed, 29 insertions(+), 8 deletions(-)

Signed-off-by: Chuck Anderson <chuck.anderson@oracle.com>
13 years agobe2iscsi 4.1.239.0 [PATCH 01/10] Remove host and session casts
Chuck Anderson [Sat, 17 Dec 2011 03:01:28 +0000 (19:01 -0800)]
be2iscsi 4.1.239.0 [PATCH 01/10]   Remove host and session casts

Dec. 16, 2011
Oracle bugzilla 13257
Oracle bug 13465921
be2iscsi HBA driver v4.1.239.0 patch set for UEK R2(2.6.39)
jayamohan.kallickal@emulex.com

Ported driver version 4.1.239.0 to UEK2 2.6.39-100.0.17 (was 2.103.298.0)

Comments from the patch headers:

  Commit ID : 3093b0484d77ea774d74dfd7f5419831a716a9aa
  [SCSI] be2iscsi: remove host and session casts

  iscsi_session_to_shost is a macro around dev_to_shost which returns a
  Scsi_Host so there is no need to cast.

  iscsi_session_to_shost is a macro around shost_priv which
  returns a void pointer so no need to cast.
---
 be_iscsi.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)

Signed-off-by: Chuck Anderson <chuck.anderson@oracle.com>
13 years agoSPEC: v2.6.39-100.0.17
Maxim Uvarov [Wed, 16 Nov 2011 18:11:13 +0000 (10:11 -0800)]
SPEC: v2.6.39-100.0.17

Signed-off-by: Maxim Uvarov <maxim.uvarov@oracle.com>
13 years agoMerge branch 'uek2-stable' of ssh://ca-server1/home/mason/git/linux-uek-2.6.39 into...
Maxim Uvarov [Wed, 16 Nov 2011 18:04:24 +0000 (10:04 -0800)]
Merge branch 'uek2-stable' of ssh://ca-server1/home/mason/git/linux-uek-2.6.39 into uek2-stable-update

13 years agoBtrfs: fix tree corruption after multi-thread snapshots and inode_cache flush
Liu Bo [Tue, 15 Nov 2011 01:48:06 +0000 (20:48 -0500)]
Btrfs: fix tree corruption after multi-thread snapshots and inode_cache flush

The btrfs snapshotting code requires that once a root has been
snapshotted, we don't change it during a commit.

But there are two cases to lead to tree corruptions:

1) multi-thread snapshots can commit serveral snapshots in a transaction,
   and this may change the src root when processing the following pending
   snapshots, which lead to the former snapshots corruptions;

2) the free inode cache was changing the roots when it root the cache,
   which lead to corruptions.

This fixes things by making sure we force COW the block after we create a
snapshot during commiting a transaction, then any changes to the roots
will result in COW, and we get all the fs roots and snapshot roots to be
consistent.

Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit f1ebcc74d5b2159f44c96b479b6eb8afc7829095)

13 years agobtrfs: rename the option to nospace_cache
David Sterba [Fri, 11 Nov 2011 15:14:57 +0000 (10:14 -0500)]
btrfs: rename the option to nospace_cache

Rename no_space_cache option to nospace_cache to be more consistent with
the rest, where the simple prefix 'no' is used to negate an option.

The option has been introduced during the -rc1 cycle and there are has not been
widely used, so it's safe.

Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit 8965593e41dd2d0e2a2f1e6f245336005ea94a2c)

13 years agoBtrfs: handle bio_add_page failure gracefully in scrub
Arne Jansen [Fri, 11 Nov 2011 13:17:10 +0000 (08:17 -0500)]
Btrfs: handle bio_add_page failure gracefully in scrub

Currently scrub fails with ENOMEM when bio_add_page fails. Unfortunately
dm based targets accept only one page per bio, thus making scrub always
fails. This patch just submits the current bio when an error is encountered
and starts a new one.

Signed-off-by: Arne Jansen <sensille@gmx.net>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit 69f4cb526bd02ae5af35846f9a710c099eec3347)

13 years agoBtrfs: fix deadlock caused by the race between relocation
Miao Xie [Fri, 11 Nov 2011 01:45:05 +0000 (20:45 -0500)]
Btrfs: fix deadlock caused by the race between relocation

We can not do flushable reservation for the relocation when we create snapshot,
because it may make the transaction commit task and the flush task wait for
each other and the deadlock happens.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit 62f30c5462374b991e7e3f42d49ce2265c1b82f1)

13 years agoBtrfs: only map pages if we know we need them when reading the space cache
Josef Bacik [Fri, 11 Nov 2011 01:45:05 +0000 (20:45 -0500)]
Btrfs: only map pages if we know we need them when reading the space cache

People have been running into a warning when loading space cache because the
page is already mapped when trying to read in a bitmap.  The way we read in
entries and pages is kind of convoluted, so fix it so that io_ctl_read_entry
maps the entries if it needs to, and if it hits the end of the page it simply
unmaps the page.  That way we can unconditionally unmap the io_ctl before
reading in the bitmap and we should stop hitting these warnings.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit 2f120c05e67ae34c93786b1050c6828904314429)

13 years agoBtrfs: fix orphan backref nodes
Miao Xie [Fri, 11 Nov 2011 01:45:05 +0000 (20:45 -0500)]
Btrfs: fix orphan backref nodes

If the root node of a fs/file tree is in the block group that is
being relocated, but the others are not in the other block groups.
when we create a snapshot for this tree between the relocation tree
creation ends and ->create_reloc_tree is set to 0, Btrfs will create
some backref nodes that are the lowest nodes of the backrefs cache.
But we forget to add them into ->leaves list of the backref cache
and deal with them, and at last, they will triggered BUG_ON().

  kernel BUG at fs/btrfs/relocation.c:239!

This patch fixes it by adding them into ->leaves list of backref cache.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit 76b9e23d25d5c99f994bee3172de39492e452e93)

13 years agoBtrfs: Abstract similar code for btrfs_block_rsv_add{, _noflush}
Miao Xie [Fri, 11 Nov 2011 01:45:05 +0000 (20:45 -0500)]
Btrfs: Abstract similar code for btrfs_block_rsv_add{, _noflush}

btrfs_block_rsv_add{, _noflush}() have similar code, so abstract that code.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit 61b520a9d0083b9b361638e456af45fd75150c87)

13 years agoBtrfs: fix unreleased path in btrfs_orphan_cleanup()
Miao Xie [Fri, 11 Nov 2011 01:45:05 +0000 (20:45 -0500)]
Btrfs: fix unreleased path in btrfs_orphan_cleanup()

When we did stress test for the space relocation, the deadlock happened.
By debugging, We found it was caused by the carelessness that we forgot
to unlock the read lock of the extent buffers in btrfs_orphan_cleanup()
before we end the transaction handle, so the transaction commit task waited
the task, which called btrfs_orphan_cleanup(), to unlock the extent buffer,
but that task waited the commit task to end the transaction commit, and
the deadlock happened. Fix it.

Signed-ff-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit 3254c87618354e58fa2a7b375c6664f567480c33)

13 years agoBtrfs: fix no reserved space for writing out inode cache
Miao Xie [Fri, 11 Nov 2011 01:45:04 +0000 (20:45 -0500)]
Btrfs: fix no reserved space for writing out inode cache

I-node cache forgets to reserve the space when writing out it. And when
we do some stress test, such as synctest, it will trigger WARN_ON() in
use_block_rsv().

WARNING: at fs/btrfs/extent-tree.c:5718 btrfs_alloc_free_block+0xbf/0x281 [btrfs]()
...
Call Trace:
 [<ffffffff8104df86>] warn_slowpath_common+0x80/0x98
 [<ffffffff8104dfb3>] warn_slowpath_null+0x15/0x17
 [<ffffffffa0369c60>] btrfs_alloc_free_block+0xbf/0x281 [btrfs]
 [<ffffffff810cbcb8>] ? __set_page_dirty_nobuffers+0xfe/0x108
 [<ffffffffa035c040>] __btrfs_cow_block+0x118/0x3b5 [btrfs]
 [<ffffffffa035c7ba>] btrfs_cow_block+0x103/0x14e [btrfs]
 [<ffffffffa035e4c4>] btrfs_search_slot+0x249/0x6a4 [btrfs]
 [<ffffffffa036d086>] btrfs_lookup_inode+0x2a/0x8a [btrfs]
 [<ffffffffa03788b7>] btrfs_update_inode+0xaa/0x141 [btrfs]
 [<ffffffffa036d7ec>] btrfs_save_ino_cache+0xea/0x202 [btrfs]
 [<ffffffffa03a761e>] ? btrfs_update_reloc_root+0x17e/0x197 [btrfs]
 [<ffffffffa0373867>] commit_fs_roots+0xaa/0x158 [btrfs]
 [<ffffffffa03746a6>] btrfs_commit_transaction+0x405/0x731 [btrfs]
 [<ffffffff810690df>] ? wake_up_bit+0x25/0x25
 [<ffffffffa039d652>] ? btrfs_log_dentry_safe+0x43/0x51 [btrfs]
 [<ffffffffa0381c5f>] btrfs_sync_file+0x16a/0x198 [btrfs]
 [<ffffffff81122806>] ? mntput+0x21/0x23
 [<ffffffff8112d150>] vfs_fsync_range+0x18/0x21
 [<ffffffff8112d170>] vfs_fsync+0x17/0x19
 [<ffffffff8112d316>] do_fsync+0x29/0x3e
 [<ffffffff8112d348>] sys_fsync+0xb/0xf
 [<ffffffff81468352>] system_call_fastpath+0x16/0x1b

Sometimes it causes BUG_ON() in the reservation code of the delayed inode
is triggered.

So we must reserve enough space for inode cache.

Note: If we can not reserve the enough space for inode cache, we will
give up writing out it.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit ba38eb4de354d228f2792f93cde2c748a3a3f3b2)

13 years agoBtrfs: fix nocow when deleting the item
Miao Xie [Fri, 11 Nov 2011 01:45:04 +0000 (20:45 -0500)]
Btrfs: fix nocow when deleting the item

btrfs_previous_item() just search the b+ tree, do not COW the nodes or leaves,
if we modify the result of it, the meta-data will be broken. fix it.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit 924cd8fbe41851eda2b68bf2ed501b2777fd77b4)

13 years agoBtrfs: tweak the delayed inode reservations again
Chris Mason [Fri, 11 Nov 2011 01:39:08 +0000 (20:39 -0500)]
Btrfs: tweak the delayed inode reservations again

Josef sent along an incremental to the inode reservation
code to make sure we try and fall back to directly updating
the inode item if things go horribly wrong.

This reworks that patch slightly, adding a fallback function
that will always try to update the inode item directly without
going through the delayed_inode code.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit 2115133f8b9a8dbdb217d14080814df07ce90479)

13 years agoBtrfs: rework error handling in btrfs_mount()
Ilya Dryomov [Wed, 9 Nov 2011 12:41:22 +0000 (14:41 +0200)]
Btrfs: rework error handling in btrfs_mount()

Commits 6c41761f and 45ea6095 introduced the possibility of NULL pointer
dereference on error paths, also we would leave all devices busy and
leak fs_info with all sub-structures on error when trying to mount an
already mounted fs to a different directory.

Fix this by doing all allocations before trying to open any of the
devices, adjust error path for mount-already-mounted-fs case.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
(cherry picked from commit 04d21a244fdf79d0ac892eaaa9a46b682467277c)

13 years agoBtrfs: close devices on all error paths in open_ctree()
Ilya Dryomov [Wed, 9 Nov 2011 11:26:37 +0000 (13:26 +0200)]
Btrfs: close devices on all error paths in open_ctree()

Fix a bug introduced by 7e662854 where we would leave devices busy on
certain error paths in open_ctree().  fs_info is guaranteed to be
non-NULL now so it's safe to dereference it on all error paths.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
(cherry picked from commit 586e46e2813c589d26258a599580421fb6fb576b)

13 years agoBtrfs: avoid null dereference and leaks when bailing from open_ctree()
Ilya Dryomov [Tue, 8 Nov 2011 22:08:15 +0000 (00:08 +0200)]
Btrfs: avoid null dereference and leaks when bailing from open_ctree()

Fix bugs introduced by 6c41761f.  Firstly, after failing to allocate any
of the tree roots (first 'goto fail' in open_ctree()) we would
dereference a NULL fs_info pointer in free_fs_info().  Secondly, after
failures from init_srcu_struct(), setup_bdi() and new_inode() we would
leak all earlier allocated roots: fs_info fields haven't been
initialized yet so free_fs_info() is rendered useless.

Fix this by initializing fs_info pointer and fs_info fields before any
allocations happen.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
(cherry picked from commit 4d34b2789538befa45a68a191dc12e0886a69f7d)

13 years agoBtrfs: fix subvol_name leak on error in btrfs_mount()
Ilya Dryomov [Tue, 8 Nov 2011 17:15:05 +0000 (19:15 +0200)]
Btrfs: fix subvol_name leak on error in btrfs_mount()

btrfs_parse_early_options() can fail due to error while scanning devices
(-o device= option), but still strdup() subvol_name string:

mount -o subvol=SUBV,device=BAD_DEVICE <dev> <mnt>

So free subvol_name string on error.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
(cherry picked from commit f23c8af8ca2789eeb0ab9ea90c214f9694d96cc5)

13 years agoBtrfs: fix memory leak in btrfs_parse_early_options()
Ilya Dryomov [Tue, 8 Nov 2011 14:47:55 +0000 (16:47 +0200)]
Btrfs: fix memory leak in btrfs_parse_early_options()

Don't leak subvol_name string in case multiple subvol= options are
given.  "The lastest option is effective" behavior (consistent with
subvolid= and subvolrootid= options) is preserved.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
(cherry picked from commit a90e8b6fb80db43b029e1e76205452afa8bdc77a)

13 years agoBtrfs: fix our reservations for updating an inode when completing io
Josef Bacik [Tue, 8 Nov 2011 20:47:34 +0000 (15:47 -0500)]
Btrfs: fix our reservations for updating an inode when completing io

People have been reporting ENOSPC crashes in finish_ordered_io.  This is because
we try to steal from the delalloc block rsv to satisfy a reservation to update
the inode.  The problem with this is we don't explicitly save space for updating
the inode when doing delalloc.  This is kind of a problem and we've gotten away
with this because way back when we just stole from the delalloc reserve without
any questions, and this worked out fine because generally speaking the leaf had
been modified either by the mtime update when we did the original write or
because we just updated the leaf when we inserted the file extent item, only on
rare occasions had the leaf not actually been modified, and that was still ok
because we'd just use a block or two out of the over-reservation that is
delalloc.

Then came the delayed inode stuff.  This is amazing, except it wants a full
reservation for updating the inode since it may do it at some point down the
road after we've written the blocks and we have to recow everything again.  This
worked out because the delayed inode stuff just stole from the global reserve,
that is until recently when I changed that because it caused other problems.

So here we are, we're doing everything right and being screwed for it.  So take
an extra reservation for the inode at delalloc reservation time and carry it
through the life of the delalloc reservation.  If we need it we can steal it in
the delayed inode stuff.  If we have already stolen it try and do a normal
metadata reservation.  If that fails try to steal from the delalloc reservation.
If _that_ fails we'll get a WARN_ON() so I can start thinking of a better way to
solve this and in the meantime we'll steal from the global reserve.

With this patch I ran xfstests 13 in a loop for a couple of hours and didn't see
any problems.

Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit 7fd2ae21a42d178982679b86086661292b4afe4a)

13 years agoBtrfs: fix oops on NULL trans handle in btrfs_truncate
Chris Mason [Tue, 8 Nov 2011 19:49:59 +0000 (14:49 -0500)]
Btrfs: fix oops on NULL trans handle in btrfs_truncate

If we fail to reserve space in the transaction during truncate, we can
error out with a NULL trans handle.  The cleanup code needs an extra
check to make sure we aren't trying to use the bad handle.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit 917c16b2b69fc2eeb432eabca73258f08c58361e)

13 years agobtrfs: fix double-free 'tree_root' in 'btrfs_mount()'
slyich@gmail.com [Mon, 7 Nov 2011 21:08:01 +0000 (16:08 -0500)]
btrfs: fix double-free 'tree_root' in 'btrfs_mount()'

On error path 'tree_root' is treed in 'free_fs_info()'.
No need to free it explicitely. Noticed by SLUB in debug mode:

Complete reproducer under usermode linux (discovered on real
machine):

    bdev=/dev/ubda
    btr_root=/btr
    /mkfs.btrfs $bdev
    mount $bdev $btr_root
    mkdir $btr_root/subvols/
    cd $btr_root/subvols/
    /btrfs su cr foo
    /btrfs su cr bar
    mount $bdev -osubvol=subvols/foo $btr_root/subvols/bar
    umount $btr_root/subvols/bar

which gives

device fsid 4d55aa28-45b1-474b-b4ec-da912322195e devid 1 transid 7 /dev/ubda
=============================================================================
BUG kmalloc-2048: Object already free
-----------------------------------------------------------------------------

INFO: Allocated in btrfs_mount+0x389/0x7f0 age=0 cpu=0 pid=277
INFO: Freed in btrfs_mount+0x51c/0x7f0 age=0 cpu=0 pid=277
INFO: Slab 0x0000000062886200 objects=15 used=9 fp=0x0000000070b4d2d0 flags=0x4081
INFO: Object 0x0000000070b4d2d0 @offset=21200 fp=0x0000000070b4a968
...
Call Trace:
70b31948:  [<6008c522>] print_trailer+0xe2/0x130
70b31978:  [<6008c5aa>] object_err+0x3a/0x50
70b319a8:  [<6008e242>] free_debug_processing+0x142/0x2a0
70b319e0:  [<600ebf6f>] btrfs_mount+0x55f/0x7f0
70b319f8:  [<6008e5c1>] __slab_free+0x221/0x2d0

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
Cc: Arne Jansen <sensille@gmx.net>
Cc: Chris Mason <chris.mason@oracle.com>
Cc: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit 45ea6095c8f0d6caad5658306416a5d254f1205e)

13 years agoBtrfs: check for a null fs root when writing to the backup root log
Chris Mason [Sun, 6 Nov 2011 23:50:56 +0000 (18:50 -0500)]
Btrfs: check for a null fs root when writing to the backup root log

During log replay, can commit the transaction before the fs_root
pointers are setup, so we have to make sure they are not null before
trying to use them.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit 7c7e82a77fe3d89ae50824aa7c897454675eb4c4)

13 years agoBtrfs: fix race during transaction joins
Chris Mason [Sun, 6 Nov 2011 08:26:19 +0000 (03:26 -0500)]
Btrfs: fix race during transaction joins

While we're allocating ram for a new transaction, we drop our spinlock.
When we get the lock back, we do check to see if a transaction started
while we slept, but we don't check to make sure it isn't blocked
because a commit has already started.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit d43317dcd074818d4bd12ddd4184a29aff98907b)

13 years agoBtrfs: fix a potential btrfs_bio leak on scrub fixups
Ilya Dryomov [Fri, 4 Nov 2011 13:41:02 +0000 (09:41 -0400)]
Btrfs: fix a potential btrfs_bio leak on scrub fixups

In case we were able to map less than we wanted (length < PAGE_SIZE
clause is true) btrfs_bio is still allocated and we have to free it.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit 56d2a48f81a1bde827c625b90221fade72fe9c61)

13 years agoBtrfs: rename btrfs_bio multi -> bbio for consistency
Ilya Dryomov [Fri, 4 Nov 2011 13:41:02 +0000 (09:41 -0400)]
Btrfs: rename btrfs_bio multi -> bbio for consistency

Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit 21ca543efc12674fddb22ddf4ea4906427f4e982)

13 years agoBtrfs: stop leaking btrfs_bios on readahead
Ilya Dryomov [Fri, 4 Nov 2011 13:41:02 +0000 (09:41 -0400)]
Btrfs: stop leaking btrfs_bios on readahead

Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit 9510dc4c62252e96dca44a94948327c76774f25b)

13 years agoBtrfs: fix delayed insertion reservation
Josef Bacik [Fri, 4 Nov 2011 23:56:02 +0000 (19:56 -0400)]
Btrfs: fix delayed insertion reservation

We all keep getting those stupid warnings from use_block_rsv when running
stress.sh, and it's because the delayed insertion stuff is being stupid.  It's
not the delayed insertion stuffs fault, it's all just stupid.  When marking an
inode dirty for oh say updating the time on it, we just do a
btrfs_join_transaction, which doesn't reserve any space.  This is stupid because
we're going to have to have space reserve to make this change, but we do it
because it's fast because chances are we're going to call it over and over again
and it doesn't matter.  Well thanks to the delayed insertion stuff this is
mostly the case, so we do actually need to make this reservation.  So if
trans->bytes_reserved is 0 then try to do a normal reservation.  If not return
ENOSPC which will make the btrfs_dirty_inode start a proper transaction which
will let it do the whole ENOSPC dance and reserve enough space for the delayed
insertion to steal the reservation from the transaction.

The other stupid thing we do is not reserve space for the inode when writing to
the thing.  Usually this is ok since we have to update the time so we'd have
already done all this work before we get to the endio stuff, so it doesn't
matter.  But this is stupid because we could write the data after the
transaction commits where we changed the mtime of the inode so we have to cow
all the way down to the inode anyway.  This used to be masked by the delalloc
reservation stuff, but because we delay the update it doesn't get masked in this
case.  So again the delayed insertion stuff bites us in the ass.  So if our
trans->block_rsv is delalloc, just steal the reservation from the delalloc
reserve.  Hopefully this won't bite us in the ass, but I've said that before.

With this patch stress.sh no longer spits out those stupid warnings (famous last
words).  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit c06a0e120a4e381a1c291c1fce3c6155c5791cae)

13 years agoBtrfs: ClearPageError during writepage and clean_tree_block
Chris Mason [Fri, 4 Nov 2011 16:29:37 +0000 (12:29 -0400)]
Btrfs: ClearPageError during writepage and clean_tree_block

Failure testing was tripping up over stale PageError bits in
metadata pages.  If we have an io error on a block, and later on
end up reusing it, nobody ever clears PageError on those pages.

During commit, we'll find PageError and think we had trouble writing
the block, which will lead to aborts and other problems.

This changes clean_tree_block and the btrfs writepage code to
clear the PageError bit.  In both cases we're either completely
done with the page or the page has good stuff and the error bit
is no longer valid.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit bf0da8c183a15656eee63c54f334c3794320872a)

13 years agoBtrfs: be smarter about committing the transaction in reserve_metadata_bytes
Josef Bacik [Fri, 4 Nov 2011 02:54:25 +0000 (22:54 -0400)]
Btrfs: be smarter about committing the transaction in reserve_metadata_bytes

Because of the overcommit stuff I had to make it so that we committed the
transaction all the time in reserve_metadata_bytes in case we had overcommitted
because of delayed items.  This was because previously we had no way of knowing
how much space was reserved for delayed items.  Now that we have the
delayed_block_rsv we can check it to see if committing the transaction would get
us anywhere.  This patch breaks out the committing logic into a helper function
that will check to see if committing the transaction would free enough space for
us to get anything done.  With this patch xfstests 83 goes from taking 445
seconds to taking 28 seconds on my box.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit 663350ac38c67ca388acea6e876dc6d668c232b0)

13 years agoBtrfs: make a delayed_block_rsv for the delayed item insertion
Josef Bacik [Fri, 4 Nov 2011 02:54:25 +0000 (22:54 -0400)]
Btrfs: make a delayed_block_rsv for the delayed item insertion

I've been hitting warnings in use_block_rsv when running the delayed insertion
stuff.  It's because we will readjust global block rsv based on what is in use,
which means we could end up discarding reservations that are for the delayed
insertion stuff.  So instead create a seperate block rsv for the delayed
insertion stuff.  This will also make it easier to debug problems with the
delayed insertion reservations since we will know that only the delayed
insertion code touches this block_rsv.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit 6d668dda0caec537fbf28c4d91e6d18181af3cff)

13 years agoBtrfs: add a log of past tree roots
Chris Mason [Thu, 3 Nov 2011 19:17:42 +0000 (15:17 -0400)]
Btrfs: add a log of past tree roots

This takes some of the free space in the btrfs super block
to record information about most of the roots in the last four
commits.

It also adds a -o recovery to use the root history log when
we're not able to read the tree of tree roots, the extent
tree root, the device tree root or the csum root.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit af31f5e5b84b5bf2bcec464153a5130b170b2770 with conflicts)

13 years agobtrfs: separate superblock items out of fs_info
David Sterba [Wed, 13 Apr 2011 13:41:04 +0000 (15:41 +0200)]
btrfs: separate superblock items out of fs_info

fs_info has now ~9kb, more than fits into one page. This will cause
mount failure when memory is too fragmented. Top space consumers are
super block structures super_copy and super_for_commit, ~2.8kb each.
Allocate them dynamically. fs_info will be ~3.5kb. (measured on x86_64)

Add a wrapper for freeing fs_info and all of it's dynamically allocated
members.

Signed-off-by: David Sterba <dsterba@suse.cz>
(cherry picked from commit 6c41761fc6efe1503103a1afe03a6635c0b5d4ec)

13 years agoBtrfs: use the global reserve when truncating the free space cache inode
Josef Bacik [Wed, 2 Nov 2011 13:29:35 +0000 (09:29 -0400)]
Btrfs: use the global reserve when truncating the free space cache inode

We no longer use the orphan block rsv for holding the reservation for truncating
the inode, so instead use the global block rsv and check to make sure it has
enough space for us to truncate the space.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit c8174313a8102e874aaa321e2fc4c7c460a87151)

13 years agoBtrfs: release metadata from global reserve if we have to fallback for unlink
Josef Bacik [Tue, 1 Nov 2011 18:32:23 +0000 (14:32 -0400)]
Btrfs: release metadata from global reserve if we have to fallback for unlink

I fixed a problem where we weren't reserving space for an orphan item when we
had to fallback to using the global reserve for an unlink, but I introduced
another problem.  I was migrating the bytes from the transaction reserve to the
global reserve and then releasing from the global reserve in
btrfs_end_transaction().  The problem with this is that a migrate will jack up
the size for the destination, but leave the size alone for the source, with the
idea that you can do a release normally on the source and it all washes out, and
then you can do a release again on the destination and it works out right.  My
way was skipping the release on the trans_block_rsv which still had the jacked
up size from our original reservation.  So instead release manually from the
global reserve if this transaction was using it, and then set the
trans->block_rsv back to the trans_block_rsv so that btrfs_end_transaction
cleans everything up properly.  With this patch xfstest 83 doesn't emit warnings
about leaking space.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit 5a77d76c243be18d854aa1b14d697525f60e169a)

13 years agoBtrfs: make sure to flush queued bios if write_cache_pages waits
Chris Mason [Tue, 1 Nov 2011 14:08:06 +0000 (10:08 -0400)]
Btrfs: make sure to flush queued bios if write_cache_pages waits

write_cache_pages tries to build up a large bio to stuff down the pipe.
But if it needs to wait for a page lock, it needs to make sure and send
down any pending writes so we don't deadlock with anyone who has the
page lock and is waiting for writeback of things inside the bio.

Dave Sterba triggered this as a deadlock between the autodefrag code and
the extent write_cache_pages

Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit 01d658f2ca3c85c1ffb20b306e30d16197000ce7)

13 years agoBtrfs: fix extent pinning bugs in the tree log
Chris Mason [Tue, 1 Nov 2011 00:52:39 +0000 (20:52 -0400)]
Btrfs: fix extent pinning bugs in the tree log

The tree log had two important bugs that could cause corruptions after a
crash.  Sometimes we were allowing tree log blocks to be reused after
the tree log was committed but before the transaction commit was done.

This allowed a future metadata write to overwrite the tree log data.  It
is fixed by adding a new variant of freeing reserved extents that always
pins them.  Credit goes to Stefan Behrens and Arne Jansen for many many
hours spent tracking this bug down.

During tree log replay, we do a pass through the tree log and pin all
the extents we find.  This makes sure the replay code won't go in and
use any of those blocks for new allocations during replay.  The problem
is the free space cache isn't honoring these pinned extents.  So the
allocator can end up handing them out, leading to all kinds of problems
during replay.

The fix here is to force any free space cache to load while we pin the
extents, and then to make sure we remove the pinned extents from the
free space rbtree.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
Reported-by: Stefan Behrens <sbehrens@giantdisaster.de>
(cherry picked from commit e688b7252f784c2479d559f9f70ca8354752c5e7)

13 years agoBtrfs: make sure btrfs_remove_free_space doesn't leak EAGAIN
Chris Mason [Fri, 14 Oct 2011 10:31:20 +0000 (06:31 -0400)]
Btrfs: make sure btrfs_remove_free_space doesn't leak EAGAIN

btrfs_remove_free_space needs to make sure to set ret back to a
valid return value after setting it to EAGAIN, otherwise we return
it to the callers.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit 1eae31e918972bbeefc119d23c1d67674f49a301)

13 years agoBtrfs: don't wait as long for more batches during SSD log commit
Chris Mason [Thu, 20 Oct 2011 19:45:37 +0000 (15:45 -0400)]
Btrfs: don't wait as long for more batches during SSD log commit

When we're doing log commits, we try to wait for more writers to come in
and make the commit bigger.  This helps improve performance on rotating
disks, but on SSDs it adds latencies.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit cd354ad613a393424f85333ceed6b15e07fb94ae)

13 years agobtrfs: ratelimit WARN_ON in use_block_rsv
David Sterba [Tue, 14 Jun 2011 10:52:17 +0000 (12:52 +0200)]
btrfs: ratelimit WARN_ON in use_block_rsv

The WARN_ON under some circumstances heavily polute log and slow down
the machine. This is just a safety, as the warning should be fixed by
another patch, nevertheless, it still pops up during testing.

Signed-off-by: David Sterba <dsterba@suse.cz>
(cherry picked from commit dff51cd1c60856c28f5d22a571294c2b70b6b322)

13 years agobtrfs: do not allow mounting non-subvolumes via subvol option
David Sterba [Thu, 29 Sep 2011 11:11:33 +0000 (13:11 +0200)]
btrfs: do not allow mounting non-subvolumes via subvol option

There's a missing test whether the path passed to subvol=path option
during mount is a real subvolume, allowing any directory located in
default subovlume to be passed and accepted for mount.

(current btrfs progs prevent this early)
$ btrfs subvol snapshot . p1-snap
ERROR: '.' is not a subvolume

(with "is subvolume?" test bypassed)
$ btrfs subvol snapshot . p1-snap
Create a snapshot of '.' in './p1-snap'

$ btrfs subvol list -p .
ID 258 parent 5 top level 5 path subvol
ID 259 parent 5 top level 5 path subvol1
ID 260 parent 5 top level 5 path default-subvol1
ID 262 parent 5 top level 5 path p1/p1-snapshot
ID 263 parent 259 top level 5 path subvol1/subvol1-snap

The problem I see is that this makes a false impression of snapshotting the
given subvolume but in fact snapshots the default one: a user expects outcome
like ID 263 but in fact gets ID 262 .

This patch makes mount fail with EINVAL with a message in syslog.

Signed-off-by: David Sterba <dsterba@suse.cz>
(cherry picked from commit f9d9ef62cd3ecbd6cbb7957a253c1e81f69d5586)

13 years agoBtrfs: close all bdevs on mount failure
Ilya Dryomov [Wed, 19 Oct 2011 21:06:20 +0000 (00:06 +0300)]
Btrfs: close all bdevs on mount failure

Fix a bug introduced by 20b45077.  We have to return EINVAL on mount
failure, but doing that too early in the sequence leaves all of the
devices opened exclusively.  This also fixes an issue where under some
scenarios only a second mount -o degraded <devices> command would
succeed.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
(cherry picked from commit 20bcd64934e4eb8f3f90a0dca54fb0ac2edd7795)

13 years agoBtrfs: fix a bug when opening seed devices
Ilya Dryomov [Wed, 12 Oct 2011 21:20:43 +0000 (00:20 +0300)]
Btrfs: fix a bug when opening seed devices

Initialize fs_info->bdev_holder a bit earlier to be able to pass a
correct holder id to blkdev_get() when opening seed devices with O_EXCL.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
(cherry picked from commit 5f524444c351e145a5f7e28253594688a421bfe8)

13 years agobtrfs: fix oops on failure path
Daniel J Blueman [Thu, 23 Jun 2011 15:01:01 +0000 (23:01 +0800)]
btrfs: fix oops on failure path

If lookup_extent_backref fails, path->nodes[0] reasonably could be
null along with other callers of btrfs_print_leaf, so ensure we have a
valid extent buffer before dereferencing.

Signed-off-by: Daniel J Blueman <daniel.blueman@gmail.com>
(cherry picked from commit 068132bad1de70f85f5f6d12c36d64f8f7848d92)

13 years agoBtrfs: fix race between multi-task space allocation and caching space
Miao Xie [Fri, 9 Sep 2011 09:34:35 +0000 (17:34 +0800)]
Btrfs: fix race between multi-task space allocation and caching space

The task may fail to get free space though it is enough when multi-task
space allocation and caching space happen at the same time.

Task1 Caching Thread Task2
------------------------------------------------------------------------
find_free_extent
  The space has not
  be cached, and start
  caching thread. And
  wait for it.
cache space, if
the space is > 2MB
wake up Task1
find_free_extent
  get all the space that
  is cached.
  try to allocate space,
  but there is no space
  now.
trigger BUG_ON()

The message is following:
btrfs allocation failed flags 1, wanted 4096
space_info has 1040187392 free, is not full
space_info total=1082130432, used=4096, pinned=41938944, reserved=0, may_use=40828928, readonly=0
block group 12582912 has 8388608 bytes, 0 used 8388608 pinned 0 reserved
block group has cluster?: no
0 blocks of free space at or bigger than bytes is
block group 1103101952 has 1073741824 bytes, 4096 used 33550336 pinned 0 reserved
block group has cluster?: no
0 blocks of free space at or bigger than bytes is
------------[ cut here ]------------
kernel BUG at fs/btrfs/inode.c:835!
 [<ffffffffa031261b>] __extent_writepage+0x1bf/0x5ce [btrfs]
 [<ffffffff810cbcb8>] ? __set_page_dirty_nobuffers+0xfe/0x108
 [<ffffffffa02f8ada>] ? wait_current_trans+0x23/0xec [btrfs]
 [<ffffffff810c3fbf>] ? find_get_pages_tag+0x73/0xe2
 [<ffffffffa0312d12>] extent_write_cache_pages.clone.0+0x176/0x29a [btrfs]
 [<ffffffffa0312e74>] extent_writepages+0x3e/0x53 [btrfs]
 [<ffffffff8110ad2c>] ? do_sync_write+0xc6/0x103
 [<ffffffffa0302d6e>] ? btrfs_submit_direct+0x414/0x414 [btrfs]
 [<ffffffff811380fa>] ? fsnotify+0x236/0x266
 [<ffffffffa02fc930>] btrfs_writepages+0x22/0x24 [btrfs]
 [<ffffffff810cc215>] do_writepages+0x1c/0x25
 [<ffffffff810c4958>] __filemap_fdatawrite_range+0x4e/0x50
 [<ffffffff810c4982>] filemap_write_and_wait_range+0x28/0x51
 [<ffffffffa0306b2e>] btrfs_sync_file+0x7d/0x198 [btrfs]
 [<ffffffff8110aa26>] ? fsnotify_modify+0x5d/0x65
 [<ffffffff8112d150>] vfs_fsync_range+0x18/0x21
 [<ffffffff8112d170>] vfs_fsync+0x17/0x19
 [<ffffffff8112d316>] do_fsync+0x29/0x3e
 [<ffffffff8112d348>] sys_fsync+0xb/0xf
 [<ffffffff81468352>] system_call_fastpath+0x16/0x1b
[SNIP]
RIP  [<ffffffffa02fe08c>] cow_file_range+0x1c4/0x32b [btrfs]

We fix this bug by trying to allocate the space again if there are block groups
in caching.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
(cherry picked from commit 60d2adbb1e7fee1cb4bc67f70bd0bd8ace7b6c3c)

13 years agoBtrfs: fix return value of btrfs_get_acl()
Tsutomu Itoh [Thu, 6 Oct 2011 04:37:08 +0000 (13:37 +0900)]
Btrfs: fix return value of btrfs_get_acl()

In btrfs_get_acl(), when the second __btrfs_getxattr() call fails,
acl is not correctly set.
Therefore, a wrong value might return to the caller.

Signed-off-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
(cherry picked from commit cfbffc39ac89dbd5197cbeec2599a1128eb928f8)

13 years agoBtrfs: pass the correct root to lookup_free_space_inode()
Ilya Dryomov [Sun, 2 Oct 2011 10:56:53 +0000 (13:56 +0300)]
Btrfs: pass the correct root to lookup_free_space_inode()

Free space items are located in tree of tree roots, not in the extent
tree.  It didn't pop up because lookup_free_space_inode() grabs the
inode all the time instead of actually searching the tree.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
(cherry picked from commit 10b2f34d6e7fbe07f498cb2006272e9a561f5e60)

13 years agoBtrfs: do not set EXTENT_DIRTY along with EXTENT_DELALLOC
Liu Bo [Thu, 29 Sep 2011 07:55:28 +0000 (15:55 +0800)]
Btrfs: do not set EXTENT_DIRTY along with EXTENT_DELALLOC

Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
(cherry picked from commit fee187d9d9ddc382c81370a9a280391132dea2e1)

13 years agoBtrfs: fix direct-io vs nodatacow
Li Zefan [Thu, 8 Sep 2011 02:26:51 +0000 (10:26 +0800)]
Btrfs: fix direct-io vs nodatacow

To reproduce the bug:

  # mount -o nodatacow /dev/sda7 /mnt/
  # dd if=/dev/zero of=/mnt/tmp bs=4K count=1
  1+0 records in
  1+0 records out
  4096 bytes (4.1 kB) copied, 0.000136115 s, 30.1 MB/s
  # dd if=/dev/zero of=/mnt/tmp bs=4K count=1 conv=notrunc oflag=direct
  dd: writing `/mnt/tmp': Input/output error
  1+0 records in
  0+0 records out

btrfs_ordered_update_i_size() may return 1, but btrfs_endio_direct_write()
mistakenly takes it as an error.

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
(cherry picked from commit f0dd9592a1aa014b3a01aa2be7e795aae040d65b)

13 years agoBtrfs: remove BUG_ON() in compress_file_range()
Li Zefan [Thu, 8 Sep 2011 02:22:01 +0000 (10:22 +0800)]
Btrfs: remove BUG_ON() in compress_file_range()

It's not a big deal if we fail to allocate the array, and instead of
panic we can just give up compressing.

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
(cherry picked from commit 560f7d75457f86a43970aa413e334e394082dce4)

13 years agoBtrfs: fix array bound checking
Li Zefan [Tue, 6 Sep 2011 08:55:34 +0000 (16:55 +0800)]
Btrfs: fix array bound checking

Otherwise we can execced the array bound of path->slots[].

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
(cherry picked from commit a05a9bb18ae0abec0b513b5fde876c47905fa13e)

13 years agobtrfs: return EINVAL if start > total_bytes in fitrim ioctl
Lukas Czerner [Mon, 5 Sep 2011 14:34:54 +0000 (16:34 +0200)]
btrfs: return EINVAL if start > total_bytes in fitrim ioctl

We should retirn EINVAL if the start is beyond the end of the file
system in the btrfs_ioctl_fitrim(). Fix that by adding the appropriate
check for it.

Also in the btrfs_trim_fs() it is possible that len+start might overflow
if big values are passed. Fix it by decrementing the len so that start+len
is equal to the file system size in the worst case.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
(cherry picked from commit f4c697e6406da5dd445eda8d923c53e1138793dd)

13 years agoBtrfs: honor extent thresh during defragmentation
Li Zefan [Fri, 2 Sep 2011 07:57:07 +0000 (15:57 +0800)]
Btrfs: honor extent thresh during defragmentation

We won't defrag an extent, if it's bigger than the threshold we
specified and there's no small extent before it, but actually
the code doesn't work this way.

There are three bugs:

- When should_defrag_range() decides we should keep on defragmenting
  an extent, last_len is not incremented. (old bug)

- The length that passes to should_defrag_range() is not the length
  we're going to defrag. (new bug)

- We always defrag 256K bytes data, and a big extent can be part of
  this range. (new bug)

For a file with 4 extents:

        | 4K | 4K | 256K | 256K |

The result of defrag with (the default) 256K extent thresh should be:

        | 264K | 256K |

but with those bugs, we'll get:

        | 520K |

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
(cherry picked from commit 008873eafbc77deb1702aedece33756c58486c6a)

13 years agobtrfs: trivial fix, a potential memory leak in btrfs_parse_early_options()
Jeff Liu [Wed, 14 Sep 2011 06:11:21 +0000 (14:11 +0800)]
btrfs: trivial fix, a potential memory leak in btrfs_parse_early_options()

Signed-off-by: Jie Liu <jeff.liu@oracle.com>
(cherry picked from commit 83c8c9bde0add721f7509aa446455183b040b931)

13 years agoBtrfs: fix wrong max_to_defrag in btrfs_defrag_file()
Li Zefan [Fri, 2 Sep 2011 07:56:55 +0000 (15:56 +0800)]
Btrfs: fix wrong max_to_defrag in btrfs_defrag_file()

It's off-by-one, and thus we may skip the last page while defragmenting.

An example case:

  # create /mnt/file with 2 4K file extents
  # btrfs fi defrag /mnt/file
  # sync
  # filefrag /mnt/file
  /mnt/file: 2 extents found

So it's not defragmented.

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
(cherry picked from commit 5ca496604b5975d371bb669ee6c2394bcbea818f)

13 years agoBtrfs: use i_size_read() in btrfs_defrag_file()
Li Zefan [Fri, 2 Sep 2011 07:56:39 +0000 (15:56 +0800)]
Btrfs: use i_size_read() in btrfs_defrag_file()

Don't use inode->i_size directly, since we're not holding i_mutex.

This also fixes another bug, that i_size can change after it's checked
against 0 and then (i_size - 1) can be negative.

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
(cherry picked from commit 151a31b25e5c941bdd9fdefed650effca223c716)

13 years agoBtrfs: fix defragmentation regression
Li Zefan [Fri, 2 Sep 2011 07:56:25 +0000 (15:56 +0800)]
Btrfs: fix defragmentation regression

There's an off-by-one bug:

  # create a file with lots of 4K file extents
  # btrfs fi defrag /mnt/file
  # sync
  # filefrag -v /mnt/file
  Filesystem type is: 9123683e
  File size of /mnt/file is 1228800 (300 blocks, blocksize 4096)
   ext logical physical expected length flags
     0       0     3372              64
     1      64     3136     3435      1
     2      65     3436     3136     64
     3     129     3201     3499      1
     4     130     3500     3201     64
     5     194     3266     3563      1
     6     195     3564     3266     64
     7     259     3331     3627      1
     8     260     3628     3331     40 eof

After this patch:

  ...
  # filefrag -v /mnt/file
  Filesystem type is: 9123683e
  File size of /mnt/file is 1228800 (300 blocks, blocksize 4096)
   ext logical physical expected length flags
     0       0     3372             300 eof
  /mnt/file: 1 extent found

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
(cherry picked from commit cbcc83265d929ac71553c1b5dafdb830171af947)

13 years agobtrfs: fix memory leak in btrfs_defrag_file
Diego Calleja [Thu, 1 Sep 2011 14:33:57 +0000 (16:33 +0200)]
btrfs: fix memory leak in btrfs_defrag_file

kmemleak found this:
unreferenced object 0xffff8801b64af968 (size 512):
  comm "btrfs-cleaner", pid 3317, jiffies 4306810886 (age 903.272s)
  hex dump (first 32 bytes):
    00 82 01 07 00 ea ff ff c0 83 01 07 00 ea ff ff  ................
    80 82 01 07 00 ea ff ff c0 87 01 07 00 ea ff ff  ................
  backtrace:
    [<ffffffff816875cc>] kmemleak_alloc+0x5c/0xc0
    [<ffffffff8114aec3>] kmem_cache_alloc_trace+0x163/0x240
    [<ffffffff8127a290>] btrfs_defrag_file+0xf0/0xb20
    [<ffffffff8125d9a5>] btrfs_run_defrag_inodes+0x165/0x210
    [<ffffffff812479d7>] cleaner_kthread+0x177/0x190
    [<ffffffff81075c7d>] kthread+0x8d/0xa0
    [<ffffffff816af5f4>] kernel_thread_helper+0x4/0x10
    [<ffffffffffffffff>] 0xffffffffffffffff

"pages" is not always freed. Fix it removing the unnecesary additional return.

Signed-off-by: Diego Calleja <diegocg@gmail.com>
(cherry picked from commit 60ccf82f5b6e26e10d41783464ca469c070c7d49)

13 years agobtrfs: check file extent backref offset underflow
Yan, Zheng [Mon, 29 Aug 2011 01:25:53 +0000 (09:25 +0800)]
btrfs: check file extent backref offset underflow

Offset field in data extent backref can underflow if clone range ioctl
is used. We can reliably detect the underflow because max file size is
limited to 2^63 and max data extent size is limited by block group size.

Signed-off-by: Zheng Yan <zheng.z.yan@intel.com>
(cherry picked from commit 84850e8d8a5ec7b9d3c47d224e9a10c9da52ff1b)

13 years agoBtrfs: don't flush the cache inode before writing it
Josef Bacik [Wed, 19 Oct 2011 14:31:37 +0000 (10:31 -0400)]
Btrfs: don't flush the cache inode before writing it

I noticed we had a little bit of latency when writing out the space cache
inodes.  It's because we flush it before we write anything in case we have dirty
pages already there.  This doesn't matter though since we're just going to
overwrite the space, and there really shouldn't be any dirty pages anyway.  This
makes some of my tests run a little bit faster.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 016fc6a63e465d5b94e4028f6d05d9703e195428)

13 years agoBtrfs: if we have a lot of pinned space, commit the transaction
Josef Bacik [Tue, 18 Oct 2011 17:07:31 +0000 (13:07 -0400)]
Btrfs: if we have a lot of pinned space, commit the transaction

Mitch kept hitting a panic because he was getting ENOSPC.  One of my previous
patches makes it so we are much better at not allocating new metadata chunks.
Unfortunately coupled with the overcommit patch this works us into a bit of a
problem if we are removing a bunch of space and end up chewing up all of our
space with pinned extents.  We can allocate chunks fine and overflow is ok, but
the only way to reclaim this space is to commit the transaction.  So if we go to
overcommit, first check and see how much pinned space we have.  If we have more
than 80% of the free space chewed up with pinned extents, just commit the
transaction, this will free up enough space for our reservation and we won't
have this problem anymore.  With this patch Mitch's test doesn't blow up
anymore.  Thanks,

Reported-and-tested-by: Mitch Harder <mitch.harder@sabayonlinux.org>
Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 7e355b83efa80e5f5821591c13c17649594d82ac)

13 years agoBtrfs: seperate out btrfs_block_rsv_check out into 2 different functions
Josef Bacik [Tue, 18 Oct 2011 16:15:48 +0000 (12:15 -0400)]
Btrfs: seperate out btrfs_block_rsv_check out into 2 different functions

Currently btrfs_block_rsv_check does 2 things, it will either refill a block
reserve like in the truncate or refill case, or it will check to see if there is
enough space in the global reserve and possibly refill it.  However because of
overcommit we could be well overcommitting ourselves just to try and refill the
global reserve, when really we should just be committing the transaction.  So
breack this out into btrfs_block_rsv_refill and btrfs_block_rsv_check.  Refill
will try to reserve more metadata if it can and btrfs_block_rsv_check will not,
it will only tell you if the factor of the total space is still reserved.
Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 36ba022ac0b748dd543f43430b03198e899426c9)

13 years agoBtrfs: reserve some space for an orphan item when unlinking
Josef Bacik [Fri, 14 Oct 2011 18:46:51 +0000 (14:46 -0400)]
Btrfs: reserve some space for an orphan item when unlinking

In __unlink_start_trans() if we don't have enough room for a reservation we will
check to see if the unlink will free up space.  If it does that's great, but we
will still could add an orphan item, so we need to reserve enough space to add
the orphan item.  Do this and migrate the space the global reserve so it all
works out right.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 3880a1b46d87a6b030c31889875befc745d95dff)

13 years agoBtrfs: release trans metadata bytes before flushing delayed refs
Josef Bacik [Fri, 14 Oct 2011 18:40:17 +0000 (14:40 -0400)]
Btrfs: release trans metadata bytes before flushing delayed refs

We started setting trans->block_rsv = NULL to allow the delayed refs flushing
stuff to use the right block_rsv and then just made
btrfs_trans_release_metadata() unconditionally use the trans block rsv.  The
problem with this is we need to reserve some space in the transaction and then
migrate it to the global block rsv, so we need to be able to free that out
properly.  So instead just move btrfs_trans_release_metadata() before the
delayed ref flushing and use trans->block_rsv for the freeing.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit b24e03db0df3e9164c9649db12fecc8c2d81b0d1)

13 years agoBtrfs: allow shrink_delalloc flush the needed reclaimed pages
Josef Bacik [Fri, 14 Oct 2011 18:02:10 +0000 (14:02 -0400)]
Btrfs: allow shrink_delalloc flush the needed reclaimed pages

Currently we only allow a maximum of 2 megabytes of pages to be flushed at a
time.  This was ok before, but now we have overcommit which will screw us in a
heartbeat if we are quickly filling the disk.  So instead pick either 2
megabytes or the number of pages we need to reclaim to be safe again, which ever
is larger.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 877da174301dde9062b915da4c8103048be49702)

13 years agoBtrfs: wait for ordered extents if we're in trouble when shrinking delalloc
Josef Bacik [Fri, 14 Oct 2011 17:56:58 +0000 (13:56 -0400)]
Btrfs: wait for ordered extents if we're in trouble when shrinking delalloc

The only way we actually reclaim delalloc space is waiting for the IO to
completely finish.  Usually we kick off a bunch of IO and wait for a little bit
and hope we can make our reservation, and usually this works out pretty well.
With overcommit however we can get seriously underwater if we're filling up the
disk quickly, so we need to be able to force the delalloc shrinker to wait for
the ordered IO to finish to give us a better chance of actually reclaiming
enough space to get our reservation.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit f104d044376aadcee74605d66b8d9dc2e145782c)

13 years agoBtrfs: don't check bytes_pinned to determine if we should commit the transaction
Josef Bacik [Fri, 14 Oct 2011 17:37:45 +0000 (13:37 -0400)]
Btrfs: don't check bytes_pinned to determine if we should commit the transaction

Before the only reason to commit the transaction to recover space in
reserve_metadata_bytes() was if there were enough pinned_bytes to satisfy our
reservation.  But now we have the delayed inode stuff which will hold it's
reservations until we commit the transaction.  So say we max out our reservation
by creating a bunch of files but don't have any pinned bytes we will ENOSPC out
early even though we could commit the transaction and get that space back.  So
now just unconditionally commit the transaction since currently there is no way
to know how much metadata space is being reserved by delayed inode stuff.
Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit bbb495c2ed9d34894cb3d6d366866fc92a2e1adc)

13 years agoBtrfs: fix regression in re-setting a large xattr
Josef Bacik [Thu, 13 Oct 2011 17:09:22 +0000 (13:09 -0400)]
Btrfs: fix regression in re-setting a large xattr

Recently I changed the xattr stuff to unconditionally set the xattr first in
case the xattr didn't exist yet.  This has introduced a regression when setting
an xattr that already exists with a large value.  If we find the key we are
looking for split_leaf will assume that we're extending that item.  The problem
is the size we pass down to btrfs_search_slot includes the size of the item
already, so if we have the largest xattr we can possibly have plus the size of
the xattr item plus the xattr item that btrfs_search_slot we'd overflow the
leaf.  Thankfully this is not what we're doing, but split_leaf doesn't know this
so it just returns EOVERFLOW.  So in the xattr code we need to check and see if
we got back EOVERFLOW and treat it like EEXIST since that's really what
happened.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit ed3ee9f44ba55eb6acfbfc8caa881e0253710d2a)

13 years agoBtrfs: fix the amount of space reserved for unlink
Josef Bacik [Tue, 11 Oct 2011 18:18:24 +0000 (14:18 -0400)]
Btrfs: fix the amount of space reserved for unlink

Our unlink reservations were a bit much, we were reserving 10 and I only count 8
possible items we're touching, so comment what we're reserving for and fix the
count value.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit e70bea5fe0e3d6355fd95674eaff5aa5a32f0564)

13 years agoBtrfs: wait for ordered extents if we didn't reclaim enough
Josef Bacik [Fri, 7 Oct 2011 15:55:34 +0000 (11:55 -0400)]
Btrfs: wait for ordered extents if we didn't reclaim enough

I noticed recently that my overcommit patch was causing one of my enospc tests
to fail 25% of the time with early ENOSPC.  This is because my overcommit patch
was letting us go way over board, but it wasn't waiting long enough to let the
delalloc shrinker do it's job.  The problem is we just start writeback and wait
a little bit hoping we flush enough, but we only free up delalloc space by
having the writes complete all the way.  We do this by waiting for ordered
extents, which we do but only if we already free'd enough for the reservation,
which isn't right, we should flush ordered extents if we didn't reclaim enough
in case that will push us over the edge.  With this patch I've not seen a
failure in this enospc test after running it in a loop for an hour.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 4b91c14f913f649d4302b3677b85c4ce87a3d8e7)

13 years agoBtrfs: inline checksums into the disk free space cache
Josef Bacik [Thu, 6 Oct 2011 12:58:24 +0000 (08:58 -0400)]
Btrfs: inline checksums into the disk free space cache

Yeah yeah I know this is how we used to do it and then I changed it, but damnit
I'm changing it back.  The fact is that writing out checksums will modify
metadata, which could cause us to dirty a block group we've already written out,
so we have to truncate it and all of it's checksums and re-write it which will
write new checksums which could dirty a blockg roup that has already been
written and you see where I'm going with this?  This can cause unmount or really
anything that depends on a transaction to commit to take it's sweet damned time
to happen.  So go back to the way it was, only this time we're specifically
setting NODATACOW because we can't go through the COW pathway anyway and we're
doing our own built-in cow'ing by truncating the free space cache.  The other
new thing is once we truncate the old cache and preallocate the new space, we
don't need to do that song and dance at all for the rest of the transaction, we
can just overwrite the existing space with the new cache if the block group
changes for whatever reason, and the NODATACOW will let us do this fine.  So
keep track of which transaction we last cleared our cache in and if we cleared
it in this transaction just say we're all setup and carry on.  This survives
xfstests and stress.sh.

The inode cache will continue to use the normal csum infrastructure since it
only gets written once and there will be no more modifications to the fs tree in
a transaction commit.

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 5b0e95bf607ddd59b39f52d3d55e6581c817b530)

13 years agoBtrfs: take overflow into account in reserving space
Josef Bacik [Wed, 5 Oct 2011 20:35:28 +0000 (16:35 -0400)]
Btrfs: take overflow into account in reserving space

My overcommit stuff can be a little racy when we're filling up the disk with
fs_mark and we overcommit into things that quickly get used up for data.  So use
num_bytes to see if we have enough available space so we're less likely to
overcommit ourselves out of the ability to make reservations.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 9a82ca659d8bfd99afc0e89bbde2202322df5755)

13 years agoBtrfs: check the return value of filemap_write_and_wait in the space cache
Josef Bacik [Wed, 5 Oct 2011 20:33:53 +0000 (16:33 -0400)]
Btrfs: check the return value of filemap_write_and_wait in the space cache

We need to check the return value of filemap_write_and_wait in the space cache
writeout code.  Also don't set the inode's generation until we're sure nothing
else is going to fail.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 549b4fdb8f3c0708bbc0ee12ff955cd206c0f60c)

13 years agoBtrfs: add a io_ctl struct and helpers for dealing with the space cache
Josef Bacik [Wed, 5 Oct 2011 19:18:58 +0000 (15:18 -0400)]
Btrfs: add a io_ctl struct and helpers for dealing with the space cache

In writing and reading the space cache we have one big loop that keeps track of
which page we are on and then a bunch of sizeable loops underneath this big loop
to try and read/write out properly.  Especially in the write case this makes
things hugely complicated and hard to follow, and makes our error checking and
recovery equally as complex.  So add a io_ctl struct with a bunch of helpers to
keep track of the pages we have, where we are, if we have enough space etc.
This unifies how we deal with the pages we're writing and keeps all the messy
tracking internal.  This allows us to kill the big loops in both the read and
write case and makes reviewing and chaning the write and read paths much
simpler.  I've run xfstests and stress.sh on this code and it survives.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit a67509c30079f4c5025fb19ea443fb2906c3a85e)

13 years agoBtrfs: don't skip writing out a empty block groups cache
Josef Bacik [Wed, 5 Oct 2011 14:00:18 +0000 (10:00 -0400)]
Btrfs: don't skip writing out a empty block groups cache

I noticed a slight bug where we will not bother writing out the block group
cache's space cache if it's space tree is empty.  Since it could have a cluster
or pinned extents that need to be written out this is just not a valid test.
Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit f75b130e9bb361850787e156c79311adb84f551e)

13 years agoBtrfs: introduce mount option no_space_cache
Josef Bacik [Mon, 3 Oct 2011 18:07:49 +0000 (14:07 -0400)]
Btrfs: introduce mount option no_space_cache

Some users have requested this and I've found I needed a way to disable cache
loading without actually clearing the cache, so introduce the no_space_cache
option.  Before we check the super blocks cache generation field and if it was
populated we always turned space caching on.  Now we check this and set the
space cache option on, and then parse the mount options so that if we want it
off it get's turned off.  Then we check the mount option all the places we do
the caching work instead of checking the super's cache generation.  This makes
things more consistent and lets us turn space caching off.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 73bc187680f94bed498f8a669103cad290e41180)

13 years agoBtrfs: only inherit btrfs specific flags when creating files
Josef Bacik [Tue, 27 Sep 2011 15:01:30 +0000 (11:01 -0400)]
Btrfs: only inherit btrfs specific flags when creating files

Xfstests 79 was failing because we were inheriting the S_APPEND flag when we
weren't supposed to.  There isn't any specific documentation on this so I'm
taking the test as the standard of how things work, and having S_APPEND set on a
directory doesn't mean that S_APPEND gets inherited by its children according to
this test.  So only inherit btrfs specific things.  This will let us set
compress/nocompress on specific directories and everything in the directories
will inherit this flag, same with nodatacow.  With this patch test 79 passes.
Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit e27425d614d68daa08f60735982a7c3a0230e855)

13 years agoBtrfs: allow us to overcommit our enospc reservations
Josef Bacik [Mon, 26 Sep 2011 21:12:22 +0000 (17:12 -0400)]
Btrfs: allow us to overcommit our enospc reservations

One of the things that kills us is the fact that our ENOSPC reservations are
horribly over the top in most normal cases.  There isn't too much that can be
done about this because when we are completely full we really need them to work
like this so we don't under reserve.  However if there is plenty of unallocated
chunks on the disk we can use that to gauge how much we can overcommit.  So this
patch adds chunk free space accounting so we always know how much unallocated
space we have.  Then if we fail to make a reservation within our allocated
space, check to see if we can overcommit.  In the normal flushing case (like
with delalloc metadata reservations) we'll take the free space and divide it by
2 if our metadata profile is setup for DUP or any of those, and then divide it
by 8 to make sure we don't overcommit too much.  Then if we're in a non-flushing
case (we really need this reservation now!) we only limit ourselves to half of
the free space.  This makes this fio test

[torrent]
filename=torrent-test
rw=randwrite
size=4g
ioengine=sync
directory=/mnt/btrfs-test

go from taking around 45 minutes to 10 seconds on my freshly formatted 3 TiB
file system.  This doesn't seem to break my other enospc tests, but could really
use some more testing as this is a super scary change.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 2bf64758fd6290797a5ce97d4b9c698a4ed1cbad)

13 years agoBtrfs: break out of orphan cleanup if we can't make progress
Josef Bacik [Mon, 26 Sep 2011 19:55:20 +0000 (15:55 -0400)]
Btrfs: break out of orphan cleanup if we can't make progress

I noticed while running xfstests 83 that if we didn't have enough space to
delete our inode the orphan cleanup would just loop.  This is because it keeps
finding the same orphan item and keeps trying to kill it but can't because we
don't get an error back from iput for deleting the inode.  So keep track of the
last guy we tried to kill, if it's the same as the one we're trying to kill
currently we know we are having problems and can just error out.  I don't have a
way to test this so look hard and make sure it's right.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 8f6d7f4f45f18a5b669dbbf068c74b3d5be59dbf)

13 years agoBtrfs: use the global reserve as a backup for deleting inodes
Josef Bacik [Mon, 26 Sep 2011 19:46:06 +0000 (15:46 -0400)]
Btrfs: use the global reserve as a backup for deleting inodes

Xfstests 83 really stresses our ENOSPC since it uses a 100mb fs which ends up
with the mixed block group stuff.  Because of this we can run into a situation
where we don't have enough space to delete inodes, or even worse we can't free
the inodes when we next mount the fs which causes the orphan code to lose its
mind.  So if we fail to make our reservation, steal from the global reserve.
The global reserve will end up taking up the entire rest of the free space on
the fs in this worst case so there really is no other option.  With this patch
test 83 doesn't freak out.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 726c35fa0edf1d9b8a88b73255532e73089aedda)

13 years agoBtrfs: stop using write_one_page
Josef Bacik [Mon, 26 Sep 2011 17:58:47 +0000 (13:58 -0400)]
Btrfs: stop using write_one_page

While looking for a performance regression a user was complaining about, I
noticed that we had a regression with the varmail test of filebench.  This was
introduced by

0d10ee2e6deb5c8409ae65b970846344897d5e4e

which keeps us from calling writepages in writepage.  This is a correct change,
however it happens to help the varmail test because we write out in larger
chunks.  This is largly to do with how we write out dirty pages for each
transaction.  If you run filebench with

load varmail
set $dir=/mnt/btrfs-test
run 60

prior to this patch you would get ~1420 ops/second, but with the patch you get
~1200 ops/second.  This is a 16% decrease.  So since we know the range of dirty
pages we want to write out, don't write out in one page chunks, write out in
ranges.  So to do this we call filemap_fdatawrite_range() on the range of bytes.
Then we convert the DIRTY extents to NEED_WAIT extents.  When we then call
btrfs_wait_marked_extents() we only have to filemap_fdatawait_range() on that
range and clear the NEED_WAIT extents.  This doesn't get us back to our original
speeds, but I've been seeing ~1380 ops/second, which is a <5% regression as
opposed to a >15% regression.  That is acceptable given that the original commit
greatly reduces our latency to begin with.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 1728366efa5ebf48bd2ed544afa8700cd07ba822 with conflicts)

13 years agoBtrfs: introduce convert_extent_bit
Josef Bacik [Mon, 26 Sep 2011 17:56:12 +0000 (13:56 -0400)]
Btrfs: introduce convert_extent_bit

If I have a range where I know a certain bit is and I want to set it to another
bit the only option I have is to call set and then clear bit, which will result
in 2 tree searches.  This is inefficient, so introduce convert_extent_bit which
will go through and set the bit I want and clear the old bit I don't want.
Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 462d6fac8960a3ba797927adfcbd29d503eb16fd)

13 years agoBtrfs: check unused against how much space we actually want
Josef Bacik [Thu, 22 Sep 2011 18:30:02 +0000 (14:30 -0400)]
Btrfs: check unused against how much space we actually want

There is a bug that may lead to early ENOSPC in our reservation code.  We've
been checking against num_bytes which may be above and beyond what we want to
actually reserve, which could give us a false ENOSPC.  Fix this by making sure
the unused space is above how much we want to reserve and not how much we're
trying to flush.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit ef3be45722317f8c2fb0e861065df0c3830ff9ac)

13 years agoBtrfs: fix orphan cleanup regression
Josef Bacik [Wed, 21 Sep 2011 20:55:59 +0000 (16:55 -0400)]
Btrfs: fix orphan cleanup regression

In fixing how we deal with bad inodes, we had a regression in the orphan cleanup
code, since it expects to get a bad inode back.  So fix it to deal with getting
-ESTALE back by deleting the orphan item manually and moving on.  Thanks,

Reported-by: Simon Kirby <sim@hostway.ca>
Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit a8c9e5769718d47e87cce40c9b84cab421804797)

13 years agoBtrfs: use the inode's mapping mask for allocating pages
Josef Bacik [Wed, 21 Sep 2011 19:05:58 +0000 (15:05 -0400)]
Btrfs: use the inode's mapping mask for allocating pages

Johannes pointed out we were allocating only kernel pages for doing writes,
which is kind of a big deal if you are on 32bit and have more than a gig of ram.
So fix our allocations to use the mapping's gfp but still clear __GFP_FS so we
don't re-enter.  Thanks,

Reported-by: Johannes Weiner <jweiner@redhat.com>
Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 3b16a4e3c355ee3c790473decfcf83d4faeb8ce0)

13 years agoBtrfs: delay iput when deleting a block group
Josef Bacik [Mon, 19 Sep 2011 16:26:24 +0000 (12:26 -0400)]
Btrfs: delay iput when deleting a block group

I kept getting warnings from evict because we were calling
btrfs_start_transaction() with a transaction already started when doing a
balance.  This is because we remove a block group which requires a transaction,
and the put the last reference on the cache inode.  Instead of doing this we
need to delay the iput so it is done not within a transaction having started.
This gets rid of our warnings.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 455757c322cc0a0f2a692c5625dd88aaf6a7b889)

13 years agoBtrfs: make sure to unset trans->block_rsv before running delayed refs
Josef Bacik [Mon, 19 Sep 2011 15:58:54 +0000 (11:58 -0400)]
Btrfs: make sure to unset trans->block_rsv before running delayed refs

Checksums are charged in 2 different ways.  The first case is when we're writing
to the disk, we account for the new checksums with the delalloc block rsv.  In
order for this to work we check if we're allocating a block for the csum root
and if trans->block_rsv == the delalloc block rsv.  But when we're deleting the
csums because of cow, this is charged to the global block rsv, and is done when
we run the delayed refs.  So we need to make sure that trans->block_rsv == NULL
when running the delayed refs.  So set it to NULL and reset it in
should_end_transaction, and set it to NULL in commit_transaction.  This got rid
of the ridiculous amount of warnings I was seeing when trying to do a balance.
Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 9c8d86db9aee6f85866d480e0f9b37817264814c)

13 years agoBtrfs: stop passing a trans handle all around the reservation code
Josef Bacik [Tue, 30 Aug 2011 16:34:28 +0000 (12:34 -0400)]
Btrfs: stop passing a trans handle all around the reservation code

The only thing that we need to have a trans handle for is in
reserve_metadata_bytes and thats to know how much flushing we can do.  So
instead of passing it around, just check current->journal_info for a
trans_handle so we know if we can commit a transaction to try and free up space
or not.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 4a92b1b8d2810db4ea0c34616b94c0b3810fa027)

13 years agoBtrfs: don't get the block_rsv in btrfs_free_tree_block
Josef Bacik [Tue, 30 Aug 2011 15:40:48 +0000 (11:40 -0400)]
Btrfs: don't get the block_rsv in btrfs_free_tree_block

Since the durable block rsv stuff has been killed there is no need to get the
block_rsv in btrfs_free_tree_block anymore.

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit d02c9955ded7fc56dd1edc987558b084ccb03eb4)

13 years agoBtrfs: use the transactions block_rsv for the csum root
Josef Bacik [Tue, 30 Aug 2011 15:31:29 +0000 (11:31 -0400)]
Btrfs: use the transactions block_rsv for the csum root

The alloc warnings everybody has been seeing is because we have been reserving
space for csums, but we weren't actually using that space.  So make
get_block_rsv() return the trans->block_rsv if we're modifying the csum root.
Also set the trans->block_rsv to NULL so that if we modify the csum root when
running delayed ref's that comes out of the global reserve like it's supposed
to.  With this patch I'm not seeing those alloc warnings anymore.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 4c13d758b7e79c14a0026c1f783f0c79e339b7bb)

13 years agoBtrfs: handle enospc accounting for free space inodes
Josef Bacik [Tue, 30 Aug 2011 14:19:10 +0000 (10:19 -0400)]
Btrfs: handle enospc accounting for free space inodes

Since free space inodes now use normal checksumming we need to make sure to
account for their metadata use.  So reserve metadata space, and then if we fail
to write out the metadata we can just release it, otherwise it will be freed up
when the io completes.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit c09544e07f8cdc455ed8615d4c067d694c33bd18)

13 years agoBtrfs: put the block group cache after we commit the super
Josef Bacik [Mon, 29 Aug 2011 18:06:00 +0000 (14:06 -0400)]
Btrfs: put the block group cache after we commit the super

In moving some enospc stuff around I noticed that when we unmount we are often
evicting the free space cache inodes before we do our last commit.  This isn't
bad, but it makes us constantly have to re-read the inodes back.  So instead
don't evict the cache until after we do our last commit, this will make things a
little less crappy and makes a future enospc change work properly.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 300e4f8a56f263797568c95b71c949f9f02e4534)