Commit Graph

89 Commits (8e4b7e883abfca81cd864808da729b2227cff34c)

Author SHA1 Message Date
Sergei Trofimovich 8e4b7e883a mkfs.btrfs: write zeroes instead on uninitialized data.
Found by valgrind:
==8968== Use of uninitialised value of size 8
==8968==    at 0x41CE7D: crc32c_le (crc32c.c:98)
==8968==    by 0x40A1D0: csum_tree_block_size (disk-io.c:82)
==8968==    by 0x40A2D4: csum_tree_block (disk-io.c:105)
==8968==    by 0x40A7D6: write_tree_block (disk-io.c:241)
==8968==    by 0x40ACEE: __commit_transaction (disk-io.c:354)
==8968==    by 0x40AE9E: btrfs_commit_transaction (disk-io.c:385)
==8968==    by 0x42CF66: make_image (mkfs.c:1061)
==8968==    by 0x42DE63: main (mkfs.c:1410)
==8968==  Uninitialised value was created by a stack allocation
==8968==    at 0x42B5FB: add_inode_items (mkfs.c:493)

1. On-disk inode format has reserved (and thus, random at alloc time) fields:
   btrfs_inode_item: __le64 reserved[4]
2. Sometimes extents are created on disk without writing data there.
   (Or at least not all data is written there). Kernel code always had
   it kzalloc'ed.
Zero them all.

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
2011-10-25 09:18:58 -04:00
Sergei Trofimovich f509f1762e mkfs.btrfs: fix symlink names writing
Found by valgrind:
==8968== Use of uninitialised value of size 8
==8968==    at 0x41CE7D: crc32c_le (crc32c.c:98)
==8968==    by 0x40A1D0: csum_tree_block_size (disk-io.c:82)
==8968==    by 0x40A2D4: csum_tree_block (disk-io.c:105)
==8968==    by 0x40A7D6: write_tree_block (disk-io.c:241)
==8968==    by 0x40ACEE: __commit_transaction (disk-io.c:354)
==8968==    by 0x40AE9E: btrfs_commit_transaction (disk-io.c:385)
==8968==    by 0x42CF66: make_image (mkfs.c:1061)
==8968==    by 0x42DE63: main (mkfs.c:1410)
==8968==  Uninitialised value was created by a stack allocation
==8968==    at 0x42B5FB: add_inode_items (mkfs.c:493)

readlink(2) does not write '\0' for us, so make it manually.

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
2011-10-25 09:18:58 -04:00
Sergei Trofimovich 545b52c2fa mkfs.btrfs: fail on scandir error (-r mode)
mkfs.btrfs does not handle relative pathnames for now. When
they are passed to it it creates empty image. So first time
I thought it does not work at all.

