Skip to content
This repository
Browse code

Allocate "desc" buffers in heap memory so that they are correctly ali…

…gned.
  • Loading branch information...
commit eb06033573e1391822ff74fd7425b7f918a7e6e9 1 parent 97fd6ca
Michael Cahill michaelcahill authored

Showing 1 changed file with 23 additions and 12 deletions. Show diff stats Hide diff stats

  1. +23 12 src/block/block_open.c
35 src/block/block_open.c
@@ -165,10 +165,14 @@ int
165 165 __wt_desc_init(WT_SESSION_IMPL *session, WT_FH *fh)
166 166 {
167 167 WT_BLOCK_DESC *desc;
168   - uint8_t buf[WT_BLOCK_DESC_SECTOR];
  168 + WT_DECL_RET;
  169 + WT_ITEM *buf;
  170 +
  171 + /* Use a scratch buffer to get correct alignment for direct I/O. */
  172 + WT_RET(__wt_scr_alloc(session, WT_BLOCK_DESC_SECTOR, &buf));
  173 + memset(buf->mem, 0, WT_BLOCK_DESC_SECTOR);
169 174
170   - memset(buf, 0, sizeof(buf));
171   - desc = (void *)buf;
  175 + desc = buf->mem;
172 176 desc->magic = WT_BLOCK_MAGIC;
173 177 desc->majorv = WT_BLOCK_MAJOR_VERSION;
174 178 desc->minorv = WT_BLOCK_MINOR_VERSION;
@@ -177,7 +181,10 @@ __wt_desc_init(WT_SESSION_IMPL *session, WT_FH *fh)
177 181 desc->cksum = 0;
178 182 desc->cksum = __wt_cksum(desc, WT_BLOCK_DESC_SECTOR);
179 183
180   - return (__wt_write(session, fh, (off_t)0, WT_BLOCK_DESC_SECTOR, desc));
  184 + ret = __wt_write(session, fh, (off_t)0, WT_BLOCK_DESC_SECTOR, desc);
  185 +
  186 + __wt_scr_free(&buf);
  187 + return (ret);
181 188 }
182 189
183 190 /*
@@ -188,16 +195,19 @@ static int
188 195 __desc_read(WT_SESSION_IMPL *session, WT_BLOCK *block)
189 196 {
190 197 WT_BLOCK_DESC *desc;
  198 + WT_DECL_RET;
  199 + WT_ITEM *buf;
191 200 uint32_t cksum;
192   - uint8_t buf[WT_BLOCK_DESC_SECTOR];
  201 +
  202 + /* Use a scratch buffer to get correct alignment for direct I/O. */
  203 + WT_RET(__wt_scr_alloc(session, WT_BLOCK_DESC_SECTOR, &buf));
193 204
194 205 /* Read the first sector and verify the file's format. */
195   - memset(buf, 0, sizeof(buf));
196   - WT_RET(__wt_read(
197   - session, block->fh, (off_t)0, WT_BLOCK_DESC_SECTOR, buf));
  206 + WT_ERR(__wt_read(
  207 + session, block->fh, (off_t)0, WT_BLOCK_DESC_SECTOR, buf->mem));
198 208
199   - desc = (void *)buf;
200   - WT_VERBOSE_RET(session, block,
  209 + desc = buf->mem;
  210 + WT_VERBOSE_ERR(session, block,
201 211 "open: magic %" PRIu32
202 212 ", major/minor: %" PRIu32 "/%" PRIu32
203 213 ", checksum %#" PRIx32,
@@ -218,16 +228,17 @@ __desc_read(WT_SESSION_IMPL *session, WT_BLOCK *block)
218 228 desc->cksum = 0;
219 229 if (desc->magic != WT_BLOCK_MAGIC ||
220 230 cksum != __wt_cksum(desc, WT_BLOCK_DESC_SECTOR))
221   - WT_RET_MSG(session, WT_ERROR,
  231 + WT_ERR_MSG(session, WT_ERROR,
222 232 "%s does not appear to be a WiredTiger file", block->name);
223 233
224 234 if (desc->majorv > WT_BLOCK_MAJOR_VERSION ||
225 235 (desc->majorv == WT_BLOCK_MAJOR_VERSION &&
226 236 desc->minorv > WT_BLOCK_MINOR_VERSION))
227   - WT_RET_MSG(session, WT_ERROR,
  237 + WT_ERR_MSG(session, WT_ERROR,
228 238 "%s is an unsupported version of a WiredTiger file",
229 239 block->name);
230 240
  241 +err: __wt_scr_free(&buf);
231 242 return (0);
232 243 }
233 244

0 comments on commit eb06033

Please sign in to comment.
Something went wrong with that request. Please try again.