btrfs-progs: receive: use static buffer for cur_subvol
Get rid of the allocation. The logic is changed so that a NULL cur_subvol::path means that no subvolume/snapshot has been found so far. Signed-off-by: David Sterba <dsterba@suse.cz>
This commit is contained in:
parent
6a039e5063
commit
230ab9376c
|
@ -64,7 +64,7 @@ struct btrfs_receive
|
||||||
char *full_root_path;
|
char *full_root_path;
|
||||||
int dest_dir_chroot;
|
int dest_dir_chroot;
|
||||||
|
|
||||||
struct subvol_info *cur_subvol;
|
struct subvol_info cur_subvol;
|
||||||
|
|
||||||
struct subvol_uuid_search sus;
|
struct subvol_uuid_search sus;
|
||||||
|
|
||||||
|
@ -87,21 +87,21 @@ static int finish_subvol(struct btrfs_receive *r)
|
||||||
char uuid_str[BTRFS_UUID_UNPARSED_SIZE];
|
char uuid_str[BTRFS_UUID_UNPARSED_SIZE];
|
||||||
u64 flags;
|
u64 flags;
|
||||||
|
|
||||||
if (r->cur_subvol == NULL)
|
if (r->cur_subvol.path == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
subvol_fd = openat(r->mnt_fd, r->cur_subvol->path,
|
subvol_fd = openat(r->mnt_fd, r->cur_subvol.path,
|
||||||
O_RDONLY | O_NOATIME);
|
O_RDONLY | O_NOATIME);
|
||||||
if (subvol_fd < 0) {
|
if (subvol_fd < 0) {
|
||||||
ret = -errno;
|
ret = -errno;
|
||||||
fprintf(stderr, "ERROR: open %s failed. %s\n",
|
fprintf(stderr, "ERROR: open %s failed. %s\n",
|
||||||
r->cur_subvol->path, strerror(-ret));
|
r->cur_subvol.path, strerror(-ret));
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&rs_args, 0, sizeof(rs_args));
|
memset(&rs_args, 0, sizeof(rs_args));
|
||||||
memcpy(rs_args.uuid, r->cur_subvol->received_uuid, BTRFS_UUID_SIZE);
|
memcpy(rs_args.uuid, r->cur_subvol.received_uuid, BTRFS_UUID_SIZE);
|
||||||
rs_args.stransid = r->cur_subvol->stransid;
|
rs_args.stransid = r->cur_subvol.stransid;
|
||||||
|
|
||||||
if (g_verbose >= 1) {
|
if (g_verbose >= 1) {
|
||||||
uuid_unparse((u8*)rs_args.uuid, uuid_str);
|
uuid_unparse((u8*)rs_args.uuid, uuid_str);
|
||||||
|
@ -116,7 +116,7 @@ static int finish_subvol(struct btrfs_receive *r)
|
||||||
strerror(-ret));
|
strerror(-ret));
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
r->cur_subvol->rtransid = rs_args.rtransid;
|
r->cur_subvol.rtransid = rs_args.rtransid;
|
||||||
|
|
||||||
ret = ioctl(subvol_fd, BTRFS_IOC_SUBVOL_GETFLAGS, &flags);
|
ret = ioctl(subvol_fd, BTRFS_IOC_SUBVOL_GETFLAGS, &flags);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
@ -139,10 +139,9 @@ static int finish_subvol(struct btrfs_receive *r)
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (r->cur_subvol) {
|
if (r->cur_subvol.path) {
|
||||||
free(r->cur_subvol->path);
|
free(r->cur_subvol.path);
|
||||||
free(r->cur_subvol);
|
r->cur_subvol.path = NULL;
|
||||||
r->cur_subvol = NULL;
|
|
||||||
}
|
}
|
||||||
if (subvol_fd != -1)
|
if (subvol_fd != -1)
|
||||||
close(subvol_fd);
|
close(subvol_fd);
|
||||||
|
@ -161,25 +160,25 @@ static int process_subvol(const char *path, const u8 *uuid, u64 ctransid,
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
r->cur_subvol = calloc(1, sizeof(*r->cur_subvol));
|
BUG_ON(r->cur_subvol.path);
|
||||||
|
|
||||||
if (strlen(r->dest_dir_path) == 0)
|
if (strlen(r->dest_dir_path) == 0)
|
||||||
r->cur_subvol->path = strdup(path);
|
r->cur_subvol.path = strdup(path);
|
||||||
else
|
else
|
||||||
r->cur_subvol->path = path_cat(r->dest_dir_path, path);
|
r->cur_subvol.path = path_cat(r->dest_dir_path, path);
|
||||||
free(r->full_subvol_path);
|
free(r->full_subvol_path);
|
||||||
r->full_subvol_path = path_cat3(r->root_path, r->dest_dir_path, path);
|
r->full_subvol_path = path_cat3(r->root_path, r->dest_dir_path, path);
|
||||||
|
|
||||||
fprintf(stderr, "At subvol %s\n", path);
|
fprintf(stderr, "At subvol %s\n", path);
|
||||||
|
|
||||||
memcpy(r->cur_subvol->received_uuid, uuid, BTRFS_UUID_SIZE);
|
memcpy(r->cur_subvol.received_uuid, uuid, BTRFS_UUID_SIZE);
|
||||||
r->cur_subvol->stransid = ctransid;
|
r->cur_subvol.stransid = ctransid;
|
||||||
|
|
||||||
if (g_verbose) {
|
if (g_verbose) {
|
||||||
uuid_unparse((u8*)r->cur_subvol->received_uuid, uuid_str);
|
uuid_unparse((u8*)r->cur_subvol.received_uuid, uuid_str);
|
||||||
fprintf(stderr, "receiving subvol %s uuid=%s, stransid=%llu\n",
|
fprintf(stderr, "receiving subvol %s uuid=%s, stransid=%llu\n",
|
||||||
path, uuid_str,
|
path, uuid_str,
|
||||||
r->cur_subvol->stransid);
|
r->cur_subvol.stransid);
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&args_v1, 0, sizeof(args_v1));
|
memset(&args_v1, 0, sizeof(args_v1));
|
||||||
|
@ -210,25 +209,25 @@ static int process_snapshot(const char *path, const u8 *uuid, u64 ctransid,
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
r->cur_subvol = calloc(1, sizeof(*r->cur_subvol));
|
BUG_ON(r->cur_subvol.path);
|
||||||
|
|
||||||
if (strlen(r->dest_dir_path) == 0)
|
if (strlen(r->dest_dir_path) == 0)
|
||||||
r->cur_subvol->path = strdup(path);
|
r->cur_subvol.path = strdup(path);
|
||||||
else
|
else
|
||||||
r->cur_subvol->path = path_cat(r->dest_dir_path, path);
|
r->cur_subvol.path = path_cat(r->dest_dir_path, path);
|
||||||
free(r->full_subvol_path);
|
free(r->full_subvol_path);
|
||||||
r->full_subvol_path = path_cat3(r->root_path, r->dest_dir_path, path);
|
r->full_subvol_path = path_cat3(r->root_path, r->dest_dir_path, path);
|
||||||
|
|
||||||
fprintf(stdout, "At snapshot %s\n", path);
|
fprintf(stdout, "At snapshot %s\n", path);
|
||||||
|
|
||||||
memcpy(r->cur_subvol->received_uuid, uuid, BTRFS_UUID_SIZE);
|
memcpy(r->cur_subvol.received_uuid, uuid, BTRFS_UUID_SIZE);
|
||||||
r->cur_subvol->stransid = ctransid;
|
r->cur_subvol.stransid = ctransid;
|
||||||
|
|
||||||
if (g_verbose) {
|
if (g_verbose) {
|
||||||
uuid_unparse((u8*)r->cur_subvol->received_uuid, uuid_str);
|
uuid_unparse((u8*)r->cur_subvol.received_uuid, uuid_str);
|
||||||
fprintf(stderr, "receiving snapshot %s uuid=%s, "
|
fprintf(stderr, "receiving snapshot %s uuid=%s, "
|
||||||
"ctransid=%llu ", path, uuid_str,
|
"ctransid=%llu ", path, uuid_str,
|
||||||
r->cur_subvol->stransid);
|
r->cur_subvol.stransid);
|
||||||
uuid_unparse(parent_uuid, uuid_str);
|
uuid_unparse(parent_uuid, uuid_str);
|
||||||
fprintf(stderr, "parent_uuid=%s, parent_ctransid=%llu\n",
|
fprintf(stderr, "parent_uuid=%s, parent_ctransid=%llu\n",
|
||||||
uuid_str, parent_ctransid);
|
uuid_str, parent_ctransid);
|
||||||
|
@ -633,10 +632,10 @@ static int process_clone(const char *path, u64 offset, u64 len,
|
||||||
si = subvol_uuid_search(&r->sus, 0, clone_uuid, clone_ctransid, NULL,
|
si = subvol_uuid_search(&r->sus, 0, clone_uuid, clone_ctransid, NULL,
|
||||||
subvol_search_by_received_uuid);
|
subvol_search_by_received_uuid);
|
||||||
if (!si) {
|
if (!si) {
|
||||||
if (memcmp(clone_uuid, r->cur_subvol->received_uuid,
|
if (memcmp(clone_uuid, r->cur_subvol.received_uuid,
|
||||||
BTRFS_UUID_SIZE) == 0) {
|
BTRFS_UUID_SIZE) == 0) {
|
||||||
/* TODO check generation of extent */
|
/* TODO check generation of extent */
|
||||||
subvol_path = strdup(r->cur_subvol->path);
|
subvol_path = strdup(r->cur_subvol.path);
|
||||||
} else {
|
} else {
|
||||||
ret = -ENOENT;
|
ret = -ENOENT;
|
||||||
fprintf(stderr, "ERROR: did not find source subvol.\n");
|
fprintf(stderr, "ERROR: did not find source subvol.\n");
|
||||||
|
@ -1074,10 +1073,9 @@ out:
|
||||||
r->full_subvol_path = NULL;
|
r->full_subvol_path = NULL;
|
||||||
r->dest_dir_path = NULL;
|
r->dest_dir_path = NULL;
|
||||||
free(dest_dir_full_path);
|
free(dest_dir_full_path);
|
||||||
if (r->cur_subvol) {
|
if (r->cur_subvol.path) {
|
||||||
free(r->cur_subvol->path);
|
free(r->cur_subvol.path);
|
||||||
free(r->cur_subvol);
|
r->cur_subvol.path = NULL;
|
||||||
r->cur_subvol = NULL;
|
|
||||||
}
|
}
|
||||||
subvol_uuid_search_finit(&r->sus);
|
subvol_uuid_search_finit(&r->sus);
|
||||||
if (r->mnt_fd != -1) {
|
if (r->mnt_fd != -1) {
|
||||||
|
|
Loading…
Reference in New Issue