summaryrefslogtreecommitdiff
path: root/utils.h
Commit message (Collapse)AuthorAge
* btrfs-progs: Factor out common print_device_infoNikolay Borisov2018-01-31
| | | | | | | | | This function has been copied twice in chunk-recover and super-recover. Factor it out into utils.c/h and use it. No functional changes. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: Use the whole file or block device to mkfs for rootdirQu Wenruo2018-01-08
| | | | | | | | | | | | | | | For --rootdir, even for large existing file or block device, it will always shrink the resulting filesystem. The problem is, mkfs.btrfs will try to calculate the dir size, and use it as @block_count to mkfs, which makes the filesystem shrunk. Fix it by trying to get the original block device or file size as @block_count, so mkfs.btrfs can use the full file/block device for --rootdir option. Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: fix regression preventing --rootdir to create fileQu Wenruo2018-01-08
| | | | | | | | | | | | | | | | Commit 460e93f25754 ("btrfs-progs: mkfs: check the status of file at mkfs") will try to check the file state before creating fs on it. The check is mostly fine for normal mkfs case, while for --rootdir option, it's allowed to create a new file if the destination file doesn't exist. Fix it by allowing non-existent file if --rootdir is specified. Fixes: 460e93f25754 ("btrfs-progs: mkfs: check the status of file at mkfs") Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: extent-cache: actually cache extent buffersJeff Mahoney2017-10-06
| | | | | | | | | | | | | | We have the infrastructure to cache extent buffers but we don't actually do the caching. As soon as the last reference is dropped, the buffer is dropped. This patch keeps the extent buffers around until the max cache size is reached (defaults to 25% of memory) and then it drops the last 10% of the LRU to free up cache space for reallocation. The cache size is configurable (for use by e.g. lowmem) when the cache is initialized. Signed-off-by: Jeff Mahoney <jeffm@suse.com> [ update codingstyle, switch total_memory to bytes ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: change seen_fsid to hold fd and DIRMisono, Tomohiro2017-10-06
| | | | | | | | | Change seen_fsid to hold fd and DIR in order to keep access to each fs. This will be used for 'subvol delete --commit-after'. Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com> Reviewed-by: Qu Wenruo <quwenruo.btrfs@gmx.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move seen_fsid to utils.cMisono, Tomohiro2017-10-06
| | | | | | | | | Move is_seen_fsid()/add_seen_fsid()/free_seen_fsid() to common functions. This will be used for 'subvol delete --commit-after'. Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com> Reviewed-by: Qu Wenruo <quwenruo.btrfs@gmx.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move get_fsid() to utils.cMisono, Tomohiro2017-10-06
| | | | | | | | | Make get_fsid() to a common functions. This will be used for 'subvol delete --commit-after'. Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com> Reviewed-by: Qu Wenruo <quwenruo.btrfs@gmx.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: inspect rootid: Allow a file to be specifiedMisono, Tomohiro2017-09-08
| | | | | | | | | | | | | Since cmd_inspect_rootid() calls btrfs_open_dir(), it rejects a file to be specified. But as the document says, a file should be supported. This patch introduces btrfs_open_file_or_dir(), which is a counterpart of btrfs_open_dir(), to safely check and open btrfs file or directory. The original btrfs_open_dir() content is moved to btrfs_open() and shared by both function. Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com> 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 csum_tree_block to use btrfs_fs_infoQu Wenruo2017-07-12
| | | | | Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move prefixcmp helper to utilsDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move message helpers out of 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: convert: move internal bg size definitionDavid 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 declarations to own header from utilsDavid 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 some common definitions to own headerDavid Sterba2017-03-08
| | | | | | | Start a header for various defines that are supposed to be used in any context or subpart. 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: 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: 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: remove stray function declarationDavid Sterba2016-10-03
| | | | 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: build: add more debugging featuresDavid Sterba2016-08-22
| | | | | | | | Add options to show file and line or stack trace for error/warning messages that use the common helpers. Possible to let any error stop execution for ease of analysis and debugging. 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: new helper for option parsing, more permissive for "no options"David Sterba2016-06-17
| | | | 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: use wider int type in btrfs_min_global_blk_rsv_sizeDavid Sterba2016-06-03
| | | | | | | | We know nodesize should not overflow with the shift, but le'ts make the code correct if the resulting type can store the full value. Resolves-coverity-id: 1358120 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: fix re-declared get_device_info()Anand Jain2016-05-02
| | | | | | | The other get_device_info() is in the same file, 4 lines above. Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: replace leafsize with nodesizeDavid Sterba2016-05-02
| | | | | | | | Nodesize is used in kernel, the values are always equal. We have to keep leafsize in headers, similarly the tree setting functions still take and set leafsize, but it's effectively a no-op. 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: 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: 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: libbtrfs: remove max/min macros from APIOndrej Kozina2016-03-14
| | | | | | | | | kerncompat.h header file is part of libbtrfs API. min/max macros cause conflict while building projects dependant on libbtrfs. Moving those macros to btrfs-progs internal header file fixes the conflict. Signed-off-by: Ondrej Kozina <okozina@redhat.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: add function attributes for the printf-likeDavid Sterba2016-01-12
| | | | | | Reported by gcc -Wsuggest-attribute=format . Signed-off-by: David Sterba <dsterba@suse.com>
* 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>