summaryrefslogtreecommitdiff
path: root/mkfs/common.c
Commit message (Collapse)AuthorAge
* btrfs-progs: treewide: Replace strerror(errno) with %m.Rosen Penev2018-01-31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As btrfs is specific to Linux, %m can be used instead of strerror(errno) in format strings. This has some size reduction benefits for embedded systems. glibc, musl, and uclibc-ng all support %m as a modifier to printf. A quick glance at the BIONIC libc source indicates that it has support for %m as well. BSDs and Windows do not but I do believe them to be beyond the scope of btrfs-progs. Compiled sizes on Ubuntu 16.04: Before: 3916512 btrfs 233688 libbtrfs.so.0.1 4899 bcp 2367672 btrfs-convert 2208488 btrfs-corrupt-block 13302 btrfs-debugfs 2152160 btrfs-debug-tree 2136024 btrfs-find-root 2287592 btrfs-image 2144600 btrfs-map-logical 2130760 btrfs-select-super 2152608 btrfstune 2131760 btrfs-zero-log 2277752 mkfs.btrfs 9166 show-blocks After: 3908744 btrfs 233256 libbtrfs.so.0.1 4899 bcp 2366560 btrfs-convert 2207432 btrfs-corrupt-block 13302 btrfs-debugfs 2151104 btrfs-debug-tree 2134968 btrfs-find-root 2281864 btrfs-image 2143536 btrfs-map-logical 2129704 btrfs-select-super 2151552 btrfstune 2130696 btrfs-zero-log 2276272 mkfs.btrfs 9166 show-blocks Total savings: 23928 (24 kilo)bytes Signed-off-by: Rosen Penev <rosenp@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: Prevent temporary system chunk to use space in reserved ↵Qu Wenruo2018-01-31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 1M range When creating btrfs, mkfs.btrfs will firstly create a temporary system chunk as basis, and then created needed trees or new devices. However the layout temporary system chunk is hard-coded and uses reserved [0, 1M) range of devid 1. Change the temporary chunk layout from old: 0 1M 4M 5M |<----------- temp chunk -------------->| And it's 1:1 mapped, which means it's a SINGLE chunk, and stripe offset is also 0. to new layout: 0 1M 4M 5M |<----------- temp chunk -------------->| And still keeps the 1:1 mapping. However this also affects btrfs_min_dev_size() which still assume temporary chunks starts at device offset 0. The problem can only be exposed by "-m single" or "-M" where we reuse the temporary chunk. With other meta profiles, system and meta chunks are allocated by later btrfs_alloc_chunk() call, and old SINGLE chunks are removed, so it will be no such problem for other meta profiles. Reported-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: Qu Wenruo <wqu@suse.com> Tested-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: Nikolay Borisov <nborisov@suse.com> [ folded fix for the minimal device size calculation ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: Enhance minimal device size calculation to fix mkfs ↵Qu Wenruo2018-01-03
| | | | | | | | | | | | | | | | | | | | | | failure on small file Since commit c11e36a29e84 ("Btrfs-progs: Do not force mixed block group creation unless '-M' option is specified"), mkfs no longer use mixed block group unless specified manually. This breaks the minimal device size calculation, which only considered mixed block group use case. This patch enhances minimal device size calculation for mkfs, by using different minimal stripe length (calculated from code) for different profiles, and use them to calculate minimal device size. Reported-by: Wesley Aptekar-Cassels <W.Aptekar@gmail.com> Fixes: c11e36a29e84 ("Btrfs-progs: Do not force mixed block group creation unless '-M' option is specified") Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com> [ updated comments ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: check the status of file at mkfsMisono, Tomohiro2018-01-03
| | | | | | | | | | | | | Currently, only the status of block devices is checked at mkfs, but we should also check for regular files whether they are already formatted or mounted to prevent overwrite accidentally. Device status is checked by test_dev_for_mkfs(). The part which is not related to block device is split from this and used for both block device and regular file. Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: refactor test_minimum_size to use the calculated minimal sizeQu Wenruo2017-11-14
| | | | | | | | | | | | | | test_minimum_size() function is only called to check if provided device is large enough. However the minimal device size only needs to be calculated once, and can be reused everywhere. Refactor that function to make later modification easier. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: Move the tree root creation to own functionGu Jinxiang2017-09-08
| | | | | | | | | | | | | make_btrfs is too long to understand, make creatation of root tree in a function. Some of the tree roots are now created in a loop, where the code is just copypasted. We now make use of the reference_root_table to translate block index to root objectid. Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com> [ updated changelog ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Use named constants for common sizesNikolay Borisov2017-09-08
| | | | | | | | | There multiple places where we use well-known sizes - 1,8,16,32 megabytes. We also have them defined as constants in the sizes.h header. So let's use them. No functional changes. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: Replace number with enumGu Jinxiang2017-09-08
| | | | | | | | | For code maintainability and scalability, replace hardcoded constant with a meaningful enum. Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com> [ add MKFS_ prefix ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Remove deprecated leafsize usageQu Wenruo2017-07-03
| | | | | | | | | | | | | | | | | | | | | | | | | | | Leafsize is deprecated for a long time, and kernel has already updated ctree.h to rename sb->leafsize to sb->__unused_leafsize. This patch will remove normal users of leafsize: 1) Remove leafsize member from btrfs_root structure Now only root->nodesize and root->sectorisze. No longer root->leafsize. 2) Remove @leafsize parameter from btrfs_setup_root() function Since no root->leafsize, no need for @leafsize parameter. The remaining user of leafsize will be: 1) btrfs inspect-internal dump-super Reformat the "leafsize" output to "leafsize (deprecated)" and use le32_to_cpu() to do the cast manually. 2) mkfs We still need to set sb->__unused_leafsize to nodesize. Do the manual cast too. 3) convert Same as mkfs, these two superblock setup should be merged later Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
* btrfs-progs: add missing limits headersBaruch Siach2017-03-16
| | | | | | | Build under musl libc fails because of missing PATH_MAX and XATTR_NAME_MAX macro declarations. Add the required headers. Signed-off-by: Baruch Siach <baruch@tkos.co.il>
* btrfs-progs: mkfs: make make_cfg::blocks an internal memberDavid Sterba2017-03-08
| | | | | | | The caller of make_btrfs does not need to set it, it's for internal use and can be read after mkfs ends. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move mkfs helper implementation out of utilsDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: move common api implementation to own fileDavid Sterba2017-03-08
Signed-off-by: David Sterba <dsterba@suse.com>