]> git.karo-electronics.de Git - karo-tx-linux.git/log
karo-tx-linux.git
12 years agoBtrfs: fix tree mod log del_ptr
Jan Schmidt [Thu, 31 May 2012 13:02:32 +0000 (15:02 +0200)]
Btrfs: fix tree mod log del_ptr

Logging for del_ptr when we're not deleting the last pointer was wrong. This
fixes both, duplicate log entries and log sequence.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
12 years agoBtrfs: add tree_mod_dont_log helper
Jan Schmidt [Thu, 31 May 2012 12:59:09 +0000 (14:59 +0200)]
Btrfs: add tree_mod_dont_log helper

Replace duplicate code by small inline helper function.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
12 years agoBtrfs: add missing spin_lock for insertion into tree mod log
Jan Schmidt [Thu, 31 May 2012 12:00:15 +0000 (14:00 +0200)]
Btrfs: add missing spin_lock for insertion into tree mod log

tree_mod_alloc calls __get_tree_mod_seq and must acquire a spinlock before
doing so.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
12 years agoBtrfs: add inodes before dropping the extent lock in find_all_leafs
Jan Schmidt [Wed, 30 May 2012 16:05:21 +0000 (18:05 +0200)]
Btrfs: add inodes before dropping the extent lock in find_all_leafs

We must build up the inode list with the extent lock held after following
indirect refs.

This also requires an extension to ulists, which allows to modify the stored
aux value in case a key already exists in the list.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
12 years agoBtrfs: use delayed ref sequence numbers for all fs-tree updates
Jan Schmidt [Tue, 29 May 2012 15:06:54 +0000 (17:06 +0200)]
Btrfs: use delayed ref sequence numbers for all fs-tree updates

The sequence number for delayed refs is needed to postpone certain delayed
refs for a very short period while walking backrefs. Before the tree
modification log, we thought we'd only have to hold back those references
that don't have a counter operation.

While now we've the tree mod log, we're rewinding fs tree blocks to a
defined consistent state. We cannot know in advance for which tree block
we'll be doing rewind operations later. Therefore, we must postpone all the
delayed refs for fs-tree blocks, even those having a counter operation.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
12 years agoBtrfs: tree mod log sanity checks in join_transaction
Jan Schmidt [Sun, 20 May 2012 13:43:53 +0000 (15:43 +0200)]
Btrfs: tree mod log sanity checks in join_transaction

When a fresh transaction begins, the tree mod log must be clean. Users of
the tree modification log must ensure they never span across transaction
boundaries.

We reset the sequence to 0 in this safe situation to make absolutely sure
overflow can't happen.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
12 years agoBtrfs: fs_info variable for join_transaction
Jan Schmidt [Sun, 20 May 2012 13:42:19 +0000 (15:42 +0200)]
Btrfs: fs_info variable for join_transaction

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
12 years agoBtrfs: use the tree modification log for backref resolving
Jan Schmidt [Wed, 16 May 2012 16:36:03 +0000 (18:36 +0200)]
Btrfs: use the tree modification log for backref resolving

This enables backref resolving on life trees while they are changing. This
is a prerequisite for quota groups and just nice to have for everything
else.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
12 years agoBtrfs: add btrfs_search_old_slot
Jan Schmidt [Wed, 16 May 2012 16:25:47 +0000 (18:25 +0200)]
Btrfs: add btrfs_search_old_slot

The tree modification log together with the current state of the tree gives
a consistent, old version of the tree. btrfs_search_old_slot is used to
search through this old version and return old (dummy!) extent buffers.
Naturally, this function cannot do any tree modifications.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
12 years agoBtrfs: add del_ptr and insert_ptr modifications to the tree mod log
Jan Schmidt [Sat, 26 May 2012 09:45:21 +0000 (11:45 +0200)]
Btrfs: add del_ptr and insert_ptr modifications to the tree mod log

Record all relevant modifications to block pointers in the tree mod log so
that we can rewind them later on for backref walking.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
12 years agoBtrfs: put all block modifications into the tree mod log
Jan Schmidt [Sat, 26 May 2012 09:43:17 +0000 (11:43 +0200)]
Btrfs: put all block modifications into the tree mod log

When running functions that can make changes to the internal trees
(e.g. btrfs_search_slot), we check if somebody may be interested in the
block we're currently modifying. If so, we record our modification to be
able to rewind it later on.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
12 years agoBtrfs: add tree modification log functions
Jan Schmidt [Wed, 16 May 2012 15:18:50 +0000 (17:18 +0200)]
Btrfs: add tree modification log functions

The tree mod log will log modifications made fs-tree nodes. Most
modifications are done by autobalance of the tree. Such changes are recorded
as long as a block entry exists. When released, the log is cleaned.

With the tree modification log, it's possible to reconstruct a consistent
old state of the tree. This is required to do backref walking on a busy
file system.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
12 years agoBtrfs: add tree mod log to fs_info
Jan Schmidt [Wed, 16 May 2012 15:55:38 +0000 (17:55 +0200)]
Btrfs: add tree mod log to fs_info

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
12 years agoBtrfs: dummy extent buffers for tree mod log
Jan Schmidt [Wed, 16 May 2012 15:00:02 +0000 (17:00 +0200)]
Btrfs: dummy extent buffers for tree mod log

The tree modification log needs two ways to create dummy extent buffers,
once by allocating a fresh one (to rebuild an old root) and once by
cloning an existing one (to make private rewind modifications) to it.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
12 years agoBtrfs: move struct seq_list to ctree.h
Jan Schmidt [Wed, 16 May 2012 14:57:09 +0000 (16:57 +0200)]
Btrfs: move struct seq_list to ctree.h

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
12 years agoBtrfs: don't set for_cow parameter for tree block functions
Jan Schmidt [Wed, 16 May 2012 15:04:52 +0000 (17:04 +0200)]
Btrfs: don't set for_cow parameter for tree block functions

