9 // not correctly in the headers yet!!
12 #define O_DIRECT 040000 /* direct disk access hint */
15 #define BLOCKSIZE 4096
16 #define CERROR(fmt, arg...) fprintf(stderr, fmt, ## arg)
17 #define __u64 long long
18 #define LASSERT(v) do {} while(0)
19 #define HTON__u64(v) (v)
23 #define LPDS sizeof(__u64)
24 int page_debug_setup(void *addr, int len, __u64 off, __u64 id)
30 memcpy(addr, (char *)&off, LPDS);
31 memcpy(addr + LPDS, (char *)&id, LPDS);
33 addr += len - LPDS - LPDS;
34 memcpy(addr, (char *)&off, LPDS);
35 memcpy(addr + LPDS, (char *)&id, LPDS);
40 int page_debug_check(char *who, void *addr, int end, __u64 off, __u64 id)
47 ne_off = HTON__u64(off);
49 if (memcmp(addr, (char *)&ne_off, LPDS)) {
50 CERROR("%s: for offset "LPU64" off: "LPX64" != "LPX64"\n",
51 who, off, *(__u64 *)addr, ne_off);
54 if (memcmp(addr + LPDS, (char *)&id, LPDS)) {
55 CERROR("%s: for offset "LPU64" id: "LPX64" != "LPX64"\n",
56 who, off, *(__u64 *)(addr + LPDS), id);
60 addr += end - LPDS - LPDS;
61 if (memcmp(addr, (char *)&ne_off, LPDS)) {
62 CERROR("%s: for offset "LPU64" end off: "LPX64" != "LPX64"\n",
63 who, off, *(__u64 *)addr, ne_off);
66 if (memcmp(addr + LPDS, (char *)&id, LPDS)) {
67 CERROR("%s: for offset "LPU64" end id: "LPX64" != "LPX64"\n",
68 who, off, *(__u64 *)(addr + LPDS), id);
76 int main(int argc, char **argv)
82 long long end, offset;
86 if (argc < 4 || argc > 5) {
88 "usage: %s file pages_per_vec count [objid]\n",
93 pg_vec = strtoul(argv[2], 0, 0);
94 count = strtoul(argv[3], 0, 0);
95 len = pg_vec * BLOCKSIZE;
96 end = (long long)count * len;
97 printf("directio on %s for %ldx%ld pages \n", argv[1], count, pg_vec);
99 buf = mmap(0, len, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, 0, 0);
101 fprintf(stderr, "No memory %s\n", strerror(errno));
105 fd = open(argv[1], O_DIRECT | O_RDWR | O_CREAT);
107 fprintf(stderr, "Cannot open %s: %s\n", argv[1],
112 for (offset = 0; offset < end; offset += len) {
115 for (i = 0; i < len; i += BLOCKSIZE)
116 page_debug_setup(buf + i, BLOCKSIZE, offset + i, objid);
118 rc = write(fd, buf, len);
120 for (i = 0; i < len; i += BLOCKSIZE) {
121 if (page_debug_check("write", buf + i, BLOCKSIZE,
127 fprintf(stderr, "Write error: %s, rc %d\n",
128 strerror(errno), rc);
133 if ( lseek(fd, 0, SEEK_SET) != 0 ) {
134 fprintf(stderr, "Cannot seek %s\n", strerror(errno));
138 for (offset = 0; offset < end; offset += len) {
141 rc = read(fd, buf, len);
143 fprintf(stderr, "Read error: %s, rc %d\n",
144 strerror(errno), rc);
148 for (i = 0; i < len; i += BLOCKSIZE) {
149 if (page_debug_check("read", buf + i, BLOCKSIZE,