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;
99 objid = strtoul(argv[4], 0, 0);
101 printf("directio on %s(%ld) for %ldx%ld pages \n",
102 argv[1], objid, count, pg_vec);
104 buf = mmap(0, len, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, 0, 0);
106 fprintf(stderr, "No memory %s\n", strerror(errno));
110 fd = open(argv[1], O_DIRECT | O_RDWR | O_CREAT);
112 fprintf(stderr, "Cannot open %s: %s\n", argv[1],
117 for (offset = 0; offset < end; offset += len) {
120 for (i = 0; i < len; i += BLOCKSIZE)
121 page_debug_setup(buf + i, BLOCKSIZE, offset + i, objid);
123 rc = write(fd, buf, len);
125 for (i = 0; i < len; i += BLOCKSIZE) {
126 if (page_debug_check("write", buf + i, BLOCKSIZE,
132 fprintf(stderr, "Write error: %s, rc %d\n",
133 strerror(errno), rc);
138 if ( lseek(fd, 0, SEEK_SET) != 0 ) {
139 fprintf(stderr, "Cannot seek %s\n", strerror(errno));
143 for (offset = 0; offset < end; offset += len) {
146 rc = read(fd, buf, len);
148 fprintf(stderr, "Read error: %s, rc %d\n",
149 strerror(errno), rc);
153 for (i = 0; i < len; i += BLOCKSIZE) {
154 if (page_debug_check("read", buf + i, BLOCKSIZE,