platform/kernel/linux-exynos.git
16 years agoBtrfs: Fix releasepage to properly keep dirty and writeback pages
Chris Mason [Thu, 11 Sep 2008 19:51:43 +0000 (15:51 -0400)]
Btrfs: Fix releasepage to properly keep dirty and writeback pages

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Update the highest objectid in a root after log replay is done
Chris Mason [Thu, 11 Sep 2008 19:51:21 +0000 (15:51 -0400)]
Btrfs: Update the highest objectid in a root after log replay is done

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Tree logging fixes
Chris Mason [Mon, 8 Sep 2008 15:18:08 +0000 (11:18 -0400)]
Btrfs: Tree logging fixes

* Pin down data blocks to prevent them from being reallocated like so:

trans 1: allocate file extent
trans 2: free file extent
trans 3: free file extent during old snapshot deletion
trans 3: allocate file extent to new file
trans 3: fsync new file

Before the tree logging code, this was legal because the fsync
would commit the transation that did the final data extent free
and the transaction that allocated the extent to the new file
at the same time.

With the tree logging code, the tree log subtransaction can commit
before the transaction that freed the extent.  If we crash,
we're left with two different files using the extent.

* Don't wait in start_transaction if log replay is going on.  This
avoids deadlocks from iput while we're cleaning up link counts in the
replay code.

* Don't deadlock in replay_one_name by trying to read an inode off
the disk while holding paths for the directory

* Hold the buffer lock while we mark a buffer as written.  This
closes a race where someone is changing a buffer while we write it.
They are supposed to mark it dirty again after they change it, but
this violates the cow rules.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: properly set blocksize when adding new device.
Zheng Yan [Fri, 5 Sep 2008 20:43:54 +0000 (16:43 -0400)]
Btrfs: properly set blocksize when adding new device.

---

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Update find free objectid function for orphan cleanup code
Zheng Yan [Fri, 5 Sep 2008 20:43:53 +0000 (16:43 -0400)]
Btrfs: Update find free objectid function for orphan cleanup code

Orphan items use BTRFS_ORPHAN_OBJECTID (-5UUL) as key objectid. This
affects the find free objectid functions, inode objectid can easily
overflow after orphan file cleanup.

---

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: trivial sparse fixes
Christoph Hellwig [Fri, 5 Sep 2008 20:43:31 +0000 (16:43 -0400)]
Btrfs: trivial sparse fixes

Fix a bunch of trivial sparse complaints.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoremove unused function btrfs_ilookup
Christoph Hellwig [Fri, 5 Sep 2008 20:43:29 +0000 (16:43 -0400)]
remove unused function btrfs_ilookup

btrfs_ilookup is unused, which is good because a normal filesystem
should never have to use ilookup anyway.  Remove it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: missing endianess conversion in insert_new_root
Christoph Hellwig [Fri, 5 Sep 2008 20:43:28 +0000 (16:43 -0400)]
Btrfs: missing endianess conversion in insert_new_root

Add two missing endianess conversions in this function, found by sparse.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: cleanup d_obtain_alias useage
Christoph Hellwig [Fri, 5 Sep 2008 20:43:20 +0000 (16:43 -0400)]
Btrfs: cleanup d_obtain_alias useage

d_obtain_alias is intended as a tailcall that can pass in errors encoded
in the inode pointer if needed, so use it that way instead of
duplicating the error handling.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Rev the disk format
Chris Mason [Fri, 5 Sep 2008 20:43:06 +0000 (16:43 -0400)]
Btrfs: Rev the disk format

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Add a write ahead tree log to optimize synchronous operations
Chris Mason [Fri, 5 Sep 2008 20:13:11 +0000 (16:13 -0400)]
Btrfs: Add a write ahead tree log to optimize synchronous operations

File syncs and directory syncs are optimized by copying their
items into a special (copy-on-write) log tree.  There is one log tree per
subvolume and the btrfs super block points to a tree of log tree roots.

After a crash, items are copied out of the log tree and back into the
subvolume.  See tree-log.c for all the details.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Add debugging checks to track down corrupted metadata
Chris Mason [Fri, 5 Sep 2008 20:09:51 +0000 (16:09 -0400)]
Btrfs: Add debugging checks to track down corrupted metadata

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: optimize btrget/set/removexattr
Christoph Hellwig [Thu, 28 Aug 2008 10:21:17 +0000 (06:21 -0400)]
Btrfs: optimize btrget/set/removexattr

btrfs actually stores the whole xattr name, including the prefix ondisk,
so using the generic resolver that strips off the prefix is not very
helpful.  Instead do the real ondisk xattrs manually and only use the
generic resolver for synthetic xattrs like ACLs.

