Commit 6994ca36 authored by David Sterba's avatar David Sterba

btrfs: free-space-cache: use unaligned helpers to access data

The free space inode stores the tracking data, checksums etc, using the
io_ctl structure and moving the pointers. The data are generally aligned
to at least 4 bytes (u32 for CRC) so it's not completely unaligned but
for clarity we should use the proper helpers whenever a struct is
initialized from io_ctl->cur pointer.
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent e2f896b3
...@@ -413,8 +413,6 @@ static int io_ctl_prepare_pages(struct btrfs_io_ctl *io_ctl, bool uptodate) ...@@ -413,8 +413,6 @@ static int io_ctl_prepare_pages(struct btrfs_io_ctl *io_ctl, bool uptodate)
static void io_ctl_set_generation(struct btrfs_io_ctl *io_ctl, u64 generation) static void io_ctl_set_generation(struct btrfs_io_ctl *io_ctl, u64 generation)
{ {
__le64 *val;
io_ctl_map_page(io_ctl, 1); io_ctl_map_page(io_ctl, 1);
/* /*
...@@ -429,14 +427,13 @@ static void io_ctl_set_generation(struct btrfs_io_ctl *io_ctl, u64 generation) ...@@ -429,14 +427,13 @@ static void io_ctl_set_generation(struct btrfs_io_ctl *io_ctl, u64 generation)
io_ctl->size -= sizeof(u64) * 2; io_ctl->size -= sizeof(u64) * 2;
} }
val = io_ctl->cur; put_unaligned_le64(generation, io_ctl->cur);
*val = cpu_to_le64(generation);
io_ctl->cur += sizeof(u64); io_ctl->cur += sizeof(u64);
} }
static int io_ctl_check_generation(struct btrfs_io_ctl *io_ctl, u64 generation) static int io_ctl_check_generation(struct btrfs_io_ctl *io_ctl, u64 generation)
{ {
__le64 *gen; u64 cache_gen;
/* /*
* Skip the crc area. If we don't check crcs then we just have a 64bit * Skip the crc area. If we don't check crcs then we just have a 64bit
...@@ -451,11 +448,11 @@ static int io_ctl_check_generation(struct btrfs_io_ctl *io_ctl, u64 generation) ...@@ -451,11 +448,11 @@ static int io_ctl_check_generation(struct btrfs_io_ctl *io_ctl, u64 generation)
io_ctl->size -= sizeof(u64) * 2; io_ctl->size -= sizeof(u64) * 2;
} }
gen = io_ctl->cur; cache_gen = get_unaligned_le64(io_ctl->cur);
if (le64_to_cpu(*gen) != generation) { if (cache_gen != generation) {
btrfs_err_rl(io_ctl->fs_info, btrfs_err_rl(io_ctl->fs_info,
"space cache generation (%llu) does not match inode (%llu)", "space cache generation (%llu) does not match inode (%llu)",
*gen, generation); cache_gen, generation);
io_ctl_unmap_page(io_ctl); io_ctl_unmap_page(io_ctl);
return -EIO; return -EIO;
} }
...@@ -525,8 +522,8 @@ static int io_ctl_add_entry(struct btrfs_io_ctl *io_ctl, u64 offset, u64 bytes, ...@@ -525,8 +522,8 @@ static int io_ctl_add_entry(struct btrfs_io_ctl *io_ctl, u64 offset, u64 bytes,
return -ENOSPC; return -ENOSPC;
entry = io_ctl->cur; entry = io_ctl->cur;
entry->offset = cpu_to_le64(offset); put_unaligned_le64(offset, &entry->offset);
entry->bytes = cpu_to_le64(bytes); put_unaligned_le64(bytes, &entry->bytes);
entry->type = (bitmap) ? BTRFS_FREE_SPACE_BITMAP : entry->type = (bitmap) ? BTRFS_FREE_SPACE_BITMAP :
BTRFS_FREE_SPACE_EXTENT; BTRFS_FREE_SPACE_EXTENT;
io_ctl->cur += sizeof(struct btrfs_free_space_entry); io_ctl->cur += sizeof(struct btrfs_free_space_entry);
...@@ -599,8 +596,8 @@ static int io_ctl_read_entry(struct btrfs_io_ctl *io_ctl, ...@@ -599,8 +596,8 @@ static int io_ctl_read_entry(struct btrfs_io_ctl *io_ctl,
} }
e = io_ctl->cur; e = io_ctl->cur;
entry->offset = le64_to_cpu(e->offset); entry->offset = get_unaligned_le64(&e->offset);
entry->bytes = le64_to_cpu(e->bytes); entry->bytes = get_unaligned_le64(&e->bytes);
*type = e->type; *type = e->type;
io_ctl->cur += sizeof(struct btrfs_free_space_entry); io_ctl->cur += sizeof(struct btrfs_free_space_entry);
io_ctl->size -= sizeof(struct btrfs_free_space_entry); io_ctl->size -= sizeof(struct btrfs_free_space_entry);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment