summaryrefslogtreecommitdiff
path: root/utils.h
Commit message (Collapse)AuthorAge
* btrfs-progs: Introduce new members for btrfs_convert_contextQu Wenruo2016-01-12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Introduce 3 new members for btrfs_convert_context: 1) struct cache_tree used Records accurate byte ranges which are used by old filesystem. This will be used to create old filesystem image. 2) struct cache_tree data_chunks Records batched ranges which must be covered by data chunks. The bytenr range is optimized to meet all the chunk requirement. 3) u64 total_bytenr Records how large the filesystem is in bytenr. Yes, we can calculate it easy, but that's for old blocks based filesystem. This will make it more friendly for extent based filesystem. And later cctx->block_counts and may be removed And 2 for mkfs_config: 1) char *chunk_uuid. Used as temporary chunk_uuid (unparsed) string for later make_convert_btrfs() 2) u64 super_bytenr Records the new temporary super bytenr after make_btrfs(). Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.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: utils: rename helpinfo unit vairablesDavid Sterba2015-11-06
| | | | 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: Introduce warning and error for common useZhao Lei2015-10-21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Current code use fprintf(stderr, "...") to output warnning and error information. The error message have different style, as: # grep fprintf *.c fprintf(stderr, "Open ctree failed\n"); fprintf(stderr, "%s: open ctree failed\n", __func__); fprintf(stderr, "ERROR: cannot open ctree\n"); ... And sometimes, we forgot add tailed '\n', or use printf instead, as in current code: printf("warning, device %llu is missing\n", This patch introduce warning() and error() as common function, to make: 1: Each warning and error information have same format 2: Easy to search/change all error message 3: Easy to modify function's internal for debug or other requirement, for example: print function/linenumber in error() dumpstack in error() add some trace for some style of message add support for -v, -vv, ... support for locales custom output functions support some special device/tty Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> [print newline after the message] 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: 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: 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: 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: add helper for copying pathsDavid Sterba2015-06-12
| | | | | | Check the source path length and do the copy. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: use less memory for pretty_size_mode buffersDavid Sterba2015-06-11
| | | | | | | | | | | | | | | | | | Anand reports that the static buffers used for pertty size strings cause a stack overflow on SPARC. Zach proposed to change the printf format to wrap the number and the suffix into a macro. This would require to change all callsites of pretty_size* and is not very convienient to write. This patch replaces the per-call-site static buffers with a limited number for slots that would be used on each invokation of pretty_size and wrap around. The number of array slots shall be 10 for now, in current codebase there are no more than 2 calls to pretty_size in a single argument list. Reported-by: Anand Jain <Anand.Jain@oracle.com> CC: Zach Brown <zab@zabbo.net> Signed-off-by: David Sterba <dsterba@suse.cz>
* 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: fix argv0_buf handlingDavid Sterba2015-06-09
| | | | | | | | | | | | | | | | The variable argv0_buf was duplicated and the changes done in utils.c were not propagated to help.c. So if an unknown commandline token was found, the error message did not contain the known part: $ btrfs scrub test : unknown token 'test' instead of $ btrfs scrub test btrfs scrub: uknown token 'test' Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: convert: allow to set filesystem featuresDavid Sterba2015-06-04
| | | | | | | | | | | | | | | Curretnly there are no features set for the converted filesystem and it's not possible to request it like in mkfs. Add new option -O|--features, use -O list-all to show all that are supported for convert. Note: from now on, convert without any -O option will use the same defaults as mkfs. The original behaviour was rather confusing. Convert is now more verbose about the parameters of the btrfs filesytem. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: add function to stringify filesystem featuresDavid Sterba2015-06-04
| | | | 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: btrfs_scan_block_devices is unused function delete itAnand Jain2015-05-14
| | | | | | | | | After Patch: remove BTRFS_SCAN_PROC scan method There isn't any consumer for btrfs_scan_block_devices() so delete it. Signed-off-by: Anand Jain <anand.jain@oracle.com> 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: Move parse_qgroupid() to utils.cQu Wenruo2015-03-24
| | | | | | Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> [constified strings in parse_qgroupid] 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: define common geopt values for unit suffixesDavid Sterba2015-01-21
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: unify header file inclusion protectionsDavid Sterba2015-01-21
| | | | | | There are missing ifdefs or defines with very generic names. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Allow debug-tree to be executed on regular file.Qu Wenruo2015-01-09
| | | | | | | | | | | The commit 1bad43fbe002 ("btrfs-progs: refine btrfs-debug-tree error prompt when a mount point given") add judgement on btrfs-debug-tree to restrict only block device to be executed on, but the command can also be used on regular file, so add regular file support for the judgement. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: move check_arg_type() to util.cGui Hecheng2014-12-29
| | | | | | | | | The check_arg_type() function does quite generic thing, move it to utils.c. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Reviewed-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: move contents of math.h to utils.h and deleteDavid Sterba2014-12-19
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: cleanup: avoid to use literal for getopt valSatoru Takeuchi2014-12-19
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: basic support for TREE_SEARCH_V2 ioctlDavid Sterba2014-12-10
| | | | | | Add the interface and helper that checks if the v2 ioctl is supported. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Add count_digits() function to help calculate filename len.Qu Wenruo2014-12-10
| | | | | | | | Add count_digits() function in utils.h to help calculate filename with ino suffix. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Add command btrfs filesystem disk-usageGoffredo Baroncelli2014-12-04
| | | | | Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Enhance the command btrfs filesystem dfGoffredo Baroncelli2014-12-04
| | | | | | | | | | Enhance the command "btrfs filesystem df" to show space usage information for a mount point(s). It shows also an estimation of the space available, on the basis of the current one used. Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it> [code moved under #if 0 instead of deletion] Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: move group type and profile pretty printers to utilsDavid Sterba2014-12-04
| | | | | | Move and add the btrfs_ prefix. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: use proper size for argv0 substitutionDavid Sterba2014-11-18
| | | | | | | | | | | | Make run from a long base path will overflow the argv0 buffer during tests. Otherwise, this would happen for all the standalone binaries that use set_argv0. Original report: https://bbs.archlinux.org/viewtopic.php?id=189861 Reported-by: WorMzy Tykashi <wormzy.tykashi@gmail.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: optimize btrfs_scan_lblkid() for multiple callsAnand Jain2014-11-03
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | btrfs_scan_lblikd() is called by most the device related command functions. And btrfs_scan_lblkid() is most expensive function and it becomes more expensive as number of devices in the system increase. Further some threads call this function more than once for absolutely no extra benefit and the real waste of resources. Below list of threads and number of times btrfs_scan_lblkid() is called in that thread. btrfs-find-root 1 btrfs rescue super-recover 2 btrfs-debug-tree 1 btrfs-image -r 2 btrfs check 2 btrfs restore 2 calc-size NC btrfs-corrupt-block NC btrfs-image NC btrfs-map-logical 1 btrfs-select-super NC btrfstune 2 btrfs-zero-log NC tester NC quick-test.c NC btrfs-convert 0 mkfs #number of devices to be mkfs btrfs label set unmounted 2 btrfs get label unmounted 2 This patch will: move out calling register_one_device with in btrfs_scan_lblkid() and so function setting the BTRFS_UPDATE_KERNEL to yes will call btrfs_register_all_devices() separately. introduce a global variable scan_done, which is set when scan is done succssfully per thread. So that following calls to this function will just return success. Further if any function needs to force scan after scan_done is set, then it can be done when there is such a requirement, but as of now there isn't any such requirement. Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: introduce btrfs_register_all_device()Anand Jain2014-11-03
| | | | | | | | | | | | This function is to register all devices found after scanning the system. Before we had this functionality with in the btrfs_scan_lblkid(), however scanning and registering are two different distinct operation its better keep them separate. Also we want to optimize btrfs_scan_lblkid and avoid multiple system scans unless needed. As of now device scan uses this function. Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: code optimize cmd_scan_dev() use btrfs_register_one_device()Anand Jain2014-11-03
| | | | | | | | cmd_scan_dev() has it own code to register device (calling ioctl BTRFS_IOC_SCAN_DEV), apparently it could use btrfs_register_one_device(). Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* Btrfs-progs: check, ability to detect and fix outdated snapshot root itemsFilipe Manana2014-10-17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change adds code to detect and fix the issue introduced in the kernel release 3.17, where creation of read-only snapshots lead to a corrupted filesystem if they were created at a moment when the source subvolume/snapshot had orphan items. The issue was that the on-disk root items became incorrect, referring to the pre orphan cleanup root node instead of the post orphan cleanup root node. A test filesystem can be generated with the test case recently submitted for xfstests/fstests, which is essencially the following (bash script): workout() { ops=$1 procs=$2 num_snapshots=$3 _scratch_mkfs >> $seqres.full 2>&1 _scratch_mount snapshot_cmd="$BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT" snapshot_cmd="$snapshot_cmd $SCRATCH_MNT/snap_\`date +'%H_%M_%S_%N'\`" run_check $FSSTRESS_PROG -p $procs \ -x "$snapshot_cmd" -X $num_snapshots -d $SCRATCH_MNT -n $ops } ops=10000 procs=4 snapshots=500 workout $ops $procs $snapshots Example of btrfsck's (btrfs check) behaviour against such filesystem: $ btrfsck /dev/loop0 root item for root 311, current bytenr 44630016, current gen 60, current level 1, new bytenr 44957696, new gen 61, new level 1 root item for root 1480, current bytenr 1003569152, current gen 1271, current level 1, new bytenr 1004175360, new gen 1272, new level 1 root item for root 1509, current bytenr 1037434880, current gen 1300, current level 1, new bytenr 1038467072, new gen 1301, new level 1 root item for root 1562, current bytenr 33636352, current gen 1354, current level 1, new bytenr 34455552, new gen 1355, new level 1 root item for root 3094, current bytenr 1011712000, current gen 2935, current level 1, new bytenr 1008484352, new gen 2936, new level 1 root item for root 3716, current bytenr 80805888, current gen 3578, current level 1, new bytenr 73515008, new gen 3579, new level 1 root item for root 4085, current bytenr 714031104, current gen 3958, current level 1, new bytenr 716816384, new gen 3959, new level 1 Found 7 roots with an outdated root item. Please run a filesystem check with the option --repair to fix them. $ echo $? 1 $ btrfsck --repair /dev/loop0 enabling repair mode fixing root item for root 311, current bytenr 44630016, current gen 60, current level 1, new bytenr 44957696, new gen 61, new level 1 fixing root item for root 1480, current bytenr 1003569152, current gen 1271, current level 1, new bytenr 1004175360, new gen 1272, new level 1 fixing root item for root 1509, current bytenr 1037434880, current gen 1300, current level 1, new bytenr 1038467072, new gen 1301, new level 1 fixing root item for root 1562, current bytenr 33636352, current gen 1354, current level 1, new bytenr 34455552, new gen 1355, new level 1 fixing root item for root 3094, current bytenr 1011712000, current gen 2935, current level 1, new bytenr 1008484352, new gen 2936, new level 1 fixing root item for root 3716, current bytenr 80805888, current gen 3578, current level 1, new bytenr 73515008, new gen 3579, new level 1 fixing root item for root 4085, current bytenr 714031104, current gen 3958, current level 1, new bytenr 716816384, new gen 3959, new level 1 Fixed 7 roots. Checking filesystem on /dev/loop0 UUID: 2186e9b9-c977-4a35-9c7b-69c6609d4620 checking extents checking free space cache cache and super generation don't match, space cache will be invalidated checking fs roots checking csums checking root refs found 618537000 bytes used err is 0 total csum bytes: 130824 total tree bytes: 601620480 total fs tree bytes: 580288512 total extent tree bytes: 18464768 btree space waste bytes: 136939144 file data blocks allocated: 34150318080 referenced 27815415808 Btrfs v3.17-rc3-2-gbbe1dd8 $ echo $? 0 Signed-off-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: add options to tune units for fi df outputDavid Sterba2014-10-10
| | | | | | | | | | | | | The size unit format is a longstanding annoyance. This patch is based on the work of Nils and Alexandre and enhances the options. It's possible to select raw bytes, SI-based or IEC-based compact units (human frientdly) or a fixed base from kilobytes to terabytes. The default is compact human readable IEC-based, no change to current version. CC: Nils Steinger <nst@voidptr.de> CC: Alexandre Oliva <oliva@gnu.org> Reviewed-by: Hugo Mills <hugo@carfax.org.uk> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: extend pretty printers with unit modeDavid Sterba2014-10-10
| | | | | | | | The functionality of pretty unit printing was duplicated by df_pretty_sizes, merge it with pretty_size and enhance the interface with more suffix mode. Raw, binary or decimal. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: remove scan_for_btrfs()Anand Jain2014-10-10
| | | | | | | | With the changes as in the previous patch, now scan_for_btrfs() is an unused function. So delete it. Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: remove BTRFS_SCAN_PROC scan methodAnand Jain2014-10-10
| | | | | | | | | | | The libblkid scan method which was introduced later, will also scan devices under /proc/partitions. So we don't have to do the explicit scan of the same. Remove the scan method BTRFS_SCAN_PROC. Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: remove BTRFS_SCAN_DEV and btrfs_scan_one_dirEric Sandeen2014-10-10
| | | | | | | | | | After the previous 2 patches, nothing uses whole-dev-tree scanning, so remove the code which implemented that functionality. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Reviewed-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: move test_isdir() to utils.cSatoru Takeuchi2014-08-22
| | | | | | | | | | | | Since test_isdir() is a utility function, it's better to move it to utils.c. In addition, "const char *" is more appropriate type as its "path" argument because this argument is not changed in this function. Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com> Cc: David Sterba <dsterba@suse.cz> Cc: Mike Fleetwood <mike.fleetwood@googlemail.com> Signed-off-by: David Sterba <dsterba@suse.cz>