mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Gang He <ghe@suse.com>
To: mfasheh@suse.com, rgoldwyn@suse.de, ghe@suse.com
Cc: linux-kernel@vger.kernel.org, ocfs2-devel@oss.oracle.com,
	akpm@linux-foundation.org
Subject: [PATCH 3/4] ocfs2: filecheck validate_extent_block function
Date: Fri, 21 Aug 2015 15:43:19 +0800	[thread overview]
Message-ID: <1440143000-24956-4-git-send-email-ghe@suse.com> (raw)
In-Reply-To: <1440143000-24956-1-git-send-email-ghe@suse.com>

Add validate_extent_block/repair_extent_block functions
for online filecheck.

Signed-off-by: Gang He <ghe@suse.com>
---
 fs/ocfs2/alloc.c       | 116 +++++++++++++++++++++++++++++++++++++++++++++++++
 fs/ocfs2/alloc.h       |   4 ++
 fs/ocfs2/ocfs2_trace.h |  24 ++++++++++
 3 files changed, 144 insertions(+)

diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
index 0afb4cb..35fbbf1 100644
--- a/fs/ocfs2/alloc.c
+++ b/fs/ocfs2/alloc.c
@@ -51,6 +51,7 @@
 #include "xattr.h"
 #include "refcounttree.h"
 #include "ocfs2_trace.h"
+#include "filecheck.h"
 
 #include "buffer_head_io.h"
 
@@ -934,6 +935,121 @@ bail:
 	return rc;
 }
 
