cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Bob Peterson <rpeterso@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 24/27] gfs2: Get rid of gfs2_log_header_in
Date: Mon, 29 Jan 2018 07:35:22 -0700	[thread overview]
Message-ID: <20180129143525.28947-25-rpeterso@redhat.com> (raw)
In-Reply-To: <20180129143525.28947-1-rpeterso@redhat.com>

From: Andreas Gruenbacher <agruenba@redhat.com>

Get rid of gfs2_log_header_in by integrating it into get_log_header.
Clean up the crc32 computations and use the same functions for encoding
and decoding to make things less confusing.  Eliminate lh_hash from
gfs2_log_header_host which is completely useless.

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Signed-off-by: Bob Peterson <rpeterso@redhat.com>
---
 fs/gfs2/incore.h   |  1 -
 fs/gfs2/log.c      |  2 +-
 fs/gfs2/recovery.c | 44 ++++++++++++++++----------------------------
 3 files changed, 17 insertions(+), 30 deletions(-)

diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h
index 9d4d7367175f..e0557b8a590a 100644
--- a/fs/gfs2/incore.h
+++ b/fs/gfs2/incore.h
@@ -44,7 +44,6 @@ struct gfs2_log_header_host {
 	u32 lh_flags;		/* GFS2_LOG_HEAD_... */
 	u32 lh_tail;		/* Block number of log tail */
 	u32 lh_blkno;
-	u32 lh_hash;
 };
 
 /*
diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c
index b9889ae5fd7c..c27cbcebfe88 100644
--- a/fs/gfs2/log.c
+++ b/fs/gfs2/log.c
@@ -680,7 +680,7 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, u64 seq, u32 tail,
 	lh->lh_flags = cpu_to_be32(flags);
 	lh->lh_tail = cpu_to_be32(tail);
 	lh->lh_blkno = cpu_to_be32(sdp->sd_log_flush_head);
-	hash = gfs2_disk_hash(page_address(page), sizeof(struct gfs2_log_header));
+	hash = ~crc32(~0, lh, sizeof(*lh));
 	lh->lh_hash = cpu_to_be32(hash);
 
 	gfs2_log_write_page(sdp, page);
diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c
index 5d3431219425..975f32166dfe 100644
--- a/fs/gfs2/recovery.c
+++ b/fs/gfs2/recovery.c
@@ -118,22 +118,6 @@ void gfs2_revoke_clean(struct gfs2_jdesc *jd)
 	}
 }
 
-static int gfs2_log_header_in(struct gfs2_log_header_host *lh, const void *buf)
-{
-	const struct gfs2_log_header *str = buf;
-
-	if (str->lh_header.mh_magic != cpu_to_be32(GFS2_MAGIC) ||
-	    str->lh_header.mh_type != cpu_to_be32(GFS2_METATYPE_LH))
-		return 1;
-
-	lh->lh_sequence = be64_to_cpu(str->lh_sequence);
-	lh->lh_flags = be32_to_cpu(str->lh_flags);
-	lh->lh_tail = be32_to_cpu(str->lh_tail);
-	lh->lh_blkno = be32_to_cpu(str->lh_blkno);
-	lh->lh_hash = be32_to_cpu(str->lh_hash);
-	return 0;
-}
-
 /**
  * get_log_header - read the log header for a given segment
  * @jd: the journal
@@ -151,29 +135,33 @@ static int gfs2_log_header_in(struct gfs2_log_header_host *lh, const void *buf)
 static int get_log_header(struct gfs2_jdesc *jd, unsigned int blk,
 			  struct gfs2_log_header_host *head)
 {
+	struct gfs2_log_header *lh;
 	struct buffer_head *bh;
-	struct gfs2_log_header_host uninitialized_var(lh);
-	const u32 nothing = 0;
 	u32 hash;
 	int error;
 
 	error = gfs2_replay_read_block(jd, blk, &bh);
 	if (error)
 		return error;
+	lh = (void *)bh->b_data;
 
-	hash = crc32_le((u32)~0, bh->b_data, sizeof(struct gfs2_log_header) -
-					     sizeof(u32));
-	hash = crc32_le(hash, (unsigned char const *)&nothing, sizeof(nothing));
-	hash ^= (u32)~0;
-	error = gfs2_log_header_in(&lh, bh->b_data);
-	brelse(bh);
+	hash = crc32(~0, lh, sizeof(*lh) - 4);
+	hash = ~crc32_le_shift(hash, 4);  /* assume lh_hash is zero */
 
-	if (error || lh.lh_blkno != blk || lh.lh_hash != hash)
-		return 1;
+	error = lh->lh_header.mh_magic != cpu_to_be32(GFS2_MAGIC) ||
+		lh->lh_header.mh_type != cpu_to_be32(GFS2_METATYPE_LH) ||
+		be32_to_cpu(lh->lh_blkno) != blk ||
+		be32_to_cpu(lh->lh_hash) != hash;
 
