summaryrefslogtreecommitdiff
path: root/send-utils.c
Commit message (Collapse)AuthorAge
* btrfs-progs: send-utils: remove unused functions path_cat and path_cat3Gu Jinxiang2018-04-24
| | | | | | | | Since function path_cat and path_cat3 are not used anymore, remove them. They have been reprecated since version 4.0. Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* 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: handle failed strdup in subvol_uuid_search2David Sterba2016-12-14
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: fixup API after change in subvol_uuid_searchDavid Sterba2016-12-14
| | | | | | | | The return value fix to subvol_uuid_search changes the API semantics, we must keep it compatible, so we introduce a v2 interface that returns the negative error value in case of error. Library version bump will follow. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: subvol_uuid_search: return error code on memory allocation failurePrasanth K S R2016-12-14
| | | | | | | | | On failure of memory allocation for a 'struct subvol_info', we would end up dereferencing a NULL pointer. This commit fixes the issue by returning an error encoded pointer. Signed-off-by: Prasanth K S R <prasanth.ksr@dell.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: subvol_uuid_search: return error encoded pointerPrasanth K S R2016-12-14
| | | | | | | | This commit changes subvol_uuid_search() to return an error encoded pointer on failure. Signed-off-by: Prasanth K S R <prasanth.ksr@dell.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: subvol_uuid_search: return error on memory allocation failurePrasanth K S R2016-12-14
| | | | | | | | This commit fixes coverity defect CID 1328695. Resolves-coverity-id: 1328695 Signed-off-by: Prasanth K S R <prasanth.ksr@dell.com> 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: 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: 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: 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: drop argument from attribute deprecatedDavid Sterba2015-06-30
| | | | | | | | | | The optional argument to attribute 'deprecated' has been introduced in gcc 4.5, and does not build on 4.4 which is still in use. The recommended replacements are mentioned in the comment, not absolutely necessary to repeat it via the attribute. Reported-by: Amr El-Sharnoby <amr.elsharnoby@horizontechs.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: send utils: deprecate path_cat and path_cat3David Sterba2015-06-16
| | | | | | The functios do no allocation error handling, use _out variants instead. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: and new path_cat helpers to send utilsDavid Sterba2015-06-15
| | | | | | | Add versions of path_cat and path_cat3 that do not allocate the memory. The unhandled memory allocations are still there. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: use PATH_MAX instead of BTRFS_PATH_NAME_MAXDavid Sterba2015-06-12
| | | | | | | | | | The path bufferes should be PATH_MAX but BTRFS_PATH_NAME_MAX is shorter due to embedding in 4k aligned structures. The only reason to use BTRFS_PATH_NAME_MAX is for the respective structures btrfs_ioctl_vol_args::name. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: fix spacing in error messagesDavid Sterba2014-11-25
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Init root_item to avoid gcc 4.8.2 warningQu Wenruo2014-03-21
| | | | | | | | | | | When using gcc 4.8.2, -Wmaybe-uninitialized will report root_item may be used uninitialized. Since root_item_valid variant is used to determine the root_item valid, it's a false alert and to avoid the warning, just init it on allocation. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* btrfs-progs: enclose uuid tree compat code with ifdefsDavid Sterba2014-03-21
| | | | | | | | | | | Commit "Btrfs-progs: make send/receive compatible with older kernels" adds code that will become deprecated, let's clearly mark it in the sources. CC: Stefan Behrens <sbehrens@giantdisaster.de> CC: 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: make send/receive compatible with older kernelsWang Shilong2014-01-31
| | | | | | | | | | | | | | | Some users complaint that with latest btrfs-progs, they will fail to use send/receive. The problem is new tool will try to use uuid tree while it dosen't work on older kernel. Now we first check if we support uuid tree, if not we fall into normal search as previous way.i copy most of codes from Alexander Block's previous codes and did some adjustments to make it work. Signed-off-by: Alexander Block <ablock84@googlemail.com> 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 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 function to map subvol ID to pathStefan Behrens2013-04-23
| | | | | | | | | | | | | | | | Several tools like btrfs-send and btrfs-receive need to map a subvolume ID to a filesystem path. The so far existing methods in btrfs-list.c cause a horrible effort when performing this operation (and the effort is dependent on the number of existing subvolumes with quadratic effort). This commit adds a function that is able to map a subvolume ID to a filesystem path with an effort that is independent of the number of existing subvolumes. In addition to this function, a command line frontend is added as well: btrfs inspect-internal subvolid-resolve <subvolid> <path> Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
* Btrfs-progs: don't allocate one byte too much each timeStefan Behrens2013-04-23
| | | | | | | | | | str1 + '/' + str2 + '\0' requires a buffer with the size strlen(str1) + strlen(str2) + 2 bytes. str1 + '/' + str2 + '/' + str3 + '\0' requires a buffer with the size strlen(str1) + strlen(str2) + strlen(str3) + 3 bytes. Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
* Btrfs-progs: add a function to free subvol_uuid_search memoryStefan Behrens2013-04-23
| | | | | | | | There was no way to free the memory that was used for the subvol_uuid_search functions. Since this is part of the libbtrfs, add such a cleanup function. Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
* Btrfs-progs: ignore subvols above BTRFS_LAST_FREE_OBJECTIDStefan Behrens2013-04-23
| | | | Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
* Btrfs-progs: bugfix for subvolume parent determination in btrfs sendJan Schmidt2013-01-21
| | | | | | | | | | We missed to add the default subvolume, because it has no ROOT_BACKREF_ITEM. This made get_parent always fail for direct decendants of the default subvolume, resulting in lots of full streams where incremental streams were requested. Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net> Reviewed-by: Alexander Block <ablock84@googlemail.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: 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: fix several complie warningMiao Xie2012-10-04
| | | | | | | | | | | | | | This patch fixed the following warning: cmds-send.c:464:6: warning: ‘ret' may be used uninitialized in this function [-Wuninitialized] crc32c.c:121:1: warning: control reaches end of non-void function [-Wreturn-type] send-utils.c:69:11: warning: ‘comp' may be used uninitialized in this function [-Wuninitialized] send-utils.c:126:6: warning: ‘comp' may be used uninitialized in this function [-Wuninitialized] send-utils.c:99:22: warning: ‘entry' may be used uninitialized in this function [-Wuninitialized] btrfs.c:261:2: warning: implicit declaration of function ‘crc32c_optimization_init' [-Wimplicit-function-declaration] btrfs.c:105:2: warning: ‘cmd' may be used uninitialized in this function [-Wuninitialized] restore.c:435:12: warning: ignoring return value of ‘ftruncate', declared with attribute warn_unused_result [-Wunused-result] Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
* Allow relative paths for btrfs sendChris Mason2012-08-09
| | | | | | | | The initial btrfs send code was easily confused by relative paths and by anything that wasn't in the root of the FS. This fixes it to take relative paths. Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: add btrfs send/receive commandsAlexander Block2012-07-26
Add user space commands for btrfs send/receive. Signed-off-by: Alexander Block <ablock84@googlemail.com> Reviewed-by: David Sterba <dave@jikos.cz> Reviewed-by: Arne Jansen <sensille@gmx.net> Reviewed-by: Jan Schmidt <list.btrfs@jan-o-sch.net> Reviewed-by: Alex Lyakas <alex.bolshoy.btrfs@gmail.com>