(Sorry Josef for guiding you towards the wrong direction here intially)

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agobtrfs: optmize listxattr
Christoph Hellwig [Thu, 28 Aug 2008 10:21:16 +0000 (06:21 -0400)]
btrfs: optmize listxattr

The ->list handler is really not useful at all, because we always call
btrfs_xattr_generic_list anyway.  After this is done
find_btrfs_xattr_handler becomes unused, and it becomes obvious that the
temporary name buffer allocation isn't needed but we can directly copy
into the supplied buffer.

Tested with various getfattr -d calls on varying xattr lists.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: compile when posix acl's are disabled
Josef Bacik [Thu, 28 Aug 2008 10:21:15 +0000 (06:21 -0400)]
Btrfs: compile when posix acl's are disabled

This patch makes btrfs so it will compile properly when acls are disabled.  I
tested this and it worked with CONFIG_FS_POSIX_ACL off and on.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Fix variable init during csum creation
Chris Mason [Thu, 28 Aug 2008 10:15:25 +0000 (06:15 -0400)]
Btrfs: Fix variable init during csum creation

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Throttle for async bio submits higher up the chain
Chris Mason [Thu, 28 Aug 2008 10:15:24 +0000 (06:15 -0400)]
Btrfs: Throttle for async bio submits higher up the chain

The current code waits for the count of async bio submits to get below
a given threshold if it is too high right after adding the latest bio
to the work queue.  This isn't optimal because the caller may have
sequential adjacent bios pending they are waiting to send down the pipe.

This changeset requires the caller to wait on the async bio count,
and changes the async checksumming submits to wait for async bios any
time they self throttle.

The end result is much higher sequential throughput.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Rev the disk format
Chris Mason [Thu, 21 Aug 2008 19:49:09 +0000 (15:49 -0400)]
Btrfs: Rev the disk format

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoClean up btrfs_get_parent() a little more, fix a free-after-free bug
David Woodhouse [Tue, 19 Aug 2008 21:33:04 +0000 (22:33 +0100)]
Clean up btrfs_get_parent() a little more, fix a free-after-free bug

Date: Tue, 19 Aug 2008 22:33:04 +0100
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Fix NFS exporting of subvol roots.
David Woodhouse [Tue, 19 Aug 2008 21:20:17 +0000 (22:20 +0100)]
Btrfs: Fix NFS exporting of subvol roots.

Date: Tue, 19 Aug 2008 22:20:17 +0100
btrfs_lookup_fs_root() only finds subvol roots which have already been
seen and put into the cache. For btrfs_get_dentry() we actually have to
go to the medium -- so use btrfs_read_fs_root_no_name() instead.

In btrfs_get_parent(), notice when we've hit the root of the
subvolume and return the real root instead.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoSwitch btrfs_name_hash() to crc32c
David Woodhouse [Tue, 19 Aug 2008 18:21:57 +0000 (19:21 +0100)]
Switch btrfs_name_hash() to crc32c

Date: Tue, 19 Aug 2008 19:21:57 +0100
Using a 64-bit hash as the readdir cookie is just asking for trouble.
And gets it, when we try to export the file system by NFS.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Reinstate '-osubvol=.' option to mount entire tree
David Woodhouse [Tue, 19 Aug 2008 15:49:35 +0000 (16:49 +0100)]
Btrfs: Reinstate '-osubvol=.' option to mount entire tree

Date: Tue, 19 Aug 2008 16:49:35 +0100
This disappeared when I removed the special case for '.' in btrfs_lookup()

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoSimplify btrfs_get_parent(), fix use-after-free bug
David Woodhouse [Mon, 18 Aug 2008 21:50:22 +0000 (22:50 +0100)]
Simplify btrfs_get_parent(), fix use-after-free bug

Date: Mon, 18 Aug 2008 22:50:22 +0100
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoMask root object ID into f_fsid in btrfs_statfs()
David Woodhouse [Mon, 18 Aug 2008 12:10:20 +0000 (13:10 +0100)]
Mask root object ID into f_fsid in btrfs_statfs()

Date: Mon, 18 Aug 2008 13:10:20 +0100
This means that subvolumes get a different fsid, and NFS exporting them
works properly.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoFill f_fsid field in btrfs_statfs()
David Woodhouse [Mon, 18 Aug 2008 11:01:52 +0000 (12:01 +0100)]
Fill f_fsid field in btrfs_statfs()

Date: Mon, 18 Aug 2008 12:01:52 +0100
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Optimise NFS readdir hack slightly; don't call readdir() again when done
David Woodhouse [Sun, 17 Aug 2008 16:12:56 +0000 (17:12 +0100)]
Btrfs: Optimise NFS readdir hack slightly; don't call readdir() again when done

