linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sean Reifschneider <sean@support.tummy.com>
To: linux-btrfs@vger.kernel.org
Subject: Patch to provide "btrfs subvolume last-gen".
Date: Wed, 03 Nov 2010 03:23:34 -0600	[thread overview]
Message-ID: <4CD12A16.4070802@support.tummy.com> (raw)


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

             reply	other threads:[~2010-11-03  9:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-03  9:23 Sean Reifschneider [this message]
  -- strict thread matches above, loose matches on Subject: below --
2010-11-03 11:04 Patch to provide "btrfs subvolume last-gen" Sean Reifschneider

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=4CD12A16.4070802@support.tummy.com \
    --to=sean@support.tummy.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 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).