This tests for the bug fixed by linux commit:
c3cd628.
Signed-off-by: Sage Weil <sage.weil@dreamhost.com>
direct_io_test_SOURCES = direct_io_test.c
test_sync_io_SOURCES = test_sync_io.c
+test_short_dio_read_SOURCES = test_short_dio_read.c
if WITH_DEBUG
-bin_PROGRAMS += direct_io_test test_sync_io
+bin_PROGRAMS += direct_io_test test_sync_io test_short_dio_read
endif
--- /dev/null
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdio.h>
+
+int main(int argc, char **argv)
+{
+ char buf[409600];
+ int fd = open(argv[1], O_WRONLY|O_CREAT);
+ ssize_t r;
+
+ printf("writing first 3 bytes of 10k file\n");
+ write(fd, "foo", 3);
+ ftruncate(fd, 10000);
+ fsync(fd);
+ close(fd);
+
+ printf("reading O_DIRECT\n");
+ fd = open(argv[1], O_RDONLY|O_DIRECT);
+ r = read(fd, buf, sizeof(buf));
+ close(fd);
+
+ printf("got %d\n", r);
+ if (r != 10000)
+ return 1;
+ return 0;
+}
direct_io_test
+test_short_dio_read
+
# a few test cases from henry
echo "test read from hole"
dd if=/dev/zero of=dd3 bs=1 seek=1048576 count=0