From patchwork Thu Jun 16 01:50:42 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zefan X-Patchwork-Id: 883882 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 p5G1kJjQ030425 for ; Thu, 16 Jun 2011 01:46:20 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753534Ab1FPBqQ (ORCPT ); Wed, 15 Jun 2011 21:46:16 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:51799 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1752590Ab1FPBqQ (ORCPT ); Wed, 15 Jun 2011 21:46:16 -0400 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 66D67170091 for ; Thu, 16 Jun 2011 09:46:14 +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 p5G1kCKD025037 for ; Thu, 16 Jun 2011 09:46:13 +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 2011061609455416-583126 ; Thu, 16 Jun 2011 09:45:54 +0800 Message-ID: <4DF96172.4020007@cn.fujitsu.com> Date: Thu, 16 Jun 2011 09:50:42 +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" 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-06-16 09:45:54, Serialize by Router on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2011-06-16 09:45:56, Serialize complete at 2011-06-16 09:45:56 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]); Thu, 16 Jun 2011 01:46:20 +0000 (UTC) We should convert the transaction id to little endian before saving it to disk. Signed-off-by: Li Zefan --- fs/btrfs/free-space-cache.c | 15 ++++++++------- 1 files changed, 8 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 9f985a4..740dbf4 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "ctree.h" #include "free-space-cache.h" #include "transaction.h" @@ -340,14 +341,15 @@ int __load_free_space_cache(struct btrfs_root *root, struct inode *inode, addr = kmap(page); if (index == 0) { - u64 *gen; + u64 gen; memcpy(disk_crcs, addr, first_page_offset); - gen = addr + (sizeof(u32) * num_checksums); - if (*gen != BTRFS_I(inode)->generation) { + gen = get_unaligned_le64( + addr + sizeof(u32) * num_checksums); + 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); @@ -814,14 +816,13 @@ int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode, /* Write the checksums and trans id to the first page */ { void *addr; - u64 *gen; page = pages[0]; addr = kmap(page); memcpy(addr, checksums, sizeof(u32) * num_pages); - gen = addr + (sizeof(u32) * num_pages); - *gen = trans->transid; + put_unaligned_le64(trans->transid, + addr + sizeof(u32) * num_pages); kunmap(page); }