-	*head = lh;
+	brelse(bh);
 
-	return 0;
+	if (!error) {
+		head->lh_sequence = be64_to_cpu(lh->lh_sequence);
+		head->lh_flags = be32_to_cpu(lh->lh_flags);
+		head->lh_tail = be32_to_cpu(lh->lh_tail);
+		head->lh_blkno = be32_to_cpu(lh->lh_blkno);
+	}
+	return error;
 }
 
 /**
-- 
2.14.3



  parent reply	other threads:[~2018-01-29 14:35 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-29 14:34 [Cluster-devel] [PATCH 00/27] GFS2: Pre-pull patch posting (merge window) Bob Peterson
2018-01-29 14:34 ` [Cluster-devel] [PATCH 01/27] GFS2: Combine gfs2_free_di with gfs2_free_uninit_di Bob Peterson
2018-01-29 14:35 ` [Cluster-devel] [PATCH 02/27] gfs2: Fix wrong error handling in init_gfs2_fs() Bob Peterson
2018-01-29 14:35 ` [Cluster-devel] [PATCH 03/27] gfs2: Remove unused gfs2_write_jdata_pagevec parameter Bob Peterson
2018-01-29 14:35 ` [Cluster-devel] [PATCH 04/27] gfs2: Add a next-resource-group pointer to resource groups Bob Peterson
2018-01-29 14:35 ` [Cluster-devel] [PATCH 05/27] gfs2: Add rindex fields to rgrp headers Bob Peterson
2018-01-29 14:35 ` [Cluster-devel] [PATCH 06/27] gfs2: Add a crc field to resource group headers Bob Peterson
2018-01-29 14:35 ` [Cluster-devel] [PATCH 07/27] GFS2: Reduce code redundancy writing log headers Bob Peterson
2018-01-29 14:35 ` [Cluster-devel] [PATCH 08/27] gfs2: Trim the ordered write list in gfs2_ordered_write() Bob Peterson
2018-01-29 14:35 ` [Cluster-devel] [PATCH 09/27] gfs2: Add gfs2_blk2rgrpd comment and fix incorrect use Bob Peterson
2018-01-29 14:35 ` [Cluster-devel] [PATCH 10/27] gfs2: Remove pointless BUG_ON Bob Peterson
2018-01-29 14:35 ` [Cluster-devel] [PATCH 11/27] gfs2: Clean up trunc_start error path Bob Peterson
2018-01-29 14:35 ` [Cluster-devel] [PATCH 12/27] gfs2: truncate: Remove unnecessary oldsize parameters Bob Peterson
2018-01-29 14:35 ` [Cluster-devel] [PATCH 13/27] gfs2: Remove minor gfs2_journaled_truncate inefficiencies Bob Peterson
2018-01-29 14:35 ` [Cluster-devel] [PATCH 14/27] gfs2: Clean up {lookup, fillup}_metapath Bob Peterson
2018-01-29 14:35 ` [Cluster-devel] [PATCH 15/27] gfs2: Fix metadata read-ahead during truncate Bob Peterson
2018-01-29 14:35 ` [Cluster-devel] [PATCH 16/27] gfs2: Improve non-recursive delete algorithm Bob Peterson
2018-01-29 14:35 ` [Cluster-devel] [PATCH 17/27] Turn gfs2_block_truncate_page into gfs2_block_zero_range Bob Peterson
2018-01-29 14:35 ` [Cluster-devel] [PATCH 18/27] gfs2: Generalize truncate code Bob Peterson
2018-01-29 14:35 ` [Cluster-devel] [PATCH 19/27] gfs2: Turn trunc_dealloc into punch_hole Bob Peterson
2018-01-29 14:35 ` [Cluster-devel] [PATCH 20/27] gfs2: Implement fallocate(FALLOC_FL_PUNCH_HOLE) Bob Peterson
2018-01-29 14:35 ` [Cluster-devel] [PATCH 21/27] gfs2: Typo fixes Bob Peterson
2018-01-29 14:35 ` [Cluster-devel] [PATCH 22/27] gfs2: Add gfs2_max_stuffed_size Bob Peterson
2018-01-29 14:35 ` [Cluster-devel] [PATCH 23/27] gfs2: Minor gfs2_page_add_databufs cleanup Bob Peterson
2018-01-29 14:35 ` Bob Peterson [this message]
2018-01-29 14:35 ` [Cluster-devel] [PATCH 25/27] GFS2: Introduce new gfs2_log_header_v2 Bob Peterson
2018-01-29 14:35 ` [Cluster-devel] [PATCH 26/27] GFS2: Log the reason for log flushes in every log header Bob Peterson
2018-01-29 14:35 ` [Cluster-devel] [PATCH 27/27] GFS2: Fix minor comment typo Bob Peterson

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=20180129143525.28947-25-rpeterso@redhat.com \
    --to=rpeterso@redhat.com \
    /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;
as well as URLs for NNTP newsgroup(s).