libext2fs: move the alignment field from unix_io to the io_manager
The align field which indicated the required data alignment of data
buffers was stored in a field specific to the unix_io manager. Move
it to the top-level io_channel structure so it can be better
generalized.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
diff --git a/lib/ext2fs/ext2_io.h b/lib/ext2fs/ext2_io.h
index bcc2f87..95b8de3 100644
--- a/lib/ext2fs/ext2_io.h
+++ b/lib/ext2fs/ext2_io.h
@@ -58,6 +58,7 @@
long reserved[14];
void *private_data;
void *app_data;
+ int align;
};
struct struct_io_stats {
diff --git a/lib/ext2fs/test_io.c b/lib/ext2fs/test_io.c
index f67f6ae..7d3cdfe 100644
--- a/lib/ext2fs/test_io.c
+++ b/lib/ext2fs/test_io.c
@@ -247,6 +247,9 @@
if ((value = safe_getenv("TEST_IO_WRITE_ABORT")) != NULL)
data->write_abort_count = strtoul(value, NULL, 0);
+ if (data->real)
+ io->align = data->real->align;
+
*channel = io;
return 0;
@@ -292,8 +295,10 @@
data = (struct test_private_data *) channel->private_data;
EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_TEST_IO_CHANNEL);
- if (data->real)
+ if (data->real) {
retval = io_channel_set_blksize(data->real, blksize);
+ channel->align = data->real->align;
+ }
if (data->set_blksize)
data->set_blksize(blksize, retval);
if (data->flags & TEST_FLAG_SET_BLKSIZE)
diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c
index da3f8fd..3269392 100644
--- a/lib/ext2fs/unix_io.c
+++ b/lib/ext2fs/unix_io.c
@@ -180,8 +180,9 @@
retval = errno ? errno : EXT2_ET_LLSEEK_FAILED;
goto error_out;
}
- if ((data->align == 0) ||
- ((IS_ALIGNED(buf, data->align)) && IS_ALIGNED(size, data->align))) {
+ if ((channel->align == 0) ||
+ (IS_ALIGNED(buf, channel->align) &&
+ IS_ALIGNED(size, channel->align))) {
actual = read(data->dev, buf, size);
if (actual != size) {
short_read:
@@ -250,8 +251,9 @@
goto error_out;
}
- if ((data->align == 0) ||
- ((IS_ALIGNED(buf, data->align)) && IS_ALIGNED(size, data->align))) {
+ if ((channel->align == 0) ||
+ (IS_ALIGNED(buf, channel->align) &&
+ IS_ALIGNED(size, channel->align))) {
actual = write(data->dev, buf, size);
if (actual != size) {
short_write:
@@ -319,14 +321,15 @@
if (cache->buf)
ext2fs_free_mem(&cache->buf);
retval = ext2fs_get_memalign(channel->block_size,
- data->align, &cache->buf);
+ channel->align, &cache->buf);
if (retval)
return retval;
}
- if (data->align) {
+ if (channel->align) {
if (data->bounce)
ext2fs_free_mem(&data->bounce);
- retval = ext2fs_get_memalign(channel->block_size, data->align,
+ retval = ext2fs_get_memalign(channel->block_size,
+ channel->align,
&data->bounce);
}
return retval;
@@ -518,8 +521,8 @@
#ifdef BLKSSZGET
if (flags & IO_FLAG_DIRECT_IO) {
- if (ioctl(data->dev, BLKSSZGET, &data->align) != 0)
- data->align = io->block_size;
+ if (ioctl(data->dev, BLKSSZGET, &io->align) != 0)
+ io->align = io->block_size;
}
#endif
@@ -534,7 +537,7 @@
* Some operating systems require that the buffers be aligned,
* regardless of O_DIRECT
*/
- data->align = 512;
+ io->align = 512;
#endif
@@ -810,7 +813,7 @@
data = (struct unix_private_data *) channel->private_data;
EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL);
- if (data->align != 0) {
+ if (channel->align != 0) {
#ifdef ALIGN_DEBUG
printf("unix_write_byte: O_DIRECT fallback\n");
#endif