When two or more -c options are specified, cannot find a suitable
parent. So, output stream is bigger than correct one.
[before]
# btrfs send -f /tmp/data1 -c Snap0 -c ../SnapX Snap[12] ../SnapY
At subvol Snap1
At subvol Snap2
At subvol ../SnapY
# ls -l /tmp/data1
-rw--- 1 root root 3153 Oct 19 10:37 /tmp/data1
#
[after]
# btrfs send -f /tmp/data1 -c Snap0 -c ../SnapX Snap[12] ../SnapY
At subvol Snap1
At subvol Snap2
At subvol ../SnapY
# ls -l /tmp/data1
-rw--- 1 root root 1492 Oct 19 10:39 /tmp/data1
#
Signed-off-by: Tsutomu Itoh
---
v2: make helper functions
---
cmds-send.c | 58 ++
1 file changed, 38 insertions(+), 20 deletions(-)
diff --git a/cmds-send.c b/cmds-send.c
index 2a8a697..f831e99 100644
--- a/cmds-send.c
+++ b/cmds-send.c
@@ -411,6 +411,36 @@ out:
return ret;
}
+static int set_root_info(struct btrfs_send *s, char *subvol, u64 *root_id)
+{
+ int ret;
+
+ ret = init_root_path(s, subvol);
+ if (ret < 0)
+ goto out;
+
+ ret = get_root_id(s, subvol_strip_mountpoint(s->root_path, subvol),
+ root_id);
+ if (ret < 0) {
+ error("cannot resolve rootid for %s", subvol);
+ goto out;
+ }
+
+out:
+ return ret;
+}
+
+static void free_send_info(struct btrfs_send *s)
+{
+ if (s->mnt_fd >= 0) {
+ close(s->mnt_fd);
+ s->mnt_fd = -1;
+ }
+ free(s->root_path);
+ s->root_path = NULL;
+ subvol_uuid_search_finit(>sus);
+}
+
int cmd_send(int argc, char **argv)
{
char *subvol = NULL;
@@ -460,18 +490,10 @@ int cmd_send(int argc, char **argv)
goto out;
}
- ret = init_root_path(, subvol);
+ ret = set_root_info(, subvol, _id);
if (ret < 0)
goto out;
- ret = get_root_id(,
- subvol_strip_mountpoint(send.root_path, subvol),
- _id);
- if (ret < 0) {
- error("cannot resolve rootid for %s", subvol);
- goto out;
- }
-
ret = is_subvol_ro(, subvol);
if (ret < 0)
goto out;
@@ -486,15 +508,9 @@ int cmd_send(int argc, char **argv)
error("cannot add clone source: %s",
strerror(-ret));
goto out;
}
- subvol_uuid_search_finit();
free(subvol);
subvol = NULL;
- if (send.mnt_fd >= 0) {
- close(send.mnt_fd);
- send.mnt_fd = -1;
- }
- free(send.root_path);
- send.root_path = NULL;
+ free_send_info();
full_send = 0;
break;
case 'f':
@@ -651,6 +667,10 @@ int cmd_send(int argc, char **argv)
}
if (!full_send && root_id) {
+ ret = set_root_info(, subvol, _id);
+ if (ret < 0)
+ goto out;
+
ret = find_good_parent(, root_id, _root_id);
if (ret < 0) {
error("parent determination failed for %lld",
@@ -680,6 +700,7 @@ int cmd_send(int argc, char **argv)
error("cannot add clone source: %s",
strerror(-ret));
goto out;
}
+ free_send_info();
}
}
@@ -689,10 +710,7 @@ out:
free(subvol);
free(snapshot_parent);
free(send.clone_sources);
- if (send.mnt_fd >= 0)
- close(send.mnt_fd);
- free(send.root_path);
- subvol_uuid_search_finit();
+ free_send_info();
return !!ret;
}
--
2.9.3
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html