summaryrefslogtreecommitdiff
path: root/utils.c
Commit message (Collapse)AuthorAge
* 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: safely copy path in btrfs_scan_lblkidDavid Sterba2015-01-03
| | | | | | | We should terminate the string, let's use the wrapper. Resolves-coverity-id: 1127097 Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: cleanup whitespace in is_same_blk_fileDavid Sterba2015-01-03
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: use strncpy in is_same_blk_fileDavid Sterba2015-01-03
| | | | | | | Although we're getting strings from the caller, let's be safe. Resolves-coverity-id: 1199475 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: 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: fix wrong num_devices for btrfs fi show with seed devicesGui Hecheng2014-12-04
| | | | | | | | | The @fi_args->num_devices in @get_fs_info() does not include seed devices. We could just correct it by searching the chunk tree and count how many dev_items there are in total which includes seed devices. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: remove BUG_ON on num of devices for btrfs fi showGui Hecheng2014-12-04
| | | | | | | | | The following BUG_ON: BUG_ON(ndevs >= fi_args->num_devices) is not needed, because it always fails with seed devices present. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: provide better error message for raid profile mismatchHidetoshi Seto2014-12-04
| | | | | | | | | | | | | | | | | | | | | Current error messages are like following: Error: unable to create FS with metadata profile 32 (have 2 devices) Error: unable to create FS with metadata profile 256 (have 2 devices) Obviously it is hard for users to interpret "profile XX" to proper meaning, such as "raidN". So use recongizable string instead of internal numerical value. In case of "DUP", use an explicit message. Plus this patch fix a bug that message mistake metadata profile for data profile. After applying this patch, messages will be like: Error: DUP is not allowed when FS have multiple devices Error: unable to create FS with metadata profile RAID6 (have 2 devices but 3 devices are required) Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.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: use the correct SI prefixesDavid Sterba2014-11-04
| | | | | | The SI standard defines lowercase 'k' and uppercase for the rest. 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>
* revert btrfs-progs: do a separate probe for _transient_ replacing deviceAnand Jain2014-11-03
| | | | | | | | | | | | | | There is a compatibility issue with older kernel with the progs commit id as below. d0588bfa479409b2a0f6243f894338a01a56221a btrfs-progs: do a separate probe for _transient_ replacing device So as of now writing to revert the above commit id. The brewing sysfs interface would help to fix the impending issue, which is seed device would fail show in 'btrfs fi show' output of a sprout device. 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: check sscanf return codeZach Brown2014-10-16
| | | | | | | | coverity warned that the return code from sscanf() assigned to 'i' wasn't checked before being assigned again. Check it. Signed-off-by: Zach Brown <zab@zabbo.net> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: open RW to register device using btrfs-controlAnand Jain2014-10-16
| | | | | | | | We are passing device path to be registered with in kernel, so we need to open with RW Signed-off-by: Anand Jain <anand.jain@oracle.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: Remove extra 'const' modifiers; they don't do anything.Adam Buchbinder2014-10-10
| | | | | | | | | | | | | 'const int const *x' means the same thing as 'const int *x' or 'int const *x'; the intent was probably 'const int * const x'. However, this won't work for the 'suffix' variable, as it has to be assigned, and making the static tables into const pointers to const chars leads to a mismatch there. This was found with clang's duplicate-decl-specifier warning. Signed-off-by: Adam Buchbinder <abuchbinder@google.com> 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: print B for bytesDavid Sterba2014-10-10
| | | | | | This arguably helps parsers. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: do a separate probe for transient replacing deviceAnand Jain2014-10-10
| | | | | | | | | | | | | | | | | | | | | | As mentioned in the kernel patch btrfs: ioctl BTRFS_IOC_FS_INFO and BTRFS_IOC_DEV_INFO miss-matched with slots The count as returned by BTRFS_IOC_FS_INFO is the number of slots that btrfs-progs would allocate for the BTRFS_IOC_DEV_INFO ioctl. Since BTRFS_IOC_DEV_INFO would loop across the seed devices, So its better ioctl BTRFS_IOC_FS_INFO returns the total_devices instead of num_devices. The above mentioned patch just does that. That is, it returns total_devices instead of num_devices. Which means we need to probe for the replacing device separately. This patch will probe for the replacing device separately. Signed-off-by: Anand Jain <anand.jain@oracle.com> 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: force overwrite should wipe stale SBAnand Jain2014-10-10
| | | | | | | | | | | | | | | | | | | | | | | | (I am unable to reproduce the issue, tried to go back with progs versions but still the same. So as of now this code remains untested, suggest to wait till we have a reproducible test case). Here is a test case which says it all.. mkfs.xfs -f $DEV mkfs.btrfs -f $DEV mount $DEV $MNT mount: /dev/vdiskc: more filesystems detected. This should not happen, use -t <type> to explicitly specify the filesystem type or use wipefs(8) to clean up the device. mount: you must specify the filesystem type with this patch btrfs_prepare_device() also wipes old FS if any, btrfs_prepare_device() is called after we have verified that user has provided -f option. 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: don't fall back to recursive /dev scanEric Sandeen2014-10-10
| | | | | | | | | | | | | | | | | | If we didn't find what we are looking for in /proc/partitions, we're not going to find it by scanning every node under /dev, either. But that's just what btrfs_scan_for_fsid() does. Remove that fallback; at that point btrfs_scan_for_fsid() just calls scan_for_btrfs(), so remove the wrapper & call it directly. Side note: so, these paths always use /proc/partitions, not libblkid. Userspace-intiated scans default to libblkid. I presume this is part of the design, and intentional? Anyway, not changing it now! 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: fix find_mount_root() to handle duplicated mount point correctlyQu Wenruo2014-09-14
| | | | | | | | | | | | | | | | | | | | | Original find_mount_root() will use the first mount point match and return it. It was OK until the following commit, which will also check the fstype: de22c28ef31d9721606ba059 btrfs-progs: Check fstype in find_mount_root() With fstype check, we should check the last match, not only the first one. Or the following mount will not pass the find_mount_root(): /dev/sdc on /mnt/test type ext4 (rw,relatime,data=ordered) /dev/sdb on /mnt/test type btrfs (rw,relatime,space_cache) This patch will use the last match to do the fstype check. Reported-by: Remco Hosman <remco@yerf-it.nl> Signed-off-by: Remco Hosman <remco@yerf-it.nl> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Reviewed-by: Omar Sandoval <osandov@osandov.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* Btrfs-progs: fix typosHolger Hoffstätte2014-09-02
| | | | | | | Fix (at least one user-visible) typos: it's its, not it's. Signed-off-by: Holger Hoffstätte <holger.hoffstaette@googlemail.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>
* btrfs-progs: introduce test_issubvolname() for simplicitySatoru Takeuchi2014-08-22
| | | | | | | | | | | There are many duplicated codes to check if the given string is correct subvolume name. Introduce test_issubvolname() for this purpose for simplicity. 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>
* btrfs-progs: fix improper return value check for is_existing_blk_or_reg_fileGui Hecheng2014-08-22
| | | | | | | | | | | | | The function @is_existing_blk_or_reg_file has a return value of -errno, which indicate the @stat call fails with non-ENOENT errors. In this condition, we should not continue the following work. But -errno evaluates to true and will let the following work go. So we should judge more accurately whether the return value of @is_existing_blk_or_reg_file is > 0 or not to decide our behavior. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* Btrfs-progs: fix some build warnings on 32bit platformWang Shilong2014-08-22
| | | | | | | | | | | | | | | | | | | | | | | | | | | Fix following build warnings on 32bit platform: ... utils.c:1708:3: warning: left shift count >= width of type [enabled by default] if (x << i & (1UL << 63)) ^ qgroup-verify.c:393:9: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] return (struct tree_block *)unode->aux; ^ qgroup-verify.c:407:38: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] if (ulist_add(tree_blocks, bytenr, (unsigned long long)block, 0) >= 0) ^ cmds-restore.c:120:4: warning: format %lu expects argument of type long unsigned int, but argument 3 has type size_t [-Wformat=] fprintf(stderr, "bad compress length %lu\n", in_len); ... BTW, this patch also switches other castings with new helpers. Signed-off-by: Wang Shilong <wangshilong1991@gmail.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Check fstype in find_mount_root()Qu Wenruo2014-08-22
| | | | | | | | | | | | | | When calling find_mount_root(), caller in fact wants to find the mount point of *BTRFS*. So also check ent->fstype in find_mount_root() and do special error string output in caller. This will suppress a lot of "Inapproiate ioctl for device" error message. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Remove fprintf() in find_mount_root().Qu Wenruo2014-08-22
| | | | | | | | | | | find_mount_root() function in utils.c should not print error string. Caller should be responsible to print error string. This patch will remove the only fprintf in find_mount_root() and modify the caller a little to use strerror() to prompt users. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: fix wrong message about forcing the mixed group profileAnand Jain2014-08-22
| | | | | | | | | | | | | | | | | | | | | | | | | | When the added disk is small, the function btrfs_prepare_device() would print message indicating that mixed group is forced, apparently thats not true reproducer: mkfs.btrfs -f -draid1 -mraid1 /dev/sdd /dev/sdc :: SMALL VOLUME: forcing mixed metadata/data groups <---- WRONG mount /dev/sdd /btrfs btrfs fi df /btrfs Data, RAID1: total=126.25MiB, used=128.00KiB Data, single: total=8.00MiB, used=0.00B System, RAID1: total=8.00MiB, used=16.00KiB System, single: total=4.00MiB, used=0.00B Metadata, RAID1: total=126.25MiB, used=112.00KiB Metadata, single: total=8.00MiB, used=0.00B GlobalReserve, single: total=16.00MiB, used=0.00B Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: mkfs: don't zero extend small filesZach Brown2014-08-22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | mkfs can try to write outside of small devices. The zeroing code doesn't test the device size and runs before mkfs tests for small devices and exits. Testers experienced this as small regular files being extended as mkfs failed: $ truncate -s 1m /tmp/some-file $ strace -epwrite ./mkfs.btrfs /tmp/some-file SMALL VOLUME: forcing mixed metadata/data groups WARNING! - Btrfs v3.14.2 IS EXPERIMENTAL WARNING! - see http://btrfs.wiki.kernel.org before using pwrite(3, ..., 2097152, 0) = 2097152 pwrite(3, ..., 4096, 65536) = 4096 pwrite(3 ..., 2097152, 18446744073708503040) = -1 EINVAL (Invalid argument) ERROR: failed to zero device '/tmp/some-file' - Input/output error $ ls -lh /tmp/some-file -rw-rw-r--. 1 zab zab 2.0M Jul 16 13:49 /tmp/some-file This simple fix adds a helper that clamps a region to be zeroed to the size of the device. It doesn't address the larger questions of whether to modify the device before the size test or whether or zero regions that have been trimmed. Finally, the error handling mess after the zeroing calls is cleaned up. zero_blocks() and its callers only return -errno. Signed-off-by: Zach Brown <zab@zabbo.net> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: define BTRFS_MKFS_SMALL_VOLUME_SIZE for small volumeAnand Jain2014-08-22
| | | | | | | | mkfs cut of size '1024 * 1024 * 1024' to mark dev as small volume so to force mixed group. Use a define for that. Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Allow btrfs_read_dev_super() to read all 3 super for super_recover.Qu Wenruo2014-08-22
| | | | | | | | | | | | | | Btrfs-progs superblock checksum check is somewhat too restricted for super-recover, since current btrfs-progs will only read the 1st superblock and if you need super-recover the 1st superblock is possibly already damaged. The fix is introducing super_recover parameter for btrfs_read_dev_super() and callers to allow scan backup superblocks if needed. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: move the check_argc_* functions into utils.cGui Hecheng2014-08-22
| | | | | | | | | | | | | | To let the independent tools(e.g. btrfs-image, btrfs-convert, etc.) share the convenience of check_argc_* functions, just move it into utils.c. Also add a new function "set_argv0" to set the correct tool name: *btrfs-image*: too few arguments The original btrfs* tools work as before. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> [moved argv0 and check_argc to utils.*] Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Add minimum device size checkQu Wenruo2014-08-22
| | | | | | | | | | | | | | | | | | | Btrfs has global block reservation, so even mkfs.btrfs can execute without problem, there is still a possibility that the filesystem can't be mounted. For example when mkfs.btrfs on a 8M file on x86_64 platform, kernel will refuse to mount due to ENOSPC, since system block group takes 4M and mixed block group takes 4M, and global block reservation will takes all the 4M from mixed block group, which makes btrfs unable to create uuid tree. This patch will add minimum device size check before actually mkfs. The minimum size calculation uses a simplified one: minimum_size_for_each_dev = 2 * (system block group + global block rsv) and global block rsv = leafsize << 10 Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Improve the parse_size() error messageQu Wenruo2014-08-22
| | | | | | | | | | | | | | | | | When using parse_size(), even non-numeric value is passed, it will only give error message "ERROR: size value is empty", which is quite confusing for end users. This patch will introduce more meaningful error message for the following new cases 1) Invalid size string (non-numeric string) 2) Minus size value (like "-1K") Also this patch will take full use of endptr returned by strtoll() to reduce unneeded loop. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: canonicalize pathnames for device commandsJeff Mahoney2014-08-22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | mount(8) will canonicalize pathnames before passing them to the kernel. Links to e.g. /dev/sda will be resolved to /dev/sda. Links to /dev/dm-# will be resolved using the name of the device mapper table to /dev/mapper/<name>. Btrfs will use whatever name the user passes to it, regardless of whether it is canonical or not. That means that if a 'btrfs device ready' is issued on any device node pointing to the original device, it will adopt the new name instead of the name that was used during mount. Mounting using /dev/sdb2 will result in df: /dev/sdb2 209715200 39328 207577088 1% /mnt lrwxrwxrwx 1 root root 4 Jun 4 13:36 /dev/whatever-i-like -> sdb2 /dev/whatever-i-like 209715200 39328 207577088 1% /mnt Likewise, mounting with /dev/mapper/whatever and using /dev/dm-0 with a btrfs device command results in df showing /dev/dm-0. This can happen with multipath devices with friendly names enabled and doing something like 'partprobe' which (at least with our version) ends up issuing a 'change' uevent on the sysfs node. That *always* uses the dm-# name, and we get confused users. This patch does the same canonicalization of the paths that mount does so that we don't end up having inconsistent names reported by ->show_devices later. Signed-off-by: Jeff Mahoney <jeffm@suse.com> [use PATH_MAX in canonicalize_dm_name] Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: mkfs: allow UUID specification at mkfs timeEric Sandeen2014-08-22
| | | | | | | | | | | | | | | Allow the specification of the filesystem UUID at mkfs time. Non-unique unique IDs are rejected. This includes attempting to re-mkfs with the same UUID; if you really want to do that, you can mkfs with a new UUID, then re-mkfs with the one you wanted. (Implemented only for mkfs.btrfs, not btrfs-convert). Signed-off-by: Eric Sandeen <sandeen@redhat.com> [converted help to asciidoc] Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: move arg_strtou64 to a separate file for libraryDavid Sterba2014-05-02
| | | | | | | | | | Linking with libbtrfs fails because arg_strtou64 is not defined and we cannot just add utils.o to library objects because it's not library-clean. Reported-by: Arvin Schnell <aschnell@suse.com> Reported-by: Anton Farygin <rider@altlinux.org> Signed-off-by: David Sterba <dsterba@suse.cz>
* Btrfs-progs: mkfs: Remove 'zero_end =1' since it has been set to a valueLi Yang2014-05-02
| | | | | | | | | In utils.c, zero_end is used as a parameter, should not force it to 1. In mkfs.c, zero_end is set to 1 or 0(-b) at the beginning, should not force it to 1 unconditionally. Signed-off-by: Li Yang <liyang.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>