1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

dev_io: fix writes for unaligned buffers

Actually the removed code is necessary - since not all writes are
getting alligned buffer - older compilers seems to be not able
to create 4K aligned buffers on stack - this the aligning code still
need to be present for write path.
This commit is contained in:
Zdenek Kabelac 2018-01-23 13:36:12 +01:00
parent 102926ed9f
commit a1cfef9f26

View File

@ -153,12 +153,10 @@ static int _io(struct device_buffer *devbuf, unsigned ioflags)
return 0; return 0;
} }
#ifndef DEBUG_MEM
if (!devbuf->buf && !(devbuf->malloc_address = devbuf->buf = dm_malloc_aligned((size_t) devbuf->where.size, 0))) { if (!devbuf->buf && !(devbuf->malloc_address = devbuf->buf = dm_malloc_aligned((size_t) devbuf->where.size, 0))) {
log_error("Bounce buffer malloc failed"); log_error("Bounce buffer malloc failed");
return 0; return 0;
} }
#endif
log_debug_io("%s %s(fd %d):%8" PRIu64 " bytes (sync) at %" PRIu64 "%s (for %s)", log_debug_io("%s %s(fd %d):%8" PRIu64 " bytes (sync) at %" PRIu64 "%s (for %s)",
devbuf->write ? "Write" : "Read ", dev_name(where->dev), fd, devbuf->write ? "Write" : "Read ", dev_name(where->dev), fd,
@ -316,9 +314,22 @@ static int _aligned_io(struct device_area *where, char *write_buffer,
if (should_write && !buffer_was_widened && !((uintptr_t) write_buffer & mask)) if (should_write && !buffer_was_widened && !((uintptr_t) write_buffer & mask))
/* Perform the I/O directly. */ /* Perform the I/O directly. */
devbuf->buf = write_buffer; devbuf->buf = write_buffer;
else else if (!should_write)
/* Postpone buffer allocation until we're about to issue the I/O */ /* Postpone buffer allocation until we're about to issue the I/O */
devbuf->buf = NULL; devbuf->buf = NULL;
else {
/* Allocate a bounce buffer with an extra block */
if (!(devbuf->malloc_address = devbuf->buf = dm_malloc((size_t) devbuf->where.size + block_size))) {
log_error("Bounce buffer malloc failed");
return 0;
}
/*
* Realign start of bounce buffer (using the extra sector)
*/
if (((uintptr_t) devbuf->buf) & mask)
devbuf->buf = (char *) ((((uintptr_t) devbuf->buf) + mask) & ~mask);
}
devbuf->write = 0; devbuf->write = 0;