summaryrefslogtreecommitdiff
path: root/cmds-receive.c
diff options
context:
space:
mode:
authorStefan Behrens <sbehrens@giantdisaster.de>2013-06-26 17:17:57 +0200
committerDavid Sterba <dsterba@suse.cz>2013-08-09 14:32:31 +0200
commit5f9c5a23e5ff0c5949480ad24a9818c50f5a8dc6 (patch)
tree24b605db2a3d20b4ef49ba4242060df3d0a80635 /cmds-receive.c
parentad280c1b3a8a88e2113dd1bcb725a36be7da5356 (diff)
Btrfs-progs: use UUID tree for send/receive
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>
Diffstat (limited to 'cmds-receive.c')
-rw-r--r--cmds-receive.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/cmds-receive.c b/cmds-receive.c
index c2fa2e1d..4e480f91 100644
--- a/cmds-receive.c
+++ b/cmds-receive.c
@@ -31,6 +31,7 @@
#include <math.h>
#include <ftw.h>
#include <wait.h>
+#include <assert.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -129,14 +130,14 @@ static int finish_subvol(struct btrfs_receive *r)
goto out;
}
- ret = btrfs_list_get_path_rootid(subvol_fd, &r->cur_subvol->root_id);
- if (ret < 0)
- goto out;
- subvol_uuid_search_add(&r->sus, r->cur_subvol);
- r->cur_subvol = NULL;
ret = 0;
out:
+ if (r->cur_subvol) {
+ free(r->cur_subvol->path);
+ free(r->cur_subvol);
+ r->cur_subvol = NULL;
+ }
if (subvol_fd != -1)
close(subvol_fd);
return ret;
@@ -197,7 +198,7 @@ static int process_snapshot(const char *path, const u8 *uuid, u64 ctransid,
struct btrfs_receive *r = user;
char uuid_str[128];
struct btrfs_ioctl_vol_args_v2 args_v2;
- struct subvol_info *parent_subvol;
+ struct subvol_info *parent_subvol = NULL;
ret = finish_subvol(r);
if (ret < 0)
@@ -268,6 +269,10 @@ static int process_snapshot(const char *path, const u8 *uuid, u64 ctransid,
}
out:
+ if (parent_subvol) {
+ free(parent_subvol->path);
+ free(parent_subvol);
+ }
return ret;
}
@@ -557,7 +562,7 @@ static int process_clone(const char *path, u64 offset, u64 len,
const char *clone_path, u64 clone_offset,
void *user)
{
- int ret = 0;
+ int ret;
struct btrfs_receive *r = user;
struct btrfs_ioctl_clone_range_args clone_args;
struct subvol_info *si = NULL;
@@ -624,6 +629,10 @@ static int process_clone(const char *path, u64 offset, u64 len,
}
out:
+ if (si) {
+ free(si->path);
+ free(si);
+ }
free(full_path);
free(full_clone_path);
free(subvol_path);