Date: Sun, 17 Aug 2008 17:12:56 +0100
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoMinor cleanup of btrfs_real_readdir()
David Woodhouse [Sun, 17 Aug 2008 16:08:36 +0000 (17:08 +0100)]
Minor cleanup of btrfs_real_readdir()

Date: Sun, 17 Aug 2008 17:08:36 +0100
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Remove special cases for "." and ".."
David Woodhouse [Sun, 17 Aug 2008 14:14:48 +0000 (15:14 +0100)]
Btrfs: Remove special cases for "." and ".."

Date: Sun, 17 Aug 2008 15:14:48 +0100
We never get asked by the VFS to lookup either of them, and we can
handle the readdir() case a lot more simply, too.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Discard sector data in __free_extent()
David Woodhouse [Tue, 12 Aug 2008 13:13:26 +0000 (14:13 +0100)]
Btrfs: Discard sector data in __free_extent()

Date: Tue, 12 Aug 2008 14:13:26 +0100
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Implement our own copy of the nfsd readdir hack, for older kernels
David Woodhouse [Wed, 6 Aug 2008 18:42:33 +0000 (19:42 +0100)]
Btrfs: Implement our own copy of the nfsd readdir hack, for older kernels

Date: Wed, 6 Aug 2008 19:42:33 +0100
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoNFS support for btrfs - v3
Balaji Rao [Sun, 20 Jul 2008 20:31:56 +0000 (02:01 +0530)]
NFS support for btrfs - v3

Date: Mon, 21 Jul 2008 02:01:56 +0530
Here's an implementation of NFS support for btrfs. It relies on the
fixes which are going in to 2.6.28 for the NFS readdir/lookup deadlock.

This uses the btrfs_iget helper introduced previously.

[dwmw2: Tidy up a little, switch to d_obtain_alias() w/compat routine,
change fh_type, store parent's root object ID where needed,
fix some get_parent() and fs_to_dentry() bugs]

Signed-off-by: Balaji Rao <balajirrao@gmail.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoIntroduce btrfs_iget helper
Balaji Rao [Sun, 20 Jul 2008 20:31:04 +0000 (02:01 +0530)]
Introduce btrfs_iget helper

Date: Mon, 21 Jul 2008 02:01:04 +0530
This patch introduces a btrfs_iget helper to be used in NFS support.

Signed-off-by: Balaji Rao <balajirrao@gmail.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Wait for async bio submissions to make some progress at queue time
Chris Mason [Wed, 20 Aug 2008 17:39:41 +0000 (13:39 -0400)]
Btrfs: Wait for async bio submissions to make some progress at queue time

Before, the btrfs bdi congestion function was used to test for too many
async bios.  This keeps that check to throttle pdflush, but also
adds a check while queuing bios.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Lookup readpage checksums on bio submission again
Chris Mason [Wed, 20 Aug 2008 13:44:52 +0000 (09:44 -0400)]
Btrfs: Lookup readpage checksums on bio submission again

This optimization had been removed because I thought it was triggering
csum errors.  The real cause of the errors was elsewhere, and so
this optimization is back.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Fix add_extent_mapping to check for duplicates across the whole range
Chris Mason [Wed, 20 Aug 2008 12:51:50 +0000 (08:51 -0400)]
Btrfs: Fix add_extent_mapping to check for duplicates across the whole range

add_extent_mapping was allowing the insertion of overlapping extents.
This never used to happen because it only inserted the extents from disk
and those were never overlapping.

But, with the data=ordered code, the disk and memory representations of the
file are not the same.  add_extent_mapping needs to ensure a new extent
does not overlap before it inserts.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Remove broken optimisations in end_bio functions.
David Woodhouse [Wed, 20 Aug 2008 12:51:49 +0000 (08:51 -0400)]
Btrfs: Remove broken optimisations in end_bio functions.

These ended up freeing objects while they were still using them. Under
guidance from Chris, just rip out the 'clever' bits and do things the
simple way.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Lower contention on the csum mutex
Chris Mason [Fri, 15 Aug 2008 19:34:18 +0000 (15:34 -0400)]
Btrfs: Lower contention on the csum mutex

This takes the csum mutex deeper in the call chain and releases it
more often.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Wait for kernel threads to make progress during async submission
Chris Mason [Fri, 15 Aug 2008 19:34:17 +0000 (15:34 -0400)]
Btrfs: Wait for kernel threads to make progress during async submission

Before this change, btrfs would use a bdi congestion function to make
sure there weren't too many pending async checksum work items.

This change makes the process creating async work items wait instead,
leading to fewer congestion returns from the bdi.  This improves
pdflush background_writeout scanning.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Give all the worker threads descriptive names
Chris Mason [Fri, 15 Aug 2008 19:34:16 +0000 (15:34 -0400)]
Btrfs: Give all the worker threads descriptive names

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Transaction commit: don't use filemap_fdatawait
Chris Mason [Fri, 15 Aug 2008 19:34:15 +0000 (15:34 -0400)]
Btrfs: Transaction commit: don't use filemap_fdatawait

