return ret;
}
+static int set_root_info(struct btrfs_send *sctx, const char *subvol,
+ u64 *root_id)
+{
+ int ret;
+
+ ret = init_root_path(sctx, subvol);
+ if (ret < 0)
+ goto out;
+
+ ret = get_root_id(sctx, subvol_strip_mountpoint(sctx->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 *sctx)
+{
+ if (sctx->mnt_fd >= 0) {
+ close(sctx->mnt_fd);
+ sctx->mnt_fd = -1;
+ }
+ free(sctx->root_path);
+ sctx->root_path = NULL;
+ subvol_uuid_search_finit(&sctx->sus);
+}
+
int cmd_send(int argc, char **argv)
{
char *subvol = NULL;
goto out;
}
- ret = init_root_path(&send, subvol);
+ ret = set_root_info(&send, subvol, &root_id);
if (ret < 0)
goto out;
- ret = get_root_id(&send,
- subvol_strip_mountpoint(send.root_path, subvol),
- &root_id);
- if (ret < 0) {
- error("cannot resolve rootid for %s", subvol);
- goto out;
- }
-
ret = is_subvol_ro(&send, subvol);
if (ret < 0)
goto out;
error("cannot add clone source: %s", strerror(-ret));
goto out;
}
- subvol_uuid_search_finit(&send.sus);
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(&send);
full_send = 0;
break;
case 'f':
}
if (!full_send && root_id) {
+ ret = set_root_info(&send, subvol, &root_id);
+ if (ret < 0)
+ goto out;
+
ret = find_good_parent(&send, root_id, &parent_root_id);
if (ret < 0) {
error("parent determination failed for %lld",
error("cannot add clone source: %s", strerror(-ret));
goto out;
}
+ free_send_info(&send);
}
}
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(&send.sus);
+ free_send_info(&send);
return !!ret;
}