summaryrefslogtreecommitdiff
path: root/cmds-subvolume.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: subvol: change set-default to also accept pathMisono, Tomohiro2017-11-14
| | | | | | | | | | | | | | | | | | This patch changes "subvol set-default" to also accept the subvolume path for convenience. If there are two args, they are assumed as subvol id and path to the fs (the same as current behavior), and if there is only one arg, it is assumed as the path to the subvolume. subvol id is resolved by test_issubvolume() + lookup_path_rootid(). The empty subvol (ino == 2) will get error on test_issubvolume() which checks whether inode num is 256 or not. Issue: #35 Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com> [ update documentation, use the new multi-line command scheme ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: subvol: group options in helpDavid Sterba2017-10-06
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: subvol: fix subvol del --commit-afterMisono, Tomohiro2017-10-06
| | | | | | | | | | | | | | | | Fix 'subvolume delete --commit-after' to work properly: - SYNC ioctl will be issued even when last delete fails - SYNC ioctl will be issued on each file system only once in the end To achieve this, get_fsid() and add_seen_fsid() are called after each delete to keep only one fd for each fs. In the end, seen_fsid_hash will be traversed and SYNC is issued on each fs. 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: subvol: exchange subvol del --commit-after and --commit-eachMisono, Tomohiro2017-10-06
| | | | | | | | | | Current code is reversed in --commit-after and --commit-each operation, i.e. --commit-after means --commit-each actually. This patch fixes this and also introduces enum type for more readable code. 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: 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: subvol show: fix the path use full_path as provided by the root ↵Anand Jain2017-07-20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | info This is a kind of preparatory patch for the patch which will add --rootid and --uuid options for the btrfs subvol show command. As of now btrfs subvol show is using the external user provided subvol path to show in the output. Which is kind of confusing. btrfs su show /btrfs /btrfs <-- Name: <FS_TREE> It will be even more confusing when proposed --uuid or --rootid options are used. btrfs su show --rootid 258 /btrfs /btrfs <-- Name: snap <-- UUID: 9630a45f-e647-4242-bd19-97590b4e20b2 Parent UUID: 30129358-c69d-3e4a-a662-29509cc69c95 Received UUID: - Creation time: 2017-07-12 12:43:28 +0800 Subvolume ID: 258 Generation: 9 Gen at creation: 9 Parent ID: 257 Top level ID: 257 Flags: - Snapshot(s): Now with this patch, it will only show what is provided by the root_info. btrfs su show --rootid 258 /btrfs sv1/snap <-- Name: snap UUID: 9630a45f-e647-4242-bd19-97590b4e20b2 Parent UUID: 30129358-c69d-3e4a-a662-29509cc69c95 Received UUID: - Creation time: 2017-07-12 12:43:28 +0800 Subvolume ID: 258 Generation: 9 Gen at creation: 9 Parent ID: 257 Top level ID: 257 Flags: - Snapshot(s): Signed-off-by: Anand Jain <anand.jain@oracle.com> 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: remove extra newline from messagesDavid Sterba2016-12-14
| | | | | | The common message helpers add the newline. 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: subvol list: cleanup layout argument setupDavid Sterba2016-11-09
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: subvol list: setup list filters laterDavid Sterba2016-11-09
| | | | | | First check for arguments and whether we can open the filesystem. 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: remove trivial helpers for filtering functionsDavid Sterba2016-09-21
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: subvol create: remove v from getoptDavid Sterba2016-09-21
| | | | | | | | The option 'v' was mistakenly added in 2ed161bd281beca29feebebbc8c4227cc6e918c3 but there's no such option for create at the moment, remove it. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: subvol delete: add missing verbose optionVincent Batts2016-09-21
| | | | | | | | There was already the logic for verbose output, but the flag parsing did not include it. Signed-off-by: Vincent Batts <vbatts@hashbangbash.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: switch ternary op to an if in cmd_subvol_showDavid Sterba2016-08-19
| | | | 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: subvolume sync: fix handling of -s optionMarek Rusinowski2016-05-11
| | | | | | | | | | | | | Setting check interval for subvolume sync resulted in picking wrong element from argv for it's value: $ btrfs subvolume sync -s 10 ./dir ERROR: invalid sleep interval ./dir $ btrfs subvolume sync ./dir -s 10 Segmentation fault Signed-off-by: Marek Rusinowski <marekrusinowski@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: 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 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: subvol get-default: fix argument parsingSatoru Takeuchi2016-03-18
| | | | | | | | | | | | | | | | | | | | | | | | | | "sub get-default" does't work since the following commit. commit 176aeca9a148 ("btrfs-progs: add getopt stubs where needed") * actual result ================================================== # ./btrfs sub get-default /btrfs btrfs subvolume get-default: too few arguments usage: btrfs subvolume get-default <path> Get the default subvolume of a filesystem ================================================== * expected result ================================================== # btrfs sub get-default /btrfs ID 5 (FS_TREE) ================================================== Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: subvol sync: fix memory corruption, undersized arrayDavid Sterba2016-03-17
| | | | | | | | | | | | | | The subvol sync command crashed randomly at the end with *** glibc detected *** btrfs: double free or corruption (out): 0x00000000006ab040 *** This is caused by running out of the ids array in case there are more than 128 subvolumes. The array is increased in steps but does not account the size of the item, so there was room for 1024 / 8 = 128 subvolume ids. Fixes: c9f885ec8963 ("btrfs-progs: subvol: let sync check only current deletions") 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: subvol show: use clean_args_no_options instead of opencodingDavid Sterba2016-01-14
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: also check filesystem type in test_issubvolumeDavid Sterba2016-01-14
| | | | | | | | A subvolume is a directory with inode number 256 on a btrfs filesytem. Add the missing check to test_issubvolume for completeness, otherwise we always do that in btrfs_open_dir. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: more verbose errors from test_issubvolumeDavid Sterba2016-01-14
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: let test_issubvolume return the exact errorDavid Sterba2016-01-14
| | | | | | Return any error from stat, minor cleanups. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: use symbolic name for subvolume inode number in test_issubvolumeDavid Sterba2016-01-14
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: handle errors from test_isdirDavid Sterba2016-01-14
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: subvol show: handle options by getoptDavid Sterba2016-01-13
| | | | | | | | | The subvolume show command does not take any optios but at least it should honor "--", as reported. Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=110181 Reported-by: <moviuro+kernel@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: remove unnecessary errno temp variablesDavid Sterba2016-01-12
| | | | | | | We can read errno directly if it's not clobbered by any intermediate calls. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: cmd subvolume: switch to common error message wrapperDavid Sterba2016-01-12
| | | | | | Message texts were adjusted. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: subvolume: use btrfs_open_dir for btrfs subvolume 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: # (/mnt/tmp is not btrfs mountpoint) # # btrfs subvolume create /mnt/tmp/123 Create subvolume '/mnt/tmp/123' ERROR: cannot create subvolume - Inappropriate ioctl for device # After patch: # btrfs subvolume create /mnt/tmp/123 ERROR: not btrfs filesystem: /mnt/tmp # Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: subvol sync: fix reversed conditionDavid Sterba2015-10-07
| | | | | | | | | | | In my local change to 07cc891d1d9819d5cf0628af555e7727d289cf7b ("btrfs-progs: Simplify all-subvolumn-clean condition for wait_for_subvolume_cleaning") that reversed the meaning of the variable dirty -> clean, I made a mistake and broke 'subvol sync' that will not wait as expected and ends prematurely. Zhao Lei's original patch worked. CC: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Simplify all-subvolumn-clean condition for ↵Zhao Lei2015-09-01
| | | | | | | | | | | | | wait_for_subvolume_cleaning Instead of using a dirty-subvolumn-counter in old code, this patch turn to use a simple and direct way: If (not dirty-subvolumn found in current loop) { return all_clean; } Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Simplify memory allocation for enumerate_dead_subvolsZhao Lei2015-09-01
| | | | | | | | | | | No need prepare memory for enumerate_dead_subvols() in caller, and pass additional argument for allocated length. Just do every thing inside enumerate_dead_subvols(), it will not increase malloc count, but make code simple. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Fix wrong return value of wait_for_subvolume_cleaning()Zhao Lei2015-09-01
| | | | | | | | | | | | | | | | Reproduce: # btrfs subvolume sync /mnt/btrfs Subvolume id 323 is gone # echo $? 1 # Reason: wait_for_subvolume_cleaning() return !0 in right case, because value of ret is set to "is subvolume clean" state before return. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Fix infinite loop of btrfs subvolumn syncZhao Lei2015-09-01
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We can trigger the bug by following operation: (no wait between commands 3~5) btrfs subvolume create /mnt/btrfs/mysubvol btrfs subvolume snapshot /mnt/btrfs/mysubvol /mnt/btrfs/mysubvol_snap btrfs subvolume delete /mnt/btrfs/mysubvol_snap btrfs subvolume delete /mnt/btrfs/mysubvol btrfs subvolume sync /mnt/btrfs The last command will not exit. Reason: List of "deleted subvolumes" are not currectly set. It caused by a typo of value assign, in detail: *ids[idx] = sh->offset; should be: (*ids)[idx] = sh->offset; So only first element is set to right memory address. If there are multiple "deleted subvolumes", program will keep wait. Above typo also caused some segment fault in my test. This patch fixed above bug. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: remove code for setup mntid in cmd_subvol_showZhao Lei2015-08-31
| | | | | | | | We don't need to use value of mntid in cmd_subvol_show(), no need to get its value. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.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: properly set up ioctl argumentsDavid Sterba2015-06-12
| | | | | | | | At some places we do not clear the whole ioctl structure and could pass garbage to kernel. Zero the ioctl vol_args and use a helper for copying the path. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: add helper to wait for subvolume cleaningDavid Sterba2015-06-09
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: subvol: let sync check only current deletionsDavid Sterba2015-06-09
| | | | | | | | | | | | | | | | | | | | So far the subvol sync command takes a shortcut and looks if there are any deleted subvols at all. It does not print the deleted subvolumes as they get cleaned. Arguably this is what the user would like to see and has to do $ btrfs subvol sync /path $(btrfs subvol list -d /path | "extract the ids") to see the progress. Make it look for all currently deleted subvolumes automatically and print the progress as if the ids were listed manually. This is a slight change in the semantics of the command. Previously, any new subvol deletion would prevent subvol sync to return. To simulate the old behaviour, run 'subvol sync' in a loop until it returns 0. 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: subvol show: tweak outputDavid Sterba2015-06-03
| | | | | | | | | - capitalize UUID - print otime with timezone - rename 'Object ID' to 'Subvolume ID' - add ID to Parent and Top level Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: subvol show: print received uuidDavid Sterba2015-06-03
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: getopt, use symbolic name for argument requirementsDavid Sterba2015-04-08
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: make getopt tables static constDavid Sterba2015-01-19
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>