[PATCH 1/3] btrfs-progs: Introduce new send-dump object

2016-09-06 Thread Qu Wenruo
Introduce send-dump.[ch] which implements a new btrfs_send_ops to
exam and output all operations inside a send stream.

It has a better output format than the old and no longer compilable
send-test tool, but still tries to be script friendly.

Provides the basis for later "inspect-internal dump-send" command.

Signed-off-by: Qu Wenruo 
---
 Makefile.in |   2 +-
 send-dump.c | 367 
 send-dump.h |  24 
 3 files changed, 392 insertions(+), 1 deletion(-)
 create mode 100644 send-dump.c
 create mode 100644 send-dump.h

diff --git a/Makefile.in b/Makefile.in
index ac6b353..97caf95 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -80,7 +80,7 @@ objects = ctree.o disk-io.o radix-tree.o extent-tree.o 
print-tree.o \
  extent-cache.o extent_io.o volumes.o utils.o repair.o \
  qgroup.o raid6.o free-space-cache.o list_sort.o props.o \
  ulist.o qgroup-verify.o backref.o string-table.o task-utils.o \
- inode.o file.o find-root.o free-space-tree.o help.o
+ inode.o file.o find-root.o free-space-tree.o help.o send-dump.o
 cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \
   cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \
   cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o \
