summaryrefslogtreecommitdiff
path: root/utils.c
Commit message (Collapse)AuthorAge
* btrfs-progs: mkfs: fix an error when using DUP on multidev fsSatoru Takeuchi2016-03-30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | To accept DUP on multidev fs, in addition to the following commit, we need to mark DUP as an allowed data/metadata profile. commit 42f1279bf8e9 ("btrfs-progs: mkfs: allow DUP on multidev fs, only warn") * actual result ============================================= # ./mkfs.btrfs -f -m DUP -d DUP /dev/sdb1 /dev/sdb2 btrfs-progs v4.5-24-ga35b7e6 See http://btrfs.wiki.kernel.org for more information. WARNING: DUP is not recommended on filesystem with multiple devices ERROR: unable to create FS with metadata profile DUP (have 2 devices but 1 devices are required) ============================================= * expected result ============================================= # ./mkfs.btrfs -f -m dup -d dup /dev/sdb1 /dev/sdb2 WARNING: DUP is not recommended on filesystem with multiple devices btrfs-progs v4.5-25-g1a10a3c See http://btrfs.wiki.kernel.org for more information. Label: (null) UUID: 010d72ff-c87c-4516-8916-5e635719d110 Node size: 16384 Sector size: 4096 Filesystem size: 28.87GiB Block group profiles: Data: DUP 1.01GiB Metadata: DUP 1.01GiB System: DUP 12.00MiB SSD detected: no Incompat features: extref, skinny-metadata Number of devices: 2 Devices: ID SIZE PATH 1 953.00MiB /dev/sdb1 2 27.94GiB /dev/sdb2 ================================================== Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: fix fd leak in get_subvol_infoDavid Sterba2016-03-30
| | | | | | | A typo, introduced in "btrfs-progs: create get_subvol_info()". Resolves-coverity-id: 1357106 Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: use safe copy for label buffer everywhereDavid Sterba2016-03-30
| | | | | | | | There's a mix of opencoded strncpy + null termination, strncpy, memcppy without termination etc. Unify them and use the helper. Resolves-coverity-id: 1357105 Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: rename __strncpy__null to __strncpy_nullDavid Sterba2016-03-30
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: allow DUP on multidev fs, only warnDavid Sterba2016-03-30
| | | | | | | The DUP profile can work on multiple filesystems, the limitation is rather artificial. Let the user make the decision and print a warning. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: cleanup block group helpers typesDavid Sterba2016-03-30
| | | | | | Use const char and remove stray prototypes. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: utils: make more arguments constDavid Sterba2016-03-30
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: rename get_subvol_name() to subvol_strip_mountpoint()Anand Jain2016-03-30
| | | | | | Signed-off-by: Anand Jain <anand.jain@oracle.com> [ renamed from subvol_minus_mnt to subvol_strip_mountpoint ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: create get_subvol_info()Anand Jain2016-03-30
| | | | | | | | | get_subvol_info() is useful as we are adding more features around subvolume. This function was inline with the function cmd_subvol_show(). Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move get_subvol_name() to utils.cAnand Jain2016-03-30
| | | | | Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: remove duplicate function __is_subvol()Anand Jain2016-03-30
| | | | | | | | The function test_issubvolume() provides the same check, and has better logic. Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move test_issubvolume() to utils.cAnand Jain2016-03-30
| | | | | Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: rearrange subvolume functions togetherAnand Jain2016-03-30
| | | | | Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: utils: make sure set_label_mounted uses correct length buffersPetros Angelatos2016-03-30
| | | | | | | | | | | | | | | | | | | | | | When `btrfs filesystem label /foo bar` command is invoked, it will pass the buffer allocated in the argv array directly to set_label_mounted() and then to the BTRFS_IOC_SET_FSLABEL ioctl. However, the kernel code handling the ioctl will always try to copy BTRFS_LABEL_SIZE bytes[1] from the userland pointer. Under certain conditions and when the label is small enough, the command will fail with: [root@localhost /]# btrfs filesystem label /mnt f ERROR: unable to set label Bad address Fix this by making sure we pass a BTRFS_LABEL_SIZE sized buffer to the ioctl containing the desired label. [1] https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/fs/btrfs/ioctl.c?id=refs/tags/v4.5#n5231 Signed-off-by: Petros Angelatos <petrosagg@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: utils: switch more error messages to common helpersDavid Sterba2016-03-14
| | | | | | Functions relatd to device changes/status/open, mount checks. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: improve error messages after failed wipingDavid Sterba2016-03-14
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Avoid interpreting options after "--" when getting unit modeSatoru Takeuchi2016-03-14
| | | | | | | | | | | | | | | | | | | | | | | | | | * actual result ====================================== # ./btrfs device usage -- -m /btrfs /dev/sdf1, ID: 1 Device size: 95367.41MiB Data,single: 2056.00MiB Metadata,DUP: 2048.00MiB System,DUP: 16.00MiB Unallocated: 91247.41MiB ====================================== * expected result ====================================== # ./btrfs device usage -- -m /btrfs ERROR: can't access '-m': No such file or directory ====================================== Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Dont' stop scanning of devices at first failed deviceYauhen Kharuzhy2016-03-14
| | | | | | | | | | | | | | | | | | | | | | When 'btrfs device scan' command is invoked, it scans all devices, check them for btrfs superblock and add devices with btrfs to a list. Next, each device from the list is passed to kernel where it is handled in the btrfs_scan_one_device() function. This function can, for example, return -EBUSY when device contains superblock matched to existing and mounted filesystem (if this device was pulled out from RAID and connected again after some time). btrfs tool stops device scan if any device has been failed to add, so other existing devices with (possibly) valid FS will never be reached. Fix this by remove stopping at any failure in the btrfs_register_all_devices(), just return error count. btrfs_scan_one_device() reports any kind of error already. Signed-off-by: Yauhen Kharuzhy <yauhen.kharuzhy@zavadatar.com> [ initialize err to 0 ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: util: Fix a wrong unit of pretty_sizeQu Wenruo2016-03-14
| | | | | | | | | | | | | | | | | If parameter for pretty_size is smaller than default base(1024), pretty_size() will output wrong unit. For example, pretty_size(1008) will output '0.98B' not '1008B' or '0.98KiB'. The cause is, for default base and auto-detect unit, base will be 1024 but num_divs is still 0, last result will still be divided by base, causing the bug. Fix it by checking num_divs in default case, and if num_divs is 0, change base to 1. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: write down the meaning of BTRFS_ARG_BLKDEVSatoru Takeuchi2016-02-05
| | | | | | | | Although BTRFS_ARG_BLKDEV can be returned from check_arg_type(), it's not explained the meaning. Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: introduce helper for parsing args without optionsDavid Sterba2016-01-14
| | | | | | | | | All commands should support the "--" option separator. This is transparently handled by getopt, but we don't use that everywhere. Introduce a helper for commands that take no options (just the path). The object file dependencies need to be adjusted a bit. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: let test_isdir return the exact errorDavid Sterba2016-01-13
| | | | | | | Return any error from stat, normalize the return value in case the path is a directory. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check for negative return value from ioctlDavid Sterba2016-01-12
| | | | | | | Handle only negative values returned by ioctl syscalls, with exception of the device remove. It returns positive values that are handled later. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: remove unnecessary errno temp variablesDavid Sterba2016-01-12
| | | | | | | We can read errno directly if it's not clobbered by any intermediate calls. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: use NULL instead of 0Byongho Lee2016-01-12
| | | | | | | Fix the code assigning 0 to pointer instead of NULL. Signed-off-by: Byongho Lee <bhlee.kernel@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: docs: mkfs, implications of DUP on devicesDavid Sterba2016-01-04
| | | | | | We offer DUP but still depend on the hardware, to do the right thing. 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: use correct size for superblock csum and writeoutDavid Sterba2015-11-19
| | | | | | | | | | If sectorsize is not BTRFS_SUPER_INFO_SIZE (4k), the superblock checksum is wrong and mkfs fails. This has been reported on ppc64 where we pick sectorisize from page size (64k). This has been broken since ages (2008) and discovered by the recently added superblock checks. Reported-by: Dinar Valeev <dvaleev@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: fix fd leak in resolve_loop_device_with_loopdevDavid Sterba2015-11-16
| | | | | Resolves-coverity-id: 1339300 Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: utils: do not expect lo_file_name to be null terminatedDavid Sterba2015-11-16
| | | | | | | The loop_info64::lo_file_name might not be null terminated. Avoid strlen and trim the length to whatever size of the loop_info buffer. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Fix partitioned loop devices resolvingFlorian Margaine2015-11-16
| | | | | | | | | | | | | | When using partitions on a loop device, the device's name can be e.g. /dev/loop0p1 or similar, and no relevant entry exists in the /sys filesystem, so the current resolve_loop_device function fails. Instead of using string functions to extract the device name and reading this file, this patch uses the loop device API through ioctl to get the correct backing file. Signed-off-by: Florian Margaine <florian@platform.sh> [ changed checks of error values from open and ioctl ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: handler memory allocation error in make_btrfsDavid Sterba2015-11-16
| | | | | | Do the allocation early, no need to cleanup. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: simplify empty stirngs checkDavid Sterba2015-11-06
| | | | | | We can do a strlen(str) == 0 in a simpler way. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: Round device size down to sectorsizeZhao Lei2015-11-03
| | | | | | | | | | | | | | | | | | | | | | | | When do following command in a vm, whose disks are created by qemu-img create -f raw 11 2.6G: # mkfs.btrfs -f /dev/vdd /dev/vde /dev/vdf # btrfs-show-super /dev/vdd /dev/vde /dev/vdf | grep dev_item.total_bytes dev_item.total_bytes 2791727104 dev_item.total_bytes 2791729152 dev_item.total_bytes 2791729152 We can see that the first device's size is little smaller. And it fails xfstests btrfs/011. Reason: First device's size is rounded down to sectorsize in make_btrfs(), but other devices are not. Fix: Round down remain devices' size in btrfs_add_to_fsid(). Reported-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Rename variables in btrfs_add_to_fsidZhao Lei2015-11-03
| | | | | | | | | | | | | | | | | There are two total_bytes in btrfs_add_to_fsid(), local variable of total_bytes means fs_total_bytes, and device->total_bytes means device's total_bytes. And device's total_bytes in argument is named block_count in current code. This patch rename: total_bytes -> fs_total_bytes block_count -> device_total_bytes To make code more readable. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: fix missing initialization of list head for dev_listAnand Jain2015-11-02
| | | | | Signed-off-by: Anand Jain <anand.jain@oracle.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: move is_numerical() helper to utils and renameAnand Jain2015-11-02
| | | | | | Signed-off-by: Anand Jain <anand.jain@oracle.com> [ moved to util.c and renamed ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: use btrfs_open_dir in open_path_or_dev_mntZhao Lei2015-11-02
| | | | | | | | | | | | | | | | | | | | | | | Use btrfs_open_dir() in open_path_or_dev_mnt() to make the function return error when target is neither block device nor btrfs mount point. Also add "verbose" argument to let function output common error message instead of putting duplicated lines in caller. Before patch: # ./btrfs device stats /mnt/tmp1 ERROR: getting dev info for devstats failed: Inappropriate ioctl for device # ./btrfs replace start /dev/vdd /dev/vde /mnt/tmp1 ERROR: ioctl(DEV_REPLACE_STATUS) failed on "/mnt/tmp1": Inappropriate ioctl for device After patch: # ./btrfs device stats /mnt/tmp1 ERROR: not a btrfs filesystem: /mnt/tmp1 # ./btrfs replace start /dev/vdd /dev/vde /mnt/tmp1 ERROR: not a btrfs filesystem: /mnt/tmp1 Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> 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: make sure that is_block_device will return only 0/1David Sterba2015-10-02
| | | | | | The macro return nonzero, we'll test against 0/1 (or < 0). 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: provide fail safe for BTRFS_IOC_GET_FSLABEL ioctlAnand Jain2015-10-02
| | | | | | | | | | | | | Old kernels before 3.9 do not provide ioctl BTRFS_IOC_GET_FSLABEL. So we need to provide a fail safe logic for btrfs-progs running on those kernel. In this patch when get_label_mounted() fails on the old kernel it will fail back to the old method and uses get_label_unmounted(), where it will read from the disk directly. Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: cleanup, update function definitions to be ANSI conformantDavid Sterba2015-09-14
| | | | | | | | | | Sparse reports: warning: non-ANSI function declaration of function and we're using func(void) elsewhere. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: handle errors in btrfs_wipe_existing_sbDavid Sterba2015-09-02
| | | | | | | | | Failure during superblock wiping is not always a hard error as we're going to overwrite it anyway but it may catch some errors earlier. The error message is not very descriptive though, because we don't get back much information from blkid. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Introduce get_unit_mode_from_arg for common useZhao Lei2015-08-31
| | | | | | | | | | | | | | | | | | We are using separate code for parsing unit mode in current code, better to use common function. This patch introduces a common function to specify units as arguments and a common help message, to make every tool in btrfs having same unit argument. The benefits are: 1: Unify current tool's arguments for unit 2: Make tools in future easy to implement such argument 3: Changes (enhancement) in common function have effect on all relative tools Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: add memory allocation fail check in btrfs_add_to_fsid()Byongho Lee2015-08-31
| | | | | | | | | | In btrfs_add_to_fsid(), strdup() allocates memory to device->name, but the return value is not checked. So add the return value check and error handling code. And clean-up error handling code for ENOMEM case. Signed-off-by: Byongho Lee <bhlee.kernel@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Introduce btrfs_open_dir wrapperZhao Lei2015-08-31
| | | | | | | | | | | This patch introduce open_btrfs_dir() to open a dir in btrfs filesystem. It can be used for several tools in btrfs-progs. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> [renamed from open_btrfs_dir, adjusted error messages] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: utils: missing newline in error messages when checking dupDavid Sterba2015-07-14
| | | | 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>