public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: xfs@oss.sgi.com
Subject: [PATCH 1/5] metadump: sanitise write_buf/index return values
Date: Thu, 23 Jan 2014 21:23:51 +1100	[thread overview]
Message-ID: <1390472635-17225-2-git-send-email-david@fromorbit.com> (raw)
In-Reply-To: <1390472635-17225-1-git-send-email-david@fromorbit.com>

From: Dave Chinner <dchinner@redhat.com>

Write_buf/write_index use confusing boolean values for return,
meaning that it's hard to tell what the correct error return is
supposed to be.  Convert them to return zero on success or a
negative errno otherwise so that it's clear what the error case is.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
---
 db/metadump.c | 34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/db/metadump.c b/db/metadump.c
index 117dc42..4104fcb 100644
--- a/db/metadump.c
+++ b/db/metadump.c
@@ -145,6 +145,8 @@ print_progress(const char *fmt, ...)
  * even if the dump is exactly aligned, the last index will be full of
  * zeros. If the last index entry is non-zero, the dump is incomplete.
  * Correspondingly, the last chunk will have a count < num_indicies.
+ *
+ * Return 0 for success, -1 for failure.
  */
 
 static int
@@ -156,12 +158,12 @@ write_index(void)
 	metablock->mb_count = cpu_to_be16(cur_index);
 	if (fwrite(metablock, (cur_index + 1) << BBSHIFT, 1, outf) != 1) {
 		print_warning("error writing to file: %s", strerror(errno));
-		return 0;
+		return -errno;
 	}
 
 	memset(block_index, 0, num_indicies * sizeof(__be64));
 	cur_index = 0;
-	return 1;
+	return 0;
 }
 
 static int
@@ -171,6 +173,7 @@ write_buf(
 	char		*data;
 	__int64_t	off;
 	int		i;
+	int		ret;
 
 	/*
 	 * Run the write verifier to recalculate the buffer CRCs and check
@@ -184,7 +187,7 @@ write_buf(
 	_("%s: write verifer failed on bno 0x%llx/0x%x\n"),
 				__func__, (long long)buf->bp->b_bn,
 				buf->bp->b_bcount);
-			return buf->bp->b_error;
+			return -buf->bp->b_error;
 		}
 	}
 
@@ -194,11 +197,12 @@ write_buf(
 		block_index[cur_index] = cpu_to_be64(off);
 		memcpy(&block_buffer[cur_index << BBSHIFT], data, BBSIZE);
 		if (++cur_index == num_indicies) {
-			if (!write_index())
-				return 0;
+			ret = write_index();
+			if (ret)
+				return ret;
 		}
 	}
-	return !seenint();
+	return seenint() ? -EINTR : 0;
 }
 
 
@@ -227,7 +231,7 @@ scan_btree(
 		rval = !stop_on_read_error;
 		goto pop_out;
 	}
-	if (!write_buf(iocur_top))
+	if (write_buf(iocur_top))
 		goto pop_out;
 
 	if (!(*func)(iocur_top->data, agno, agbno, level - 1, btype, arg))
@@ -1439,7 +1443,7 @@ process_bmbt_reclist(
 
 				default: ;
 			    }
-			if (!write_buf(iocur_top)) {
+			if (write_buf(iocur_top)) {
 				pop_cur();
 				return 0;
 			}
@@ -1748,7 +1752,7 @@ copy_inode_chunk(
 		xfs_dinode_calc_crc(mp, dip);
 	}
 skip_processing:
-	if (!write_buf(iocur_top))
+	if (write_buf(iocur_top))
 		goto pop_out;
 
 	inodes_copied += XFS_INODES_PER_CHUNK;
@@ -1866,7 +1870,7 @@ scan_ag(
 		if (stop_on_read_error)
 			goto pop_out;
 	} else {
-		if (!write_buf(iocur_top))
+		if (write_buf(iocur_top))
 			goto pop_out;
 	}
 
@@ -1881,7 +1885,7 @@ scan_ag(
 		if (stop_on_read_error)
 			goto pop_out;
 	} else {
-		if (!write_buf(iocur_top))
+		if (write_buf(iocur_top))
 			goto pop_out;
 	}
 
@@ -1896,7 +1900,7 @@ scan_ag(
 		if (stop_on_read_error)
 			goto pop_out;
 	} else {
-		if (!write_buf(iocur_top))
+		if (write_buf(iocur_top))
 			goto pop_out;
 	}
 
@@ -1910,7 +1914,7 @@ scan_ag(
 		if (stop_on_read_error)
 			goto pop_out;
 	} else {
-		if (!write_buf(iocur_top))
+		if (write_buf(iocur_top))
 			goto pop_out;
 	}
 
@@ -2015,7 +2019,7 @@ copy_log(void)
 		print_warning("cannot read log");
 		return !stop_on_read_error;
 	}
-	return write_buf(iocur_top);
+	return !write_buf(iocur_top);
 }
 
 static int
@@ -2121,7 +2125,7 @@ metadump_f(
 
 	/* write the remaining index */
 	if (!exitcode)
-		exitcode = !write_index();
+		exitcode = write_index() < 0;
 
 	if (progress_since_warning)
 		fputc('\n', (outf == stdout) ? stderr : stdout);
-- 
1.8.4.rc3

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

  reply	other threads:[~2014-01-23 10:24 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-23 10:23 [PATCH 0/5] metadump: discontiguous directory block support Dave Chinner
2014-01-23 10:23 ` Dave Chinner [this message]
2014-02-03 11:08   ` [PATCH 1/5] metadump: sanitise write_buf/index return values Christoph Hellwig
2014-02-13 19:30   ` Mark Tinguely
2014-02-14  2:20     ` Dave Chinner
2014-02-14 19:51       ` Mark Tinguely
2014-02-14 20:54         ` Mark Tinguely
2014-01-23 10:23 ` [PATCH 2/5] metadump: support writing discontiguous io cursors Dave Chinner
2014-02-03 15:06   ` Christoph Hellwig
2014-01-23 10:23 ` [PATCH 3/5] metadump: separate single block objects from multiblock objects Dave Chinner
2014-02-03 15:09   ` Christoph Hellwig
2014-02-03 22:19     ` Dave Chinner
2014-01-23 10:23 ` [PATCH 4/5] metadump: walk single fsb objects a block at a time Dave Chinner
2014-02-03 15:43   ` Christoph Hellwig
2014-01-23 10:23 ` [PATCH 5/5] metadump: fully support discontiguous directory blocks Dave Chinner
2014-02-03 21:15   ` Christoph Hellwig
2014-02-03  3:19 ` [PATCH 0/5] metadump: discontiguous directory block support Dave Chinner

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=1390472635-17225-2-git-send-email-david@fromorbit.com \
    --to=david@fromorbit.com \
    --cc=xfs@oss.sgi.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