After writing out all the remaining btree blocks in the transaction,
the commit code would use filemap_fdatawait to make sure it was all
on disk.  This means it would wait for blocks written by other procs
as well.

The new code walks the list of blocks for this transaction again
and waits only for those required by this transaction.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Count async bios separately from async checksum work items
Chris Mason [Fri, 15 Aug 2008 19:34:15 +0000 (15:34 -0400)]
Btrfs: Count async bios separately from async checksum work items

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Limit the number of async bio submission kthreads to the number of devices
Chris Mason [Fri, 15 Aug 2008 19:34:14 +0000 (15:34 -0400)]
Btrfs: Limit the number of async bio submission kthreads to the number of devices

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Init address_space->writeback_index properly
Chris Mason [Fri, 15 Aug 2008 19:34:14 +0000 (15:34 -0400)]
Btrfs: Init address_space->writeback_index properly

The writeback_index field is used by write_cache_pages to pick up where
writeback on a given inode left off.  But, it is never set to a sane
value, so writeback can often start at a random offset in the file.

Kernels 2.6.28 and higher will have this fixed, but for everyone else,
we also fill in the value in btrfs.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Change TestSetPageLocked() to trylock_page()
David Woodhouse [Thu, 7 Aug 2008 15:19:43 +0000 (11:19 -0400)]
Btrfs: Change TestSetPageLocked() to trylock_page()

Add backwards compatibility in compat.h

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
---
 compat.h    |    3 +++
 extent_io.c |    3 ++-
 2 files changed, 5 insertions(+), 1 deletions(-)

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: fix RHEL test for ClearPageFsMisc
Eric Sandeen [Thu, 7 Aug 2008 15:19:42 +0000 (11:19 -0400)]
Btrfs: fix RHEL test for ClearPageFsMisc

Newer RHEL5 kernels define both ClearPageFSMisc and
ClearPageChecked, so test for both before redefining.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Update version.sh to v0.16
Chris Mason [Mon, 4 Aug 2008 19:45:30 +0000 (15:45 -0400)]
Btrfs: Update version.sh to v0.16

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Avoid calling into the FS for the final iput on fake root inodes
Chris Mason [Tue, 5 Aug 2008 17:30:48 +0000 (13:30 -0400)]
Btrfs: Avoid calling into the FS for the final iput on fake root inodes

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Fix nodatacow for the new data=ordered mode
Yan Zheng [Tue, 5 Aug 2008 17:05:02 +0000 (13:05 -0400)]
Btrfs: Fix nodatacow for the new data=ordered mode

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoGet rid of BTRFS_I(inode)->index and use local vars instead
Chris Mason [Tue, 5 Aug 2008 15:18:09 +0000 (11:18 -0400)]
Get rid of BTRFS_I(inode)->index and use local vars instead

rename and link don't always have a lock on the source inode, and
our use of a per-inode index variable was racy.  This changes things to
store the index in a local variable instead.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Fix the multi-bio code to save the original bio for completion
Chris Mason [Tue, 5 Aug 2008 14:13:57 +0000 (10:13 -0400)]
Btrfs: Fix the multi-bio code to save the original bio for completion

The multi-bio code is responsible for duplicating blocks in raid1 and
single spindle duplication.  It has counters to make sure all of
the locations for a given extent are properly written before io completion
is returned to the higher layers.

But, it didn't always complete the same bio it was given, sometimes a
clone was completed instead.  This lead to problems with the async
work queues because they saved a pointer to the bio in a struct off
bi_private.

The fix is to remember the original bio and only complete that one.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Update clone file ioctl
Yan Zheng [Tue, 5 Aug 2008 03:23:47 +0000 (23:23 -0400)]
Btrfs: Update clone file ioctl

This patch updates the file clone ioctl for the tree locking and new
data ordered code.

---

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Various small fixes.
Yan Zheng [Tue, 5 Aug 2008 03:23:47 +0000 (23:23 -0400)]
Btrfs: Various small fixes.

This trivial patch contains two locking fixes and a off by one fix.

---

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agobtrfs_lookup_bio_sums seems broken, go back to the readpage_io_hook for now
Chris Mason [Tue, 5 Aug 2008 03:17:27 +0000 (23:17 -0400)]
btrfs_lookup_bio_sums seems broken, go back to the readpage_io_hook for now

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Maintain a list of inodes that are delalloc and a way to wait on them
Chris Mason [Tue, 5 Aug 2008 03:17:27 +0000 (23:17 -0400)]
Btrfs: Maintain a list of inodes that are delalloc and a way to wait on them

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Don't corrupt ram in shrink_extent_tree, leak it instead
Chris Mason [Tue, 5 Aug 2008 03:17:26 +0000 (23:17 -0400)]
Btrfs: Don't corrupt ram in shrink_extent_tree, leak it instead

