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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
Chris Mason [Mon, 21 Jul 2008 14:29:44 +0000 (10:29 -0400)]
Btrfs: Data ordered fixes
* In btrfs_delete_inode, wait for ordered extents after calling
truncate_inode_pages. This is much faster, and more correct
* Properly clear our the PageChecked bit everywhere we redirty the page.
* Change the writepage fixup handler to lock the page range and check to
see if an ordered extent had been inserted since the improperly dirtied
page was discovered
* Wait for ordered extents outside the transaction. This isn't required
for locking rules but does improve transaction latencies
* Reduce contention on the alloc_mutex by dropping it while incrementing
refs on a node/leaf and while dropping refs on a leaf.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Sat, 19 Jul 2008 00:42:20 +0000 (20:42 -0400)]
Fix btrfs_wait_ordered_extent_range to properly wait
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Fri, 18 Jul 2008 16:01:11 +0000 (12:01 -0400)]
Btrfs: Keep extent mappings in ram until pending ordered extents are done
It was possible for stale mappings from disk to be used instead of the
new pending ordered extent. This adds a flag to the extent map struct
to keep it pinned until the pending ordered extent is actually on disk.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Fri, 18 Jul 2008 15:56:15 +0000 (11:56 -0400)]
Btrfs: Don't allow releasepage to succeed if EXTENT_ORDERED is set
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Fri, 18 Jul 2008 10:17:13 +0000 (06:17 -0400)]
Btrfs: Handle data checksumming on bios that span multiple ordered extents
Data checksumming is done right before the bio is sent down the IO stack,
which means a single bio might span more than one ordered extent. In
this case, the checksumming data is split between two ordered extents.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Thu, 17 Jul 2008 17:53:27 +0000 (13:53 -0400)]
Btrfs: Cleanup and comment ordered-data.c
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Thu, 17 Jul 2008 16:54:48 +0000 (12:54 -0400)]
Btrfs: Force caching of metadata block groups on mount to avoid deadlock
This is a temporary change to avoid deadlocks until the extent tree locking
is fixed up.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Thu, 17 Jul 2008 16:54:43 +0000 (12:54 -0400)]
btrfs_next_leaf: do readahead when skip_locking is turned on
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Thu, 17 Jul 2008 16:54:40 +0000 (12:54 -0400)]
Add a per-inode lock around btrfs_drop_extents
btrfs_drop_extents is always called with a range lock held on the inode.
But, it may operate on extents outside that range as it drops and splits
them.
This patch adds a per-inode mutex that is held while calling
btrfs_drop_extents and while inserting new extents into the tree. It
prevents races from two procs working against adjacent ranges in the tree.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Thu, 17 Jul 2008 16:54:15 +0000 (12:54 -0400)]
Btrfs: Don't pin pages in ram until the entire ordered extent is on disk.
Checksum items are not inserted until the entire ordered extent is on disk,
but individual pages might be clean and available for reclaim long before
the whole extent is on disk.
In order to allow those pages to be freed, we need to be able to search
the list of ordered extents to find the checksum that is going to be inserted
in the tree. This way if the page needs to be read back in before
the checksums are in the btree, we'll be able to verify the checksum on
the page.
This commit adds the ability to search the pending ordered extents for
a given offset in the file, and changes btrfs_releasepage to allow
ordered pages to be freed.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Thu, 17 Jul 2008 16:54:14 +0000 (12:54 -0400)]
btrfs_start_transaction: wait for commits in progress to finish
btrfs_commit_transaction has to loop waiting for any writers in the
transaction to finish before it can proceed. btrfs_start_transaction
should be polite and not join a transaction that is in the process
of being finished off.
There are a few places that can't wait, basically the ones doing IO that
might be needed to finish the transaction. For them, btrfs_join_transaction
is added.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Thu, 17 Jul 2008 16:54:05 +0000 (12:54 -0400)]
Btrfs: Update on disk i_size only after pending ordered extents are done
This changes the ordered data code to update i_size after the extent
is on disk. An on disk i_size is maintained in the in-memory btrfs inode
structures, and this is updated as extents finish.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Thu, 17 Jul 2008 16:53:51 +0000 (12:53 -0400)]
Btrfs: Use async helpers to deal with pages that have been improperly dirtied
Higher layers sometimes call set_page_dirty without asking the filesystem
to help. This causes many problems for the data=ordered and cow code.
This commit detects pages that haven't been properly setup for IO and
kicks off an async helper to deal with them.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Thu, 17 Jul 2008 16:53:50 +0000 (12:53 -0400)]
Btrfs: New data=ordered implementation
The old data=ordered code would force commit to wait until
all the data extents from the transaction were fully on disk. This
introduced large latencies into the commit and stalled new writers
in the transaction for a long time.
The new code changes the way data allocations and extents work:
* When delayed allocation is filled, data extents are reserved, and
the extent bit EXTENT_ORDERED is set on the entire range of the extent.
A struct btrfs_ordered_extent is allocated an inserted into a per-inode
rbtree to track the pending extents.
* As each page is written EXTENT_ORDERED is cleared on the bytes corresponding
to that page.
* When all of the bytes corresponding to a single struct btrfs_ordered_extent
are written, The previously reserved extent is inserted into the FS
btree and into the extent allocation trees. The checksums for the file
data are also updated.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Tue, 8 Jul 2008 18:32:12 +0000 (14:32 -0400)]
Btrfs: Drop some verbose printks
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Tue, 8 Jul 2008 18:19:17 +0000 (14:19 -0400)]
Btrfs: Add locking around volume management (device add/remove/balance)
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Thu, 26 Jun 2008 14:34:20 +0000 (10:34 -0400)]
Btrfs: Fix deadlock while searching for dead roots on mount
btrfs_find_dead_roots called btrfs_read_fs_root_no_radix, which
means we end up calling btrfs_search_slot with a path already held.
The fix is to remember the key inside btrfs_find_dead_roots and drop
the path.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Wed, 25 Jun 2008 20:14:04 +0000 (16:14 -0400)]
Btrfs: Reduce contention on the root node
This calls unlock_up sooner in btrfs_search_slot in order to decrease the
amount of work done with the higher level tree locks held.
Also, it changes btrfs_tree_lock to spin for a big against the page lock
before scheduling. This makes a big difference in context switch rate under
highly contended workloads.
Longer term, a better locking structure is needed than the page lock.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Wed, 25 Jun 2008 20:01:31 +0000 (16:01 -0400)]
Btrfs: Online btree defragmentation fixes
The btree defragger wasn't making forward progress because the new key wasn't
being saved by the btrfs_search_forward function.
This also disables the automatic btree defrag, it wasn't scaling well to
huge filesystems. The auto-defrag needs to be done differently.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Wed, 25 Jun 2008 20:01:31 +0000 (16:01 -0400)]
Btrfs: Add a per-inode csum mutex to avoid races creating csum items
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Wed, 25 Jun 2008 20:01:31 +0000 (16:01 -0400)]
Btrfs: Change find_extent_buffer to use TestSetPageLocked
This makes it possible for callers to check for extent_buffers in cache
without deadlocking against any btree locks held.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Wed, 25 Jun 2008 20:01:31 +0000 (16:01 -0400)]
Btrfs: Add btree locking to the tree defragmentation code
The online btree defragger is simplified and rewritten to use
standard btree searches instead of a walk up / down mechanism.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Wed, 25 Jun 2008 20:01:31 +0000 (16:01 -0400)]
Btrfs: Replace the transaction work queue with kthreads
This creates one kthread for commits and one kthread for
deleting old snapshots. All the work queues are removed.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Wed, 25 Jun 2008 20:01:31 +0000 (16:01 -0400)]
Add btrfs_end_transaction_throttle to force writers to wait for pending commits
The existing throttle mechanism was often not sufficient to prevent
new writers from coming in and making a given transaction run forever.
This adds an explicit wait at the end of most operations so they will
allow the current transaction to close.
There is no wait inside file_write, inode updates, or cow filling, all which
have different deadlock possibilities.
This is a temporary measure until better asynchronous commit support is
added. This code leads to stalls as it waits for data=ordered
writeback, and it really needs to be fixed.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Wed, 25 Jun 2008 20:01:30 +0000 (16:01 -0400)]
Btrfs: Fix snapshot deletion to release the alloc_mutex much more often.
This lowers the impact of snapshot deletion on the rest of the FS.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Wed, 25 Jun 2008 20:01:30 +0000 (16:01 -0400)]
Btrfs: Add a skip_locking parameter to struct path, and make various funcs honor it
Allocations may need to read in block groups from the extent allocation tree,
which will require a tree search and take locks on the extent allocation
tree. But, those locks might already be held in other places, leading
to deadlocks.
Since the alloc_mutex serializes everything right now, it is safe to
skip the btree locking while caching block groups. A better fix will be
to either create a recursive lock or find a way to back off existing
locks while caching block groups.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Wed, 25 Jun 2008 20:01:30 +0000 (16:01 -0400)]
Fix btrfs_next_leaf to check for new items after dropping locks
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Wed, 25 Jun 2008 20:01:30 +0000 (16:01 -0400)]
Fix btrfs_del_ordered_inode to allow forcing the drop during unlinks
This allows us to delete an unlinked inode with dirty pages from the list
instead of forcing commit to write these out before deleting the inode.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Wed, 25 Jun 2008 20:01:30 +0000 (16:01 -0400)]
Drop locks in btrfs_search_slot when reading a tree block.
One lock per btree block can make for significant congestion if everyone
has to wait for IO at the high levels of the btree. This drops
locks held by a path when doing reads during a tree search.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Wed, 25 Jun 2008 20:01:30 +0000 (16:01 -0400)]
Btrfs: Replace the big fs_mutex with a collection of other locks
Extent alloctions are still protected by a large alloc_mutex.
Objectid allocations are covered by a objectid mutex
Other btree operations are protected by a lock on individual btree nodes
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Wed, 25 Jun 2008 20:01:30 +0000 (16:01 -0400)]
Btrfs: Start btree concurrency work.
The allocation trees and the chunk trees are serialized via their own
dedicated mutexes. This means allocation location is still not very
fine grained.
The main FS btree is protected by locks on each block in the btree. Locks
are taken top / down, and as processing finishes on a given level of the
tree, the lock is released after locking the lower level.
The end result of a search is now a path where only the lowest level
is locked. Releasing or freeing the path drops any locks held.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Thu, 12 Jun 2008 18:46:17 +0000 (14:46 -0400)]
Btrfs: Add a thread pool just for submit_bio
If a bio submission is after a lock holder waiting for the bio
on the work queue, it is possible to deadlock. Move the bios
into their own pool.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Christoph Hellwig [Thu, 12 Jun 2008 01:53:58 +0000 (21:53 -0400)]
BTRFS_IOC_TRANS_START should be privilegued
As mentioned in the comment next to it btrfs_ioctl_trans_start can
do bad damage to filesystems and thus should be limited to privilegued
users.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Christoph Hellwig [Thu, 12 Jun 2008 01:53:53 +0000 (21:53 -0400)]
Btrfs: split out ioctl.c
Split the ioctl handling out of inode.c into a file of it's own.
Also fix up checkpatch.pl warnings for the moved code.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Christoph Hellwig [Thu, 12 Jun 2008 01:52:17 +0000 (21:52 -0400)]
Btrfs: kerneldoc comments for extent_map.c
Add kerneldoc comments for all exported functions.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Thu, 12 Jun 2008 01:47:56 +0000 (21:47 -0400)]
Btrfs: Add a mount option to control worker thread pool size
mount -o thread_pool_size changes the default, which is
min(num_cpus + 2, 8). Larger thread pools would make more sense on
very large disk arrays.
This mount option controls the max size of each thread pool. There
are multiple thread pools, so the total worker count will be larger
than the mount option.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Thu, 12 Jun 2008 00:21:24 +0000 (20:21 -0400)]
Btrfs: Worker thread optimizations
This changes the worker thread pool to maintain a list of idle threads,
avoiding a complex search for a good thread to wake up.
Threads have two states:
idle - we try to reuse the last thread used in hopes of improving the batching
ratios
busy - each time a new work item is added to a busy task, the task is
rotated to the end of the line.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Wed, 11 Jun 2008 21:09:48 +0000 (17:09 -0400)]
Btrfs: Add backport for the kthread work on kernels older than 2.6.20
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Wed, 11 Jun 2008 20:51:38 +0000 (16:51 -0400)]
Btrfs: Fix mount -o max_inline=0
max_inline=0 used to force the max_inline size to one sector instead. Now
it properly disables inline data items, while still being able to read
any that happen to exist on disk.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Wed, 11 Jun 2008 20:50:36 +0000 (16:50 -0400)]
Btrfs: Add async worker threads for pre and post IO checksumming
Btrfs has been using workqueues to spread the checksumming load across
other CPUs in the system. But, workqueues only schedule work on the
same CPU that queued the work, giving them a limited benefit for systems with
higher CPU counts.
This code adds a generic facility to schedule work with pools of kthreads,
and changes the bio submission code to queue bios up. The queueing is
important to make sure large numbers of procs on the system don't
turn streaming workloads into random workloads by sending IO down
concurrently.
The end result of all of this is much higher performance (and CPU usage) when
doing checksumming on large machines. Two worker pools are created,
one for writes and one for endio processing. The two could deadlock if
we tried to service both from a single pool.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Christoph Hellwig [Tue, 10 Jun 2008 14:40:46 +0000 (10:40 -0400)]
btrfs: allow scanning multiple devices during mount
Allows to specify one or multiple device=/dev/foo options during mount
so that ioctls on the control device can be avoided. Especially useful
when trying to mount a multi-device setup as root.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Christoph Hellwig [Tue, 10 Jun 2008 14:40:29 +0000 (10:40 -0400)]
btrfs: sanity mount option parsing and early mount code
Also adds lots of comments to describe what's going on here.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Christoph Hellwig [Tue, 10 Jun 2008 14:21:04 +0000 (10:21 -0400)]
btrfs: fix strange indentation in lookup_extent_mapping
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Christoph Hellwig [Tue, 10 Jun 2008 14:20:57 +0000 (10:20 -0400)]
btrfs: tiny makefile cleanup
use normal kbuild syntax to build acl.o conditinally and remove comment
out lines.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Sage Weil [Tue, 10 Jun 2008 14:07:39 +0000 (10:07 -0400)]
Btrfs: transaction ioctls
These ioctls let a user application hold a transaction open while it
performs a series of operations. A final ioctl does a sync on the fs
(closing the current transaction). This is the main requirement for
Ceph's OSD to be able to keep the data it's storing in a btrfs volume
consistent, and AFAICS it works just fine. The application would do
something like
fd = ::open("some/file", O_RDONLY);
::ioctl(fd, BTRFS_IOC_TRANS_START);
/* do a bunch of stuff */
::ioctl(fd, BTRFS_IOC_TRANS_END);
or just
::close(fd);
And to ensure it commits to disk,
::ioctl(fd, BTRFS_IOC_SYNC);
When a transaction is held open, the trans_handle is attached to the
struct file (via private_data) so that it will get cleaned up if the
process dies unexpectedly. A held transaction is also ended on fsync() to
avoid a deadlock.
A misbehaving application could also deliberately hold a transaction open,
effectively locking up the FS, so it may make sense to restrict something
like this to root or something.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Yan [Tue, 10 Jun 2008 02:21:46 +0000 (22:21 -0400)]
Btrfs: Dislable acl xattr handlers
The acl code is not yet complete, and the xattr handlers are causing
problems for cp -p on some distros.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Jan Engelhardt [Tue, 10 Jun 2008 02:19:40 +0000 (22:19 -0400)]
Btrfs: bdi_init and bdi_destroy come with 2.6.23
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Linda Knippers [Tue, 10 Jun 2008 02:17:11 +0000 (22:17 -0400)]
btrfsctl -A error code fixup
Send the error back to userland if the ioctl fails
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Sven Wegener [Tue, 10 Jun 2008 01:57:42 +0000 (21:57 -0400)]
Btrfs: Invalidate dcache entry after creating snapshot and
We need to invalidate an existing dcache entry after creating a new
snapshot or subvolume, because a negative dache entry will stop us from
accessing the new snapshot or subvolume.
---
ctree.h | 23 +++++++++++++++++++++++
inode.c | 4 ++++
transaction.c | 4 ++++
3 files changed, 31 insertions(+)
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Mon, 9 Jun 2008 13:35:50 +0000 (09:35 -0400)]
Btrfs: Fix race in running_transaction checks
When a new transaction was started, the code would incorrectly
set the pointer in fs_info before all the data structures were setup.
fsync heavy workloads hit races on the setup of the ordered inode spinlock
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Mingming [Tue, 27 May 2008 14:55:43 +0000 (10:55 -0400)]
btrfs delete ordered inode handling fix
Use btrfs_release_file instead of a put_inode call
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Tue, 27 May 2008 14:52:17 +0000 (10:52 -0400)]
Btrfs: Always use the async submission queue for checksummed writes
This avoids IO stalls and poorly ordered IO from inline writers mixing in
with the async submission queue
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Sat, 24 May 2008 18:04:53 +0000 (14:04 -0400)]
Btrfs: Allocator fix variety pack
* Force chunk allocation when find_free_extent has to do a full scan
* Record the max key at the start of defrag so it doesn't run forever
* Block groups might not be contiguous, make a forward search for the
next block group in extent-tree.c
* Get rid of extra checks for total fs size
* Fix relocate_one_reference to avoid relocating the same file data block
twice when referenced by an older transaction
* Use the open device count when allocating chunks so that we don't
try to allocate from devices that don't exist
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Fri, 16 May 2008 17:30:15 +0000 (13:30 -0400)]
Btrfs: Use kzalloc on the fs_devices allocation
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Fri, 16 May 2008 17:14:57 +0000 (13:14 -0400)]
Btrfs: Handle transid == 0 while opening devices
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Fri, 16 May 2008 17:06:51 +0000 (13:06 -0400)]
Btrfs: Enable btree balancing on old kernels again
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Thu, 15 May 2008 20:15:45 +0000 (16:15 -0400)]
Btrfs: Change the congestion functions to meter the number of async submits as well
The async submit workqueue was absorbing too many requests, leading to long
stalls where the async submitters were stalling.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Thu, 15 May 2008 13:13:45 +0000 (09:13 -0400)]
Fix corners in writepage and btrfs_truncate_page
The extent_io writepage calls needed an extra check for discarding
pages that started on th last byte in the file.
btrfs_truncate_page needed checks to make sure the page was still part
of the file after reading it, and most importantly, needed to wait for
all IO to the page to finish before freeing the corresponding extents on
disk.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Tue, 13 May 2008 20:03:06 +0000 (16:03 -0400)]
Fix btrfs_open_devices to deal with changes since the scan ioctls
Devices can change after the scan ioctls are done, and btrfs_open_devices
needs to be able to verify them as they are opened and used by the FS.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Tue, 13 May 2008 17:46:40 +0000 (13:46 -0400)]
Btrfs: Add mount -o degraded to allow mounts to continue with missing devices
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Mon, 12 May 2008 17:39:03 +0000 (13:39 -0400)]
Btrfs: Handle write errors on raid1 and raid10
When duplicate copies exist, writes are allowed to fail to one of those
copies. This changeset includes a few changes that allow the FS to
continue even when some IOs fail.
It also adds verification of the parent generation number for btree blocks.
This generation is stored in the pointer to a block, and it ensures
that missed writes to are detected.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Mon, 12 May 2008 16:59:19 +0000 (12:59 -0400)]
Btrfs: Pass down the expected generation number when reading tree blocks
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Fri, 9 May 2008 15:52:25 +0000 (11:52 -0400)]
Btrfs: Don't do btree balance_dirty_pages on old kernels, it stalls forever
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Fri, 9 May 2008 15:46:48 +0000 (11:46 -0400)]
Btrfs: Chunk relocation fine tuning, and add a few printks to show progress
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Thu, 8 May 2008 20:31:21 +0000 (16:31 -0400)]
Btrfs: A number of nodatacow fixes
Once part of a delalloc request fails the cow checks, just cow the
entire range
It is possible for the back references to all be from the same root,
but still have snapshots against an extent. The checks are now more strict,
forcing cow any time there are multiple refs against the data extent.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Thu, 8 May 2008 19:05:58 +0000 (15:05 -0400)]
Btrfs: Only open block devices once during mount -o subvol=
btrfs_open_devices needed a check to see if the device was already
open.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Thu, 8 May 2008 18:11:56 +0000 (14:11 -0400)]
Btrfs: Update nodatacow mode to support cloned single files and resizing
Before, nodatacow only checked to make sure multiple roots didn't have
references on a single extent. This check makes sure that multiple
inodes don't have references.
nodatacow needed an extra check to see if the block group was currently
readonly. This way cows forced by the chunk relocation code are honored.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Thu, 8 May 2008 17:26:18 +0000 (13:26 -0400)]
Btrfs: Properly find the root for snapshotted blocks during chunk relocation
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Wed, 7 May 2008 15:43:44 +0000 (11:43 -0400)]
Btrfs: Add support for online device removal
This required a few structural changes to the code that manages bdev pointers:
The VFS super block now gets an anon-bdev instead of a pointer to the
lowest bdev. This allows us to avoid swapping the super block bdev pointer
around at run time.
The code to read in the super block no longer goes through the extent
buffer interface. Things got ugly keeping the mapping constant.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason [Mon, 5 May 2008 10:26:21 +0000 (06:26 -0400)]
Btrfs: Fix clone ioctl to not hold the path over inserts
Signed-off-by: Chris Mason <chris.mason@oracle.com>