Three callers of btrfs_free_tree_block or btrfs_alloc_tree_block passed
parameter for_cow = 1. In fact, these two functions should never mark
their tree modification operations as for_cow, because they can change
the number of blocks referenced by a tree.

Hence, we remove the extra for_cow parameter from these functions and
make them pass a zero down.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
12 years agoBtrfs: look into the extent during find_all_leafs
Jan Schmidt [Thu, 17 May 2012 14:43:03 +0000 (16:43 +0200)]
Btrfs: look into the extent during find_all_leafs

Before this patch we called find_all_leafs for a data extent, then called
find_all_roots and then looked into the extent to grab the information
we were seeking. This was done without holding the leaves locked to avoid
deadlocks. However, this can obviouly race with concurrent tree
modifications.

Instead, we now look into the extent while we're holding the lock during
find_all_leafs and store this information together with the leaf list.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
12 years agoBtrfs: bugfix: ignore the wrong key for indirect tree block backrefs
Jan Schmidt [Tue, 15 May 2012 15:55:51 +0000 (17:55 +0200)]
Btrfs: bugfix: ignore the wrong key for indirect tree block backrefs

The key we store with a tree block backref is only a hint. It is set when
the ref is created and can remain correct for a long time. As the tree is
rebalanced, however, eventually the key no longer points to the correct
destination.

With this patch, we change find_parent_nodes to no longer add keys unless it
knows for sure they're correct (e.g. because they're for an extent data
backref). Then when we later encounter a backref ref with no parent and no
key set, we grab the block and take the first key from the block itself.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
12 years agoBtrfs: bugfix in btrfs_find_parent_nodes
Jan Schmidt [Tue, 22 May 2012 11:43:25 +0000 (13:43 +0200)]
Btrfs: bugfix in btrfs_find_parent_nodes

That one has been around since the addition of backref.c. Due to the way we
calculate our slot numbers, after adding inline refs we're missing one keyed
ref unless it's located at the beginning of a new leaf.

Reported-by: Alexander Block <ablock84@googlemail.com>
Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
12 years agoBtrfs: ulist realloc bugfix
Jan Schmidt [Tue, 22 May 2012 12:56:50 +0000 (14:56 +0200)]
Btrfs: ulist realloc bugfix

ulist_next gets the pointer to the previously returned element to find the
next element from there. However, when we call ulist_add while iteration
with ulist_next is in progress (ulist explicitly supports this), we can
realloc the ulist internal memory, which makes the pointer to the previous
element useless.

Instead, we now use an iterator parameter that's independent from the
internal pointers.

Reported-by: Alexander Block <ablock84@googlemail.com>
Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
12 years agoBtrfs: avoid sleeping in verify_parent_transid while atomic
Chris Mason [Sun, 6 May 2012 11:23:47 +0000 (07:23 -0400)]
Btrfs: avoid sleeping in verify_parent_transid while atomic

verify_parent_transid needs to lock the extent range to make
sure no IO is underway, and so it can safely clear the
uptodate bits if our checks fail.

But, a few callers are using it with spinlocks held.  Most
of the time, the generation numbers are going to match, and
we don't want to switch to a blocking lock just for the error
case.  This adds an atomic flag to verify_parent_transid,
and changes it to return EAGAIN if it needs to block to
properly verifiy things.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: fix crash in scrub repair code when device is missing
Stefan Behrens [Fri, 4 May 2012 19:16:07 +0000 (15:16 -0400)]
Btrfs: fix crash in scrub repair code when device is missing

Fix that when scrub tries to repair an I/O or checksum error and one of
the devices containing the mirror is missing, it crashes in bio_add_page
because the bdev is a NULL pointer for missing devices.

Reported-by: Marco L. Crociani <marco.crociani@gmail.com>
Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agobtrfs: Fix mismatching struct members in ioctl.h
Alexander Block [Fri, 4 May 2012 19:16:06 +0000 (15:16 -0400)]
btrfs: Fix mismatching struct members in ioctl.h

Fix the size members of btrfs_ioctl_ino_path_args and
btrfs_ioctl_logical_ino_args. The user space btrfs-progs utilities used
__u64 and the kernel headers used __u32 before.

Signed-off-by: Alexander Block <ablock84@googlemail.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: fix page leak when allocing extent buffers
Josef Bacik [Fri, 4 May 2012 19:16:06 +0000 (15:16 -0400)]
Btrfs: fix page leak when allocing extent buffers

If we happen to alloc a extent buffer and then alloc a page and notice that
page is already attached to an extent buffer, we will only unlock it and
free our existing eb.  Any pages currently attached to that eb will be
properly freed, but we don't do the page_cache_release() on the page where
we noticed the other extent buffer which can cause us to leak pages and I
hope cause the weird issues we've been seeing in this area.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: Add properly locking around add_root_to_dirty_list
Chris Mason [Thu, 3 May 2012 16:08:48 +0000 (12:08 -0400)]
Btrfs: Add properly locking around add_root_to_dirty_list

add_root_to_dirty_list happens once at the very beginning of the
transaction, but it is still racey.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: reduce lock contention during extent insertion
Chris Mason [Fri, 27 Apr 2012 18:31:29 +0000 (14:31 -0400)]
Btrfs: reduce lock contention during extent insertion

We're spending huge amounts of time on lock contention during
end_io processing because we unconditionally assume we are overwriting
an existing extent in the file for each IO.

This checks to see if we are outside i_size, and if so, it uses a
less expensive readonly search of the btree to look for existing
extents.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: avoid deadlocks from GFP_KERNEL allocations during btrfs_real_readdir
Chris Mason [Fri, 27 Apr 2012 18:23:22 +0000 (14:23 -0400)]
Btrfs: avoid deadlocks from GFP_KERNEL allocations during btrfs_real_readdir

Btrfs has an optimization where it will preallocate dentries during
readdir to fill in enough information to open the inode without an extra
lookup.