Far from the perfect fix, but these structs are small.  TODO for the
next release.  The block group cache structs are referenced in many
different places, and it isn't safe to just free them while resizing.

A real fix will be a larger change to the allocator so that it doesn't
have to carry about the block group cache structs to find good places
to search for free blocks.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: fix ioctl-initiated transactions vs wait_current_trans()
Sage Weil [Mon, 4 Aug 2008 14:41:27 +0000 (10:41 -0400)]
Btrfs: fix ioctl-initiated transactions vs wait_current_trans()

Commit 597:466b27332893 (btrfs_start_transaction: wait for commits in
progress) breaks the transaction start/stop ioctls by making
btrfs_start_transaction conditionally wait for the next transaction to
start.  If an application artificially is holding a transaction open,
things deadlock.

This workaround maintains a count of open ioctl-initiated transactions in
fs_info, and avoids wait_current_trans() if any are currently open (in
start_transaction() and btrfs_throttle()).  The start transaction ioctl
uses a new btrfs_start_ioctl_transaction() that _does_ call
wait_current_trans(), effectively pushing the join/wait decision to the
outer ioctl-initiated transaction.

This more or less neuters btrfs_throttle() when ioctl-initiated
transactions are in use, but that seems like a pretty fundamental
consequence of wrapping lots of write()'s in a transaction.  Btrfs has no
way to tell if the application considers a given operation as part of it's
transaction.

Obviously, if the transaction start/stop ioctls aren't being used, there
is no effect on current behavior.

Signed-off-by: Sage Weil <sage@newdream.net>
---
 ctree.h       |    1 +
 ioctl.c       |   12 +++++++++++-
 transaction.c |   18 +++++++++++++-----
 transaction.h |    2 ++
 4 files changed, 27 insertions(+), 6 deletions(-)

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Add support for HW assisted crc32c
Chris Mason [Mon, 4 Aug 2008 15:10:20 +0000 (11:10 -0400)]
Btrfs: Add support for HW assisted crc32c

Intel doesn't yet ship hardware to the public with this enabled, but when they
do, they will be ready.  Original code from:

Austin Zhang <austin_zhang@linux.intel.com>

It is currently disabled, but edit crc32c.h to turn it on.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Hold csum mutex while reading in sums during readpages
Chris Mason [Mon, 4 Aug 2008 12:35:53 +0000 (08:35 -0400)]
Btrfs: Hold csum mutex while reading in sums during readpages

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: More throttle tuning
Chris Mason [Mon, 4 Aug 2008 12:20:15 +0000 (08:20 -0400)]
Btrfs: More throttle tuning

* Make walk_down_tree wake up throttled tasks more often
* Make walk_down_tree call cond_resched during long loops
* As the size of the ref cache grows, wait longer in throttle
* Get rid of the reada code in walk_down_tree, the leaves don't get
  read anymore, thanks to the ref cache.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agobtrfs_search_slot: reduce lock contention by cowing in two stages
Chris Mason [Fri, 1 Aug 2008 19:11:20 +0000 (15:11 -0400)]
btrfs_search_slot: reduce lock contention by cowing in two stages

A btree block cow has two parts, the first is to allocate a destination
block and the second is to copy the old bock over.

The first part needs locks in the extent allocation tree, and may need to
do IO.  This changeset splits that into a separate function that can be
called without any tree locks held.

btrfs_search_slot is changed to drop its path and start over if it has
to COW a contended block.  This often means that many writers will
pre-alloc a new destination for a the same contended block, but they
cache their prealloc for later use on lower levels in the tree.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Throttle less often waiting for snapshots to delete
Chris Mason [Fri, 1 Aug 2008 17:11:41 +0000 (13:11 -0400)]
Btrfs: Throttle less often waiting for snapshots to delete

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Improve and cleanup locking done by walk_down_tree
Chris Mason [Fri, 1 Aug 2008 15:27:23 +0000 (11:27 -0400)]
Btrfs: Improve and cleanup locking done by walk_down_tree

While dropping snapshots, walk_down_tree does most of the work of checking
reference counts and limiting tree traversal to just the blocks that
we are freeing.

It dropped and held the allocation mutex in strange and confusing ways,
this commit changes it to only hold the mutex while actually freeing a block.