+static int ocfs2_filecheck_validate_extent_block(struct super_block *sb,
+					struct buffer_head *bh)
+{
+	int rc;
+	struct ocfs2_extent_block *eb =
+		(struct ocfs2_extent_block *)bh->b_data;
+
+	trace_ocfs2_filecheck_validate_extent_block(
+					(unsigned long long)bh->b_blocknr);
+
+	BUG_ON(!buffer_uptodate(bh));
+
+	if (!OCFS2_IS_VALID_EXTENT_BLOCK(eb)) {
+		mlog(ML_ERROR,
+		"Filecheck: extent block #%llu has bad signature %.*s\n",
+		(unsigned long long)bh->b_blocknr,
+		7, eb->h_signature);
+		return -OCFS2_FILECHECK_ERR_INVALIDEXT;
+	}
+
+	rc = ocfs2_validate_meta_ecc(sb, bh->b_data, &eb->h_check);
+	if (rc) {
+		mlog(ML_ERROR, "Filecheck: checksum failed for extent "
+		"block %llu\n",
+		(unsigned long long)bh->b_blocknr);
+		return -OCFS2_FILECHECK_ERR_BLOCKECC;
+	}
+
+	if (le64_to_cpu(eb->h_blkno) != bh->b_blocknr) {
+		mlog(ML_ERROR,
+		"Filecheck: extent block #%llu has an invalid h_blkno "
+		"of %llu\n",
+		(unsigned long long)bh->b_blocknr,
+		(unsigned long long)le64_to_cpu(eb->h_blkno));
+		return -OCFS2_FILECHECK_ERR_BLOCKNO;
+	}
+
+	if (le32_to_cpu(eb->h_fs_generation) != OCFS2_SB(sb)->fs_generation) {
+		mlog(ML_ERROR,
+		"Filecheck: extent block #%llu has an invalid "
+		"h_fs_generation of #%u\n",
+		(unsigned long long)bh->b_blocknr,
+		le32_to_cpu(eb->h_fs_generation));
+		return -OCFS2_FILECHECK_ERR_GENERATION;
+	}
+
+	return 0;
+}
+
+static int ocfs2_filecheck_repair_extent_block(struct super_block *sb,
+					struct buffer_head *bh)
+{
+	int rc;
+	int changed = 0;
+	struct ocfs2_extent_block *eb =
+		(struct ocfs2_extent_block *)bh->b_data;
+
+	rc = ocfs2_filecheck_validate_extent_block(sb, bh);
+	/* Can't fix invalid extent block */
+	if (!rc || rc == -OCFS2_FILECHECK_ERR_INVALIDEXT)
+		return rc;
+
+	trace_ocfs2_filecheck_repair_extent_block(
+					(unsigned long long)bh->b_blocknr);
+
+	if (le64_to_cpu(eb->h_blkno) != bh->b_blocknr) {
+		eb->h_blkno = cpu_to_le64(bh->b_blocknr);
+		changed = 1;
+		mlog(ML_ERROR,
+		"Filecheck: reset extent block #%llu: h_blkno to %llu\n",
+		(unsigned long long)bh->b_blocknr,
+		(unsigned long long)le64_to_cpu(eb->h_blkno));
+	}
+
+	if (le32_to_cpu(eb->h_fs_generation) != OCFS2_SB(sb)->fs_generation) {
+		eb->h_fs_generation = cpu_to_le32(OCFS2_SB(sb)->fs_generation);
+		changed = 1;
+		mlog(ML_ERROR,
+		"Filecheck: reset extent block #%llu: "
+		"h_fs_generation to %u\n",
+		(unsigned long long)bh->b_blocknr,
+		le32_to_cpu(eb->h_fs_generation));
+	}
+
+	if (changed || ocfs2_validate_meta_ecc(sb, bh->b_data, &eb->h_check)) {
+		ocfs2_compute_meta_ecc(sb, bh->b_data, &eb->h_check);
+		mark_buffer_dirty(bh);
+		mlog(ML_ERROR,
+		"Filecheck: reset extent block #%llu: compute meta ecc\n",
+		(unsigned long long)bh->b_blocknr);
+	}
+
+	return 0;
+}
+
+int
+ocfs2_filecheck_read_extent_block(struct ocfs2_caching_info *ci, u64 eb_blkno,
+				struct buffer_head **bh, unsigned int flags)
+{
+	int rc;
+	struct buffer_head *tmp = *bh;
+
+	if (!flags) /* check extent block */
+		rc = ocfs2_read_block(ci, eb_blkno, &tmp,
+				ocfs2_filecheck_validate_extent_block);
+	else /* repair extent block */
+		rc = ocfs2_read_block(ci, eb_blkno, &tmp,
+				ocfs2_filecheck_repair_extent_block);
+
+	if (!rc && !*bh)
+		*bh = tmp;
+
+	return rc;
+}
+
 int ocfs2_read_extent_block(struct ocfs2_caching_info *ci, u64 eb_blkno,
 			    struct buffer_head **bh)
 {
diff --git a/fs/ocfs2/alloc.h b/fs/ocfs2/alloc.h
index fb09b97..c882d52 100644
--- a/fs/ocfs2/alloc.h
+++ b/fs/ocfs2/alloc.h
@@ -92,6 +92,10 @@ void ocfs2_init_refcount_extent_tree(struct ocfs2_extent_tree *et,
 int ocfs2_read_extent_block(struct ocfs2_caching_info *ci, u64 eb_blkno,
 			    struct buffer_head **bh);
 
+int
+ocfs2_filecheck_read_extent_block(struct ocfs2_caching_info *ci, u64 eb_blkno,
+				struct buffer_head **bh, unsigned int flags);
+
 struct ocfs2_alloc_context;
 int ocfs2_insert_extent(handle_t *handle,
 			struct ocfs2_extent_tree *et,
diff --git a/fs/ocfs2/ocfs2_trace.h b/fs/ocfs2/ocfs2_trace.h
index d9205e0..4788748 100644
--- a/fs/ocfs2/ocfs2_trace.h
+++ b/fs/ocfs2/ocfs2_trace.h
@@ -557,6 +557,30 @@ TRACE_EVENT(ocfs2_validate_extent_block,
 	TP_printk("%llu ", __entry->blkno)
 );
 
+TRACE_EVENT(ocfs2_filecheck_validate_extent_block,
+	TP_PROTO(unsigned long long blkno),
+	TP_ARGS(blkno),
+	TP_STRUCT__entry(
+		__field(unsigned long long, blkno)
+	),
+	TP_fast_assign(
+		__entry->blkno = blkno;
+	),
+	TP_printk("%llu ", __entry->blkno)
+);
+
+TRACE_EVENT(ocfs2_filecheck_repair_extent_block,
+	TP_PROTO(unsigned long long blkno),
+	TP_ARGS(blkno),
+	TP_STRUCT__entry(
+		__field(unsigned long long, blkno)
+	),
+	TP_fast_assign(
+		__entry->blkno = blkno;
+	),
+	TP_printk("%llu ", __entry->blkno)
+);
+
 TRACE_EVENT(ocfs2_rotate_leaf,
 	TP_PROTO(unsigned int insert_cpos, int insert_index,
 		 int has_empty, int next_free,
-- 
2.1.2


  parent reply	other threads:[~2015-08-21  7:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-21  7:43 [PATCH 0/4] ocfs2: add file extent block online check Gang He
2015-08-21  7:43 ` [PATCH 1/4] ocfs2: update filecheck copyright Gang He
2015-08-21  7:43 ` [PATCH 2/4] ocfs2: add errno and macro definitions Gang He
2015-08-21  7:43 ` Gang He [this message]
2015-08-21  7:43 ` [PATCH 4/4] ocfs2: add file extent block check Gang He

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1440143000-24956-4-git-send-email-ghe@suse.com \
    --to=ghe@suse.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mfasheh@suse.com \
    --cc=ocfs2-devel@oss.oracle.com \
    --cc=rgoldwyn@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®