summaryrefslogtreecommitdiff
path: root/cmds-inspect.c
Commit message (Collapse)AuthorAge
* btrfs-progs: treewide: Replace strerror(errno) with %m.Rosen Penev2018-01-31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As btrfs is specific to Linux, %m can be used instead of strerror(errno) in format strings. This has some size reduction benefits for embedded systems. glibc, musl, and uclibc-ng all support %m as a modifier to printf. A quick glance at the BIONIC libc source indicates that it has support for %m as well. BSDs and Windows do not but I do believe them to be beyond the scope of btrfs-progs. Compiled sizes on Ubuntu 16.04: Before: 3916512 btrfs 233688 libbtrfs.so.0.1 4899 bcp 2367672 btrfs-convert 2208488 btrfs-corrupt-block 13302 btrfs-debugfs 2152160 btrfs-debug-tree 2136024 btrfs-find-root 2287592 btrfs-image 2144600 btrfs-map-logical 2130760 btrfs-select-super 2152608 btrfstune 2131760 btrfs-zero-log 2277752 mkfs.btrfs 9166 show-blocks After: 3908744 btrfs 233256 libbtrfs.so.0.1 4899 bcp 2366560 btrfs-convert 2207432 btrfs-corrupt-block 13302 btrfs-debugfs 2151104 btrfs-debug-tree 2134968 btrfs-find-root 2281864 btrfs-image 2143536 btrfs-map-logical 2129704 btrfs-select-super 2151552 btrfstune 2130696 btrfs-zero-log 2276272 mkfs.btrfs 9166 show-blocks Total savings: 23928 (24 kilo)bytes Signed-off-by: Rosen Penev <rosenp@gmail.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: move command definitions to commands.hDavid Sterba2017-08-24
| | | | | | | There are some trivial helpers, we can group the command declarations in one place. 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: 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: use PATH_MAX in cmd_inspect_logical_resolveDavid Sterba2016-10-03
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: inspect: improved error handlingDavid Sterba2016-09-21
| | | | | | Two remaining BUG_ON, be more specific what's wrong. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: do not set optind if not necessaryDavid Sterba2016-07-13
| | | | | | | In the subcommand callbacks that are called just once, we don't need to explicitly reset optind. 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: 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: use ioctl search headers everywhereDavid Sterba2016-05-11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Generated by following semantic patch and manually tweaked. <SmPL> @@ struct btrfs_ioctl_search_header *SH; @@ ( - SH->objectid + btrfs_search_header_objectid(SH) | - SH->offset + btrfs_search_header_offset(SH) | - SH->transid + btrfs_search_header_transid(SH) | - SH->len + btrfs_search_header_len(SH) | - SH->type + btrfs_search_header_type(SH) ) </SmPL> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=112131 Reported-and-tested-by: Anatoly Pugachev <matorola@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: copy btrfs-calc-size to inspect-internal tree-statsAlexander Fougner2016-05-02
| | | | | Signed-off-by: Alexander Fougner <fougner89@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: inspect subvolid-resolve: fix argument parsingSatoru Takeuchi2016-03-18
| | | | | | | | | | | | | | | | | | | | | | | | | | "inspect-internal subvolid-resolve" doesn't work from the following commit. commit 176aeca9a148 ("btrfs-progs: add getopt stubs where needed") It's because 1st argument, subvolid, is also used for the pathname of filesystem. 2nd argument should be used for this purpose instead. * actual result ================================================== # ./btrfs inspect-internal subvolid-resolve 260 /btrfs ERROR: cannot access '260': No such file or directory ================================================== * expected result ================================================== # btrfs inspect-internal subvolid-resolve 260 /btrfs snap ================================================== Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: switch more error messages to common helpersDavid Sterba2016-03-14
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: inspect: remove unnecessary helpersDavid Sterba2016-03-14
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: unify naming of argc and argvDavid Sterba2016-03-14
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: add getopt stubs where neededDavid Sterba2016-03-14
| | | | | | | | | Commands that do not take any options do not use getopt, which means the standard option separator "--" does not work. Update all command handlers that need it, argv needs to be referenced using the optind that is correctly pointed after the separator. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: introduce inspect-internal dump-superAlexander Fougner2016-03-14
| | | | | | | | The long-term plan is to merge the features of standalone tools into the btrfs binary, reducing the number of shipped binaries. Signed-off-by: Alexander Fougner <fougner89@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: copy functionality of btrfs-debug-tree to inspect-internal ↵Alexander Fougner2016-03-14
| | | | | | | | | | subcommand The long-term plan is to merge the features of standalone tools into the btrfs binary, reducing the number of shipped binaries. Signed-off-by: Alexander Fougner <fougner89@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check for negative return value from ioctlDavid Sterba2016-01-12
| | | | | | | Handle only negative values returned by ioctl syscalls, with exception of the device remove. It returns positive values that are handled later. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: cleanup, move usage help strings closer to the command callbacksDavid Sterba2016-01-12
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: use on-stack buffer in __ino_to_path_fdDavid Sterba2015-11-13
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: inspect: use btrfs_open_dir for btrfs inspect commandZhao Lei2015-11-02
| | | | | | | | | | | | | | | | | | | | | | | | | | We can use btrfs_open_dir() to check whether target dir is in btrfs's mount point before open, instead of checking it in kernel space of ioctl, and return fuzzy error message. Before patch: # ./btrfs inspect-internal rootid /mnt/tmp1 ERROR: Failed to lookup root id - Inappropriate ioctl for device btrfs inspect-internal rootid: rootid failed with ret=-1 # ./btrfs inspect-internal inode-resolve 256 /mnt/tmp1 ioctl ret=-1, error: Inappropriate ioctl for device # ./btrfs inspect-internal min-dev-size /mnt/tmp1 Error invoking tree search ioctl: Inappropriate ioctl for device After patch: # ./btrfs inspect-internal rootid /mnt/tmp1 ERROR: not a btrfs filesystem: /mnt/tmp1 # ./btrfs inspect-internal inode-resolve 256 /mnt/tmp1 ERROR: not a btrfs filesystem: /mnt/tmp1 # ./btrfs inspect-internal min-dev-size /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: inspect: set return value of error caseZhao Lei2015-11-02
| | | | | | | | In case of open_file_or_dir() failed, ret is not set to right value, and the function will return unwanted value(ret of sprintf). Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: inspect: Bypass unnecessary clean function in open_errorZhao Lei2015-11-02
| | | | | | | No need to cleanup fd in open_fail case, because it is not opened. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: compilation errors when using musl libcBrendan Heading2015-08-31
| | | | | | | | | | | | | - limits.h must be included to pick up PATH_MAX. - remove double declaration of BTRFS_DISABLE_BACKTRACE kerncompat.h assumed that if __GLIBC__ was not defined, it could safely define BTRFS_DISABLE_BACKTRACE, however this can be defined by the configure script. Added a check to ensure it is not defined first. Signed-off-by: Brendan Heading <brendanheading@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: unify naming of command handlersDavid Sterba2015-08-31
| | | | | | Use cmd_ + group + command schema. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: inspect: add command min-dev-sizeDavid Sterba2015-08-31
| | | | | | | | | | Previously in 'filesystem resize get_min_size', now 'inspect-internal min-dev-size'. We'd like to avoid cluttering the 'resize' syntax further. The test has been updated to exercise the new option. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move min-resize implementation to inspect-internalDavid Sterba2015-08-31
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: inspect: Fix out of bounds string termination.Patrik Lundquist2015-06-26
| | | | | Signed-off-by: Patrik Lundquist <patrik.lundquist@gmail.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: use PATH_MAX instead of BTRFS_PATH_NAME_MAXDavid Sterba2015-06-12
| | | | | | | | | | The path bufferes should be PATH_MAX but BTRFS_PATH_NAME_MAX is shorter due to embedding in 4k aligned structures. The only reason to use BTRFS_PATH_NAME_MAX is for the respective structures btrfs_ioctl_vol_args::name. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: add command group info stringsDavid Sterba2015-06-09
| | | | | | They're printed in the 'btrfs' command group summary. 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: switch to arg_strtou64() part2Wang Shilong2014-03-21
| | | | | | Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* btrfs-progs: look up the containing tree root idDavid Sterba2013-10-16
| | | | | | | | | | Find the tree id of the containing subvolume for a given file or directory. For subvolume return it's own id. $ btrfs inspect-internal rootid <path> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: fix magic return value in cmds-inspect.cWang Shilong2013-10-16
| | | | | | Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: use NULL instead of 0Zach Brown2013-09-03
| | | | | | | | | These were mostly in option structs but there were a few gross string pointer arguments given as 0. Signed-off-by: Zach Brown <zab@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: Update the usage strings of some cmdsQu Wenruo2013-08-09
| | | | | | | | | | | Update the usage strings of some cmds to keep the them consistent with the source. Also some minor changes are done to fit the man page syntax. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: fix closing of opendir()Wang Shilong2013-08-09
| | | | | | | | | | valgrind complains open_file_or_dir() causes a memory leak.That is because if we open a directoy by opendir(), and then we should call closedir() to free memory. Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: add function to map subvol ID to pathStefan Behrens2013-04-23
| | | | | | | | | | | | | | | | Several tools like btrfs-send and btrfs-receive need to map a subvolume ID to a filesystem path. The so far existing methods in btrfs-list.c cause a horrible effort when performing this operation (and the effort is dependent on the number of existing subvolumes with quadratic effort). This commit adds a function that is able to map a subvolume ID to a filesystem path with an effort that is independent of the number of existing subvolumes. In addition to this function, a command line frontend is added as well: btrfs inspect-internal subvolid-resolve <subvolid> <path> Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
* btrfs-progs: Fix pointer math in __ino_to_path_fdMark Fasheh2013-02-19
| | | | | | | | | We are casting an array of u64 values into a char ** array so when we dereference this array (as a char **) on a 32 bit system we're then re-casting that back to a 32 bit value. This causes problems when we try to print those strings. Signed-off-by: Mark Fasheh <mfasheh@suse.de>
* btrfs-progs: zero out inspect ioctl argsEric Sandeen2013-02-05
| | | | | | | | Mostly just to keep things like coverity happy about potentially uninitialized structure members, since it doesn't grok the ioctl. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Zach Brown <zab@redhat.com>
* btrfs-progs: don't leak fds in logical resolveZach Brown2013-02-05
| | | | Signed-off-by: Zach Brown <zab@redhat.com>
* btrfs-progs: close fd in inode resolveZach Brown2013-02-05
| | | | Signed-off-by: Zach Brown <zab@redhat.com>
* Btrfs-progs: move open_file_or_dir() to utils.cAnand Jain2013-01-30
| | | | | | | | | | | The definition of the function open_file_or_dir() is moved from common.c to utils.c in order to be able to share some common code between scrub and the device stats in the following step. That common code uses open_file_or_dir(). Since open_file_or_dir() makes use of the function dirfd(3), the required XOPEN version was raised from 6 to 7. Signed-off-by: Anand Jain <anand.jain@oracle.com> Original-Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
* btrfs-progs: fix 32bit int/pointer cast warningsZach Brown2013-01-17
| | | | | | | | | | | | This uses uintptr_t to cast pointers to u64 ioctl arguments to silence some 32bit build warnings: cmds-inspect.c: In function ‘__ino_to_path_fd’: cmds-inspect.c:47:15: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] cmds-inspect.c: In function ‘cmd_logical_resolve’: cmds-inspect.c:171:15: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] Signed-off-by: Zach Brown <zab@redhat.com>
* Cast args to min to fix compiler warningsChris Mason2012-10-04
|
* Btrfs-progs: add options to change bufsize in logical to inode translationLiu Bo2012-10-04
| | | | | | | | | Add an option 's' to set bufsize in logical to inode transition, then we are able to read all the refs to the logical address. Meanwhile, set a max value 64k for the bufsize. Signed-off-by: Liu Bo <bo.li.liu@oracle.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: restructure list_subvolumesMiao Xie2012-10-04
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The current code of list_subvols() has very bad scalability, if we want to add new filter conditions or new sort methods, we have to modify lots of code. Beside that, the most code of list_snapshots() is similar to list_subvols(), So I restructure list_subvols(), and split the subvolume filter function, the subvolume sort function and the output function from list_subvols(). In order to implement it, we defined some importtant structures: struct btrfs_list_filter { btrfs_list_filter_func filter_func; void *data; }; struct btrfs_list_comparer { btrfs_list_comp_func comp_func; int is_descending; }; struct { char *name; char *column_name; int need_print; } btrfs_list_columns[]; If we want to add a new filter condition, we can choose a suitable filter function, or implement a new filter function[1], and add it into a set of the filters, and then pass the filter set into list_subvols(). We also can mix several filters (just add those filters into the set, and pass the set into list_subvols()) if the users specify two or more filter conditions. The subvolume sort function is similar to the subvolume filter function. The differentiation is the order of comparers in the array which is passed into list_subvols() show us the priority of the sort methods. The output function is different with the above two functions, we define a array to manage all the columns that can be outputed, and use a member variant (->need_print) to control the output of the relative column. Some columns are outputed by default. But we can change it according to the requirement of the users. After appling this patch, we needn't implement a independent list_snapshots() function, just pass a filter function which is used to identify the snapshot into list_subvols(). [1]: If we implement new filter functions or compare functions, we must add them into the array all_filter_funcs or the array all_comp_funcs, and modify the relative enum variants(btrfs_list_filter_enum, btrfs_list_comp_enum). Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>