The rest of the checks around reference counts should be safe without the lock
because we only allow one process in btrfs_drop_snapshot at a time.  Other
processes dropping reference counts should not drop it to 1 because
their tree roots already have an extra ref on the block.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Hold a reference on bios during submit_bio, add some extra bio checks
Chris Mason [Thu, 31 Jul 2008 20:29:02 +0000 (16:29 -0400)]
Btrfs: Hold a reference on bios during submit_bio, add some extra bio checks

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Drop some debugging around the extent_map pinned flag
Chris Mason [Thu, 31 Jul 2008 19:42:54 +0000 (15:42 -0400)]
Btrfs: Drop some debugging around the extent_map pinned flag

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Fix streaming read performance with checksumming on
Chris Mason [Thu, 31 Jul 2008 19:42:53 +0000 (15:42 -0400)]
Btrfs: Fix streaming read performance with checksumming on

Large streaming reads make for large bios, which means each entry on the
list async work queues represents a large amount of data.  IO
congestion throttling on the device was kicking in before the async
worker threads decided a single thread was busy and needed some help.

The end result was that a streaming read would result in a single CPU
running at 100% instead of balancing the work off to other CPUs.

This patch also changes the pre-IO checksum lookup done by reads to
work on a per-bio basis instead of a per-page.  This results in many
extra btree lookups on large streaming reads.  Doing the checksum lookup
right before bio submit allows us to reuse searches while processing
adjacent offsets.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Throttle tuning
Chris Mason [Thu, 31 Jul 2008 14:48:37 +0000 (10:48 -0400)]
Btrfs: Throttle tuning

This avoids waiting for transactions with pages locked by breaking out
the code to wait for the current transaction to close into a function
called by btrfs_throttle.

It also lowers the limits for where we start throttling.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Add missing hunk from Yan Zheng's cache reclaim patch
Chris Mason [Thu, 31 Jul 2008 13:46:18 +0000 (09:46 -0400)]
Btrfs: Add missing hunk from Yan Zheng's cache reclaim patch

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Add compatibility for kernels >= 2.6.27-rc1
Sven Wegener [Wed, 30 Jul 2008 20:54:26 +0000 (16:54 -0400)]
Btrfs: Add compatibility for kernels >= 2.6.27-rc1

Add a couple of #if's to follow API changes.

Signed-off-by: Sven Wegener <sven.wegener@stealer.net>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: implement memory reclaim for leaf reference cache
Yan [Wed, 30 Jul 2008 20:29:20 +0000 (16:29 -0400)]
Btrfs: implement memory reclaim for leaf reference cache

The memory reclaiming issue happens when snapshot exists. In that
case, some cache entries may not be used during old snapshot dropping,
so they will remain in the cache until umount.

The patch adds a field to struct btrfs_leaf_ref to record create time. Besides,
the patch makes all dead roots of a given snapshot linked together in order of
create time. After a old snapshot was completely dropped, we check the dead
root list and remove all cache entries created before the oldest dead root in
the list.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Fix verify_parent_transid
Chris Mason [Wed, 30 Jul 2008 14:29:12 +0000 (10:29 -0400)]
Btrfs: Fix verify_parent_transid

It was incorrectly clearing the up to date flag on the buffer even
when the buffer properly verified.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Update and fix mount -o nodatacow
Yan Zheng [Wed, 30 Jul 2008 13:26:11 +0000 (09:26 -0400)]
Btrfs: Update and fix mount -o nodatacow

To check whether a given file extent is referenced by multiple snapshots, the
checker walks down the fs tree through dead root and checks all tree blocks in
the path.

We can easily detect whether a given tree block is directly referenced by other
snapshot. We can also detect any indirect reference from other snapshot by
checking reference's generation. The checker can always detect multiple
references, but can't reliably detect cases of single reference. So btrfs may
do file data cow even there is only one reference.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: async-thread: fix possible memory leak
Li Zefan [Wed, 30 Jul 2008 13:24:37 +0000 (09:24 -0400)]
Btrfs: async-thread: fix possible memory leak

When kthread_run() returns failure, this worker hasn't been
added to the list, so btrfs_stop_workers() won't free it.

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Throttle operations if the reference cache gets too large
Chris Mason [Tue, 29 Jul 2008 20:15:18 +0000 (16:15 -0400)]
Btrfs: Throttle operations if the reference cache gets too large

A large reference cache is directly related to a lot of work pending
for the cleaner thread.  This throttles back new operations based on
the size of the reference cache so the cleaner thread will be able to keep
up.

Overall, this actually makes the FS faster because the cleaner thread will
be more likely to find things in cache.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Fix version.sh when used outside of an hg repo
Chris Mason [Tue, 29 Jul 2008 20:11:35 +0000 (16:11 -0400)]
Btrfs: Fix version.sh when used outside of an hg repo

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Leaf reference cache update
Chris Mason [Mon, 28 Jul 2008 19:32:51 +0000 (15:32 -0400)]
Btrfs: Leaf reference cache update

