summaryrefslogtreecommitdiff
path: root/cmds-subvolume.c
Commit message (Collapse)AuthorAge
* btrfs-progs: subvol delete: rename variable to match the option nameDavid Sterba2014-12-10
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: subvol delete: add verbosity optionDavid Sterba2014-12-10
| | | | | | Add an the option -v and use it for the transaction commit mode message. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: let subvol delete print commit mode inlineDavid Sterba2014-12-10
| | | | | | | | | | | | There are options to specify if the subvolume deletion should wait for commit after each subvol or at the end. This is reported at the beginning and considered as a noise. We'd like to report the mode for each subvolume instead. http://www.mail-archive.com/linux-btrfs%40vger.kernel.org/msg34617.html Reported-by: Marc MERLIN <marc@merlins.org Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: fix return value problem for btrfs sub showGui Hecheng2014-11-27
| | | | | | | | | | | | | | | | If you exec: # btrfs sub show <dir> <== non-subvolume dir The cmd print error messages as expected, but returns 0. By convetion, it should return non-zero and we should explicitly set it before it goto out. With other pieces adopted: 1) removed a unnecessary return value set -EINVAL 2) fixed another code branch which may return 0 upon error. 3) with 2) applied, the ret = 0 follows can be removed Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: wait until all subvolumes are cleanedDavid Sterba2014-10-10
| | | | | | | | Enhance the 'subvolume' subcommand to wait until a given list of subvolumes or all currently scheduled for deletion are cleaned completely from the filesystem. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Add -R to list UUIDs of original received subvolumeHugo Mills2014-09-14
| | | | | | | | | | | When using send/receive, it it useful to be able to match up source subvols on the send side (as, say, for -p or -c clone sources) with their corresponding copies on the receive side. This patch adds a -R option to btrfs sub list to show the received subvolume UUID on the receive side, allowing the user to perform that matching correctly. Signed-off-by: Hugo Mills <hugo@carfax.org.uk> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Fix spelling in btrfs sub list helpHugo Mills2014-08-22
| | | | | | | "below", not "bellow" Signed-off-by: Hugo Mills <hugo@carfax.org.uk> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: move test_isdir() to utils.cSatoru Takeuchi2014-08-22
| | | | | | | | | | | | Since test_isdir() is a utility function, it's better to move it to utils.c. In addition, "const char *" is more appropriate type as its "path" argument because this argument is not changed in this function. Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com> Cc: David Sterba <dsterba@suse.cz> Cc: Mike Fleetwood <mike.fleetwood@googlemail.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: introduce test_issubvolname() for simplicitySatoru Takeuchi2014-08-22
| | | | | | | | | | | There are many duplicated codes to check if the given string is correct subvolume name. Introduce test_issubvolname() for this purpose for simplicity. Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com> Cc: David Sterba <dsterba@suse.cz> Cc: Mike Fleetwood <mike.fleetwood@googlemail.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Unify the messy error message formatsSatoru Takeuchi2014-08-22
| | | | | Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Check fstype in find_mount_root()Qu Wenruo2014-08-22
| | | | | | | | | | | | | | When calling find_mount_root(), caller in fact wants to find the mount point of *BTRFS*. So also check ent->fstype in find_mount_root() and do special error string output in caller. This will suppress a lot of "Inapproiate ioctl for device" error message. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* 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>