summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Bostic <keith.bostic@mongodb.com>2016-07-22 16:16:32 -0400
committerGitHub <noreply@github.com>2016-07-22 16:16:32 -0400
commit898a4e682e3ccef8feaae10d0cb35eed3a465b56 (patch)
tree9f8410a246247a9aee527245df10b5849ab9a156
parentf58dd0479c2f32fa94e915522ecb6d0dbe28708e (diff)
downloadmongo-898a4e682e3ccef8feaae10d0cb35eed3a465b56.tar.gz
WT-2737 page scrubbing: more fixes (#2901)
Rework 8bfe54b: we have to swap the page-header before calculating the checksum and I don't want to leave the caller's data changed in the case of an error. I also don't want to rework all the error handling in the __wt_block_write_off() function, so wrap the block-write functionality in a new function that only handles page-header swapping.
-rw-r--r--src/block/block_write.c44
1 files changed, 31 insertions, 13 deletions
diff --git a/src/block/block_write.c b/src/block/block_write.c
index 8a77641e1f3..30d06e6259a 100644
--- a/src/block/block_write.c
+++ b/src/block/block_write.c
@@ -228,12 +228,12 @@ __wt_block_write(WT_SESSION_IMPL *session, WT_BLOCK *block, WT_ITEM *buf,
}
/*
- * __wt_block_write_off --
+ * __block_write_off --
* Write a buffer into a block, returning the block's offset, size and
* checksum.
*/
-int
-__wt_block_write_off(WT_SESSION_IMPL *session, WT_BLOCK *block,
+static int
+__block_write_off(WT_SESSION_IMPL *session, WT_BLOCK *block,
WT_ITEM *buf, wt_off_t *offsetp, uint32_t *sizep, uint32_t *cksump,
bool data_cksum, bool checkpoint_io, bool caller_locked)
{
@@ -339,16 +339,9 @@ __wt_block_write_off(WT_SESSION_IMPL *session, WT_BLOCK *block,
__wt_spin_unlock(session, &block->live_lock);
WT_RET(ret);
- /*
- * Ensure the page header is in little endian order; this doesn't belong
- * here, but it's the best place to catch all callers. After the write,
- * swap values back to native order so callers never see anything other
- * than their original content.
- */
- __wt_page_header_byteswap(buf->mem);
- ret = __wt_write(session, fh, offset, align_size, buf->mem);
- __wt_page_header_byteswap(buf->mem);
- if (ret != 0) {
+ /* Write the block. */
+ if ((ret =
+ __wt_write(session, fh, offset, align_size, buf->mem)) != 0) {
if (!caller_locked)
__wt_spin_lock(session, &block->live_lock);
WT_TRET(__wt_block_off_free(
@@ -395,3 +388,28 @@ __wt_block_write_off(WT_SESSION_IMPL *session, WT_BLOCK *block,
return (0);
}
+
+/*
+ * __wt_block_write_off --
+ * Write a buffer into a block, returning the block's offset, size and
+ * checksum.
+ */
+int
+__wt_block_write_off(WT_SESSION_IMPL *session, WT_BLOCK *block,
+ WT_ITEM *buf, wt_off_t *offsetp, uint32_t *sizep, uint32_t *cksump,
+ bool data_cksum, bool checkpoint_io, bool caller_locked)
+{
+ WT_DECL_RET;
+
+ /*
+ * Ensure the page header is in little endian order; this doesn't belong
+ * here, but it's the best place to catch all callers. After the write,
+ * swap values back to native order so callers never see anything other
+ * than their original content.
+ */
+ __wt_page_header_byteswap(buf->mem);
+ ret = __block_write_off(session, block, buf,
+ offsetp, sizep, cksump, data_cksum, checkpoint_io, caller_locked);
+ __wt_page_header_byteswap(buf->mem);
+ return (ret);
+}