Commit Graph

296 Commits (master)

Author SHA1 Message Date
Eric Sandeen dbeedbed2a btrfs-progs: remove duplicate __setup_root
__setup_root() was present in find-root.c as well
as disk-io.c.  No need for the cut and paste, just
use the one in disk-io.c

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Zach Brown <zab@redhat.com>
2013-02-05 16:09:41 -08:00
Zach Brown 7d365c5a87 btrfs-progs: don't write memory after sb to disk
struct btrfs_super is about 3.5k but a few writing paths were writing it
out as the full 4k BTRFS_SUPER_INFO_SIZE, leaking a few hundred bytes
after the super_block onto disk.  In practice this meant the memory
after super_copy in struct btrfs_fs_info and whatever came after it in
the heap.

Signed-off-by: Zach Brown <zab@redhat.com>
2013-02-05 16:09:39 -08:00
Zach Brown ea0ac9416f btrfs-progs: return error from commit_tree_roots()
Errors cow-ing the root block are silently being dropped.  This is
just a step towards error handling because both the caller and calee
assert on errors.

Signed-off-by: Zach Brown <zab@redhat.com>
2013-02-05 16:09:38 -08:00
Zach Brown 52162700bb btrfs-progs: treat super.magic as an le64
The super block magic is a le64 whose value looks like an unterminated
string in memory.  The lack of null termination leads to clumsy use of
string functions and causes static analysis tools to warn that the
string will be unterminated.

So let's just treat it as the le64 that it is.  Endian wrappers are used
on the constant so that they're compiled into run-time constants.

Signed-off-by: Zach Brown <zab@redhat.com>
2013-02-05 16:09:32 -08:00
David Woodhouse 4d48b96b28 Add basic RAID[56] support
David Woodhouse originally contributed this code, and Chris Mason
changed it around to reflect the current design goals for raid56.

The original code expected all metadata and data writes to be full
stripes.  This meant metadata block size == stripe size, and had a few
other restrictions.

This version allows metadata blocks smaller than the stripe size.  It
implements both raid5 and raid6, although it does not have code to
rebuild from parity if one of the drives is missing or incorrect.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-02-01 14:22:07 -05:00
Chris Mason 8fe354744c Clear caches when opening and closing devices
This should fix problems with cache aliases in the kernel
2013-02-01 10:51:10 -05:00
Stefan Behrens 5f3ab71103 Btrfs-progs: fix an off-by-one in write_dev_supers()
Fix an off-by-one in write_dev_supers().

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
2013-01-22 12:31:41 +01:00
Kenji Okimoto 1cce8d72f2 btrfs-progs: check malloc() result
Signed-off-by: Kenji Okimoto <okimoto@clear-code.com>
2013-01-17 18:27:55 +01:00
Kenji Okimoto 057d6ea34c btrfs-progs: plug a memory leak reported by cppcheck
[src/btrfs/disk-io.c:462]: (error) Memory leak: log_root

Signed-off-by: Kenji Okimoto <okimoto@clear-code.com>
2013-01-17 18:27:55 +01:00
Goffredo Baroncelli 6eba900295 Correct un-initialized fsid variable 2012-10-04 20:32:19 -04:00
Chris Mason 47b104b7f1 btrfsck: add --init-csum-tree to replace the csum root with an empty one
This will effectively delete all of your crcs, but at least you'll
be able to mount the FS with nodatasum.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
2012-02-09 10:38:05 -05:00
Chris Mason e7580bb296 Add open_ctree_fs_info for partial FS opens
fsck needs to be able to open a damaged FS, which means open_ctree needs
to be able to return a damaged FS.

This adds a new open_ctree_fs_info which can be used to open any and all
roots that are valid.  btrfs-debug-tree is changed to use it.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
2012-02-05 16:11:48 -05:00
Chris Mason f25e1d16a5 btrfs-progs: remove old debugging statement
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-10-27 23:48:47 -04:00
Josef Bacik be826706b5 btrfs-progs: add a recovery utility to pull files from damanged filesystems
Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-10-27 12:49:54 -04:00
Anton Blanchard fa81a569ac btrfs-progs: cast u64 to long long to avoid printf warnings
When building on ppc64 I hit a number of warnings in printf:

btrfs-map-logical.c:69: error: format ‘%Lu’ expects type ‘long long
unsigned int’, but argument 4 has type ‘u64’

Fix them.

Signed-off-by: Anton Blanchard <anton@samba.org>
Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
2011-10-25 09:18:57 -04:00
Chris Ball fcdc0929c6 Fix unused-but-set errors in gcc-4.6
gcc-4.6 (as shipped in Fedora) turns on -Wunused-but-set-variable by
default, which breaks the build when combined with -Wall, e.g.:

debug-tree.c: In function ‘print_extent_leaf’:
debug-tree.c:45:13: error: variable ‘last_len’ set but not used [-Werror=unused-but-set-variable]
debug-tree.c:44:13: error: variable ‘last’ set but not used [-Werror=unused-but-set-variable]
debug-tree.c:41:21: error: variable ‘item’ set but not used [-Werror=unused-but-set-variable]
cc1: all warnings being treated as errors

This patch fixes the errors by removing the unused variables.

Signed-off-by: Chris Ball <cjb@laptop.org>
Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
2011-10-25 09:18:32 -04:00
Chris Mason b4382217f1 Btrfs-progs: add a btrfs-select-super command to overwrite the super
Btrfs stores multiple copies of the superblock, and for common power-failure
crashes where barriers were not in use, one of the super copies is often
valid while the first copy is not.

This adds a btrfs-select-super -s N /dev/xxx command, which can
overwrite all the super blocks with a copy that you have already
determined is valid with btrfsck -s

Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-10-25 09:18:31 -04:00
Chris Mason 7cd060deea Fill missing devices so degraded filesystems can be read
When a device is missing, the btrfs tools need to be able to read alternate
copies from the remaining devices.  This creates placeholder devices
that always return -EIO so the tools can limp along.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-04-22 14:52:40 -04:00
Jeff Mahoney bba632af0e Fix use after free in close_ctree
After the roots are closed, root is freed. Yet close_ctree continues
to use it. It works generally because no new memory is allocated in
the interim, but with glibc malloc perturbing enabled, it crashes
every time. This is because root->fs_info points to garbage.

This patch uses the already-cached fs_info variable for the rest of
the accesses and fixes the crash.

This issue was reported at:
https://bugzilla.novell.com/show_bug.cgi?id=603620

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
2010-09-23 20:26:50 -04:00
Zhu Yanhai b227b4dd7c Make csum_tree_block_size complain about the right thing.
It dereferenced a wrong pointer before.

Signed-off-by: Zhu Yanhai <yanhai.zhu@linux.intel.com>
2010-09-23 20:26:49 -04:00
Yan Zheng 50860d6e31 Update converter for the new format
Signed-off-by: Yan Zheng <zheng.yan@oracle.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-06-08 13:31:10 -04:00
Chris Mason 95d3f20b51 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.

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
2009-06-08 13:30:36 -04:00
nick d 99b6d94018 Fix spelling mistake when running 'btrfsck' when argument doesn't exist.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-06-03 12:15:40 -04:00
Chris Mason cc04d99e90 Add scan of the btrfs log tree to btrfs-debug-tree 2009-04-15 14:30:14 -04:00
Thadeu Lima de Souza Cascardo af250420ca btrfsck: Exit and print error message when not able to open a device
If btrfsck is not able to open a device, it segfaults. This fixes it and
prints an error message too.
2009-01-21 13:59:36 -05:00
Yan Zheng 0d53b212d8 Btrfs: update converter for the new disk format
This patch updates the ext3 to btrfs converter for the new
disk format. This mainly involves changing the convert's
data relocation and free space management code. This patch
also ports some functions from kernel module to btrfs-progs.
Thank you,

Signed-off-by: Yan Zheng <zheng.yan@oracle.com>
2008-12-17 16:10:07 -05:00
Yan Zheng 5ccd1715fa superblock duplication
This patch updates btrfs-progs for superblock duplication.
Note: I didn't make this patch as complete as the one for
kernel since updating the converter requires changing the
code again. Thank you,

Signed-off-by: Yan Zheng <zheng.yan@oracle.com>
2008-12-05 12:21:31 -05:00
Josef Bacik 1148e55804 btrfs-progs: support for different csum algorithims
This is the btrfs-progs version of the patch to add the ability to have
different csum algorithims.  Note I didn't change the image maker since it
seemed a bit more complicated than just changing some stuff around so I will let
Yan take care of that.

Everything else was converted and for now a mkfs just
sets the type to be BTRFS_CSUM_TYPE_CRC32.

Signed-off-by: Josef Bacik <jbacik@redhat.com>
2008-12-02 09:58:23 -05:00
Yan Zheng aa62e84c84 Btrfs image tool
This patch adds btrfs image tool. The image tool is
a debugging tool that creates/restores btrfs metadump
image.

Signed-off-by: Yan Zheng <zheng.yan@oracle.com>
2008-11-20 09:52:48 -05:00
Yan Zheng 4d1d3a59d6 update btrfs-progs for seed device support
This patch does the following:

1) Update device management code to match the kernel code.

2) Allocator fixes.

3) Add a program called btrfstune to set/clear the SEEDING
   super block flags.
2008-11-18 10:40:06 -05:00
Chris Mason 0a7869d69d Avoid tree of tree root cow when committing a clean FS
The root node generation number code made commit_tree_root look like the
kernel code.  It forces a cow of the tree of tree roots even when
the FS hasn't changed.

This causes errors during fsck and other readonly operations.  This adds
a check to see if commit_tree_root is going to trigger writes to the
tree of tree roots, and bails if none are pending.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
2008-10-30 11:11:39 -04:00
Yan Zheng 38702ea7c6 Add root tree pointer transaction ids
This patch adds transaction IDs to root tree pointers.
Transaction IDs in tree pointers are compared with the
generation numbers in block headers when reading root
blocks of trees. This can detect some types of IO errors.

Signed-off-by: Yan Zheng <zheng.yan@oracle.com>
2008-10-29 14:07:47 -04:00
Chris Mason 351d17fca2 Verify parent generation number on btree reads 2008-05-13 13:48:58 -04:00
Chris Mason 9a9bdd6047 Pass down the expected generation number when reading tree blocks 2008-05-12 13:51:24 -04:00
Chris Mason a62332eeb2 Add a readonly flag open_ctree to force RO opens 2008-05-05 09:45:26 -04:00
Chris Mason 8bfbb6b6f8 Update the Ext3 converter
The main changes in this patch are adding chunk handing and data relocation
ability. In the last step of conversion, the converter relocates data in system
chunk and move chunk tree into system chunk. In the rollback process, the
converter remove chunk tree from system chunk and copy data back.

Regards
YZ
---
2008-04-22 14:06:56 -04:00
Chris Mason 358564890a Add a command to show all of the btrfs filesystems on the box (btrfs-show) 2008-04-22 14:06:31 -04:00
Chris Mason 951fd7371c Add chunk uuids and update multi-device back references
Block headers now store the chunk tree uuid

Chunk items records the device uuid for each stripes

Device extent items record better back refs to the chunk tree

Block groups record better back refs to the chunk tree

The chunk tree format has also changed.  The objectid of BTRFS_CHUNK_ITEM_KEY
used to be the logical offset of the chunk.  Now it is a chunk tree id,
with the logical offset being stored in the offset field of the key.

This allows a single chunk tree to record multiple logical address spaces,
upping the number of bytes indexed by a chunk tree from 2^64 to
2^128.
2008-04-15 15:42:08 -04:00
Chris Mason d1b04c2112 Write all super blocks during commit 2008-04-10 16:22:00 -04:00
Chris Mason fd2d0af0bf Retry metadata reads in the face of checksum failures 2008-04-09 16:28:12 -04:00
Chris Mason 1b74adf90b Change btrfs_map_block to return a structure with mappings for all stripes 2008-04-09 16:28:12 -04:00
Chris Mason a37e1e7204 Recow all roots at the end of mkfs
The mkfs code bootstraps the filesystem on a single device.  Once
the raid block groups are setup, it needs to recow all of the blocks so
that each tree is properly allocated.
2008-04-04 15:42:17 -04:00
Chris Mason a6de0bd778 Add mirroring support across multiple drives 2008-04-03 16:35:48 -04:00
Alex Chiang 857e9a2a63 btrfs-progs: Fix printf format casting errors
We get lots of warnings of the flavor:

utils.c:441: warning: format '%Lu' expects type 'long long unsigned int' but argument 2 has type 'u64'

And thanks to -Werror, the build fails. Clean up these printfs
by properly casting the arg to the format specified.

Signed-off-by: Alex Chiang <achiang@hp.com>
2008-04-01 10:52:22 -04:00
Chris Mason ad67cd73b7 Update struct btrfs_header flags, and use it to indicate buffers are written 2008-04-01 10:20:06 -04:00
Chris Mason 0dcfa3b827 Walk all block devices looking for btrfs 2008-03-24 15:05:44 -04:00
Chris Mason 1f3ba6a3f9 Btrfsck updates for multi-device filesystems 2008-03-24 15:04:37 -04:00
Chris Mason d12d4c7203 Dynamic chunk allocation 2008-03-24 15:03:58 -04:00
Chris Mason 510be29677 Add support for multiple devices per filesystem 2008-03-24 15:03:18 -04:00
Chris Mason 80791984f6 Rename the extent_map code to extent_io
This mirrors the changes in the kernel code.
2008-03-04 11:16:54 -05:00
Yan d1b729ac2b Add rollback support for the converter
This patch adds rollback support for the converter,  the converter can
roll back a conversion if the image file haven't been modified.  In
addition,  I rearrange some codes in convert.c and add a few comments.
2008-01-08 15:56:32 -05:00
Yan 84b99666be Update find_free_extent for the ext3 conversion tool
This patch adds customized find_free_extent support to btrfs-progs,
the conversion program requires this.
2008-01-04 10:41:19 -05:00
Yan 7777e63b42 Update btrfs-progs to match kernel sources 2008-01-04 10:38:22 -05:00
Chris Mason c4603e35d7 Verify extent back references in btrfsck 2007-12-14 11:00:30 -05:00
Yan 07a4f1b81d Update btrfs-progs to better match the kernel 2007-12-05 10:41:38 -05:00
Chris Mason 1883251686 Add simple stripe size parameter 2007-11-30 11:30:24 -05:00
Chris Mason 678af9b3a4 Remove the last radix tree (block_group_cache) 2007-10-17 09:58:56 -04:00
Chris Mason 167388ab2b Make the crc32c code match what the kernel modules are currently doing 2007-10-15 16:25:43 -04:00
Chris Mason 28de03cb0a Create a slightly more generic extent-caching structure 2007-10-15 16:25:41 -04:00
Chris Mason 38f79f9077 Switch to byte granular allocations 2007-10-15 16:25:14 -04:00
Chris Mason 08c66b7738 Stop using radix trees to record pending allocations 2007-10-15 16:25:04 -04:00
Chris Mason f12d799856 Allow large blocks 2007-10-15 16:24:39 -04:00
Josef Bacik 4623a01bdc calculate checksums during IO 2007-06-28 16:20:29 -04:00
Chris Mason d9f1317c7d add GPLv2 2007-06-12 09:07:11 -04:00
Chris Mason b53a236c3e remove device tree 2007-06-09 09:22:37 -04:00
Chris Mason 5856b7e124 start of block group code 2007-04-26 16:46:06 -04:00
Chris Mason d7260c060c faster btrfsck 2007-04-23 15:56:27 -04:00
Chris Mason 2f2264fc2d add owner and type fields to the extents aand block headers 2007-04-20 20:23:29 -04:00
Chris Mason 3eaaf935e5 add some support for multiple devices to progs 2007-04-12 12:14:47 -04:00
Chris Mason d23ea8706c early support for multiple devices 2007-04-11 13:57:55 -04:00
Chris Mason 1b4ca380ed drop the inode map tree 2007-04-10 12:13:29 -04:00
Chris Mason 43f6ab83bf btrfsctl 2007-04-10 09:27:30 -04:00
Chris Mason d785b7d058 uuids 2007-04-05 14:29:12 -04:00
Chris Mason 8a2c8123c5 create a root dir in mkfs 2007-03-21 11:13:29 -04:00
Chris Mason b55672a2a1 Better block record keeping, real mkfs 2007-03-20 20:35:03 -04:00
Chris Mason ab61081c6c change dir-test to insert inode_items 2007-03-20 15:57:25 -04:00
Chris Mason 099f1ae6e4 Add inode map, and the start of file extent items 2007-03-20 14:38:32 -04:00
Chris Mason f247156e4f transaction handles everywhere 2007-03-16 16:20:31 -04:00
Chris Mason 7a0a809b4c variable block size support 2007-03-14 14:14:43 -04:00
Chris Mason d9c9960f8d Change the super to point to a tree of trees to enable persistent snapshots 2007-03-13 16:47:54 -04:00
Chris Mason aa60202f13 rename funcs and structs to btrfs 2007-03-13 10:46:10 -04:00
Chris Mason 8e17fab249 get/set for struct header fields 2007-03-12 12:01:18 -04:00
Chris Mason 2db1ff3570 fix leak in btrfs_drop_snapshot 2007-03-12 09:03:27 -04:00
Chris Mason 2adfc44778 Fixup last found extent caching 2007-03-07 16:15:30 -05:00
Chris Mason 79b90e3fdf Fixup reference counting on cows 2007-03-06 20:08:01 -05:00
Chris Mason 7da449a2f6 early reference counting 2007-03-02 16:08:05 -05:00
Chris Mason bd530a2cff period commit during initial fill in the random tester 2007-03-02 10:06:43 -05:00
Chris Mason 11bc1cd2a5 Fix extent code to use merge during delete
Remove implicit commit in del_item and insert_item
Add implicit commit to close()
Add commit op in random-test
2007-03-02 09:47:58 -05:00
Chris Mason a71a25da69 pretend page cache & commit code 2007-03-01 18:59:40 -05:00
Chris Mason 67a8d4bbac fixup dbfile perms 2007-02-26 10:46:55 -05:00
Chris Mason 74556aa757 Break up ctree.c a little
Extent fixes
2007-02-24 06:24:44 -05:00
Chris Mason c6c63c3e74 Block sized tree extents and extent deletion 2007-02-23 08:38:36 -05:00
Chris Mason e0bafb2999 switch to early splits 2007-02-22 11:39:13 -05:00
Chris Mason 72777fbe29 extent fixes 2007-02-21 17:04:57 -05:00
Chris Mason c12e4863d2 early extent mapping support 2007-02-20 16:40:44 -05:00
Chris Mason 215ad20a9b Add backing store, memory management 2007-02-02 09:18:22 -05:00