From patchwork Thu Sep 6 10:50:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao Xie X-Patchwork-Id: 1412971 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 83407DFFCF for ; Thu, 6 Sep 2012 10:50:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758228Ab2IFKuP (ORCPT ); Thu, 6 Sep 2012 06:50:15 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:24723 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1757460Ab2IFKuO (ORCPT ); Thu, 6 Sep 2012 06:50:14 -0400 X-IronPort-AV: E=Sophos;i="4.80,380,1344182400"; d="scan'208";a="5797118" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 06 Sep 2012 18:49:02 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id q86AoD6G019807 for ; Thu, 6 Sep 2012 18:50:13 +0800 Received: from [10.167.225.199] ([10.167.225.199]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2012090618494937-670974 ; Thu, 6 Sep 2012 18:49:49 +0800 Message-ID: <50487FD8.1000804@cn.fujitsu.com> Date: Thu, 06 Sep 2012 18:50:00 +0800 From: Miao Xie Reply-To: miaox@cn.fujitsu.com User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120605 Thunderbird/13.0 MIME-Version: 1.0 To: Linux Btrfs Subject: [PATCH V3 4/7] Btrfs-progs: fix wrong way to check if the root item contains otime and uuid X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2012/09/06 18:49:49, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2012/09/06 18:49:49, Serialize complete at 2012/09/06 18:49:49 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org 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 comparing the size of btrfs_root_item because the size is different between the old and new ones. 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 --- Changelog v1 -> v3: - new patch --- btrfs-list.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/btrfs-list.c b/btrfs-list.c index ef621f0..2101695 100644 --- a/btrfs-list.c +++ b/btrfs-list.c @@ -737,7 +737,7 @@ 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)) { t = ri->otime.sec; memcpy(uuid, ri->uuid, BTRFS_UUID_SIZE); } else { @@ -844,7 +844,7 @@ 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)) { t = item->otime.sec; memcpy(uuid, item->uuid, BTRFS_UUID_SIZE); } else {