All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wang Nan <wangnan0@huawei.com>
To: kumagai-atsushi@mxc.nes.nec.co.jp
Cc: Wang Nan <wangnan0@huawei.com>,
	kexec@lists.infradead.org, Geng Hui <hui.geng@huawei.com>
Subject: [PATCH v2] makedumpfile: code cleanup: set_bitmap
Date: Thu, 24 Apr 2014 17:11:13 +0800	[thread overview]
Message-ID: <1398330673-23016-1-git-send-email-wangnan0@huawei.com> (raw)
In-Reply-To: <0910DD04CBD6DE4193FCF86B9C00BE97205CAA@BPXM01GP.gisp.nec.co.jp>

This patch makes set_bitmap() to call sync_bitmap() instead rewrite
identical code to do same thing.

Change from v1:

- fix a simple mistake:
  sync_bitmap() returns TRUE(1) when it succeeds, so use
  (!sync_bitmap()) for checking.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: kexec@lists.infradead.org
Cc: Geng Hui <hui.geng@huawei.com>
---
 makedumpfile.c | 70 ++++++++++++++++++++++++++--------------------------------
 1 file changed, 31 insertions(+), 39 deletions(-)

diff --git a/makedumpfile.c b/makedumpfile.c
index ce4a866..cea37a2 100644
--- a/makedumpfile.c
+++ b/makedumpfile.c
@@ -3309,6 +3309,34 @@ initialize_2nd_bitmap(struct dump_bitmap *bitmap)
 }
 
 int
+sync_bitmap(struct dump_bitmap *bitmap)
+{
+	off_t offset;
+	offset = bitmap->offset + BUFSIZE_BITMAP * bitmap->no_block;
+
+	/*
+	 * The bitmap buffer is not dirty, and it is not necessary
+	 * to write out it.
+	 */
+	if (bitmap->no_block < 0)
+		return TRUE;
+
+	if (lseek(bitmap->fd, offset, SEEK_SET) < 0 ) {
+		ERRMSG("Can't seek the bitmap(%s). %s\n",
+		    bitmap->file_name, strerror(errno));
+		return FALSE;
+	}
+	if (write(bitmap->fd, bitmap->buf, BUFSIZE_BITMAP)
+	    != BUFSIZE_BITMAP) {
+		ERRMSG("Can't write the bitmap(%s). %s\n",
+		    bitmap->file_name, strerror(errno));
+		return FALSE;
+	}
+	return TRUE;
+}
+
+
+int
 set_bitmap(struct dump_bitmap *bitmap, unsigned long long pfn,
     int val)
 {
@@ -3317,20 +3345,11 @@ set_bitmap(struct dump_bitmap *bitmap, unsigned long long pfn,
 	old_offset = bitmap->offset + BUFSIZE_BITMAP * bitmap->no_block;
 	new_offset = bitmap->offset + BUFSIZE_BITMAP * (pfn / PFN_BUFBITMAP);
 
-	if (0 <= bitmap->no_block && old_offset != new_offset) {
-		if (lseek(bitmap->fd, old_offset, SEEK_SET) < 0 ) {
-			ERRMSG("Can't seek the bitmap(%s). %s\n",
-			    bitmap->file_name, strerror(errno));
-			return FALSE;
-		}
-		if (write(bitmap->fd, bitmap->buf, BUFSIZE_BITMAP)
-		    != BUFSIZE_BITMAP) {
-			ERRMSG("Can't write the bitmap(%s). %s\n",
-			    bitmap->file_name, strerror(errno));
+	if (old_offset != new_offset) {
+		if (!sync_bitmap(bitmap)) {
+			ERRMSG("Can't sync bitmap\n");
 			return FALSE;
 		}
-	}
-	if (old_offset != new_offset) {
 		if (lseek(bitmap->fd, new_offset, SEEK_SET) < 0 ) {
 			ERRMSG("Can't seek the bitmap(%s). %s\n",
 			    bitmap->file_name, strerror(errno));
@@ -3386,33 +3405,6 @@ set_bitmap_cyclic(char *bitmap, unsigned long long pfn, int val, struct cycle *c
 }
 
 int
-sync_bitmap(struct dump_bitmap *bitmap)
-{
-	off_t offset;
-	offset = bitmap->offset + BUFSIZE_BITMAP * bitmap->no_block;
-
-	/*
-	 * The bitmap buffer is not dirty, and it is not necessary
-	 * to write out it.
-	 */
-	if (bitmap->no_block < 0)
-		return TRUE;
-
-	if (lseek(bitmap->fd, offset, SEEK_SET) < 0 ) {
-		ERRMSG("Can't seek the bitmap(%s). %s\n",
-		    bitmap->file_name, strerror(errno));
-		return FALSE;
-	}
-	if (write(bitmap->fd, bitmap->buf, BUFSIZE_BITMAP)
-	    != BUFSIZE_BITMAP) {
-		ERRMSG("Can't write the bitmap(%s). %s\n",
-		    bitmap->file_name, strerror(errno));
-		return FALSE;
-	}
-	return TRUE;
-}
-
-int
 sync_1st_bitmap(void)
 {
 	return sync_bitmap(info->bitmap1);
-- 
1.8.4


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

  reply	other threads:[~2014-04-24  9:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-14  6:15 [PATCH] makedumpfile: code cleanup: set_bitmap Wang Nan
2014-04-21  7:33 ` Atsushi Kumagai
2014-04-24  9:11   ` Wang Nan [this message]
2014-04-24  9:28     ` [PATCH v2] " Petr Tesarik
2014-04-25  5:25       ` Wang Nan
2014-04-25  8:03         ` Petr Tesarik
2014-04-26  4:31           ` Wang Nan
2014-04-28  7:27             ` Atsushi Kumagai

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=1398330673-23016-1-git-send-email-wangnan0@huawei.com \
    --to=wangnan0@huawei.com \
    --cc=hui.geng@huawei.com \
    --cc=kexec@lists.infradead.org \
    --cc=kumagai-atsushi@mxc.nes.nec.co.jp \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.