From patchwork Wed Aug 3 08:12:12 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zefan X-Patchwork-Id: 1030752 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p738CI8E021863 for ; Wed, 3 Aug 2011 08:12:18 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753038Ab1HCIMP (ORCPT ); Wed, 3 Aug 2011 04:12:15 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:54273 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1752192Ab1HCIMO (ORCPT ); Wed, 3 Aug 2011 04:12:14 -0400 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 9819A17003F; Wed, 3 Aug 2011 16:11:57 +0800 (CST) Received: from mailserver.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 p738Bv4g003435; Wed, 3 Aug 2011 16:11:57 +0800 Received: from [10.167.225.230] ([10.167.225.230]) by mailserver.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.1FP4) with ESMTP id 2011080316105922-35069 ; Wed, 3 Aug 2011 16:10:59 +0800 Message-ID: <4E3902DC.4010105@cn.fujitsu.com> Date: Wed, 03 Aug 2011 16:12:12 +0800 From: Li Zefan User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.9) Gecko/20100921 Fedora/3.1.4-1.fc14 Thunderbird/3.1.4 MIME-Version: 1.0 To: "linux-btrfs@vger.kernel.org" CC: Josef Bacik Subject: [PATCH] Btrfs: fix byte order issue in free space cache X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2011-08-03 16:10:59, Serialize by Router on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2011-08-03 16:10:59, Serialize complete at 2011-08-03 16:10:59 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Wed, 03 Aug 2011 08:12:18 +0000 (UTC) We should convert the generation number to little endian before saving it to disk. We've just changed to use the normal checksumming infrastructure for free space cache, so it's the perfect time to fix this bug. Signed-off-by: Li Zefan --- fs/btrfs/free-space-cache.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 6377713..9277d65 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -325,7 +325,7 @@ int __load_free_space_cache(struct btrfs_root *root, struct inode *inode, addr = kmap(page); if (index == 0) { - u64 *gen; + u64 gen; /* * We put a bogus crc in the front of the first page in @@ -335,11 +335,11 @@ int __load_free_space_cache(struct btrfs_root *root, struct inode *inode, addr += sizeof(u64); offset += sizeof(u64); - gen = addr; - if (*gen != BTRFS_I(inode)->generation) { + gen = le64_to_cpu(*(__le64 *)addr); + if (gen != BTRFS_I(inode)->generation) { printk(KERN_ERR "btrfs: space cache generation" " (%llu) does not match inode (%llu)\n", - (unsigned long long)*gen, + (unsigned long long)gen, (unsigned long long) BTRFS_I(inode)->generation); kunmap(page); @@ -636,7 +636,7 @@ int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode, orig = addr = kmap(page); if (index == 0) { - u64 *gen; + __le64 *gen; /* * We're going to put in a bogus crc for this page to @@ -647,7 +647,7 @@ int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode, offset += sizeof(u64); gen = addr; - *gen = trans->transid; + *gen = cpu_to_le64(trans->transid); addr += sizeof(u64); offset += sizeof(u64); }