btrfs-progs: send: add option to for the no-data mode

Signed-off-by: David Sterba <dsterba@suse.cz>
This commit is contained in:
David Sterba 2015-06-12 13:15:41 +02:00
parent 14de97259b
commit c55415e4cb
2 changed files with 30 additions and 5 deletions

View File

@ -40,6 +40,10 @@ Use this snapshot as a clone source for an incremental send (multiple allowed).
-f <outfile>:: -f <outfile>::
Output is normally written to stdout. To write to a file, use this option. Output is normally written to stdout. To write to a file, use this option.
An alternative would be to use pipes. An alternative would be to use pipes.
--no-data::
Send in NO_FILE_DATA mode. The output stream does not contain any file
data and thus cannot be used to transfer changes. This mode is faster and
useful to show the differences in metadata.
EXIT STATUS EXIT STATUS
----------- -----------

View File

@ -31,7 +31,7 @@
#include <libgen.h> #include <libgen.h>
#include <mntent.h> #include <mntent.h>
#include <assert.h> #include <assert.h>
#include <getopt.h>
#include <uuid/uuid.h> #include <uuid/uuid.h>
#include "ctree.h" #include "ctree.h"
@ -243,7 +243,8 @@ out:
} }
static int do_send(struct btrfs_send *send, u64 parent_root_id, static int do_send(struct btrfs_send *send, u64 parent_root_id,
int is_first_subvol, int is_last_subvol, char *subvol) int is_first_subvol, int is_last_subvol, char *subvol,
u64 flags)
{ {
int ret; int ret;
pthread_t t_read; pthread_t t_read;
@ -281,6 +282,7 @@ static int do_send(struct btrfs_send *send, u64 parent_root_id,
goto out; goto out;
} }
io_send.flags = flags;
io_send.clone_sources = (__u64*)send->clone_sources; io_send.clone_sources = (__u64*)send->clone_sources;
io_send.clone_sources_count = send->clone_sources_count; io_send.clone_sources_count = send->clone_sources_count;
io_send.parent_root = parent_root_id; io_send.parent_root = parent_root_id;
@ -424,7 +426,6 @@ out:
int cmd_send(int argc, char **argv) int cmd_send(int argc, char **argv)
{ {
char *subvol = NULL; char *subvol = NULL;
int c;
int ret; int ret;
char *outname = NULL; char *outname = NULL;
struct btrfs_send send; struct btrfs_send send;
@ -435,11 +436,21 @@ int cmd_send(int argc, char **argv)
u64 parent_root_id = 0; u64 parent_root_id = 0;
int full_send = 1; int full_send = 1;
int new_end_cmd_semantic = 0; int new_end_cmd_semantic = 0;
u64 send_flags = 0;
memset(&send, 0, sizeof(send)); memset(&send, 0, sizeof(send));
send.dump_fd = fileno(stdout); send.dump_fd = fileno(stdout);
while ((c = getopt(argc, argv, "vec:f:i:p:")) != -1) { while (1) {
enum { GETOPT_VAL_SEND_NO_DATA = 256 };
static const struct option long_options[] = {
{ "no-data", no_argument, NULL, GETOPT_VAL_SEND_NO_DATA }
};
int c = getopt_long(argc, argv, "vec:f:i:p:", long_options, NULL);
if (c < 0)
break;
switch (c) { switch (c) {
case 'v': case 'v':
g_verbose++; g_verbose++;
@ -530,6 +541,9 @@ int cmd_send(int argc, char **argv)
"ERROR: -i was removed, use -c instead\n"); "ERROR: -i was removed, use -c instead\n");
ret = 1; ret = 1;
goto out; goto out;
case GETOPT_VAL_SEND_NO_DATA:
send_flags |= BTRFS_SEND_FLAG_NO_FILE_DATA;
break;
case '?': case '?':
default: default:
fprintf(stderr, "ERROR: send args invalid.\n"); fprintf(stderr, "ERROR: send args invalid.\n");
@ -632,6 +646,9 @@ int cmd_send(int argc, char **argv)
} }
} }
if (send_flags & BTRFS_SEND_FLAG_NO_FILE_DATA)
printf("Mode NO_FILE_DATA enabled\n");
for (i = optind; i < argc; i++) { for (i = optind; i < argc; i++) {
int is_first_subvol; int is_first_subvol;
int is_last_subvol; int is_last_subvol;
@ -678,7 +695,7 @@ int cmd_send(int argc, char **argv)
is_last_subvol = 1; is_last_subvol = 1;
} }
ret = do_send(&send, parent_root_id, is_first_subvol, ret = do_send(&send, parent_root_id, is_first_subvol,
is_last_subvol, subvol); is_last_subvol, subvol, send_flags);
if (ret < 0) if (ret < 0)
goto out; goto out;
@ -731,5 +748,9 @@ const char * const cmd_send_usage[] = {
"-f <outfile> Output is normally written to stdout. To write to", "-f <outfile> Output is normally written to stdout. To write to",
" a file, use this option. An alternative would be to", " a file, use this option. An alternative would be to",
" use pipes.", " use pipes.",
"--no-data send in NO_FILE_DATA mode, Note: the output stream",
" does not contain any file data and thus cannot be used",
" to transfer changes. This mode is faster and useful to",
" show the differences in metadata.",
NULL NULL
}; };