summaryrefslogtreecommitdiff
path: root/utils.c
Commit message (Collapse)AuthorAge
* btrfs-progs: constify string arguments where appropriateDavid Sterba2016-10-03
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: change btrfs_csum_final result param type to u8Domagoj Tršan2016-10-03
| | | | | Signed-off-by: Domagoj Tršan <domagoj.trsan@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: use standard allocation functions in non-kenrel codeDavid Sterba2016-10-03
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: improve error handling in btrfs_add_to_fsidDavid Sterba2016-10-03
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: remove redundant check in btrfs_add_to_fsidDavid Sterba2016-10-03
| | | | | | The callers do the sanity checks. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: handle block ordering errors in make_btrfsDavid Sterba2016-09-21
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: check for sane sectorsize earlierDavid Sterba2016-09-21
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: more verbose error handling in creation helpersDavid Sterba2016-09-21
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: switch BUG_ON to ASSERT in reserve_free_spaceDavid Sterba2016-09-21
| | | | | | That's not a real error condition, catch bad function usge. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: use preallocated buffers for config uuidsDavid Sterba2016-09-21
| | | | | | | No need for dynamic allocation, the buffers are small, remove the now-useless error conditions. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: Warn user for minimal RAID5/6 devices setupQu Wenruo2016-09-21
| | | | | | | | | | | For RAID5, 2 devices setup is just RAID1 with more overhead. For RAID6, 3 devices setup is RAID1 with 3 copies, not what most user want. So warn user at mkfs time for such case, and add explain in man pages. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: two staged filesystem creationDavid Sterba2016-08-24
| | | | | | | | | | | | | | | | | | | | | | | | The filesystem existence on a device is manifested by the signature, during the mkfs process we write it first and then create other structures. Such filesystem is not valid and should not be registered during device scan nor listed among devices from blkid. This patch will introduce two staged creation. In the first phase, the signature is wrong, but recognized as a partially created filesystem (by open or scan helpers). Once we successfully create and write everything, we fixup the signature. At this point automated scanning should find a valid filesystem on all devices. We can also rely on the partially created filesystem to do better error handling during creation. We can just bail out and do not need to clean up. The partial signature is '!BHRfS_M', can be shown by btrfs inspect-internal dump-super -F image Reviewed-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: introduce signature for a partially set up filesystemDavid Sterba2016-08-24
| | | | | | | | | | | | Currently the superblock is created first, with a valid signaure, but the rest of the filesystem is missing. When the creation process is interrupted, the filesystem still might be considered as valid. To prevent that, create the filesytem with an invalid signature that would be still recognized during the mkfs process, and finalize at the end. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: make superblock reading/scanning api more genericDavid Sterba2016-08-24
| | | | | | We'll add more modes that affect scanning. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: refactor and extend btrfs_prepare_device argumentsDavid Sterba2016-07-28
| | | | | | | | The message about discard is printed unconditionally and does not conform to the --quite option eg. in mkfs. Consolidate the operation flags into one argument and add support for verbosity. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: du: fix to skip not btrfs dir/fileWang Shilong2016-07-13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 'btrfs file du' is a very useful tool to watch my system file usage information with snapshot aware. when trying to run following commands: [root@localhost btrfs-progs]# btrfs file du / Total Exclusive Set shared Filename ERROR: Failed to lookup root id - Inappropriate ioctl for device ERROR: cannot check space of '/': Unknown error -1 and My Filesystem looks like this: [root@localhost btrfs-progs]# df -Th Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 16G 0 16G 0% /dev tmpfs tmpfs 16G 368K 16G 1% /dev/shm tmpfs tmpfs 16G 1.4M 16G 1% /run tmpfs tmpfs 16G 0 16G 0% /sys/fs/cgroup /dev/sda3 btrfs 60G 19G 40G 33% / tmpfs tmpfs 16G 332K 16G 1% /tmp /dev/sdc btrfs 2.8T 166G 1.7T 9% /data /dev/sda2 xfs 2.0G 452M 1.6G 23% /boot /dev/sda1 vfat 1.9G 11M 1.9G 1% /boot/efi tmpfs tmpfs 3.2G 24K 3.2G 1% /run/user/1000 So I installed Btrfs as my root partition, but boot partition can be other fs. We can Let btrfs tool aware of this is not a btrfs file or directory and skip those files, so that someone like me could just run 'btrfs file du /' to scan all btrfs filesystems. After patch, it will look like: Total Exclusive Set shared Filename 0.00B 0.00B - //root/.bash_logout 0.00B 0.00B - //root/.bash_profile 0.00B 0.00B - //root/.bashrc 0.00B 0.00B - //root/.cshrc 0.00B 0.00B - //root/.tcshrc This works for me to analysis system usage and analysis performaces. Signed-off-by: Wang Shilong <wangshilong1991@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: new helper for option parsing, more permissive for "no options"David Sterba2016-06-17
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Introduce function to setup temporary extent treeQu Wenruo2016-06-07
| | | | | | | | Introduce new function, setup_temporary_extent_tree() to build a temporary extent tree for make_btrfs_v2(). Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Introduce function to initialize csum treeQu Wenruo2016-06-07
| | | | | | | | Introduce new function, setup_temp_csum_tree(), to setup temporary csum tree for make_btrfs_v2(). Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Introduce function to initialize fs treeQu Wenruo2016-06-07
| | | | | | | | Introudce new function, setup_temp_fs_tree(), to setup temporary fs tree for make_btrfs_v2(). Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Introduce function to initialize device treeQu Wenruo2016-06-07
| | | | | | | | Introduce new function, setup_temp_device_tree(), to setup temporary device tree for make_btrfs_v2(). Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Introduce function to setup temporary chunk rootQu Wenruo2016-06-07
| | | | | | | | Introduce new function, setup_temp_chunk_root(), to initialize temporary chunk root for make_btrfs_v2(). Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Introduce function to setup temporary tree rootQu Wenruo2016-06-07
| | | | | | | | | | | | | | Introduce new function, setup_temp_tree_root(), to initialize temporary tree root for make_btrfs_v2(). The new function will setup tree root at metadata chunk and ensure data won't be written into metadata chunk. Also, new make_btrfs_v2() will have a much better code structure than old make_btrfs(). Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Introduce function to setup temporary superblockQu Wenruo2016-06-07
| | | | | | | | | Introduce a new function, setup_temp_super(), to setup temporary super for make_btrfs_v2(). Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> [ use __strncpy_null in setup_temp_super ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: utils: Introduce new function for convertQu Wenruo2016-06-07
| | | | | | | | | | | | | | | | Introduce new function make_convert_btrfs() for convert. This new function will have the following features: 1) Allocate temporary sb/metadata/system chunk, avoiding old used data 2) More structured functions No more over 1000 lines function, better function split and code reuse This will finally replace current make_btrfs(), but now only used for convert. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: utils: Introduce new pseudo random APIQu Wenruo2016-06-01
| | | | | | | | | | | | | | David has reported some quite chaos usage of pseudo random numbers. Like using static srand seed, or even calling rand() without setting seed correctly. The new pseudo random API will initialize the random seed on its first calling and use uniformly distributed pseudo random number generator as backend. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> [ renamed variables and functions, added prefixes ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: switch to common message helpers in utils.cDavid Sterba2016-06-01
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: typo review of strings and commentsNicholas D Steeves2016-06-01
| | | | | Signed-off-by: Nicholas D Steeves <nsteeves@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* 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>