2007-06-12 20:07:21 +07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 Oracle. All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public
|
|
|
|
* License v2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 021110-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2007-08-29 20:11:44 +07:00
|
|
|
#include <linux/blkdev.h>
|
2007-03-21 22:12:56 +07:00
|
|
|
#include <linux/module.h>
|
2007-03-22 23:13:20 +07:00
|
|
|
#include <linux/buffer_head.h>
|
2007-03-21 22:12:56 +07:00
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/highmem.h>
|
|
|
|
#include <linux/time.h>
|
|
|
|
#include <linux/init.h>
|
2009-04-03 03:46:06 +07:00
|
|
|
#include <linux/seq_file.h>
|
2007-03-21 22:12:56 +07:00
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/backing-dev.h>
|
2007-08-29 20:11:44 +07:00
|
|
|
#include <linux/mount.h>
|
2007-03-27 03:00:06 +07:00
|
|
|
#include <linux/mpage.h>
|
2007-03-29 22:56:46 +07:00
|
|
|
#include <linux/swap.h>
|
|
|
|
#include <linux/writeback.h>
|
2007-04-20 08:01:03 +07:00
|
|
|
#include <linux/statfs.h>
|
2007-06-09 02:33:54 +07:00
|
|
|
#include <linux/compat.h>
|
2007-08-29 20:11:44 +07:00
|
|
|
#include <linux/parser.h>
|
2007-12-18 08:14:04 +07:00
|
|
|
#include <linux/ctype.h>
|
2007-12-19 04:15:09 +07:00
|
|
|
#include <linux/namei.h>
|
2008-03-25 02:02:04 +07:00
|
|
|
#include <linux/miscdevice.h>
|
2009-01-16 04:51:03 +07:00
|
|
|
#include <linux/magic.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2011-05-26 23:01:56 +07:00
|
|
|
#include <linux/cleancache.h>
|
2011-11-30 22:45:38 +07:00
|
|
|
#include <linux/ratelimit.h>
|
2013-01-29 13:04:50 +07:00
|
|
|
#include <linux/btrfs.h>
|
btrfs: implement delayed inode items operation
Changelog V5 -> V6:
- Fix oom when the memory load is high, by storing the delayed nodes into the
root's radix tree, and letting btrfs inodes go.
Changelog V4 -> V5:
- Fix the race on adding the delayed node to the inode, which is spotted by
Chris Mason.
- Merge Chris Mason's incremental patch into this patch.
- Fix deadlock between readdir() and memory fault, which is reported by
Itaru Kitayama.
Changelog V3 -> V4:
- Fix nested lock, which is reported by Itaru Kitayama, by updating space cache
inode in time.
Changelog V2 -> V3:
- Fix the race between the delayed worker and the task which does delayed items
balance, which is reported by Tsutomu Itoh.
- Modify the patch address David Sterba's comment.
- Fix the bug of the cpu recursion spinlock, reported by Chris Mason
Changelog V1 -> V2:
- break up the global rb-tree, use a list to manage the delayed nodes,
which is created for every directory and file, and used to manage the
delayed directory name index items and the delayed inode item.
- introduce a worker to deal with the delayed nodes.
Compare with Ext3/4, the performance of file creation and deletion on btrfs
is very poor. the reason is that btrfs must do a lot of b+ tree insertions,
such as inode item, directory name item, directory name index and so on.
If we can do some delayed b+ tree insertion or deletion, we can improve the
performance, so we made this patch which implemented delayed directory name
index insertion/deletion and delayed inode update.
Implementation:
- introduce a delayed root object into the filesystem, that use two lists to
manage the delayed nodes which are created for every file/directory.
One is used to manage all the delayed nodes that have delayed items. And the
other is used to manage the delayed nodes which is waiting to be dealt with
by the work thread.
- Every delayed node has two rb-tree, one is used to manage the directory name
index which is going to be inserted into b+ tree, and the other is used to
manage the directory name index which is going to be deleted from b+ tree.
- introduce a worker to deal with the delayed operation. This worker is used
to deal with the works of the delayed directory name index items insertion
and deletion and the delayed inode update.
When the delayed items is beyond the lower limit, we create works for some
delayed nodes and insert them into the work queue of the worker, and then
go back.
When the delayed items is beyond the upper bound, we create works for all
the delayed nodes that haven't been dealt with, and insert them into the work
queue of the worker, and then wait for that the untreated items is below some
threshold value.
- When we want to insert a directory name index into b+ tree, we just add the
information into the delayed inserting rb-tree.
And then we check the number of the delayed items and do delayed items
balance. (The balance policy is above.)
- When we want to delete a directory name index from the b+ tree, we search it
in the inserting rb-tree at first. If we look it up, just drop it. If not,
add the key of it into the delayed deleting rb-tree.
Similar to the delayed inserting rb-tree, we also check the number of the
delayed items and do delayed items balance.
(The same to inserting manipulation)
- When we want to update the metadata of some inode, we cached the data of the
inode into the delayed node. the worker will flush it into the b+ tree after
dealing with the delayed insertion and deletion.
- We will move the delayed node to the tail of the list after we access the
delayed node, By this way, we can cache more delayed items and merge more
inode updates.
- If we want to commit transaction, we will deal with all the delayed node.
- the delayed node will be freed when we free the btrfs inode.
- Before we log the inode items, we commit all the directory name index items
and the delayed inode update.
I did a quick test by the benchmark tool[1] and found we can improve the
performance of file creation by ~15%, and file deletion by ~20%.
Before applying this patch:
Create files:
Total files: 50000
Total time: 1.096108
Average time: 0.000022
Delete files:
Total files: 50000
Total time: 1.510403
Average time: 0.000030
After applying this patch:
Create files:
Total files: 50000
Total time: 0.932899
Average time: 0.000019
Delete files:
Total files: 50000
Total time: 1.215732
Average time: 0.000024
[1] http://marc.info/?l=linux-btrfs&m=128212635122920&q=p3
Many thanks for Kitayama-san's help!
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Reviewed-by: David Sterba <dave@jikos.cz>
Tested-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
Tested-by: Itaru Kitayama <kitayama@cl.bb4u.ne.jp>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-04-22 17:12:22 +07:00
|
|
|
#include "delayed-inode.h"
|
2007-03-21 22:12:56 +07:00
|
|
|
#include "ctree.h"
|
2007-03-22 23:13:20 +07:00
|
|
|
#include "disk-io.h"
|
2007-03-23 21:01:08 +07:00
|
|
|
#include "transaction.h"
|
2007-04-02 21:50:19 +07:00
|
|
|
#include "btrfs_inode.h"
|
2007-05-25 00:35:57 +07:00
|
|
|
#include "print-tree.h"
|
2014-01-12 09:22:46 +07:00
|
|
|
#include "hash.h"
|
Btrfs: add support for inode properties
This change adds infrastructure to allow for generic properties for
inodes. Properties are name/value pairs that can be associated with
inodes for different purposes. They are stored as xattrs with the
prefix "btrfs."
Properties can be inherited - this means when a directory inode has
inheritable properties set, these are added to new inodes created
under that directory. Further, subvolumes can also have properties
associated with them, and they can be inherited from their parent
subvolume. Naturally, directory properties have priority over subvolume
properties (in practice a subvolume property is just a regular
property associated with the root inode, objectid 256, of the
subvolume's fs tree).
This change also adds one specific property implementation, named
"compression", whose values can be "lzo" or "zlib" and it's an
inheritable property.
The corresponding changes to btrfs-progs were also implemented.
A patch with xfstests for this feature will follow once there's
agreement on this change/feature.
Further, the script at the bottom of this commit message was used to
do some benchmarks to measure any performance penalties of this feature.
Basically the tests correspond to:
Test 1 - create a filesystem and mount it with compress-force=lzo,
then sequentially create N files of 64Kb each, measure how long it took
to create the files, unmount the filesystem, mount the filesystem and
perform an 'ls -lha' against the test directory holding the N files, and
report the time the command took.
Test 2 - create a filesystem and don't use any compression option when
mounting it - instead set the compression property of the subvolume's
root to 'lzo'. Then create N files of 64Kb, and report the time it took.
The unmount the filesystem, mount it again and perform an 'ls -lha' like
in the former test. This means every single file ends up with a property
(xattr) associated to it.
Test 3 - same as test 2, but uses 4 properties - 3 are duplicates of the
compression property, have no real effect other than adding more work
when inheriting properties and taking more btree leaf space.
Test 4 - same as test 3 but with 10 properties per file.
Results (in seconds, and averages of 5 runs each), for different N
numbers of files follow.
* Without properties (test 1)
file creation time ls -lha time
10 000 files 3.49 0.76
100 000 files 47.19 8.37
1 000 000 files 518.51 107.06
* With 1 property (compression property set to lzo - test 2)
file creation time ls -lha time
10 000 files 3.63 0.93
100 000 files 48.56 9.74
1 000 000 files 537.72 125.11
* With 4 properties (test 3)
file creation time ls -lha time
10 000 files 3.94 1.20
100 000 files 52.14 11.48
1 000 000 files 572.70 142.13
* With 10 properties (test 4)
file creation time ls -lha time
10 000 files 4.61 1.35
100 000 files 58.86 13.83
1 000 000 files 656.01 177.61
The increased latencies with properties are essencialy because of:
*) When creating an inode, we now synchronously write 1 more item
(an xattr item) for each property inherited from the parent dir
(or subvolume). This could be done in an asynchronous way such
as we do for dir intex items (delayed-inode.c), which could help
reduce the file creation latency;
*) With properties, we now have larger fs trees. For this particular
test each xattr item uses 75 bytes of leaf space in the fs tree.
This could be less by using a new item for xattr items, instead of
the current btrfs_dir_item, since we could cut the 'location' and
'type' fields (saving 18 bytes) and maybe 'transid' too (saving a
total of 26 bytes per xattr item) from the btrfs_dir_item type.
Also tried batching the xattr insertions (ignoring proper hash
collision handling, since it didn't exist) when creating files that
inherit properties from their parent inode/subvolume, but the end
results were (surprisingly) essentially the same.
Test script:
$ cat test.pl
#!/usr/bin/perl -w
use strict;
use Time::HiRes qw(time);
use constant NUM_FILES => 10_000;
use constant FILE_SIZES => (64 * 1024);
use constant DEV => '/dev/sdb4';
use constant MNT_POINT => '/home/fdmanana/btrfs-tests/dev';
use constant TEST_DIR => (MNT_POINT . '/testdir');
system("mkfs.btrfs", "-l", "16384", "-f", DEV) == 0 or die "mkfs.btrfs failed!";
# following line for testing without properties
#system("mount", "-o", "compress-force=lzo", DEV, MNT_POINT) == 0 or die "mount failed!";
# following 2 lines for testing with properties
system("mount", DEV, MNT_POINT) == 0 or die "mount failed!";
system("btrfs", "prop", "set", MNT_POINT, "compression", "lzo") == 0 or die "set prop failed!";
system("mkdir", TEST_DIR) == 0 or die "mkdir failed!";
my ($t1, $t2);
$t1 = time();
for (my $i = 1; $i <= NUM_FILES; $i++) {
my $p = TEST_DIR . '/file_' . $i;
open(my $f, '>', $p) or die "Error opening file!";
$f->autoflush(1);
for (my $j = 0; $j < FILE_SIZES; $j += 4096) {
print $f ('A' x 4096) or die "Error writing to file!";
}
close($f);
}
$t2 = time();
print "Time to create " . NUM_FILES . ": " . ($t2 - $t1) . " seconds.\n";
system("umount", DEV) == 0 or die "umount failed!";
system("mount", DEV, MNT_POINT) == 0 or die "mount failed!";
$t1 = time();
system("bash -c 'ls -lha " . TEST_DIR . " > /dev/null'") == 0 or die "ls failed!";
$t2 = time();
print "Time to ls -lha all files: " . ($t2 - $t1) . " seconds.\n";
system("umount", DEV) == 0 or die "umount failed!";
Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: Chris Mason <clm@fb.com>
2014-01-07 18:47:46 +07:00
|
|
|
#include "props.h"
|
2007-11-16 23:45:54 +07:00
|
|
|
#include "xattr.h"
|
2008-03-25 02:02:07 +07:00
|
|
|
#include "volumes.h"
|
2008-07-21 03:31:56 +07:00
|
|
|
#include "export.h"
|
Btrfs: Add zlib compression support
This is a large change for adding compression on reading and writing,
both for inline and regular extents. It does some fairly large
surgery to the writeback paths.
Compression is off by default and enabled by mount -o compress. Even
when the -o compress mount option is not used, it is possible to read
compressed extents off the disk.
If compression for a given set of pages fails to make them smaller, the
file is flagged to avoid future compression attempts later.
* While finding delalloc extents, the pages are locked before being sent down
to the delalloc handler. This allows the delalloc handler to do complex things
such as cleaning the pages, marking them writeback and starting IO on their
behalf.
* Inline extents are inserted at delalloc time now. This allows us to compress
the data before inserting the inline extent, and it allows us to insert
an inline extent that spans multiple pages.
* All of the in-memory extent representations (extent_map.c, ordered-data.c etc)
are changed to record both an in-memory size and an on disk size, as well
as a flag for compression.
From a disk format point of view, the extent pointers in the file are changed
to record the on disk size of a given extent and some encoding flags.
Space in the disk format is allocated for compression encoding, as well
as encryption and a generic 'other' field. Neither the encryption or the
'other' field are currently used.
In order to limit the amount of data read for a single random read in the
file, the size of a compressed extent is limited to 128k. This is a
software only limit, the disk format supports u64 sized compressed extents.
In order to limit the ram consumed while processing extents, the uncompressed
size of a compressed extent is limited to 256k. This is a software only limit
and will be subject to tuning later.
Checksumming is still done on compressed extents, and it is done on the
uncompressed version of the data. This way additional encodings can be
layered on without having to figure out which encoding to checksum.
Compression happens at delalloc time, which is basically singled threaded because
it is usually done by a single pdflush thread. This makes it tricky to
spread the compression load across all the cpus on the box. We'll have to
look at parallel pdflush walks of dirty inodes at a later time.
Decompression is hooked into readpages and it does spread across CPUs nicely.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2008-10-30 01:49:59 +07:00
|
|
|
#include "compression.h"
|
2012-06-06 01:13:12 +07:00
|
|
|
#include "rcu-string.h"
|
2012-11-06 19:15:27 +07:00
|
|
|
#include "dev-replace.h"
|
2013-03-15 20:47:08 +07:00
|
|
|
#include "free-space-cache.h"
|
2013-08-09 12:25:36 +07:00
|
|
|
#include "backref.h"
|
2013-08-15 02:05:12 +07:00
|
|
|
#include "tests/btrfs-tests.h"
|
2007-03-21 22:12:56 +07:00
|
|
|
|
2014-07-18 02:39:00 +07:00
|
|
|
#include "qgroup.h"
|
Btrfs: add initial tracepoint support for btrfs
Tracepoints can provide insight into why btrfs hits bugs and be greatly
helpful for debugging, e.g
dd-7822 [000] 2121.641088: btrfs_inode_request: root = 5(FS_TREE), gen = 4, ino = 256, blocks = 8, disk_i_size = 0, last_trans = 8, logged_trans = 0
dd-7822 [000] 2121.641100: btrfs_inode_new: root = 5(FS_TREE), gen = 8, ino = 257, blocks = 0, disk_i_size = 0, last_trans = 0, logged_trans = 0
btrfs-transacti-7804 [001] 2146.935420: btrfs_cow_block: root = 2(EXTENT_TREE), refs = 2, orig_buf = 29368320 (orig_level = 0), cow_buf = 29388800 (cow_level = 0)
btrfs-transacti-7804 [001] 2146.935473: btrfs_cow_block: root = 1(ROOT_TREE), refs = 2, orig_buf = 29364224 (orig_level = 0), cow_buf = 29392896 (cow_level = 0)
btrfs-transacti-7804 [001] 2146.972221: btrfs_transaction_commit: root = 1(ROOT_TREE), gen = 8
flush-btrfs-2-7821 [001] 2155.824210: btrfs_chunk_alloc: root = 3(CHUNK_TREE), offset = 1103101952, size = 1073741824, num_stripes = 1, sub_stripes = 0, type = DATA
flush-btrfs-2-7821 [001] 2155.824241: btrfs_cow_block: root = 2(EXTENT_TREE), refs = 2, orig_buf = 29388800 (orig_level = 0), cow_buf = 29396992 (cow_level = 0)
flush-btrfs-2-7821 [001] 2155.824255: btrfs_cow_block: root = 4(DEV_TREE), refs = 2, orig_buf = 29372416 (orig_level = 0), cow_buf = 29401088 (cow_level = 0)
flush-btrfs-2-7821 [000] 2155.824329: btrfs_cow_block: root = 3(CHUNK_TREE), refs = 2, orig_buf = 20971520 (orig_level = 0), cow_buf = 20975616 (cow_level = 0)
btrfs-endio-wri-7800 [001] 2155.898019: btrfs_cow_block: root = 5(FS_TREE), refs = 2, orig_buf = 29384704 (orig_level = 0), cow_buf = 29405184 (cow_level = 0)
btrfs-endio-wri-7800 [001] 2155.898043: btrfs_cow_block: root = 7(CSUM_TREE), refs = 2, orig_buf = 29376512 (orig_level = 0), cow_buf = 29409280 (cow_level = 0)
Here is what I have added:
1) ordere_extent:
btrfs_ordered_extent_add
btrfs_ordered_extent_remove
btrfs_ordered_extent_start
btrfs_ordered_extent_put
These provide critical information to understand how ordered_extents are
updated.
2) extent_map:
btrfs_get_extent
extent_map is used in both read and write cases, and it is useful for tracking
how btrfs specific IO is running.
3) writepage:
__extent_writepage
btrfs_writepage_end_io_hook
Pages are cirtical resourses and produce a lot of corner cases during writeback,
so it is valuable to know how page is written to disk.
4) inode:
btrfs_inode_new
btrfs_inode_request
btrfs_inode_evict
These can show where and when a inode is created, when a inode is evicted.
5) sync:
btrfs_sync_file
btrfs_sync_fs
These show sync arguments.
6) transaction:
btrfs_transaction_commit
In transaction based filesystem, it will be useful to know the generation and
who does commit.
7) back reference and cow:
btrfs_delayed_tree_ref
btrfs_delayed_data_ref
btrfs_delayed_ref_head
btrfs_cow_block
Btrfs natively supports back references, these tracepoints are helpful on
understanding btrfs's COW mechanism.
8) chunk:
btrfs_chunk_alloc
btrfs_chunk_free
Chunk is a link between physical offset and logical offset, and stands for space
infomation in btrfs, and these are helpful on tracing space things.
9) reserved_extent:
btrfs_reserved_extent_alloc
btrfs_reserved_extent_free
These can show how btrfs uses its space.
Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-03-24 18:18:59 +07:00
|
|
|
#define CREATE_TRACE_POINTS
|
|
|
|
#include <trace/events/btrfs.h>
|
|
|
|
|
2009-09-22 07:01:09 +07:00
|
|
|
static const struct super_operations btrfs_super_ops;
|
2011-07-26 02:55:42 +07:00
|
|
|
static struct file_system_type btrfs_fs_type;
|
2007-03-29 22:56:46 +07:00
|
|
|
|
btrfs: allow mounting btrfs subvolumes with different ro/rw options
Given the following /etc/fstab entries:
/dev/sda3 /mnt/foo btrfs subvol=foo,ro 0 0
/dev/sda3 /mnt/bar btrfs subvol=bar,rw 0 0
you can't issue:
$ mount /mnt/foo
$ mount /mnt/bar
You would have to do:
$ mount /mnt/foo
$ mount -o remount,rw /mnt/foo
$ mount --bind -o remount,ro /mnt/foo
$ mount /mnt/bar
or
$ mount /mnt/bar
$ mount --rw /mnt/foo
$ mount --bind -o remount,ro /mnt/foo
With this patch you can do
$ mount /mnt/foo
$ mount /mnt/bar
$ cat /proc/self/mountinfo
49 33 0:41 /foo /mnt/foo ro,relatime shared:36 - btrfs /dev/sda3 rw,ssd,space_cache
87 33 0:41 /bar /mnt/bar rw,relatime shared:74 - btrfs /dev/sda3 rw,ssd,space_cache
Signed-off-by: Chris Mason <clm@fb.com>
2013-11-19 17:36:05 +07:00
|
|
|
static int btrfs_remount(struct super_block *sb, int *flags, char *data);
|
|
|
|
|
2013-03-12 21:46:08 +07:00
|
|
|
static const char *btrfs_decode_error(int errno)
|
2011-01-06 18:30:25 +07:00
|
|
|
{
|
2013-03-12 21:46:08 +07:00
|
|
|
char *errstr = "unknown";
|
2011-01-06 18:30:25 +07:00
|
|
|
|
|
|
|
switch (errno) {
|
|
|
|
case -EIO:
|
|
|
|
errstr = "IO failure";
|
|
|
|
break;
|
|
|
|
case -ENOMEM:
|
|
|
|
errstr = "Out of memory";
|
|
|
|
break;
|
|
|
|
case -EROFS:
|
|
|
|
errstr = "Readonly filesystem";
|
|
|
|
break;
|
2011-10-04 10:22:31 +07:00
|
|
|
case -EEXIST:
|
|
|
|
errstr = "Object already exists";
|
|
|
|
break;
|
2013-03-20 21:29:47 +07:00
|
|
|
case -ENOSPC:
|
|
|
|
errstr = "No space left";
|
|
|
|
break;
|
|
|
|
case -ENOENT:
|
|
|
|
errstr = "No such entry";
|
|
|
|
break;
|
2011-01-06 18:30:25 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return errstr;
|
|
|
|
}
|
|
|
|
|
2013-03-12 00:07:45 +07:00
|
|
|
static void save_error_info(struct btrfs_fs_info *fs_info)
|
2011-01-06 18:30:25 +07:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* today we only save the error info into ram. Long term we'll
|
|
|
|
* also send it down to the disk
|
|
|
|
*/
|
2013-01-29 17:14:48 +07:00
|
|
|
set_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state);
|
2011-01-06 18:30:25 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* btrfs handle error by forcing the filesystem readonly */
|
|
|
|
static void btrfs_handle_error(struct btrfs_fs_info *fs_info)
|
|
|
|
{
|
|
|
|
struct super_block *sb = fs_info->sb;
|
|
|
|
|
|
|
|
if (sb->s_flags & MS_RDONLY)
|
|
|
|
return;
|
|
|
|
|
2013-01-29 17:14:48 +07:00
|
|
|
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) {
|
2011-01-06 18:30:25 +07:00
|
|
|
sb->s_flags |= MS_RDONLY;
|
2013-03-20 05:41:23 +07:00
|
|
|
btrfs_info(fs_info, "forced readonly");
|
2012-11-05 23:11:06 +07:00
|
|
|
/*
|
|
|
|
* Note that a running device replace operation is not
|
|
|
|
* canceled here although there is no way to update
|
|
|
|
* the progress. It would add the risk of a deadlock,
|
|
|
|
* therefore the canceling is ommited. The only penalty
|
|
|
|
* is that some I/O remains active until the procedure
|
|
|
|
* completes. The next time when the filesystem is
|
|
|
|
* mounted writeable again, the device replace
|
|
|
|
* operation continues.
|
|
|
|
*/
|
2011-01-06 18:30:25 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-31 04:40:13 +07:00
|
|
|
#ifdef CONFIG_PRINTK
|
2011-01-06 18:30:25 +07:00
|
|
|
/*
|
|
|
|
* __btrfs_std_error decodes expected errors from the caller and
|
|
|
|
* invokes the approciate error response.
|
|
|
|
*/
|
|
|
|
void __btrfs_std_error(struct btrfs_fs_info *fs_info, const char *function,
|
2012-03-01 20:57:30 +07:00
|
|
|
unsigned int line, int errno, const char *fmt, ...)
|
2011-01-06 18:30:25 +07:00
|
|
|
{
|
|
|
|
struct super_block *sb = fs_info->sb;
|
|
|
|
const char *errstr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Special case: if the error is EROFS, and we're already
|
|
|
|
* under MS_RDONLY, then it is safe here.
|
|
|
|
*/
|
|
|
|
if (errno == -EROFS && (sb->s_flags & MS_RDONLY))
|
2012-03-01 20:57:30 +07:00
|
|
|
return;
|
|
|
|
|
2013-03-12 21:46:08 +07:00
|
|
|
errstr = btrfs_decode_error(errno);
|
2012-03-01 20:57:30 +07:00
|
|
|
if (fmt) {
|
2013-01-31 07:54:58 +07:00
|
|
|
struct va_format vaf;
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
vaf.fmt = fmt;
|
|
|
|
vaf.va = &args;
|
2012-03-01 20:57:30 +07:00
|
|
|
|
2013-12-20 23:37:06 +07:00
|
|
|
printk(KERN_CRIT
|
|
|
|
"BTRFS: error (device %s) in %s:%d: errno=%d %s (%pV)\n",
|
2013-03-12 21:46:08 +07:00
|
|
|
sb->s_id, function, line, errno, errstr, &vaf);
|
2013-01-31 07:54:58 +07:00
|
|
|
va_end(args);
|
2012-03-01 20:57:30 +07:00
|
|
|
} else {
|
2013-12-20 23:37:06 +07:00
|
|
|
printk(KERN_CRIT "BTRFS: error (device %s) in %s:%d: errno=%d %s\n",
|
2013-03-12 21:46:08 +07:00
|
|
|
sb->s_id, function, line, errno, errstr);
|
2012-03-01 20:57:30 +07:00
|
|
|
}
|
2011-01-06 18:30:25 +07:00
|
|
|
|
2012-03-01 20:57:30 +07:00
|
|
|
/* Don't go through full error handling during mount */
|
2013-04-01 22:23:58 +07:00
|
|
|
save_error_info(fs_info);
|
|
|
|
if (sb->s_flags & MS_BORN)
|
2012-03-01 20:57:30 +07:00
|
|
|
btrfs_handle_error(fs_info);
|
|
|
|
}
|
2011-01-06 18:30:25 +07:00
|
|
|
|
2012-07-31 04:40:13 +07:00
|
|
|
static const char * const logtypes[] = {
|
2012-03-01 20:57:30 +07:00
|
|
|
"emergency",
|
|
|
|
"alert",
|
|
|
|
"critical",
|
|
|
|
"error",
|
|
|
|
"warning",
|
|
|
|
"notice",
|
|
|
|
"info",
|
|
|
|
"debug",
|
|
|
|
};
|
|
|
|
|
2013-03-20 05:41:23 +07:00
|
|
|
void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
|
2012-03-01 20:57:30 +07:00
|
|
|
{
|
|
|
|
struct super_block *sb = fs_info->sb;
|
|
|
|
char lvl[4];
|
|
|
|
struct va_format vaf;
|
|
|
|
va_list args;
|
|
|
|
const char *type = logtypes[4];
|
2012-07-31 04:40:13 +07:00
|
|
|
int kern_level;
|
2012-03-01 20:57:30 +07:00
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
|
2012-07-31 04:40:13 +07:00
|
|
|
kern_level = printk_get_level(fmt);
|
|
|
|
if (kern_level) {
|
|
|
|
size_t size = printk_skip_level(fmt) - fmt;
|
|
|
|
memcpy(lvl, fmt, size);
|
|
|
|
lvl[size] = '\0';
|
|
|
|
fmt += size;
|
|
|
|
type = logtypes[kern_level - '0'];
|
2012-03-01 20:57:30 +07:00
|
|
|
} else
|
|
|
|
*lvl = '\0';
|
|
|
|
|
|
|
|
vaf.fmt = fmt;
|
|
|
|
vaf.va = &args;
|
2012-07-31 04:40:13 +07:00
|
|
|
|
2013-03-20 05:41:23 +07:00
|
|
|
printk("%sBTRFS %s (device %s): %pV\n", lvl, type, sb->s_id, &vaf);
|
2012-07-31 04:40:13 +07:00
|
|
|
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
void __btrfs_std_error(struct btrfs_fs_info *fs_info, const char *function,
|
|
|
|
unsigned int line, int errno, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
struct super_block *sb = fs_info->sb;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Special case: if the error is EROFS, and we're already
|
|
|
|
* under MS_RDONLY, then it is safe here.
|
|
|
|
*/
|
|
|
|
if (errno == -EROFS && (sb->s_flags & MS_RDONLY))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Don't go through full error handling during mount */
|
|
|
|
if (sb->s_flags & MS_BORN) {
|
|
|
|
save_error_info(fs_info);
|
|
|
|
btrfs_handle_error(fs_info);
|
|
|
|
}
|
2011-01-06 18:30:25 +07:00
|
|
|
}
|
2012-07-31 04:40:13 +07:00
|
|
|
#endif
|
2011-01-06 18:30:25 +07:00
|
|
|
|
2012-03-01 23:24:58 +07:00
|
|
|
/*
|
|
|
|
* We only mark the transaction aborted and then set the file system read-only.
|
|
|
|
* This will prevent new transactions from starting or trying to join this
|
|
|
|
* one.
|
|
|
|
*
|
|
|
|
* This means that error recovery at the call site is limited to freeing
|
|
|
|
* any local memory allocations and passing the error code up without
|
|
|
|
* further cleanup. The transaction should complete as it normally would
|
|
|
|
* in the call path but will return -EIO.
|
|
|
|
*
|
|
|
|
* We'll complete the cleanup in btrfs_end_transaction and
|
|
|
|
* btrfs_commit_transaction.
|
|
|
|
*/
|
|
|
|
void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
|
|
|
|
struct btrfs_root *root, const char *function,
|
|
|
|
unsigned int line, int errno)
|
|
|
|
{
|
2013-03-12 21:46:08 +07:00
|
|
|
/*
|
|
|
|
* Report first abort since mount
|
|
|
|
*/
|
|
|
|
if (!test_and_set_bit(BTRFS_FS_STATE_TRANS_ABORTED,
|
|
|
|
&root->fs_info->fs_state)) {
|
2013-12-20 23:37:06 +07:00
|
|
|
WARN(1, KERN_DEBUG "BTRFS: Transaction aborted (error %d)\n",
|
2013-03-12 21:46:08 +07:00
|
|
|
errno);
|
|
|
|
}
|
2012-03-01 23:24:58 +07:00
|
|
|
trans->aborted = errno;
|
|
|
|
/* Nothing used. The other threads that have joined this
|
|
|
|
* transaction may be able to continue. */
|
|
|
|
if (!trans->blocks_used) {
|
2012-09-06 17:04:44 +07:00
|
|
|
const char *errstr;
|
|
|
|
|
2013-03-12 21:46:08 +07:00
|
|
|
errstr = btrfs_decode_error(errno);
|
2013-03-20 05:41:23 +07:00
|
|
|
btrfs_warn(root->fs_info,
|
|
|
|
"%s:%d: Aborting unused transaction(%s).",
|
|
|
|
function, line, errstr);
|
2011-01-06 18:30:25 +07:00
|
|
|
return;
|
2012-03-01 23:24:58 +07:00
|
|
|
}
|
2013-01-15 13:27:25 +07:00
|
|
|
ACCESS_ONCE(trans->transaction->aborted) = errno;
|
2013-06-11 03:47:23 +07:00
|
|
|
/* Wake up anybody who may be waiting on this transaction */
|
|
|
|
wake_up(&root->fs_info->transaction_wait);
|
|
|
|
wake_up(&root->fs_info->transaction_blocked_wait);
|
2012-03-01 23:24:58 +07:00
|
|
|
__btrfs_std_error(root->fs_info, function, line, errno, NULL);
|
|
|
|
}
|
2011-10-04 10:22:31 +07:00
|
|
|
/*
|
|
|
|
* __btrfs_panic decodes unexpected, fatal errors from the caller,
|
|
|
|
* issues an alert, and either panics or BUGs, depending on mount options.
|
|
|
|
*/
|
|
|
|
void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function,
|
|
|
|
unsigned int line, int errno, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
char *s_id = "<unknown>";
|
|
|
|
const char *errstr;
|
|
|
|
struct va_format vaf = { .fmt = fmt };
|
|
|
|
va_list args;
|
2011-01-06 18:30:25 +07:00
|
|
|
|
2011-10-04 10:22:31 +07:00
|
|
|
if (fs_info)
|
|
|
|
s_id = fs_info->sb->s_id;
|
2011-01-06 18:30:25 +07:00
|
|
|
|
2011-10-04 10:22:31 +07:00
|
|
|
va_start(args, fmt);
|
|
|
|
vaf.va = &args;
|
|
|
|
|
2013-03-12 21:46:08 +07:00
|
|
|
errstr = btrfs_decode_error(errno);
|
2013-01-31 07:54:55 +07:00
|
|
|
if (fs_info && (fs_info->mount_opt & BTRFS_MOUNT_PANIC_ON_FATAL_ERROR))
|
2013-03-12 21:46:08 +07:00
|
|
|
panic(KERN_CRIT "BTRFS panic (device %s) in %s:%d: %pV (errno=%d %s)\n",
|
|
|
|
s_id, function, line, &vaf, errno, errstr);
|
2011-10-04 10:22:31 +07:00
|
|
|
|
2013-12-20 23:37:06 +07:00
|
|
|
btrfs_crit(fs_info, "panic in %s:%d: %pV (errno=%d %s)",
|
|
|
|
function, line, &vaf, errno, errstr);
|
2011-10-04 10:22:31 +07:00
|
|
|
va_end(args);
|
|
|
|
/* Caller calls BUG() */
|
2011-01-06 18:30:25 +07:00
|
|
|
}
|
|
|
|
|
2009-01-06 09:25:51 +07:00
|
|
|
static void btrfs_put_super(struct super_block *sb)
|
2007-04-18 00:26:50 +07:00
|
|
|
{
|
2014-06-04 23:10:45 +07:00
|
|
|
close_ctree(btrfs_sb(sb)->tree_root);
|
2007-03-29 22:56:46 +07:00
|
|
|
}
|
|
|
|
|
2007-08-29 20:11:44 +07:00
|
|
|
enum {
|
Btrfs: change how we mount subvolumes
This work is in preperation for being able to set a different root as the
default mounting root.
There is currently a problem with how we mount subvolumes. We cannot currently
mount a subvolume of a subvolume, you can only mount subvolumes/snapshots of the
default subvolume. So say you take a snapshot of the default subvolume and call
it snap1, and then take a snapshot of snap1 and call it snap2, so now you have
/
/snap1
/snap1/snap2
as your available volumes. Currently you can only mount / and /snap1,
you cannot mount /snap1/snap2. To fix this problem instead of passing
subvolid=<name> you must pass in subvolid=<treeid>, where <treeid> is
the tree id that gets spit out via the subvolume listing you get from
the subvolume listing patches (btrfs filesystem list). This allows us
to mount /, /snap1 and /snap1/snap2 as the root volume.
In addition to the above, we also now read the default dir item in the
tree root to get the root key that it points to. For now this just
points at what has always been the default subvolme, but later on I plan
to change it to point at whatever root you want to be the new default
root, so you can just set the default mount and not have to mount with
-o subvolid=<treeid>. I tested this out with the above scenario and it
worked perfectly. Thanks,
mount -o subvol operates inside the selected subvolid. For example:
mount -o subvol=snap1,subvolid=256 /dev/xxx /mnt
/mnt will have the snap1 directory for the subvolume with id
256.
mount -o subvol=snap /dev/xxx /mnt
/mnt will be the snap directory of whatever the default subvolume
is.
Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-12-05 00:38:27 +07:00
|
|
|
Opt_degraded, Opt_subvol, Opt_subvolid, Opt_device, Opt_nodatasum,
|
2010-03-20 01:07:23 +07:00
|
|
|
Opt_nodatacow, Opt_max_inline, Opt_alloc_start, Opt_nobarrier, Opt_ssd,
|
|
|
|
Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl, Opt_compress,
|
2010-12-17 13:21:50 +07:00
|
|
|
Opt_compress_type, Opt_compress_force, Opt_compress_force_type,
|
|
|
|
Opt_notreelog, Opt_ratio, Opt_flushoncommit, Opt_discard,
|
2011-02-17 01:10:41 +07:00
|
|
|
Opt_space_cache, Opt_clear_cache, Opt_user_subvol_rm_allowed,
|
2012-01-17 03:04:48 +07:00
|
|
|
Opt_enospc_debug, Opt_subvolrootid, Opt_defrag, Opt_inode_cache,
|
|
|
|
Opt_no_space_cache, Opt_recovery, Opt_skip_balance,
|
2011-11-09 19:44:05 +07:00
|
|
|
Opt_check_integrity, Opt_check_integrity_including_extent_data,
|
2013-08-15 22:11:24 +07:00
|
|
|
Opt_check_integrity_print_mask, Opt_fatal_errors, Opt_rescan_uuid_tree,
|
2014-01-06 08:58:27 +07:00
|
|
|
Opt_commit_interval, Opt_barrier, Opt_nodefrag, Opt_nodiscard,
|
2014-01-06 08:58:31 +07:00
|
|
|
Opt_noenospc_debug, Opt_noflushoncommit, Opt_acl, Opt_datacow,
|
2014-01-13 12:36:06 +07:00
|
|
|
Opt_datasum, Opt_treelog, Opt_noinode_cache,
|
2012-01-17 03:04:48 +07:00
|
|
|
Opt_err,
|
2007-08-29 20:11:44 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static match_table_t tokens = {
|
2008-05-14 00:46:40 +07:00
|
|
|
{Opt_degraded, "degraded"},
|
2007-08-29 20:11:44 +07:00
|
|
|
{Opt_subvol, "subvol=%s"},
|
2013-07-24 09:29:20 +07:00
|
|
|
{Opt_subvolid, "subvolid=%s"},
|
2008-06-10 21:40:46 +07:00
|
|
|
{Opt_device, "device=%s"},
|
2007-12-15 03:30:32 +07:00
|
|
|
{Opt_nodatasum, "nodatasum"},
|
2014-01-06 08:58:32 +07:00
|
|
|
{Opt_datasum, "datasum"},
|
2007-12-18 08:14:01 +07:00
|
|
|
{Opt_nodatacow, "nodatacow"},
|
2014-01-06 08:58:31 +07:00
|
|
|
{Opt_datacow, "datacow"},
|
2008-01-09 21:23:21 +07:00
|
|
|
{Opt_nobarrier, "nobarrier"},
|
2014-01-06 08:58:25 +07:00
|
|
|
{Opt_barrier, "barrier"},
|
2008-01-30 04:03:38 +07:00
|
|
|
{Opt_max_inline, "max_inline=%s"},
|
2008-01-02 22:01:11 +07:00
|
|
|
{Opt_alloc_start, "alloc_start=%s"},
|
2008-06-12 08:47:56 +07:00
|
|
|
{Opt_thread_pool, "thread_pool=%d"},
|
Btrfs: Add zlib compression support
This is a large change for adding compression on reading and writing,
both for inline and regular extents. It does some fairly large
surgery to the writeback paths.
Compression is off by default and enabled by mount -o compress. Even
when the -o compress mount option is not used, it is possible to read
compressed extents off the disk.
If compression for a given set of pages fails to make them smaller, the
file is flagged to avoid future compression attempts later.
* While finding delalloc extents, the pages are locked before being sent down
to the delalloc handler. This allows the delalloc handler to do complex things
such as cleaning the pages, marking them writeback and starting IO on their
behalf.
* Inline extents are inserted at delalloc time now. This allows us to compress
the data before inserting the inline extent, and it allows us to insert
an inline extent that spans multiple pages.
* All of the in-memory extent representations (extent_map.c, ordered-data.c etc)
are changed to record both an in-memory size and an on disk size, as well
as a flag for compression.
From a disk format point of view, the extent pointers in the file are changed
to record the on disk size of a given extent and some encoding flags.
Space in the disk format is allocated for compression encoding, as well
as encryption and a generic 'other' field. Neither the encryption or the
'other' field are currently used.
In order to limit the amount of data read for a single random read in the
file, the size of a compressed extent is limited to 128k. This is a
software only limit, the disk format supports u64 sized compressed extents.
In order to limit the ram consumed while processing extents, the uncompressed
size of a compressed extent is limited to 256k. This is a software only limit
and will be subject to tuning later.
Checksumming is still done on compressed extents, and it is done on the
uncompressed version of the data. This way additional encodings can be
layered on without having to figure out which encoding to checksum.
Compression happens at delalloc time, which is basically singled threaded because
it is usually done by a single pdflush thread. This makes it tricky to
spread the compression load across all the cpus on the box. We'll have to
look at parallel pdflush walks of dirty inodes at a later time.
Decompression is hooked into readpages and it does spread across CPUs nicely.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2008-10-30 01:49:59 +07:00
|
|
|
{Opt_compress, "compress"},
|
2010-12-17 13:21:50 +07:00
|
|
|
{Opt_compress_type, "compress=%s"},
|
2010-01-29 04:18:15 +07:00
|
|
|
{Opt_compress_force, "compress-force"},
|
2010-12-17 13:21:50 +07:00
|
|
|
{Opt_compress_force_type, "compress-force=%s"},
|
2008-01-18 22:54:22 +07:00
|
|
|
{Opt_ssd, "ssd"},
|
2009-06-10 07:28:34 +07:00
|
|
|
{Opt_ssd_spread, "ssd_spread"},
|
2009-06-10 03:42:22 +07:00
|
|
|
{Opt_nossd, "nossd"},
|
2014-01-06 08:58:30 +07:00
|
|
|
{Opt_acl, "acl"},
|
2008-07-24 23:16:36 +07:00
|
|
|
{Opt_noacl, "noacl"},
|
2009-04-03 03:49:40 +07:00
|
|
|
{Opt_notreelog, "notreelog"},
|
2014-01-06 08:58:33 +07:00
|
|
|
{Opt_treelog, "treelog"},
|
2009-04-03 03:59:01 +07:00
|
|
|
{Opt_flushoncommit, "flushoncommit"},
|
2014-01-06 08:58:29 +07:00
|
|
|
{Opt_noflushoncommit, "noflushoncommit"},
|
2009-04-22 04:40:57 +07:00
|
|
|
{Opt_ratio, "metadata_ratio=%d"},
|
2009-10-14 20:24:59 +07:00
|
|
|
{Opt_discard, "discard"},
|
2014-01-06 08:58:27 +07:00
|
|
|
{Opt_nodiscard, "nodiscard"},
|
2010-06-22 01:48:16 +07:00
|
|
|
{Opt_space_cache, "space_cache"},
|
2010-09-22 01:21:34 +07:00
|
|
|
{Opt_clear_cache, "clear_cache"},
|
2010-10-30 02:46:43 +07:00
|
|
|
{Opt_user_subvol_rm_allowed, "user_subvol_rm_allowed"},
|
2011-02-17 01:10:41 +07:00
|
|
|
{Opt_enospc_debug, "enospc_debug"},
|
2014-01-06 08:58:28 +07:00
|
|
|
{Opt_noenospc_debug, "noenospc_debug"},
|
2011-04-06 14:33:51 +07:00
|
|
|
{Opt_subvolrootid, "subvolrootid=%d"},
|
2011-05-25 02:35:30 +07:00
|
|
|
{Opt_defrag, "autodefrag"},
|
2014-01-06 08:58:26 +07:00
|
|
|
{Opt_nodefrag, "noautodefrag"},
|
2011-06-03 20:36:29 +07:00
|
|
|
{Opt_inode_cache, "inode_cache"},
|
2014-01-13 12:36:06 +07:00
|
|
|
{Opt_noinode_cache, "noinode_cache"},
|
2011-11-11 22:14:57 +07:00
|
|
|
{Opt_no_space_cache, "nospace_cache"},
|
2011-11-04 02:17:42 +07:00
|
|
|
{Opt_recovery, "recovery"},
|
2012-01-17 03:04:48 +07:00
|
|
|
{Opt_skip_balance, "skip_balance"},
|
2011-11-09 19:44:05 +07:00
|
|
|
{Opt_check_integrity, "check_int"},
|
|
|
|
{Opt_check_integrity_including_extent_data, "check_int_data"},
|
|
|
|
{Opt_check_integrity_print_mask, "check_int_print_mask=%d"},
|
2013-08-15 22:11:24 +07:00
|
|
|
{Opt_rescan_uuid_tree, "rescan_uuid_tree"},
|
2011-10-04 10:22:31 +07:00
|
|
|
{Opt_fatal_errors, "fatal_errors=%s"},
|
2013-08-01 23:14:52 +07:00
|
|
|
{Opt_commit_interval, "commit=%d"},
|
2008-07-24 23:16:36 +07:00
|
|
|
{Opt_err, NULL},
|
2007-08-29 20:11:44 +07:00
|
|
|
};
|
|
|
|
|
2008-06-10 21:40:29 +07:00
|
|
|
/*
|
|
|
|
* Regular mount options parser. Everything that is needed only when
|
|
|
|
* reading in a new superblock is parsed here.
|
2012-03-01 23:24:58 +07:00
|
|
|
* XXX JDM: This needs to be cleaned up for remount.
|
2008-06-10 21:40:29 +07:00
|
|
|
*/
|
|
|
|
int btrfs_parse_options(struct btrfs_root *root, char *options)
|
2007-08-29 20:11:44 +07:00
|
|
|
{
|
2008-06-10 21:40:29 +07:00
|
|
|
struct btrfs_fs_info *info = root->fs_info;
|
2007-08-29 20:11:44 +07:00
|
|
|
substring_t args[MAX_OPT_ARGS];
|
2011-10-04 01:07:49 +07:00
|
|
|
char *p, *num, *orig = NULL;
|
|
|
|
u64 cache_gen;
|
2008-06-12 08:47:56 +07:00
|
|
|
int intarg;
|
2009-11-07 13:19:16 +07:00
|
|
|
int ret = 0;
|
2010-12-17 13:21:50 +07:00
|
|
|
char *compress_type;
|
|
|
|
bool compress_force = false;
|
2007-12-15 03:30:32 +07:00
|
|
|
|
2011-04-13 20:41:04 +07:00
|
|
|
cache_gen = btrfs_super_cache_generation(root->fs_info->super_copy);
|
2011-10-04 01:07:49 +07:00
|
|
|
if (cache_gen)
|
|
|
|
btrfs_set_opt(info->mount_opt, SPACE_CACHE);
|
|
|
|
|
2007-08-29 20:11:44 +07:00
|
|
|
if (!options)
|
2011-10-04 01:07:49 +07:00
|
|
|
goto out;
|
2007-08-29 20:11:44 +07:00
|
|
|
|
2007-12-18 08:14:01 +07:00
|
|
|
/*
|
|
|
|
* strsep changes the string, duplicate it because parse_options
|
|
|
|
* gets called twice
|
|
|
|
*/
|
|
|
|
options = kstrdup(options, GFP_NOFS);
|
|
|
|
if (!options)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-02-26 03:38:35 +07:00
|
|
|
orig = options;
|
2007-12-18 08:14:01 +07:00
|
|
|
|
2008-06-10 21:40:29 +07:00
|
|
|
while ((p = strsep(&options, ",")) != NULL) {
|
2007-08-29 20:11:44 +07:00
|
|
|
int token;
|
|
|
|
if (!*p)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
token = match_token(p, tokens, args);
|
|
|
|
switch (token) {
|
2008-05-14 00:46:40 +07:00
|
|
|
case Opt_degraded:
|
2013-12-20 23:37:06 +07:00
|
|
|
btrfs_info(root->fs_info, "allowing degraded mounts");
|
2008-06-10 21:40:29 +07:00
|
|
|
btrfs_set_opt(info->mount_opt, DEGRADED);
|
2008-05-14 00:46:40 +07:00
|
|
|
break;
|
2007-08-29 20:11:44 +07:00
|
|
|
case Opt_subvol:
|
Btrfs: change how we mount subvolumes
This work is in preperation for being able to set a different root as the
default mounting root.
There is currently a problem with how we mount subvolumes. We cannot currently
mount a subvolume of a subvolume, you can only mount subvolumes/snapshots of the
default subvolume. So say you take a snapshot of the default subvolume and call
it snap1, and then take a snapshot of snap1 and call it snap2, so now you have
/
/snap1
/snap1/snap2
as your available volumes. Currently you can only mount / and /snap1,
you cannot mount /snap1/snap2. To fix this problem instead of passing
subvolid=<name> you must pass in subvolid=<treeid>, where <treeid> is
the tree id that gets spit out via the subvolume listing you get from
the subvolume listing patches (btrfs filesystem list). This allows us
to mount /, /snap1 and /snap1/snap2 as the root volume.
In addition to the above, we also now read the default dir item in the
tree root to get the root key that it points to. For now this just
points at what has always been the default subvolme, but later on I plan
to change it to point at whatever root you want to be the new default
root, so you can just set the default mount and not have to mount with
-o subvolid=<treeid>. I tested this out with the above scenario and it
worked perfectly. Thanks,
mount -o subvol operates inside the selected subvolid. For example:
mount -o subvol=snap1,subvolid=256 /dev/xxx /mnt
/mnt will have the snap1 directory for the subvolume with id
256.
mount -o subvol=snap /dev/xxx /mnt
/mnt will be the snap directory of whatever the default subvolume
is.
Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-12-05 00:38:27 +07:00
|
|
|
case Opt_subvolid:
|
2011-04-06 14:33:51 +07:00
|
|
|
case Opt_subvolrootid:
|
2008-06-10 21:40:46 +07:00
|
|
|
case Opt_device:
|
2008-06-10 21:40:29 +07:00
|
|
|
/*
|
2008-06-10 21:40:46 +07:00
|
|
|
* These are parsed by btrfs_parse_early_options
|
2008-06-10 21:40:29 +07:00
|
|
|
* and can be happily ignored here.
|
|
|
|
*/
|
2007-12-15 03:30:32 +07:00
|
|
|
break;
|
|
|
|
case Opt_nodatasum:
|
2014-01-13 12:36:07 +07:00
|
|
|
btrfs_set_and_info(root, NODATASUM,
|
|
|
|
"setting nodatasum");
|
2007-12-18 08:14:01 +07:00
|
|
|
break;
|
2014-01-06 08:58:32 +07:00
|
|
|
case Opt_datasum:
|
2014-01-13 12:36:07 +07:00
|
|
|
if (btrfs_test_opt(root, NODATASUM)) {
|
|
|
|
if (btrfs_test_opt(root, NODATACOW))
|
|
|
|
btrfs_info(root->fs_info, "setting datasum, datacow enabled");
|
|
|
|
else
|
|
|
|
btrfs_info(root->fs_info, "setting datasum");
|
|
|
|
}
|
2014-01-06 08:58:32 +07:00
|
|
|
btrfs_clear_opt(info->mount_opt, NODATACOW);
|
|
|
|
btrfs_clear_opt(info->mount_opt, NODATASUM);
|
|
|
|
break;
|
2007-12-18 08:14:01 +07:00
|
|
|
case Opt_nodatacow:
|
2014-01-13 12:36:07 +07:00
|
|
|
if (!btrfs_test_opt(root, NODATACOW)) {
|
|
|
|
if (!btrfs_test_opt(root, COMPRESS) ||
|
|
|
|
!btrfs_test_opt(root, FORCE_COMPRESS)) {
|
2013-12-20 23:37:06 +07:00
|
|
|
btrfs_info(root->fs_info,
|
2014-01-13 12:36:07 +07:00
|
|
|
"setting nodatacow, compression disabled");
|
|
|
|
} else {
|
|
|
|
btrfs_info(root->fs_info, "setting nodatacow");
|
|
|
|
}
|
2012-09-20 21:42:11 +07:00
|
|
|
}
|
|
|
|
btrfs_clear_opt(info->mount_opt, COMPRESS);
|
|
|
|
btrfs_clear_opt(info->mount_opt, FORCE_COMPRESS);
|
2008-06-10 21:40:29 +07:00
|
|
|
btrfs_set_opt(info->mount_opt, NODATACOW);
|
|
|
|
btrfs_set_opt(info->mount_opt, NODATASUM);
|
2007-08-29 20:11:44 +07:00
|
|
|
break;
|
2014-01-06 08:58:31 +07:00
|
|
|
case Opt_datacow:
|
2014-01-13 12:36:07 +07:00
|
|
|
btrfs_clear_and_info(root, NODATACOW,
|
|
|
|
"setting datacow");
|
2014-01-06 08:58:31 +07:00
|
|
|
break;
|
2010-01-29 04:18:15 +07:00
|
|
|
case Opt_compress_force:
|
2010-12-17 13:21:50 +07:00
|
|
|
case Opt_compress_force_type:
|
|
|
|
compress_force = true;
|
2013-01-31 07:54:56 +07:00
|
|
|
/* Fallthrough */
|
2010-12-17 13:21:50 +07:00
|
|
|
case Opt_compress:
|
|
|
|
case Opt_compress_type:
|
|
|
|
if (token == Opt_compress ||
|
|
|
|
token == Opt_compress_force ||
|
|
|
|
strcmp(args[0].from, "zlib") == 0) {
|
|
|
|
compress_type = "zlib";
|
|
|
|
info->compress_type = BTRFS_COMPRESS_ZLIB;
|
2012-04-16 20:27:51 +07:00
|
|
|
btrfs_set_opt(info->mount_opt, COMPRESS);
|
2012-09-20 21:42:11 +07:00
|
|
|
btrfs_clear_opt(info->mount_opt, NODATACOW);
|
|
|
|
btrfs_clear_opt(info->mount_opt, NODATASUM);
|
2010-10-25 14:12:26 +07:00
|
|
|
} else if (strcmp(args[0].from, "lzo") == 0) {
|
|
|
|
compress_type = "lzo";
|
|
|
|
info->compress_type = BTRFS_COMPRESS_LZO;
|
2012-04-16 20:27:51 +07:00
|
|
|
btrfs_set_opt(info->mount_opt, COMPRESS);
|
2012-09-20 21:42:11 +07:00
|
|
|
btrfs_clear_opt(info->mount_opt, NODATACOW);
|
|
|
|
btrfs_clear_opt(info->mount_opt, NODATASUM);
|
2012-07-25 00:58:43 +07:00
|
|
|
btrfs_set_fs_incompat(info, COMPRESS_LZO);
|
2012-04-16 20:27:51 +07:00
|
|
|
} else if (strncmp(args[0].from, "no", 2) == 0) {
|
|
|
|
compress_type = "no";
|
|
|
|
btrfs_clear_opt(info->mount_opt, COMPRESS);
|
|
|
|
btrfs_clear_opt(info->mount_opt, FORCE_COMPRESS);
|
|
|
|
compress_force = false;
|
2010-12-17 13:21:50 +07:00
|
|
|
} else {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (compress_force) {
|
2014-01-13 12:36:07 +07:00
|
|
|
btrfs_set_and_info(root, FORCE_COMPRESS,
|
|
|
|
"force %s compression",
|
|
|
|
compress_type);
|
2014-07-29 22:41:08 +07:00
|
|
|
} else {
|
2014-01-13 12:36:07 +07:00
|
|
|
if (!btrfs_test_opt(root, COMPRESS))
|
|
|
|
btrfs_info(root->fs_info,
|
2014-05-15 21:48:20 +07:00
|
|
|
"btrfs: use %s compression",
|
2014-01-13 12:36:07 +07:00
|
|
|
compress_type);
|
2014-06-30 09:51:25 +07:00
|
|
|
/*
|
|
|
|
* If we remount from compress-force=xxx to
|
|
|
|
* compress=xxx, we need clear FORCE_COMPRESS
|
|
|
|
* flag, otherwise, there is no way for users
|
|
|
|
* to disable forcible compression separately.
|
|
|
|
*/
|
|
|
|
btrfs_clear_opt(info->mount_opt, FORCE_COMPRESS);
|
2013-11-22 17:47:59 +07:00
|
|
|
}
|
2010-01-29 04:18:15 +07:00
|
|
|
break;
|
2008-01-18 22:54:22 +07:00
|
|
|
case Opt_ssd:
|
2014-01-13 12:36:07 +07:00
|
|
|
btrfs_set_and_info(root, SSD,
|
|
|
|
"use ssd allocation scheme");
|
2008-01-18 22:54:22 +07:00
|
|
|
break;
|
2009-06-10 07:28:34 +07:00
|
|
|
case Opt_ssd_spread:
|
2014-01-13 12:36:07 +07:00
|
|
|
btrfs_set_and_info(root, SSD_SPREAD,
|
|
|
|
"use spread ssd allocation scheme");
|
2014-06-28 04:50:31 +07:00
|
|
|
btrfs_set_opt(info->mount_opt, SSD);
|
2009-06-10 07:28:34 +07:00
|
|
|
break;
|
2009-06-10 03:42:22 +07:00
|
|
|
case Opt_nossd:
|
2014-06-28 04:50:31 +07:00
|
|
|
btrfs_set_and_info(root, NOSSD,
|
2014-01-13 12:36:07 +07:00
|
|
|
"not using ssd allocation scheme");
|
2009-06-10 03:42:22 +07:00
|
|
|
btrfs_clear_opt(info->mount_opt, SSD);
|
|
|
|
break;
|
2014-01-06 08:58:25 +07:00
|
|
|
case Opt_barrier:
|
2014-01-13 12:36:07 +07:00
|
|
|
btrfs_clear_and_info(root, NOBARRIER,
|
|
|
|
"turning on barriers");
|
2014-01-06 08:58:25 +07:00
|
|
|
break;
|
2008-01-09 21:23:21 +07:00
|
|
|
case Opt_nobarrier:
|
2014-01-13 12:36:07 +07:00
|
|
|
btrfs_set_and_info(root, NOBARRIER,
|
|
|
|
"turning off barriers");
|
2008-01-09 21:23:21 +07:00
|
|
|
break;
|
2008-06-12 08:47:56 +07:00
|
|
|
case Opt_thread_pool:
|
2013-07-24 09:29:05 +07:00
|
|
|
ret = match_int(&args[0], &intarg);
|
|
|
|
if (ret) {
|
|
|
|
goto out;
|
|
|
|
} else if (intarg > 0) {
|
2008-06-12 08:47:56 +07:00
|
|
|
info->thread_pool_size = intarg;
|
2013-07-24 09:29:05 +07:00
|
|
|
} else {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2008-06-12 08:47:56 +07:00
|
|
|
break;
|
2008-01-30 04:03:38 +07:00
|
|
|
case Opt_max_inline:
|
2008-06-10 21:40:29 +07:00
|
|
|
num = match_strdup(&args[0]);
|
|
|
|
if (num) {
|
2010-02-28 17:59:11 +07:00
|
|
|
info->max_inline = memparse(num, NULL);
|
2008-06-10 21:40:29 +07:00
|
|
|
kfree(num);
|
|
|
|
|
2008-06-12 03:51:38 +07:00
|
|
|
if (info->max_inline) {
|
2014-02-13 22:13:16 +07:00
|
|
|
info->max_inline = min_t(u64,
|
2008-06-12 03:51:38 +07:00
|
|
|
info->max_inline,
|
|
|
|
root->sectorsize);
|
|
|
|
}
|
2013-12-20 23:37:06 +07:00
|
|
|
btrfs_info(root->fs_info, "max_inline at %llu",
|
2013-08-20 18:20:07 +07:00
|
|
|
info->max_inline);
|
2013-07-24 09:29:05 +07:00
|
|
|
} else {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
2008-01-30 04:03:38 +07:00
|
|
|
}
|
|
|
|
break;
|
2008-01-02 22:01:11 +07:00
|
|
|
case Opt_alloc_start:
|
2008-06-10 21:40:29 +07:00
|
|
|
num = match_strdup(&args[0]);
|
|
|
|
if (num) {
|
Btrfs: protect fs_info->alloc_start
fs_info->alloc_start is a 64bits variant, can be accessed by
multi-task, but it is not protected strictly, it can be changed
while we are accessing it. On 32bit machine, we will get wrong
value because we access it by two instructions.(In fact, it is
also possible that the same problem happens on the 64bit machine,
because the compiler may split the 64bit operation into two 32bit
operation.)
For example:
Assuming -> alloc_start is 0x0000 0000 0001 0000 at the beginning,
then we remount and set ->alloc_start to 0x0000 0100 0000 0000.
Task0 Task1
load high 32 bits
set high 32 bits
set low 32 bits
load low 32 bits
Task1 will get 0.
This patch fixes this problem by using two locks to protect it
fs_info->chunk_mutex
sb->s_umount
On the read side, we just need get one of these two locks, and on
the write side, we must lock all of them.
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
2013-01-29 17:07:33 +07:00
|
|
|
mutex_lock(&info->chunk_mutex);
|
2010-02-28 17:59:11 +07:00
|
|
|
info->alloc_start = memparse(num, NULL);
|
Btrfs: protect fs_info->alloc_start
fs_info->alloc_start is a 64bits variant, can be accessed by
multi-task, but it is not protected strictly, it can be changed
while we are accessing it. On 32bit machine, we will get wrong
value because we access it by two instructions.(In fact, it is
also possible that the same problem happens on the 64bit machine,
because the compiler may split the 64bit operation into two 32bit
operation.)
For example:
Assuming -> alloc_start is 0x0000 0000 0001 0000 at the beginning,
then we remount and set ->alloc_start to 0x0000 0100 0000 0000.
Task0 Task1
load high 32 bits
set high 32 bits
set low 32 bits
load low 32 bits
Task1 will get 0.
This patch fixes this problem by using two locks to protect it
fs_info->chunk_mutex
sb->s_umount
On the read side, we just need get one of these two locks, and on
the write side, we must lock all of them.
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
2013-01-29 17:07:33 +07:00
|
|
|
mutex_unlock(&info->chunk_mutex);
|
2008-06-10 21:40:29 +07:00
|
|
|
kfree(num);
|
2013-12-20 23:37:06 +07:00
|
|
|
btrfs_info(root->fs_info, "allocations start at %llu",
|
2013-08-20 18:20:07 +07:00
|
|
|
info->alloc_start);
|
2013-07-24 09:29:05 +07:00
|
|
|
} else {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
2008-01-02 22:01:11 +07:00
|
|
|
}
|
|
|
|
break;
|
2014-01-06 08:58:30 +07:00
|
|
|
case Opt_acl:
|
2014-05-12 10:04:33 +07:00
|
|
|
#ifdef CONFIG_BTRFS_FS_POSIX_ACL
|
2014-01-06 08:58:30 +07:00
|
|
|
root->fs_info->sb->s_flags |= MS_POSIXACL;
|
|
|
|
break;
|
2014-05-12 10:04:33 +07:00
|
|
|
#else
|
|
|
|
btrfs_err(root->fs_info,
|
|
|
|
"support for ACL not compiled in!");
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
#endif
|
2008-07-24 23:16:36 +07:00
|
|
|
case Opt_noacl:
|
|
|
|
root->fs_info->sb->s_flags &= ~MS_POSIXACL;
|
|
|
|
break;
|
2009-04-03 03:49:40 +07:00
|
|
|
case Opt_notreelog:
|
2014-01-13 12:36:07 +07:00
|
|
|
btrfs_set_and_info(root, NOTREELOG,
|
|
|
|
"disabling tree log");
|
2014-01-06 08:58:33 +07:00
|
|
|
break;
|
|
|
|
case Opt_treelog:
|
2014-01-13 12:36:07 +07:00
|
|
|
btrfs_clear_and_info(root, NOTREELOG,
|
|
|
|
"enabling tree log");
|
2009-04-03 03:49:40 +07:00
|
|
|
break;
|
2009-04-03 03:59:01 +07:00
|
|
|
case Opt_flushoncommit:
|
2014-01-13 12:36:07 +07:00
|
|
|
btrfs_set_and_info(root, FLUSHONCOMMIT,
|
|
|
|
"turning on flush-on-commit");
|
2009-04-03 03:59:01 +07:00
|
|
|
break;
|
2014-01-06 08:58:29 +07:00
|
|
|
case Opt_noflushoncommit:
|
2014-01-13 12:36:07 +07:00
|
|
|
btrfs_clear_and_info(root, FLUSHONCOMMIT,
|
|
|
|
"turning off flush-on-commit");
|
2014-01-06 08:58:29 +07:00
|
|
|
break;
|
2009-04-22 04:40:57 +07:00
|
|
|
case Opt_ratio:
|
2013-07-24 09:29:05 +07:00
|
|
|
ret = match_int(&args[0], &intarg);
|
|
|
|
if (ret) {
|
|
|
|
goto out;
|
|
|
|
} else if (intarg >= 0) {
|
2009-04-22 04:40:57 +07:00
|
|
|
info->metadata_ratio = intarg;
|
2013-12-20 23:37:06 +07:00
|
|
|
btrfs_info(root->fs_info, "metadata ratio %d",
|
2009-04-22 04:40:57 +07:00
|
|
|
info->metadata_ratio);
|
2013-07-24 09:29:05 +07:00
|
|
|
} else {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
2009-04-22 04:40:57 +07:00
|
|
|
}
|
|
|
|
break;
|
2009-10-14 20:24:59 +07:00
|
|
|
case Opt_discard:
|
2014-01-13 12:36:07 +07:00
|
|
|
btrfs_set_and_info(root, DISCARD,
|
|
|
|
"turning on discard");
|
2009-10-14 20:24:59 +07:00
|
|
|
break;
|
2014-01-06 08:58:27 +07:00
|
|
|
case Opt_nodiscard:
|
2014-01-13 12:36:07 +07:00
|
|
|
btrfs_clear_and_info(root, DISCARD,
|
|
|
|
"turning off discard");
|
2014-01-06 08:58:27 +07:00
|
|
|
break;
|
2010-06-22 01:48:16 +07:00
|
|
|
case Opt_space_cache:
|
2014-01-13 12:36:07 +07:00
|
|
|
btrfs_set_and_info(root, SPACE_CACHE,
|
|
|
|
"enabling disk space caching");
|
2010-11-19 20:40:41 +07:00
|
|
|
break;
|
2013-08-15 22:11:24 +07:00
|
|
|
case Opt_rescan_uuid_tree:
|
|
|
|
btrfs_set_opt(info->mount_opt, RESCAN_UUID_TREE);
|
|
|
|
break;
|
2011-10-04 01:07:49 +07:00
|
|
|
case Opt_no_space_cache:
|
2014-01-13 12:36:07 +07:00
|
|
|
btrfs_clear_and_info(root, SPACE_CACHE,
|
|
|
|
"disabling disk space caching");
|
2011-10-04 01:07:49 +07:00
|
|
|
break;
|
2011-06-03 20:36:29 +07:00
|
|
|
case Opt_inode_cache:
|
2014-01-13 12:36:07 +07:00
|
|
|
btrfs_set_and_info(root, CHANGE_INODE_CACHE,
|
|
|
|
"enabling inode map caching");
|
2014-01-13 12:36:06 +07:00
|
|
|
break;
|
|
|
|
case Opt_noinode_cache:
|
2014-01-13 12:36:07 +07:00
|
|
|
btrfs_clear_and_info(root, CHANGE_INODE_CACHE,
|
|
|
|
"disabling inode map caching");
|
2011-06-03 20:36:29 +07:00
|
|
|
break;
|
2010-09-22 01:21:34 +07:00
|
|
|
case Opt_clear_cache:
|
2014-01-13 12:36:07 +07:00
|
|
|
btrfs_set_and_info(root, CLEAR_CACHE,
|
|
|
|
"force clearing of disk cache");
|
2010-06-22 01:48:16 +07:00
|
|
|
break;
|
2010-10-30 02:46:43 +07:00
|
|
|
case Opt_user_subvol_rm_allowed:
|
|
|
|
btrfs_set_opt(info->mount_opt, USER_SUBVOL_RM_ALLOWED);
|
|
|
|
break;
|
2011-02-17 01:10:41 +07:00
|
|
|
case Opt_enospc_debug:
|
|
|
|
btrfs_set_opt(info->mount_opt, ENOSPC_DEBUG);
|
|
|
|
break;
|
2014-01-06 08:58:28 +07:00
|
|
|
case Opt_noenospc_debug:
|
|
|
|
btrfs_clear_opt(info->mount_opt, ENOSPC_DEBUG);
|
|
|
|
break;
|
2011-05-25 02:35:30 +07:00
|
|
|
case Opt_defrag:
|
2014-01-13 12:36:07 +07:00
|
|
|
btrfs_set_and_info(root, AUTO_DEFRAG,
|
|
|
|
"enabling auto defrag");
|
2011-05-25 02:35:30 +07:00
|
|
|
break;
|
2014-01-06 08:58:26 +07:00
|
|
|
case Opt_nodefrag:
|
2014-01-13 12:36:07 +07:00
|
|
|
btrfs_clear_and_info(root, AUTO_DEFRAG,
|
|
|
|
"disabling auto defrag");
|
2014-01-06 08:58:26 +07:00
|
|
|
break;
|
2011-11-04 02:17:42 +07:00
|
|
|
case Opt_recovery:
|
2013-12-20 23:37:06 +07:00
|
|
|
btrfs_info(root->fs_info, "enabling auto recovery");
|
2011-11-04 02:17:42 +07:00
|
|
|
btrfs_set_opt(info->mount_opt, RECOVERY);
|
|
|
|
break;
|
2012-01-17 03:04:48 +07:00
|
|
|
case Opt_skip_balance:
|
|
|
|
btrfs_set_opt(info->mount_opt, SKIP_BALANCE);
|
|
|
|
break;
|
2011-11-09 19:44:05 +07:00
|
|
|
#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
|
|
|
|
case Opt_check_integrity_including_extent_data:
|
2013-12-20 23:37:06 +07:00
|
|
|
btrfs_info(root->fs_info,
|
|
|
|
"enabling check integrity including extent data");
|
2011-11-09 19:44:05 +07:00
|
|
|
btrfs_set_opt(info->mount_opt,
|
|
|
|
CHECK_INTEGRITY_INCLUDING_EXTENT_DATA);
|
|
|
|
btrfs_set_opt(info->mount_opt, CHECK_INTEGRITY);
|
|
|
|
break;
|
|
|
|
case Opt_check_integrity:
|
2013-12-20 23:37:06 +07:00
|
|
|
btrfs_info(root->fs_info, "enabling check integrity");
|
2011-11-09 19:44:05 +07:00
|
|
|
btrfs_set_opt(info->mount_opt, CHECK_INTEGRITY);
|
|
|
|
break;
|
|
|
|
case Opt_check_integrity_print_mask:
|
2013-07-24 09:29:05 +07:00
|
|
|
ret = match_int(&args[0], &intarg);
|
|
|
|
if (ret) {
|
|
|
|
goto out;
|
|
|
|
} else if (intarg >= 0) {
|
2011-11-09 19:44:05 +07:00
|
|
|
info->check_integrity_print_mask = intarg;
|
2013-12-20 23:37:06 +07:00
|
|
|
btrfs_info(root->fs_info, "check_integrity_print_mask 0x%x",
|
2011-11-09 19:44:05 +07:00
|
|
|
info->check_integrity_print_mask);
|
2013-07-24 09:29:05 +07:00
|
|
|
} else {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
2011-11-09 19:44:05 +07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
#else
|
|
|
|
case Opt_check_integrity_including_extent_data:
|
|
|
|
case Opt_check_integrity:
|
|
|
|
case Opt_check_integrity_print_mask:
|
2013-12-20 23:37:06 +07:00
|
|
|
btrfs_err(root->fs_info,
|
|
|
|
"support for check_integrity* not compiled in!");
|
2011-11-09 19:44:05 +07:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
#endif
|
2011-10-04 10:22:31 +07:00
|
|
|
case Opt_fatal_errors:
|
|
|
|
if (strcmp(args[0].from, "panic") == 0)
|
|
|
|
btrfs_set_opt(info->mount_opt,
|
|
|
|
PANIC_ON_FATAL_ERROR);
|
|
|
|
else if (strcmp(args[0].from, "bug") == 0)
|
|
|
|
btrfs_clear_opt(info->mount_opt,
|
|
|
|
PANIC_ON_FATAL_ERROR);
|
|
|
|
else {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
break;
|
2013-08-01 23:14:52 +07:00
|
|
|
case Opt_commit_interval:
|
|
|
|
intarg = 0;
|
|
|
|
ret = match_int(&args[0], &intarg);
|
|
|
|
if (ret < 0) {
|
2013-12-20 23:37:06 +07:00
|
|
|
btrfs_err(root->fs_info, "invalid commit interval");
|
2013-08-01 23:14:52 +07:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (intarg > 0) {
|
|
|
|
if (intarg > 300) {
|
2013-12-20 23:37:06 +07:00
|
|
|
btrfs_warn(root->fs_info, "excessive commit interval %d",
|
2013-08-01 23:14:52 +07:00
|
|
|
intarg);
|
|
|
|
}
|
|
|
|
info->commit_interval = intarg;
|
|
|
|
} else {
|
2013-12-20 23:37:06 +07:00
|
|
|
btrfs_info(root->fs_info, "using default commit interval %ds",
|
2013-08-01 23:14:52 +07:00
|
|
|
BTRFS_DEFAULT_COMMIT_INTERVAL);
|
|
|
|
info->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL;
|
|
|
|
}
|
|
|
|
break;
|
2009-11-07 13:19:16 +07:00
|
|
|
case Opt_err:
|
2013-12-20 23:37:06 +07:00
|
|
|
btrfs_info(root->fs_info, "unrecognized mount option '%s'", p);
|
2009-11-07 13:19:16 +07:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
2007-08-29 20:11:44 +07:00
|
|
|
default:
|
2007-12-18 08:14:01 +07:00
|
|
|
break;
|
2007-08-29 20:11:44 +07:00
|
|
|
}
|
|
|
|
}
|
2009-11-07 13:19:16 +07:00
|
|
|
out:
|
2011-10-04 01:07:49 +07:00
|
|
|
if (!ret && btrfs_test_opt(root, SPACE_CACHE))
|
2013-12-20 23:37:06 +07:00
|
|
|
btrfs_info(root->fs_info, "disk space caching is enabled");
|
2010-02-26 03:38:35 +07:00
|
|
|
kfree(orig);
|
2009-11-07 13:19:16 +07:00
|
|
|
return ret;
|
2008-06-10 21:40:29 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse mount options that are required early in the mount process.
|
|
|
|
*
|
|
|
|
* All other options will be parsed on much later in the mount process and
|
|
|
|
* only when we need to allocate a new super block.
|
|
|
|
*/
|
2008-12-02 18:36:09 +07:00
|
|
|
static int btrfs_parse_early_options(const char *options, fmode_t flags,
|
Btrfs: change how we mount subvolumes
This work is in preperation for being able to set a different root as the
default mounting root.
There is currently a problem with how we mount subvolumes. We cannot currently
mount a subvolume of a subvolume, you can only mount subvolumes/snapshots of the
default subvolume. So say you take a snapshot of the default subvolume and call
it snap1, and then take a snapshot of snap1 and call it snap2, so now you have
/
/snap1
/snap1/snap2
as your available volumes. Currently you can only mount / and /snap1,
you cannot mount /snap1/snap2. To fix this problem instead of passing
subvolid=<name> you must pass in subvolid=<treeid>, where <treeid> is
the tree id that gets spit out via the subvolume listing you get from
the subvolume listing patches (btrfs filesystem list). This allows us
to mount /, /snap1 and /snap1/snap2 as the root volume.
In addition to the above, we also now read the default dir item in the
tree root to get the root key that it points to. For now this just
points at what has always been the default subvolme, but later on I plan
to change it to point at whatever root you want to be the new default
root, so you can just set the default mount and not have to mount with
-o subvolid=<treeid>. I tested this out with the above scenario and it
worked perfectly. Thanks,
mount -o subvol operates inside the selected subvolid. For example:
mount -o subvol=snap1,subvolid=256 /dev/xxx /mnt
/mnt will have the snap1 directory for the subvolume with id
256.
mount -o subvol=snap /dev/xxx /mnt
/mnt will be the snap directory of whatever the default subvolume
is.
Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-12-05 00:38:27 +07:00
|
|
|
void *holder, char **subvol_name, u64 *subvol_objectid,
|
2013-03-20 20:21:10 +07:00
|
|
|
struct btrfs_fs_devices **fs_devices)
|
2008-06-10 21:40:29 +07:00
|
|
|
{
|
|
|
|
substring_t args[MAX_OPT_ARGS];
|
2011-09-14 13:11:21 +07:00
|
|
|
char *device_name, *opts, *orig, *p;
|
2013-07-24 09:29:20 +07:00
|
|
|
char *num = NULL;
|
2008-06-10 21:40:29 +07:00
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
if (!options)
|
2011-07-26 02:55:42 +07:00
|
|
|
return 0;
|
2008-06-10 21:40:29 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* strsep changes the string, duplicate it because parse_options
|
|
|
|
* gets called twice
|
|
|
|
*/
|
|
|
|
opts = kstrdup(options, GFP_KERNEL);
|
|
|
|
if (!opts)
|
|
|
|
return -ENOMEM;
|
2010-12-27 15:43:13 +07:00
|
|
|
orig = opts;
|
2008-06-10 21:40:29 +07:00
|
|
|
|
|
|
|
while ((p = strsep(&opts, ",")) != NULL) {
|
|
|
|
int token;
|
|
|
|
if (!*p)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
token = match_token(p, tokens, args);
|
|
|
|
switch (token) {
|
|
|
|
case Opt_subvol:
|
2011-11-08 21:47:55 +07:00
|
|
|
kfree(*subvol_name);
|
2008-06-10 21:40:29 +07:00
|
|
|
*subvol_name = match_strdup(&args[0]);
|
2013-07-24 09:29:05 +07:00
|
|
|
if (!*subvol_name) {
|
|
|
|
error = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
2008-06-10 21:40:29 +07:00
|
|
|
break;
|
Btrfs: change how we mount subvolumes
This work is in preperation for being able to set a different root as the
default mounting root.
There is currently a problem with how we mount subvolumes. We cannot currently
mount a subvolume of a subvolume, you can only mount subvolumes/snapshots of the
default subvolume. So say you take a snapshot of the default subvolume and call
it snap1, and then take a snapshot of snap1 and call it snap2, so now you have
/
/snap1
/snap1/snap2
as your available volumes. Currently you can only mount / and /snap1,
you cannot mount /snap1/snap2. To fix this problem instead of passing
subvolid=<name> you must pass in subvolid=<treeid>, where <treeid> is
the tree id that gets spit out via the subvolume listing you get from
the subvolume listing patches (btrfs filesystem list). This allows us
to mount /, /snap1 and /snap1/snap2 as the root volume.
In addition to the above, we also now read the default dir item in the
tree root to get the root key that it points to. For now this just
points at what has always been the default subvolme, but later on I plan
to change it to point at whatever root you want to be the new default
root, so you can just set the default mount and not have to mount with
-o subvolid=<treeid>. I tested this out with the above scenario and it
worked perfectly. Thanks,
mount -o subvol operates inside the selected subvolid. For example:
mount -o subvol=snap1,subvolid=256 /dev/xxx /mnt
/mnt will have the snap1 directory for the subvolume with id
256.
mount -o subvol=snap /dev/xxx /mnt
/mnt will be the snap directory of whatever the default subvolume
is.
Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-12-05 00:38:27 +07:00
|
|
|
case Opt_subvolid:
|
2013-07-24 09:29:20 +07:00
|
|
|
num = match_strdup(&args[0]);
|
|
|
|
if (num) {
|
|
|
|
*subvol_objectid = memparse(num, NULL);
|
|
|
|
kfree(num);
|
2009-12-15 02:18:38 +07:00
|
|
|
/* we want the original fs_tree */
|
2013-07-24 09:29:20 +07:00
|
|
|
if (!*subvol_objectid)
|
2009-12-15 02:18:38 +07:00
|
|
|
*subvol_objectid =
|
|
|
|
BTRFS_FS_TREE_OBJECTID;
|
2013-07-24 09:29:05 +07:00
|
|
|
} else {
|
|
|
|
error = -EINVAL;
|
|
|
|
goto out;
|
2009-12-15 02:18:38 +07:00
|
|
|
}
|
Btrfs: change how we mount subvolumes
This work is in preperation for being able to set a different root as the
default mounting root.
There is currently a problem with how we mount subvolumes. We cannot currently
mount a subvolume of a subvolume, you can only mount subvolumes/snapshots of the
default subvolume. So say you take a snapshot of the default subvolume and call
it snap1, and then take a snapshot of snap1 and call it snap2, so now you have
/
/snap1
/snap1/snap2
as your available volumes. Currently you can only mount / and /snap1,
you cannot mount /snap1/snap2. To fix this problem instead of passing
subvolid=<name> you must pass in subvolid=<treeid>, where <treeid> is
the tree id that gets spit out via the subvolume listing you get from
the subvolume listing patches (btrfs filesystem list). This allows us
to mount /, /snap1 and /snap1/snap2 as the root volume.
In addition to the above, we also now read the default dir item in the
tree root to get the root key that it points to. For now this just
points at what has always been the default subvolme, but later on I plan
to change it to point at whatever root you want to be the new default
root, so you can just set the default mount and not have to mount with
-o subvolid=<treeid>. I tested this out with the above scenario and it
worked perfectly. Thanks,
mount -o subvol operates inside the selected subvolid. For example:
mount -o subvol=snap1,subvolid=256 /dev/xxx /mnt
/mnt will have the snap1 directory for the subvolume with id
256.
mount -o subvol=snap /dev/xxx /mnt
/mnt will be the snap directory of whatever the default subvolume
is.
Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-12-05 00:38:27 +07:00
|
|
|
break;
|
2011-04-06 14:33:51 +07:00
|
|
|
case Opt_subvolrootid:
|
2013-03-20 20:21:10 +07:00
|
|
|
printk(KERN_WARNING
|
2013-12-20 23:37:06 +07:00
|
|
|
"BTRFS: 'subvolrootid' mount option is deprecated and has "
|
|
|
|
"no effect\n");
|
2011-04-06 14:33:51 +07:00
|
|
|
break;
|
2008-06-10 21:40:46 +07:00
|
|
|
case Opt_device:
|
2011-09-14 13:11:21 +07:00
|
|
|
device_name = match_strdup(&args[0]);
|
|
|
|
if (!device_name) {
|
|
|
|
error = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
error = btrfs_scan_one_device(device_name,
|
2008-06-10 21:40:46 +07:00
|
|
|
flags, holder, fs_devices);
|
2011-09-14 13:11:21 +07:00
|
|
|
kfree(device_name);
|
2008-06-10 21:40:46 +07:00
|
|
|
if (error)
|
2011-07-26 02:55:42 +07:00
|
|
|
goto out;
|
2008-06-10 21:40:46 +07:00
|
|
|
break;
|
2008-06-10 21:40:29 +07:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-26 02:55:42 +07:00
|
|
|
out:
|
2010-12-27 15:43:13 +07:00
|
|
|
kfree(orig);
|
2008-06-10 21:40:29 +07:00
|
|
|
return error;
|
2007-08-29 20:11:44 +07:00
|
|
|
}
|
|
|
|
|
Btrfs: change how we mount subvolumes
This work is in preperation for being able to set a different root as the
default mounting root.
There is currently a problem with how we mount subvolumes. We cannot currently
mount a subvolume of a subvolume, you can only mount subvolumes/snapshots of the
default subvolume. So say you take a snapshot of the default subvolume and call
it snap1, and then take a snapshot of snap1 and call it snap2, so now you have
/
/snap1
/snap1/snap2
as your available volumes. Currently you can only mount / and /snap1,
you cannot mount /snap1/snap2. To fix this problem instead of passing
subvolid=<name> you must pass in subvolid=<treeid>, where <treeid> is
the tree id that gets spit out via the subvolume listing you get from
the subvolume listing patches (btrfs filesystem list). This allows us
to mount /, /snap1 and /snap1/snap2 as the root volume.
In addition to the above, we also now read the default dir item in the
tree root to get the root key that it points to. For now this just
points at what has always been the default subvolme, but later on I plan
to change it to point at whatever root you want to be the new default
root, so you can just set the default mount and not have to mount with
-o subvolid=<treeid>. I tested this out with the above scenario and it
worked perfectly. Thanks,
mount -o subvol operates inside the selected subvolid. For example:
mount -o subvol=snap1,subvolid=256 /dev/xxx /mnt
/mnt will have the snap1 directory for the subvolume with id
256.
mount -o subvol=snap /dev/xxx /mnt
/mnt will be the snap directory of whatever the default subvolume
is.
Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-12-05 00:38:27 +07:00
|
|
|
static struct dentry *get_default_root(struct super_block *sb,
|
|
|
|
u64 subvol_objectid)
|
|
|
|
{
|
2011-11-18 03:40:49 +07:00
|
|
|
struct btrfs_fs_info *fs_info = btrfs_sb(sb);
|
|
|
|
struct btrfs_root *root = fs_info->tree_root;
|
Btrfs: change how we mount subvolumes
This work is in preperation for being able to set a different root as the
default mounting root.
There is currently a problem with how we mount subvolumes. We cannot currently
mount a subvolume of a subvolume, you can only mount subvolumes/snapshots of the
default subvolume. So say you take a snapshot of the default subvolume and call
it snap1, and then take a snapshot of snap1 and call it snap2, so now you have
/
/snap1
/snap1/snap2
as your available volumes. Currently you can only mount / and /snap1,
you cannot mount /snap1/snap2. To fix this problem instead of passing
subvolid=<name> you must pass in subvolid=<treeid>, where <treeid> is
the tree id that gets spit out via the subvolume listing you get from
the subvolume listing patches (btrfs filesystem list). This allows us
to mount /, /snap1 and /snap1/snap2 as the root volume.
In addition to the above, we also now read the default dir item in the
tree root to get the root key that it points to. For now this just
points at what has always been the default subvolme, but later on I plan
to change it to point at whatever root you want to be the new default
root, so you can just set the default mount and not have to mount with
-o subvolid=<treeid>. I tested this out with the above scenario and it
worked perfectly. Thanks,
mount -o subvol operates inside the selected subvolid. For example:
mount -o subvol=snap1,subvolid=256 /dev/xxx /mnt
/mnt will have the snap1 directory for the subvolume with id
256.
mount -o subvol=snap /dev/xxx /mnt
/mnt will be the snap directory of whatever the default subvolume
is.
Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-12-05 00:38:27 +07:00
|
|
|
struct btrfs_root *new_root;
|
|
|
|
struct btrfs_dir_item *di;
|
|
|
|
struct btrfs_path *path;
|
|
|
|
struct btrfs_key location;
|
|
|
|
struct inode *inode;
|
|
|
|
u64 dir_id;
|
|
|
|
int new = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We have a specific subvol we want to mount, just setup location and
|
|
|
|
* go look up the root.
|
|
|
|
*/
|
|
|
|
if (subvol_objectid) {
|
|
|
|
location.objectid = subvol_objectid;
|
|
|
|
location.type = BTRFS_ROOT_ITEM_KEY;
|
|
|
|
location.offset = (u64)-1;
|
|
|
|
goto find_root;
|
|
|
|
}
|
|
|
|
|
|
|
|
path = btrfs_alloc_path();
|
|
|
|
if (!path)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
path->leave_spinning = 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the "default" dir item which points to the root item that we
|
|
|
|
* will mount by default if we haven't been given a specific subvolume
|
|
|
|
* to mount.
|
|
|
|
*/
|
2011-11-18 03:40:49 +07:00
|
|
|
dir_id = btrfs_super_root_dir(fs_info->super_copy);
|
Btrfs: change how we mount subvolumes
This work is in preperation for being able to set a different root as the
default mounting root.
There is currently a problem with how we mount subvolumes. We cannot currently
mount a subvolume of a subvolume, you can only mount subvolumes/snapshots of the
default subvolume. So say you take a snapshot of the default subvolume and call
it snap1, and then take a snapshot of snap1 and call it snap2, so now you have
/
/snap1
/snap1/snap2
as your available volumes. Currently you can only mount / and /snap1,
you cannot mount /snap1/snap2. To fix this problem instead of passing
subvolid=<name> you must pass in subvolid=<treeid>, where <treeid> is
the tree id that gets spit out via the subvolume listing you get from
the subvolume listing patches (btrfs filesystem list). This allows us
to mount /, /snap1 and /snap1/snap2 as the root volume.
In addition to the above, we also now read the default dir item in the
tree root to get the root key that it points to. For now this just
points at what has always been the default subvolme, but later on I plan
to change it to point at whatever root you want to be the new default
root, so you can just set the default mount and not have to mount with
-o subvolid=<treeid>. I tested this out with the above scenario and it
worked perfectly. Thanks,
mount -o subvol operates inside the selected subvolid. For example:
mount -o subvol=snap1,subvolid=256 /dev/xxx /mnt
/mnt will have the snap1 directory for the subvolume with id
256.
mount -o subvol=snap /dev/xxx /mnt
/mnt will be the snap directory of whatever the default subvolume
is.
Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-12-05 00:38:27 +07:00
|
|
|
di = btrfs_lookup_dir_item(NULL, root, path, dir_id, "default", 7, 0);
|
2011-05-14 14:10:51 +07:00
|
|
|
if (IS_ERR(di)) {
|
|
|
|
btrfs_free_path(path);
|
2010-05-29 16:40:57 +07:00
|
|
|
return ERR_CAST(di);
|
2011-05-14 14:10:51 +07:00
|
|
|
}
|
Btrfs: change how we mount subvolumes
This work is in preperation for being able to set a different root as the
default mounting root.
There is currently a problem with how we mount subvolumes. We cannot currently
mount a subvolume of a subvolume, you can only mount subvolumes/snapshots of the
default subvolume. So say you take a snapshot of the default subvolume and call
it snap1, and then take a snapshot of snap1 and call it snap2, so now you have
/
/snap1
/snap1/snap2
as your available volumes. Currently you can only mount / and /snap1,
you cannot mount /snap1/snap2. To fix this problem instead of passing
subvolid=<name> you must pass in subvolid=<treeid>, where <treeid> is
the tree id that gets spit out via the subvolume listing you get from
the subvolume listing patches (btrfs filesystem list). This allows us
to mount /, /snap1 and /snap1/snap2 as the root volume.
In addition to the above, we also now read the default dir item in the
tree root to get the root key that it points to. For now this just
points at what has always been the default subvolme, but later on I plan
to change it to point at whatever root you want to be the new default
root, so you can just set the default mount and not have to mount with
-o subvolid=<treeid>. I tested this out with the above scenario and it
worked perfectly. Thanks,
mount -o subvol operates inside the selected subvolid. For example:
mount -o subvol=snap1,subvolid=256 /dev/xxx /mnt
/mnt will have the snap1 directory for the subvolume with id
256.
mount -o subvol=snap /dev/xxx /mnt
/mnt will be the snap directory of whatever the default subvolume
is.
Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-12-05 00:38:27 +07:00
|
|
|
if (!di) {
|
|
|
|
/*
|
|
|
|
* Ok the default dir item isn't there. This is weird since
|
|
|
|
* it's always been there, but don't freak out, just try and
|
|
|
|
* mount to root most subvolume.
|
|
|
|
*/
|
|
|
|
btrfs_free_path(path);
|
|
|
|
dir_id = BTRFS_FIRST_FREE_OBJECTID;
|
2011-11-18 03:40:49 +07:00
|
|
|
new_root = fs_info->fs_root;
|
Btrfs: change how we mount subvolumes
This work is in preperation for being able to set a different root as the
default mounting root.
There is currently a problem with how we mount subvolumes. We cannot currently
mount a subvolume of a subvolume, you can only mount subvolumes/snapshots of the
default subvolume. So say you take a snapshot of the default subvolume and call
it snap1, and then take a snapshot of snap1 and call it snap2, so now you have
/
/snap1
/snap1/snap2
as your available volumes. Currently you can only mount / and /snap1,
you cannot mount /snap1/snap2. To fix this problem instead of passing
subvolid=<name> you must pass in subvolid=<treeid>, where <treeid> is
the tree id that gets spit out via the subvolume listing you get from
the subvolume listing patches (btrfs filesystem list). This allows us
to mount /, /snap1 and /snap1/snap2 as the root volume.
In addition to the above, we also now read the default dir item in the
tree root to get the root key that it points to. For now this just
points at what has always been the default subvolme, but later on I plan
to change it to point at whatever root you want to be the new default
root, so you can just set the default mount and not have to mount with
-o subvolid=<treeid>. I tested this out with the above scenario and it
worked perfectly. Thanks,
mount -o subvol operates inside the selected subvolid. For example:
mount -o subvol=snap1,subvolid=256 /dev/xxx /mnt
/mnt will have the snap1 directory for the subvolume with id
256.
mount -o subvol=snap /dev/xxx /mnt
/mnt will be the snap directory of whatever the default subvolume
is.
Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-12-05 00:38:27 +07:00
|
|
|
goto setup_root;
|
|
|
|
}
|
|
|
|
|
|
|
|
btrfs_dir_item_key_to_cpu(path->nodes[0], di, &location);
|
|
|
|
btrfs_free_path(path);
|
|
|
|
|
|
|
|
find_root:
|
2011-11-18 03:40:49 +07:00
|
|
|
new_root = btrfs_read_fs_root_no_name(fs_info, &location);
|
Btrfs: change how we mount subvolumes
This work is in preperation for being able to set a different root as the
default mounting root.
There is currently a problem with how we mount subvolumes. We cannot currently
mount a subvolume of a subvolume, you can only mount subvolumes/snapshots of the
default subvolume. So say you take a snapshot of the default subvolume and call
it snap1, and then take a snapshot of snap1 and call it snap2, so now you have
/
/snap1
/snap1/snap2
as your available volumes. Currently you can only mount / and /snap1,
you cannot mount /snap1/snap2. To fix this problem instead of passing
subvolid=<name> you must pass in subvolid=<treeid>, where <treeid> is
the tree id that gets spit out via the subvolume listing you get from
the subvolume listing patches (btrfs filesystem list). This allows us
to mount /, /snap1 and /snap1/snap2 as the root volume.
In addition to the above, we also now read the default dir item in the
tree root to get the root key that it points to. For now this just
points at what has always been the default subvolme, but later on I plan
to change it to point at whatever root you want to be the new default
root, so you can just set the default mount and not have to mount with
-o subvolid=<treeid>. I tested this out with the above scenario and it
worked perfectly. Thanks,
mount -o subvol operates inside the selected subvolid. For example:
mount -o subvol=snap1,subvolid=256 /dev/xxx /mnt
/mnt will have the snap1 directory for the subvolume with id
256.
mount -o subvol=snap /dev/xxx /mnt
/mnt will be the snap directory of whatever the default subvolume
is.
Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-12-05 00:38:27 +07:00
|
|
|
if (IS_ERR(new_root))
|
2010-10-30 02:14:23 +07:00
|
|
|
return ERR_CAST(new_root);
|
Btrfs: change how we mount subvolumes
This work is in preperation for being able to set a different root as the
default mounting root.
There is currently a problem with how we mount subvolumes. We cannot currently
mount a subvolume of a subvolume, you can only mount subvolumes/snapshots of the
default subvolume. So say you take a snapshot of the default subvolume and call
it snap1, and then take a snapshot of snap1 and call it snap2, so now you have
/
/snap1
/snap1/snap2
as your available volumes. Currently you can only mount / and /snap1,
you cannot mount /snap1/snap2. To fix this problem instead of passing
subvolid=<name> you must pass in subvolid=<treeid>, where <treeid> is
the tree id that gets spit out via the subvolume listing you get from
the subvolume listing patches (btrfs filesystem list). This allows us
to mount /, /snap1 and /snap1/snap2 as the root volume.
In addition to the above, we also now read the default dir item in the
tree root to get the root key that it points to. For now this just
points at what has always been the default subvolme, but later on I plan
to change it to point at whatever root you want to be the new default
root, so you can just set the default mount and not have to mount with
-o subvolid=<treeid>. I tested this out with the above scenario and it
worked perfectly. Thanks,
mount -o subvol operates inside the selected subvolid. For example:
mount -o subvol=snap1,subvolid=256 /dev/xxx /mnt
/mnt will have the snap1 directory for the subvolume with id
256.
mount -o subvol=snap /dev/xxx /mnt
/mnt will be the snap directory of whatever the default subvolume
is.
Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-12-05 00:38:27 +07:00
|
|
|
|
|
|
|
dir_id = btrfs_root_dirid(&new_root->root_item);
|
|
|
|
setup_root:
|
|
|
|
location.objectid = dir_id;
|
|
|
|
location.type = BTRFS_INODE_ITEM_KEY;
|
|
|
|
location.offset = 0;
|
|
|
|
|
|
|
|
inode = btrfs_iget(sb, &location, new_root, &new);
|
2010-05-29 16:42:19 +07:00
|
|
|
if (IS_ERR(inode))
|
|
|
|
return ERR_CAST(inode);
|
Btrfs: change how we mount subvolumes
This work is in preperation for being able to set a different root as the
default mounting root.
There is currently a problem with how we mount subvolumes. We cannot currently
mount a subvolume of a subvolume, you can only mount subvolumes/snapshots of the
default subvolume. So say you take a snapshot of the default subvolume and call
it snap1, and then take a snapshot of snap1 and call it snap2, so now you have
/
/snap1
/snap1/snap2
as your available volumes. Currently you can only mount / and /snap1,
you cannot mount /snap1/snap2. To fix this problem instead of passing
subvolid=<name> you must pass in subvolid=<treeid>, where <treeid> is
the tree id that gets spit out via the subvolume listing you get from
the subvolume listing patches (btrfs filesystem list). This allows us
to mount /, /snap1 and /snap1/snap2 as the root volume.
In addition to the above, we also now read the default dir item in the
tree root to get the root key that it points to. For now this just
points at what has always been the default subvolme, but later on I plan
to change it to point at whatever root you want to be the new default
root, so you can just set the default mount and not have to mount with
-o subvolid=<treeid>. I tested this out with the above scenario and it
worked perfectly. Thanks,
mount -o subvol operates inside the selected subvolid. For example:
mount -o subvol=snap1,subvolid=256 /dev/xxx /mnt
/mnt will have the snap1 directory for the subvolume with id
256.
mount -o subvol=snap /dev/xxx /mnt
/mnt will be the snap directory of whatever the default subvolume
is.
Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-12-05 00:38:27 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we're just mounting the root most subvol put the inode and return
|
|
|
|
* a reference to the dentry. We will have already gotten a reference
|
|
|
|
* to the inode in btrfs_fill_super so we're good to go.
|
|
|
|
*/
|
|
|
|
if (!new && sb->s_root->d_inode == inode) {
|
|
|
|
iput(inode);
|
|
|
|
return dget(sb->s_root);
|
|
|
|
}
|
|
|
|
|
2014-02-15 05:35:37 +07:00
|
|
|
return d_obtain_root(inode);
|
Btrfs: change how we mount subvolumes
This work is in preperation for being able to set a different root as the
default mounting root.
There is currently a problem with how we mount subvolumes. We cannot currently
mount a subvolume of a subvolume, you can only mount subvolumes/snapshots of the
default subvolume. So say you take a snapshot of the default subvolume and call
it snap1, and then take a snapshot of snap1 and call it snap2, so now you have
/
/snap1
/snap1/snap2
as your available volumes. Currently you can only mount / and /snap1,
you cannot mount /snap1/snap2. To fix this problem instead of passing
subvolid=<name> you must pass in subvolid=<treeid>, where <treeid> is
the tree id that gets spit out via the subvolume listing you get from
the subvolume listing patches (btrfs filesystem list). This allows us
to mount /, /snap1 and /snap1/snap2 as the root volume.
In addition to the above, we also now read the default dir item in the
tree root to get the root key that it points to. For now this just
points at what has always been the default subvolme, but later on I plan
to change it to point at whatever root you want to be the new default
root, so you can just set the default mount and not have to mount with
-o subvolid=<treeid>. I tested this out with the above scenario and it
worked perfectly. Thanks,
mount -o subvol operates inside the selected subvolid. For example:
mount -o subvol=snap1,subvolid=256 /dev/xxx /mnt
/mnt will have the snap1 directory for the subvolume with id
256.
mount -o subvol=snap /dev/xxx /mnt
/mnt will be the snap directory of whatever the default subvolume
is.
Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-12-05 00:38:27 +07:00
|
|
|
}
|
|
|
|
|
2009-01-06 09:25:51 +07:00
|
|
|
static int btrfs_fill_super(struct super_block *sb,
|
2008-03-25 02:02:07 +07:00
|
|
|
struct btrfs_fs_devices *fs_devices,
|
2009-01-06 09:25:51 +07:00
|
|
|
void *data, int silent)
|
2007-03-29 22:56:46 +07:00
|
|
|
{
|
2009-01-06 09:25:51 +07:00
|
|
|
struct inode *inode;
|
2011-11-18 03:40:49 +07:00
|
|
|
struct btrfs_fs_info *fs_info = btrfs_sb(sb);
|
Btrfs: Mixed back reference (FORWARD ROLLING FORMAT CHANGE)
This commit introduces a new kind of back reference for btrfs metadata.
Once a filesystem has been mounted with this commit, IT WILL NO LONGER
BE MOUNTABLE BY OLDER KERNELS.
When a tree block in subvolume tree is cow'd, the reference counts of all
extents it points to are increased by one. At transaction commit time,
the old root of the subvolume is recorded in a "dead root" data structure,
and the btree it points to is later walked, dropping reference counts
and freeing any blocks where the reference count goes to 0.
The increments done during cow and decrements done after commit cancel out,
and the walk is a very expensive way to go about freeing the blocks that
are no longer referenced by the new btree root. This commit reduces the
transaction overhead by avoiding the need for dead root records.
When a non-shared tree block is cow'd, we free the old block at once, and the
new block inherits old block's references. When a tree block with reference
count > 1 is cow'd, we increase the reference counts of all extents
the new block points to by one, and decrease the old block's reference count by
one.
This dead tree avoidance code removes the need to modify the reference
counts of lower level extents when a non-shared tree block is cow'd.
But we still need to update back ref for all pointers in the block.
This is because the location of the block is recorded in the back ref
item.
We can solve this by introducing a new type of back ref. The new
back ref provides information about pointer's key, level and in which
tree the pointer lives. This information allow us to find the pointer
by searching the tree. The shortcoming of the new back ref is that it
only works for pointers in tree blocks referenced by their owner trees.
This is mostly a problem for snapshots, where resolving one of these
fuzzy back references would be O(number_of_snapshots) and quite slow.
The solution used here is to use the fuzzy back references in the common
case where a given tree block is only referenced by one root,
and use the full back references when multiple roots have a reference
on a given block.
This commit adds per subvolume red-black tree to keep trace of cached
inodes. The red-black tree helps the balancing code to find cached
inodes whose inode numbers within a given range.
This commit improves the balancing code by introducing several data
structures to keep the state of balancing. The most important one
is the back ref cache. It caches how the upper level tree blocks are
referenced. This greatly reduce the overhead of checking back ref.
The improved balancing code scales significantly better with a large
number of snapshots.
This is a very large commit and was written in a number of
pieces. But, they depend heavily on the disk format change and were
squashed together to make sure git bisect didn't end up in a
bad state wrt space balancing or the format change.
Signed-off-by: Yan Zheng <zheng.yan@oracle.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-06-10 21:45:14 +07:00
|
|
|
struct btrfs_key key;
|
2007-06-12 17:35:45 +07:00
|
|
|
int err;
|
2007-04-19 03:15:28 +07:00
|
|
|
|
2007-06-12 17:35:45 +07:00
|
|
|
sb->s_maxbytes = MAX_LFS_FILESIZE;
|
|
|
|
sb->s_magic = BTRFS_SUPER_MAGIC;
|
|
|
|
sb->s_op = &btrfs_super_ops;
|
2010-12-20 22:56:06 +07:00
|
|
|
sb->s_d_op = &btrfs_dentry_operations;
|
2008-07-21 03:31:56 +07:00
|
|
|
sb->s_export_op = &btrfs_export_ops;
|
2007-11-16 23:45:54 +07:00
|
|
|
sb->s_xattr = btrfs_xattr_handlers;
|
2007-06-12 17:35:45 +07:00
|
|
|
sb->s_time_gran = 1;
|
2009-10-14 00:50:18 +07:00
|
|
|
#ifdef CONFIG_BTRFS_FS_POSIX_ACL
|
2008-07-24 23:16:36 +07:00
|
|
|
sb->s_flags |= MS_POSIXACL;
|
2009-09-30 00:51:04 +07:00
|
|
|
#endif
|
2012-04-06 02:03:02 +07:00
|
|
|
sb->s_flags |= MS_I_VERSION;
|
2011-11-17 13:10:02 +07:00
|
|
|
err = open_ctree(sb, fs_devices, (char *)data);
|
|
|
|
if (err) {
|
2013-12-20 23:37:06 +07:00
|
|
|
printk(KERN_ERR "BTRFS: open_ctree failed\n");
|
2011-11-17 13:10:02 +07:00
|
|
|
return err;
|
2007-04-19 03:15:28 +07:00
|
|
|
}
|
|
|
|
|
Btrfs: Mixed back reference (FORWARD ROLLING FORMAT CHANGE)
This commit introduces a new kind of back reference for btrfs metadata.
Once a filesystem has been mounted with this commit, IT WILL NO LONGER
BE MOUNTABLE BY OLDER KERNELS.
When a tree block in subvolume tree is cow'd, the reference counts of all
extents it points to are increased by one. At transaction commit time,
the old root of the subvolume is recorded in a "dead root" data structure,
and the btree it points to is later walked, dropping reference counts
and freeing any blocks where the reference count goes to 0.
The increments done during cow and decrements done after commit cancel out,
and the walk is a very expensive way to go about freeing the blocks that
are no longer referenced by the new btree root. This commit reduces the
transaction overhead by avoiding the need for dead root records.
When a non-shared tree block is cow'd, we free the old block at once, and the
new block inherits old block's references. When a tree block with reference
count > 1 is cow'd, we increase the reference counts of all extents
the new block points to by one, and decrease the old block's reference count by
one.
This dead tree avoidance code removes the need to modify the reference
counts of lower level extents when a non-shared tree block is cow'd.
But we still need to update back ref for all pointers in the block.
This is because the location of the block is recorded in the back ref
item.
We can solve this by introducing a new type of back ref. The new
back ref provides information about pointer's key, level and in which
tree the pointer lives. This information allow us to find the pointer
by searching the tree. The shortcoming of the new back ref is that it
only works for pointers in tree blocks referenced by their owner trees.
This is mostly a problem for snapshots, where resolving one of these
fuzzy back references would be O(number_of_snapshots) and quite slow.
The solution used here is to use the fuzzy back references in the common
case where a given tree block is only referenced by one root,
and use the full back references when multiple roots have a reference
on a given block.
This commit adds per subvolume red-black tree to keep trace of cached
inodes. The red-black tree helps the balancing code to find cached
inodes whose inode numbers within a given range.
This commit improves the balancing code by introducing several data
structures to keep the state of balancing. The most important one
is the back ref cache. It caches how the upper level tree blocks are
referenced. This greatly reduce the overhead of checking back ref.
The improved balancing code scales significantly better with a large
number of snapshots.
This is a very large commit and was written in a number of
pieces. But, they depend heavily on the disk format change and were
squashed together to make sure git bisect didn't end up in a
bad state wrt space balancing or the format change.
Signed-off-by: Yan Zheng <zheng.yan@oracle.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-06-10 21:45:14 +07:00
|
|
|
key.objectid = BTRFS_FIRST_FREE_OBJECTID;
|
|
|
|
key.type = BTRFS_INODE_ITEM_KEY;
|
|
|
|
key.offset = 0;
|
2011-11-17 13:00:31 +07:00
|
|
|
inode = btrfs_iget(sb, &key, fs_info->fs_root, NULL);
|
Btrfs: Mixed back reference (FORWARD ROLLING FORMAT CHANGE)
This commit introduces a new kind of back reference for btrfs metadata.
Once a filesystem has been mounted with this commit, IT WILL NO LONGER
BE MOUNTABLE BY OLDER KERNELS.
When a tree block in subvolume tree is cow'd, the reference counts of all
extents it points to are increased by one. At transaction commit time,
the old root of the subvolume is recorded in a "dead root" data structure,
and the btree it points to is later walked, dropping reference counts
and freeing any blocks where the reference count goes to 0.
The increments done during cow and decrements done after commit cancel out,
and the walk is a very expensive way to go about freeing the blocks that
are no longer referenced by the new btree root. This commit reduces the
transaction overhead by avoiding the need for dead root records.
When a non-shared tree block is cow'd, we free the old block at once, and the
new block inherits old block's references. When a tree block with reference
count > 1 is cow'd, we increase the reference counts of all extents
the new block points to by one, and decrease the old block's reference count by
one.
This dead tree avoidance code removes the need to modify the reference
counts of lower level extents when a non-shared tree block is cow'd.
But we still need to update back ref for all pointers in the block.
This is because the location of the block is recorded in the back ref
item.
We can solve this by introducing a new type of back ref. The new
back ref provides information about pointer's key, level and in which
tree the pointer lives. This information allow us to find the pointer
by searching the tree. The shortcoming of the new back ref is that it
only works for pointers in tree blocks referenced by their owner trees.
This is mostly a problem for snapshots, where resolving one of these
fuzzy back references would be O(number_of_snapshots) and quite slow.
The solution used here is to use the fuzzy back references in the common
case where a given tree block is only referenced by one root,
and use the full back references when multiple roots have a reference
on a given block.
This commit adds per subvolume red-black tree to keep trace of cached
inodes. The red-black tree helps the balancing code to find cached
inodes whose inode numbers within a given range.
This commit improves the balancing code by introducing several data
structures to keep the state of balancing. The most important one
is the back ref cache. It caches how the upper level tree blocks are
referenced. This greatly reduce the overhead of checking back ref.
The improved balancing code scales significantly better with a large
number of snapshots.
This is a very large commit and was written in a number of
pieces. But, they depend heavily on the disk format change and were
squashed together to make sure git bisect didn't end up in a
bad state wrt space balancing or the format change.
Signed-off-by: Yan Zheng <zheng.yan@oracle.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-06-10 21:45:14 +07:00
|
|
|
if (IS_ERR(inode)) {
|
|
|
|
err = PTR_ERR(inode);
|
2007-06-12 17:35:45 +07:00
|
|
|
goto fail_close;
|
2007-03-30 02:15:27 +07:00
|
|
|
}
|
|
|
|
|
2012-01-09 10:15:13 +07:00
|
|
|
sb->s_root = d_make_root(inode);
|
|
|
|
if (!sb->s_root) {
|
2007-06-12 17:35:45 +07:00
|
|
|
err = -ENOMEM;
|
|
|
|
goto fail_close;
|
2007-03-30 02:15:27 +07:00
|
|
|
}
|
2007-08-30 02:47:34 +07:00
|
|
|
|
2008-02-21 04:11:05 +07:00
|
|
|
save_mount_options(sb, data);
|
2011-05-26 23:01:56 +07:00
|
|
|
cleancache_init_fs(sb);
|
2011-11-17 13:56:28 +07:00
|
|
|
sb->s_flags |= MS_ACTIVE;
|
2007-04-11 03:58:11 +07:00
|
|
|
return 0;
|
2007-06-12 17:35:45 +07:00
|
|
|
|
|
|
|
fail_close:
|
2011-11-18 03:40:49 +07:00
|
|
|
close_ctree(fs_info->tree_root);
|
2007-06-12 17:35:45 +07:00
|
|
|
return err;
|
2007-04-11 03:58:11 +07:00
|
|
|
}
|
|
|
|
|
2008-06-10 21:07:39 +07:00
|
|
|
int btrfs_sync_fs(struct super_block *sb, int wait)
|
2007-04-10 20:27:04 +07:00
|
|
|
{
|
|
|
|
struct btrfs_trans_handle *trans;
|
2011-11-18 03:40:49 +07:00
|
|
|
struct btrfs_fs_info *fs_info = btrfs_sb(sb);
|
|
|
|
struct btrfs_root *root = fs_info->tree_root;
|
2007-04-11 03:58:11 +07:00
|
|
|
|
Btrfs: add initial tracepoint support for btrfs
Tracepoints can provide insight into why btrfs hits bugs and be greatly
helpful for debugging, e.g
dd-7822 [000] 2121.641088: btrfs_inode_request: root = 5(FS_TREE), gen = 4, ino = 256, blocks = 8, disk_i_size = 0, last_trans = 8, logged_trans = 0
dd-7822 [000] 2121.641100: btrfs_inode_new: root = 5(FS_TREE), gen = 8, ino = 257, blocks = 0, disk_i_size = 0, last_trans = 0, logged_trans = 0
btrfs-transacti-7804 [001] 2146.935420: btrfs_cow_block: root = 2(EXTENT_TREE), refs = 2, orig_buf = 29368320 (orig_level = 0), cow_buf = 29388800 (cow_level = 0)
btrfs-transacti-7804 [001] 2146.935473: btrfs_cow_block: root = 1(ROOT_TREE), refs = 2, orig_buf = 29364224 (orig_level = 0), cow_buf = 29392896 (cow_level = 0)
btrfs-transacti-7804 [001] 2146.972221: btrfs_transaction_commit: root = 1(ROOT_TREE), gen = 8
flush-btrfs-2-7821 [001] 2155.824210: btrfs_chunk_alloc: root = 3(CHUNK_TREE), offset = 1103101952, size = 1073741824, num_stripes = 1, sub_stripes = 0, type = DATA
flush-btrfs-2-7821 [001] 2155.824241: btrfs_cow_block: root = 2(EXTENT_TREE), refs = 2, orig_buf = 29388800 (orig_level = 0), cow_buf = 29396992 (cow_level = 0)
flush-btrfs-2-7821 [001] 2155.824255: btrfs_cow_block: root = 4(DEV_TREE), refs = 2, orig_buf = 29372416 (orig_level = 0), cow_buf = 29401088 (cow_level = 0)
flush-btrfs-2-7821 [000] 2155.824329: btrfs_cow_block: root = 3(CHUNK_TREE), refs = 2, orig_buf = 20971520 (orig_level = 0), cow_buf = 20975616 (cow_level = 0)
btrfs-endio-wri-7800 [001] 2155.898019: btrfs_cow_block: root = 5(FS_TREE), refs = 2, orig_buf = 29384704 (orig_level = 0), cow_buf = 29405184 (cow_level = 0)
btrfs-endio-wri-7800 [001] 2155.898043: btrfs_cow_block: root = 7(CSUM_TREE), refs = 2, orig_buf = 29376512 (orig_level = 0), cow_buf = 29409280 (cow_level = 0)
Here is what I have added:
1) ordere_extent:
btrfs_ordered_extent_add
btrfs_ordered_extent_remove
btrfs_ordered_extent_start
btrfs_ordered_extent_put
These provide critical information to understand how ordered_extents are
updated.
2) extent_map:
btrfs_get_extent
extent_map is used in both read and write cases, and it is useful for tracking
how btrfs specific IO is running.
3) writepage:
__extent_writepage
btrfs_writepage_end_io_hook
Pages are cirtical resourses and produce a lot of corner cases during writeback,
so it is valuable to know how page is written to disk.
4) inode:
btrfs_inode_new
btrfs_inode_request
btrfs_inode_evict
These can show where and when a inode is created, when a inode is evicted.
5) sync:
btrfs_sync_file
btrfs_sync_fs
These show sync arguments.
6) transaction:
btrfs_transaction_commit
In transaction based filesystem, it will be useful to know the generation and
who does commit.
7) back reference and cow:
btrfs_delayed_tree_ref
btrfs_delayed_data_ref
btrfs_delayed_ref_head
btrfs_cow_block
Btrfs natively supports back references, these tracepoints are helpful on
understanding btrfs's COW mechanism.
8) chunk:
btrfs_chunk_alloc
btrfs_chunk_free
Chunk is a link between physical offset and logical offset, and stands for space
infomation in btrfs, and these are helpful on tracing space things.
9) reserved_extent:
btrfs_reserved_extent_alloc
btrfs_reserved_extent_free
These can show how btrfs uses its space.
Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-03-24 18:18:59 +07:00
|
|
|
trace_btrfs_sync_fs(wait);
|
|
|
|
|
2007-06-12 17:35:45 +07:00
|
|
|
if (!wait) {
|
2011-11-18 03:40:49 +07:00
|
|
|
filemap_flush(fs_info->btree_inode->i_mapping);
|
2007-06-12 17:35:45 +07:00
|
|
|
return 0;
|
|
|
|
}
|
2008-11-07 10:02:51 +07:00
|
|
|
|
2013-11-04 22:13:25 +07:00
|
|
|
btrfs_wait_ordered_roots(fs_info, -1);
|
2008-11-07 10:02:51 +07:00
|
|
|
|
Btrfs: fix uncompleted transaction
In some cases, we need commit the current transaction, but don't want
to start a new one if there is no running transaction, so we introduce
the function - btrfs_attach_transaction(), which can catch the current
transaction, and return -ENOENT if there is no running transaction.
But no running transaction doesn't mean the current transction completely,
because we removed the running transaction before it completes. In some
cases, it doesn't matter. But in some special cases, such as freeze fs, we
hope the transaction is fully on disk, it will introduce some bugs, for
example, we may feeze the fs and dump the data in the disk, if the transction
doesn't complete, we would dump inconsistent data. So we need fix the above
problem for those cases.
We fixes this problem by introducing a function:
btrfs_attach_transaction_barrier()
if we hope all the transaction is fully on the disk, even they are not
running, we can use this function.
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
2013-02-20 16:17:06 +07:00
|
|
|
trans = btrfs_attach_transaction_barrier(root);
|
2012-09-14 21:34:40 +07:00
|
|
|
if (IS_ERR(trans)) {
|
Btrfs: fix orphan transaction on the freezed filesystem
With the following debug patch:
static int btrfs_freeze(struct super_block *sb)
{
+ struct btrfs_fs_info *fs_info = btrfs_sb(sb);
+ struct btrfs_transaction *trans;
+
+ spin_lock(&fs_info->trans_lock);
+ trans = fs_info->running_transaction;
+ if (trans) {
+ printk("Transid %llu, use_count %d, num_writer %d\n",
+ trans->transid, atomic_read(&trans->use_count),
+ atomic_read(&trans->num_writers));
+ }
+ spin_unlock(&fs_info->trans_lock);
return 0;
}
I found there was a orphan transaction after the freeze operation was done.
It is because the transaction may not be committed when the transaction handle
end even though it is the last handle of the current transaction. This design
avoid committing the transaction frequently, but also introduce the above
problem.
So I add btrfs_attach_transaction() which can catch the current transaction
and commit it. If there is no transaction, it will return ENOENT, and do not
anything.
This function also can be used to instead of btrfs_join_transaction_freeze()
because it don't increase the writer counter and don't start a new transaction,
so it also can fix the deadlock between sync and freeze.
Besides that, it is used to instead of btrfs_join_transaction() in
transaction_kthread(), because if there is no transaction, the transaction
kthread needn't anything.
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
2012-09-20 14:54:00 +07:00
|
|
|
/* no transaction, don't bother */
|
|
|
|
if (PTR_ERR(trans) == -ENOENT)
|
2012-09-14 21:34:40 +07:00
|
|
|
return 0;
|
2011-01-20 13:19:37 +07:00
|
|
|
return PTR_ERR(trans);
|
2012-09-14 21:34:40 +07:00
|
|
|
}
|
2012-08-25 01:53:03 +07:00
|
|
|
return btrfs_commit_transaction(trans, root);
|
2007-04-02 21:50:19 +07:00
|
|
|
}
|
|
|
|
|
2011-12-09 09:32:45 +07:00
|
|
|
static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry)
|
2009-04-03 03:46:06 +07:00
|
|
|
{
|
2011-11-18 03:40:49 +07:00
|
|
|
struct btrfs_fs_info *info = btrfs_sb(dentry->d_sb);
|
|
|
|
struct btrfs_root *root = info->tree_root;
|
2011-03-31 07:44:29 +07:00
|
|
|
char *compress_type;
|
2009-04-03 03:46:06 +07:00
|
|
|
|
|
|
|
if (btrfs_test_opt(root, DEGRADED))
|
|
|
|
seq_puts(seq, ",degraded");
|
|
|
|
if (btrfs_test_opt(root, NODATASUM))
|
|
|
|
seq_puts(seq, ",nodatasum");
|
|
|
|
if (btrfs_test_opt(root, NODATACOW))
|
|
|
|
seq_puts(seq, ",nodatacow");
|
|
|
|
if (btrfs_test_opt(root, NOBARRIER))
|
|
|
|
seq_puts(seq, ",nobarrier");
|
2013-08-09 04:45:48 +07:00
|
|
|
if (info->max_inline != BTRFS_DEFAULT_MAX_INLINE)
|
2013-08-20 18:20:07 +07:00
|
|
|
seq_printf(seq, ",max_inline=%llu", info->max_inline);
|
2009-04-03 03:46:06 +07:00
|
|
|
if (info->alloc_start != 0)
|
2013-08-20 18:20:07 +07:00
|
|
|
seq_printf(seq, ",alloc_start=%llu", info->alloc_start);
|
2009-04-03 03:46:06 +07:00
|
|
|
if (info->thread_pool_size != min_t(unsigned long,
|
|
|
|
num_online_cpus() + 2, 8))
|
|
|
|
seq_printf(seq, ",thread_pool=%d", info->thread_pool_size);
|
2011-03-31 07:44:29 +07:00
|
|
|
if (btrfs_test_opt(root, COMPRESS)) {
|
|
|
|
if (info->compress_type == BTRFS_COMPRESS_ZLIB)
|
|
|
|
compress_type = "zlib";
|
|
|
|
else
|
|
|
|
compress_type = "lzo";
|
|
|
|
if (btrfs_test_opt(root, FORCE_COMPRESS))
|
|
|
|
seq_printf(seq, ",compress-force=%s", compress_type);
|
|
|
|
else
|
|
|
|
seq_printf(seq, ",compress=%s", compress_type);
|
|
|
|
}
|
2009-06-10 20:51:32 +07:00
|
|
|
if (btrfs_test_opt(root, NOSSD))
|
|
|
|
seq_puts(seq, ",nossd");
|
2009-06-10 07:28:34 +07:00
|
|
|
if (btrfs_test_opt(root, SSD_SPREAD))
|
|
|
|
seq_puts(seq, ",ssd_spread");
|
|
|
|
else if (btrfs_test_opt(root, SSD))
|
2009-04-03 03:46:06 +07:00
|
|
|
seq_puts(seq, ",ssd");
|
2009-04-03 03:49:40 +07:00
|
|
|
if (btrfs_test_opt(root, NOTREELOG))
|
2009-05-15 00:52:21 +07:00
|
|
|
seq_puts(seq, ",notreelog");
|
2009-04-03 03:59:01 +07:00
|
|
|
if (btrfs_test_opt(root, FLUSHONCOMMIT))
|
2009-05-15 00:52:21 +07:00
|
|
|
seq_puts(seq, ",flushoncommit");
|
2009-12-15 05:01:12 +07:00
|
|
|
if (btrfs_test_opt(root, DISCARD))
|
|
|
|
seq_puts(seq, ",discard");
|
2009-04-03 03:46:06 +07:00
|
|
|
if (!(root->fs_info->sb->s_flags & MS_POSIXACL))
|
|
|
|
seq_puts(seq, ",noacl");
|
2011-03-31 07:44:29 +07:00
|
|
|
if (btrfs_test_opt(root, SPACE_CACHE))
|
|
|
|
seq_puts(seq, ",space_cache");
|
2011-10-04 01:07:49 +07:00
|
|
|
else
|
2011-11-11 22:14:57 +07:00
|
|
|
seq_puts(seq, ",nospace_cache");
|
2013-08-15 22:11:24 +07:00
|
|
|
if (btrfs_test_opt(root, RESCAN_UUID_TREE))
|
|
|
|
seq_puts(seq, ",rescan_uuid_tree");
|
2011-03-31 07:44:29 +07:00
|
|
|
if (btrfs_test_opt(root, CLEAR_CACHE))
|
|
|
|
seq_puts(seq, ",clear_cache");
|
|
|
|
if (btrfs_test_opt(root, USER_SUBVOL_RM_ALLOWED))
|
|
|
|
seq_puts(seq, ",user_subvol_rm_allowed");
|
2011-06-28 22:10:37 +07:00
|
|
|
if (btrfs_test_opt(root, ENOSPC_DEBUG))
|
|
|
|
seq_puts(seq, ",enospc_debug");
|
|
|
|
if (btrfs_test_opt(root, AUTO_DEFRAG))
|
|
|
|
seq_puts(seq, ",autodefrag");
|
|
|
|
if (btrfs_test_opt(root, INODE_MAP_CACHE))
|
|
|
|
seq_puts(seq, ",inode_cache");
|
2012-01-17 03:04:48 +07:00
|
|
|
if (btrfs_test_opt(root, SKIP_BALANCE))
|
|
|
|
seq_puts(seq, ",skip_balance");
|
2013-07-24 09:30:02 +07:00
|
|
|
if (btrfs_test_opt(root, RECOVERY))
|
|
|
|
seq_puts(seq, ",recovery");
|
|
|
|
#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
|
|
|
|
if (btrfs_test_opt(root, CHECK_INTEGRITY_INCLUDING_EXTENT_DATA))
|
|
|
|
seq_puts(seq, ",check_int_data");
|
|
|
|
else if (btrfs_test_opt(root, CHECK_INTEGRITY))
|
|
|
|
seq_puts(seq, ",check_int");
|
|
|
|
if (info->check_integrity_print_mask)
|
|
|
|
seq_printf(seq, ",check_int_print_mask=%d",
|
|
|
|
info->check_integrity_print_mask);
|
|
|
|
#endif
|
|
|
|
if (info->metadata_ratio)
|
|
|
|
seq_printf(seq, ",metadata_ratio=%d",
|
|
|
|
info->metadata_ratio);
|
2011-10-04 10:22:31 +07:00
|
|
|
if (btrfs_test_opt(root, PANIC_ON_FATAL_ERROR))
|
|
|
|
seq_puts(seq, ",fatal_errors=panic");
|
2013-08-01 23:14:52 +07:00
|
|
|
if (info->commit_interval != BTRFS_DEFAULT_COMMIT_INTERVAL)
|
|
|
|
seq_printf(seq, ",commit=%d", info->commit_interval);
|
2009-04-03 03:46:06 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-07 22:43:44 +07:00
|
|
|
static int btrfs_test_super(struct super_block *s, void *data)
|
2007-08-29 20:11:44 +07:00
|
|
|
{
|
2011-11-18 03:40:49 +07:00
|
|
|
struct btrfs_fs_info *p = data;
|
|
|
|
struct btrfs_fs_info *fs_info = btrfs_sb(s);
|
2007-08-29 20:11:44 +07:00
|
|
|
|
2011-11-18 03:40:49 +07:00
|
|
|
return fs_info->fs_devices == p->fs_devices;
|
2007-08-29 20:11:44 +07:00
|
|
|
}
|
|
|
|
|
2010-11-20 02:59:15 +07:00
|
|
|
static int btrfs_set_super(struct super_block *s, void *data)
|
|
|
|
{
|
2011-11-17 13:29:09 +07:00
|
|
|
int err = set_anon_super(s, data);
|
|
|
|
if (!err)
|
|
|
|
s->s_fs_info = data;
|
|
|
|
return err;
|
2007-08-29 20:11:44 +07:00
|
|
|
}
|
|
|
|
|
2011-09-29 18:11:33 +07:00
|
|
|
/*
|
|
|
|
* subvolumes are identified by ino 256
|
|
|
|
*/
|
|
|
|
static inline int is_subvolume_inode(struct inode *inode)
|
|
|
|
{
|
|
|
|
if (inode && inode->i_ino == BTRFS_FIRST_FREE_OBJECTID)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-26 02:55:42 +07:00
|
|
|
/*
|
|
|
|
* This will strip out the subvol=%s argument for an argument string and add
|
|
|
|
* subvolid=0 to make sure we get the actual tree root for path walking to the
|
|
|
|
* subvol we want.
|
|
|
|
*/
|
|
|
|
static char *setup_root_args(char *args)
|
|
|
|
{
|
2012-04-26 02:24:17 +07:00
|
|
|
unsigned len = strlen(args) + 2 + 1;
|
|
|
|
char *src, *dst, *buf;
|
2011-07-26 02:55:42 +07:00
|
|
|
|
|
|
|
/*
|
2012-04-26 02:24:17 +07:00
|
|
|
* We need the same args as before, but with this substitution:
|
|
|
|
* s!subvol=[^,]+!subvolid=0!
|
2011-07-26 02:55:42 +07:00
|
|
|
*
|
2012-04-26 02:24:17 +07:00
|
|
|
* Since the replacement string is up to 2 bytes longer than the
|
|
|
|
* original, allocate strlen(args) + 2 + 1 bytes.
|
2011-07-26 02:55:42 +07:00
|
|
|
*/
|
|
|
|
|
2012-04-26 02:24:17 +07:00
|
|
|
src = strstr(args, "subvol=");
|
2011-07-26 02:55:42 +07:00
|
|
|
/* This shouldn't happen, but just in case.. */
|
2012-04-26 02:24:17 +07:00
|
|
|
if (!src)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
buf = dst = kmalloc(len, GFP_NOFS);
|
|
|
|
if (!buf)
|
2011-07-26 02:55:42 +07:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/*
|
2012-04-26 02:24:17 +07:00
|
|
|
* If the subvol= arg is not at the start of the string,
|
|
|
|
* copy whatever precedes it into buf.
|
2011-07-26 02:55:42 +07:00
|
|
|
*/
|
2012-04-26 02:24:17 +07:00
|
|
|
if (src != args) {
|
|
|
|
*src++ = '\0';
|
|
|
|
strcpy(buf, args);
|
|
|
|
dst += strlen(args);
|
2011-07-26 02:55:42 +07:00
|
|
|
}
|
|
|
|
|
2012-04-26 02:24:17 +07:00
|
|
|
strcpy(dst, "subvolid=0");
|
|
|
|
dst += strlen("subvolid=0");
|
2011-07-26 02:55:42 +07:00
|
|
|
|
|
|
|
/*
|
2012-04-26 02:24:17 +07:00
|
|
|
* If there is a "," after the original subvol=... string,
|
|
|
|
* copy that suffix into our buffer. Otherwise, we're done.
|
2011-07-26 02:55:42 +07:00
|
|
|
*/
|
2012-04-26 02:24:17 +07:00
|
|
|
src = strchr(src, ',');
|
|
|
|
if (src)
|
|
|
|
strcpy(dst, src);
|
2011-07-26 02:55:42 +07:00
|
|
|
|
2012-04-26 02:24:17 +07:00
|
|
|
return buf;
|
2011-07-26 02:55:42 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct dentry *mount_subvol(const char *subvol_name, int flags,
|
|
|
|
const char *device_name, char *data)
|
|
|
|
{
|
|
|
|
struct dentry *root;
|
|
|
|
struct vfsmount *mnt;
|
|
|
|
char *newargs;
|
|
|
|
|
|
|
|
newargs = setup_root_args(data);
|
|
|
|
if (!newargs)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
mnt = vfs_kern_mount(&btrfs_fs_type, flags, device_name,
|
|
|
|
newargs);
|
btrfs: allow mounting btrfs subvolumes with different ro/rw options
Given the following /etc/fstab entries:
/dev/sda3 /mnt/foo btrfs subvol=foo,ro 0 0
/dev/sda3 /mnt/bar btrfs subvol=bar,rw 0 0
you can't issue:
$ mount /mnt/foo
$ mount /mnt/bar
You would have to do:
$ mount /mnt/foo
$ mount -o remount,rw /mnt/foo
$ mount --bind -o remount,ro /mnt/foo
$ mount /mnt/bar
or
$ mount /mnt/bar
$ mount --rw /mnt/foo
$ mount --bind -o remount,ro /mnt/foo
With this patch you can do
$ mount /mnt/foo
$ mount /mnt/bar
$ cat /proc/self/mountinfo
49 33 0:41 /foo /mnt/foo ro,relatime shared:36 - btrfs /dev/sda3 rw,ssd,space_cache
87 33 0:41 /bar /mnt/bar rw,relatime shared:74 - btrfs /dev/sda3 rw,ssd,space_cache
Signed-off-by: Chris Mason <clm@fb.com>
2013-11-19 17:36:05 +07:00
|
|
|
|
|
|
|
if (PTR_RET(mnt) == -EBUSY) {
|
|
|
|
if (flags & MS_RDONLY) {
|
|
|
|
mnt = vfs_kern_mount(&btrfs_fs_type, flags & ~MS_RDONLY, device_name,
|
|
|
|
newargs);
|
|
|
|
} else {
|
|
|
|
int r;
|
|
|
|
mnt = vfs_kern_mount(&btrfs_fs_type, flags | MS_RDONLY, device_name,
|
|
|
|
newargs);
|
2014-04-12 18:33:13 +07:00
|
|
|
if (IS_ERR(mnt)) {
|
|
|
|
kfree(newargs);
|
btrfs: allow mounting btrfs subvolumes with different ro/rw options
Given the following /etc/fstab entries:
/dev/sda3 /mnt/foo btrfs subvol=foo,ro 0 0
/dev/sda3 /mnt/bar btrfs subvol=bar,rw 0 0
you can't issue:
$ mount /mnt/foo
$ mount /mnt/bar
You would have to do:
$ mount /mnt/foo
$ mount -o remount,rw /mnt/foo
$ mount --bind -o remount,ro /mnt/foo
$ mount /mnt/bar
or
$ mount /mnt/bar
$ mount --rw /mnt/foo
$ mount --bind -o remount,ro /mnt/foo
With this patch you can do
$ mount /mnt/foo
$ mount /mnt/bar
$ cat /proc/self/mountinfo
49 33 0:41 /foo /mnt/foo ro,relatime shared:36 - btrfs /dev/sda3 rw,ssd,space_cache
87 33 0:41 /bar /mnt/bar rw,relatime shared:74 - btrfs /dev/sda3 rw,ssd,space_cache
Signed-off-by: Chris Mason <clm@fb.com>
2013-11-19 17:36:05 +07:00
|
|
|
return ERR_CAST(mnt);
|
2014-04-12 18:33:13 +07:00
|
|
|
}
|
btrfs: allow mounting btrfs subvolumes with different ro/rw options
Given the following /etc/fstab entries:
/dev/sda3 /mnt/foo btrfs subvol=foo,ro 0 0
/dev/sda3 /mnt/bar btrfs subvol=bar,rw 0 0
you can't issue:
$ mount /mnt/foo
$ mount /mnt/bar
You would have to do:
$ mount /mnt/foo
$ mount -o remount,rw /mnt/foo
$ mount --bind -o remount,ro /mnt/foo
$ mount /mnt/bar
or
$ mount /mnt/bar
$ mount --rw /mnt/foo
$ mount --bind -o remount,ro /mnt/foo
With this patch you can do
$ mount /mnt/foo
$ mount /mnt/bar
$ cat /proc/self/mountinfo
49 33 0:41 /foo /mnt/foo ro,relatime shared:36 - btrfs /dev/sda3 rw,ssd,space_cache
87 33 0:41 /bar /mnt/bar rw,relatime shared:74 - btrfs /dev/sda3 rw,ssd,space_cache
Signed-off-by: Chris Mason <clm@fb.com>
2013-11-19 17:36:05 +07:00
|
|
|
|
|
|
|
r = btrfs_remount(mnt->mnt_sb, &flags, NULL);
|
|
|
|
if (r < 0) {
|
|
|
|
/* FIXME: release vfsmount mnt ??*/
|
2014-04-12 18:33:13 +07:00
|
|
|
kfree(newargs);
|
btrfs: allow mounting btrfs subvolumes with different ro/rw options
Given the following /etc/fstab entries:
/dev/sda3 /mnt/foo btrfs subvol=foo,ro 0 0
/dev/sda3 /mnt/bar btrfs subvol=bar,rw 0 0
you can't issue:
$ mount /mnt/foo
$ mount /mnt/bar
You would have to do:
$ mount /mnt/foo
$ mount -o remount,rw /mnt/foo
$ mount --bind -o remount,ro /mnt/foo
$ mount /mnt/bar
or
$ mount /mnt/bar
$ mount --rw /mnt/foo
$ mount --bind -o remount,ro /mnt/foo
With this patch you can do
$ mount /mnt/foo
$ mount /mnt/bar
$ cat /proc/self/mountinfo
49 33 0:41 /foo /mnt/foo ro,relatime shared:36 - btrfs /dev/sda3 rw,ssd,space_cache
87 33 0:41 /bar /mnt/bar rw,relatime shared:74 - btrfs /dev/sda3 rw,ssd,space_cache
Signed-off-by: Chris Mason <clm@fb.com>
2013-11-19 17:36:05 +07:00
|
|
|
return ERR_PTR(r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-12 18:33:13 +07:00
|
|
|
kfree(newargs);
|
|
|
|
|
2011-07-26 02:55:42 +07:00
|
|
|
if (IS_ERR(mnt))
|
|
|
|
return ERR_CAST(mnt);
|
|
|
|
|
2011-11-17 09:43:59 +07:00
|
|
|
root = mount_subtree(mnt, subvol_name);
|
2011-07-26 02:55:42 +07:00
|
|
|
|
2011-11-17 09:43:59 +07:00
|
|
|
if (!IS_ERR(root) && !is_subvolume_inode(root->d_inode)) {
|
|
|
|
struct super_block *s = root->d_sb;
|
|
|
|
dput(root);
|
|
|
|
root = ERR_PTR(-EINVAL);
|
|
|
|
deactivate_locked_super(s);
|
2013-12-20 23:37:06 +07:00
|
|
|
printk(KERN_ERR "BTRFS: '%s' is not a valid subvolume\n",
|
2011-09-29 18:11:33 +07:00
|
|
|
subvol_name);
|
|
|
|
}
|
|
|
|
|
2011-07-26 02:55:42 +07:00
|
|
|
return root;
|
|
|
|
}
|
2010-11-20 02:59:15 +07:00
|
|
|
|
2014-09-23 12:40:08 +07:00
|
|
|
static int parse_security_options(char *orig_opts,
|
|
|
|
struct security_mnt_opts *sec_opts)
|
|
|
|
{
|
|
|
|
char *secdata = NULL;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
secdata = alloc_secdata();
|
|
|
|
if (!secdata)
|
|
|
|
return -ENOMEM;
|
|
|
|
ret = security_sb_copy_data(orig_opts, secdata);
|
|
|
|
if (ret) {
|
|
|
|
free_secdata(secdata);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ret = security_sb_parse_opts_str(secdata, sec_opts);
|
|
|
|
free_secdata(secdata);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int setup_security_options(struct btrfs_fs_info *fs_info,
|
|
|
|
struct super_block *sb,
|
|
|
|
struct security_mnt_opts *sec_opts)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call security_sb_set_mnt_opts() to check whether new sec_opts
|
|
|
|
* is valid.
|
|
|
|
*/
|
|
|
|
ret = security_sb_set_mnt_opts(sb, sec_opts, 0, NULL);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2014-10-08 09:19:08 +07:00
|
|
|
#ifdef CONFIG_SECURITY
|
2014-09-23 12:40:08 +07:00
|
|
|
if (!fs_info->security_opts.num_mnt_opts) {
|
|
|
|
/* first time security setup, copy sec_opts to fs_info */
|
|
|
|
memcpy(&fs_info->security_opts, sec_opts, sizeof(*sec_opts));
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Since SELinux(the only one supports security_mnt_opts) does
|
|
|
|
* NOT support changing context during remount/mount same sb,
|
|
|
|
* This must be the same or part of the same security options,
|
|
|
|
* just free it.
|
|
|
|
*/
|
|
|
|
security_free_mnt_opts(sec_opts);
|
|
|
|
}
|
2014-10-08 09:19:08 +07:00
|
|
|
#endif
|
2014-09-23 12:40:08 +07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-06-10 21:40:29 +07:00
|
|
|
/*
|
|
|
|
* Find a superblock for the given device / mount point.
|
|
|
|
*
|
|
|
|
* Note: This is based on get_sb_bdev from fs/super.c with a few additions
|
|
|
|
* for multiple device setup. Make sure to keep it in sync.
|
|
|
|
*/
|
2010-07-26 19:21:33 +07:00
|
|
|
static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,
|
2011-04-19 19:29:38 +07:00
|
|
|
const char *device_name, void *data)
|
2007-08-29 20:11:44 +07:00
|
|
|
{
|
|
|
|
struct block_device *bdev = NULL;
|
|
|
|
struct super_block *s;
|
|
|
|
struct dentry *root;
|
2008-03-25 02:02:07 +07:00
|
|
|
struct btrfs_fs_devices *fs_devices = NULL;
|
2010-11-20 02:59:15 +07:00
|
|
|
struct btrfs_fs_info *fs_info = NULL;
|
2014-09-23 12:40:08 +07:00
|
|
|
struct security_mnt_opts new_sec_opts;
|
2008-12-02 18:36:09 +07:00
|
|
|
fmode_t mode = FMODE_READ;
|
Btrfs: change how we mount subvolumes
This work is in preperation for being able to set a different root as the
default mounting root.
There is currently a problem with how we mount subvolumes. We cannot currently
mount a subvolume of a subvolume, you can only mount subvolumes/snapshots of the
default subvolume. So say you take a snapshot of the default subvolume and call
it snap1, and then take a snapshot of snap1 and call it snap2, so now you have
/
/snap1
/snap1/snap2
as your available volumes. Currently you can only mount / and /snap1,
you cannot mount /snap1/snap2. To fix this problem instead of passing
subvolid=<name> you must pass in subvolid=<treeid>, where <treeid> is
the tree id that gets spit out via the subvolume listing you get from
the subvolume listing patches (btrfs filesystem list). This allows us
to mount /, /snap1 and /snap1/snap2 as the root volume.
In addition to the above, we also now read the default dir item in the
tree root to get the root key that it points to. For now this just
points at what has always been the default subvolme, but later on I plan
to change it to point at whatever root you want to be the new default
root, so you can just set the default mount and not have to mount with
-o subvolid=<treeid>. I tested this out with the above scenario and it
worked perfectly. Thanks,
mount -o subvol operates inside the selected subvolid. For example:
mount -o subvol=snap1,subvolid=256 /dev/xxx /mnt
/mnt will have the snap1 directory for the subvolume with id
256.
mount -o subvol=snap /dev/xxx /mnt
/mnt will be the snap directory of whatever the default subvolume
is.
Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-12-05 00:38:27 +07:00
|
|
|
char *subvol_name = NULL;
|
|
|
|
u64 subvol_objectid = 0;
|
2007-08-29 20:11:44 +07:00
|
|
|
int error = 0;
|
|
|
|
|
2008-12-02 18:36:09 +07:00
|
|
|
if (!(flags & MS_RDONLY))
|
|
|
|
mode |= FMODE_WRITE;
|
|
|
|
|
|
|
|
error = btrfs_parse_early_options(data, mode, fs_type,
|
Btrfs: change how we mount subvolumes
This work is in preperation for being able to set a different root as the
default mounting root.
There is currently a problem with how we mount subvolumes. We cannot currently
mount a subvolume of a subvolume, you can only mount subvolumes/snapshots of the
default subvolume. So say you take a snapshot of the default subvolume and call
it snap1, and then take a snapshot of snap1 and call it snap2, so now you have
/
/snap1
/snap1/snap2
as your available volumes. Currently you can only mount / and /snap1,
you cannot mount /snap1/snap2. To fix this problem instead of passing
subvolid=<name> you must pass in subvolid=<treeid>, where <treeid> is
the tree id that gets spit out via the subvolume listing you get from
the subvolume listing patches (btrfs filesystem list). This allows us
to mount /, /snap1 and /snap1/snap2 as the root volume.
In addition to the above, we also now read the default dir item in the
tree root to get the root key that it points to. For now this just
points at what has always been the default subvolme, but later on I plan
to change it to point at whatever root you want to be the new default
root, so you can just set the default mount and not have to mount with
-o subvolid=<treeid>. I tested this out with the above scenario and it
worked perfectly. Thanks,
mount -o subvol operates inside the selected subvolid. For example:
mount -o subvol=snap1,subvolid=256 /dev/xxx /mnt
/mnt will have the snap1 directory for the subvolume with id
256.
mount -o subvol=snap /dev/xxx /mnt
/mnt will be the snap directory of whatever the default subvolume
is.
Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-12-05 00:38:27 +07:00
|
|
|
&subvol_name, &subvol_objectid,
|
2013-03-20 20:21:10 +07:00
|
|
|
&fs_devices);
|
2011-11-09 00:15:05 +07:00
|
|
|
if (error) {
|
|
|
|
kfree(subvol_name);
|
2010-07-26 19:21:33 +07:00
|
|
|
return ERR_PTR(error);
|
2011-11-09 00:15:05 +07:00
|
|
|
}
|
2008-06-10 21:40:29 +07:00
|
|
|
|
2011-07-26 02:55:42 +07:00
|
|
|
if (subvol_name) {
|
|
|
|
root = mount_subvol(subvol_name, flags, device_name, data);
|
|
|
|
kfree(subvol_name);
|
|
|
|
return root;
|
|
|
|
}
|
|
|
|
|
2014-09-23 12:40:08 +07:00
|
|
|
security_init_mnt_opts(&new_sec_opts);
|
|
|
|
if (data) {
|
|
|
|
error = parse_security_options(data, &new_sec_opts);
|
|
|
|
if (error)
|
|
|
|
return ERR_PTR(error);
|
|
|
|
}
|
|
|
|
|
2011-04-19 19:29:38 +07:00
|
|
|
error = btrfs_scan_one_device(device_name, mode, fs_type, &fs_devices);
|
2008-03-25 02:02:07 +07:00
|
|
|
if (error)
|
2014-09-23 12:40:08 +07:00
|
|
|
goto error_sec_opts;
|
2007-08-29 20:11:44 +07:00
|
|
|
|
2010-11-20 02:59:15 +07:00
|
|
|
/*
|
|
|
|
* Setup a dummy root and fs_info for test/set super. This is because
|
|
|
|
* we don't actually fill this stuff out until open_ctree, but we need
|
|
|
|
* it for searching for existing supers, so this lets us do that and
|
|
|
|
* then open_ctree will properly initialize everything later.
|
|
|
|
*/
|
|
|
|
fs_info = kzalloc(sizeof(struct btrfs_fs_info), GFP_NOFS);
|
2014-09-23 12:40:08 +07:00
|
|
|
if (!fs_info) {
|
|
|
|
error = -ENOMEM;
|
|
|
|
goto error_sec_opts;
|
|
|
|
}
|
2011-11-09 19:41:22 +07:00
|
|
|
|
2010-11-20 02:59:15 +07:00
|
|
|
fs_info->fs_devices = fs_devices;
|
|
|
|
|
2011-04-13 20:41:04 +07:00
|
|
|
fs_info->super_copy = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_NOFS);
|
|
|
|
fs_info->super_for_commit = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_NOFS);
|
2014-09-23 12:40:08 +07:00
|
|
|
security_init_mnt_opts(&fs_info->security_opts);
|
2011-04-13 20:41:04 +07:00
|
|
|
if (!fs_info->super_copy || !fs_info->super_for_commit) {
|
|
|
|
error = -ENOMEM;
|
2011-11-09 19:41:22 +07:00
|
|
|
goto error_fs_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = btrfs_open_devices(fs_devices, mode, fs_type);
|
|
|
|
if (error)
|
|
|
|
goto error_fs_info;
|
|
|
|
|
|
|
|
if (!(flags & MS_RDONLY) && fs_devices->rw_devices == 0) {
|
|
|
|
error = -EACCES;
|
2011-04-13 20:41:04 +07:00
|
|
|
goto error_close_devices;
|
|
|
|
}
|
|
|
|
|
2008-05-14 00:46:40 +07:00
|
|
|
bdev = fs_devices->latest_bdev;
|
2012-06-25 18:55:37 +07:00
|
|
|
s = sget(fs_type, btrfs_test_super, btrfs_set_super, flags | MS_NOSEC,
|
|
|
|
fs_info);
|
2011-07-26 02:55:42 +07:00
|
|
|
if (IS_ERR(s)) {
|
|
|
|
error = PTR_ERR(s);
|
|
|
|
goto error_close_devices;
|
|
|
|
}
|
2007-08-29 20:11:44 +07:00
|
|
|
|
|
|
|
if (s->s_root) {
|
2008-11-18 09:11:30 +07:00
|
|
|
btrfs_close_devices(fs_devices);
|
2011-04-13 20:41:04 +07:00
|
|
|
free_fs_info(fs_info);
|
2011-11-17 13:56:28 +07:00
|
|
|
if ((flags ^ s->s_flags) & MS_RDONLY)
|
|
|
|
error = -EBUSY;
|
2007-08-29 20:11:44 +07:00
|
|
|
} else {
|
|
|
|
char b[BDEVNAME_SIZE];
|
|
|
|
|
|
|
|
strlcpy(s->s_id, bdevname(bdev, b), sizeof(s->s_id));
|
2011-11-18 03:40:49 +07:00
|
|
|
btrfs_sb(s)->bdev_holder = fs_type;
|
2008-03-25 02:02:07 +07:00
|
|
|
error = btrfs_fill_super(s, fs_devices, data,
|
|
|
|
flags & MS_SILENT ? 1 : 0);
|
2007-08-29 20:11:44 +07:00
|
|
|
}
|
|
|
|
|
2011-11-17 13:56:28 +07:00
|
|
|
root = !error ? get_default_root(s, subvol_objectid) : ERR_PTR(error);
|
2014-09-23 12:40:08 +07:00
|
|
|
if (IS_ERR(root)) {
|
|
|
|
deactivate_locked_super(s);
|
|
|
|
error = PTR_ERR(root);
|
|
|
|
goto error_sec_opts;
|
|
|
|
}
|
|
|
|
|
|
|
|
fs_info = btrfs_sb(s);
|
|
|
|
error = setup_security_options(fs_info, s, &new_sec_opts);
|
|
|
|
if (error) {
|
|
|
|
dput(root);
|
2011-07-26 02:55:42 +07:00
|
|
|
deactivate_locked_super(s);
|
2014-09-23 12:40:08 +07:00
|
|
|
goto error_sec_opts;
|
|
|
|
}
|
2007-08-29 20:11:44 +07:00
|
|
|
|
2010-07-26 19:21:33 +07:00
|
|
|
return root;
|
2007-08-29 20:11:44 +07:00
|
|
|
|
2008-11-13 02:34:12 +07:00
|
|
|
error_close_devices:
|
2008-03-25 02:02:07 +07:00
|
|
|
btrfs_close_devices(fs_devices);
|
2011-11-09 19:41:22 +07:00
|
|
|
error_fs_info:
|
2011-04-13 20:41:04 +07:00
|
|
|
free_fs_info(fs_info);
|
2014-09-23 12:40:08 +07:00
|
|
|
error_sec_opts:
|
|
|
|
security_free_mnt_opts(&new_sec_opts);
|
2010-07-26 19:21:33 +07:00
|
|
|
return ERR_PTR(error);
|
2007-08-29 20:11:44 +07:00
|
|
|
}
|
2007-03-21 22:12:56 +07:00
|
|
|
|
2012-04-25 02:59:16 +07:00
|
|
|
static void btrfs_resize_thread_pool(struct btrfs_fs_info *fs_info,
|
|
|
|
int new_pool_size, int old_pool_size)
|
|
|
|
{
|
|
|
|
if (new_pool_size == old_pool_size)
|
|
|
|
return;
|
|
|
|
|
|
|
|
fs_info->thread_pool_size = new_pool_size;
|
|
|
|
|
2013-12-20 23:37:06 +07:00
|
|
|
btrfs_info(fs_info, "resize thread pool %d -> %d",
|
2012-04-25 02:59:16 +07:00
|
|
|
old_pool_size, new_pool_size);
|
|
|
|
|
2014-02-28 09:46:06 +07:00
|
|
|
btrfs_workqueue_set_max(fs_info->workers, new_pool_size);
|
2014-02-28 09:46:07 +07:00
|
|
|
btrfs_workqueue_set_max(fs_info->delalloc_workers, new_pool_size);
|
2014-02-28 09:46:08 +07:00
|
|
|
btrfs_workqueue_set_max(fs_info->submit_workers, new_pool_size);
|
2014-02-28 09:46:12 +07:00
|
|
|
btrfs_workqueue_set_max(fs_info->caching_workers, new_pool_size);
|
2014-02-28 09:46:10 +07:00
|
|
|
btrfs_workqueue_set_max(fs_info->endio_workers, new_pool_size);
|
|
|
|
btrfs_workqueue_set_max(fs_info->endio_meta_workers, new_pool_size);
|
|
|
|
btrfs_workqueue_set_max(fs_info->endio_meta_write_workers,
|
|
|
|
new_pool_size);
|
|
|
|
btrfs_workqueue_set_max(fs_info->endio_write_workers, new_pool_size);
|
|
|
|
btrfs_workqueue_set_max(fs_info->endio_freespace_worker, new_pool_size);
|
2014-02-28 09:46:15 +07:00
|
|
|
btrfs_workqueue_set_max(fs_info->delayed_workers, new_pool_size);
|
2014-02-28 09:46:13 +07:00
|
|
|
btrfs_workqueue_set_max(fs_info->readahead_workers, new_pool_size);
|
2014-02-28 09:46:17 +07:00
|
|
|
btrfs_workqueue_set_max(fs_info->scrub_wr_completion_workers,
|
|
|
|
new_pool_size);
|
2012-04-25 02:59:16 +07:00
|
|
|
}
|
|
|
|
|
2013-04-11 17:29:35 +07:00
|
|
|
static inline void btrfs_remount_prepare(struct btrfs_fs_info *fs_info)
|
2013-02-21 13:32:52 +07:00
|
|
|
{
|
|
|
|
set_bit(BTRFS_FS_STATE_REMOUNTING, &fs_info->fs_state);
|
2013-04-11 17:29:35 +07:00
|
|
|
}
|
2013-02-21 13:32:52 +07:00
|
|
|
|
2013-04-11 17:29:35 +07:00
|
|
|
static inline void btrfs_remount_begin(struct btrfs_fs_info *fs_info,
|
|
|
|
unsigned long old_opts, int flags)
|
|
|
|
{
|
2013-02-21 13:32:52 +07:00
|
|
|
if (btrfs_raw_test_opt(old_opts, AUTO_DEFRAG) &&
|
|
|
|
(!btrfs_raw_test_opt(fs_info->mount_opt, AUTO_DEFRAG) ||
|
|
|
|
(flags & MS_RDONLY))) {
|
|
|
|
/* wait for any defraggers to finish */
|
|
|
|
wait_event(fs_info->transaction_wait,
|
|
|
|
(atomic_read(&fs_info->defrag_running) == 0));
|
|
|
|
if (flags & MS_RDONLY)
|
|
|
|
sync_filesystem(fs_info->sb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void btrfs_remount_cleanup(struct btrfs_fs_info *fs_info,
|
|
|
|
unsigned long old_opts)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We need cleanup all defragable inodes if the autodefragment is
|
|
|
|
* close or the fs is R/O.
|
|
|
|
*/
|
|
|
|
if (btrfs_raw_test_opt(old_opts, AUTO_DEFRAG) &&
|
|
|
|
(!btrfs_raw_test_opt(fs_info->mount_opt, AUTO_DEFRAG) ||
|
|
|
|
(fs_info->sb->s_flags & MS_RDONLY))) {
|
|
|
|
btrfs_cleanup_defrag_inodes(fs_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
clear_bit(BTRFS_FS_STATE_REMOUNTING, &fs_info->fs_state);
|
|
|
|
}
|
|
|
|
|
2008-11-13 02:34:12 +07:00
|
|
|
static int btrfs_remount(struct super_block *sb, int *flags, char *data)
|
|
|
|
{
|
2011-11-18 03:40:49 +07:00
|
|
|
struct btrfs_fs_info *fs_info = btrfs_sb(sb);
|
|
|
|
struct btrfs_root *root = fs_info->tree_root;
|
2012-03-01 23:24:58 +07:00
|
|
|
unsigned old_flags = sb->s_flags;
|
|
|
|
unsigned long old_opts = fs_info->mount_opt;
|
|
|
|
unsigned long old_compress_type = fs_info->compress_type;
|
|
|
|
u64 old_max_inline = fs_info->max_inline;
|
|
|
|
u64 old_alloc_start = fs_info->alloc_start;
|
|
|
|
int old_thread_pool_size = fs_info->thread_pool_size;
|
|
|
|
unsigned int old_metadata_ratio = fs_info->metadata_ratio;
|
2008-11-13 02:34:12 +07:00
|
|
|
int ret;
|
|
|
|
|
2014-03-13 21:14:33 +07:00
|
|
|
sync_filesystem(sb);
|
2013-04-11 17:29:35 +07:00
|
|
|
btrfs_remount_prepare(fs_info);
|
2013-02-21 13:32:52 +07:00
|
|
|
|
2014-09-23 12:40:08 +07:00
|
|
|
if (data) {
|
|
|
|
struct security_mnt_opts new_sec_opts;
|
|
|
|
|
|
|
|
security_init_mnt_opts(&new_sec_opts);
|
|
|
|
ret = parse_security_options(data, &new_sec_opts);
|
|
|
|
if (ret)
|
|
|
|
goto restore;
|
|
|
|
ret = setup_security_options(fs_info, sb,
|
|
|
|
&new_sec_opts);
|
|
|
|
if (ret) {
|
|
|
|
security_free_mnt_opts(&new_sec_opts);
|
|
|
|
goto restore;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-12 21:37:35 +07:00
|
|
|
ret = btrfs_parse_options(root, data);
|
2012-03-01 23:24:58 +07:00
|
|
|
if (ret) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto restore;
|
|
|
|
}
|
2009-02-12 21:37:35 +07:00
|
|
|
|
2013-04-11 17:29:35 +07:00
|
|
|
btrfs_remount_begin(fs_info, old_opts, *flags);
|
2012-04-25 02:59:16 +07:00
|
|
|
btrfs_resize_thread_pool(fs_info,
|
|
|
|
fs_info->thread_pool_size, old_thread_pool_size);
|
|
|
|
|
2008-11-13 02:34:12 +07:00
|
|
|
if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
|
2013-02-21 13:32:52 +07:00
|
|
|
goto out;
|
2008-11-13 02:34:12 +07:00
|
|
|
|
|
|
|
if (*flags & MS_RDONLY) {
|
2012-11-06 19:15:27 +07:00
|
|
|
/*
|
|
|
|
* this also happens on 'umount -rf' or on shutdown, when
|
|
|
|
* the filesystem is busy.
|
|
|
|
*/
|
Btrfs: reclaim the reserved metadata space at background
Before applying this patch, the task had to reclaim the metadata space
by itself if the metadata space was not enough. And When the task started
the space reclamation, all the other tasks which wanted to reserve the
metadata space were blocked. At some cases, they would be blocked for
a long time, it made the performance fluctuate wildly.
So we introduce the background metadata space reclamation, when the space
is about to be exhausted, we insert a reclaim work into the workqueue, the
worker of the workqueue helps us to reclaim the reserved space at the
background. By this way, the tasks needn't reclaim the space by themselves at
most cases, and even if the tasks have to reclaim the space or are blocked
for the space reclamation, they will get enough space more quickly.
Here is my test result(Tested by compilebench):
Memory: 2GB
CPU: 2Cores * 1CPU
Partition: 40GB(SSD)
Test command:
# compilebench -D <mnt> -m
Without this patch:
intial create total runs 30 avg 54.36 MB/s (user 0.52s sys 2.44s)
compile total runs 30 avg 123.72 MB/s (user 0.13s sys 1.17s)
read compiled tree total runs 3 avg 81.15 MB/s (user 0.74s sys 4.89s)
delete compiled tree total runs 30 avg 5.32 seconds (user 0.35s sys 4.37s)
With this patch:
intial create total runs 30 avg 59.80 MB/s (user 0.52s sys 2.53s)
compile total runs 30 avg 151.44 MB/s (user 0.13s sys 1.11s)
read compiled tree total runs 3 avg 83.25 MB/s (user 0.76s sys 4.91s)
delete compiled tree total runs 30 avg 5.29 seconds (user 0.34s sys 4.34s)
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <clm@fb.com>
2014-05-14 07:29:04 +07:00
|
|
|
cancel_work_sync(&fs_info->async_reclaim_work);
|
2013-10-11 22:14:58 +07:00
|
|
|
|
|
|
|
/* wait for the uuid_scan task to finish */
|
|
|
|
down(&fs_info->uuid_tree_rescan_sem);
|
|
|
|
/* avoid complains from lockdep et al. */
|
|
|
|
up(&fs_info->uuid_tree_rescan_sem);
|
|
|
|
|
2008-11-13 02:34:12 +07:00
|
|
|
sb->s_flags |= MS_RDONLY;
|
|
|
|
|
2012-11-06 19:15:27 +07:00
|
|
|
btrfs_dev_replace_suspend_for_unmount(fs_info);
|
|
|
|
btrfs_scrub_cancel(fs_info);
|
2013-05-15 14:48:17 +07:00
|
|
|
btrfs_pause_balance(fs_info);
|
2012-11-06 19:15:27 +07:00
|
|
|
|
2012-03-01 23:24:58 +07:00
|
|
|
ret = btrfs_commit_super(root);
|
|
|
|
if (ret)
|
|
|
|
goto restore;
|
2008-11-13 02:34:12 +07:00
|
|
|
} else {
|
2013-09-13 22:41:20 +07:00
|
|
|
if (test_bit(BTRFS_FS_STATE_ERROR, &root->fs_info->fs_state)) {
|
|
|
|
btrfs_err(fs_info,
|
2013-12-20 23:37:06 +07:00
|
|
|
"Remounting read-write after error is not allowed");
|
2013-09-13 22:41:20 +07:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto restore;
|
|
|
|
}
|
2012-04-16 10:44:37 +07:00
|
|
|
if (fs_info->fs_devices->rw_devices == 0) {
|
2012-03-01 23:24:58 +07:00
|
|
|
ret = -EACCES;
|
|
|
|
goto restore;
|
2012-04-16 10:44:37 +07:00
|
|
|
}
|
2008-11-18 09:11:30 +07:00
|
|
|
|
2012-10-31 00:16:16 +07:00
|
|
|
if (fs_info->fs_devices->missing_devices >
|
|
|
|
fs_info->num_tolerated_disk_barrier_failures &&
|
|
|
|
!(*flags & MS_RDONLY)) {
|
2013-12-20 23:37:06 +07:00
|
|
|
btrfs_warn(fs_info,
|
|
|
|
"too many missing devices, writeable remount is not allowed");
|
2012-10-31 00:16:16 +07:00
|
|
|
ret = -EACCES;
|
|
|
|
goto restore;
|
|
|
|
}
|
|
|
|
|
2012-04-16 10:44:37 +07:00
|
|
|
if (btrfs_super_log_root(fs_info->super_copy) != 0) {
|
2012-03-01 23:24:58 +07:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto restore;
|
2012-04-16 10:44:37 +07:00
|
|
|
}
|
2008-11-13 02:34:12 +07:00
|
|
|
|
2011-11-18 03:40:49 +07:00
|
|
|
ret = btrfs_cleanup_fs_roots(fs_info);
|
2012-03-01 23:24:58 +07:00
|
|
|
if (ret)
|
|
|
|
goto restore;
|
2008-11-13 02:34:12 +07:00
|
|
|
|
2010-05-16 21:49:58 +07:00
|
|
|
/* recover relocation */
|
2014-06-26 10:08:16 +07:00
|
|
|
mutex_lock(&fs_info->cleaner_mutex);
|
2010-05-16 21:49:58 +07:00
|
|
|
ret = btrfs_recover_relocation(root);
|
2014-06-26 10:08:16 +07:00
|
|
|
mutex_unlock(&fs_info->cleaner_mutex);
|
2012-03-01 23:24:58 +07:00
|
|
|
if (ret)
|
|
|
|
goto restore;
|
2008-11-13 02:34:12 +07:00
|
|
|
|
2012-06-23 01:24:13 +07:00
|
|
|
ret = btrfs_resume_balance_async(fs_info);
|
|
|
|
if (ret)
|
|
|
|
goto restore;
|
|
|
|
|
2012-11-06 19:15:27 +07:00
|
|
|
ret = btrfs_resume_dev_replace_async(fs_info);
|
|
|
|
if (ret) {
|
2013-12-20 23:37:06 +07:00
|
|
|
btrfs_warn(fs_info, "failed to resume dev_replace");
|
2012-11-06 19:15:27 +07:00
|
|
|
goto restore;
|
|
|
|
}
|
2013-09-21 09:33:20 +07:00
|
|
|
|
|
|
|
if (!fs_info->uuid_root) {
|
2013-12-20 23:37:06 +07:00
|
|
|
btrfs_info(fs_info, "creating UUID tree");
|
2013-09-21 09:33:20 +07:00
|
|
|
ret = btrfs_create_uuid_tree(fs_info);
|
|
|
|
if (ret) {
|
2013-12-20 23:37:06 +07:00
|
|
|
btrfs_warn(fs_info, "failed to create the UUID tree %d", ret);
|
2013-09-21 09:33:20 +07:00
|
|
|
goto restore;
|
|
|
|
}
|
|
|
|
}
|
2008-11-13 02:34:12 +07:00
|
|
|
sb->s_flags &= ~MS_RDONLY;
|
|
|
|
}
|
2013-02-21 13:32:52 +07:00
|
|
|
out:
|
2014-02-20 23:48:07 +07:00
|
|
|
wake_up_process(fs_info->transaction_kthread);
|
2013-02-21 13:32:52 +07:00
|
|
|
btrfs_remount_cleanup(fs_info, old_opts);
|
2008-11-13 02:34:12 +07:00
|
|
|
return 0;
|
2012-03-01 23:24:58 +07:00
|
|
|
|
|
|
|
restore:
|
|
|
|
/* We've hit an error - don't reset MS_RDONLY */
|
|
|
|
if (sb->s_flags & MS_RDONLY)
|
|
|
|
old_flags |= MS_RDONLY;
|
|
|
|
sb->s_flags = old_flags;
|
|
|
|
fs_info->mount_opt = old_opts;
|
|
|
|
fs_info->compress_type = old_compress_type;
|
|
|
|
fs_info->max_inline = old_max_inline;
|
Btrfs: protect fs_info->alloc_start
fs_info->alloc_start is a 64bits variant, can be accessed by
multi-task, but it is not protected strictly, it can be changed
while we are accessing it. On 32bit machine, we will get wrong
value because we access it by two instructions.(In fact, it is
also possible that the same problem happens on the 64bit machine,
because the compiler may split the 64bit operation into two 32bit
operation.)
For example:
Assuming -> alloc_start is 0x0000 0000 0001 0000 at the beginning,
then we remount and set ->alloc_start to 0x0000 0100 0000 0000.
Task0 Task1
load high 32 bits
set high 32 bits
set low 32 bits
load low 32 bits
Task1 will get 0.
This patch fixes this problem by using two locks to protect it
fs_info->chunk_mutex
sb->s_umount
On the read side, we just need get one of these two locks, and on
the write side, we must lock all of them.
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
2013-01-29 17:07:33 +07:00
|
|
|
mutex_lock(&fs_info->chunk_mutex);
|
2012-03-01 23:24:58 +07:00
|
|
|
fs_info->alloc_start = old_alloc_start;
|
Btrfs: protect fs_info->alloc_start
fs_info->alloc_start is a 64bits variant, can be accessed by
multi-task, but it is not protected strictly, it can be changed
while we are accessing it. On 32bit machine, we will get wrong
value because we access it by two instructions.(In fact, it is
also possible that the same problem happens on the 64bit machine,
because the compiler may split the 64bit operation into two 32bit
operation.)
For example:
Assuming -> alloc_start is 0x0000 0000 0001 0000 at the beginning,
then we remount and set ->alloc_start to 0x0000 0100 0000 0000.
Task0 Task1
load high 32 bits
set high 32 bits
set low 32 bits
load low 32 bits
Task1 will get 0.
This patch fixes this problem by using two locks to protect it
fs_info->chunk_mutex
sb->s_umount
On the read side, we just need get one of these two locks, and on
the write side, we must lock all of them.
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
2013-01-29 17:07:33 +07:00
|
|
|
mutex_unlock(&fs_info->chunk_mutex);
|
2012-04-25 02:59:16 +07:00
|
|
|
btrfs_resize_thread_pool(fs_info,
|
|
|
|
old_thread_pool_size, fs_info->thread_pool_size);
|
2012-03-01 23:24:58 +07:00
|
|
|
fs_info->metadata_ratio = old_metadata_ratio;
|
2013-02-21 13:32:52 +07:00
|
|
|
btrfs_remount_cleanup(fs_info, old_opts);
|
2012-03-01 23:24:58 +07:00
|
|
|
return ret;
|
2008-11-13 02:34:12 +07:00
|
|
|
}
|
|
|
|
|
2011-04-12 15:43:21 +07:00
|
|
|
/* Used to sort the devices by max_avail(descending sort) */
|
|
|
|
static int btrfs_cmp_device_free_bytes(const void *dev_info1,
|
|
|
|
const void *dev_info2)
|
|
|
|
{
|
|
|
|
if (((struct btrfs_device_info *)dev_info1)->max_avail >
|
|
|
|
((struct btrfs_device_info *)dev_info2)->max_avail)
|
|
|
|
return -1;
|
|
|
|
else if (((struct btrfs_device_info *)dev_info1)->max_avail <
|
|
|
|
((struct btrfs_device_info *)dev_info2)->max_avail)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sort the devices by max_avail, in which max free extent size of each device
|
|
|
|
* is stored.(Descending Sort)
|
|
|
|
*/
|
|
|
|
static inline void btrfs_descending_sort_devices(
|
|
|
|
struct btrfs_device_info *devices,
|
|
|
|
size_t nr_devices)
|
|
|
|
{
|
|
|
|
sort(devices, nr_devices, sizeof(struct btrfs_device_info),
|
|
|
|
btrfs_cmp_device_free_bytes, NULL);
|
|
|
|
}
|
|
|
|
|
btrfs: fix wrong free space information of btrfs
When we store data by raid profile in btrfs with two or more different size
disks, df command shows there is some free space in the filesystem, but the
user can not write any data in fact, df command shows the wrong free space
information of btrfs.
# mkfs.btrfs -d raid1 /dev/sda9 /dev/sda10
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 28.00KB
devid 1 size 5.01GB used 2.03GB path /dev/sda9
devid 2 size 10.00GB used 2.01GB path /dev/sda10
# btrfs device scan /dev/sda9 /dev/sda10
# mount /dev/sda9 /mnt
# dd if=/dev/zero of=tmpfile0 bs=4K count=9999999999
(fill the filesystem)
# sync
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 5.4G 62% /mnt
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 3.99GB
devid 1 size 5.01GB used 5.01GB path /dev/sda9
devid 2 size 10.00GB used 4.99GB path /dev/sda10
It is because btrfs cannot allocate chunks when one of the pairing disks has
no space, the free space on the other disks can not be used for ever, and should
be subtracted from the total space, but btrfs doesn't subtract this space from
the total. It is strange to the user.
This patch fixes it by calcing the free space that can be used to allocate
chunks.
Implementation:
1. get all the devices free space, and align them by stripe length.
2. sort the devices by the free space.
3. check the free space of the devices,
3.1. if it is not zero, and then check the number of the devices that has
more free space than this device,
if the number of the devices is beyond the min stripe number, the free
space can be used, and add into total free space.
if the number of the devices is below the min stripe number, we can not
use the free space, the check ends.
3.2. if the free space is zero, check the next devices, goto 3.1
This implementation is just likely fake chunk allocation.
After appling this patch, df can show correct space information:
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 0 100% /mnt
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-01-05 17:07:31 +07:00
|
|
|
/*
|
|
|
|
* The helper to calc the free space on the devices that can be used to store
|
|
|
|
* file data.
|
|
|
|
*/
|
|
|
|
static int btrfs_calc_avail_data_space(struct btrfs_root *root, u64 *free_bytes)
|
|
|
|
{
|
|
|
|
struct btrfs_fs_info *fs_info = root->fs_info;
|
|
|
|
struct btrfs_device_info *devices_info;
|
|
|
|
struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
|
|
|
|
struct btrfs_device *device;
|
|
|
|
u64 skip_space;
|
|
|
|
u64 type;
|
|
|
|
u64 avail_space;
|
|
|
|
u64 used_space;
|
|
|
|
u64 min_stripe_size;
|
2011-12-15 08:12:02 +07:00
|
|
|
int min_stripes = 1, num_stripes = 1;
|
btrfs: fix wrong free space information of btrfs
When we store data by raid profile in btrfs with two or more different size
disks, df command shows there is some free space in the filesystem, but the
user can not write any data in fact, df command shows the wrong free space
information of btrfs.
# mkfs.btrfs -d raid1 /dev/sda9 /dev/sda10
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 28.00KB
devid 1 size 5.01GB used 2.03GB path /dev/sda9
devid 2 size 10.00GB used 2.01GB path /dev/sda10
# btrfs device scan /dev/sda9 /dev/sda10
# mount /dev/sda9 /mnt
# dd if=/dev/zero of=tmpfile0 bs=4K count=9999999999
(fill the filesystem)
# sync
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 5.4G 62% /mnt
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 3.99GB
devid 1 size 5.01GB used 5.01GB path /dev/sda9
devid 2 size 10.00GB used 4.99GB path /dev/sda10
It is because btrfs cannot allocate chunks when one of the pairing disks has
no space, the free space on the other disks can not be used for ever, and should
be subtracted from the total space, but btrfs doesn't subtract this space from
the total. It is strange to the user.
This patch fixes it by calcing the free space that can be used to allocate
chunks.
Implementation:
1. get all the devices free space, and align them by stripe length.
2. sort the devices by the free space.
3. check the free space of the devices,
3.1. if it is not zero, and then check the number of the devices that has
more free space than this device,
if the number of the devices is beyond the min stripe number, the free
space can be used, and add into total free space.
if the number of the devices is below the min stripe number, we can not
use the free space, the check ends.
3.2. if the free space is zero, check the next devices, goto 3.1
This implementation is just likely fake chunk allocation.
After appling this patch, df can show correct space information:
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 0 100% /mnt
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-01-05 17:07:31 +07:00
|
|
|
int i = 0, nr_devices;
|
|
|
|
int ret;
|
|
|
|
|
2014-11-03 20:56:50 +07:00
|
|
|
/*
|
|
|
|
* We aren't under the device list lock, so this is racey-ish, but good
|
|
|
|
* enough for our purposes.
|
|
|
|
*/
|
2011-11-28 15:43:00 +07:00
|
|
|
nr_devices = fs_info->fs_devices->open_devices;
|
2014-11-03 20:56:50 +07:00
|
|
|
if (!nr_devices) {
|
|
|
|
smp_mb();
|
|
|
|
nr_devices = fs_info->fs_devices->open_devices;
|
|
|
|
ASSERT(nr_devices);
|
|
|
|
if (!nr_devices) {
|
|
|
|
*free_bytes = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
btrfs: fix wrong free space information of btrfs
When we store data by raid profile in btrfs with two or more different size
disks, df command shows there is some free space in the filesystem, but the
user can not write any data in fact, df command shows the wrong free space
information of btrfs.
# mkfs.btrfs -d raid1 /dev/sda9 /dev/sda10
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 28.00KB
devid 1 size 5.01GB used 2.03GB path /dev/sda9
devid 2 size 10.00GB used 2.01GB path /dev/sda10
# btrfs device scan /dev/sda9 /dev/sda10
# mount /dev/sda9 /mnt
# dd if=/dev/zero of=tmpfile0 bs=4K count=9999999999
(fill the filesystem)
# sync
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 5.4G 62% /mnt
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 3.99GB
devid 1 size 5.01GB used 5.01GB path /dev/sda9
devid 2 size 10.00GB used 4.99GB path /dev/sda10
It is because btrfs cannot allocate chunks when one of the pairing disks has
no space, the free space on the other disks can not be used for ever, and should
be subtracted from the total space, but btrfs doesn't subtract this space from
the total. It is strange to the user.
This patch fixes it by calcing the free space that can be used to allocate
chunks.
Implementation:
1. get all the devices free space, and align them by stripe length.
2. sort the devices by the free space.
3. check the free space of the devices,
3.1. if it is not zero, and then check the number of the devices that has
more free space than this device,
if the number of the devices is beyond the min stripe number, the free
space can be used, and add into total free space.
if the number of the devices is below the min stripe number, we can not
use the free space, the check ends.
3.2. if the free space is zero, check the next devices, goto 3.1
This implementation is just likely fake chunk allocation.
After appling this patch, df can show correct space information:
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 0 100% /mnt
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-01-05 17:07:31 +07:00
|
|
|
|
2013-10-31 12:02:18 +07:00
|
|
|
devices_info = kmalloc_array(nr_devices, sizeof(*devices_info),
|
btrfs: fix wrong free space information of btrfs
When we store data by raid profile in btrfs with two or more different size
disks, df command shows there is some free space in the filesystem, but the
user can not write any data in fact, df command shows the wrong free space
information of btrfs.
# mkfs.btrfs -d raid1 /dev/sda9 /dev/sda10
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 28.00KB
devid 1 size 5.01GB used 2.03GB path /dev/sda9
devid 2 size 10.00GB used 2.01GB path /dev/sda10
# btrfs device scan /dev/sda9 /dev/sda10
# mount /dev/sda9 /mnt
# dd if=/dev/zero of=tmpfile0 bs=4K count=9999999999
(fill the filesystem)
# sync
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 5.4G 62% /mnt
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 3.99GB
devid 1 size 5.01GB used 5.01GB path /dev/sda9
devid 2 size 10.00GB used 4.99GB path /dev/sda10
It is because btrfs cannot allocate chunks when one of the pairing disks has
no space, the free space on the other disks can not be used for ever, and should
be subtracted from the total space, but btrfs doesn't subtract this space from
the total. It is strange to the user.
This patch fixes it by calcing the free space that can be used to allocate
chunks.
Implementation:
1. get all the devices free space, and align them by stripe length.
2. sort the devices by the free space.
3. check the free space of the devices,
3.1. if it is not zero, and then check the number of the devices that has
more free space than this device,
if the number of the devices is beyond the min stripe number, the free
space can be used, and add into total free space.
if the number of the devices is below the min stripe number, we can not
use the free space, the check ends.
3.2. if the free space is zero, check the next devices, goto 3.1
This implementation is just likely fake chunk allocation.
After appling this patch, df can show correct space information:
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 0 100% /mnt
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-01-05 17:07:31 +07:00
|
|
|
GFP_NOFS);
|
|
|
|
if (!devices_info)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/* calc min stripe number for data space alloction */
|
|
|
|
type = btrfs_get_alloc_profile(root, 1);
|
2011-12-15 08:12:02 +07:00
|
|
|
if (type & BTRFS_BLOCK_GROUP_RAID0) {
|
btrfs: fix wrong free space information of btrfs
When we store data by raid profile in btrfs with two or more different size
disks, df command shows there is some free space in the filesystem, but the
user can not write any data in fact, df command shows the wrong free space
information of btrfs.
# mkfs.btrfs -d raid1 /dev/sda9 /dev/sda10
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 28.00KB
devid 1 size 5.01GB used 2.03GB path /dev/sda9
devid 2 size 10.00GB used 2.01GB path /dev/sda10
# btrfs device scan /dev/sda9 /dev/sda10
# mount /dev/sda9 /mnt
# dd if=/dev/zero of=tmpfile0 bs=4K count=9999999999
(fill the filesystem)
# sync
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 5.4G 62% /mnt
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 3.99GB
devid 1 size 5.01GB used 5.01GB path /dev/sda9
devid 2 size 10.00GB used 4.99GB path /dev/sda10
It is because btrfs cannot allocate chunks when one of the pairing disks has
no space, the free space on the other disks can not be used for ever, and should
be subtracted from the total space, but btrfs doesn't subtract this space from
the total. It is strange to the user.
This patch fixes it by calcing the free space that can be used to allocate
chunks.
Implementation:
1. get all the devices free space, and align them by stripe length.
2. sort the devices by the free space.
3. check the free space of the devices,
3.1. if it is not zero, and then check the number of the devices that has
more free space than this device,
if the number of the devices is beyond the min stripe number, the free
space can be used, and add into total free space.
if the number of the devices is below the min stripe number, we can not
use the free space, the check ends.
3.2. if the free space is zero, check the next devices, goto 3.1
This implementation is just likely fake chunk allocation.
After appling this patch, df can show correct space information:
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 0 100% /mnt
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-01-05 17:07:31 +07:00
|
|
|
min_stripes = 2;
|
2011-12-15 08:12:02 +07:00
|
|
|
num_stripes = nr_devices;
|
|
|
|
} else if (type & BTRFS_BLOCK_GROUP_RAID1) {
|
btrfs: fix wrong free space information of btrfs
When we store data by raid profile in btrfs with two or more different size
disks, df command shows there is some free space in the filesystem, but the
user can not write any data in fact, df command shows the wrong free space
information of btrfs.
# mkfs.btrfs -d raid1 /dev/sda9 /dev/sda10
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 28.00KB
devid 1 size 5.01GB used 2.03GB path /dev/sda9
devid 2 size 10.00GB used 2.01GB path /dev/sda10
# btrfs device scan /dev/sda9 /dev/sda10
# mount /dev/sda9 /mnt
# dd if=/dev/zero of=tmpfile0 bs=4K count=9999999999
(fill the filesystem)
# sync
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 5.4G 62% /mnt
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 3.99GB
devid 1 size 5.01GB used 5.01GB path /dev/sda9
devid 2 size 10.00GB used 4.99GB path /dev/sda10
It is because btrfs cannot allocate chunks when one of the pairing disks has
no space, the free space on the other disks can not be used for ever, and should
be subtracted from the total space, but btrfs doesn't subtract this space from
the total. It is strange to the user.
This patch fixes it by calcing the free space that can be used to allocate
chunks.
Implementation:
1. get all the devices free space, and align them by stripe length.
2. sort the devices by the free space.
3. check the free space of the devices,
3.1. if it is not zero, and then check the number of the devices that has
more free space than this device,
if the number of the devices is beyond the min stripe number, the free
space can be used, and add into total free space.
if the number of the devices is below the min stripe number, we can not
use the free space, the check ends.
3.2. if the free space is zero, check the next devices, goto 3.1
This implementation is just likely fake chunk allocation.
After appling this patch, df can show correct space information:
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 0 100% /mnt
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-01-05 17:07:31 +07:00
|
|
|
min_stripes = 2;
|
2011-12-15 08:12:02 +07:00
|
|
|
num_stripes = 2;
|
|
|
|
} else if (type & BTRFS_BLOCK_GROUP_RAID10) {
|
btrfs: fix wrong free space information of btrfs
When we store data by raid profile in btrfs with two or more different size
disks, df command shows there is some free space in the filesystem, but the
user can not write any data in fact, df command shows the wrong free space
information of btrfs.
# mkfs.btrfs -d raid1 /dev/sda9 /dev/sda10
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 28.00KB
devid 1 size 5.01GB used 2.03GB path /dev/sda9
devid 2 size 10.00GB used 2.01GB path /dev/sda10
# btrfs device scan /dev/sda9 /dev/sda10
# mount /dev/sda9 /mnt
# dd if=/dev/zero of=tmpfile0 bs=4K count=9999999999
(fill the filesystem)
# sync
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 5.4G 62% /mnt
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 3.99GB
devid 1 size 5.01GB used 5.01GB path /dev/sda9
devid 2 size 10.00GB used 4.99GB path /dev/sda10
It is because btrfs cannot allocate chunks when one of the pairing disks has
no space, the free space on the other disks can not be used for ever, and should
be subtracted from the total space, but btrfs doesn't subtract this space from
the total. It is strange to the user.
This patch fixes it by calcing the free space that can be used to allocate
chunks.
Implementation:
1. get all the devices free space, and align them by stripe length.
2. sort the devices by the free space.
3. check the free space of the devices,
3.1. if it is not zero, and then check the number of the devices that has
more free space than this device,
if the number of the devices is beyond the min stripe number, the free
space can be used, and add into total free space.
if the number of the devices is below the min stripe number, we can not
use the free space, the check ends.
3.2. if the free space is zero, check the next devices, goto 3.1
This implementation is just likely fake chunk allocation.
After appling this patch, df can show correct space information:
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 0 100% /mnt
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-01-05 17:07:31 +07:00
|
|
|
min_stripes = 4;
|
2011-12-15 08:12:02 +07:00
|
|
|
num_stripes = 4;
|
|
|
|
}
|
btrfs: fix wrong free space information of btrfs
When we store data by raid profile in btrfs with two or more different size
disks, df command shows there is some free space in the filesystem, but the
user can not write any data in fact, df command shows the wrong free space
information of btrfs.
# mkfs.btrfs -d raid1 /dev/sda9 /dev/sda10
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 28.00KB
devid 1 size 5.01GB used 2.03GB path /dev/sda9
devid 2 size 10.00GB used 2.01GB path /dev/sda10
# btrfs device scan /dev/sda9 /dev/sda10
# mount /dev/sda9 /mnt
# dd if=/dev/zero of=tmpfile0 bs=4K count=9999999999
(fill the filesystem)
# sync
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 5.4G 62% /mnt
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 3.99GB
devid 1 size 5.01GB used 5.01GB path /dev/sda9
devid 2 size 10.00GB used 4.99GB path /dev/sda10
It is because btrfs cannot allocate chunks when one of the pairing disks has
no space, the free space on the other disks can not be used for ever, and should
be subtracted from the total space, but btrfs doesn't subtract this space from
the total. It is strange to the user.
This patch fixes it by calcing the free space that can be used to allocate
chunks.
Implementation:
1. get all the devices free space, and align them by stripe length.
2. sort the devices by the free space.
3. check the free space of the devices,
3.1. if it is not zero, and then check the number of the devices that has
more free space than this device,
if the number of the devices is beyond the min stripe number, the free
space can be used, and add into total free space.
if the number of the devices is below the min stripe number, we can not
use the free space, the check ends.
3.2. if the free space is zero, check the next devices, goto 3.1
This implementation is just likely fake chunk allocation.
After appling this patch, df can show correct space information:
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 0 100% /mnt
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-01-05 17:07:31 +07:00
|
|
|
|
|
|
|
if (type & BTRFS_BLOCK_GROUP_DUP)
|
|
|
|
min_stripe_size = 2 * BTRFS_STRIPE_LEN;
|
|
|
|
else
|
|
|
|
min_stripe_size = BTRFS_STRIPE_LEN;
|
|
|
|
|
2014-11-03 20:56:50 +07:00
|
|
|
if (fs_info->alloc_start)
|
|
|
|
mutex_lock(&fs_devices->device_list_mutex);
|
|
|
|
rcu_read_lock();
|
|
|
|
list_for_each_entry_rcu(device, &fs_devices->devices, dev_list) {
|
2012-11-06 00:29:28 +07:00
|
|
|
if (!device->in_fs_metadata || !device->bdev ||
|
|
|
|
device->is_tgtdev_for_dev_replace)
|
btrfs: fix wrong free space information of btrfs
When we store data by raid profile in btrfs with two or more different size
disks, df command shows there is some free space in the filesystem, but the
user can not write any data in fact, df command shows the wrong free space
information of btrfs.
# mkfs.btrfs -d raid1 /dev/sda9 /dev/sda10
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 28.00KB
devid 1 size 5.01GB used 2.03GB path /dev/sda9
devid 2 size 10.00GB used 2.01GB path /dev/sda10
# btrfs device scan /dev/sda9 /dev/sda10
# mount /dev/sda9 /mnt
# dd if=/dev/zero of=tmpfile0 bs=4K count=9999999999
(fill the filesystem)
# sync
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 5.4G 62% /mnt
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 3.99GB
devid 1 size 5.01GB used 5.01GB path /dev/sda9
devid 2 size 10.00GB used 4.99GB path /dev/sda10
It is because btrfs cannot allocate chunks when one of the pairing disks has
no space, the free space on the other disks can not be used for ever, and should
be subtracted from the total space, but btrfs doesn't subtract this space from
the total. It is strange to the user.
This patch fixes it by calcing the free space that can be used to allocate
chunks.
Implementation:
1. get all the devices free space, and align them by stripe length.
2. sort the devices by the free space.
3. check the free space of the devices,
3.1. if it is not zero, and then check the number of the devices that has
more free space than this device,
if the number of the devices is beyond the min stripe number, the free
space can be used, and add into total free space.
if the number of the devices is below the min stripe number, we can not
use the free space, the check ends.
3.2. if the free space is zero, check the next devices, goto 3.1
This implementation is just likely fake chunk allocation.
After appling this patch, df can show correct space information:
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 0 100% /mnt
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-01-05 17:07:31 +07:00
|
|
|
continue;
|
|
|
|
|
2014-11-03 20:56:50 +07:00
|
|
|
if (i >= nr_devices)
|
|
|
|
break;
|
|
|
|
|
btrfs: fix wrong free space information of btrfs
When we store data by raid profile in btrfs with two or more different size
disks, df command shows there is some free space in the filesystem, but the
user can not write any data in fact, df command shows the wrong free space
information of btrfs.
# mkfs.btrfs -d raid1 /dev/sda9 /dev/sda10
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 28.00KB
devid 1 size 5.01GB used 2.03GB path /dev/sda9
devid 2 size 10.00GB used 2.01GB path /dev/sda10
# btrfs device scan /dev/sda9 /dev/sda10
# mount /dev/sda9 /mnt
# dd if=/dev/zero of=tmpfile0 bs=4K count=9999999999
(fill the filesystem)
# sync
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 5.4G 62% /mnt
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 3.99GB
devid 1 size 5.01GB used 5.01GB path /dev/sda9
devid 2 size 10.00GB used 4.99GB path /dev/sda10
It is because btrfs cannot allocate chunks when one of the pairing disks has
no space, the free space on the other disks can not be used for ever, and should
be subtracted from the total space, but btrfs doesn't subtract this space from
the total. It is strange to the user.
This patch fixes it by calcing the free space that can be used to allocate
chunks.
Implementation:
1. get all the devices free space, and align them by stripe length.
2. sort the devices by the free space.
3. check the free space of the devices,
3.1. if it is not zero, and then check the number of the devices that has
more free space than this device,
if the number of the devices is beyond the min stripe number, the free
space can be used, and add into total free space.
if the number of the devices is below the min stripe number, we can not
use the free space, the check ends.
3.2. if the free space is zero, check the next devices, goto 3.1
This implementation is just likely fake chunk allocation.
After appling this patch, df can show correct space information:
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 0 100% /mnt
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-01-05 17:07:31 +07:00
|
|
|
avail_space = device->total_bytes - device->bytes_used;
|
|
|
|
|
|
|
|
/* align with stripe_len */
|
|
|
|
do_div(avail_space, BTRFS_STRIPE_LEN);
|
|
|
|
avail_space *= BTRFS_STRIPE_LEN;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In order to avoid overwritting the superblock on the drive,
|
|
|
|
* btrfs starts at an offset of at least 1MB when doing chunk
|
|
|
|
* allocation.
|
|
|
|
*/
|
|
|
|
skip_space = 1024 * 1024;
|
|
|
|
|
|
|
|
/* user can set the offset in fs_info->alloc_start. */
|
2014-11-03 20:56:50 +07:00
|
|
|
if (fs_info->alloc_start &&
|
|
|
|
fs_info->alloc_start + BTRFS_STRIPE_LEN <=
|
|
|
|
device->total_bytes) {
|
|
|
|
rcu_read_unlock();
|
btrfs: fix wrong free space information of btrfs
When we store data by raid profile in btrfs with two or more different size
disks, df command shows there is some free space in the filesystem, but the
user can not write any data in fact, df command shows the wrong free space
information of btrfs.
# mkfs.btrfs -d raid1 /dev/sda9 /dev/sda10
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 28.00KB
devid 1 size 5.01GB used 2.03GB path /dev/sda9
devid 2 size 10.00GB used 2.01GB path /dev/sda10
# btrfs device scan /dev/sda9 /dev/sda10
# mount /dev/sda9 /mnt
# dd if=/dev/zero of=tmpfile0 bs=4K count=9999999999
(fill the filesystem)
# sync
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 5.4G 62% /mnt
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 3.99GB
devid 1 size 5.01GB used 5.01GB path /dev/sda9
devid 2 size 10.00GB used 4.99GB path /dev/sda10
It is because btrfs cannot allocate chunks when one of the pairing disks has
no space, the free space on the other disks can not be used for ever, and should
be subtracted from the total space, but btrfs doesn't subtract this space from
the total. It is strange to the user.
This patch fixes it by calcing the free space that can be used to allocate
chunks.
Implementation:
1. get all the devices free space, and align them by stripe length.
2. sort the devices by the free space.
3. check the free space of the devices,
3.1. if it is not zero, and then check the number of the devices that has
more free space than this device,
if the number of the devices is beyond the min stripe number, the free
space can be used, and add into total free space.
if the number of the devices is below the min stripe number, we can not
use the free space, the check ends.
3.2. if the free space is zero, check the next devices, goto 3.1
This implementation is just likely fake chunk allocation.
After appling this patch, df can show correct space information:
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 0 100% /mnt
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-01-05 17:07:31 +07:00
|
|
|
skip_space = max(fs_info->alloc_start, skip_space);
|
|
|
|
|
2014-11-03 20:56:50 +07:00
|
|
|
/*
|
|
|
|
* btrfs can not use the free space in
|
|
|
|
* [0, skip_space - 1], we must subtract it from the
|
|
|
|
* total. In order to implement it, we account the used
|
|
|
|
* space in this range first.
|
|
|
|
*/
|
|
|
|
ret = btrfs_account_dev_extents_size(device, 0,
|
|
|
|
skip_space - 1,
|
|
|
|
&used_space);
|
|
|
|
if (ret) {
|
|
|
|
kfree(devices_info);
|
|
|
|
mutex_unlock(&fs_devices->device_list_mutex);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
rcu_read_lock();
|
btrfs: fix wrong free space information of btrfs
When we store data by raid profile in btrfs with two or more different size
disks, df command shows there is some free space in the filesystem, but the
user can not write any data in fact, df command shows the wrong free space
information of btrfs.
# mkfs.btrfs -d raid1 /dev/sda9 /dev/sda10
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 28.00KB
devid 1 size 5.01GB used 2.03GB path /dev/sda9
devid 2 size 10.00GB used 2.01GB path /dev/sda10
# btrfs device scan /dev/sda9 /dev/sda10
# mount /dev/sda9 /mnt
# dd if=/dev/zero of=tmpfile0 bs=4K count=9999999999
(fill the filesystem)
# sync
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 5.4G 62% /mnt
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 3.99GB
devid 1 size 5.01GB used 5.01GB path /dev/sda9
devid 2 size 10.00GB used 4.99GB path /dev/sda10
It is because btrfs cannot allocate chunks when one of the pairing disks has
no space, the free space on the other disks can not be used for ever, and should
be subtracted from the total space, but btrfs doesn't subtract this space from
the total. It is strange to the user.
This patch fixes it by calcing the free space that can be used to allocate
chunks.
Implementation:
1. get all the devices free space, and align them by stripe length.
2. sort the devices by the free space.
3. check the free space of the devices,
3.1. if it is not zero, and then check the number of the devices that has
more free space than this device,
if the number of the devices is beyond the min stripe number, the free
space can be used, and add into total free space.
if the number of the devices is below the min stripe number, we can not
use the free space, the check ends.
3.2. if the free space is zero, check the next devices, goto 3.1
This implementation is just likely fake chunk allocation.
After appling this patch, df can show correct space information:
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 0 100% /mnt
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-01-05 17:07:31 +07:00
|
|
|
|
2014-11-03 20:56:50 +07:00
|
|
|
/* calc the free space in [0, skip_space - 1] */
|
|
|
|
skip_space -= used_space;
|
|
|
|
}
|
btrfs: fix wrong free space information of btrfs
When we store data by raid profile in btrfs with two or more different size
disks, df command shows there is some free space in the filesystem, but the
user can not write any data in fact, df command shows the wrong free space
information of btrfs.
# mkfs.btrfs -d raid1 /dev/sda9 /dev/sda10
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 28.00KB
devid 1 size 5.01GB used 2.03GB path /dev/sda9
devid 2 size 10.00GB used 2.01GB path /dev/sda10
# btrfs device scan /dev/sda9 /dev/sda10
# mount /dev/sda9 /mnt
# dd if=/dev/zero of=tmpfile0 bs=4K count=9999999999
(fill the filesystem)
# sync
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 5.4G 62% /mnt
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 3.99GB
devid 1 size 5.01GB used 5.01GB path /dev/sda9
devid 2 size 10.00GB used 4.99GB path /dev/sda10
It is because btrfs cannot allocate chunks when one of the pairing disks has
no space, the free space on the other disks can not be used for ever, and should
be subtracted from the total space, but btrfs doesn't subtract this space from
the total. It is strange to the user.
This patch fixes it by calcing the free space that can be used to allocate
chunks.
Implementation:
1. get all the devices free space, and align them by stripe length.
2. sort the devices by the free space.
3. check the free space of the devices,
3.1. if it is not zero, and then check the number of the devices that has
more free space than this device,
if the number of the devices is beyond the min stripe number, the free
space can be used, and add into total free space.
if the number of the devices is below the min stripe number, we can not
use the free space, the check ends.
3.2. if the free space is zero, check the next devices, goto 3.1
This implementation is just likely fake chunk allocation.
After appling this patch, df can show correct space information:
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 0 100% /mnt
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-01-05 17:07:31 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* we can use the free space in [0, skip_space - 1], subtract
|
|
|
|
* it from the total.
|
|
|
|
*/
|
|
|
|
if (avail_space && avail_space >= skip_space)
|
|
|
|
avail_space -= skip_space;
|
|
|
|
else
|
|
|
|
avail_space = 0;
|
|
|
|
|
|
|
|
if (avail_space < min_stripe_size)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
devices_info[i].dev = device;
|
|
|
|
devices_info[i].max_avail = avail_space;
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
2014-11-03 20:56:50 +07:00
|
|
|
rcu_read_unlock();
|
|
|
|
if (fs_info->alloc_start)
|
|
|
|
mutex_unlock(&fs_devices->device_list_mutex);
|
btrfs: fix wrong free space information of btrfs
When we store data by raid profile in btrfs with two or more different size
disks, df command shows there is some free space in the filesystem, but the
user can not write any data in fact, df command shows the wrong free space
information of btrfs.
# mkfs.btrfs -d raid1 /dev/sda9 /dev/sda10
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 28.00KB
devid 1 size 5.01GB used 2.03GB path /dev/sda9
devid 2 size 10.00GB used 2.01GB path /dev/sda10
# btrfs device scan /dev/sda9 /dev/sda10
# mount /dev/sda9 /mnt
# dd if=/dev/zero of=tmpfile0 bs=4K count=9999999999
(fill the filesystem)
# sync
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 5.4G 62% /mnt
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 3.99GB
devid 1 size 5.01GB used 5.01GB path /dev/sda9
devid 2 size 10.00GB used 4.99GB path /dev/sda10
It is because btrfs cannot allocate chunks when one of the pairing disks has
no space, the free space on the other disks can not be used for ever, and should
be subtracted from the total space, but btrfs doesn't subtract this space from
the total. It is strange to the user.
This patch fixes it by calcing the free space that can be used to allocate
chunks.
Implementation:
1. get all the devices free space, and align them by stripe length.
2. sort the devices by the free space.
3. check the free space of the devices,
3.1. if it is not zero, and then check the number of the devices that has
more free space than this device,
if the number of the devices is beyond the min stripe number, the free
space can be used, and add into total free space.
if the number of the devices is below the min stripe number, we can not
use the free space, the check ends.
3.2. if the free space is zero, check the next devices, goto 3.1
This implementation is just likely fake chunk allocation.
After appling this patch, df can show correct space information:
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 0 100% /mnt
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-01-05 17:07:31 +07:00
|
|
|
|
|
|
|
nr_devices = i;
|
|
|
|
|
|
|
|
btrfs_descending_sort_devices(devices_info, nr_devices);
|
|
|
|
|
|
|
|
i = nr_devices - 1;
|
|
|
|
avail_space = 0;
|
|
|
|
while (nr_devices >= min_stripes) {
|
2011-12-15 08:12:02 +07:00
|
|
|
if (num_stripes > nr_devices)
|
|
|
|
num_stripes = nr_devices;
|
|
|
|
|
btrfs: fix wrong free space information of btrfs
When we store data by raid profile in btrfs with two or more different size
disks, df command shows there is some free space in the filesystem, but the
user can not write any data in fact, df command shows the wrong free space
information of btrfs.
# mkfs.btrfs -d raid1 /dev/sda9 /dev/sda10
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 28.00KB
devid 1 size 5.01GB used 2.03GB path /dev/sda9
devid 2 size 10.00GB used 2.01GB path /dev/sda10
# btrfs device scan /dev/sda9 /dev/sda10
# mount /dev/sda9 /mnt
# dd if=/dev/zero of=tmpfile0 bs=4K count=9999999999
(fill the filesystem)
# sync
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 5.4G 62% /mnt
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 3.99GB
devid 1 size 5.01GB used 5.01GB path /dev/sda9
devid 2 size 10.00GB used 4.99GB path /dev/sda10
It is because btrfs cannot allocate chunks when one of the pairing disks has
no space, the free space on the other disks can not be used for ever, and should
be subtracted from the total space, but btrfs doesn't subtract this space from
the total. It is strange to the user.
This patch fixes it by calcing the free space that can be used to allocate
chunks.
Implementation:
1. get all the devices free space, and align them by stripe length.
2. sort the devices by the free space.
3. check the free space of the devices,
3.1. if it is not zero, and then check the number of the devices that has
more free space than this device,
if the number of the devices is beyond the min stripe number, the free
space can be used, and add into total free space.
if the number of the devices is below the min stripe number, we can not
use the free space, the check ends.
3.2. if the free space is zero, check the next devices, goto 3.1
This implementation is just likely fake chunk allocation.
After appling this patch, df can show correct space information:
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 0 100% /mnt
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-01-05 17:07:31 +07:00
|
|
|
if (devices_info[i].max_avail >= min_stripe_size) {
|
|
|
|
int j;
|
|
|
|
u64 alloc_size;
|
|
|
|
|
2011-12-15 08:12:02 +07:00
|
|
|
avail_space += devices_info[i].max_avail * num_stripes;
|
btrfs: fix wrong free space information of btrfs
When we store data by raid profile in btrfs with two or more different size
disks, df command shows there is some free space in the filesystem, but the
user can not write any data in fact, df command shows the wrong free space
information of btrfs.
# mkfs.btrfs -d raid1 /dev/sda9 /dev/sda10
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 28.00KB
devid 1 size 5.01GB used 2.03GB path /dev/sda9
devid 2 size 10.00GB used 2.01GB path /dev/sda10
# btrfs device scan /dev/sda9 /dev/sda10
# mount /dev/sda9 /mnt
# dd if=/dev/zero of=tmpfile0 bs=4K count=9999999999
(fill the filesystem)
# sync
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 5.4G 62% /mnt
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 3.99GB
devid 1 size 5.01GB used 5.01GB path /dev/sda9
devid 2 size 10.00GB used 4.99GB path /dev/sda10
It is because btrfs cannot allocate chunks when one of the pairing disks has
no space, the free space on the other disks can not be used for ever, and should
be subtracted from the total space, but btrfs doesn't subtract this space from
the total. It is strange to the user.
This patch fixes it by calcing the free space that can be used to allocate
chunks.
Implementation:
1. get all the devices free space, and align them by stripe length.
2. sort the devices by the free space.
3. check the free space of the devices,
3.1. if it is not zero, and then check the number of the devices that has
more free space than this device,
if the number of the devices is beyond the min stripe number, the free
space can be used, and add into total free space.
if the number of the devices is below the min stripe number, we can not
use the free space, the check ends.
3.2. if the free space is zero, check the next devices, goto 3.1
This implementation is just likely fake chunk allocation.
After appling this patch, df can show correct space information:
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 0 100% /mnt
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-01-05 17:07:31 +07:00
|
|
|
alloc_size = devices_info[i].max_avail;
|
2011-12-15 08:12:02 +07:00
|
|
|
for (j = i + 1 - num_stripes; j <= i; j++)
|
btrfs: fix wrong free space information of btrfs
When we store data by raid profile in btrfs with two or more different size
disks, df command shows there is some free space in the filesystem, but the
user can not write any data in fact, df command shows the wrong free space
information of btrfs.
# mkfs.btrfs -d raid1 /dev/sda9 /dev/sda10
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 28.00KB
devid 1 size 5.01GB used 2.03GB path /dev/sda9
devid 2 size 10.00GB used 2.01GB path /dev/sda10
# btrfs device scan /dev/sda9 /dev/sda10
# mount /dev/sda9 /mnt
# dd if=/dev/zero of=tmpfile0 bs=4K count=9999999999
(fill the filesystem)
# sync
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 5.4G 62% /mnt
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 3.99GB
devid 1 size 5.01GB used 5.01GB path /dev/sda9
devid 2 size 10.00GB used 4.99GB path /dev/sda10
It is because btrfs cannot allocate chunks when one of the pairing disks has
no space, the free space on the other disks can not be used for ever, and should
be subtracted from the total space, but btrfs doesn't subtract this space from
the total. It is strange to the user.
This patch fixes it by calcing the free space that can be used to allocate
chunks.
Implementation:
1. get all the devices free space, and align them by stripe length.
2. sort the devices by the free space.
3. check the free space of the devices,
3.1. if it is not zero, and then check the number of the devices that has
more free space than this device,
if the number of the devices is beyond the min stripe number, the free
space can be used, and add into total free space.
if the number of the devices is below the min stripe number, we can not
use the free space, the check ends.
3.2. if the free space is zero, check the next devices, goto 3.1
This implementation is just likely fake chunk allocation.
After appling this patch, df can show correct space information:
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 0 100% /mnt
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-01-05 17:07:31 +07:00
|
|
|
devices_info[j].max_avail -= alloc_size;
|
|
|
|
}
|
|
|
|
i--;
|
|
|
|
nr_devices--;
|
|
|
|
}
|
|
|
|
|
|
|
|
kfree(devices_info);
|
|
|
|
*free_bytes = avail_space;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-01 21:21:33 +07:00
|
|
|
/*
|
|
|
|
* Calculate numbers for 'df', pessimistic in case of mixed raid profiles.
|
|
|
|
*
|
|
|
|
* If there's a redundant raid level at DATA block groups, use the respective
|
|
|
|
* multiplier to scale the sizes.
|
|
|
|
*
|
|
|
|
* Unused device space usage is based on simulating the chunk allocator
|
|
|
|
* algorithm that respects the device sizes, order of allocations and the
|
|
|
|
* 'alloc_start' value, this is a close approximation of the actual use but
|
|
|
|
* there are other factors that may change the result (like a new metadata
|
|
|
|
* chunk).
|
|
|
|
*
|
|
|
|
* FIXME: not accurate for mixed block groups, total and free/used are ok,
|
|
|
|
* available appears slightly larger.
|
|
|
|
*/
|
2007-04-20 08:01:03 +07:00
|
|
|
static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf)
|
|
|
|
{
|
2011-11-18 03:40:49 +07:00
|
|
|
struct btrfs_fs_info *fs_info = btrfs_sb(dentry->d_sb);
|
|
|
|
struct btrfs_super_block *disk_super = fs_info->super_copy;
|
|
|
|
struct list_head *head = &fs_info->space_info;
|
Btrfs: make df be a little bit more understandable
The way we report df usage is way confusing for everybody, including some other
utilities (bacula for one). So this patch makes df a little bit more
understandable. First we make used actually count the total amount of used
space in all space info's. This will give us a real view of how much disk space
is in use. Second, for blocks available, only count data space. This makes
things like bacula work because it says 0 when you can no longer write anymore
data to the disk. I think this is a nice compromise, since you will end up with
something like the following
[root@alpha ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
148G 30G 111G 21% /
/dev/sda1 194M 116M 68M 64% /boot
tmpfs 985M 12K 985M 1% /dev/shm
/dev/mapper/VolGroup-LogVol02
145G 140G 0 100% /mnt/btrfs-test
Compare this with btrfsctl -i output
[root@alpha btrfs-progs-unstable]# ./btrfsctl -i /mnt/btrfs-test/
Metadata, DUP: total=4.62GB, used=2.46GB
System, DUP: total=8.00MB, used=24.00KB
Data: total=134.80GB, used=134.80GB
Metadata: total=8.00MB, used=0.00
System: total=4.00MB, used=0.00
operation complete
This way we show that there is no more data space to be used, but we have
another 5GB of space left for metadata. Thanks,
Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2010-03-06 04:59:21 +07:00
|
|
|
struct btrfs_space_info *found;
|
|
|
|
u64 total_used = 0;
|
btrfs: fix wrong free space information of btrfs
When we store data by raid profile in btrfs with two or more different size
disks, df command shows there is some free space in the filesystem, but the
user can not write any data in fact, df command shows the wrong free space
information of btrfs.
# mkfs.btrfs -d raid1 /dev/sda9 /dev/sda10
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 28.00KB
devid 1 size 5.01GB used 2.03GB path /dev/sda9
devid 2 size 10.00GB used 2.01GB path /dev/sda10
# btrfs device scan /dev/sda9 /dev/sda10
# mount /dev/sda9 /mnt
# dd if=/dev/zero of=tmpfile0 bs=4K count=9999999999
(fill the filesystem)
# sync
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 5.4G 62% /mnt
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 3.99GB
devid 1 size 5.01GB used 5.01GB path /dev/sda9
devid 2 size 10.00GB used 4.99GB path /dev/sda10
It is because btrfs cannot allocate chunks when one of the pairing disks has
no space, the free space on the other disks can not be used for ever, and should
be subtracted from the total space, but btrfs doesn't subtract this space from
the total. It is strange to the user.
This patch fixes it by calcing the free space that can be used to allocate
chunks.
Implementation:
1. get all the devices free space, and align them by stripe length.
2. sort the devices by the free space.
3. check the free space of the devices,
3.1. if it is not zero, and then check the number of the devices that has
more free space than this device,
if the number of the devices is beyond the min stripe number, the free
space can be used, and add into total free space.
if the number of the devices is below the min stripe number, we can not
use the free space, the check ends.
3.2. if the free space is zero, check the next devices, goto 3.1
This implementation is just likely fake chunk allocation.
After appling this patch, df can show correct space information:
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 0 100% /mnt
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-01-05 17:07:31 +07:00
|
|
|
u64 total_free_data = 0;
|
2007-10-16 03:15:53 +07:00
|
|
|
int bits = dentry->d_sb->s_blocksize_bits;
|
2011-11-18 03:40:49 +07:00
|
|
|
__be32 *fsid = (__be32 *)fs_info->fsid;
|
2014-07-01 21:21:33 +07:00
|
|
|
unsigned factor = 1;
|
|
|
|
struct btrfs_block_rsv *block_rsv = &fs_info->global_block_rsv;
|
btrfs: fix wrong free space information of btrfs
When we store data by raid profile in btrfs with two or more different size
disks, df command shows there is some free space in the filesystem, but the
user can not write any data in fact, df command shows the wrong free space
information of btrfs.
# mkfs.btrfs -d raid1 /dev/sda9 /dev/sda10
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 28.00KB
devid 1 size 5.01GB used 2.03GB path /dev/sda9
devid 2 size 10.00GB used 2.01GB path /dev/sda10
# btrfs device scan /dev/sda9 /dev/sda10
# mount /dev/sda9 /mnt
# dd if=/dev/zero of=tmpfile0 bs=4K count=9999999999
(fill the filesystem)
# sync
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 5.4G 62% /mnt
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 3.99GB
devid 1 size 5.01GB used 5.01GB path /dev/sda9
devid 2 size 10.00GB used 4.99GB path /dev/sda10
It is because btrfs cannot allocate chunks when one of the pairing disks has
no space, the free space on the other disks can not be used for ever, and should
be subtracted from the total space, but btrfs doesn't subtract this space from
the total. It is strange to the user.
This patch fixes it by calcing the free space that can be used to allocate
chunks.
Implementation:
1. get all the devices free space, and align them by stripe length.
2. sort the devices by the free space.
3. check the free space of the devices,
3.1. if it is not zero, and then check the number of the devices that has
more free space than this device,
if the number of the devices is beyond the min stripe number, the free
space can be used, and add into total free space.
if the number of the devices is below the min stripe number, we can not
use the free space, the check ends.
3.2. if the free space is zero, check the next devices, goto 3.1
This implementation is just likely fake chunk allocation.
After appling this patch, df can show correct space information:
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 0 100% /mnt
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-01-05 17:07:31 +07:00
|
|
|
int ret;
|
2007-04-20 08:01:03 +07:00
|
|
|
|
2014-09-03 20:35:40 +07:00
|
|
|
/*
|
|
|
|
* holding chunk_muext to avoid allocating new chunks, holding
|
|
|
|
* device_list_mutex to avoid the device being removed
|
|
|
|
*/
|
Btrfs: make df be a little bit more understandable
The way we report df usage is way confusing for everybody, including some other
utilities (bacula for one). So this patch makes df a little bit more
understandable. First we make used actually count the total amount of used
space in all space info's. This will give us a real view of how much disk space
is in use. Second, for blocks available, only count data space. This makes
things like bacula work because it says 0 when you can no longer write anymore
data to the disk. I think this is a nice compromise, since you will end up with
something like the following
[root@alpha ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
148G 30G 111G 21% /
/dev/sda1 194M 116M 68M 64% /boot
tmpfs 985M 12K 985M 1% /dev/shm
/dev/mapper/VolGroup-LogVol02
145G 140G 0 100% /mnt/btrfs-test
Compare this with btrfsctl -i output
[root@alpha btrfs-progs-unstable]# ./btrfsctl -i /mnt/btrfs-test/
Metadata, DUP: total=4.62GB, used=2.46GB
System, DUP: total=8.00MB, used=24.00KB
Data: total=134.80GB, used=134.80GB
Metadata: total=8.00MB, used=0.00
System: total=4.00MB, used=0.00
operation complete
This way we show that there is no more data space to be used, but we have
another 5GB of space left for metadata. Thanks,
Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2010-03-06 04:59:21 +07:00
|
|
|
rcu_read_lock();
|
2010-10-15 01:52:27 +07:00
|
|
|
list_for_each_entry_rcu(found, head, list) {
|
btrfs: fix wrong free space information of btrfs
When we store data by raid profile in btrfs with two or more different size
disks, df command shows there is some free space in the filesystem, but the
user can not write any data in fact, df command shows the wrong free space
information of btrfs.
# mkfs.btrfs -d raid1 /dev/sda9 /dev/sda10
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 28.00KB
devid 1 size 5.01GB used 2.03GB path /dev/sda9
devid 2 size 10.00GB used 2.01GB path /dev/sda10
# btrfs device scan /dev/sda9 /dev/sda10
# mount /dev/sda9 /mnt
# dd if=/dev/zero of=tmpfile0 bs=4K count=9999999999
(fill the filesystem)
# sync
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 5.4G 62% /mnt
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 3.99GB
devid 1 size 5.01GB used 5.01GB path /dev/sda9
devid 2 size 10.00GB used 4.99GB path /dev/sda10
It is because btrfs cannot allocate chunks when one of the pairing disks has
no space, the free space on the other disks can not be used for ever, and should
be subtracted from the total space, but btrfs doesn't subtract this space from
the total. It is strange to the user.
This patch fixes it by calcing the free space that can be used to allocate
chunks.
Implementation:
1. get all the devices free space, and align them by stripe length.
2. sort the devices by the free space.
3. check the free space of the devices,
3.1. if it is not zero, and then check the number of the devices that has
more free space than this device,
if the number of the devices is beyond the min stripe number, the free
space can be used, and add into total free space.
if the number of the devices is below the min stripe number, we can not
use the free space, the check ends.
3.2. if the free space is zero, check the next devices, goto 3.1
This implementation is just likely fake chunk allocation.
After appling this patch, df can show correct space information:
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 0 100% /mnt
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-01-05 17:07:31 +07:00
|
|
|
if (found->flags & BTRFS_BLOCK_GROUP_DATA) {
|
2014-07-01 21:21:33 +07:00
|
|
|
int i;
|
|
|
|
|
btrfs: fix wrong free space information of btrfs
When we store data by raid profile in btrfs with two or more different size
disks, df command shows there is some free space in the filesystem, but the
user can not write any data in fact, df command shows the wrong free space
information of btrfs.
# mkfs.btrfs -d raid1 /dev/sda9 /dev/sda10
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 28.00KB
devid 1 size 5.01GB used 2.03GB path /dev/sda9
devid 2 size 10.00GB used 2.01GB path /dev/sda10
# btrfs device scan /dev/sda9 /dev/sda10
# mount /dev/sda9 /mnt
# dd if=/dev/zero of=tmpfile0 bs=4K count=9999999999
(fill the filesystem)
# sync
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 5.4G 62% /mnt
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 3.99GB
devid 1 size 5.01GB used 5.01GB path /dev/sda9
devid 2 size 10.00GB used 4.99GB path /dev/sda10
It is because btrfs cannot allocate chunks when one of the pairing disks has
no space, the free space on the other disks can not be used for ever, and should
be subtracted from the total space, but btrfs doesn't subtract this space from
the total. It is strange to the user.
This patch fixes it by calcing the free space that can be used to allocate
chunks.
Implementation:
1. get all the devices free space, and align them by stripe length.
2. sort the devices by the free space.
3. check the free space of the devices,
3.1. if it is not zero, and then check the number of the devices that has
more free space than this device,
if the number of the devices is beyond the min stripe number, the free
space can be used, and add into total free space.
if the number of the devices is below the min stripe number, we can not
use the free space, the check ends.
3.2. if the free space is zero, check the next devices, goto 3.1
This implementation is just likely fake chunk allocation.
After appling this patch, df can show correct space information:
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 0 100% /mnt
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-01-05 17:07:31 +07:00
|
|
|
total_free_data += found->disk_total - found->disk_used;
|
|
|
|
total_free_data -=
|
|
|
|
btrfs_account_ro_block_groups_free_space(found);
|
2014-07-01 21:21:33 +07:00
|
|
|
|
|
|
|
for (i = 0; i < BTRFS_NR_RAID_TYPES; i++) {
|
|
|
|
if (!list_empty(&found->block_groups[i])) {
|
|
|
|
switch (i) {
|
|
|
|
case BTRFS_RAID_DUP:
|
|
|
|
case BTRFS_RAID_RAID1:
|
|
|
|
case BTRFS_RAID_RAID10:
|
|
|
|
factor = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
btrfs: fix wrong free space information of btrfs
When we store data by raid profile in btrfs with two or more different size
disks, df command shows there is some free space in the filesystem, but the
user can not write any data in fact, df command shows the wrong free space
information of btrfs.
# mkfs.btrfs -d raid1 /dev/sda9 /dev/sda10
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 28.00KB
devid 1 size 5.01GB used 2.03GB path /dev/sda9
devid 2 size 10.00GB used 2.01GB path /dev/sda10
# btrfs device scan /dev/sda9 /dev/sda10
# mount /dev/sda9 /mnt
# dd if=/dev/zero of=tmpfile0 bs=4K count=9999999999
(fill the filesystem)
# sync
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 5.4G 62% /mnt
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 3.99GB
devid 1 size 5.01GB used 5.01GB path /dev/sda9
devid 2 size 10.00GB used 4.99GB path /dev/sda10
It is because btrfs cannot allocate chunks when one of the pairing disks has
no space, the free space on the other disks can not be used for ever, and should
be subtracted from the total space, but btrfs doesn't subtract this space from
the total. It is strange to the user.
This patch fixes it by calcing the free space that can be used to allocate
chunks.
Implementation:
1. get all the devices free space, and align them by stripe length.
2. sort the devices by the free space.
3. check the free space of the devices,
3.1. if it is not zero, and then check the number of the devices that has
more free space than this device,
if the number of the devices is beyond the min stripe number, the free
space can be used, and add into total free space.
if the number of the devices is below the min stripe number, we can not
use the free space, the check ends.
3.2. if the free space is zero, check the next devices, goto 3.1
This implementation is just likely fake chunk allocation.
After appling this patch, df can show correct space information:
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 0 100% /mnt
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-01-05 17:07:31 +07:00
|
|
|
}
|
|
|
|
|
2010-05-16 21:46:24 +07:00
|
|
|
total_used += found->disk_used;
|
2010-10-15 01:52:27 +07:00
|
|
|
}
|
2014-07-01 21:21:33 +07:00
|
|
|
|
Btrfs: make df be a little bit more understandable
The way we report df usage is way confusing for everybody, including some other
utilities (bacula for one). So this patch makes df a little bit more
understandable. First we make used actually count the total amount of used
space in all space info's. This will give us a real view of how much disk space
is in use. Second, for blocks available, only count data space. This makes
things like bacula work because it says 0 when you can no longer write anymore
data to the disk. I think this is a nice compromise, since you will end up with
something like the following
[root@alpha ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
148G 30G 111G 21% /
/dev/sda1 194M 116M 68M 64% /boot
tmpfs 985M 12K 985M 1% /dev/shm
/dev/mapper/VolGroup-LogVol02
145G 140G 0 100% /mnt/btrfs-test
Compare this with btrfsctl -i output
[root@alpha btrfs-progs-unstable]# ./btrfsctl -i /mnt/btrfs-test/
Metadata, DUP: total=4.62GB, used=2.46GB
System, DUP: total=8.00MB, used=24.00KB
Data: total=134.80GB, used=134.80GB
Metadata: total=8.00MB, used=0.00
System: total=4.00MB, used=0.00
operation complete
This way we show that there is no more data space to be used, but we have
another 5GB of space left for metadata. Thanks,
Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2010-03-06 04:59:21 +07:00
|
|
|
rcu_read_unlock();
|
|
|
|
|
2014-07-01 21:21:33 +07:00
|
|
|
buf->f_blocks = div_u64(btrfs_super_total_bytes(disk_super), factor);
|
|
|
|
buf->f_blocks >>= bits;
|
|
|
|
buf->f_bfree = buf->f_blocks - (div_u64(total_used, factor) >> bits);
|
|
|
|
|
|
|
|
/* Account global block reserve as used, it's in logical size already */
|
|
|
|
spin_lock(&block_rsv->lock);
|
|
|
|
buf->f_bfree -= block_rsv->size >> bits;
|
|
|
|
spin_unlock(&block_rsv->lock);
|
|
|
|
|
btrfs: fix wrong free space information of btrfs
When we store data by raid profile in btrfs with two or more different size
disks, df command shows there is some free space in the filesystem, but the
user can not write any data in fact, df command shows the wrong free space
information of btrfs.
# mkfs.btrfs -d raid1 /dev/sda9 /dev/sda10
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 28.00KB
devid 1 size 5.01GB used 2.03GB path /dev/sda9
devid 2 size 10.00GB used 2.01GB path /dev/sda10
# btrfs device scan /dev/sda9 /dev/sda10
# mount /dev/sda9 /mnt
# dd if=/dev/zero of=tmpfile0 bs=4K count=9999999999
(fill the filesystem)
# sync
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 5.4G 62% /mnt
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 3.99GB
devid 1 size 5.01GB used 5.01GB path /dev/sda9
devid 2 size 10.00GB used 4.99GB path /dev/sda10
It is because btrfs cannot allocate chunks when one of the pairing disks has
no space, the free space on the other disks can not be used for ever, and should
be subtracted from the total space, but btrfs doesn't subtract this space from
the total. It is strange to the user.
This patch fixes it by calcing the free space that can be used to allocate
chunks.
Implementation:
1. get all the devices free space, and align them by stripe length.
2. sort the devices by the free space.
3. check the free space of the devices,
3.1. if it is not zero, and then check the number of the devices that has
more free space than this device,
if the number of the devices is beyond the min stripe number, the free
space can be used, and add into total free space.
if the number of the devices is below the min stripe number, we can not
use the free space, the check ends.
3.2. if the free space is zero, check the next devices, goto 3.1
This implementation is just likely fake chunk allocation.
After appling this patch, df can show correct space information:
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 0 100% /mnt
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-01-05 17:07:31 +07:00
|
|
|
buf->f_bavail = total_free_data;
|
2011-11-18 03:40:49 +07:00
|
|
|
ret = btrfs_calc_avail_data_space(fs_info->tree_root, &total_free_data);
|
2014-11-03 20:56:50 +07:00
|
|
|
if (ret)
|
btrfs: fix wrong free space information of btrfs
When we store data by raid profile in btrfs with two or more different size
disks, df command shows there is some free space in the filesystem, but the
user can not write any data in fact, df command shows the wrong free space
information of btrfs.
# mkfs.btrfs -d raid1 /dev/sda9 /dev/sda10
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 28.00KB
devid 1 size 5.01GB used 2.03GB path /dev/sda9
devid 2 size 10.00GB used 2.01GB path /dev/sda10
# btrfs device scan /dev/sda9 /dev/sda10
# mount /dev/sda9 /mnt
# dd if=/dev/zero of=tmpfile0 bs=4K count=9999999999
(fill the filesystem)
# sync
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 5.4G 62% /mnt
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 3.99GB
devid 1 size 5.01GB used 5.01GB path /dev/sda9
devid 2 size 10.00GB used 4.99GB path /dev/sda10
It is because btrfs cannot allocate chunks when one of the pairing disks has
no space, the free space on the other disks can not be used for ever, and should
be subtracted from the total space, but btrfs doesn't subtract this space from
the total. It is strange to the user.
This patch fixes it by calcing the free space that can be used to allocate
chunks.
Implementation:
1. get all the devices free space, and align them by stripe length.
2. sort the devices by the free space.
3. check the free space of the devices,
3.1. if it is not zero, and then check the number of the devices that has
more free space than this device,
if the number of the devices is beyond the min stripe number, the free
space can be used, and add into total free space.
if the number of the devices is below the min stripe number, we can not
use the free space, the check ends.
3.2. if the free space is zero, check the next devices, goto 3.1
This implementation is just likely fake chunk allocation.
After appling this patch, df can show correct space information:
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 0 100% /mnt
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-01-05 17:07:31 +07:00
|
|
|
return ret;
|
2014-07-01 21:21:33 +07:00
|
|
|
buf->f_bavail += div_u64(total_free_data, factor);
|
btrfs: fix wrong free space information of btrfs
When we store data by raid profile in btrfs with two or more different size
disks, df command shows there is some free space in the filesystem, but the
user can not write any data in fact, df command shows the wrong free space
information of btrfs.
# mkfs.btrfs -d raid1 /dev/sda9 /dev/sda10
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 28.00KB
devid 1 size 5.01GB used 2.03GB path /dev/sda9
devid 2 size 10.00GB used 2.01GB path /dev/sda10
# btrfs device scan /dev/sda9 /dev/sda10
# mount /dev/sda9 /mnt
# dd if=/dev/zero of=tmpfile0 bs=4K count=9999999999
(fill the filesystem)
# sync
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 5.4G 62% /mnt
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 3.99GB
devid 1 size 5.01GB used 5.01GB path /dev/sda9
devid 2 size 10.00GB used 4.99GB path /dev/sda10
It is because btrfs cannot allocate chunks when one of the pairing disks has
no space, the free space on the other disks can not be used for ever, and should
be subtracted from the total space, but btrfs doesn't subtract this space from
the total. It is strange to the user.
This patch fixes it by calcing the free space that can be used to allocate
chunks.
Implementation:
1. get all the devices free space, and align them by stripe length.
2. sort the devices by the free space.
3. check the free space of the devices,
3.1. if it is not zero, and then check the number of the devices that has
more free space than this device,
if the number of the devices is beyond the min stripe number, the free
space can be used, and add into total free space.
if the number of the devices is below the min stripe number, we can not
use the free space, the check ends.
3.2. if the free space is zero, check the next devices, goto 3.1
This implementation is just likely fake chunk allocation.
After appling this patch, df can show correct space information:
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 0 100% /mnt
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-01-05 17:07:31 +07:00
|
|
|
buf->f_bavail = buf->f_bavail >> bits;
|
2009-01-06 09:25:51 +07:00
|
|
|
|
2014-07-01 21:21:33 +07:00
|
|
|
buf->f_type = BTRFS_SUPER_MAGIC;
|
|
|
|
buf->f_bsize = dentry->d_sb->s_blocksize;
|
|
|
|
buf->f_namelen = BTRFS_NAME_LEN;
|
|
|
|
|
2008-08-18 18:01:52 +07:00
|
|
|
/* We treat it as constant endianness (it doesn't matter _which_)
|
2009-01-06 09:25:51 +07:00
|
|
|
because we want the fsid to come out the same whether mounted
|
2008-08-18 18:01:52 +07:00
|
|
|
on a big-endian or little-endian host */
|
|
|
|
buf->f_fsid.val[0] = be32_to_cpu(fsid[0]) ^ be32_to_cpu(fsid[2]);
|
|
|
|
buf->f_fsid.val[1] = be32_to_cpu(fsid[1]) ^ be32_to_cpu(fsid[3]);
|
2008-08-18 19:10:20 +07:00
|
|
|
/* Mask in the root object ID too, to disambiguate subvols */
|
|
|
|
buf->f_fsid.val[0] ^= BTRFS_I(dentry->d_inode)->root->objectid >> 32;
|
|
|
|
buf->f_fsid.val[1] ^= BTRFS_I(dentry->d_inode)->root->objectid;
|
|
|
|
|
2007-04-20 08:01:03 +07:00
|
|
|
return 0;
|
|
|
|
}
|
2007-04-24 22:52:22 +07:00
|
|
|
|
2011-11-17 13:22:46 +07:00
|
|
|
static void btrfs_kill_super(struct super_block *sb)
|
|
|
|
{
|
2011-11-18 03:40:49 +07:00
|
|
|
struct btrfs_fs_info *fs_info = btrfs_sb(sb);
|
2011-11-17 13:22:46 +07:00
|
|
|
kill_anon_super(sb);
|
2011-11-17 13:46:50 +07:00
|
|
|
free_fs_info(fs_info);
|
2011-11-17 13:22:46 +07:00
|
|
|
}
|
|
|
|
|
2007-03-21 22:12:56 +07:00
|
|
|
static struct file_system_type btrfs_fs_type = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "btrfs",
|
2010-07-26 19:21:33 +07:00
|
|
|
.mount = btrfs_mount,
|
2011-11-17 13:22:46 +07:00
|
|
|
.kill_sb = btrfs_kill_super,
|
2014-09-23 12:40:08 +07:00
|
|
|
.fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA,
|
2007-03-21 22:12:56 +07:00
|
|
|
};
|
2013-03-03 10:39:14 +07:00
|
|
|
MODULE_ALIAS_FS("btrfs");
|
2008-03-25 02:02:04 +07:00
|
|
|
|
2008-09-30 02:18:18 +07:00
|
|
|
/*
|
|
|
|
* used by btrfsctl to scan devices when no FS is mounted
|
|
|
|
*/
|
2008-03-25 02:02:07 +07:00
|
|
|
static long btrfs_control_ioctl(struct file *file, unsigned int cmd,
|
|
|
|
unsigned long arg)
|
|
|
|
{
|
|
|
|
struct btrfs_ioctl_vol_args *vol;
|
|
|
|
struct btrfs_fs_devices *fs_devices;
|
2009-01-16 23:59:08 +07:00
|
|
|
int ret = -ENOTTY;
|
2008-03-25 02:02:07 +07:00
|
|
|
|
2009-01-06 04:57:23 +07:00
|
|
|
if (!capable(CAP_SYS_ADMIN))
|
|
|
|
return -EPERM;
|
|
|
|
|
2009-04-08 14:06:54 +07:00
|
|
|
vol = memdup_user((void __user *)arg, sizeof(*vol));
|
|
|
|
if (IS_ERR(vol))
|
|
|
|
return PTR_ERR(vol);
|
2009-01-16 23:59:08 +07:00
|
|
|
|
2008-03-25 02:02:07 +07:00
|
|
|
switch (cmd) {
|
|
|
|
case BTRFS_IOC_SCAN_DEV:
|
2008-12-02 18:36:09 +07:00
|
|
|
ret = btrfs_scan_one_device(vol->name, FMODE_READ,
|
2008-03-25 02:02:07 +07:00
|
|
|
&btrfs_fs_type, &fs_devices);
|
|
|
|
break;
|
2012-06-22 03:03:58 +07:00
|
|
|
case BTRFS_IOC_DEVICES_READY:
|
|
|
|
ret = btrfs_scan_one_device(vol->name, FMODE_READ,
|
|
|
|
&btrfs_fs_type, &fs_devices);
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
ret = !(fs_devices->num_devices == fs_devices->total_devices);
|
|
|
|
break;
|
2008-03-25 02:02:07 +07:00
|
|
|
}
|
2009-04-08 14:06:54 +07:00
|
|
|
|
2008-03-25 02:02:07 +07:00
|
|
|
kfree(vol);
|
2008-06-10 09:17:11 +07:00
|
|
|
return ret;
|
2008-03-25 02:02:07 +07:00
|
|
|
}
|
|
|
|
|
2009-01-10 21:09:52 +07:00
|
|
|
static int btrfs_freeze(struct super_block *sb)
|
2008-01-23 00:46:56 +07:00
|
|
|
{
|
Btrfs: fix orphan transaction on the freezed filesystem
With the following debug patch:
static int btrfs_freeze(struct super_block *sb)
{
+ struct btrfs_fs_info *fs_info = btrfs_sb(sb);
+ struct btrfs_transaction *trans;
+
+ spin_lock(&fs_info->trans_lock);
+ trans = fs_info->running_transaction;
+ if (trans) {
+ printk("Transid %llu, use_count %d, num_writer %d\n",
+ trans->transid, atomic_read(&trans->use_count),
+ atomic_read(&trans->num_writers));
+ }
+ spin_unlock(&fs_info->trans_lock);
return 0;
}
I found there was a orphan transaction after the freeze operation was done.
It is because the transaction may not be committed when the transaction handle
end even though it is the last handle of the current transaction. This design
avoid committing the transaction frequently, but also introduce the above
problem.
So I add btrfs_attach_transaction() which can catch the current transaction
and commit it. If there is no transaction, it will return ENOENT, and do not
anything.
This function also can be used to instead of btrfs_join_transaction_freeze()
because it don't increase the writer counter and don't start a new transaction,
so it also can fix the deadlock between sync and freeze.
Besides that, it is used to instead of btrfs_join_transaction() in
transaction_kthread(), because if there is no transaction, the transaction
kthread needn't anything.
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
2012-09-20 14:54:00 +07:00
|
|
|
struct btrfs_trans_handle *trans;
|
|
|
|
struct btrfs_root *root = btrfs_sb(sb)->tree_root;
|
|
|
|
|
Btrfs: fix uncompleted transaction
In some cases, we need commit the current transaction, but don't want
to start a new one if there is no running transaction, so we introduce
the function - btrfs_attach_transaction(), which can catch the current
transaction, and return -ENOENT if there is no running transaction.
But no running transaction doesn't mean the current transction completely,
because we removed the running transaction before it completes. In some
cases, it doesn't matter. But in some special cases, such as freeze fs, we
hope the transaction is fully on disk, it will introduce some bugs, for
example, we may feeze the fs and dump the data in the disk, if the transction
doesn't complete, we would dump inconsistent data. So we need fix the above
problem for those cases.
We fixes this problem by introducing a function:
btrfs_attach_transaction_barrier()
if we hope all the transaction is fully on the disk, even they are not
running, we can use this function.
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
2013-02-20 16:17:06 +07:00
|
|
|
trans = btrfs_attach_transaction_barrier(root);
|
Btrfs: fix orphan transaction on the freezed filesystem
With the following debug patch:
static int btrfs_freeze(struct super_block *sb)
{
+ struct btrfs_fs_info *fs_info = btrfs_sb(sb);
+ struct btrfs_transaction *trans;
+
+ spin_lock(&fs_info->trans_lock);
+ trans = fs_info->running_transaction;
+ if (trans) {
+ printk("Transid %llu, use_count %d, num_writer %d\n",
+ trans->transid, atomic_read(&trans->use_count),
+ atomic_read(&trans->num_writers));
+ }
+ spin_unlock(&fs_info->trans_lock);
return 0;
}
I found there was a orphan transaction after the freeze operation was done.
It is because the transaction may not be committed when the transaction handle
end even though it is the last handle of the current transaction. This design
avoid committing the transaction frequently, but also introduce the above
problem.
So I add btrfs_attach_transaction() which can catch the current transaction
and commit it. If there is no transaction, it will return ENOENT, and do not
anything.
This function also can be used to instead of btrfs_join_transaction_freeze()
because it don't increase the writer counter and don't start a new transaction,
so it also can fix the deadlock between sync and freeze.
Besides that, it is used to instead of btrfs_join_transaction() in
transaction_kthread(), because if there is no transaction, the transaction
kthread needn't anything.
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
2012-09-20 14:54:00 +07:00
|
|
|
if (IS_ERR(trans)) {
|
|
|
|
/* no transaction, don't bother */
|
|
|
|
if (PTR_ERR(trans) == -ENOENT)
|
|
|
|
return 0;
|
|
|
|
return PTR_ERR(trans);
|
|
|
|
}
|
|
|
|
return btrfs_commit_transaction(trans, root);
|
2008-01-23 00:46:56 +07:00
|
|
|
}
|
|
|
|
|
2009-01-10 21:09:52 +07:00
|
|
|
static int btrfs_unfreeze(struct super_block *sb)
|
2008-01-23 00:46:56 +07:00
|
|
|
{
|
2009-01-10 21:09:52 +07:00
|
|
|
return 0;
|
2008-01-23 00:46:56 +07:00
|
|
|
}
|
2007-03-21 22:12:56 +07:00
|
|
|
|
2012-06-06 01:13:12 +07:00
|
|
|
static int btrfs_show_devname(struct seq_file *m, struct dentry *root)
|
|
|
|
{
|
|
|
|
struct btrfs_fs_info *fs_info = btrfs_sb(root->d_sb);
|
|
|
|
struct btrfs_fs_devices *cur_devices;
|
|
|
|
struct btrfs_device *dev, *first_dev = NULL;
|
|
|
|
struct list_head *head;
|
|
|
|
struct rcu_string *name;
|
|
|
|
|
|
|
|
mutex_lock(&fs_info->fs_devices->device_list_mutex);
|
|
|
|
cur_devices = fs_info->fs_devices;
|
|
|
|
while (cur_devices) {
|
|
|
|
head = &cur_devices->devices;
|
|
|
|
list_for_each_entry(dev, head, dev_list) {
|
2012-08-02 21:22:20 +07:00
|
|
|
if (dev->missing)
|
|
|
|
continue;
|
2014-06-30 16:12:48 +07:00
|
|
|
if (!dev->name)
|
|
|
|
continue;
|
2012-06-06 01:13:12 +07:00
|
|
|
if (!first_dev || dev->devid < first_dev->devid)
|
|
|
|
first_dev = dev;
|
|
|
|
}
|
|
|
|
cur_devices = cur_devices->seed;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (first_dev) {
|
|
|
|
rcu_read_lock();
|
|
|
|
name = rcu_dereference(first_dev->name);
|
|
|
|
seq_escape(m, name->str, " \t\n\\");
|
|
|
|
rcu_read_unlock();
|
|
|
|
} else {
|
|
|
|
WARN_ON(1);
|
|
|
|
}
|
|
|
|
mutex_unlock(&fs_info->fs_devices->device_list_mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-22 07:01:09 +07:00
|
|
|
static const struct super_operations btrfs_super_ops = {
|
2009-09-22 03:00:26 +07:00
|
|
|
.drop_inode = btrfs_drop_inode,
|
2010-06-07 22:35:40 +07:00
|
|
|
.evict_inode = btrfs_evict_inode,
|
2007-03-22 23:13:20 +07:00
|
|
|
.put_super = btrfs_put_super,
|
2007-03-23 21:01:08 +07:00
|
|
|
.sync_fs = btrfs_sync_fs,
|
2009-04-03 03:46:06 +07:00
|
|
|
.show_options = btrfs_show_options,
|
2012-06-06 01:13:12 +07:00
|
|
|
.show_devname = btrfs_show_devname,
|
2007-03-26 23:00:39 +07:00
|
|
|
.write_inode = btrfs_write_inode,
|
2007-04-02 21:50:19 +07:00
|
|
|
.alloc_inode = btrfs_alloc_inode,
|
|
|
|
.destroy_inode = btrfs_destroy_inode,
|
2007-04-20 08:01:03 +07:00
|
|
|
.statfs = btrfs_statfs,
|
2008-11-13 02:34:12 +07:00
|
|
|
.remount_fs = btrfs_remount,
|
2009-01-10 21:09:52 +07:00
|
|
|
.freeze_fs = btrfs_freeze,
|
|
|
|
.unfreeze_fs = btrfs_unfreeze,
|
2007-03-22 23:13:20 +07:00
|
|
|
};
|
2008-03-25 02:02:04 +07:00
|
|
|
|
|
|
|
static const struct file_operations btrfs_ctl_fops = {
|
|
|
|
.unlocked_ioctl = btrfs_control_ioctl,
|
|
|
|
.compat_ioctl = btrfs_control_ioctl,
|
|
|
|
.owner = THIS_MODULE,
|
llseek: automatically add .llseek fop
All file_operations should get a .llseek operation so we can make
nonseekable_open the default for future file operations without a
.llseek pointer.
The three cases that we can automatically detect are no_llseek, seq_lseek
and default_llseek. For cases where we can we can automatically prove that
the file offset is always ignored, we use noop_llseek, which maintains
the current behavior of not returning an error from a seek.
New drivers should normally not use noop_llseek but instead use no_llseek
and call nonseekable_open at open time. Existing drivers can be converted
to do the same when the maintainer knows for certain that no user code
relies on calling seek on the device file.
The generated code is often incorrectly indented and right now contains
comments that clarify for each added line why a specific variant was
chosen. In the version that gets submitted upstream, the comments will
be gone and I will manually fix the indentation, because there does not
seem to be a way to do that using coccinelle.
Some amount of new code is currently sitting in linux-next that should get
the same modifications, which I will do at the end of the merge window.
Many thanks to Julia Lawall for helping me learn to write a semantic
patch that does all this.
===== begin semantic patch =====
// This adds an llseek= method to all file operations,
// as a preparation for making no_llseek the default.
//
// The rules are
// - use no_llseek explicitly if we do nonseekable_open
// - use seq_lseek for sequential files
// - use default_llseek if we know we access f_pos
// - use noop_llseek if we know we don't access f_pos,
// but we still want to allow users to call lseek
//
@ open1 exists @
identifier nested_open;
@@
nested_open(...)
{
<+...
nonseekable_open(...)
...+>
}
@ open exists@
identifier open_f;
identifier i, f;
identifier open1.nested_open;
@@
int open_f(struct inode *i, struct file *f)
{
<+...
(
nonseekable_open(...)
|
nested_open(...)
)
...+>
}
@ read disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ read_no_fpos disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
... when != off
}
@ write @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ write_no_fpos @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
... when != off
}
@ fops0 @
identifier fops;
@@
struct file_operations fops = {
...
};
@ has_llseek depends on fops0 @
identifier fops0.fops;
identifier llseek_f;
@@
struct file_operations fops = {
...
.llseek = llseek_f,
...
};
@ has_read depends on fops0 @
identifier fops0.fops;
identifier read_f;
@@
struct file_operations fops = {
...
.read = read_f,
...
};
@ has_write depends on fops0 @
identifier fops0.fops;
identifier write_f;
@@
struct file_operations fops = {
...
.write = write_f,
...
};
@ has_open depends on fops0 @
identifier fops0.fops;
identifier open_f;
@@
struct file_operations fops = {
...
.open = open_f,
...
};
// use no_llseek if we call nonseekable_open
////////////////////////////////////////////
@ nonseekable1 depends on !has_llseek && has_open @
identifier fops0.fops;
identifier nso ~= "nonseekable_open";
@@
struct file_operations fops = {
... .open = nso, ...
+.llseek = no_llseek, /* nonseekable */
};
@ nonseekable2 depends on !has_llseek @
identifier fops0.fops;
identifier open.open_f;
@@
struct file_operations fops = {
... .open = open_f, ...
+.llseek = no_llseek, /* open uses nonseekable */
};
// use seq_lseek for sequential files
/////////////////////////////////////
@ seq depends on !has_llseek @
identifier fops0.fops;
identifier sr ~= "seq_read";
@@
struct file_operations fops = {
... .read = sr, ...
+.llseek = seq_lseek, /* we have seq_read */
};
// use default_llseek if there is a readdir
///////////////////////////////////////////
@ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier readdir_e;
@@
// any other fop is used that changes pos
struct file_operations fops = {
... .readdir = readdir_e, ...
+.llseek = default_llseek, /* readdir is present */
};
// use default_llseek if at least one of read/write touches f_pos
/////////////////////////////////////////////////////////////////
@ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read.read_f;
@@
// read fops use offset
struct file_operations fops = {
... .read = read_f, ...
+.llseek = default_llseek, /* read accesses f_pos */
};
@ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write.write_f;
@@
// write fops use offset
struct file_operations fops = {
... .write = write_f, ...
+ .llseek = default_llseek, /* write accesses f_pos */
};
// Use noop_llseek if neither read nor write accesses f_pos
///////////////////////////////////////////////////////////
@ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
identifier write_no_fpos.write_f;
@@
// write fops use offset
struct file_operations fops = {
...
.write = write_f,
.read = read_f,
...
+.llseek = noop_llseek, /* read and write both use no f_pos */
};
@ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write_no_fpos.write_f;
@@
struct file_operations fops = {
... .write = write_f, ...
+.llseek = noop_llseek, /* write uses no f_pos */
};
@ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
@@
struct file_operations fops = {
... .read = read_f, ...
+.llseek = noop_llseek, /* read uses no f_pos */
};
@ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
@@
struct file_operations fops = {
...
+.llseek = noop_llseek, /* no read or write fn */
};
===== End semantic patch =====
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Julia Lawall <julia@diku.dk>
Cc: Christoph Hellwig <hch@infradead.org>
2010-08-15 23:52:59 +07:00
|
|
|
.llseek = noop_llseek,
|
2008-03-25 02:02:04 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct miscdevice btrfs_misc = {
|
driver core: add devname module aliases to allow module on-demand auto-loading
This adds:
alias: devname:<name>
to some common kernel modules, which will allow the on-demand loading
of the kernel module when the device node is accessed.
Ideally all these modules would be compiled-in, but distros seems too
much in love with their modularization that we need to cover the common
cases with this new facility. It will allow us to remove a bunch of pretty
useless init scripts and modprobes from init scripts.
The static device node aliases will be carried in the module itself. The
program depmod will extract this information to a file in the module directory:
$ cat /lib/modules/2.6.34-00650-g537b60d-dirty/modules.devname
# Device nodes to trigger on-demand module loading.
microcode cpu/microcode c10:184
fuse fuse c10:229
ppp_generic ppp c108:0
tun net/tun c10:200
dm_mod mapper/control c10:235
Udev will pick up the depmod created file on startup and create all the
static device nodes which the kernel modules specify, so that these modules
get automatically loaded when the device node is accessed:
$ /sbin/udevd --debug
...
static_dev_create_from_modules: mknod '/dev/cpu/microcode' c10:184
static_dev_create_from_modules: mknod '/dev/fuse' c10:229
static_dev_create_from_modules: mknod '/dev/ppp' c108:0
static_dev_create_from_modules: mknod '/dev/net/tun' c10:200
static_dev_create_from_modules: mknod '/dev/mapper/control' c10:235
udev_rules_apply_static_dev_perms: chmod '/dev/net/tun' 0666
udev_rules_apply_static_dev_perms: chmod '/dev/fuse' 0666
A few device nodes are switched to statically allocated numbers, to allow
the static nodes to work. This might also useful for systems which still run
a plain static /dev, which is completely unsafe to use with any dynamic minor
numbers.
Note:
The devname aliases must be limited to the *common* and *single*instance*
device nodes, like the misc devices, and never be used for conceptually limited
systems like the loop devices, which should rather get fixed properly and get a
control node for losetup to talk to, instead of creating a random number of
device nodes in advance, regardless if they are ever used.
This facility is to hide the mess distros are creating with too modualized
kernels, and just to hide that these modules are not compiled-in, and not to
paper-over broken concepts. Thanks! :)
Cc: Greg Kroah-Hartman <gregkh@suse.de>
Cc: David S. Miller <davem@davemloft.net>
Cc: Miklos Szeredi <miklos@szeredi.hu>
Cc: Chris Mason <chris.mason@oracle.com>
Cc: Alasdair G Kergon <agk@redhat.com>
Cc: Tigran Aivazian <tigran@aivazian.fsnet.co.uk>
Cc: Ian Kent <raven@themaw.net>
Signed-Off-By: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-05-20 23:07:20 +07:00
|
|
|
.minor = BTRFS_MINOR,
|
2008-03-25 02:02:04 +07:00
|
|
|
.name = "btrfs-control",
|
|
|
|
.fops = &btrfs_ctl_fops
|
|
|
|
};
|
|
|
|
|
driver core: add devname module aliases to allow module on-demand auto-loading
This adds:
alias: devname:<name>
to some common kernel modules, which will allow the on-demand loading
of the kernel module when the device node is accessed.
Ideally all these modules would be compiled-in, but distros seems too
much in love with their modularization that we need to cover the common
cases with this new facility. It will allow us to remove a bunch of pretty
useless init scripts and modprobes from init scripts.
The static device node aliases will be carried in the module itself. The
program depmod will extract this information to a file in the module directory:
$ cat /lib/modules/2.6.34-00650-g537b60d-dirty/modules.devname
# Device nodes to trigger on-demand module loading.
microcode cpu/microcode c10:184
fuse fuse c10:229
ppp_generic ppp c108:0
tun net/tun c10:200
dm_mod mapper/control c10:235
Udev will pick up the depmod created file on startup and create all the
static device nodes which the kernel modules specify, so that these modules
get automatically loaded when the device node is accessed:
$ /sbin/udevd --debug
...
static_dev_create_from_modules: mknod '/dev/cpu/microcode' c10:184
static_dev_create_from_modules: mknod '/dev/fuse' c10:229
static_dev_create_from_modules: mknod '/dev/ppp' c108:0
static_dev_create_from_modules: mknod '/dev/net/tun' c10:200
static_dev_create_from_modules: mknod '/dev/mapper/control' c10:235
udev_rules_apply_static_dev_perms: chmod '/dev/net/tun' 0666
udev_rules_apply_static_dev_perms: chmod '/dev/fuse' 0666
A few device nodes are switched to statically allocated numbers, to allow
the static nodes to work. This might also useful for systems which still run
a plain static /dev, which is completely unsafe to use with any dynamic minor
numbers.
Note:
The devname aliases must be limited to the *common* and *single*instance*
device nodes, like the misc devices, and never be used for conceptually limited
systems like the loop devices, which should rather get fixed properly and get a
control node for losetup to talk to, instead of creating a random number of
device nodes in advance, regardless if they are ever used.
This facility is to hide the mess distros are creating with too modualized
kernels, and just to hide that these modules are not compiled-in, and not to
paper-over broken concepts. Thanks! :)
Cc: Greg Kroah-Hartman <gregkh@suse.de>
Cc: David S. Miller <davem@davemloft.net>
Cc: Miklos Szeredi <miklos@szeredi.hu>
Cc: Chris Mason <chris.mason@oracle.com>
Cc: Alasdair G Kergon <agk@redhat.com>
Cc: Tigran Aivazian <tigran@aivazian.fsnet.co.uk>
Cc: Ian Kent <raven@themaw.net>
Signed-Off-By: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2010-05-20 23:07:20 +07:00
|
|
|
MODULE_ALIAS_MISCDEV(BTRFS_MINOR);
|
|
|
|
MODULE_ALIAS("devname:btrfs-control");
|
|
|
|
|
2008-03-25 02:02:04 +07:00
|
|
|
static int btrfs_interface_init(void)
|
|
|
|
{
|
|
|
|
return misc_register(&btrfs_misc);
|
|
|
|
}
|
|
|
|
|
2008-12-02 21:54:17 +07:00
|
|
|
static void btrfs_interface_exit(void)
|
2008-03-25 02:02:04 +07:00
|
|
|
{
|
|
|
|
if (misc_deregister(&btrfs_misc) < 0)
|
2013-12-20 23:37:06 +07:00
|
|
|
printk(KERN_INFO "BTRFS: misc_deregister failed for control device\n");
|
2008-03-25 02:02:04 +07:00
|
|
|
}
|
|
|
|
|
2013-04-30 23:51:59 +07:00
|
|
|
static void btrfs_print_info(void)
|
|
|
|
{
|
|
|
|
printk(KERN_INFO "Btrfs loaded"
|
|
|
|
#ifdef CONFIG_BTRFS_DEBUG
|
|
|
|
", debug=on"
|
|
|
|
#endif
|
2013-09-03 20:25:27 +07:00
|
|
|
#ifdef CONFIG_BTRFS_ASSERT
|
|
|
|
", assert=on"
|
|
|
|
#endif
|
2013-04-30 23:51:59 +07:00
|
|
|
#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
|
|
|
|
", integrity-checker=on"
|
|
|
|
#endif
|
|
|
|
"\n");
|
|
|
|
}
|
|
|
|
|
2013-08-15 02:05:12 +07:00
|
|
|
static int btrfs_run_sanity_tests(void)
|
|
|
|
{
|
2013-09-20 03:07:01 +07:00
|
|
|
int ret;
|
|
|
|
|
2013-10-09 23:00:56 +07:00
|
|
|
ret = btrfs_init_test_fs();
|
2013-09-20 03:07:01 +07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2013-10-09 23:00:56 +07:00
|
|
|
|
|
|
|
ret = btrfs_test_free_space_cache();
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
ret = btrfs_test_extent_buffer_operations();
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
ret = btrfs_test_extent_io();
|
2013-10-12 01:44:09 +07:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
ret = btrfs_test_inodes();
|
2014-05-08 04:06:09 +07:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
ret = btrfs_test_qgroups();
|
2013-10-09 23:00:56 +07:00
|
|
|
out:
|
|
|
|
btrfs_destroy_test_fs();
|
|
|
|
return ret;
|
2013-08-15 02:05:12 +07:00
|
|
|
}
|
|
|
|
|
2007-03-21 22:12:56 +07:00
|
|
|
static int __init init_btrfs_fs(void)
|
|
|
|
{
|
2007-04-02 21:50:19 +07:00
|
|
|
int err;
|
2007-08-30 02:47:34 +07:00
|
|
|
|
2014-01-12 09:22:46 +07:00
|
|
|
err = btrfs_hash_init();
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
Btrfs: add support for inode properties
This change adds infrastructure to allow for generic properties for
inodes. Properties are name/value pairs that can be associated with
inodes for different purposes. They are stored as xattrs with the
prefix "btrfs."
Properties can be inherited - this means when a directory inode has
inheritable properties set, these are added to new inodes created
under that directory. Further, subvolumes can also have properties
associated with them, and they can be inherited from their parent
subvolume. Naturally, directory properties have priority over subvolume
properties (in practice a subvolume property is just a regular
property associated with the root inode, objectid 256, of the
subvolume's fs tree).
This change also adds one specific property implementation, named
"compression", whose values can be "lzo" or "zlib" and it's an
inheritable property.
The corresponding changes to btrfs-progs were also implemented.
A patch with xfstests for this feature will follow once there's
agreement on this change/feature.
Further, the script at the bottom of this commit message was used to
do some benchmarks to measure any performance penalties of this feature.
Basically the tests correspond to:
Test 1 - create a filesystem and mount it with compress-force=lzo,
then sequentially create N files of 64Kb each, measure how long it took
to create the files, unmount the filesystem, mount the filesystem and
perform an 'ls -lha' against the test directory holding the N files, and
report the time the command took.
Test 2 - create a filesystem and don't use any compression option when
mounting it - instead set the compression property of the subvolume's
root to 'lzo'. Then create N files of 64Kb, and report the time it took.
The unmount the filesystem, mount it again and perform an 'ls -lha' like
in the former test. This means every single file ends up with a property
(xattr) associated to it.
Test 3 - same as test 2, but uses 4 properties - 3 are duplicates of the
compression property, have no real effect other than adding more work
when inheriting properties and taking more btree leaf space.
Test 4 - same as test 3 but with 10 properties per file.
Results (in seconds, and averages of 5 runs each), for different N
numbers of files follow.
* Without properties (test 1)
file creation time ls -lha time
10 000 files 3.49 0.76
100 000 files 47.19 8.37
1 000 000 files 518.51 107.06
* With 1 property (compression property set to lzo - test 2)
file creation time ls -lha time
10 000 files 3.63 0.93
100 000 files 48.56 9.74
1 000 000 files 537.72 125.11
* With 4 properties (test 3)
file creation time ls -lha time
10 000 files 3.94 1.20
100 000 files 52.14 11.48
1 000 000 files 572.70 142.13
* With 10 properties (test 4)
file creation time ls -lha time
10 000 files 4.61 1.35
100 000 files 58.86 13.83
1 000 000 files 656.01 177.61
The increased latencies with properties are essencialy because of:
*) When creating an inode, we now synchronously write 1 more item
(an xattr item) for each property inherited from the parent dir
(or subvolume). This could be done in an asynchronous way such
as we do for dir intex items (delayed-inode.c), which could help
reduce the file creation latency;
*) With properties, we now have larger fs trees. For this particular
test each xattr item uses 75 bytes of leaf space in the fs tree.
This could be less by using a new item for xattr items, instead of
the current btrfs_dir_item, since we could cut the 'location' and
'type' fields (saving 18 bytes) and maybe 'transid' too (saving a
total of 26 bytes per xattr item) from the btrfs_dir_item type.
Also tried batching the xattr insertions (ignoring proper hash
collision handling, since it didn't exist) when creating files that
inherit properties from their parent inode/subvolume, but the end
results were (surprisingly) essentially the same.
Test script:
$ cat test.pl
#!/usr/bin/perl -w
use strict;
use Time::HiRes qw(time);
use constant NUM_FILES => 10_000;
use constant FILE_SIZES => (64 * 1024);
use constant DEV => '/dev/sdb4';
use constant MNT_POINT => '/home/fdmanana/btrfs-tests/dev';
use constant TEST_DIR => (MNT_POINT . '/testdir');
system("mkfs.btrfs", "-l", "16384", "-f", DEV) == 0 or die "mkfs.btrfs failed!";
# following line for testing without properties
#system("mount", "-o", "compress-force=lzo", DEV, MNT_POINT) == 0 or die "mount failed!";
# following 2 lines for testing with properties
system("mount", DEV, MNT_POINT) == 0 or die "mount failed!";
system("btrfs", "prop", "set", MNT_POINT, "compression", "lzo") == 0 or die "set prop failed!";
system("mkdir", TEST_DIR) == 0 or die "mkdir failed!";
my ($t1, $t2);
$t1 = time();
for (my $i = 1; $i <= NUM_FILES; $i++) {
my $p = TEST_DIR . '/file_' . $i;
open(my $f, '>', $p) or die "Error opening file!";
$f->autoflush(1);
for (my $j = 0; $j < FILE_SIZES; $j += 4096) {
print $f ('A' x 4096) or die "Error writing to file!";
}
close($f);
}
$t2 = time();
print "Time to create " . NUM_FILES . ": " . ($t2 - $t1) . " seconds.\n";
system("umount", DEV) == 0 or die "umount failed!";
system("mount", DEV, MNT_POINT) == 0 or die "mount failed!";
$t1 = time();
system("bash -c 'ls -lha " . TEST_DIR . " > /dev/null'") == 0 or die "ls failed!";
$t2 = time();
print "Time to ls -lha all files: " . ($t2 - $t1) . " seconds.\n";
system("umount", DEV) == 0 or die "umount failed!";
Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: Chris Mason <clm@fb.com>
2014-01-07 18:47:46 +07:00
|
|
|
btrfs_props_init();
|
|
|
|
|
2007-08-30 02:47:34 +07:00
|
|
|
err = btrfs_init_sysfs();
|
|
|
|
if (err)
|
2014-01-12 09:22:46 +07:00
|
|
|
goto free_hash;
|
2007-08-30 02:47:34 +07:00
|
|
|
|
2012-03-01 20:56:26 +07:00
|
|
|
btrfs_init_compress();
|
2008-01-25 04:13:08 +07:00
|
|
|
|
2010-12-17 13:21:50 +07:00
|
|
|
err = btrfs_init_cachep();
|
|
|
|
if (err)
|
|
|
|
goto free_compress;
|
|
|
|
|
2008-01-25 04:13:08 +07:00
|
|
|
err = extent_io_init();
|
2007-11-19 22:22:33 +07:00
|
|
|
if (err)
|
|
|
|
goto free_cachep;
|
|
|
|
|
2008-01-25 04:13:08 +07:00
|
|
|
err = extent_map_init();
|
|
|
|
if (err)
|
|
|
|
goto free_extent_io;
|
|
|
|
|
2012-09-06 17:01:51 +07:00
|
|
|
err = ordered_data_init();
|
2007-11-19 22:22:33 +07:00
|
|
|
if (err)
|
|
|
|
goto free_extent_map;
|
Btrfs: Add zlib compression support
This is a large change for adding compression on reading and writing,
both for inline and regular extents. It does some fairly large
surgery to the writeback paths.
Compression is off by default and enabled by mount -o compress. Even
when the -o compress mount option is not used, it is possible to read
compressed extents off the disk.
If compression for a given set of pages fails to make them smaller, the
file is flagged to avoid future compression attempts later.
* While finding delalloc extents, the pages are locked before being sent down
to the delalloc handler. This allows the delalloc handler to do complex things
such as cleaning the pages, marking them writeback and starting IO on their
behalf.
* Inline extents are inserted at delalloc time now. This allows us to compress
the data before inserting the inline extent, and it allows us to insert
an inline extent that spans multiple pages.
* All of the in-memory extent representations (extent_map.c, ordered-data.c etc)
are changed to record both an in-memory size and an on disk size, as well
as a flag for compression.
From a disk format point of view, the extent pointers in the file are changed
to record the on disk size of a given extent and some encoding flags.
Space in the disk format is allocated for compression encoding, as well
as encryption and a generic 'other' field. Neither the encryption or the
'other' field are currently used.
In order to limit the amount of data read for a single random read in the
file, the size of a compressed extent is limited to 128k. This is a
software only limit, the disk format supports u64 sized compressed extents.
In order to limit the ram consumed while processing extents, the uncompressed
size of a compressed extent is limited to 256k. This is a software only limit
and will be subject to tuning later.
Checksumming is still done on compressed extents, and it is done on the
uncompressed version of the data. This way additional encodings can be
layered on without having to figure out which encoding to checksum.
Compression happens at delalloc time, which is basically singled threaded because
it is usually done by a single pdflush thread. This makes it tricky to
spread the compression load across all the cpus on the box. We'll have to
look at parallel pdflush walks of dirty inodes at a later time.
Decompression is hooked into readpages and it does spread across CPUs nicely.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2008-10-30 01:49:59 +07:00
|
|
|
|
2012-09-06 17:01:51 +07:00
|
|
|
err = btrfs_delayed_inode_init();
|
|
|
|
if (err)
|
|
|
|
goto free_ordered_data;
|
|
|
|
|
2012-11-26 16:24:43 +07:00
|
|
|
err = btrfs_auto_defrag_init();
|
btrfs: implement delayed inode items operation
Changelog V5 -> V6:
- Fix oom when the memory load is high, by storing the delayed nodes into the
root's radix tree, and letting btrfs inodes go.
Changelog V4 -> V5:
- Fix the race on adding the delayed node to the inode, which is spotted by
Chris Mason.
- Merge Chris Mason's incremental patch into this patch.
- Fix deadlock between readdir() and memory fault, which is reported by
Itaru Kitayama.
Changelog V3 -> V4:
- Fix nested lock, which is reported by Itaru Kitayama, by updating space cache
inode in time.
Changelog V2 -> V3:
- Fix the race between the delayed worker and the task which does delayed items
balance, which is reported by Tsutomu Itoh.
- Modify the patch address David Sterba's comment.
- Fix the bug of the cpu recursion spinlock, reported by Chris Mason
Changelog V1 -> V2:
- break up the global rb-tree, use a list to manage the delayed nodes,
which is created for every directory and file, and used to manage the
delayed directory name index items and the delayed inode item.
- introduce a worker to deal with the delayed nodes.
Compare with Ext3/4, the performance of file creation and deletion on btrfs
is very poor. the reason is that btrfs must do a lot of b+ tree insertions,
such as inode item, directory name item, directory name index and so on.
If we can do some delayed b+ tree insertion or deletion, we can improve the
performance, so we made this patch which implemented delayed directory name
index insertion/deletion and delayed inode update.
Implementation:
- introduce a delayed root object into the filesystem, that use two lists to
manage the delayed nodes which are created for every file/directory.
One is used to manage all the delayed nodes that have delayed items. And the
other is used to manage the delayed nodes which is waiting to be dealt with
by the work thread.
- Every delayed node has two rb-tree, one is used to manage the directory name
index which is going to be inserted into b+ tree, and the other is used to
manage the directory name index which is going to be deleted from b+ tree.
- introduce a worker to deal with the delayed operation. This worker is used
to deal with the works of the delayed directory name index items insertion
and deletion and the delayed inode update.
When the delayed items is beyond the lower limit, we create works for some
delayed nodes and insert them into the work queue of the worker, and then
go back.
When the delayed items is beyond the upper bound, we create works for all
the delayed nodes that haven't been dealt with, and insert them into the work
queue of the worker, and then wait for that the untreated items is below some
threshold value.
- When we want to insert a directory name index into b+ tree, we just add the
information into the delayed inserting rb-tree.
And then we check the number of the delayed items and do delayed items
balance. (The balance policy is above.)
- When we want to delete a directory name index from the b+ tree, we search it
in the inserting rb-tree at first. If we look it up, just drop it. If not,
add the key of it into the delayed deleting rb-tree.
Similar to the delayed inserting rb-tree, we also check the number of the
delayed items and do delayed items balance.
(The same to inserting manipulation)
- When we want to update the metadata of some inode, we cached the data of the
inode into the delayed node. the worker will flush it into the b+ tree after
dealing with the delayed insertion and deletion.
- We will move the delayed node to the tail of the list after we access the
delayed node, By this way, we can cache more delayed items and merge more
inode updates.
- If we want to commit transaction, we will deal with all the delayed node.
- the delayed node will be freed when we free the btrfs inode.
- Before we log the inode items, we commit all the directory name index items
and the delayed inode update.
I did a quick test by the benchmark tool[1] and found we can improve the
performance of file creation by ~15%, and file deletion by ~20%.
Before applying this patch:
Create files:
Total files: 50000
Total time: 1.096108
Average time: 0.000022
Delete files:
Total files: 50000
Total time: 1.510403
Average time: 0.000030
After applying this patch:
Create files:
Total files: 50000
Total time: 0.932899
Average time: 0.000019
Delete files:
Total files: 50000
Total time: 1.215732
Average time: 0.000024
[1] http://marc.info/?l=linux-btrfs&m=128212635122920&q=p3
Many thanks for Kitayama-san's help!
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Reviewed-by: David Sterba <dave@jikos.cz>
Tested-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
Tested-by: Itaru Kitayama <kitayama@cl.bb4u.ne.jp>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-04-22 17:12:22 +07:00
|
|
|
if (err)
|
|
|
|
goto free_delayed_inode;
|
|
|
|
|
2012-11-21 09:21:28 +07:00
|
|
|
err = btrfs_delayed_ref_init();
|
2012-11-26 16:24:43 +07:00
|
|
|
if (err)
|
|
|
|
goto free_auto_defrag;
|
|
|
|
|
2013-08-09 12:25:36 +07:00
|
|
|
err = btrfs_prelim_ref_init();
|
|
|
|
if (err)
|
2014-07-30 05:58:37 +07:00
|
|
|
goto free_delayed_ref;
|
2013-08-09 12:25:36 +07:00
|
|
|
|
2014-07-30 05:55:42 +07:00
|
|
|
err = btrfs_end_io_wq_init();
|
2012-11-21 09:21:28 +07:00
|
|
|
if (err)
|
2014-07-30 05:58:37 +07:00
|
|
|
goto free_prelim_ref;
|
2012-11-21 09:21:28 +07:00
|
|
|
|
2014-07-30 05:55:42 +07:00
|
|
|
err = btrfs_interface_init();
|
|
|
|
if (err)
|
|
|
|
goto free_end_io_wq;
|
|
|
|
|
2012-03-23 23:14:20 +07:00
|
|
|
btrfs_init_lockdep();
|
|
|
|
|
2013-04-30 23:51:59 +07:00
|
|
|
btrfs_print_info();
|
2013-08-15 02:05:12 +07:00
|
|
|
|
|
|
|
err = btrfs_run_sanity_tests();
|
|
|
|
if (err)
|
|
|
|
goto unregister_ioctl;
|
|
|
|
|
|
|
|
err = register_filesystem(&btrfs_fs_type);
|
|
|
|
if (err)
|
|
|
|
goto unregister_ioctl;
|
2013-03-15 20:47:08 +07:00
|
|
|
|
2007-11-19 22:22:33 +07:00
|
|
|
return 0;
|
|
|
|
|
2008-03-25 02:02:04 +07:00
|
|
|
unregister_ioctl:
|
|
|
|
btrfs_interface_exit();
|
2014-07-30 05:55:42 +07:00
|
|
|
free_end_io_wq:
|
|
|
|
btrfs_end_io_wq_exit();
|
2013-08-09 12:25:36 +07:00
|
|
|
free_prelim_ref:
|
|
|
|
btrfs_prelim_ref_exit();
|
2012-11-21 09:21:28 +07:00
|
|
|
free_delayed_ref:
|
|
|
|
btrfs_delayed_ref_exit();
|
2012-11-26 16:24:43 +07:00
|
|
|
free_auto_defrag:
|
|
|
|
btrfs_auto_defrag_exit();
|
btrfs: implement delayed inode items operation
Changelog V5 -> V6:
- Fix oom when the memory load is high, by storing the delayed nodes into the
root's radix tree, and letting btrfs inodes go.
Changelog V4 -> V5:
- Fix the race on adding the delayed node to the inode, which is spotted by
Chris Mason.
- Merge Chris Mason's incremental patch into this patch.
- Fix deadlock between readdir() and memory fault, which is reported by
Itaru Kitayama.
Changelog V3 -> V4:
- Fix nested lock, which is reported by Itaru Kitayama, by updating space cache
inode in time.
Changelog V2 -> V3:
- Fix the race between the delayed worker and the task which does delayed items
balance, which is reported by Tsutomu Itoh.
- Modify the patch address David Sterba's comment.
- Fix the bug of the cpu recursion spinlock, reported by Chris Mason
Changelog V1 -> V2:
- break up the global rb-tree, use a list to manage the delayed nodes,
which is created for every directory and file, and used to manage the
delayed directory name index items and the delayed inode item.
- introduce a worker to deal with the delayed nodes.
Compare with Ext3/4, the performance of file creation and deletion on btrfs
is very poor. the reason is that btrfs must do a lot of b+ tree insertions,
such as inode item, directory name item, directory name index and so on.
If we can do some delayed b+ tree insertion or deletion, we can improve the
performance, so we made this patch which implemented delayed directory name
index insertion/deletion and delayed inode update.
Implementation:
- introduce a delayed root object into the filesystem, that use two lists to
manage the delayed nodes which are created for every file/directory.
One is used to manage all the delayed nodes that have delayed items. And the
other is used to manage the delayed nodes which is waiting to be dealt with
by the work thread.
- Every delayed node has two rb-tree, one is used to manage the directory name
index which is going to be inserted into b+ tree, and the other is used to
manage the directory name index which is going to be deleted from b+ tree.
- introduce a worker to deal with the delayed operation. This worker is used
to deal with the works of the delayed directory name index items insertion
and deletion and the delayed inode update.
When the delayed items is beyond the lower limit, we create works for some
delayed nodes and insert them into the work queue of the worker, and then
go back.
When the delayed items is beyond the upper bound, we create works for all
the delayed nodes that haven't been dealt with, and insert them into the work
queue of the worker, and then wait for that the untreated items is below some
threshold value.
- When we want to insert a directory name index into b+ tree, we just add the
information into the delayed inserting rb-tree.
And then we check the number of the delayed items and do delayed items
balance. (The balance policy is above.)
- When we want to delete a directory name index from the b+ tree, we search it
in the inserting rb-tree at first. If we look it up, just drop it. If not,
add the key of it into the delayed deleting rb-tree.
Similar to the delayed inserting rb-tree, we also check the number of the
delayed items and do delayed items balance.
(The same to inserting manipulation)
- When we want to update the metadata of some inode, we cached the data of the
inode into the delayed node. the worker will flush it into the b+ tree after
dealing with the delayed insertion and deletion.
- We will move the delayed node to the tail of the list after we access the
delayed node, By this way, we can cache more delayed items and merge more
inode updates.
- If we want to commit transaction, we will deal with all the delayed node.
- the delayed node will be freed when we free the btrfs inode.
- Before we log the inode items, we commit all the directory name index items
and the delayed inode update.
I did a quick test by the benchmark tool[1] and found we can improve the
performance of file creation by ~15%, and file deletion by ~20%.
Before applying this patch:
Create files:
Total files: 50000
Total time: 1.096108
Average time: 0.000022
Delete files:
Total files: 50000
Total time: 1.510403
Average time: 0.000030
After applying this patch:
Create files:
Total files: 50000
Total time: 0.932899
Average time: 0.000019
Delete files:
Total files: 50000
Total time: 1.215732
Average time: 0.000024
[1] http://marc.info/?l=linux-btrfs&m=128212635122920&q=p3
Many thanks for Kitayama-san's help!
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Reviewed-by: David Sterba <dave@jikos.cz>
Tested-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
Tested-by: Itaru Kitayama <kitayama@cl.bb4u.ne.jp>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-04-22 17:12:22 +07:00
|
|
|
free_delayed_inode:
|
|
|
|
btrfs_delayed_inode_exit();
|
2012-09-06 17:01:51 +07:00
|
|
|
free_ordered_data:
|
|
|
|
ordered_data_exit();
|
2007-11-19 22:22:33 +07:00
|
|
|
free_extent_map:
|
|
|
|
extent_map_exit();
|
2008-01-25 04:13:08 +07:00
|
|
|
free_extent_io:
|
|
|
|
extent_io_exit();
|
2007-11-19 22:22:33 +07:00
|
|
|
free_cachep:
|
|
|
|
btrfs_destroy_cachep();
|
2010-12-17 13:21:50 +07:00
|
|
|
free_compress:
|
|
|
|
btrfs_exit_compress();
|
2007-11-19 22:22:33 +07:00
|
|
|
btrfs_exit_sysfs();
|
2014-01-12 09:22:46 +07:00
|
|
|
free_hash:
|
|
|
|
btrfs_hash_exit();
|
2007-11-19 22:22:33 +07:00
|
|
|
return err;
|
2007-03-21 22:12:56 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit exit_btrfs_fs(void)
|
|
|
|
{
|
2007-06-12 17:35:45 +07:00
|
|
|
btrfs_destroy_cachep();
|
2012-11-21 09:21:28 +07:00
|
|
|
btrfs_delayed_ref_exit();
|
2012-11-26 16:24:43 +07:00
|
|
|
btrfs_auto_defrag_exit();
|
btrfs: implement delayed inode items operation
Changelog V5 -> V6:
- Fix oom when the memory load is high, by storing the delayed nodes into the
root's radix tree, and letting btrfs inodes go.
Changelog V4 -> V5:
- Fix the race on adding the delayed node to the inode, which is spotted by
Chris Mason.
- Merge Chris Mason's incremental patch into this patch.
- Fix deadlock between readdir() and memory fault, which is reported by
Itaru Kitayama.
Changelog V3 -> V4:
- Fix nested lock, which is reported by Itaru Kitayama, by updating space cache
inode in time.
Changelog V2 -> V3:
- Fix the race between the delayed worker and the task which does delayed items
balance, which is reported by Tsutomu Itoh.
- Modify the patch address David Sterba's comment.
- Fix the bug of the cpu recursion spinlock, reported by Chris Mason
Changelog V1 -> V2:
- break up the global rb-tree, use a list to manage the delayed nodes,
which is created for every directory and file, and used to manage the
delayed directory name index items and the delayed inode item.
- introduce a worker to deal with the delayed nodes.
Compare with Ext3/4, the performance of file creation and deletion on btrfs
is very poor. the reason is that btrfs must do a lot of b+ tree insertions,
such as inode item, directory name item, directory name index and so on.
If we can do some delayed b+ tree insertion or deletion, we can improve the
performance, so we made this patch which implemented delayed directory name
index insertion/deletion and delayed inode update.
Implementation:
- introduce a delayed root object into the filesystem, that use two lists to
manage the delayed nodes which are created for every file/directory.
One is used to manage all the delayed nodes that have delayed items. And the
other is used to manage the delayed nodes which is waiting to be dealt with
by the work thread.
- Every delayed node has two rb-tree, one is used to manage the directory name
index which is going to be inserted into b+ tree, and the other is used to
manage the directory name index which is going to be deleted from b+ tree.
- introduce a worker to deal with the delayed operation. This worker is used
to deal with the works of the delayed directory name index items insertion
and deletion and the delayed inode update.
When the delayed items is beyond the lower limit, we create works for some
delayed nodes and insert them into the work queue of the worker, and then
go back.
When the delayed items is beyond the upper bound, we create works for all
the delayed nodes that haven't been dealt with, and insert them into the work
queue of the worker, and then wait for that the untreated items is below some
threshold value.
- When we want to insert a directory name index into b+ tree, we just add the
information into the delayed inserting rb-tree.
And then we check the number of the delayed items and do delayed items
balance. (The balance policy is above.)
- When we want to delete a directory name index from the b+ tree, we search it
in the inserting rb-tree at first. If we look it up, just drop it. If not,
add the key of it into the delayed deleting rb-tree.
Similar to the delayed inserting rb-tree, we also check the number of the
delayed items and do delayed items balance.
(The same to inserting manipulation)
- When we want to update the metadata of some inode, we cached the data of the
inode into the delayed node. the worker will flush it into the b+ tree after
dealing with the delayed insertion and deletion.
- We will move the delayed node to the tail of the list after we access the
delayed node, By this way, we can cache more delayed items and merge more
inode updates.
- If we want to commit transaction, we will deal with all the delayed node.
- the delayed node will be freed when we free the btrfs inode.
- Before we log the inode items, we commit all the directory name index items
and the delayed inode update.
I did a quick test by the benchmark tool[1] and found we can improve the
performance of file creation by ~15%, and file deletion by ~20%.
Before applying this patch:
Create files:
Total files: 50000
Total time: 1.096108
Average time: 0.000022
Delete files:
Total files: 50000
Total time: 1.510403
Average time: 0.000030
After applying this patch:
Create files:
Total files: 50000
Total time: 0.932899
Average time: 0.000019
Delete files:
Total files: 50000
Total time: 1.215732
Average time: 0.000024
[1] http://marc.info/?l=linux-btrfs&m=128212635122920&q=p3
Many thanks for Kitayama-san's help!
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Reviewed-by: David Sterba <dave@jikos.cz>
Tested-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
Tested-by: Itaru Kitayama <kitayama@cl.bb4u.ne.jp>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-04-22 17:12:22 +07:00
|
|
|
btrfs_delayed_inode_exit();
|
2013-08-09 12:25:36 +07:00
|
|
|
btrfs_prelim_ref_exit();
|
2012-09-06 17:01:51 +07:00
|
|
|
ordered_data_exit();
|
2007-08-28 03:49:44 +07:00
|
|
|
extent_map_exit();
|
2008-01-25 04:13:08 +07:00
|
|
|
extent_io_exit();
|
2008-03-25 02:02:04 +07:00
|
|
|
btrfs_interface_exit();
|
2014-10-16 04:19:59 +07:00
|
|
|
btrfs_end_io_wq_exit();
|
2007-03-21 22:12:56 +07:00
|
|
|
unregister_filesystem(&btrfs_fs_type);
|
2007-08-30 02:47:34 +07:00
|
|
|
btrfs_exit_sysfs();
|
2008-03-25 02:02:07 +07:00
|
|
|
btrfs_cleanup_fs_uuids();
|
2010-12-17 13:21:50 +07:00
|
|
|
btrfs_exit_compress();
|
2014-01-12 09:22:46 +07:00
|
|
|
btrfs_hash_exit();
|
2007-03-21 22:12:56 +07:00
|
|
|
}
|
|
|
|
|
2014-02-02 04:27:56 +07:00
|
|
|
late_initcall(init_btrfs_fs);
|
2007-03-21 22:12:56 +07:00
|
|
|
module_exit(exit_btrfs_fs)
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|