* [PATCH] Btrfs: fix byte order issue in free space cache
@ 2011-06-16 1:50 Li Zefan
0 siblings, 0 replies; 2+ messages in thread
From: Li Zefan @ 2011-06-16 1:50 UTC (permalink / raw)
To: linux-btrfs@vger.kernel.org
We should convert the transaction id to little endian before saving
it to disk.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
---
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 <linux/sched.h>
#include <linux/slab.h>
#include <linux/math64.h>
+#include <asm/unaligned.h>
#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);
}
--
1.7.3.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH] Btrfs: fix byte order issue in free space cache
@ 2011-08-03 8:12 Li Zefan
0 siblings, 0 replies; 2+ messages in thread
From: Li Zefan @ 2011-08-03 8:12 UTC (permalink / raw)
To: linux-btrfs@vger.kernel.org; +Cc: Josef Bacik
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 <lizf@cn.fujitsu.com>
---
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);
}
--
1.7.3.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-08-03 8:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-16 1:50 [PATCH] Btrfs: fix byte order issue in free space cache Li Zefan
-- strict thread matches above, loose matches on Subject: below --
2011-08-03 8:12 Li Zefan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).