summaryrefslogtreecommitdiff
path: root/cmds-send.c
Commit message (Collapse)AuthorAge
* btrfs-progs: send: check for output file existence before creatingDavid Sterba2016-11-11
| | | | | | | | In some cases the root might not be able to create the output file (and streaming to stdout is not an option). Make the output file creation two step and let it work if the file is already created. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: send: fix handling of -c optionTsutomu Itoh2016-11-11
| | | | | | | | | | | | | | | | | | | | | When two or more -c options are specified, cannot find a suitable parent. So, output stream is bigger than correct one. [before] At subvol Snap1 At subvol Snap2 At subvol ../SnapY -rw------- 1 root root 3153 Oct 19 10:37 /tmp/data1 [after] At subvol Snap1 At subvol Snap2 At subvol ../SnapY -rw------- 1 root root 1492 Oct 19 10:39 /tmp/data1 Signed-off-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com> [ constify subvol argument, renamed single letter variables ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: send: cleanup use of ctransid delta temporary variable in ↵David Sterba2016-11-09
| | | | | | find_good_parent Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: send: cleanup, rename send context variablesDavid Sterba2016-11-09
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: send: cleanup, rename some variables in dump_threadDavid Sterba2016-11-09
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: send: clean types in write_bufDavid Sterba2016-11-09
| | | | | | Use matching types for buffer, return value and buffer sizes. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: send: use proper type for read result, and rename the variableDavid Sterba2016-11-09
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: send: increase size of transfer bufferDavid Sterba2016-11-09
| | | | | | | | | | | | | | | | | | 4K is quite small, increase it to 64K. This reduces number of context switches and calls to read. Kernel sends us about 50K of data per read, so increasing the buffer further does not make any improvement. Example run on tests/cli-tests/004-send-parent-multi-subvol: 4K: - ~800 context switches - ~5000 calls to read 64K: - ~450 context switches - ~500 calls to read Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: send: constify some arugmentsDavid Sterba2016-11-09
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: send: fix handling of multiple snapshots (-p option)Tsutomu Itoh2016-11-09
| | | | | | | | | | | | | | | | | | | | We cannot send multiple snapshots at once by -p option. [before] # btrfs send -f /tmp/data0 -p Snap0 Snap[12] At subvol Snap1 At subvol Snap2 ERROR: parent determination failed for 0 # [after] # btrfs send -f /tmp/data0 -p Snap0 Snap[12] At subvol Snap1 At subvol Snap2 # Signed-off-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: send: remove unnecessary codeTsutomu Itoh2016-10-25
| | | | | | | | | | Some unnecessary codes are deleted. - the setting of subvol is duplicated - read only check was already done by the previous loop Signed-off-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: send: add quiet optionM G Berberich2016-06-01
| | | | | | | | | | | | Add new options -q,--quiet to prevent printing messages on stderr, added --verbose as alternative for -v. Moved 'Mode NO_FILE_DATA enabled' message to stderr. The default verboisty level is 1 to keep some backward compatibility. Signed-off-by: M G Berberich <btrfs@oss.m-berberich.de> [ minor adjustments in the options, help text and changelog, added manual page text ] 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: make error message from add_clone_source more genericDavid Sterba2016-03-30
| | | | | | Do not hardcode the error message. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: send: fix handling of multiple snapshotsTsutomu Itoh2016-03-30
| | | | | | | | | | | | | | | | | | | | We cannot send multiple snapshots at once. [before fix] # btrfs send ./snap[12] > snap12.data At subvol ./snap1 At subvol ./snap2 ERROR: parent determination failed for 0 # [after fix] # btrfs send ./snap[12] > snap12.data At subvol ./snap1 At subvol ./snap2 # Signed-off-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: rename get_subvol_name() to subvol_strip_mountpoint()Anand Jain2016-03-30
| | | | | | Signed-off-by: Anand Jain <anand.jain@oracle.com> [ renamed from subvol_minus_mnt to subvol_strip_mountpoint ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move get_subvol_name() 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: describe btrfs-send requires read-only subvolumeSatoru Takeuchi2016-02-04
| | | | | | | | Both man btrfs-send(8) and usage message don't describe btrfs-send needs read-only snapshot as its argument. Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.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: cmd send: switch to common error message wrapperDavid Sterba2016-01-12
| | | | | | Message texts were adjusted. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: add newline to some error messagesTsutomu Itoh2015-08-31
| | | | | | | | | Added a missing newline to some error messages. Also printf() was changed to fprintf(stderr) for error messages. Signed-off-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com> Reviewed-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: fix memory leaks in error pathByongho Lee2015-08-31
| | | | | | | | | | This patch includes below fixes in error path: 1. fix memory leaks if realloc() fails 2. add missing call free_history() before return error in scrub_read_file() Signed-off-by: Byongho Lee <bhlee.kernel@gmail.com> Reviewed-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: send: use static buffer for output file nameDavid Sterba2015-06-15
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: send: add option to for the no-data modeDavid Sterba2015-06-12
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: drop feature defines from C files, in favour of CFLAGS definesDimitri John Ledkov2015-01-27
| | | | | | | | | | | | | | | | | | | | | | glibc 2.10+ (5+ years old) enables all the desired features: _XOPEN_SOURCE 700, __XOPEN2K8, POSIX_C_SOURCE, DEFAULT_SOURCE; with a single _GNU_SOURCE define in the makefile alone. For portability to other libc implementations (e.g. dietlibc) _XOPEN_SOURCE=700 is also defined. This also resolves Debian bug report filed by Michael Tautschnig - "Inconsistent use of _XOPEN_SOURCE results in conflicting declarations". Whilst I was not able to reproduce the results, the reported fact is that _XOPEN_SOURCE set to 500 in one set of files (e.g. cmds-filesystem.c) generates/defines different struct stat from other files (cmds-replace.c). This patch thus cleans up all feature defines, and sets them at a consistent level. Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=747969 Signed-off-by: Dimitri John Ledkov <dimitri.j.ledkov@intel.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: check allocation result in add_clone_sourceDavid Sterba2014-12-19
| | | | | | Resolves-Coverity-CID: 1054894 Reviewed-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: fix compiler warningChristian Hesse2014-11-07
| | | | | | | | | | | gcc 4.9.0 gives warnings about possibly uninitialized values when compiling with function inlining and optimization level two enabled (CFLAGS="-finline-functions -O2"). Initializing the values fixes the warning. Hope this is correct. Signed-off-by: Christian Hesse <mail@eworm.de> 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: Remove fprintf() in find_mount_root().Qu Wenruo2014-08-22
| | | | | | | | | | | find_mount_root() function in utils.c should not print error string. Caller should be responsible to print error string. This patch will remove the only fprintf in find_mount_root() and modify the caller a little to use strerror() to prompt users. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: use check_argc_* to check arg number for all toolsGui Hecheng2014-08-22
| | | | | | | | | | | | Since this patch: btrfs-progs: move the check_argc_* functions into utils.c All tools including the independent tools(e.g. btrfs-image, btrfs-convert) can share the convenience of the check_argc_* functions, so this patch adopt the argc check functions globally. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Remove unneeded assert in find_good_parent().Qu Wenruo2014-08-22
| | | | | | | | | | | | find_good_parent() uses assert to deal with the problem that clone source's parent can't be found. But in fact the assert is somewhat overkilled since subvol_uuid_search() has enough error messages for debug and caller of find_good_parent() can handle the problems in find_good_parent(), so the assert can be removed without any problem. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* Btrfs-progs: remove unsed pthread attribute objectsRakesh Pandit2014-04-22
| | | | | | | | | Threads always use default attributes in all tools, so pthread attribute objects and their initializations are of no use. Just pass NULL as attr attribute to pthread_create for default attributes. Signed-off-by: Rakesh Pandit <rakesh@tuxera.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: use usage() to replace the warning msg on no-arg usageGui Hecheng2014-03-21
| | | | | | | | | To be consistent with the other cmds, replace the warning msg with usage() when send/receive are used without any args. 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: move find_mount_root to utils.[ch]Qu Wenruo2014-03-21
| | | | | | | | Move find_mount_root to utils.[ch] for general use. Signed-off-by: Qu Wenruo <quwenruo@cn.fuijitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* btrfs-progs: update send help strings and manpageDavid Sterba2014-01-31
| | | | | | | | | - send accepts multiple subvolumes - add missing option -e to man - minor man formatting fix Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* btrfs-progs: send: check if parent or clone sources are read-onlyDavid Sterba2014-01-31
| | | | | Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* Btrfs-progs: avoid using btrfs internal subvolume path to sendWang Shilong2014-01-31
| | | | | | | | | | | | | | | | | | | | | Steps to reproduce: # mkfs.btrfs -f /dev/sda # mount /dev/sda /mnt # btrfs subvolume create /mnt/foo # umount /mnt # mount -o subvol=foo /dev/sda /mnt # btrfs sub snapshot -r /mnt /mnt/snap # btrfs send /mnt/snap > /dev/null We will fail to send '/mnt/snap',this is because btrfs send try to open '/mnt/snap' by btrfs internal subvolume path 'foo/snap' rather than relative path based on mounted point, this will return us 'no such file or directory',this is not right, fix it. Reported-by: Thomas Scheiblauer <tom@sharkbay.at> 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: use mntent functions in find_mount_rootDavid Sterba2014-01-31
| | | | | | | | getmntent should be used in context of *mntent functions, though fopen/fclose works. Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* btrfs-progs: use /proc/self/mountsAnand Jain2014-01-31
| | | | | | 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 test for return of realpath in find_mount_root()Eric Sandeen2013-11-07
| | | | | | | | | | find_mount_root() tries to test for realpath() failure, but tests the wrong value. Fix it. Resolves-Coverity-CID: 1125940 Signed-off-by: Eric Sandeen <sandeen@redhat.com> Reviewed-by: Anand Jain <anand.jain@oracle.com> 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: check fopen failure in cmds-sendZach Brown2013-10-16
| | | | | | | | | | Check for fopen() failure. This shows up in static analysis as a possible null pointer derference. Signed-off-by: Zach Brown <zab@redhat.com> Laughed-at-by: Stefan Behrens <sbehrens@giantdisaster.de> 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-send.cWang Shilong2013-10-16
| | | | | | | | If btrfs send return failure, we return 1,otherwise 0 will be returned. 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: drop weird indirections & dead code from send/receiveEric Sandeen2013-09-03
| | | | | | | | | | | | | cmds-recieve.c & cmds-send.c seem to have weird wrappers and indirections, and "groups" of commands which have only one member, which are never referenced in the code. I think these can be removed. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Reviewed-by: Stefan Behrens <sbehrens@giantdisaster.de> 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: use UUID tree for send/receiveStefan Behrens2013-08-09
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit changes the btrfs send/receive commands to use the UUID tree to map UUIDs to subvolumes, and to use the root tree to map subvolume IDs to paths. Now these tools start fast and are independent on the number of subvolules/snapshot that exist. Before this commit, mapping UUIDs to subvolume IDs was an operation with a high effort. The algorithm even had quadratic effort (based on the number of existing subvolumes). E.g. with 15,000 subvolumes it took much more than 5 minutes on a state of the art XEON CPU to start btrfs send or receive before these tools were able to send or receive the first byte). Even linear effort instead of the current quadratic effort would be too much since it would be a waste. And these data structures to allow mapping UUIDs to subvolume IDs had been created every time a btrfs send/receive instance was started. It is much more efficient to maintain a searchable persistent data structure in the filesystem, one that is updated whenever a subvolume/snapshot is created and deleted, and when the received subvolume UUID is set by the btrfs-receive tool. Therefore kernel code was added that is able to maintain data structures in the filesystem that allow to quickly search for a given UUID and to retrieve data that is assigned to this UUID, like which subvolume ID is related to this UUID. Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: add send option for using new end-cmd semanticStefan Behrens2013-08-09
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit adds a command line option to enable sending streams which make use of the new end-cmd semantic if multiple snapshots are sent back-to-back. The goal is to use the <end cmd> as an indication to stop reading the input stream. So far, the receiver could only use EOF to recognize the end. If the new command line option '-e' is set, this commit requires a kernel which is able to support the new flags in the send ioctl. New bits in the flags of the send ioctl will be set which cause EINVAL on old kernels. However, if the option '-e' is not set, it works with old and new kernels without any errors or any changed behavior. This used to be the encoding (with 2 snapshots in this example): <stream header> + <sequence of commands> + <end cmd> + <stream header> + <sequence of commands> + <end cmd> + EOF The new format (if the two new flags are used) is this one: <stream header> + <sequence of commands> + <sequence of commands> + <end cmd> Note that the currently existing receivers treat <end cmd> only as an indication that a new <stream header> is following. This means, you can just skip the sequence <end cmd> <stream header> without loosing compatibility. As long as an EOF is following, the currently existing receivers handle the new format (if the two new flags are used) exactly as the old one. Also note that the kernel interface was changed in a way that is backward compatible to old btrfs-progs tools. You set one or two bits in the flags field of the ioctl to enable the new behavior. Old tools set these flags to zero, thus getting exactly the same as they got with older kernels. And this is exactly what happens if the new '-e' option is not set, the new bits in the flags are not set and thus old kernels and new kernels are both supported. So what is the benefit of this change? The goal is to be able to use a single stream (one TCP connection) to multiplex a request/response handshake plus Btrfs send streams, all in the same stream. In this case you cannot evaluate an EOF condition as an end of the Btrfs send stream. You need something else, and the <end cmd> is just perfect for this purpose. Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: btrfs-send: free used memory and close fdsStefan Behrens2013-04-23
| | | | | | | | Not important at all since exit() is called afterwards and this is not part of the library. It just makes valgrind happy and thus allows to search for real flaws. Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
* btrfs-progs: Fix the receive code pathingAlex Lyakas2013-04-23
| | | | | | | | | | | | | The receive code was not distinguishing properly between the mount root and the directory to create the received subvolume in. Also make sure the find_mount_root reports an error if it cannot find a match at all. Reported-by: Robert Buhren <robert@robertbuhren.de> Reported-by: Rory Campbell-Lange <rory@campbell-lange.net> Reported-by: Stefan Priebe - Profihost AG <s.priebe@profihost.ag> Signed-off-by: Alex Lyakas <alex.btrfs@zadarastorage.com> Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>