But, we're calling d_alloc, which is doing GFP_KERNEL allocations, and
that leads to deadlocks because our readdir code has tree locks held.

For now, disable this optimization.  We'll fix the gfp mask in the next
merge window.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: Fix space checking during fs resize
Daniel J Blueman [Fri, 27 Apr 2012 16:41:46 +0000 (12:41 -0400)]
Btrfs: Fix space checking during fs resize

Fix out-of-space checking, addressing a warning and potential resource
leak when resizing the filesystem down while allocating blocks.

Signed-off-by: Daniel J Blueman <daniel@quora.org>
Reviewed-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: fix block_rsv and space_info lock ordering
Stefan Behrens [Fri, 27 Apr 2012 16:41:46 +0000 (12:41 -0400)]
Btrfs: fix block_rsv and space_info lock ordering

may_commit_transaction() calls
        spin_lock(&space_info->lock);
        spin_lock(&delayed_rsv->lock);
and update_global_block_rsv() calls
        spin_lock(&block_rsv->lock);
        spin_lock(&sinfo->lock);

Lockdep complains about this at run time.
Everywhere except in update_global_block_rsv(), the space_info lock is
the outer lock, therefore the locking order in update_global_block_rsv()
is changed.

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: Prevent root_list corruption
Daniel J Blueman [Fri, 27 Apr 2012 16:41:46 +0000 (12:41 -0400)]
Btrfs: Prevent root_list corruption

I was seeing root_list corruption on unmount during fs resize in 3.4-rc4; add
correct locking to address this.

Signed-off-by: Daniel J Blueman <daniel@quora.org>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: fix repair code for RAID10
Jan Schmidt [Fri, 27 Apr 2012 16:41:45 +0000 (12:41 -0400)]
Btrfs: fix repair code for RAID10

btrfs_map_block sets mirror_num, so that the repair code knows eventually
which device gave us the read error. For RAID10, mirror_num must be 1 or 2.
Before this fix mirror_num was incorrectly related to our stripe index.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: do not start delalloc inodes during sync
Josef Bacik [Tue, 24 Apr 2012 00:35:03 +0000 (20:35 -0400)]
Btrfs: do not start delalloc inodes during sync

btrfs_start_delalloc_inodes will just walk the list of delalloc inodes and
start writing them out, but it doesn't splice the list or anything so as
long as somebody is doing work on the box you could end up in this section
_forever_.  So just remove it, it's not needed anyway since sync will start
writeback on all inodes anyway, all we need to do is wait for ordered
extents and then we can commit the transaction.  In my horrible torture test
sync goes from taking 4 minutes to about 1.5 minutes.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: fix that check_int_data mount option was ignored
Stefan Behrens [Fri, 30 Mar 2012 11:58:32 +0000 (13:58 +0200)]
Btrfs: fix that check_int_data mount option was ignored

The bitfield member mount_opt was too small by one bit to hold the mount
option that enabled to include data extents in the integrity checker.
Since the same issue happened when the BTRFS_MOUNT_PANIC_ON_FATAL_ERROR
option was added (git rebase silently merges so that the increase of the
size of the bitfield member is lost), the bit limit was removed entirely.

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
12 years agoBtrfs: don't count CRC or header errors twice while scrubbing
Stefan Behrens [Fri, 30 Mar 2012 11:58:31 +0000 (13:58 +0200)]
Btrfs: don't count CRC or header errors twice while scrubbing

Each CRC or header error was counted twice, this is now fixed.

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
12 years agoBtrfs: fix btrfs_ioctl_dev_info() crash on missing device
Stefan Behrens [Mon, 19 Mar 2012 15:17:22 +0000 (16:17 +0100)]
Btrfs: fix btrfs_ioctl_dev_info() crash on missing device

When a filesystem is mounted with the degraded option, it is
possible that some of the devices are not there.
btrfs_ioctl_dev_info() crashs in this case because the device
name is a NULL pointer. This ioctl was only used for scrub.

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
12 years agobtrfs: don't return EINTR
Arne Jansen [Wed, 18 Apr 2012 08:27:16 +0000 (10:27 +0200)]
btrfs: don't return EINTR

It is basically a good thing if we are interruptible when waiting for
free space, but the generality in which it is implemented currently
leads to system calls being interruptible that are not documented this
way. For example git can't handle interrupted unlink(), leading to
corrupt repos under space pressure.
Instead we raise the bar to only be interruptible by SIGKILL.
Thanks to David Sterba for suggesting this.

Signed-off-by: Arne Jansen <sensille@gmx.net>
12 years agoBtrfs: double unlock bug in error handling
Dan Carpenter [Wed, 18 Apr 2012 06:59:03 +0000 (09:59 +0300)]
Btrfs: double unlock bug in error handling

The caller expects this function to return with the lock held and
releases it immediately on error.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
12 years agoBtrfs: always store the mirror we read the eb from
Josef Bacik [Mon, 16 Apr 2012 13:42:26 +0000 (09:42 -0400)]
Btrfs: always store the mirror we read the eb from

A user reported a panic where we were trying to fix a bad mirror but the
mirror number we were giving was 0, which is invalid.  This is because we
don't do the transid verification until after the read, so as far as the
read code is concerned the read was a success.  So instead store the mirror
we read from so that if there is some failure post read we know which mirror
to try next and which mirror needs to be fixed if we find a good copy of the
block.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
12 years agofs/btrfs/volumes.c: add missing free_fs_devices
Julia Lawall [Sat, 14 Apr 2012 09:24:33 +0000 (11:24 +0200)]
fs/btrfs/volumes.c: add missing free_fs_devices

Free fs_devices as done in the error-handling code just below.

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
12 years agobtrfs: fix early abort in 'remount'
Sergei Trofimovich [Mon, 16 Apr 2012 03:44:37 +0000 (06:44 +0300)]
btrfs: fix early abort in 'remount'

Cc: Jeff Mahoney <jeffm@suse.com>
Cc: Chris Mason <chris.mason@oracle.com>
Cc: Josef Bacik <josef@redhat.com>
Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
12 years agoBtrfs: fix max chunk size check in chunk allocator
Ilya Dryomov [Fri, 13 Apr 2012 14:05:08 +0000 (17:05 +0300)]
Btrfs: fix max chunk size check in chunk allocator

Fix a bug, where in case we need to adjust stripe_size so that the
length of the resulting chunk is less than or equal to max_chunk_size,
DUP chunks turn out to be only half as big as they could be.

Cc: Arne Jansen <sensille@gmx.net>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
12 years agoBtrfs: add missing read locks in backref.c
Jan Schmidt [Fri, 13 Apr 2012 10:28:08 +0000 (12:28 +0200)]
Btrfs: add missing read locks in backref.c

iref_to_path and iterate_irefs both increment the eb's refcount to use it
after releasing the path. Both depend on consistent data remaining in the
extent buffer and need a read lock to protect it.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
12 years agoBtrfs: don't call free_extent_buffer twice in iterate_irefs
Jan Schmidt [Fri, 13 Apr 2012 10:28:00 +0000 (12:28 +0200)]
Btrfs: don't call free_extent_buffer twice in iterate_irefs

Avoid calling free_extent_buffer more than once when the iterator function
returns non-zero. The only code that uses this is scrub repair for corrupted
nodatasum blocks.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
12 years agoBtrfs: Make free_ipath() deal gracefully with NULL pointers
Jesper Juhl [Thu, 12 Apr 2012 20:47:52 +0000 (22:47 +0200)]
Btrfs: Make free_ipath() deal gracefully with NULL pointers

Make free_ipath() behave like most other freeing functions in the
kernel and gracefully do nothing when passed a NULL pointer.

Besides this making the bahaviour consistent with functions such as
kfree(), vfree(), btrfs_free_path() etc etc, it also fixes a real NULL
deref issue in fs/btrfs/ioctl.c::btrfs_ioctl_ino_to_path(). In that
function we have this code:

...
        ipath = init_ipath(size, root, path);
        if (IS_ERR(ipath)) {
                ret = PTR_ERR(ipath);
                ipath = NULL;
                goto out;
        }
...
out:
        btrfs_free_path(path);
        free_ipath(ipath);
...

If we ever take the true branch of that 'if' statement we'll end up
passing a NULL pointer to free_ipath() which will subsequently
dereference it and we'll go "Boom" :-(
This patch will avoid that.

Signed-off-by: Jesper Juhl <jj@chaosbits.net>
12 years agoBtrfs: avoid possible use-after-free in clear_extent_bit()
Li Zefan [Mon, 12 Mar 2012 08:39:48 +0000 (16:39 +0800)]
Btrfs: avoid possible use-after-free in clear_extent_bit()

clear_extent_bit()
{
    next_node = rb_next(&state->rb_node);
    ...
    clear_state_bit(state);  <-- this may free next_node
    if (next_node) {
        state = rb_entry(next_node);
        ...
    }
}

clear_state_bit() calls merge_state() which may free the next node
of the passing extent_state, so clear_extent_bit() may end up
referencing freed memory.

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
12 years agoBtrfs: retrurn void from clear_state_bit
Li Zefan [Mon, 12 Mar 2012 08:39:28 +0000 (16:39 +0800)]
Btrfs: retrurn void from clear_state_bit

Currently it returns a set of bits that were cleared, but this return
value is not used at all.

Moreover it doesn't seem to be useful, because we may clear the bits
of a few extent_states, but only the cleared bits of last one is
returned.

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
12 years agobtrfs: add missing unlocks to transaction abort paths
David Sterba [Mon, 2 Apr 2012 16:31:37 +0000 (18:31 +0200)]
btrfs: add missing unlocks to transaction abort paths

Added in commit 49b25e0540904be0bf558b84475c69d72e4de66e
("btrfs: enhance transaction abort infrastructure")

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
12 years agoBtrfs: do not mount when we have a sectorsize unequal to PAGE_SIZE
Liu Bo [Tue, 3 Apr 2012 01:56:53 +0000 (09:56 +0800)]
Btrfs: do not mount when we have a sectorsize unequal to PAGE_SIZE

Our code is not ready to cope with a sectorsize that's not equal to PAGE_SIZE.
It will lead to hanging-on while writing something.

Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
12 years agobtrfs: don't add both copies of DUP to reada extent tree
Arne Jansen [Sat, 25 Feb 2012 08:09:47 +0000 (09:09 +0100)]
btrfs: don't add both copies of DUP to reada extent tree

Normally when there are 2 copies of a block, we add both to the
reada extent tree and prefetch only the one that is easier to reach.
This way we can better utilize multiple devices.
In case of DUP this makes no sense as both copies reside on the
same device.

Signed-off-by: Arne Jansen <sensille@gmx.net>
12 years agobtrfs: fix race in reada
Arne Jansen [Sat, 25 Feb 2012 08:09:30 +0000 (09:09 +0100)]
btrfs: fix race in reada

When inserting into the radix tree returns EEXIST, get the existing
entry without giving up the spinlock in between.
There was a race for both the zones trees and the extent tree.

Signed-off-by: Arne Jansen <sensille@gmx.net>
12 years agoBtrfs: avoid setting ->d_op twice
Li Zefan [Tue, 21 Feb 2012 09:04:28 +0000 (17:04 +0800)]
Btrfs: avoid setting ->d_op twice

