From: Sage Weil Date: Wed, 8 Jun 2011 05:09:24 +0000 (-0700) Subject: qa: test_sync_io X-Git-Tag: v0.30~105 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e2c808aea97ced6e9a55b143116b66d344f72c0b;p=ceph.git qa: test_sync_io Currently only tests the read path for O_DIRECT and sync (if the ioctl is in place). Also currently crashes the kclient with read_direct buf_align 0 offset 4190720 len 4096 Signed-off-by: Sage Weil --- diff --git a/src/test/test_sync_io.c b/src/test/test_sync_io.c new file mode 100644 index 000000000000..c5191e834cc3 --- /dev/null +++ b/src/test/test_sync_io.c @@ -0,0 +1,94 @@ + +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include + +//#include "../client/ioctl.h" + +#include +#include +#define CEPH_IOCTL_MAGIC 0x97 +#define CEPH_IOC_SYNCIO _IO(CEPH_IOCTL_MAGIC, 5) + +void write_pattern() +{ + printf("writing pattern\n"); + + int fd = open("foo", O_CREAT|O_WRONLY, 0644); + uint64_t i; + + for (i=0; i<1048576 * sizeof(i); i += sizeof(i)) { + write(fd, &i, sizeof(i)); + } + + close(fd); +} + +int verify_pattern(char *buf, size_t len, uint64_t off) +{ + size_t i; + + for (i = 0; i < len; i += sizeof(uint64_t)) { + uint64_t expected = i + off; + uint64_t actual = *(uint64_t*)(buf + i); + if (expected != actual) { + printf("error: offset %llu had %llu\n", expected, actual); + return -1; + } + } + return 0; +} + +int read_direct(int buf_align, uint64_t offset, int len) +{ + printf("read_direct buf_align %d offset %llu len %d\n", buf_align, offset, len); + int fd = open("foo", O_RDONLY|O_DIRECT); + void *rawbuf; + posix_memalign(&rawbuf, 4096, len + buf_align); + void *buf = (char *)rawbuf + buf_align; + pread(fd, buf, len, offset); + close(fd); + int r = verify_pattern(buf, len, offset); + free(rawbuf); + return r; +} + +int read_sync(int buf_align, uint64_t offset, int len) +{ + printf("read_sync buf_align %d offset %llu len %d\n", buf_align, offset, len); + int fd = open("foo", O_RDONLY); + ioctl(fd, CEPH_IOC_SYNCIO); + void *rawbuf; + posix_memalign(&rawbuf, 4096, len + buf_align); + void *buf = (char *)rawbuf + buf_align; + pread(fd, buf, len, offset); + close(fd); + int r = verify_pattern(buf, len, offset); + free(rawbuf); + return r; +} + +int main(int argc, char **argv) +{ + char *buf; + int fd; + uint64_t i, j, k; + + write_pattern(); + + for (i = 0; i < 4096; i += 512) + for (j = 4*1024*1024 - 4096; j < 4*1024*1024 + 4096; j += 512) + for (k = 1024; k <= 16384; k *= 2) { + read_direct(i, j, k); + read_sync(i, j, k); + } + + return 0; +}