Commit c175a518 authored by Joel Becker's avatar Joel Becker Committed by Mark Fasheh

ocfs2: Checksum and ECC for directory blocks.

Use the db_check field of ocfs2_dir_block_trailer to crc/ecc the
dirblocks.
Signed-off-by: default avatarJoel Becker <joel.becker@oracle.com>
Signed-off-by: default avatarMark Fasheh <mfasheh@suse.com>
parent 87d35a74
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
#include "ocfs2.h" #include "ocfs2.h"
#include "alloc.h" #include "alloc.h"
#include "blockcheck.h"
#include "dir.h" #include "dir.h"
#include "dlmglue.h" #include "dlmglue.h"
#include "extent_map.h" #include "extent_map.h"
...@@ -107,6 +108,17 @@ static inline unsigned int ocfs2_dir_trailer_blk_off(struct super_block *sb) ...@@ -107,6 +108,17 @@ static inline unsigned int ocfs2_dir_trailer_blk_off(struct super_block *sb)
#define ocfs2_trailer_from_bh(_bh, _sb) ((struct ocfs2_dir_block_trailer *) ((_bh)->b_data + ocfs2_dir_trailer_blk_off((_sb)))) #define ocfs2_trailer_from_bh(_bh, _sb) ((struct ocfs2_dir_block_trailer *) ((_bh)->b_data + ocfs2_dir_trailer_blk_off((_sb))))
/* XXX ocfs2_block_dqtrailer() is similar but not quite - can we make
* them more consistent? */
struct ocfs2_dir_block_trailer *ocfs2_dir_trailer_from_size(int blocksize,
void *data)
{
char *p = data;
p += blocksize - sizeof(struct ocfs2_dir_block_trailer);
return (struct ocfs2_dir_block_trailer *)p;
}
/* /*
* XXX: This is executed once on every dirent. We should consider optimizing * XXX: This is executed once on every dirent. We should consider optimizing
* it. * it.
...@@ -268,14 +280,35 @@ static struct buffer_head *ocfs2_find_entry_id(const char *name, ...@@ -268,14 +280,35 @@ static struct buffer_head *ocfs2_find_entry_id(const char *name,
static int ocfs2_validate_dir_block(struct super_block *sb, static int ocfs2_validate_dir_block(struct super_block *sb,
struct buffer_head *bh) struct buffer_head *bh)
{ {
int rc;
struct ocfs2_dir_block_trailer *trailer =
ocfs2_trailer_from_bh(bh, sb);
/* /*
* Nothing yet. We don't validate dirents here, that's handled * We don't validate dirents here, that's handled
* in-place when the code walks them. * in-place when the code walks them.
*/ */
mlog(0, "Validating dirblock %llu\n", mlog(0, "Validating dirblock %llu\n",
(unsigned long long)bh->b_blocknr); (unsigned long long)bh->b_blocknr);
return 0; BUG_ON(!buffer_uptodate(bh));
/*
* If the ecc fails, we return the error but otherwise
* leave the filesystem running. We know any error is
* local to this block.
*
* Note that we are safe to call this even if the directory
* doesn't have a trailer. Filesystems without metaecc will do
* nothing, and filesystems with it will have one.
*/
rc = ocfs2_validate_meta_ecc(sb, bh->b_data, &trailer->db_check);
if (rc)
mlog(ML_ERROR, "Checksum failed for dinode %llu\n",
(unsigned long long)bh->b_blocknr);
return rc;
} }
/* /*
......
...@@ -83,4 +83,6 @@ int ocfs2_fill_new_dir(struct ocfs2_super *osb, ...@@ -83,4 +83,6 @@ int ocfs2_fill_new_dir(struct ocfs2_super *osb,
struct buffer_head *fe_bh, struct buffer_head *fe_bh,
struct ocfs2_alloc_context *data_ac); struct ocfs2_alloc_context *data_ac);
struct ocfs2_dir_block_trailer *ocfs2_dir_trailer_from_size(int blocksize,
void *data);
#endif /* OCFS2_DIR_H */ #endif /* OCFS2_DIR_H */
...@@ -415,6 +415,26 @@ static void ocfs2_dq_commit_trigger(struct jbd2_buffer_trigger_type *triggers, ...@@ -415,6 +415,26 @@ static void ocfs2_dq_commit_trigger(struct jbd2_buffer_trigger_type *triggers,
ocfs2_block_check_compute(data, size, &dqt->dq_check); ocfs2_block_check_compute(data, size, &dqt->dq_check);
} }
/*
* Directory blocks also have their own trigger because the
* struct ocfs2_block_check offset depends on the blocksize.
*/
static void ocfs2_db_commit_trigger(struct jbd2_buffer_trigger_type *triggers,
struct buffer_head *bh,
void *data, size_t size)
{
struct ocfs2_dir_block_trailer *trailer =
ocfs2_dir_trailer_from_size(size, data);
/*
* We aren't guaranteed to have the superblock here, so we
* must unconditionally compute the ecc data.
* __ocfs2_journal_access() will only set the triggers if
* metaecc is enabled.
*/
ocfs2_block_check_compute(data, size, &trailer->db_check);
}
static void ocfs2_abort_trigger(struct jbd2_buffer_trigger_type *triggers, static void ocfs2_abort_trigger(struct jbd2_buffer_trigger_type *triggers,
struct buffer_head *bh) struct buffer_head *bh)
{ {
...@@ -454,6 +474,13 @@ static struct ocfs2_triggers gd_triggers = { ...@@ -454,6 +474,13 @@ static struct ocfs2_triggers gd_triggers = {
.ot_offset = offsetof(struct ocfs2_group_desc, bg_check), .ot_offset = offsetof(struct ocfs2_group_desc, bg_check),
}; };
static struct ocfs2_triggers db_triggers = {
.ot_triggers = {
.t_commit = ocfs2_db_commit_trigger,
.t_abort = ocfs2_abort_trigger,
},
};
static struct ocfs2_triggers xb_triggers = { static struct ocfs2_triggers xb_triggers = {
.ot_triggers = { .ot_triggers = {
.t_commit = ocfs2_commit_trigger, .t_commit = ocfs2_commit_trigger,
...@@ -555,8 +582,8 @@ int ocfs2_journal_access_gd(handle_t *handle, struct inode *inode, ...@@ -555,8 +582,8 @@ int ocfs2_journal_access_gd(handle_t *handle, struct inode *inode,
int ocfs2_journal_access_db(handle_t *handle, struct inode *inode, int ocfs2_journal_access_db(handle_t *handle, struct inode *inode,
struct buffer_head *bh, int type) struct buffer_head *bh, int type)
{ {
/* Right now, nothing for dirblocks */ return __ocfs2_journal_access(handle, inode, bh, &db_triggers,
return __ocfs2_journal_access(handle, inode, bh, NULL, type); type);
} }
int ocfs2_journal_access_xb(handle_t *handle, struct inode *inode, int ocfs2_journal_access_xb(handle_t *handle, struct inode *inode,
......
...@@ -776,7 +776,7 @@ struct ocfs2_dir_block_trailer { ...@@ -776,7 +776,7 @@ struct ocfs2_dir_block_trailer {
/*20*/ __le64 db_blkno; /* Offset on disk, in blocks */ /*20*/ __le64 db_blkno; /* Offset on disk, in blocks */
__le64 db_parent_dinode; /* dinode which owns me, in __le64 db_parent_dinode; /* dinode which owns me, in
blocks */ blocks */
/*30*/ __le64 db_check; /* Error checking */ /*30*/ struct ocfs2_block_check db_check; /* Error checking */
/*40*/ /*40*/
}; };
......
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