Follow those instructions, and you'll trigger a warning in the
beginning of d_set_d_op():

  # mkfs.btrfs /dev/loop3
  # mount /dev/loop3 /mnt
  # btrfs sub create /mnt/sub
  # btrfs sub snap /mnt /mnt/snap
  # touch /mnt/snap/sub
  touch: cannot touch `tmp': Permission denied

__d_alloc() set d_op to sb->s_d_op (btrfs_dentry_operations), and
then simple_lookup() reset it to simple_dentry_operations, which
triggered the warning.

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
12 years agoBtrfs: use commit root when loading free space cache
Josef Bacik [Thu, 12 Apr 2012 20:03:57 +0000 (16:03 -0400)]
Btrfs: use commit root when loading free space cache

A user reported that booting his box up with btrfs root on 3.4 was way
slower than on 3.3 because I removed the ideal caching code.  It turns out
that we don't load the free space cache if we're in a commit for deadlock
reasons, but since we're reading the cache and it hasn't changed yet we are
safe reading the inode and free space item from the commit root, so do that
and remove all of the deadlock checks so we don't unnecessarily skip loading
the free space cache.  The user reported this fixed the slowness.  Thanks,

Tested-by: Calvin Walton <calvin.walton@kepstin.ca>
Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: fix use-after-free in __btrfs_end_transaction
Dave Jones [Thu, 12 Apr 2012 20:03:56 +0000 (16:03 -0400)]
Btrfs: fix use-after-free in __btrfs_end_transaction

49b25e0540904be0bf558b84475c69d72e4de66e introduced a use-after-free bug
that caused spurious -EIO's to be returned.

Do the check before we free the transaction.

Cc: David Sterba <dsterba@suse.cz>
Cc: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: Dave Jones <davej@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: check return value of bio_alloc() properly
Tsutomu Itoh [Thu, 12 Apr 2012 20:03:56 +0000 (16:03 -0400)]
Btrfs: check return value of bio_alloc() properly

bio_alloc() has the possibility of returning NULL.
So, it is necessary to check the return value.

Signed-off-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: remove lock assert from get_restripe_target()
Ilya Dryomov [Thu, 12 Apr 2012 20:03:56 +0000 (16:03 -0400)]
Btrfs: remove lock assert from get_restripe_target()

This fixes a regression introduced by fc67c450.  spin_is_locked() always
returns 0 on UP kernels, which caused assert in get_restripe_target() to
be fired on every call from btrfs_reduce_alloc_profile() on UP systems.
Remove it completely for now, it's not clear if it's going to be needed
in future.

Reported-by: Bobby Powers <bobbypowers@gmail.com>
Reported-by: Mitch Harder <mitch.harder@sabayonlinux.org>
Tested-by: Mitch Harder <mitch.harder@sabayonlinux.org>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: fix eof while discarding extents
Liu Bo [Thu, 12 Apr 2012 20:03:56 +0000 (16:03 -0400)]
Btrfs: fix eof while discarding extents

We miscalculate the length of extents we're discarding, and it leads to
an eof of device.

Reported-by: Daniel Blueman <daniel@quora.org>
Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: fix uninit variable in repair_eb_io_failure
Chris Mason [Thu, 12 Apr 2012 19:55:15 +0000 (15:55 -0400)]
Btrfs: fix uninit variable in repair_eb_io_failure

We'd have to be passing bogus extent buffers for this uninit variable to
actually be used, but set it to zero just in case.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoRevert "Btrfs: increase the global block reserve estimates"
Chris Mason [Thu, 12 Apr 2012 17:46:48 +0000 (13:46 -0400)]
Revert "Btrfs: increase the global block reserve estimates"

This reverts commit 5500cdbe14d7435e04f66ff3cfb8ecd8b8e44ebf.

We've had a number of complaints of early enospc that bisect down
to this patch.  We'll hae to fix the reservations differently.

CC: stable@kernel.org
Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: update the checks for mixed block groups with big metadata blocks
Chris Mason [Thu, 29 Mar 2012 21:02:47 +0000 (17:02 -0400)]
Btrfs: update the checks for mixed block groups with big metadata blocks

Dave Sterba had put in patches to look for mixed data/metadata groups
with metadata bigger than 4KB.  But these ended up in the wrong place
and it wasn't testing the feature flag correctly.

This updates the tests to make sure our sizes are matching

Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: update to the right index of defragment
Liu Bo [Thu, 29 Mar 2012 13:57:45 +0000 (09:57 -0400)]
Btrfs: update to the right index of defragment

When we use autodefrag, we forget to update the index which indicates
the last page we've dirty.  And we'll set dirty flags on a same set of
pages again and again.

Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: do not bother to defrag an extent if it is a big real extent
Liu Bo [Thu, 29 Mar 2012 13:57:45 +0000 (09:57 -0400)]
Btrfs: do not bother to defrag an extent if it is a big real extent

$ mkfs.btrfs /dev/sdb7
$ mount /dev/sdb7 /mnt/btrfs/ -oautodefrag
$ dd if=/dev/zero of=/mnt/btrfs/foobar bs=4k count=10 oflag=direct 2>/dev/null
$ filefrag -v /mnt/btrfs/foobar
Filesystem type is: 9123683e
File size of /mnt/btrfs/foobar is 40960 (10 blocks, blocksize 4096)
 ext logical physical expected length flags
   0       0     3072              10 eof
/mnt/btrfs/foobar: 1 extent found

Now we have a big real extent [0, 40960), but autodefrag will still defrag it.

$ sync
$ filefrag -v /mnt/btrfs/foobar
Filesystem type is: 9123683e
File size of /mnt/btrfs/foobar is 40960 (10 blocks, blocksize 4096)
 ext logical physical expected length flags
   0       0     3082              10 eof
/mnt/btrfs/foobar: 1 extent found

So if we already find a big real extent, we're ok about that, just skip it.

Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: add a check to decide if we should defrag the range
Liu Bo [Thu, 29 Mar 2012 13:57:45 +0000 (09:57 -0400)]
Btrfs: add a check to decide if we should defrag the range

If our file's layout is as follows:
| hole | data1 | hole | data2 |

we do not need to defrag this file, because this file has holes and
cannot be merged into one extent.

Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: fix recursive defragment with autodefrag option
Liu Bo [Thu, 29 Mar 2012 13:57:45 +0000 (09:57 -0400)]
Btrfs: fix recursive defragment with autodefrag option

$ mkfs.btrfs disk
$ mount disk /mnt -o autodefrag
$ dd if=/dev/zero of=/mnt/foobar bs=4k count=10 2>/dev/null && sync
$ for i in `seq 9 -2 0`; do dd if=/dev/zero of=/mnt/foobar bs=4k count=1 \
  seek=$i conv=notrunc 2> /dev/null; done && sync

then we'll get to defrag "foobar" again and again.
So does option "-o autodefrag,compress".

Reasons:
When the cleaner kthread gets to fetch inodes from the defrag tree and defrag
them, it will dirty pages and submit them, this will comes to another DATA COW
where the processing inode will be inserted to the defrag tree again.

This patch sets a rule for COW code, i.e. insert an inode when we're really
going to make some defragments.

Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: fix the mismatch of page->mapping
Liu Bo [Thu, 29 Mar 2012 13:57:44 +0000 (09:57 -0400)]
Btrfs: fix the mismatch of page->mapping

commit 600a45e1d5e376f679ff9ecc4ce9452710a6d27c
(Btrfs: fix deadlock on page lock when doing auto-defragment)
fixes the deadlock on page, but it also introduces another bug.

A page may have been truncated after unlock & lock.
So we need to find it again to get the right one.

And since we've held i_mutex lock, inode size remains unchanged and
we can drop isize overflow checks.

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>
12 years agoBtrfs: fix race between direct io and autodefrag
Liu Bo [Thu, 29 Mar 2012 13:57:44 +0000 (09:57 -0400)]
Btrfs: fix race between direct io and autodefrag

The bug is from running xfstests 209 with autodefrag.

The race is as follows:
       t1                       t2(autodefrag)
   direct IO
     invalidate pagecache
     dio(old data)             add_inode_defrag
     invalidate pagecache
   endio

   direct IO
     invalidate pagecache
                                run_defrag
                                  readpage(old data)
                                  set page dirty (old data)
     dio(new data, rewrite)
     invalidate pagecache (*)
     endio

t2(autodefrag) will get old data into pagecache via readpage and set
pagecache dirty.  Meanwhile, invalidate pagecache(*) will fail due to
dirty flags in pages.  So the old data may be flushed into disk by
flush thread, which will lead to data loss.

And so does the case of user defragment progs.

The patch fixes this race by holding i_mutex when we readpage and set page dirty.

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>
12 years agoBtrfs: fix deadlock during allocating chunks
Liu Bo [Thu, 29 Mar 2012 13:57:44 +0000 (09:57 -0400)]
Btrfs: fix deadlock during allocating chunks

This deadlock comes from xfstests 251.

We'll hold the chunk_mutex throughout the whole of a chunk allocation.
But if we find that we've used up system chunk space, we need to allocate a
new system chunk, but this will lead to a recursion of chunk allocation and end
up with a deadlock on chunk_mutex.
So instead we need to allocate the system chunk first if we find we're in ENOSPC.

Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: show useful info in space reservation tracepoint
Liu Bo [Thu, 29 Mar 2012 13:57:44 +0000 (09:57 -0400)]
Btrfs: show useful info in space reservation tracepoint

o For space info, the type of space info is useful for debug.
o For transaction handle, its transid is useful.

Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: don't use crc items bigger than 4KB
Chris Mason [Wed, 1 Feb 2012 01:19:02 +0000 (20:19 -0500)]
Btrfs: don't use crc items bigger than 4KB

With the big metadata blocks, we can have crc items
that are much bigger than a page.  There are a few
places that we try to kmalloc memory to hold the
items during a split.

Items bigger than 4KB don't really have a huge benefit
in efficiency, but they do trigger larger order allocations.
This commits changes the csums to make sure they stay under
4KB.  This is not a format change, just a #define to limit
huge items.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: flush out and clean up any block device pages during mount
Chris Mason [Tue, 27 Mar 2012 22:56:56 +0000 (18:56 -0400)]
Btrfs: flush out and clean up any block device pages during mount

Btrfs puts the filesystem metadata into its own address space, and
somehow the block device address space isn't getting onto disk properly
before a mount.  The end result is that a loop of mkfs and mounting the
filesystem will sometimes find stale or incorrect data.

This commit should fix it by sprinkling fdatawrites and invalidate_bdev
calls around.  This is a short term measure to make sure it is fixed.
The block devices really should be flushed and cleaned up higher in the
stack.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoMerge git://git.jan-o-sch.net/btrfs-unstable into for-linus
Chris Mason [Thu, 29 Mar 2012 00:33:40 +0000 (20:33 -0400)]
Merge git://git.jan-o-sch.net/btrfs-unstable into for-linus

Conflicts:
fs/btrfs/transaction.c

Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoMerge branch 'for-chris' of git://github.com/idryomov/btrfs-unstable into for-linus
Chris Mason [Thu, 29 Mar 2012 00:32:46 +0000 (20:32 -0400)]
Merge branch 'for-chris' of git://github.com/idryomov/btrfs-unstable into for-linus

12 years agoMerge branch 'error-handling' into for-linus
Chris Mason [Thu, 29 Mar 2012 00:31:37 +0000 (20:31 -0400)]
Merge branch 'error-handling' into for-linus

Conflicts:
fs/btrfs/ctree.c
fs/btrfs/disk-io.c
fs/btrfs/extent-tree.c
fs/btrfs/extent_io.c
fs/btrfs/extent_io.h
fs/btrfs/inode.c
fs/btrfs/scrub.c

Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agobtrfs: disallow unequal data/metadata blocksize for mixed block groups
David Sterba [Fri, 17 Feb 2012 11:26:09 +0000 (12:26 +0100)]
btrfs: disallow unequal data/metadata blocksize for mixed block groups

With support for bigger metadata blocks, we must avoid mounting a
filesystem with different block size for mixed block groups, this causes
corruption (found by xfstests/083).

Signed-off-by: David Sterba <dsterba@suse.cz>
12 years agoBtrfs: enhance superblock sanity checks
David Sterba [Mon, 5 Mar 2012 23:06:18 +0000 (00:06 +0100)]
Btrfs: enhance superblock sanity checks

Validate checksum algorithm during mount and prevent BUG_ON later in
btrfs_super_csum_size.

Signed-off-by: David Sterba <dsterba@suse.cz>
12 years agoBtrfs: change scrub to support big blocks
Stefan Behrens [Tue, 27 Mar 2012 18:21:27 +0000 (14:21 -0400)]
Btrfs: change scrub to support big blocks

Scrub used to be coded for nodesize == leafsize == sectorsize == PAGE_SIZE.
This is now changed to support sizes for nodesize and leafsize which are
N * PAGE_SIZE.

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: minor cleanup in scrub
Stefan Behrens [Tue, 27 Mar 2012 18:21:26 +0000 (14:21 -0400)]
Btrfs: minor cleanup in scrub

Just a minor cleanup commit in preparation for the big block changes.

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: introduce common define for max number of mirrors
Stefan Behrens [Tue, 27 Mar 2012 18:21:26 +0000 (14:21 -0400)]
Btrfs: introduce common define for max number of mirrors

Readahead already has a define for the max number of mirrors. Scrub
needs such a define now, the rest of the code will need something
like this soon. Therefore the define was added to ctree.h and removed
from the readahead code.

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: fix infinite loop in btrfs_shrink_device()
Ilya Dryomov [Tue, 27 Mar 2012 14:09:18 +0000 (17:09 +0300)]
Btrfs: fix infinite loop in btrfs_shrink_device()

If relocate of block group 0 fails with ENOSPC we end up infinitely
looping because key.offset -= 1 statement in that case brings us back to
where we started.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
12 years agoBtrfs: fix memory leak in resolver code
Ilya Dryomov [Tue, 27 Mar 2012 14:09:18 +0000 (17:09 +0300)]
Btrfs: fix memory leak in resolver code

init_ipath() allocates btrfs_data_container which is never freed.  Free
it in free_ipath() and nuke the comment for init_data_container() - we
can safely free it with kfree().

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
12 years agoBtrfs: allow dup for data chunks in mixed mode
Ilya Dryomov [Tue, 27 Mar 2012 14:09:17 +0000 (17:09 +0300)]
Btrfs: allow dup for data chunks in mixed mode

Generally we don't allow dup for data, but mixed chunks are special and
people seem to think this has its use cases.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
12 years agoBtrfs: validate target profiles only if we are going to use them
Ilya Dryomov [Tue, 27 Mar 2012 14:09:17 +0000 (17:09 +0300)]
Btrfs: validate target profiles only if we are going to use them

Do not run sanity checks on all target profiles unless they all will be
used.  This came up because alloc_profile_is_valid() is now more strict
than it used to be.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
12 years agoBtrfs: improve the logic in btrfs_can_relocate()
Ilya Dryomov [Tue, 27 Mar 2012 14:09:17 +0000 (17:09 +0300)]
Btrfs: improve the logic in btrfs_can_relocate()

Currently if we don't have enough space allocated we go ahead and loop
though devices in the hopes of finding enough space for a chunk of the
*same* type as the one we are trying to relocate.  The problem with that
is that if we are trying to restripe the chunk its target type can be
more relaxed than the current one (eg require less devices or less
space).  So, when restriping, run checks against the target profile
instead of the current one.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
12 years agoBtrfs: add __get_block_group_index() helper
Ilya Dryomov [Tue, 27 Mar 2012 14:09:17 +0000 (17:09 +0300)]
Btrfs: add __get_block_group_index() helper

Add __get_block_group_index() helper to be able to derive block group
index from an arbitary set of flags.  Implement get_block_group_index()
in terms of it.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
12 years agoBtrfs: add get_restripe_target() helper
Ilya Dryomov [Tue, 27 Mar 2012 14:09:17 +0000 (17:09 +0300)]
Btrfs: add get_restripe_target() helper

Add get_restripe_target() helper and switch everybody to use it.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
12 years agoBtrfs: move alloc_profile_is_valid() to volumes.c
Ilya Dryomov [Tue, 27 Mar 2012 14:09:17 +0000 (17:09 +0300)]
Btrfs: move alloc_profile_is_valid() to volumes.c

Header file is not a good place to define functions.  This also moves a
call to alloc_profile_is_valid() down the stack and removes a redundant
check from __btrfs_alloc_chunk() - alloc_profile_is_valid() takes it
into account.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
12 years agoBtrfs: make profile_is_valid() check more strict
Ilya Dryomov [Tue, 27 Mar 2012 14:09:17 +0000 (17:09 +0300)]
Btrfs: make profile_is_valid() check more strict

"0" is a valid value for an on-disk chunk profile, but it is not a valid
extended profile.  (We have a separate bit for single chunks in extended
case)

Also rename it to alloc_profile_is_valid() for clarity.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
12 years agoBtrfs: add wrappers for working with alloc profiles
Ilya Dryomov [Tue, 27 Mar 2012 14:09:16 +0000 (17:09 +0300)]
Btrfs: add wrappers for working with alloc profiles

Add functions to abstract the conversion between chunk and extended
allocation profile formats and switch everybody to use them.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
12 years agoBtrfs: stop silently switching single chunks to raid0 on balance
Ilya Dryomov [Tue, 27 Mar 2012 14:09:16 +0000 (17:09 +0300)]
Btrfs: stop silently switching single chunks to raid0 on balance

This has been causing a lot of confusion for quite a while now and a lot
of users were surprised by this (some of them were even stuck in a
ENOSPC situation which they couldn't easily get out of).  The addition
of restriper gives users a clear choice between raid0 and drive concat
setup so there's absolutely no excuse for us to keep doing this.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
12 years agoBtrfs: fix regression in scrub path resolving
Jan Schmidt [Fri, 23 Mar 2012 16:32:28 +0000 (17:32 +0100)]
Btrfs: fix regression in scrub path resolving

In commit 4692cf58 we introduced new backref walking code for btrfs. This
assumes we're searching live roots, which requires a transaction context.
While scrubbing, however, we must not join a transaction because this could
deadlock with the commit path. Additionally, what scrub really wants to do
is resolving a logical address in the commit root it's currently checking.

This patch adds support for logical to path resolving on commit roots and
makes scrub use that.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
12 years agoBtrfs: check return value of btrfs_cow_block()
Jan Schmidt [Fri, 23 Mar 2012 16:24:19 +0000 (17:24 +0100)]
Btrfs: check return value of btrfs_cow_block()

The two helper functions commit_cowonly_roots() and
create_pending_snapshot() failed to check the return value from
btrfs_cow_block(), which could at least in theory fail with -ENOSPC from
btrfs_alloc_free_block(). This commit adds the missing checks.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
12 years agoBtrfs: actually call btrfs_init_lockdep
Jan Schmidt [Fri, 23 Mar 2012 16:14:20 +0000 (17:14 +0100)]
Btrfs: actually call btrfs_init_lockdep

btrfs_init_lockdep only makes our lockdep class names look prettier, thus
it did never hurt we forgot to actually call it. This turns our lockdep
identifier strings from lockdep auto-set #[id] into really pretty
"btrfs-fs-01" or "btrfs-csum-03".

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
12 years agoBtrfs: deal with read errors on extent buffers differently
Josef Bacik [Tue, 27 Mar 2012 01:57:36 +0000 (21:57 -0400)]
Btrfs: deal with read errors on extent buffers differently

Since we need to read and write extent buffers in their entirety we can't use
the normal bio_readpage_error stuff since it only works on a per page basis.  So
instead make it so that if we see an io error in endio we just mark the eb as
having an IO error and then in btree_read_extent_buffer_pages we will manually
try other mirrors and then overwrite the bad mirror if we find a good copy.
This works with larger than page size blocks.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: don't use threaded IO completion helpers for metadata writes
Chris Mason [Fri, 23 Mar 2012 14:22:46 +0000 (10:22 -0400)]
Btrfs: don't use threaded IO completion helpers for metadata writes

The metadata write IO completion code is now simple enough that we
don't need the threaded helpers anymore.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: adjust the write_lock_level as we unlock
Chris Mason [Mon, 19 Mar 2012 19:54:38 +0000 (15:54 -0400)]
Btrfs: adjust the write_lock_level as we unlock

btrfs_search_slot sometimes needs write locks on high levels of
the tree.  It remembers the highest level that needs a write lock
and will use that for all future searches through the tree in a given
call.

But, very often we'll just cow the top level or the level below and we
won't really need write locks on the root again after that.  This patch
changes things to adjust the write lock requirement as it unlocks
levels.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: loop waiting on writeback
Chris Mason [Wed, 21 Mar 2012 16:09:56 +0000 (12:09 -0400)]
Btrfs: loop waiting on writeback

lock_extent_buffer_for_io needs to loop around and make sure the
writeback bits are not set.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: add the ability to cache a pointer into the eb
Chris Mason [Sat, 3 Mar 2012 12:40:03 +0000 (07:40 -0500)]
Btrfs: add the ability to cache a pointer into the eb

This cuts down on the CPU time used by map_private_extent_buffer

Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: ensure an entire eb is written at once
Josef Bacik [Tue, 13 Mar 2012 13:38:00 +0000 (09:38 -0400)]
Btrfs: ensure an entire eb is written at once

This patch simplifies how we track our extent buffers.  Previously we could exit
writepages with only having written half of an extent buffer, which meant we had
to track the state of the pages and the state of the extent buffers differently.
Now we only read in entire extent buffers and write out entire extent buffers,
this allows us to simply set bits in our bflags to indicate the state of the eb
and we no longer have to do things like track uptodate with our iotree.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: introduce mark_extent_buffer_accessed
Josef Bacik [Thu, 15 Mar 2012 22:24:42 +0000 (18:24 -0400)]
Btrfs: introduce mark_extent_buffer_accessed

Because an eb can have multiple pages we need to make sure that all pages within
the eb are markes as accessed, since releasepage can be called against any page
in the eb.  This will keep us from possibly evicting hot eb's when we're doing
larger than pagesize eb's.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
12 years agoBtrfs: introduce free_extent_buffer_stale
Josef Bacik [Fri, 9 Mar 2012 21:01:49 +0000 (16:01 -0500)]
Btrfs: introduce free_extent_buffer_stale

Because btrfs cow's we can end up with extent buffers that are no longer
necessary just sitting around in memory.  So instead of evicting these pages, we
could end up evicting things we actually care about.  Thus we have
free_extent_buffer_stale for use when we are freeing tree blocks.  This will
make it so that the ref for the eb being in the radix tree is dropped as soon as
possible and then is freed when the refcount hits 0 instead of waiting to be
released by releasepage.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
12 years agoBtrfs: only use the existing eb if it's count isn't 0
Josef Bacik [Fri, 9 Mar 2012 14:51:43 +0000 (09:51 -0500)]
Btrfs: only use the existing eb if it's count isn't 0

We can run into a problem where we find an eb for our existing page already on
the radix tree but it has a ref count of 0.  It hasn't yet been removed by RCU
yet so this can cause issues where we will use the EB after free.  So do
atomic_inc_not_zero on the exists->refs and if it is zero just do
synchronize_rcu() and try again.  We won't have to worry about new allocators
coming in since they will block on the page lock at this point.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>