This changes the reference cache to make a single cache per root
instead of one cache per transaction, and to key by the byte number
of the disk block instead of the keys inside.

This makes it much less likely to have cache misses if a snapshot
or something has an extra reference on a higher node or a leaf while
the first transaction that added the leaf into the cache is dropping.

Some throttling is added to functions that free blocks heavily so they
wait for old transactions to drop.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Add a leaf reference cache
Yan Zheng [Mon, 28 Jul 2008 19:32:19 +0000 (15:32 -0400)]
Btrfs: Add a leaf reference cache

Much of the IO done while dropping snapshots is done looking up
leaves in the filesystem trees to see if they point to any extents and
to drop the references on any extents found.

This creates a cache so that IO isn't required.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Rev the disk format magic
Chris Mason [Thu, 24 Jul 2008 16:25:50 +0000 (12:25 -0400)]
Btrfs: Rev the disk format magic

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Null terminate strings passed in from userspace
Mark Fasheh [Thu, 24 Jul 2008 16:20:14 +0000 (12:20 -0400)]
Btrfs: Null terminate strings passed in from userspace

The 'char name[BTRFS_PATH_NAME_MAX]' member of struct btrfs_ioctl_vol_args
is passed directly to strlen() after being copied from user. I haven't
verified this, but in theory a userspace program could pass in an
unterminated string and cause a kernel crash as strlen walks off the end of
the array.

This patch terminates the ->name string in all btrfs ioctl functions which
currently use a 'struct btrfs_ioctl_vol_args'. Since the string is now
properly terminated, it's length will never be longer than
BTRFS_PATH_NAME_MAX so that error check has been removed.

By the way, it might be better overall to just have the ioctl pass an
unterminated string + length structure but I didn't bother with that since
it'd change the kernel/user interface.

Signed-off-by: Mark Fasheh <mfasheh@suse.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoFix path slots selection in btrfs_search_forward
Yan [Thu, 24 Jul 2008 16:19:49 +0000 (12:19 -0400)]
Fix path slots selection in btrfs_search_forward

We should decrease the found slot by one as btrfs_search_slot does
when bin_search return 1 and node level > 0.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Fix .. lookup corner case
Yan [Thu, 24 Jul 2008 16:19:32 +0000 (12:19 -0400)]
Btrfs: Fix .. lookup corner case

Inode ref item can be in the next leaf when we find "path->slots[0] ==
btrfs_header_nritems(...)".

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Properly release lock in pin_down_bytes
Yan [Thu, 24 Jul 2008 16:18:16 +0000 (12:18 -0400)]
Btrfs: Properly release lock in pin_down_bytes

When buffer isn't uptodate, pin_down_bytes may leave the tree locked
after it returns.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Remove unused variable in fixup_tree_root_location
Balaji Rao [Thu, 24 Jul 2008 16:17:15 +0000 (12:17 -0400)]
Btrfs: Remove unused variable in fixup_tree_root_location

Remove a unused variable 'path' in fixup_tree_root_location.

Signed-off-by: Balaji Rao <balajirrao@gmail.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Fix a few functions that exit without stopping their transaction
Josef Bacik [Thu, 24 Jul 2008 16:17:14 +0000 (12:17 -0400)]
Btrfs: Fix a few functions that exit without stopping their transaction

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Create orphan inode records to prevent lost files after a crash
Josef Bacik [Thu, 24 Jul 2008 16:17:14 +0000 (12:17 -0400)]
Btrfs: Create orphan inode records to prevent lost files after a crash

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Add ACL support
Josef Bacik [Thu, 24 Jul 2008 16:16:36 +0000 (12:16 -0400)]
Btrfs: Add ACL support

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Remove unused xattr code
Josef Bacik [Thu, 24 Jul 2008 16:16:03 +0000 (12:16 -0400)]
Btrfs: Remove unused xattr code

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Implement new dir index format
Josef Bacik [Thu, 24 Jul 2008 16:12:38 +0000 (12:12 -0400)]
Btrfs: Implement new dir index format

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Fix the defragmention code and the block relocation code for data=ordered
Chris Mason [Thu, 24 Jul 2008 15:57:52 +0000 (11:57 -0400)]
Btrfs: Fix the defragmention code and the block relocation code for data=ordered

Before setting an extent to delalloc, the code needs to wait for
pending ordered extents.

Also, the relocation code needs to wait for ordered IO before scanning
the block group again.  This is because the extents are not removed
until the IO for the new extents is finished

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Use assert_spin_locked instead of spin_trylock
David Woodhouse [Thu, 24 Jul 2008 14:09:43 +0000 (10:09 -0400)]
Btrfs: Use assert_spin_locked instead of spin_trylock

