linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: Patch to provide "btrfs subvolume last-gen".
@ 2010-11-03 11:04 Sean Reifschneider
  0 siblings, 0 replies; 2+ messages in thread
From: Sean Reifschneider @ 2010-11-03 11:04 UTC (permalink / raw)
  To: linux-btrfs


[-- Attachment #1.1: Type: text/plain, Size: 523 bytes --]

Thanks for the feedback Goffredo.  I've given it some thought and in the
spirit of "small programs cooperating", it seems like just having it write
out the generation id without the surrounding text makes sense.  The text
I pulled from the find-new sub-command, where it makes sense (to
differentiate it from the other changes).

The patch here makes that change and also adds the man page entries for
last-gen and find-new (since last-gen refers to it, but there isn't any
documentation for it).

Thanks,
Sean

[-- Attachment #1.2: 0002-Updating-man-page-and-removing-transid-text.patch --]
[-- Type: text/plain, Size: 2319 bytes --]

From 17459dcc8cc9d54963cbfd844006340315b73e86 Mon Sep 17 00:00:00 2001
From: Sean Reifschneider <jafo@tummy.com>
Date: Wed, 3 Nov 2010 04:59:20 -0600
Subject: [PATCH 2/2] Updating man page and removing transid text.

---
 btrfs_cmds.c   |    2 +-
 man/btrfs.8.in |   19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/btrfs_cmds.c b/btrfs_cmds.c
index 25eafb8..9439457 100644
--- a/btrfs_cmds.c
+++ b/btrfs_cmds.c
@@ -272,7 +272,7 @@ int do_get_latest_gen(int argc, char **argv)
 		return 12;
 	}
 	max_found = find_root_gen(fd);
-	printf("transid marker was %llu\n", (unsigned long long)max_found);
+	printf("%llu\n", (unsigned long long)max_found);
 	return 0;
 }
 
diff --git a/man/btrfs.8.in b/man/btrfs.8.in
index 26ef982..23ba7d2 100644
--- a/man/btrfs.8.in
+++ b/man/btrfs.8.in
@@ -15,6 +15,10 @@ btrfs \- control a btrfs filesystem
 .PP
 \fBbtrfs\fP \fBsubvolume set-default\fP\fI <id> <path>\fP
 .PP
+\fBbtrfs\fP \fBsubvolume last-gen\fP\fI <path>\fP
+.PP
+\fBbtrfs\fP \fBsubvolume find-new\fP\fI <path> <last_gen>\fP
+.PP
 \fBbtrfs\fP \fBfilesystem defrag\fP\fI <file>|<dir> [<file>|<dir>...]\fP
 .PP
 \fBbtrfs\fP \fBfilesystem sync\fP\fI <path> \fP
@@ -96,6 +100,21 @@ These <ID> may be used by the \fBsubvolume set-default\fR command, or at
 mount time via the \fIsubvol=\fR option.
 .TP
 
+\fBsubvolume last-gen\fR\fI <path>\fR
+Return the most current generation id of \fI<path>\fR.  This number is
+suitable for use with the \fBsubvolume find-new\fR command, for example.
+A single number is sent to stdout, representing the most recent generation
+within a subvolume/snapshot.
+
+\fBsubvolume find-new\fR\fI <path> <last_gen>\fR
+Display changes to the subvolume \fI<path>\fR since the generation id
+\fI<last_gen>\fR.  The resulting information includes filenames, offset
+within the file, length, and more.  The last line output displays the most
+recent generation id represented by the output.  For example, one could
+feed this id back in to get an ongoing report of changes to the
+subvolume.
+.TP
+
 \fBsubvolume set-default\fR\fI <id> <path>\fR
 Set the subvolume of the filesystem \fI<path>\fR which is mounted as 
 \fIdefault\fR. The subvolume is identified by \fB<id>\fR, which 
-- 
1.7.3.1


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 253 bytes --]

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Patch to provide "btrfs subvolume last-gen".
@ 2010-11-03  9:23 Sean Reifschneider
  0 siblings, 0 replies; 2+ messages in thread
From: Sean Reifschneider @ 2010-11-03  9:23 UTC (permalink / raw)
  To: linux-btrfs


