summaryrefslogtreecommitdiff
path: root/mkfs.c
Commit message (Collapse)AuthorAge
* btrfs-progs: unify naming of argc and argvDavid Sterba2016-03-14
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: use on-stack buffer in add_symbolic_linkDavid Sterba2016-01-12
| | | | | | | Also get rid of the unhandled memory allocation. Resolves-coverity-id: 1338298 Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: ftw_add_entry_size: Round up file size to sectorsizeChandan Rajendra2016-01-12
| | | | | | | | | | ftw_add_entry_size() assumes 4k as the block size of the underlying filesystem and hence the file sizes computed is incorrect for non-4k sectorsized filesystems. Fix this by rounding up file sizes to sectorsize. Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: allow --data DUP for single deviceZhao Lei2015-11-26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Current code don't support DUP profile on single device, except it is in mixed mode, because of following reasons: 1: Some SSD do deduplication internally, so the duplication on the filesystem side has no effect. 2: On a physical device, if the entire disk broken, --data DUP does not help. 3: Half performance compared to single profile. 4: We have a workaround: create multi-partition on a single device, and btffs will treat them as multi device. Instead of refusing --data DUP, we give the user a choice and print a wrning. Test: 1: Tested by xfstests Run with modified xfstests, I add test items of -d dup in single device into btrfs/* and common/rc, run tests of btrfs/*, with all mount option, no regression diffed with v4.3. 2: Tested by btrfs-progs Checked following commands in "-m dup -d dup" fs with memleck checking, all passed: mkfs.btrfs -f --data dup --metadata dup /dev/sda6 btrfs filesystem show /dev/sda6 btrfs filesystem label /dev/sda6 btrfs_label_test btrfs filesystem label /dev/sda6 btrfs device scan --all-devices btrfs device scan /dev/sda6 btrfs device scan /dev/sda6 btrfs device ready /dev/sda6 btrfs check /dev/sda6 btrfs check -s 1 /dev/sda6 btrfs check --repair /dev/sda6 btrfs check --init-csum-tree /dev/sda6 btrfs check --init-extent-tree /dev/sda6 btrfs check --check-data-csum /dev/sda6 btrfs check --qgroup-report /dev/sda6 btrfs rescue super-recover -y /dev/sda6 btrfs rescue zero-log /dev/sda6 btrfs restore -l /dev/sda6 btrfs restore /dev/sda6 / btrfs restore -s /dev/sda6 / btrfs restore -x /dev/sda6 / btrfs restore -m /dev/sda6 / btrfs restore -S /dev/sda6 / btrfs restore -v /dev/sda6 / btrfs restore -i /dev/sda6 / btrfs restore -o /dev/sda6 / btrfs restore -u0 /dev/sda6 / btrfs restore -u1 /dev/sda6 / btrfs restore -D /dev/sda6 / btrfs property list /dev/sda6 btrfs property get /dev/sda6 label btrfs property set /dev/sda6 label test btrfs property set /dev/sda6 label btrfs_label_test btrfs help btrfs help --full btrfs version btrfsck /dev/sda6 btrfs-find-root /dev/sda6 btrfs-find-root -a /dev/sda6 btrfs-map-logical -l1 /dev/sda6 btrfs-map-logical -l1 -c1 /dev/sda6 btrfs-map-logical -l1 -o /tmp/btrfs-map-logic-out /dev/sda6 btrfs-map-logical -l1 -b1 /dev/sda6 btrfs-select-super -s 0 /dev/sda6 btrfs-select-super -s 1 /dev/sda6 btrfstune -S 1 /dev/sda6 btrfstune -f -S 0 /dev/sda6 btrfstune -r /dev/sda6 btrfstune -x /dev/sda6 btrfstune -n /dev/sda6 btrfstune -f -U 00000000-0000-0000-0000-000000000000 /dev/sda6 btrfstune -f -u /dev/sda6 btrfs-calc-size /dev/sda6 btrfs-calc-size -v /dev/sda6 btrfs-calc-size -b /dev/sda6 btrfs-debug-tree /dev/sda6 btrfs-debug-tree -e /dev/sda6 btrfs-debug-tree -d /dev/sda6 btrfs-debug-tree -r /dev/sda6 btrfs-debug-tree -R /dev/sda6 btrfs-debug-tree -u /dev/sda6 btrfs-debug-tree -b 0 /dev/sda6 btrfs-debug-tree -t 0 /dev/sda6 btrfs-debug-tree -t 2 /dev/sda6 btrfs-show-super /dev/sda6 btrfs-show-super -i 0 /dev/sda6 btrfs-show-super -i 1 /dev/sda6 btrfs-show-super -i 2 /dev/sda6 btrfs-show-super -a /dev/sda6 btrfs-show-super -f /dev/sda6 btrfs-show-super -F /dev/sda6 btrfs subvolume list /mnt/btrfs-progs-tests btrfs subvolume create /mnt/btrfs-progs-tests/mysubvol btrfs subvolume list /mnt/btrfs-progs-tests btrfs subvolume get-default /mnt/btrfs-progs-tests btrfs subvolume set-default 258 /mnt/btrfs-progs-tests btrfs subvolume get-default /mnt/btrfs-progs-tests btrfs subvolume set-default /mnt/btrfs-progs-tests btrfs subvolume snapshot /mnt/btrfs-progs-tests/mysubvol /mnt/btrfs-progs-tests/mysubvol_snap btrfs subvolume list /mnt/btrfs-progs-tests btrfs subvolume find-new /mnt/btrfs-progs-tests 0 btrfs subvolume find-new /mnt/btrfs-progs-tests 0 btrfs subvolume find-new /mnt/btrfs-progs-tests/mysubvol 0 btrfs subvolume find-new /mnt/btrfs-progs-tests/mysubvol 0 btrfs subvolume show /mnt/btrfs-progs-tests btrfs subvolume show /mnt/btrfs-progs-tests/mysubvol btrfs subvolume show /mnt/btrfs-progs-tests/mysubvol_snap btrfs subvolume sync /mnt/btrfs-progs-tests btrfs subvolume delete /mnt/btrfs-progs-tests/mysubvol_snap btrfs subvolume delete /mnt/btrfs-progs-tests/mysubvol btrfs subvolume sync /mnt/btrfs-progs-tests btrfs filesystem df /mnt/btrfs-progs-tests btrfs filesystem show /mnt/btrfs-progs-tests btrfs filesystem sync /mnt/btrfs-progs-tests btrfs filesystem label /mnt/btrfs-progs-tests btrfs_label_test btrfs filesystem label /mnt/btrfs-progs-tests btrfs filesystem usage /mnt/btrfs-progs-tests btrfs filesystem defragment -s 1024 -l 2048 /mnt/btrfs-progs-tests/filesystem_test_dir/test_dir_0/test_file_0 btrfs filesystem defragment /mnt/btrfs-progs-tests/filesystem_test_dir/test_dir_0/test_file_1 btrfs filesystem defragment -f /mnt/btrfs-progs-tests/filesystem_test_dir/test_dir_0/test_file_2 btrfs filesystem defragment -czlib /mnt/btrfs-progs-tests/filesystem_test_dir/test_dir_0/test_file_3 btrfs filesystem defragment -clzo /mnt/btrfs-progs-tests/filesystem_test_dir/test_dir_0/test_file_4 btrfs filesystem defragment /mnt/btrfs-progs-tests/filesystem_test_dir btrfs filesystem defragment -r /mnt/btrfs-progs-tests/filesystem_test_dir btrfs filesystem defragment /mnt/btrfs-progs-tests btrfs filesystem resize 1:-10M /mnt/btrfs-progs-tests btrfs filesystem resize 1:max /mnt/btrfs-progs-tests btrfs balance start /mnt/btrfs-progs-tests btrfs balance start -v /mnt/btrfs-progs-tests btrfs balance start -f /mnt/btrfs-progs-tests btrfs balance status -v /mnt/btrfs-progs-tests btrfs balance pause /mnt/btrfs-progs-tests btrfs balance status /mnt/btrfs-progs-tests btrfs balance resume /mnt/btrfs-progs-tests btrfs balance status -v /mnt/btrfs-progs-tests btrfs balance cancel /mnt/btrfs-progs-tests btrfs balance start -dprofiles=single /mnt/btrfs-progs-tests btrfs balance start -dconvert=single /mnt/btrfs-progs-tests btrfs balance start -ddevid=1 /mnt/btrfs-progs-tests btrfs balance start -f -mprofiles=single /mnt/btrfs-progs-tests btrfs balance start -f -mconvert=single /mnt/btrfs-progs-tests btrfs balance start -f -mdevid=1 /mnt/btrfs-progs-tests btrfs balance start -f -sprofiles=single /mnt/btrfs-progs-tests btrfs balance start -f -sconvert=single /mnt/btrfs-progs-tests btrfs balance start -f -sdevid=1 /mnt/btrfs-progs-tests btrfs device add -f /dev/sda10 /mnt/btrfs-progs-tests btrfs device del /dev/sda10 /mnt/btrfs-progs-tests btrfs device stats /dev/sda6 btrfs device stats -z /dev/sda6 btrfs device stats /mnt/btrfs-progs-tests btrfs device stats -z /mnt/btrfs-progs-tests btrfs device usage /mnt/btrfs-progs-tests btrfs scrub status /mnt/btrfs-progs-tests btrfs scrub start -B /mnt/btrfs-progs-tests btrfs scrub start -B -d /mnt/btrfs-progs-tests btrfs scrub start -B -r /mnt/btrfs-progs-tests btrfs scrub status /mnt/btrfs-progs-tests btrfs scrub start /mnt/btrfs-progs-tests btrfs scrub status /mnt/btrfs-progs-tests btrfs scrub status /mnt/btrfs-progs-tests btrfs scrub status -d /mnt/btrfs-progs-tests btrfs scrub status -R /mnt/btrfs-progs-tests btrfs scrub status /mnt/btrfs-progs-tests btrfs scrub start /dev/sda6 btrfs scrub status /dev/sda6 btrfs scrub status /dev/sda6 btrfs scrub status -d /dev/sda6 btrfs scrub status -R /dev/sda6 btrfs scrub status /dev/sda6 btrfs subvolume snapshot -r /mnt/btrfs-progs-tests /mnt/btrfs-progs-tests/snap1 btrfs send -f /tmp/btrfs_snapshot_test /mnt/btrfs-progs-tests/snap1 btrfs send -e -f /tmp/btrfs_snapshot_test /mnt/btrfs-progs-tests/snap1 btrfs send --no-data -f /tmp/btrfs_snapshot_test /mnt/btrfs-progs-tests/snap1 btrfs quota enable /mnt/btrfs-progs-tests btrfs quota rescan /mnt/btrfs-progs-tests btrfs quota rescan -s /mnt/btrfs-progs-tests btrfs quota rescan -w /mnt/btrfs-progs-tests btrfs quota disable /mnt/btrfs-progs-tests btrfs quota enable /mnt/btrfs-progs-tests btrfs qgroup create 1/5 /mnt/btrfs-progs-tests btrfs qgroup create 2/5 /mnt/btrfs-progs-tests btrfs qgroup assign 1/5 2/5 /mnt/btrfs-progs-tests btrfs qgroup limit 1G 1/5 /mnt/btrfs-progs-tests btrfs qgroup show /mnt/btrfs-progs-tests btrfs qgroup show -p -c -r -e -F -f /mnt/btrfs-progs-tests btrfs qgroup remove 1/5 2/5 /mnt/btrfs-progs-tests btrfs qgroup destroy 2/5 /mnt/btrfs-progs-tests btrfs qgroup destroy 1/5 /mnt/btrfs-progs-tests btrfs quota disable /mnt/btrfs-progs-tests btrfs replace start -f -B /dev/sda6 /dev/sda10 /mnt/btrfs-progs-tests btrfs replace status /mnt/btrfs-progs-tests btrfs replace start -f -B /dev/sda10 /dev/sda6 /mnt/btrfs-progs-tests btrfs-convert /dev/sda6 btrfs-convert -r /dev/sda6 btrfs-convert -d /dev/sda6 btrfs-convert -i /dev/sda6 btrfs-convert -n /dev/sda6 btrfs-convert -N 4096 /dev/sda6 btrfs-convert -l test /dev/sda6 btrfs-convert -L /dev/sda6 btrfs-convert --no-progress /dev/sda6 mkfs.btrfs -f /dev/sda6 btrfs-image /dev/sda6 /tmp/btrfs_image.img btrfs-image -r /tmp/btrfs_image.img /dev/sda6 mkfs.btrfs -f /dev/sda6 btrfs-image -c 0 /dev/sda6 /tmp/btrfs_image.img btrfs-image -r /tmp/btrfs_image.img /dev/sda6 mkfs.btrfs -f /dev/sda6 btrfs-image -c 9 /dev/sda6 /tmp/btrfs_image.img btrfs-image -r /tmp/btrfs_image.img /dev/sda6 mkfs.btrfs -f /dev/sda6 btrfs-image -t 0 /dev/sda6 /tmp/btrfs_image.img btrfs-image -r /tmp/btrfs_image.img /dev/sda6 mkfs.btrfs -f /dev/sda6 btrfs-image -t 1 /dev/sda6 /tmp/btrfs_image.img btrfs-image -r /tmp/btrfs_image.img /dev/sda6 mkfs.btrfs -f /dev/sda6 btrfs-image -t 32 /dev/sda6 /tmp/btrfs_image.img btrfs-image -r /tmp/btrfs_image.img /dev/sda6 mkfs.btrfs -f /dev/sda6 btrfs-image -w /dev/sda6 /tmp/btrfs_image.img btrfs-image -r /tmp/btrfs_image.img /dev/sda6 mkfs.btrfs -f /dev/sda6 btrfs-image -w /dev/sda6 /tmp/btrfs_image.img btrfs-image -r /tmp/btrfs_image.img /dev/sda6 btrfs-image -r -t 0 /tmp/btrfs_image.img /dev/sda6 btrfs-image -r -t 1 /tmp/btrfs_image.img /dev/sda6 btrfs-image -r -t 32 /tmp/btrfs_image.img /dev/sda6 btrfs-image -r -o /tmp/btrfs_image.img /dev/sda6 3: Manual check relation source by: grep DUP *.c Confirmed that all source are modified. 4: Use this raid type manually, do some operations in fs, no error found in command and dmesg. 5: Combination of dup conversion with fsck Confirmed OK with relative kernel patch titled: [PATCH] btrfs: Support convert to -d dup for btrfs-convert export TEST_DEV='/dev/vdc' export TEST_DIR='/var/ltf/tester/mnt' do_dup_test() { local m_from="$1" local d_from="$2" local m_to="$3" local d_to="$4" echo "Convert from -m $m_from -d $d_from to -m $m_to -d $d_to" umount "$TEST_DIR" &>/dev/null ./mkfs.btrfs -f -m "$m_from" -d "$d_from" "$TEST_DEV" >/dev/null || return 1 mount "$TEST_DEV" "$TEST_DIR" || return 1 cp -a /sbin/* "$TEST_DIR" [[ "$m_from" != "$m_to" ]] && { ./btrfs balance start -f -mconvert="$m_to" "$TEST_DIR" || return 1 } [[ "$d_from" != "$d_to" ]] && { local opt=() [[ "$d_to" == single ]] && opt+=("-f") ./btrfs balance start "${opt[@]}" -dconvert="$d_to" "$TEST_DIR" || return 1 } umount "$TEST_DIR" || return 1 ./btrfsck "$TEST_DEV" || return 1 echo return 0 } test_all() { for m_from in single dup; do for d_from in single dup; do for m_to in single dup; do for d_to in single dup; do do_dup_test "$m_from" "$d_from" "$m_to" "$d_to" || return 1 done done done done } test_all Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Tested-by: Austin S. Hemmelgarn <ahferroin7@gmail.com> [ minor updates in the changelog ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: increase buffer size in is_ssdMichael Lass2015-11-16
| | | | | | | | | | | | | | | | In current versions of util-linux the buffer passed to blkid_devno_to_wholedisk has to be sufficiently large to not only hold the device name but the complete target of the /sys/dev/block/<maj:min> symlink. This was changed only recently in 4419ffb9eff5801fdbd385a4a6199b3877f802ad. The small buffer size currently can lead to failure of is_ssd due to truncated device names: readlink("/sys/dev/block/254:7", "../../devices/virtual/block/dm-", 31) = 31 open("/sys/block/dm-/queue/rotational", O_RDONLY) = -1 ENOENT (No such file or directory) Signed-off-by: Michael Lass <bevan@bi-co.net> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: drop unused argument from zero_output_fileDavid Sterba2015-11-13
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: use fixed size buffer in zero_output_fileDavid Sterba2015-11-13
| | | | | | | Rewrite the loop so we don't need to allocate sectorsize and write in 4k steps instead. We know that sectorsize is divisible by 4096. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: handle memory allocation failures in traverse_directoryDavid Sterba2015-11-13
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: handle memory allocation failure in add_file_itemsDavid Sterba2015-11-13
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: do not truncate the image when --rootdir is setDavid Sterba2015-11-05
| | | | | | | | | | | | | | With the rootdir option we try to guess the final size of the image and fill it with zeros, preceded by truncation. After patch "Btrfs-progs: Do not force mixed block group creation unless '-M' option is specified" the misc test 002 will fail, because of the non-mixed mode. I think we should not touch the image size (no change for block devices) and try to fit into whatever is provided by user. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: remove unused code of format uuid stringZhao Lei2015-11-03
| | | | | | | | Variant named dev_uuid and uuid_unparse() for set its value are not used, remove it. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: output device list in sorted orderZhao Lei2015-11-03
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | list_for_each_entry_reverse() in current code can not output devices in sorted order, because the sequence are broken in btrfs_alloc_chunk(). We can use list_sort() instead. Before patch: # mkfs.btrfs -f /dev/vdd /dev/vde /dev/vdf ... Number of devices: 3 Devices: ID SIZE PATH 3 2.60GiB /dev/vdf 1 2.60GiB /dev/vdd 2 2.60GiB /dev/vde After patch: # mkfs.btrfs -f /dev/vdd /dev/vde /dev/vdf ... Number of devices: 3 Devices: ID SIZE PATH 1 2.60GiB /dev/vdd 2 2.60GiB /dev/vde 3 2.60GiB /dev/vdf Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: print version info firstDavid Sterba2015-11-02
| | | | | | The version info should not be preceded by any messages. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: remove stray message about forced mixed-bgDavid Sterba2015-11-02
| | | | | | | | We no longer force mixed-bg mode since "Btrfs-progs: Do not force mixed block group creation unless '-M' option is specified", the message is not relevant anymore. Signed-off-by: David Sterba <dsterba@suse.com>
* Btrfs-progs: Prevent creation of filesystem with 'mixed bgs' and having ↵Chandan Rajendra2015-11-02
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | differing sectorsize and nodesize. mkfs.btrfs allows creation of Btrfs filesystem instances with mixed block group feature enabled and having a sectorsize different from nodesize. For e.g: [root@localhost btrfs-progs]# mkfs.btrfs -f -M -s 4096 -n 16384 /dev/loop0 Forcing mixed metadata/data groups btrfs-progs v3.19-rc2-404-gbbbd18e-dirty See http://btrfs.wiki.kernel.org for more information. Performing full device TRIM (4.00GiB) ... Label: (null) UUID: c82b5720-6d88-4fa1-ac05-d0d4cb797fd5 Node size: 16384 Sector size: 4096 Filesystem size: 4.00GiB Block group profiles: Data+Metadata: single 8.00MiB System: single 4.00MiB SSD detected: no Incompat features: mixed-bg, extref, skinny-metadata Number of devices: 1 Devices: ID SIZE PATH 1 4.00GiB /dev/loop6 This commit fixes the issue by setting BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS feature bit before checking the validity of nodesize that was specified on the command line. Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com> Signed-off-by: David Sterba <dsterba@suse.com>
* Btrfs-progs: Do not force mixed block group creation unless '-M' option is ↵Chandan Rajendra2015-11-02
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | specified When creating small Btrfs filesystem instances (i.e. filesystem size <= 1GiB), mkfs.btrfs fails if both sectorsize and nodesize are specified on the command line and sectorsize != nodesize, since mixed block groups involves both data and metadata blocks sharing the same block group. This is an incorrect behavior when '-M' option isn't specified on the command line. This commit makes optional the creation of mixed block groups i.e. Mixed block groups are created only when -M option is specified on the command line. Since we now allow small filesystem instances with sectorsize != nodesize to be created, we can end up in the following situation, [root@localhost ~]# mkfs.btrfs -f -n 65536 /dev/loop0 btrfs-progs v3.19-rc2-405-g976307c See http://btrfs.wiki.kernel.org for more information. Performing full device TRIM (512.00MiB) ... Label: (null) UUID: 49fab72e-0c8b-466b-a3ca-d1bfe56475f0 Node size: 65536 Sector size: 4096 Filesystem size: 512.00MiB Block group profiles: Data: single 8.00MiB Metadata: DUP 40.00MiB System: DUP 12.00MiB SSD detected: no Incompat features: extref, skinny-metadata Number of devices: 1 Devices: ID SIZE PATH 1 512.00MiB /dev/loop0 [root@localhost ~]# mount /dev/loop0 /mnt/ mount: mount /dev/loop0 on /mnt failed: No space left on device The ENOSPC occurs during the creation of the UUID tree. This is because of things like large metadata block size, DUP mode used for metadata and global reservation consuming space. Also, large nodesize does not make sense on small filesystems, hence this should not be an issue. Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: use calloc instead of malloc+memsetSilvio Fricke2015-10-21
| | | | | | | | | | | | | | | | | | | | | | This patch is generated from a coccinelle semantic patch: identifier t; expression e; statement s; @@ -t = malloc(e); +t = calloc(1, e); ( if (!t) s | if (t == NULL) s | ) -memset(t, 0, e); Signed-off-by: Silvio Fricke <silvio.fricke@gmail.com> [squashed patches into one] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: fix is_block_device() return checksAnand Jain2015-10-02
| | | | | | | | | | | | | | it was highlighted to me is_block_device(), returns 1 if the file is a block device, < 0 in case of an error (eg: file not found) 0 otherwise This patch makes proper return checks at all the places where is_block_device() is used. Thanks to Goffredo. Signed-off-by: Anand Jain <anand.jain@oracle.com> Suggested-by: Goffredo Baroncelli <kreijack@inwind.it> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: utils: Check nodesize against featuresQu Wenruo2015-10-02
| | | | | | | | | | | Check nodesize against features, not only sectorsize. In fact, one of the btrfs-convert and mkfs differs in the nodesize check. This patch also provides the basis for later btrfs-convert fix. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: use android compat headerDavid Sterba2015-09-01
| | | | | | Applies to sources where pthreads are used. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: add newline to some error messagesTsutomu Itoh2015-08-31
| | | | | | | | | Added a missing newline to some error messages. Also printf() was changed to fprintf(stderr) for error messages. Signed-off-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com> Reviewed-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: close all fs_devices before exit in some commandsZhao Lei2015-08-31
| | | | | | | | | | | | | | | | | | mkfs creates more than one fs_devices in fs_uuids. 1: one is for file system being created 2: others are created in test_dev_for_mkfs in order to check mount point test_dev_for_mkfs()-> ... -> btrfs_scan_one_device() Current code only closes 1, and this patch also closes in case 2. Similar problem exist in other tools, eg.:: cmd-check.c: the function is: cmd_check()->check_mounted()-> ... -> btrfs_scan_one_device() ... Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Add missing exit for parse_profile functionQu Wenruo2015-08-31
| | | | | | | | | | In parse_profile() function, in error handling route, it output error message but forgot to exit(1), causing even profile is not valid, it will just fallback to single. Reported-by: James Harvey <jamespharvey20@gmail.com> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* 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>