All of lore.kernel.org
 help / color / mirror / Atom feed
From: Miao Xie <miaox@cn.fujitsu.com>
To: Linux Btrfs <linux-btrfs@vger.kernel.org>
Subject: [PATCH V4 4/7] Btrfs-progs: fix wrong way to check if the root item contains otime and uuid
Date: Tue, 18 Sep 2012 18:59:44 +0800	[thread overview]
Message-ID: <50585420.6060407@cn.fujitsu.com> (raw)
In-Reply-To: <50584E6D.8000602@cn.fujitsu.com>

From: Miao Xie <miaox@cn.fujitsu.com>

Now we check if the root item contains otime and uuid or not by comparing
->generation_v2 and ->generation of the btrfs_root_item structure, it is
wrong because it is possbile that ->generation may equal to the first
variant of the next item. We fix this problem by check the size of btrfs_root_item,
if it is larger than the original one, the new btrfs_root_item contains otime
and uuid. we needn't worry the case that the new filesystem is mounted on the
old kernel. because the otime and uuid are not changed on the old kernel, we can
get the correct result even on the kernel.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
---
Changelog v3 -> v4:
- change the check method of btrfs_root_item, if the size of btrfs_root_item
  is larger than the original one, the new btrfs_root_item contains otime and
  uuid.

Changelog v1 -> v3:
- new patch
---
 btrfs-list.c |    9 ++++++---
 ctree.h      |   15 +++++++++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/btrfs-list.c b/btrfs-list.c
index ef621f0..ed28021 100644
--- a/btrfs-list.c
+++ b/btrfs-list.c
@@ -737,7 +737,8 @@ again:
 			} else if (get_gen && sh->type == BTRFS_ROOT_ITEM_KEY) {
 				ri = (struct btrfs_root_item *)(args.buf + off);
 				gen = btrfs_root_generation(ri);
-				if(ri->generation == ri->generation_v2) {
+				if(sh->len >
+				   sizeof(struct btrfs_root_item_v0)) {
 					t = ri->otime.sec;
 					memcpy(uuid, ri->uuid, BTRFS_UUID_SIZE);
 				} else {
@@ -844,9 +845,11 @@ static int __list_snapshot_search(int fd, struct root_lookup *root_lookup)
 			off += sizeof(*sh);
 			if (sh->type == BTRFS_ROOT_ITEM_KEY && sh->offset) {
 				item = (struct btrfs_root_item *)(args.buf + off);
-				if(item->generation == item->generation_v2) {
+				if(sh->len >
+				   sizeof(struct btrfs_root_item_v0)) {
 					t = item->otime.sec;
-					memcpy(uuid, item->uuid, BTRFS_UUID_SIZE);
+					memcpy(uuid, item->uuid,
+					       BTRFS_UUID_SIZE);
 				} else {
 					t = 0;
 					memset(uuid, 0, BTRFS_UUID_SIZE);
diff --git a/ctree.h b/ctree.h
index 7f55229..c55d033 100644
--- a/ctree.h
+++ b/ctree.h
@@ -637,6 +637,21 @@ struct btrfs_dir_item {
 	u8 type;
 } __attribute__ ((__packed__));
 
+struct btrfs_root_item_v0 {
+	struct btrfs_inode_item inode;
+	__le64 generation;
+	__le64 root_dirid;
+	__le64 bytenr;
+	__le64 byte_limit;
+	__le64 bytes_used;
+	__le64 last_snapshot;
+	__le64 flags;
+	__le32 refs;
+	struct btrfs_disk_key drop_progress;
+	u8 drop_level;
+	u8 level;
+} __attribute__ ((__packed__));
+
 struct btrfs_root_item {
 	struct btrfs_inode_item inode;
 	__le64 generation;
-- 
1.7.6.5


  parent reply	other threads:[~2012-09-18 10:59 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-18 10:35 [PATCH V4 0/7 ] Btrfs-progs: enhance btrfs subvol list only to show read-only snapshots Miao Xie
2012-09-18 10:50 ` [PATCH V4 1/7] Btrfs-progs: move the function declarations to a new head file Miao Xie
2012-09-18 10:52 ` [PATCH V4 2/7] Btrfs-progs: fix compile warning of implicit declaration of "list_snapshots" Miao Xie
2012-09-18 10:55 ` [PATCH V4 3/7] Btrfs-progs: fix wrong usage of btrfs subvolume list command Miao Xie
2012-09-18 10:59 ` Miao Xie [this message]
2012-09-19  1:55   ` [PATCH V4 4/7] Btrfs-progs: fix wrong way to check if the root item contains otime and uuid Anand Jain
2012-09-19  2:58     ` Miao Xie
2012-09-18 11:06 ` [PATCH V4 5/7] Btrfs-progs: restructure list_subvolumes Miao Xie
2012-09-20 12:09   ` David Sterba
2012-10-09 16:05   ` Alex Lyakas
2012-10-10  2:12     ` Miao Xie
2012-10-10 19:45       ` Alex Lyakas
2012-10-15  4:06         ` Miao Xie
2012-09-18 11:09 ` [PATCH V4 6/7] Btrfs-progs: enhance btrfs subvol list only to show read-only snapshots Miao Xie
2012-09-18 15:11   ` Martin Steigerwald
2012-09-18 11:12 ` [PATCH V4 7/7] Btrfs-progs: update the manpage entries for the btrfs subvolume list Miao Xie
2012-09-28 12:55 ` [PATCH] Btrfs-progs: make btrfs_list_setup_filter to modify a set filter Anand jain
2012-10-03  0:03 ` [PATCH V4 0/7 ] Btrfs-progs: enhance btrfs subvol list only to show read-only snapshots Chris Mason
2012-10-09  6:01   ` Miao Xie
2012-10-09 15:57     ` David Sterba
2012-10-04 10:12 ` [PATCH] Btrfs-progs: add parent uuid for snapshots Anand jain
2012-10-04 12:00   ` Dong Robin
2012-10-05  2:27     ` Anand Jain
2012-10-05  2:25 ` [PATCH] Btrfs-progs: Corrections and additions to the btrfs man page Anand jain
2012-10-05  2:25   ` [PATCH] Btrfs-progs: Update btrfs man page for -P option Anand jain
2012-10-05  2:25   ` [PATCH V2] Btrfs-progs: add parent uuid for snapshots Anand jain
2012-10-09 15:44     ` David Sterba
2012-10-16  7:00       ` [PATCH V3] " Anand jain
2012-10-16  7:00         ` [PATCH] Btrfs-progs: make use of column_name Anand jain
2012-10-16  7:00         ` [PATCH] Btrfs-progs: update man page for -u and -q option in subvol list Anand jain
2012-10-16  7:03       ` [PATCH V2] Btrfs-progs: add parent uuid for snapshots Anand Jain

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=50585420.6060407@cn.fujitsu.com \
    --to=miaox@cn.fujitsu.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.