This patch adds error handling for scandir(). With patch it behaves
this way:

    $ mkfs.btrfs -r ./root
    ...
    fs created label (null) on output.img
            nodesize 4096 leafsize 4096 sectorsize 4096 size 256.00MB
    Btrfs v0.19-52-g438c5ff-dirty
    scandir for ./root failed: No such file or directory
    unable to traverse_directory
    Making image is aborted.
    mkfs.btrfs: mkfs.c:1402: main: Assertion `!(ret)' failed.

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
2011-10-25 09:18:58 -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
Donggeun Kim 4e64e05c6b btrfs-progs: Add new feature to mkfs.btrfs to make file system image file from source directory
Changes from V1 to V2:
- support extended attributes
- move btrfs_alloc_data_chunk function to volumes.c
- fix an execution error when additional useless parameters are specified
- fix traverse_directory function so that the insertion functions for the common items are invoked in a single point

The extended attributes is implemented through llistxattr and getxattr function calls.

Thanks

Signed-off-by: Donggeun Kim <dg77.kim@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-10-25 09:18:31 -04:00
Josef Bacik b8802ae3fa Btrfs-progs: add support for mixed data+metadata block groups
So alot of crazy people (I'm looking at you Meego) want to use btrfs on phones
and such with small devices.  Unfortunately the way we split out metadata/data
chunks it makes space usage inefficient for volumes that are smaller than
1gigabyte.  So add a -M option for mixing metadata+data, and default to this
mixed mode if the filesystem is less than or equal to 1 gigabyte.  I've tested
this with xfstests on a 100mb filesystem and everything is a-ok.

Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-10-25 09:18:31 -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
Luca Bruno 6fa19b04d9 Fix printf format casting errors
There are still some warnings of the form:

format '%llu' expects type 'long long unsigned int' but argument has type 'u64'

In conjunction with -Werror, this is causing some build failures.
Now they're properly casted, avoiding compiler warnings.

Signed-off-by: Luca Bruno <lucab@debian.org>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-06-03 12:15:40 -04:00
Luca Bruno 3fb5c031fe Add -V|--version to mkfs.btrfs argument parser
mkfs.btrfs now prints its version when invoked with -V|--version
and exits without error.

All other mkfs.* tools provide this feature and follow this
implicit argument naming convention, as it is commonly used to
check for helper tools presence.

The corrisponding manual already mentions this option, no need to
touch it.

Signed-off-by: Luca Bruno <lucab@debian.org>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-06-03 12:15:40 -04:00
Chris Mason 6a63d49114 Fix mispatch of the experimental warnings
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-01-11 07:58:35 -05:00
Shen Feng 238fdcca20 Fix mkfs.btrfs usage help to match the current args
Signed-off-by: Shen Feng <shen@cn.fujitsu.com>
2009-01-07 14:57:12 -05:00
Shen Feng f7f0e8567f Make the minimum filesystem size error message more clear
Signed-off-by: Shen Feng <shen@cn.fujitsu.com>
2009-01-07 14:57:12 -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
Chris Mason d79f499eae Btrfs: move data checksumming into a dedicated tree
Btrfs stores checksums for each data block.  Until now, they have
been stored in the subvolume trees, indexed by the inode that is
referencing the data block.  This means that when we read the inode,
we've probably read in at least some checksums as well.

But, this has a few problems:

* The checksums are indexed by logical offset in the file.  When
compression is on, this means we have to do the expensive checksumming
on the uncompressed data.  It would be faster if we could checksum
the compressed data instead.

* If we implement encryption, we'll be checksumming the plain text and
storing that on disk.  This is significantly less secure.

* For either compression or encryption, we have to get the plain text
back before we can verify the checksum as correct.  This makes the raid
layer balancing and extent moving much more expensive.

* It makes the front end caching code more complex, as we have touch
the subvolume and inodes as we cache extents.

* There is potentitally one copy of the checksum in each subvolume
referencing an extent.

The solution used here is to store the extent checksums in a dedicated
tree.  This allows us to index the checksums by phyiscal extent
start and length.  It means:

* The checksum is against the data stored on disk, after any compression
or encryption is done.

* The checksum is stored in a central location, and can be verified without
following back references, or reading inodes.

This makes compression significantly faster by reducing the amount of
data that needs to be checksummed.  It will also allow much faster
raid management code in general.

The checksums are indexed by a key with a fixed objectid (a magic value
in ctree.h) and offset set to the starting byte of the extent.  This
allows us to copy the checksum items into the fsync log tree directly (or
any other tree), without having to invent a second format for them.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
2008-12-08 17:00:31 -05: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
Zheng Yan 09ab0365ff update mkfs.btrfs for the new space balancing code
The new space balancing code needs a subvol to store the
temporary inode for data extent relocation.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
2008-09-26 10:26:53 -04:00
Zheng Yan 428b7fa630 Full back reference support
This patch makes the back reference system to explicit record the
location of parent node for all types of extents. The location of
parent node is placed into the offset field of backref key. Every
time a tree block is balanced, the back references for the affected
lower level extents are updated.
2008-09-23 12:29:10 -04:00
Josef Bacik 059c20b384 btrfs-progs new dir index support 2008-07-24 12:13:32 -04:00
Chris Mason 9864c90760 Print the version string in a few programs 2008-07-24 12:13:30 -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 f86e8be3f8 Fix uninitialized variables, and use -O so gcc starts checking for them
Gcc only sends warnings for uninitialized variables when you compile with -O,
and there were a couple of bugs sprinkled in the code.  The biggest was the
alloc_start variable for mkfs, which can cause strange things to happen.

(thanks to Gabor Micsko for helping to find this)
2008-05-01 10:22:47 -04:00
Chris Mason b327761ead Add btrfs-vol command to balance, add and (eventually) remove devices 2008-04-28 16:44:22 -04:00
Chris Mason 083faf794f Add mkfs.btrfs -A offset to control allocation start on devices
This is a utility option for the resizer, it makes sure to allocate
at offset bytes in the disk or higher.  It ensures the resizer will have
something to move when testing it.
2008-04-25 16:55:21 -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 0e08036ee4 Add checks to avoid adding the same device twice during mkfs 2008-04-18 10:45:17 -04:00
Chris Mason 734603d927 Use better chunk sizes for small and large filesystems 2008-04-18 10:31:42 -04:00
Chris Mason 588bb9dfff Add support for filesystem labels via mkfs.btrfs -L 2008-04-18 10:31:42 -04:00
Chris Mason 1f81c1b6fc Add raid10 support 2008-04-16 11:14:21 -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 4f9e7f0bae Use leafsize and nodesize == pagesize for now 2008-04-09 19:49:01 -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 a57a255e44 Add mkfs options for data and metadata mirroring modes
mkfs.btrfs --data {raid0,raid1,single}
mkfs.btrfs --metadata {raid0,raid1,single}

In single mode, no extra duplication or striping is done.
In raid0 mode, blocks are spread across all of the available devices
In raid1 mode, blocks are mirrored across two devices.

For metadata, if raid1 is used and there is only one device, the
metadata is duplicated on that single spindle.

The defaults are raid0 for data and raid1 for metadata
2008-04-03 16:35:48 -04:00
Chris Mason c7be130df7 Add support for single single duplication of metadata 2008-04-03 16:35:48 -04:00
Chris Mason a6de0bd778 Add mirroring support across multiple drives 2008-04-03 16:35:48 -04:00
Chris Mason 6a87b4c00a Use getopt_long and introduce long mkfs options. -s now means --sectorsize 2008-04-01 11:08:13 -04:00
Goldwyn Rodrigues c2c5e3e7e5 check if partition is mounted before mkfs
This saves from the blunder of formatting a live mounted filesystem.
This can be extended to get the mount flags of the filesystem
mounted.

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@gmail.com>
2008-04-01 10:36:46 -04:00
Chris Mason 0dcfa3b827 Walk all block devices looking for btrfs 2008-03-24 15:05:44 -04:00
Chris Mason 26afd0f31d ioctls to scan for btrfs filesystems 2008-03-24 15:04:49 -04:00
Chris Mason 510be29677 Add support for multiple devices per filesystem 2008-03-24 15:03:18 -04:00
Chris Mason 0c6513b1d1 mkfs: Zero 2MB at the start and end of the device
But, on sparc, don't zero the first 1k.
2008-02-15 11:19:26 -05:00
Yan 7777e63b42 Update btrfs-progs to match kernel sources 2008-01-04 10:38:22 -05:00
Chris Mason 7e03dadf20 Add online resizing ioctls
btrfsctl -r size mount_point
2007-12-21 16:25:35 -05:00
Chris Mason 29bf1724b1 Reorder extent back refs to differentiate file data from btree blocks 2007-12-13 11:12:45 -05:00
Chris Mason 140d96a562 Create macros to generation set/get funcs for on disk structures 2007-12-12 14:39:46 -05:00
Chris Mason 4122e65cb2 Add back pointers from extents to the file or btree referencing them 2007-12-11 09:21:42 -05:00
Chris Mason 73372dcf8f Add generation numbers to block pointers 2007-12-09 13:46:24 -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