diff --git a/send-dump.c b/send-dump.c
new file mode 100644
index 000..bf451c7
--- /dev/null
+++ b/send-dump.c
@@ -0,0 +1,367 @@
+/*
+ * Copyright (C) 2016 Fujitsu.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License v2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "utils.h"
+#include "commands.h"
+#include "send-utils.h"
+#include "send-stream.h"
+#include "send-dump.h"
+
+#define path_cat_out_with_error(function_name, out_path, path1, path2, ret) \
+ret = path_cat_out(out_path, path1, path2);\
+if (ret < 0) { \
+   error("%s: path invalid: %s\n", function_name, path2);  \
+   return ret; \
+}
+
+#define TITLE_WIDTH16
+#define PATH_WIDTH 32
+
+static void print_dump(const char *title, const char *path,
+  const char *fmt, ...)
+{
+   va_list args;
+   char real_title[TITLE_WIDTH + 1];
+
+   real_title[0]='\0';
+   /* Append ':' to title*/
+   strncpy(real_title, title, TITLE_WIDTH - 1);
+   strncat(real_title, ":", TITLE_WIDTH);
+
+   /* Unified output */
+   printf("%-*s%-*s", TITLE_WIDTH, real_title, PATH_WIDTH, path);
+   va_start(args, fmt);
+   /* Command specified output */
+   vprintf(fmt, args);
+   va_end(args);
+   printf("\n");
+}
+
+static int print_subvol(const char *path, const u8 *uuid, u64 ctransid,
+   void *user)
+{
+   struct btrfs_dump_send_args *r = user;
+   char uuid_str[BTRFS_UUID_UNPARSED_SIZE];
+   int ret;
+
+   path_cat_out_with_error("subvol", r->full_subvol_path, r->root_path,
+   path, ret);
+   uuid_unparse(uuid, uuid_str);
+
+   print_dump("subvol", r->full_subvol_path, "uuid: %s, transid: %llu",
+  uuid_str, ctransid);
+   return 0;
+}
+
+static int print_snapshot(const char *path, const u8 *uuid, u64 ctransid,
+ const u8 *parent_uuid, u64 parent_ctransid,
+ void *user)
+{
+   struct btrfs_dump_send_args *r = user;
+   char uuid_str[BTRFS_UUID_UNPARSED_SIZE];
+   char parent_uuid_str[BTRFS_UUID_UNPARSED_SIZE];
+   int ret;
+
+   path_cat_out_with_error("snapshot", r->full_subvol_path, r->root_path,
+   path, ret);
+   uuid_unparse(uuid, uuid_str);
+   uuid_unparse(parent_uuid, parent_uuid_str);
+
+   print_dump("snapshot", r->full_subvol_path,
+  "uuid: %s, transid: %llu, parent_uuid: %s, parent_transid: 
%llu",
+  uuid_str, ctransid, parent_uuid_str, parent_ctransid);
+   return 0;
+}
+
+static int print_mkfile(const char *path, void *user)
+{
+   struct btrfs_dump_send_args *r = user;
+   char full_path[PATH_MAX];
+   int ret;
+
+   path_cat_out_with_error("mkfile", full_path, r->full_subvol_path, path,
+   ret);
+   print_dump("mkfile

Re: [PATCH 1/3] btrfs-progs: Introduce new send-dump object

2016-09-05 Thread Qu Wenruo



At 08/24/2016 08:49 PM, David Sterba wrote:

On Wed, Aug 17, 2016 at 08:42:48AM +0800, Qu Wenruo wrote:



At 08/16/2016 10:31 PM, David Sterba wrote:

On Mon, Aug 01, 2016 at 02:29:42PM +0800, Qu Wenruo wrote:

Introduce send-dump.[ch] which implements a new btrfs_send_ops to
exam and output all operations inside a send stream.

It has a better output format than the old and no longer compilable
send-test tool, but still tries to be script friendly.

Provides the basis for later "inspect-internal dump-send" command.


I'd rather put that into the receive subcommand, as it takes the stream
as argument and it's closer to the send/receive commands, but that's
a minor thing.



I'm OK to put it into receive command.

Although unlike normal receive usage, it doesn't need the 
parameter, and make  to be optional.


That's a good point and would make the syntax work in two modes, but we
do that in ohter commands and I hope it will not be confusing. Exmaples:

Normal receive:

 btrfs receive -f file /mount

Dump the stream:

 btrs receive --dump -f file


Sorry for the late reply.

I'm OK for the new syntax.

If no other problem I'll begin to change the syntax and rebase it to devel.

Thanks,
Qu


--
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


Re: [PATCH 1/3] btrfs-progs: Introduce new send-dump object

2016-08-24 Thread David Sterba
On Wed, Aug 17, 2016 at 08:42:48AM +0800, Qu Wenruo wrote:
> 
> 
> At 08/16/2016 10:31 PM, David Sterba wrote:
> > On Mon, Aug 01, 2016 at 02:29:42PM +0800, Qu Wenruo wrote:
> >> Introduce send-dump.[ch] which implements a new btrfs_send_ops to
> >> exam and output all operations inside a send stream.
> >>
> >> It has a better output format than the old and no longer compilable
> >> send-test tool, but still tries to be script friendly.
> >>
> >> Provides the basis for later "inspect-internal dump-send" command.
> >
> > I'd rather put that into the receive subcommand, as it takes the stream
> > as argument and it's closer to the send/receive commands, but that's
> > a minor thing.
> >
> >
> I'm OK to put it into receive command.
> 
> Although unlike normal receive usage, it doesn't need the  
> parameter, and make  to be optional.

That's a good point and would make the syntax work in two modes, but we
do that in ohter commands and I hope it will not be confusing. Exmaples:

Normal receive:

 btrfs receive -f file /mount

Dump the stream:

 btrs receive --dump -f file
--
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


Re: [PATCH 1/3] btrfs-progs: Introduce new send-dump object

2016-08-17 Thread David Sterba
On Wed, Aug 17, 2016 at 08:42:48AM +0800, Qu Wenruo wrote:
> 
> 
> At 08/16/2016 10:31 PM, David Sterba wrote:
> > On Mon, Aug 01, 2016 at 02:29:42PM +0800, Qu Wenruo wrote:
> >> Introduce send-dump.[ch] which implements a new btrfs_send_ops to
> >> exam and output all operations inside a send stream.
> >>
> >> It has a better output format than the old and no longer compilable
> >> send-test tool, but still tries to be script friendly.
> >>
> >> Provides the basis for later "inspect-internal dump-send" command.
> >
> > I'd rather put that into the receive subcommand, as it takes the stream
> > as argument and it's closer to the send/receive commands, but that's
> > a minor thing.
> >
> >
> I'm OK to put it into receive command.
> 
> Although unlike normal receive usage, it doesn't need the  
> parameter, and make  to be optional.
> 
> If it's fine to you, then I can update the patchset to merge it into 
> receive subcommand.

Hold on, I want to go through the whole patchset still.
--
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


Re: [PATCH 1/3] btrfs-progs: Introduce new send-dump object

2016-08-16 Thread Qu Wenruo



At 08/16/2016 10:31 PM, David Sterba wrote:

On Mon, Aug 01, 2016 at 02:29:42PM +0800, Qu Wenruo wrote:

Introduce send-dump.[ch] which implements a new btrfs_send_ops to
exam and output all operations inside a send stream.

It has a better output format than the old and no longer compilable
send-test tool, but still tries to be script friendly.

Provides the basis for later "inspect-internal dump-send" command.


I'd rather put that into the receive subcommand, as it takes the stream
as argument and it's closer to the send/receive commands, but that's
a minor thing.



I'm OK to put it into receive command.

Although unlike normal receive usage, it doesn't need the  
parameter, and make  to be optional.


If it's fine to you, then I can update the patchset to merge it into 
receive subcommand.


Thanks,
Qu


--
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


Re: [PATCH 1/3] btrfs-progs: Introduce new send-dump object

2016-08-16 Thread David Sterba
On Mon, Aug 01, 2016 at 02:29:42PM +0800, Qu Wenruo wrote:
> Introduce send-dump.[ch] which implements a new btrfs_send_ops to
> exam and output all operations inside a send stream.
> 
> It has a better output format than the old and no longer compilable
> send-test tool, but still tries to be script friendly.
> 
> Provides the basis for later "inspect-internal dump-send" command.

I'd rather put that into the receive subcommand, as it takes the stream
as argument and it's closer to the send/receive commands, but that's
a minor thing.
--
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


[PATCH 1/3] btrfs-progs: Introduce new send-dump object

2016-07-31 Thread Qu Wenruo
Introduce send-dump.[ch] which implements a new btrfs_send_ops to
exam and output all operations inside a send stream.

It has a better output format than the old and no longer compilable
send-test tool, but still tries to be script friendly.

Provides the basis for later "inspect-internal dump-send" command.

Signed-off-by: Qu Wenruo 
---
 Makefile.in |   2 +-
 send-dump.c | 367 
 send-dump.h |  24 
 3 files changed, 392 insertions(+), 1 deletion(-)
 create mode 100644 send-dump.c
 create mode 100644 send-dump.h

diff --git a/Makefile.in b/Makefile.in
index ac6b353..97caf95 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -80,7 +80,7 @@ objects = ctree.o disk-io.o radix-tree.o extent-tree.o 
print-tree.o \
  extent-cache.o extent_io.o volumes.o utils.o repair.o \
  qgroup.o raid6.o free-space-cache.o list_sort.o props.o \
  ulist.o qgroup-verify.o backref.o string-table.o task-utils.o \
- inode.o file.o find-root.o free-space-tree.o help.o
+ inode.o file.o find-root.o free-space-tree.o help.o send-dump.o
 cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \
   cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \
   cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o \
diff --git a/send-dump.c b/send-dump.c
new file mode 100644
index 000..bf451c7
--- /dev/null
+++ b/send-dump.c
@@ -0,0 +1,367 @@
+/*
+ * Copyright (C) 2016 Fujitsu.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License v2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "utils.h"
+#include "commands.h"
+#include "send-utils.h"
+#include "send-stream.h"
+#include "send-dump.h"
+
+#define path_cat_out_with_error(function_name, out_path, path1, path2, ret) \
+ret = path_cat_out(out_path, path1, path2);\
+if (ret < 0) { \
+   error("%s: path invalid: %s\n", function_name, path2);  \
+   return ret; \
+}
+
+#define TITLE_WIDTH16
+#define PATH_WIDTH 32
+
+static void print_dump(const char *title, const char *path,
+  const char *fmt, ...)
+{
+   va_list args;
+   char real_title[TITLE_WIDTH + 1];
+
+   real_title[0]='\0';
+   /* Append ':' to title*/
+   strncpy(real_title, title, TITLE_WIDTH - 1);
+   strncat(real_title, ":", TITLE_WIDTH);
+
+   /* Unified output */
+   printf("%-*s%-*s", TITLE_WIDTH, real_title, PATH_WIDTH, path);
+   va_start(args, fmt);
+   /* Command specified output */
+   vprintf(fmt, args);
+   va_end(args);
+   printf("\n");
+}
+
+static int print_subvol(const char *path, const u8 *uuid, u64 ctransid,
+   void *user)
+{
+   struct btrfs_dump_send_args *r = user;
+   char uuid_str[BTRFS_UUID_UNPARSED_SIZE];
+   int ret;
+
+   path_cat_out_with_error("subvol", r->full_subvol_path, r->root_path,
+   path, ret);
+   uuid_unparse(uuid, uuid_str);
+
+   print_dump("subvol", r->full_subvol_path, "uuid: %s, transid: %llu",
+  uuid_str, ctransid);
+   return 0;
+}
+
+static int print_snapshot(const char *path, const u8 *uuid, u64 ctransid,
+ const u8 *parent_uuid, u64 parent_ctransid,
+ void *user)
+{
+   struct btrfs_dump_send_args *r = user;
+   char uuid_str[BTRFS_UUID_UNPARSED_SIZE];
+   char parent_uuid_str[BTRFS_UUID_UNPARSED_SIZE];
+   int ret;
+
+   path_cat_out_with_error("snapshot", r->full_subvol_path, r->root_path,
+   path, ret);
+   uuid_unparse(uuid, uuid_str);
+   uuid_unparse(parent_uuid, parent_uuid_str);
+
+   print_dump("snapshot", r->full_subvol_path,
+  "uuid: %s, transid: %llu, parent_uuid: %s, parent_transid: 
%llu",
+  uuid_str, ctransid, parent_uuid_str, parent_ctransid);
+   return 0;
+}
+
+static int print_mkfile(const char *path, void *user)
+{
+   struct btrfs_dump_send_args *r = user;
+   char full_path[PATH_MAX];
+   int ret;
+
+   path_cat_out_with_error("mkfile", full_path, r->full_subvol_path, path,
+   ret);
+   print_dump("mkfile