[-- Attachment #1.1: Type: text/plain, Size: 1269 bytes --]

Here is a patch to btrfs-progs to provide the command "subvolume last-gen":

   $ sudo ./btrfs subvolume last-gen /.snaps/1h-20101102-010001
   transid marker was 2808
   $ sudo ./btrfs subvolume last-gen /.snaps/1h-20101102-020001/
   transid marker was 2942
   $

So we can do something like:

   $ sudo ./btrfs subvolume find-new /.snaps/1h-20101102-020001 2808 | head -5
   inode 100399 file offset 2093056 len 4096 disk start 58160975872 offset 0
gen 2901 flags NONE var/log/messages
   inode 100399 file offset 2097152 len 4096 disk start 58161836032 offset 0
gen 2934 flags NONE var/log/messages
   inode 100400 file offset 40960 len 4096 disk start 58162188288 offset 0 gen
2941 flags NONE var/log/secure
   inode 100401 file offset 139264 len 4096 disk start 58155618304 offset 0
gen 2883 flags NONE var/log/maillog
   inode 100401 file offset 143360 len 8192 disk start 58154278912 offset 0
gen 2930 flags NONE var/log/maillog
   $

Otherwise, the only way I could figure out to do it was to pass a gen id
that was hopefully too big to get the transid line:

   $ sudo ./btrfs subvolume find-new /.snapshots/1h-20101102-010001 \
         999999999999999
   transid marker was 2808
   $

Unless I'm missing something...

Sean

[-- Attachment #1.2: 0001-Adding-last-gen-comand.patch --]
[-- Type: text/plain, Size: 3033 bytes --]

From 0a831df42f5b64db5c2f6a80531d2c4572ba5fc4 Mon Sep 17 00:00:00 2001
From: Sean Reifschneider <jafo@tummy.com>
Date: Wed, 3 Nov 2010 03:03:56 -0600
Subject: [PATCH] Adding last-gen comand.

---
 btrfs-list.c |    2 +-
 btrfs.c      |    3 +++
 btrfs_cmds.c |   29 +++++++++++++++++++++++++++++
 btrfs_cmds.h |    2 ++
 4 files changed, 35 insertions(+), 1 deletions(-)

diff --git a/btrfs-list.c b/btrfs-list.c
index 93766a8..7e4a282 100644
--- a/btrfs-list.c
+++ b/btrfs-list.c
@@ -310,7 +310,7 @@ static int lookup_ino_path(int fd, struct root_info *ri)
  * Then we use the tree search ioctl to scan all the root items for a
  * given root id and spit out the latest generation we can find
  */
-static u64 find_root_gen(int fd)
+u64 find_root_gen(int fd)
 {
 	struct btrfs_ioctl_ino_lookup_args ino_args;
 	int ret;
diff --git a/btrfs.c b/btrfs.c
index 46314cf..188b451 100644
--- a/btrfs.c
+++ b/btrfs.c
@@ -64,6 +64,9 @@ static struct Command commands[] = {
 	{ do_find_newer, 2, "subvolume find-new", "<path> <last_gen>\n"
 		"List the recently modified files in a filesystem."
 	},
+	{ do_get_latest_gen, 1, "subvolume last-gen", "<path>\n"
+		"Return the latest generation of a filesystem."
+	},
 	{ do_defrag, -1,
 	  "filesystem defragment", "[-vcf] [-s start] [-l len] [-t size] <file>|<dir> [<file>|<dir>...]\n"
 		"Defragment a file or a directory."
diff --git a/btrfs_cmds.c b/btrfs_cmds.c
index 8031c58..25eafb8 100644
--- a/btrfs_cmds.c
+++ b/btrfs_cmds.c
@@ -247,6 +247,35 @@ int do_defrag(int ac, char **av)
 	return errors + 20;
 }
 
+int do_get_latest_gen(int argc, char **argv)
+{
+	int fd;
+	int ret;
+	char *subvol;
+	u64 max_found = 0;
+
+	subvol = argv[1];
+
+	ret = test_issubvolume(subvol);
+	if (ret < 0) {
+		fprintf(stderr, "ERROR: error accessing '%s'\n", subvol);
+		return 12;
+	}
+	if (!ret) {
+		fprintf(stderr, "ERROR: '%s' is not a subvolume\n", subvol);
+		return 13;
+	}
+
+	fd = open_file_or_dir(subvol);
+	if (fd < 0) {
+		fprintf(stderr, "ERROR: can't access '%s'\n", subvol);
+		return 12;
+	}
+	max_found = find_root_gen(fd);
+	printf("transid marker was %llu\n", (unsigned long long)max_found);
+	return 0;
+}
+
 int do_find_newer(int argc, char **argv)
 {
 	int fd;
diff --git a/btrfs_cmds.h b/btrfs_cmds.h
index 7bde191..ea4e18e 100644
--- a/btrfs_cmds.h
+++ b/btrfs_cmds.h
@@ -20,6 +20,7 @@ int do_delete_subvolume(int nargs, char **argv);
 int do_create_subvol(int nargs, char **argv);
 int do_fssync(int nargs, char **argv);
 int do_defrag(int argc, char **argv);
+int do_get_latest_gen(int argc, char **argv);
 int do_show_filesystem(int nargs, char **argv);
 int do_add_volume(int nargs, char **args);
 int do_balance(int nargs, char **argv);
@@ -32,3 +33,4 @@ int list_subvols(int fd);
 int do_df_filesystem(int nargs, char **argv);
 int find_updated_files(int fd, u64 root_id, u64 oldest_gen);
 int do_find_newer(int argc, char **argv);
+u64 find_root_gen(int fd);
-- 
1.7.3.1


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 253 bytes --]

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-11-03 11:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-03 11:04 Patch to provide "btrfs subvolume last-gen" Sean Reifschneider
  -- strict thread matches above, loose matches on Subject: below --
2010-11-03  9:23 Sean Reifschneider

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).