summaryrefslogtreecommitdiff
path: root/cmds-subvolume.c
Commit message (Collapse)AuthorAge
* Btrfs-progs: switch to arg_strtou64() part3Wang Shilong2014-03-21
| | | | | | | | | Switch to new helper arg_strtou64(), also check if user assign a valid super copy. 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: fix double free when deleting subvolumesWang Shilong2014-01-31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Steps to reproduce: # mkfs.btrfs -f /dev/sda8 # mount /dev/sda8 /mnt # btrfs sub create /mnt/a # touch /mnt/b # btrfs sub create /mnt/c # btrfs sub delete /mnt/* Above steps will trigger following abortion: ERROR: 'b' is not a subvolume *** Error in `btrfs': double free or corruption (out): 0x0000000002116060 *** ======= Backtrace: ========= /lib64/libc.so.6[0x3fa467cef8] /lib64/libc.so.6(closedir+0xd)[0x3fa46b846d] btrfs[0x43e608] btrfs[0x40622f] btrfs[0x403d19] btrfs[0x4062c6] btrfs[0x403f68] We try to fix it by resetting @fd && @dirstream before trying next subvolume deletion. 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: fix minor grammar issuesMitchel Humpherys2014-01-31
| | | | | | | | Remove the extraneous `to' from `Can't access to X'. Signed-off-by: Mitchel Humpherys <mitch.special@gmail.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* btrfs-progs: add options to set commit mode after subvol deleteDavid Sterba2014-01-31
| | | | | | | | | | | | | | | | | | Subvolume deletion does not do a full transaction commit. This can lead to an unexpected result when the system crashes between deletion and commit, the subvolume directory will appear again. Add options to request filesystem sync after each deleted subvolume or after the last one. If the command with --commit option finishes succesfully, the subvolume(s) deletion status is safely stored on the media. Userspace approach is more flexible than in-kernel. Related discussions: http://www.spinics.net/lists/linux-btrfs/msg22088.html http://www.spinics.net/lists/linux-btrfs/msg27240.html CC: Alex Lyakas <alex.btrfs@zadarastorage.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* btrfs-progs: remove NULL-ptr judge before free for btrfs-progsGui Hecheng2014-01-31
| | | | | | | | | free(3) already checks the pointer for NULL, no need to do it on your own. This patch make the change globally. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* btrfs-progs: define BTRFS_UUID_UNPARSE_SIZE for uuid unparse buf sizeAnand Jain2014-01-31
| | | | | | | | | we use 37 as the allocation size to hold the uuid_unparse, here it defines BTRFS_UUID_UNPARSE_SIZE for the same. Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* btrfs-progs: fix potential double-frees in cmd_subvol_delete()Eric Sandeen2013-11-07
| | | | | | | | | | | | | If we "goto again" in cmd_subvol_delete(), and error out to out: before re-allocating the dupdname and dupvname pointers, we'll double-free them. Set them to NULL after freeing to avoid this. Resolves-Coverity-CID: 1125944 Resolves-Coverity-CID: 1125945 Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: set return value to 0 if subvolume get-default successfullyEryu Guan2013-11-07
| | | | | | | | | | cmd_subvol_get_default() returns 1 even if finds default subvolume successfully. Set the correct return value. Signed-off-by: Eryu Guan <guaneryu@gmail.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: add filter for deleted but uncleanded subvolumesDavid Sterba2013-10-24
| | | | | | | | | | | | | New option to subvolume list that acts as a global filter and applies the other filters to either live subvolumes or the uncleaned ones. The path to the deleted subvolumes is lost at the deletion time, sample output looks like: ID 259 gen 7 top level 0 path <FS_TREE>/DELETED Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: check return value of realpath(3)Eryu Guan2013-10-16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I hit a segfault when deleting a subvolume with very long name(>4096), it's because cmd_subvol_delete() calls strdup() and passes NULL as argument, which is returned by realpath(3). I used the following script to reproduce #!/bin/bash mnt=$1 i=1 path=$mnt/subvol_$i # Create very deep subvolumes while btrfs sub create $path;do ((i++)) path="$path/subvol_$i" done last_vol=$(dirname $path) dir=$(dirname $last_vol) vol=$(basename $last_vol) # Try to delete tha last one, this would get segfault pushd $dir btrfs sub delete $vol popd Fix it by checking return value of realpath(3), also fix the one in find_mount_root(). Signed-off-by: Eryu Guan <guaneryu@gmail.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: cmd_find_new: Sync fs before searching for modified files.chandan2013-10-16
| | | | | | | | | The sync makes sure that 'very recently' introduced delayed work is accounted for in the output of 'btrfs subvolume find-new' command. Signed-off-by: chandan <chandan@linux.vnet.ibm.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: free strdup()s that are not freedGui Hecheng2013-10-16
| | | | | | | | The strdup()s not freed are reported as memory leaks by valgrind. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> 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-subvolume.cWang Shilong2013-10-16
| | | | | | | | The patch also fixes some coding styles problems. 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: listing subvols and getting default subvol don't need a subv pathWang Shilong2013-08-09
| | | | | | | | | Listing subvolumes and getting default subvol in the filesystem don't need a subv path,Any valid path related to Btrfs filesystem is ok to finish the work. 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 reentrant localtimeDavid Sterba2013-08-09
| | | | | | | | | localtime may return NULL (when an error is detected eg. after setting tzname), followed by a segfault when the values is about to be used. localtime_r works, does not set tzname and does not return NULL. Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: fix possible memory leak related to subvolume/snapshot creationWang Shilong2013-08-09
| | | | | | | | | The operation related qgroup inherit may fails, if it fails, we should free memory allocated,otherwise, memory leak happens. 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: fix compile warnings in i386 machineWang Shilong2013-05-10
| | | | | | | | | | | | | | | | | | | | | | | | See the warnings below: [CC] btrfs-list.o btrfs-list.c: In function 'filter_by_parent': btrfs-list.c:1183:34: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] [CC] cmds-subvolume.o cmds-subvolume.c: In function 'cmd_subvol_show': cmds-subvolume.c:917:5: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] [CC] cmds-restore.o cmds-restore.c: In function 'decompress_lzo': cmds-restore.c:116:10: warning: passing argument 4 of 'lzo1x_decompress_safe' from incompatible pointer type [enabled by default] In file included from cmds-restore.c:31:0: /usr/include/lzo/lzo1x.h:77:1: note: expected 'lzo_uint *' but argument is of type 'size_t *' Reported-by: Russell Coker <russell@coker.com.au> Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: add quota-related info to usage messagesKoen De Wit2013-04-23
| | | | | | | | | | | Extending usage messages with some info on the quota functionality: - The -i option of "subvol create" and "subvol snapshot" was not documented - The -c option of "qgroup limit" is the default option - The "qouta rescan" command is not yet implemented, while it should be executed after enabling quota on a non-empty filesystem. Signed-off-by: Koen De Wit <koen.de.wit@oracle.com>
* 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>