summaryrefslogtreecommitdiff
path: root/mkfs.c
Commit message (Collapse)AuthorAge
* btrfs-progs: mkfs: catch errors after transaction startDavid Sterba2015-08-31
| | | | | | Replace missing or BUG_ON in main(). Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: Cleanup temporary chunk to avoid strange balance behavior.Qu Wenruo2015-07-14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | [BUG] # mkfs.btrfs /dev/sdb /dev/sdd -m raid0 -d raid0 # mount /dev/sdb /mnt/btrfs # btrfs balance start /mnt/btrfs # btrfs fi df /mnt/btrfs Data, single: total=1.00GiB, used=320.00KiB System, single: total=32.00MiB, used=16.00KiB Metadata, RAID0: total=256.00MiB, used=112.00KiB GlobalReserve, single: total=16.00MiB, used=0.00B Only metadata stay RAID0. Data and system goes from RAID0 to single. [REASON] The problem is caused by the temporary single chunk. In mkfs, it will always create single data/metadata/sys chunk and them add device into the temporary btrfs. When doing all chunk balance, for data and syschunk, they are almost empty, so balance will move them into the single chunk and remove the old RAID0 chunk. For metadata, it has more data and will kick the metadata chunk pre alloc, so new RAID0 chunk is allocated and the old metadata is move there. Old RAID0 and single chunks are removed. [FIX] Now we add a new function to cleanup the temporary chunks at the end of mkfs routine. It will cleanup the chunks which is empty and its profile differs from the mkfs profile. So in balance, btrfs will always alloc a new chunk to keep the profile, other than moving data into the single chunk. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* Revert "btrfs-progs: mkfs: create only desired block groups for single device"Qu Wenruo2015-07-14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit 5f8232e5c8f0b0de0ef426274911385b0e877392. This commit causes a regression: $ mkfs.btrfs -f /dev/sda6 $ btrfsck /dev/sda6 Checking filesystem on /dev/sda6 UUID: 2ebb483c-1986-4610-802a-c6f3e6ab4b76 checking extents Chunk[256, 228, 0]: length(4194304), offset(0), type(2) mismatch with block group[0, 192, 4194304]: offset(4194304), objectid(0), flags(34) Chunk[256, 228, 4194304]: length(8388608), offset(4194304), type(4) mismatch with block group[4194304, 192, 8388608]: offset(8388608), objectid(4194304), flags(36) Block group[0, 4194304] (flags = 34) didn't find the relative chunk. Block group[4194304, 8388608] (flags = 36) didn't find the relative chunk. ...... The commit has the following bug causing the problem. 1) Typo forgets to add meta/data_profile for alloc_chunk. Only meta/data_profile is added to allocate a block group, but not chunk. 2) Type for the first system chunk is impossible to modify yet. The type for the first chunk and its stripe is hard coded into make_btrfs() function. So even we try to modify the type of the block group, we are unable to change the type of the first chunk. Causing the chunk type mismatch problem. The 1st bug can be fixed quite easily but the second is not. The good news is, the last patch "btrfs-progs: mkfs: Cleanup temporary chunk to avoid strange balance behavior." from my patchset can handle it quite well alone. So just revert the patch. New bug fix for btrfsck(err is 0 even chunk/extent tree is corrupted) and new test cases for mkfs will follow soon. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: create only desired block groups for single deviceDavid Sterba2015-07-03
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The filesystem creation has to solve some chicken-egg problems and creates some temporary objects. In our case it's an extra single/single pair of block groups that's not used unless the user asks that explicitly. Example: Data, single: total=8.00MiB, used=64.00KiB System, DUP: total=8.00MiB, used=16.00KiB System, single: total=4.00MiB, used=0.00B Metadata, DUP: total=153.56MiB, used=112.00KiB Metadata, single: total=8.00MiB, used=0.00B GlobalReserve, single: total=16.00MiB, used=0.00B Even with a single device filesystem and defaults, there's single block group for metadata and system. The single device case is easy to fix, we'll simply create the right type from the beginning. Example: Data, single: total=8.00MiB, used=64.00KiB System, DUP: total=4.00MiB, used=16.00KiB Metadata, DUP: total=136.00MiB, used=112.00KiB GlobalReserve, single: total=16.00MiB, used=0.00B Filesystem on top of multiple devices still leaves the single/single groups behind. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: drop unused argument from create_raid_groupsDavid Sterba2015-07-02
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: split data block group creation out of make_root_dirDavid Sterba2015-07-02
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move transaction start/commit out of make_root_dirDavid Sterba2015-07-01
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: split metadata group creation out of make_root_dirDavid Sterba2015-07-01
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: drop unused parameter from make_btrfsDavid Sterba2015-07-01
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move make_btrfs arguments to a structDavid Sterba2015-07-01
| | | | | | | No functional change, just introduce the structure and switch current users. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: print error within test_num_disk_vs_raidDavid Sterba2015-06-11
| | | | | | | | The error string buffer passed as an argument is of a fixed size, though we could print up to PATH_MAX + something bytes. Print the error message directly. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: print error within test_dev_for_mkfsDavid Sterba2015-06-11
| | | | | | | | The error string buffer passed as an argument is of a fixed size, though we could print up to PATH_MAX + something bytes. Print the error message directly. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: accept --help as option in the standalone utilitiesDavid Sterba2015-06-11
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: mkfs: make the summary more compactDavid Sterba2015-06-08
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Single device example: btrfs-progs v4.0.1-39 See http://btrfs.wiki.kernel.org for more information. Label: (null) UUID: a88bfc85-b454-4a32-8de7-276c01f04d58 Node size: 16384 Sector size: 4096 Filesystem size: 2.00GiB Block group profiles: Data: single 8.00MiB Metadata: single 8.00MiB System: single 4.00MiB SSD detected: no Incompat features: extref, skinny-metadata Number of devices: 1 Devices: ID SIZE PATH 1 2.00GiB /dev/sda Multiple devices: btrfs-progs v4.0.1-39 See http://btrfs.wiki.kernel.org for more information. Label: (null) UUID: 9db282ef-55f3-4070-a59f-012a654614b2 Node size: 16384 Sector size: 4096 Filesystem size: 8.00GiB Block group profiles: Data: RAID6 417.50MiB Metadata: RAID6 417.50MiB System: RAID6 20.00MiB SSD detected: no Incompat features: extref, raid56, skinny-metadata Number of devices: 4 Devices: ID SIZE PATH 1 2.00GiB /dev/sda 2 2.00GiB /dev/sdb 3 2.00GiB /dev/sdc 4 2.00GiB /dev/sdd Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: mkfs: drop mixed from summaryDavid Sterba2015-06-08
| | | | | | The mixed-bg incompat feature should be enough. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: mkfs, drop UUID from device summaryDavid Sterba2015-06-08
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: mkfs, move uuid to the end of device summaryDavid Sterba2015-06-08
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: mkfs: print the summaryGoffredo Baroncelli2015-06-08
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch prints the summary of the filesystem after the creation. The main fileds printed are: - devices list with their uuid, devid, path and size - raid profile (dup,single,raid0...) - leafsize/nodesize/sectorsize - filesystem features (raid56, extref, mixed-bg) - chunk size and type If the '-v' switched is passed, the output is more verbose; if the '-q' switched is passed, only the errors are printed. Below an example: BTRFS filesystem summary: Label: btrfs-test UUID: 14ae8a88-98ac-4f22-8441-79f76ec622f7 Node size: 4096 Leaf size: 4096 Sector size: 4096 Initial chunks: Data+Metadata: 9.01GiB System: 18.06MiB Metadata profile: RAID5 Data profile: RAID5 Mixed mode: YES SSD detected: NO Incompat features: mixed-bg, extref, raid56 Number of devices: 10 UUID ID SIZE PATH ------------------------------------ -- --------- ----------- df1c7f50-1980-4da2-8bc9-7ee6ffb0b554 1 50.00GiB /dev/vdb 32c808a0-cd7b-4497-a2c0-1d77a9854af9 2 50.00GiB /dev/vdc 3159782e-d108-40bc-9e15-090ecac160b4 3 50.00GiB /dev/vdd db7eaf0c-beb8-4093-a9d0-b9c25c146305 4 50.00GiB /dev/vde c367ca04-1f71-49c0-a331-11fc0b87e9fc 5 50.00GiB /dev/vdf e9b73c86-4058-4b3a-90ac-18741a276e70 6 50.00GiB /dev/vdg c4298b7a-ad41-4690-bf10-bf748b319413 7 50.00GiB /dev/vdh 1cf048c8-af8a-4225-b09a-5d12e9b217fa 8 2.00GiB /dev/vdi 7e157869-768a-4725-bad5-82e6bd05fd17 9 2.00GiB /dev/vdj 2c9431ac-c7f0-45a5-8529-cef8cf6e4033 10 2.00GiB /dev/vdk Total devices size: 356.01GiB Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: mkfs: track sizes of created block groupsGoffredo Baroncelli2015-06-08
| | | | | Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: return the fsid from make_btrfs()Goffredo Baroncelli2015-06-08
| | | | | | | | | | | The function make_btrfs() has as argument the fsid of the filesystem. If this fsid is empty or null make_btrfs() generates a new fsid. However If the buffer is valid (but the string is empty) the generated fsid is copied back to the caller. Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it> Reviewed-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: mkfs: do not try to register non-block-devicesDavid Sterba2015-06-08
| | | | | | | | | | | | | | | | | A mkfs on a regular file will try to call the DEV_SCAN ioctl that will take the loop through the kernel and fail: ERROR: device scan failed './test.img' - Block device required If a user without permission to open the control device tries to mkfs a regular file, an error message is printed: failed to open /dev/btrfs-control skipping device registration: Permission denied So we should not try to pass a non-block-device besides that this makes the --quiet option more quiet. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: mkfs: move info message out of btrfs_add_to_fsidDavid Sterba2015-06-08
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: mkfs: accept mixed case for profile namesDavid Sterba2015-06-06
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: mkfs: add option to make it quietDavid Sterba2015-06-06
| | | | | | | | Add option to silecne mkfs and print only errors, warnings or info on user request like features or help. Based on patch from Goffredo Baroncelli <kreijack@inwind.it> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: mkfs: check metadata redundancySam Tygier2015-06-02
| | | | | | | | | | | | | | | | Currently BTRFS allows you to make bad choices of data and metadata levels. For example -d raid1 -m raid0 means you can only use half your total disk space, but will lose everything if 1 disk fails. It should give a warning in these cases. When making a filesystem, check that metadata mode is at least as redundant as the data mode. For example give warning when: -d raid1 -m raid0 Signed-off-by: Sam Tygier <samtygier@yahoo.co.uk> [make the check more visible in mkfs output] Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: add info about list-all to the helpAnand Jain2015-06-01
| | | | | | | | mkfs.btrfs -O list-all is a good options to list features, publish it in the help. Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: getopt, use symbolic name for argument requirementsDavid Sterba2015-04-08
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: cleanup option index argument from getopt_longDavid Sterba2015-04-08
| | | | | | | We're not using it anywhere. The best practice is to add enums with values > 255 for the long options, option index counting is error prone. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: print fs features filtered by a maskDavid Sterba2015-04-07
| | | | | | | mkfs and convert will not support the same features, -O will print only the list according to the given mask. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: move feature parsing from mkfs to utilsDavid Sterba2015-04-07
| | | | | | | We'll use them in convert as well. Move defines and the interface functions to utils.*. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: mkfs, deprecate leafsize and clean up the codeDavid Sterba2015-04-07
| | | | | | | Using the --leafsize will issue a warning. Replace leafsize with nodesize in the mkfs-related code. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: mkfs, add required arguments to help stringsDavid Sterba2015-03-24
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: mkfs, align help stringsDavid Sterba2015-03-24
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: mkfs: Move out some nodesize codeSebastian Thorarensen2015-03-23
| | | | | | | | | | | Move the constant DEFAULT_MKFS_LEAF_SIZE to utils.h and rename it to BTRFS_MKFS_DEFAULT_NODE_SIZE for consistency. Move the function check_leaf_or_node_size to utils.c and rename it to btrfs_check_node_or_leaf_size. Signed-off-by: Sebastian Thorarensen <sebth@naju.se> [added btrfs_ prefix] Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: autoconf: use standard PACKAGE_* macrosKarel Zak2015-01-28
| | | | | | | | | | | | | - use standard PACKAGE_{NAME,VERSION,STRING,URL,...} autoconf macros rather than homemade BTRFS_BUILD_VERSION - don't #include version.h, now the file is necessary for library API only Note that "btrfs version" returns "btrfs-progs <version>" instead of the original confusing "btrfs <version>". Signed-off-by: Karel Zak <kzak@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: drop feature defines from C files, in favour of CFLAGS definesDimitri John Ledkov2015-01-27
| | | | | | | | | | | | | | | | | | | | | | glibc 2.10+ (5+ years old) enables all the desired features: _XOPEN_SOURCE 700, __XOPEN2K8, POSIX_C_SOURCE, DEFAULT_SOURCE; with a single _GNU_SOURCE define in the makefile alone. For portability to other libc implementations (e.g. dietlibc) _XOPEN_SOURCE=700 is also defined. This also resolves Debian bug report filed by Michael Tautschnig - "Inconsistent use of _XOPEN_SOURCE results in conflicting declarations". Whilst I was not able to reproduce the results, the reported fact is that _XOPEN_SOURCE set to 500 in one set of files (e.g. cmds-filesystem.c) generates/defines different struct stat from other files (cmds-replace.c). This patch thus cleans up all feature defines, and sets them at a consistent level. Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=747969 Signed-off-by: Dimitri John Ledkov <dimitri.j.ledkov@intel.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: make getopt tables static constDavid Sterba2015-01-19
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: cleanup, move getop long options close to their useDavid Sterba2015-01-19
| | | | | | Move long_option defintions just before getopt_long everywhere. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: include headers required for musl-libcMerlijn Wajer2014-12-18
| | | | | | | | This fixes various compilation errors where PATH_MAX and XATTR_SIZE_MAX were missing. To my knowledge, this should have no bad side effects. Signed-off-by: Merlijn Wajer <merlijn@wizzup.org> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: mkfs: make skinny-metadata defaultDavid Sterba2014-12-10
| | | | | | | According to public poll, this is desired and deemed to be safe. Feature introduced in kernel 3.10 (Jun 2013). Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: mkfs should be consistent in calling register deviceAnand Jain2014-10-16
| | | | | | | | | | | | | | | | | | | | | | | | | | | When we have one device we don't call register device. (in fact not mandatory, but to make it consistent) And when we have more than one we call register device. reproducer: Nothing in the kernel device list cat /proc/fs/btrfs/devlist | egrep fsid | wc -l 0 mkfs.btrfs will automatically call register device when devices is more than 1. mkfs.btrfs -f /dev/sdb /dev/sdc cat /proc/fs/btrfs/devlist | egrep fsid | wc -l 1 But it does not when there is only one device mkfs.btrfs -f /dev/sdb cat /proc/fs/btrfs/devlist | egrep fsid | wc -l 0 Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: mkfs make --uuid require an argumentDavid Sterba2014-08-22
| | | | | | | $ mkfs.btrfs --uuid 1234... /dev/sdx Error: error checking 1234... status: No such file or directory Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: mkfs: remove experimental tagDavid Sterba2014-08-22
| | | | | | | Make it consistent with kernel status and documentation. Reviewed-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: define BTRFS_MKFS_SMALL_VOLUME_SIZE for small volumeAnand Jain2014-08-22
| | | | | | | | mkfs cut of size '1024 * 1024 * 1024' to mark dev as small volume so to force mixed group. Use a define for that. Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: dont break the stringAnand Jain2014-08-22
| | | | | Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Add minimum device size checkQu Wenruo2014-08-22
| | | | | | | | | | | | | | | | | | | Btrfs has global block reservation, so even mkfs.btrfs can execute without problem, there is still a possibility that the filesystem can't be mounted. For example when mkfs.btrfs on a 8M file on x86_64 platform, kernel will refuse to mount due to ENOSPC, since system block group takes 4M and mixed block group takes 4M, and global block reservation will takes all the 4M from mixed block group, which makes btrfs unable to create uuid tree. This patch will add minimum device size check before actually mkfs. The minimum size calculation uses a simplified one: minimum_size_for_each_dev = 2 * (system block group + global block rsv) and global block rsv = leafsize << 10 Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: mkfs: allow UUID specification at mkfs timeEric Sandeen2014-08-22
| | | | | | | | | | | | | | | Allow the specification of the filesystem UUID at mkfs time. Non-unique unique IDs are rejected. This includes attempting to re-mkfs with the same UUID; if you really want to do that, you can mkfs with a new UUID, then re-mkfs with the one you wanted. (Implemented only for mkfs.btrfs, not btrfs-convert). Signed-off-by: Eric Sandeen <sandeen@redhat.com> [converted help to asciidoc] Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: fix mkfs.btrfs segfault with --features optionHolger Hoffstätte2014-05-02
| | | | | | | | | | The mkfs.btrfs --features long option takes an argument but does not declare it. Consequently getopt does not allocate an argument, which makes an unconditional strdup() crash during options parsing. Fix by declaring the argument in the options alias array. Signed-off-by: Holger Hoffstätte <holger.hoffstaette@googlemail.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* Btrfs-progs: mkfs: remove ununsed parametersRakesh Pandit2014-05-02
| | | | | | | Remove ununsed parameters since 71d6bd3c in create_raid_groups. Signed-off-by: Rakesh Pandit <rakesh@tuxera.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* Btrfs-progs: mkfs: Remove 'zero_end =1' since it has been set to a valueLi Yang2014-05-02
| | | | | | | | | In utils.c, zero_end is used as a parameter, should not force it to 1. In mkfs.c, zero_end is set to 1 or 0(-b) at the beginning, should not force it to 1 unconditionally. Signed-off-by: Li Yang <liyang.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>