From: Jeff Liu <jeff.liu@oracle.com>
To: "linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>
Subject: [RFC PATCH 5/5] btrfs-progs: let this feature works at subvolume command group.
Date: Tue, 07 Aug 2012 16:58:01 +0800 [thread overview]
Message-ID: <5020D899.4070301@oracle.com> (raw)
In-Reply-To: <5020D84E.4010900@oracle.com>
make this feature works as `btrfs subvolume diff-snapshot [options] <src> <dest>`.
Signed-off-by: Jie Liu <jeff.liu@oracle.com>
---
cmds-subvolume.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 90 insertions(+), 0 deletions(-)
diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index 3508ce6..e7cc3cc 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -28,6 +28,7 @@
#include "ioctl.h"
#include "commands.h"
+#include "diff-snapshot.h"
/* btrfs-list.c */
int list_subvols(int fd, int print_parent, int get_default);
@@ -515,6 +516,94 @@ static int cmd_find_new(int argc, char **argv)
return 0;
}
+static const char * const cmd_snapshot_diff_usage[] = {
+ "btrfs subvolume diff-snapshot [options] <source> <dest>",
+ "List the differences between two snapshots",
+ "By default, list all changes in destination snapshot towards source",
+ "",
+ "-n list the new items in destination snapshot\n",
+ "-r list the removed items in destination snapshot\n",
+ "-u list the updated items in destination snapshot\n",
+ NULL
+};
+
+static int cmd_snapshot_diff(int argc, char **argv)
+{
+ int ret;
+ int src_fd;
+ int dst_fd;
+ char *src_snapshot;
+ char *dest_snapshot;
+ unsigned int flags = 0;
+
+ while (1) {
+ int c = getopt(argc, argv, "rnu");
+ if (c < 0)
+ break;
+ switch (c) {
+ case 'r':
+ flags |= SNAPSHOT_DIFF_LIST_REMOVED_ITEM;
+ break;
+ case 'n':
+ flags |= SNAPSHOT_DIFF_LIST_NEW_ITEM;
+ break;
+ case 'u':
+ flags |= SNAPSHOT_DIFF_LIST_UPDATED_ITEM;
+ break;
+ default:
+ fprintf(stderr, "ERROR: snapshot diff args invalid.\n"
+ " -r list removed items\n"
+ " -n list new items\n"
+ " -u list updated items\n");
+ return 1;
+ }
+ }
+
+ src_snapshot = argv[argc - 2];
+ dest_snapshot = argv[argc - 1];
+
+ ret = test_issubvolume(src_snapshot);
+ if (ret < 0) {
+ fprintf(stderr, "ERROR: error accessing '%s'\n",
+ src_snapshot);
+ return 12;
+ }
+ if (!ret) {
+ fprintf(stderr, "ERROR: '%s' is not a subvolume\n",
+ src_snapshot);
+ return 13;
+ }
+
+ ret = test_issubvolume(dest_snapshot);
+ if (ret < 0) {
+ fprintf(stderr, "ERROR: error accessing '%s'\n",
+ dest_snapshot);
+ return 12;
+ }
+ if (!ret) {
+ fprintf(stderr, "ERROR: '%s' is not a subvolume\n",
+ dest_snapshot);
+ return 13;
+ }
+
+ src_fd = open_file_or_dir(src_snapshot);
+ if (src_fd < 0) {
+ fprintf(stderr, "ERROR: can't access '%s'\n", src_snapshot);
+ return 12;
+ }
+
+ dst_fd = open_file_or_dir(dest_snapshot);
+ if (dst_fd < 0) {
+ fprintf(stderr, "ERROR: can't access '%s'\n", dest_snapshot);
+ return 12;
+ }
+
+ ret = snapshot_diff(src_fd, dst_fd, src_snapshot, dest_snapshot, flags);
+ if (ret)
+ return 19;
+ return 0;
+}
+
const struct cmd_group subvolume_cmd_group = {
subvolume_cmd_group_usage, NULL, {
{ "create", cmd_subvol_create, cmd_subvol_create_usage, NULL, 0 },
@@ -526,6 +615,7 @@ const struct cmd_group subvolume_cmd_group = {
{ "set-default", cmd_subvol_set_default,
cmd_subvol_set_default_usage, NULL, 0 },
{ "find-new", cmd_find_new, cmd_find_new_usage, NULL, 0 },
+ { "diff-snapshot", cmd_snapshot_diff, cmd_snapshot_diff_usage, NULL, 0 },
{ 0, 0, 0, 0, 0 }
}
};
--
1.7.4.1
next prev parent reply other threads:[~2012-08-07 8:58 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-07 8:56 [RFC PATCH 0/5] btrfs-progs: snapshot diff function Jeff Liu
2012-08-07 8:57 ` [RFC PATCH 1/5] btrfs-progs: make ino_resovle() shared Jeff Liu
2012-08-07 8:57 ` [RFC PATCH 2/5] btrfs-progs: header file of snapshot diff Jeff Liu
2012-08-07 8:57 ` [RFC PATCH 3/5] btrfs-progs: souce " Jeff Liu
2012-08-07 8:57 ` [RFC PATCH 4/5] btrfs-progs: teach Makefile aware of the new comer Jeff Liu
2012-08-07 8:58 ` Jeff Liu [this message]
2012-08-24 13:09 ` [RFC PATCH 0/5] btrfs-progs: snapshot diff function Alex Lyakas
2012-08-24 14:15 ` Jeff Liu
2012-08-25 6:23 ` Alexander Block
2012-08-26 12:26 ` Jie Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5020D899.4070301@oracle.com \
--to=jeff.liu@oracle.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.