diff mbox

[V4,4/7] Btrfs-progs: fix wrong way to check if the root item contains otime and uuid

Message ID 50585420.6060407@cn.fujitsu.com (mailing list archive)
State New, archived
Headers show

Commit Message

Miao Xie Sept. 18, 2012, 10:59 a.m. UTC
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(-)

Comments

Anand Jain Sept. 19, 2012, 1:55 a.m. UTC | #1
Miao,

> wrong because it is possbile that ->generation may equal to the first
> variant of the next item.

  When can this happen ?  Can you provide a scenario to run through. ?

Thanks, Anand
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Miao Xie Sept. 19, 2012, 2:58 a.m. UTC | #2
On 	wed, 19 Sep 2012 09:55:19 +0800, Anand Jain wrote:
> 
> Miao,
> 
>> wrong because it is possbile that ->generation may equal to the first
>> variant of the next item.
> 
>  When can this happen ?  Can you provide a scenario to run through. ?

On the old kernel:
# mkfs.btrfs <partition>
# mount <partition> <mnt>
# btrfs sub snap <mnt> <mnt>/snap0
# btrfs sub snap <mnt> <mnt>/snap1
# btrfs sub list -u <mnt>

Thanks
Miao

> 
> Thanks, Anand
> -- 
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

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;