summaryrefslogtreecommitdiff
path: root/cmds-subvolume.c
Commit message (Collapse)AuthorAge
* btrfs-progs: Free resources when returning error from cmd_subvol_create()Eric Sandeen2013-03-10
| | | | | | | | cmd_subvol_create() currently returns without freeing resources in almost every error case. Switch to a goto arrangement so all cleanup can be done in one place. Signed-off-by: Eric Sandeen <sandeen@redhat.com>
* btrfs-progs: tidy up cmd_subvol_create() whitespace & returnsEric Sandeen2013-03-10
| | | | | | Just whitespace fixes, and magical return value removal. Signed-off-by: Eric Sandeen <sandeen@redhat.com>
* btrfs-progs: Free resources when returning error from cmd_snapshot()Eric Sandeen2013-03-10
| | | | | | | | cmd_snapshot() currently returns without freeing resources in almost every error case. Switch to a goto arrangement so all cleanup can be done in one place. Signed-off-by: Eric Sandeen <sandeen@redhat.com>
* btrfs-progs: tidy up cmd_snapshot() whitespace & returnsEric Sandeen2013-03-10
| | | | | | Just whitespace fixes, and magical return value removal. Signed-off-by: Eric Sandeen <sandeen@redhat.com>
* btrfs-progs: close fd on cmd_subvol_list returnEric Sandeen2013-03-10
| | | | | | stops an fd leak that Coverity found. Signed-off-by: Eric Sandeen <sandeen@redhat.com>
* btrfs-progs: fix fd leak in cmd_subvol_set_defaultEric Sandeen2013-02-27
| | | | | | | | | | Rearrange cmd_subvol_set_default() slightly so we don't have to close the fd on an error return. While we're at it, fix whitespace & remove magic return values. Signed-off-by: Eric Sandeen <sandeen@redhat.com>
* btrfs-progs: close fd on cmd_subvol_get_default returnEric Sandeen2013-02-27
| | | | | | | | | Without this we leak the fd when we return from the function. Also, remove the senseless random return values. Signed-off-by: Eric Sandeen <sandeen@redhat.com>
* btrfs-progs: btrfs_list_get_path_rootid error handlingEric Sandeen2013-02-27
| | | | | | | | | | | btrfs_list_get_path_rootid() tries to return a negative number on error, but it's a u64 function. Callers which test for a return < 0 will never see an error. Change the function to fill in the rootid via a pointer, and then return a simple int as error. Signed-off-by: Eric Sandeen <sandeen@redhat.com>
* btrfs-progs: simplify ioctl name copy and null terminationEric Sandeen2013-02-05
| | | | | | | | | | | | | | | | | | | | | | | | | In the places where we copy a string into the name member of btrfs_ioctl_vol_args or btrfs_ioctl_vol_args_v2, we use strncopy (to not overflow the name array) and then set the last position to the null character. Howver, in both cases the arrays are defined with: char name[MAX+1]; hence the last array position is name[MAX]. In most cases, we now insert the null at name[MAX-1] which deprives us of one useful character. Even the above isn't consistent through the code, so make some helper code to make it simple, i.e. strncpy_null(dest, src) which automatically does the right thing based on the size of dest. Thanks to Zach Brown for the macro suggestion. Signed-off-by: Eric Sandeen <sandeen@redhat.com>
* btrfs-progs: fix name lengths in cmd_subvol_createEric Sandeen2013-02-05
| | | | | | | | | | | | | cmd_subvol_create() calls either BTRFS_IOC_SUBVOL_CREATE or BTRFS_IOC_SUBVOL_CREATE_V2 depending on whether or not inherit is set. However, these 2 ioctls have different args structures with different length name[] members. In the BTRFS_IOC_SUBVOL_CREATE case, the arg is btrfs_ioctl_vol_args, with a BTRFS_PATH_NAME_MAX length name, not a BTRFS_SUBVOL_NAME_MAX length name. Signed-off-by: Eric Sandeen <sandeen@redhat.com>
* btrfs-progs: don't leak inherit on errorsZach Brown2013-02-05
| | | | | | A few paths returned errors before freeing their inherit allocation. Signed-off-by: Zach Brown <zab@redhat.com>
* btrfs-progs: close ioctl fd in find newZach Brown2013-02-05
| | | | Signed-off-by: Zach Brown <zab@redhat.com>
* btrfs-progs: don't close(<0) in subvol createZach Brown2013-02-05
| | | | | | | Don't try to close an fd immediately after discovering that opening it failed. Signed-off-by: Zach Brown <zab@redhat.com>
* Btrfs-progs: dont print uuid unless -u option is givenAnand Jain2013-02-01
| | | | | | | | unless it was intentional to include uuid when -s option is (show snapshot only) given, we would need this break statement. Signed-off-by: Anand Jain <anand.jain@oracle.com>
* btrfs-progs: add option c to show ogenerationDavid Sterba2013-02-01
| | | | | | This will also pair the 'C' filter. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: add option g to show generationDavid Sterba2013-02-01
| | | | | | Add 'g' to pair the 'G' filter. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: upcase filter optionsDavid Sterba2013-02-01
| | | | | | | | Rename filter options in 'subvol list' subcommand, that way we can distinguish them from the options that just show some option in the output and can have a matching uppercase filter. Signed-off-by: David Sterba <dsterba@suse.cz>
* Btrfs-progs: add subvol flags to printAnand Jain2013-02-01
| | | | | | | This patch adds the flags row which as of now will show if the subvol/snapshot is readonly. Signed-off-by: Anand Jain <anand.jain@oracle.com>
* Btrfs-progs: Fix a small memory leak in managing the btrfs list filterAnand Jain2013-02-01
| | | | Signed-off-by: Anand Jain <anand.jain@oracle.com>
* Btrfs-progs: add show subcommand to subvol cliAnand Jain2013-02-01
| | | | | | | | This adds show sub-command to the btrfs subvol cli to display detailed inforamtion of the given subvol or snapshot. Signed-off-by: Anand Jain <anand.jain@oracle.com>
* Btrfs-progs: make printing subvol extensible to newer layoutsAnand Jain2013-02-01
| | | | | | | | Currently you can print subvol in a list or table format. This patch will provide a way to extend this to other formats like the upcoming raw format. Signed-off-by: Anand Jain <anand.jain@oracle.com>
* Btrfs-progs: add parent uuid for snapshotsAnand Jain2013-02-01
| | | | Signed-off-by: Anand Jain <anand.jain@oracle.com>
* Btrfs-progs: move printing subvol list outside of btrfs_list_subvolsAnand Jain2013-02-01
| | | | | | | To improve the code reuse its better to have btrfs_list_subvols just return list of subvols witout printing Signed-off-by: Anand Jain <anand.jain@oracle.com>
* Btrfs-progs: List all subvolumes by defaultLukas Czerner2013-02-01
| | | | | | | | | | | | | | | | | | | | | | | Commit a1e89891eb6af5381539d9875b85c196150171b6 changed subvolume list command so that we list only subvolumes under the specified directory. However this is confusing and unnecessary obstacle, because one usually want to see all subvolumes in the file system. It was introduced with the notion the full_path may be invalid which is not exactly true as the full_path is always relative to the root subvolume which makes perfect sense. Simply making option '-a' default is not enough since it introduces the relative/absolute path distinction effectively obfuscating the subvolume nesting. This commit returns the subvolume list command behaviour before commit a1e89891eb6af5381539d9875b85c196150171b6 where we list all subvolumes in the filesystem with path naming from root subovolume. IMO this is the best default as it is well understood and gives all the important information about file system subvolumes including subvolume nesting without the need to parse additional information. Signed-off-by: Lukas Czerner <lczerner@redhat.com>
* Btrfs-progs: add '-o' option into subvolume list commandLukas Czerner2013-02-01
| | | | | | | | This commit introduces new option '-o' to list only subvolumes under the specified path. This does not change subvolume list behaviour. It has been default in the past and it is even with this commit. Signed-off-by: Lukas Czerner <lczerner@redhat.com>
* Btrfs-progs: move path modification to filtersLukas Czerner2013-02-01
| | | | | | | | | | | | Commit 8e8e019e910f20947fea7eff5da40753639d8870 introduces -a option which will list all subvolumes with distinguishing between relative and absolute by prepending absolute patch with "<FS_TREE>". This commit moves the path modification to a filter code rather than doing so in path construction in resolve_root(). This gives us more flexibility in formatting path output. Signed-off-by: Lukas Czerner <lczerner@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: btrfs subvolume delete could delete subvolumesAnand Jain2012-10-04
| | | | | | | | | With this user will be able to provide more than one subvolume to delete. eg: btrfs subvolume delete <subvol1> <subvol2> Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-Progs: update '-s' option without a argument.Wang Shilong2012-10-04
| | | | | | | Since '--sort' options was given ,and we can list snapshots in generation order by --sort=+/-gen to replace '-s [0|1]' totally. Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujistsu.com>
* Btrfs-progs: introduces '-a' option into subvolume list commandWang Shilong2012-10-04
| | | | | | | | | | | | | | | We list the subvolumes under current directory according to the input subvolume. However, if we still want to list all the subvolumes in the tree, we can use '-a' option to help us. There may be two kinds of path: absolute path , relative path . The absolute path is beginning with "<FS_TREE>" The relative path is under current path that you input. Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
* Btrfs-Progs: fix subvolumes's some full_path invaild problems.Wang Shilong2012-10-04
| | | | | | | | | | | | | In the privous way, we list all the subvolumes in the filesystem default. But if a subvolume mounts on another directory, some result's full_path may be invaild. According to this, we try to list subvolumes under directoy only by default. In this way, all the subvolume can be arrived by the full_path. Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
* Btrfs-progs: introduce '-t' option into subvolume list commandMiao Xie2012-10-04
| | | | | | | | This patch introduces '-t' option into subvolume list command. By this option, we can output the result as a table. Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com> Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
* Btrfs-progs: introduce -g -c --sort options into btrfs subvol list commandwangshilong2012-10-04
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch introduces '-g' '-c' '--sort' options The option '-g' can help you filter the subvolumes by the generation, you may use it just like: btrfs subvol list -g +/-value <path> '+' means the generation of the subvolumes should >= the value you specified. '-' means the generation should <= the value If you don't input either '+' nor '-', this command will list the subvolumes that their generation equals to the value. However if you want to find gengeration between value1 and value2 you may use the above like: btrfs sub list -g -value1 -g +value2 <path> The option '-c' can help you filter the subvolumes by the ogeneration, you may use it just like: btrfs subvol list -c +/-value <path> The usage is the same to '-g' You might want to list subvolumes in order of some items, such as root id, gen and so on, you can use '--sort'. Now you can sort the subvolumes by root id, gen, ogen and path. For example: If you want to list subvolumes in order of rootid, you can use the option like that: btrfs sub list --sort=+/-rooid <path> Here, '+' means the result is sorted by ascending order. '-' is by descending order. If you don't specify either '+' nor '-', the result is sorted by default - ascending order. If you want to combine sort items, you do it like that: btrfs sub list --sort=-rootid,+path,ogen,gen <path> Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com> Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
* Btrfs-progs: enhance btrfs subvol list only to show read-only snapshotsMiao Xie2012-10-04
| | | | | | | | | | | | We want 'btrfs subvolume list' only to list readonly subvolumes, this patch set introduces a new option 'r' to implement it. You can use the command like that: btrfs subvolume list -r <path> Original-Signed-off-by: Zhou Bo <zhoub-fnst@cn.fujitsu.com> Signed-off-by: Miao Xie <miaox@cn.fujitsu.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>
* Btrfs-progs: fix wrong usage of btrfs subvolume list commandMiao Xie2012-10-04
| | | | | | | Since the uuid output function has been implemented, we should update the usage to tell the users. Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
* Btrfs-progs: move the function declarations to a new head fileZhou Bo2012-10-04
| | | | | | Move the function declarations to a new head file. Signed-off-by: Zhou Bo <zhoub-fnst@cn.fujitsu.com>
* Btrfs-progs: add -u to show subvol uuidAnand Jain2012-10-04
| | | | | | | Applications would need to know the uuid to manage the configurations associated with the subvol and snapshots Signed-off-by: Anand Jain <anand.jain@oracle.com>
* Btrfs-progs: list snapshots by generationLiu Bo2012-10-04
| | | | | | | | | | | | | | | The idea is that we usually use snapshot to backup/restore our data, and the common way can be a cron script which makes lots of snapshots, so we can end up with spending some time to find the latest snapshot to restore. This adds a feature for 'btrfs subvolume list' to let it list snapshots by their _created_ generation. What we need to do is just to list them in descending order and get the latest snapshot. What's more, we can find the oldest snapshot as well by listing snapshots in ascending order. Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
* Btrfs progs: quota groups supportArne Jansen2012-09-04
| | | | | Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net> Signed-off-by: Arne Jansen <sensille@gmx.net>
* Fix "set-dafault" typo in cmds-subvolume.cChris Samuel2012-07-03
| | | | | | | Andrei Popa reported that there were two typos of default as dafault, this patch fixes those two typos up. Signed-off-by: Chris Samuel <chris@csamuel.org>
* mkfs: avoid heap-buffer-read-underrun for zero-length "size" argJim Meyering2012-06-05
| | | | | | | | * mkfs.c (parse_size): ./mkfs.btrfs -A '' would read and possibly write the byte before beginning of strdup'd heap buffer. All other size-accepting options were similarly affected. Reviewed-by: Josef Bacik <josef@redhat.com>
* avoid several strncpy-induced buffer overrunsJim Meyering2012-06-05
| | | | | | | | | | | | | | * restore.c (main): Ensure strncpy-copied dir_name is NUL-terminated. * btrfsctl.c (main): Likewise, for a command-line argument. * utils.c (multiple functions): Likewise. * btrfs-list.c (add_root): Likewise. * btrfslabel.c (change_label_unmounted): Likewise. * cmds-device.c (cmd_add_dev, cmd_rm_dev, cmd_scan_dev): Likewise. * cmds-filesystem.c (cmd_resize): Likewise. * cmds-subvolume.c (cmd_subvol_create, cmd_subvol_delete, cmd_snapshot): Likewise. Reviewed-by: Josef Bacik <josef@redhat.com>
* Btrfs-progs: allow multi-line command group synopsisIlya Dryomov2012-02-08
| | | | Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
* Btrfs-progs: switch all existing commands to a new parserIlya Dryomov2012-02-03
| | | | | | | The new infrastructure offloads checking number of arguments passed to a command to individual command handlers. Fix them up accordingly. Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
* Btrfs-progs: rearrange files in the repoIlya Dryomov2012-02-03
Separate every command group into its own file (cmds_<group>.c) and rearrange includes. Remove btrfs_cmds.c. Signed-off-by: Ilya Dryomov <idryomov@gmail.com>