summaryrefslogtreecommitdiff
path: root/utils.c
Commit message (Collapse)AuthorAge
* btrfs-progs: add crude error handling when transaction start failsDavid Sterba2017-09-08
| | | | | | | | | | Currently transaction bugs out insided btrfs_start_transaction in case of error, we want to lift the error handling to the callers. This patch adds the BUG_ON anywhere it's been missing so far. This is not the best way of course. Transforming BUG_ON to a proper error handling highly depends on the caller and should be dealt with case by case. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: subvol show: add support to search subvolume by rootid or uuidAnand Jain2017-07-20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Unless the top level is mounted there is no way to know the details of all the subvolume. For example: mount -o subvol=sv1/newsv1 /dev/sdb /btrfs btrfs su list /btrfs ID 257 gen 12 top level 5 path sv1 ID 258 gen 9 top level 257 path sv1/snap ID 259 gen 11 top level 257 path sv1/newsv1 You can't subvol show for sv1 and sv1/snap as its paths aren't accessible to the user unless the its top level is mounted. This patch adds two new options to the existing btrfs subvol show cli. They are --rootid/-r or --uuid/-u, with this now the user will be able to look for a subvolume using the rootid OR the uuid. ./btrfs su show -r 257 /btrfs sv1 Name: sv1 UUID: 30129358-c69d-3e4a-a662-29509cc69c95 Parent UUID: - Received UUID: - Creation time: 2017-07-11 20:32:57 +0800 Subvolume ID: 257 Generation: 12 Gen at creation: 7 Parent ID: 5 Top level ID: 5 Flags: - Snapshot(s): sv1/snap Signed-off-by: Anand Jain <anand.jain@oracle.com> [ minor adjustments in the help text ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Refactor btrfs_add_device() to use btrfs_fs_infoQu Wenruo2017-07-12
| | | | | | | | BTW, there is a duplicated definition of btrfs_add_device() in volumes.h, also remove it. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Refactor nodesize users in utils.cQu Wenruo2017-07-03
| | | | Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
* btrfs-progs: move prefixcmp helper to utilsDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move utils code out of headerDavid Sterba2017-03-08
| | | | | | | There are not performance critical static inlines, we can do the normal declaration/definition split for various helpers. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move mkfs helper implementation out of utilsDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move more mkfs declarations to the common headerDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move fs features implementation to own fileDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move fs features declarations to own header from utilsDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: convert: move common api implementation to own fileDavid Sterba2017-03-08
| | | | | | Lots of moved code but no actual changes. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: move common api implementation to own fileDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move convert definitions to own headerDavid Sterba2017-03-08
| | | | | | | Create a header for filesystem conversion API, the config and the main entry function. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move mkfs definitions to own headerDavid Sterba2017-03-08
| | | | | | | Create a header for filesystem creation API, the config and the main entry function. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move help implemetnation to own fileDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move help defines to own headerDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Introduce kernel sizes to cleanup large intermediate numberQu Wenruo2017-03-08
| | | | | | | | | | | Large numbers like (1024 * 1024 * 1024) may cost reader/reviewer to waste one second to convert to 1G. Introduce kernel include/linux/sizes.h to replace any intermediate number larger than 4096 (not including 4096) to SZ_*. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: introduce global configDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs/convert: separate the convert part from make_btrfsDavid Sterba2017-01-27
| | | | | | | The regulare mkfs_btrfs does not anything special about convert and just passes the arguments. Make that two functions. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: print device name while trimmingDavid Sterba2017-01-25
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: make negative number pretty printing optionalDavid Sterba2017-01-25
| | | | | | | Add a unit mode that will interpret the input number as a signed 64bit, optionally and not by default for all numbers. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: utils: negative numbers are more plausible than sizes over 8 EiBZygo Blaxell2017-01-25
| | | | | | | | | | | | | | | | | I got tired of seeing "16.00EiB" whenever btrfs-progs encounters a negative size value, e.g. during resize: Unallocated: /dev/mapper/datamd18 16.00EiB This version is much more useful: Unallocated: /dev/mapper/datamd18 -26.29GiB Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org> Reviewed-by: Omar Sandoval <osandov@fb.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Use helper function to access ↵Chandan Rajendra2016-12-14
| | | | | | | | | | | | | btrfs_super_block->sys_chunk_array_size btrfs_super_block->sys_chunk_array_size is stored as le32 data on disk. However insert_temp_chunk_item() writes sys_chunk_array_size in host cpu order. This commit fixes this by using super block access helper functions to read and write btrfs_super_block->sys_chunk_array_size field. Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move lookup_path_rootid to library utilsDavid Sterba2016-11-24
| | | | | | | | | | | The refactoring in commit 1c85c3de5aab997ff66ea95cb0f2c9f79726ec40 has broken use of libbtrfs that does not exhibit during build but at the run time. Fixes: 1c85c3de5aab997ff66ea95cb0f2c9f79726ec40 Bugzilla: https://bugs.gentoo.org/show_bug.cgi?id=600078 Reported-by: Mike Gilbert <floppymaster@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: utils: Fix NULL pointer derefernces in string_is_numericalQu Wenruo2016-11-23
| | | | | | | | | | | | | | In get_running_kernel_version() function, we directly pass return pointer from strtok_r() to string_is_numerical(). Return pointer from strok_r() can be NULL, but string_is_numerical() can't handle it and will cause NULL pointer derefernces. Fix it by check if it's a NULL pointer first. Resolves-Coverity-CID: 1374097 Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: add names of matching sysfs feature namesDavid Sterba2016-11-11
| | | | | | The mkfs parameters do not match file names exported through sysfs. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: enhance feature tableDavid Sterba2016-11-11
| | | | | | | Add string and numeric version for later use so we don't have to convert all the time. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: extend mkfs features with compat, safe and default versionsDavid Sterba2016-11-11
| | | | | | | Enhance the mkfs_features list with the minimum kernel versions that will allow for turning on compatible and/or safe options. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: add temporary variable for fs featuresDavid Sterba2016-11-11
| | | | | | A minor cleanup before other changes. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: use correct type for device id iteration in get_fs_infoDavid Sterba2016-11-09
| | | | | | | | Coverity reports (CID 1374096) that there's return value overflow of ret from get_device_info, but this most likely cannot happen. There's another minor issue where we use int to iterate over devids. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: fix search tree v2 ioctl detectionDavid Sterba2016-11-09
| | | | | | | The result of the test applies per-filesystem, so we can't simply cache it. The function hasn't been used yet. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: utils: remove useless check in make_btrfsDavid Sterba2016-11-09
| | | | | | | A leftover when fs_uuid was dynamically allocated, the condition was always true, no functional change. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: store creation time of the toplevel subvolumeDavid Sterba2016-11-09
| | | | | | | For unkonwn reasons, the creation time of the toplevel subvolume inode item hasn't been set. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: subvol show: print more details about toplevel subvolumeDavid Sterba2016-11-09
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The toplevel subvolume is special and the other listing code leaves it out so we have to add several special cases to handle it. There's no backreference so the path is built artificially. New helper btrfs_get_toplevel_subvol is a reduced version of btrfs_get_subvol. There's some information usually missing for the toplevel subvolume, eg. the uuid or creation info. This has to be fixed on the mkfs side, the other subvolumes are created by kernel. Example: /mnt Name: <FS_TREE> UUID: - Parent UUID: - Received UUID: - Creation time: - Subvolume ID: 5 Generation: 233 Gen at creation: 0 Parent ID: 0 Top level ID: 0 Flags: - Snapshot(s): subv1 Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: use existing rootid resolving helper in btrfs_list_get_path_rootidDavid Sterba2016-11-09
| | | | | | | | The utils helper is not verbose in case of an error, for now the helper used for subvolume listing will print the error message but not duplicate the ioctl anymore. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: rename lookup_ino_rootidDavid Sterba2016-11-09
| | | | | | It does not resolve the inode number but path where fd has been opened. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: rename btrfs_scan_lblkid() to btrfs_scan_devices()Karel Zak2016-10-25
| | | | | | | | | It seems like bad idea to use a library name (lblkid) within generic function name. The currently used scanning library is implementation detail and this detail should be hidden for rest of the code. Signed-off-by: Karel Zak <kzak@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: mkfs: detect version of running kernelDavid Sterba2016-10-25
| | | | | | Use the uname syscall and parse the string. Signed-off-by: David Sterba <dsterba@suse.com>
* 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>