On UP systems spin_trylock always succeeds

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Add version strings on module load
Chris Mason [Wed, 23 Jul 2008 16:12:13 +0000 (12:12 -0400)]
Btrfs: Add version strings on module load

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Fix some build problems on 2.6.18 based enterprise kernels
Chris Mason [Thu, 24 Jul 2008 13:51:08 +0000 (09:51 -0400)]
Btrfs: Fix some build problems on 2.6.18 based enterprise kernels

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Search data ordered extents first for checksums on read
Chris Mason [Thu, 24 Jul 2008 13:41:53 +0000 (09:41 -0400)]
Btrfs: Search data ordered extents first for checksums on read

Checksum items are not inserted into the tree until all of the io from a
given extent is complete.  This means one dirty page from an extent may
be written, freed, and then read again before the entire extent is on disk
and the checksum item is inserted.

The checksums themselves are stored in the ordered extent so they can
be inserted in bulk when IO is complete.  On read, if a checksum item isn't
found, the ordered extents were being searched for a checksum record.

This all worked most of the time, but the checksum insertion code tries
to reduce the number of tree operations by pre-inserting checksum items
based on i_size and a few other factors.  This means the read code might
find a checksum item that hasn't yet really been filled in.

This commit changes things to check the ordered extents first and only
dive into the btree if nothing was found.  This removes the need for
extra locking and is more reliable.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Fix 32 bit compiles by using an unsigned long byte count in the ordered extent
Chris Mason [Wed, 23 Jul 2008 13:26:26 +0000 (09:26 -0400)]
Btrfs: Fix 32 bit compiles by using an unsigned long byte count in the ordered extent

The ordered extents have to fit in memory, so an unsigned long is sufficient.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Take the csum mutex while reading checksums
Chris Mason [Wed, 23 Jul 2008 03:06:42 +0000 (23:06 -0400)]
Btrfs: Take the csum mutex while reading checksums

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: alloc_mutex latency reduction
Chris Mason [Wed, 23 Jul 2008 03:06:41 +0000 (23:06 -0400)]
Btrfs: alloc_mutex latency reduction

This releases the alloc_mutex in a few places that hold it for over long
operations.  btrfs_lookup_block_group is changed so that it doesn't need
the mutex at all.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Add some conditional schedules near the alloc_mutex
Chris Mason [Tue, 22 Jul 2008 16:08:37 +0000 (12:08 -0400)]
Btrfs: Add some conditional schedules near the alloc_mutex

This helps prevent stalls, especially while the snapshot cleaner is
running hard

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Use mutex_lock_nested for tree locking
Chris Mason [Tue, 22 Jul 2008 15:18:09 +0000 (11:18 -0400)]
Btrfs: Use mutex_lock_nested for tree locking

Lockdep has the notion of locking subclasses so that you can identify
locks you expect to be taken after other locks of the same class.  This
changes the per-extent buffer btree locking routines to use a subclass based
on the level in the tree.

Unfortunately, lockdep can only handle 8 total subclasses, and the btrfs
max level is also 8.  So when lockdep is on, use a lower max level.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Fix some data=ordered related data corruptions
Chris Mason [Tue, 22 Jul 2008 15:18:09 +0000 (11:18 -0400)]
Btrfs: Fix some data=ordered related data corruptions

Stress testing was showing data checksum errors, most of which were caused
by a lookup bug in the extent_map tree.  The tree was caching the last
pointer returned, and searches would check the last pointer first.

But, search callers also expect the search to return the very first
matching extent in the range, which wasn't always true with the last
pointer usage.

For now, the code to cache the last return value is just removed.  It is
easy to fix, but I think lookups are rare enough that it isn't required anymore.

This commit also replaces do_sync_mapping_range with a local copy of the
related functions.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Use a mutex in the extent buffer for tree block locking
Chris Mason [Tue, 22 Jul 2008 15:18:08 +0000 (11:18 -0400)]
Btrfs: Use a mutex in the extent buffer for tree block locking

This replaces the use of the page cache lock bit for locking, which wasn't
suitable for block size < page size and couldn't be used recursively.

The mutexes alone don't fix either problem, but they are the first step.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
16 years agoBtrfs: Index extent buffers in an rbtree
Chris Mason [Tue, 22 Jul 2008 15:18:07 +0000 (11:18 -0400)]
Btrfs: Index extent buffers in an rbtree

Before, extent buffers were a temporary object, meant to map a number of pages
at once and collect operations on them.

But, a few extra fields have crept in, and they are also the best place to
store a per-tree block lock field as well.  This commit puts the extent
buffers into an rbtree, and ensures a single extent buffer for each
tree block.

Signed-off-by: Chris Mason <chris.mason@oracle.com>