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)
26 #define LPDS sizeof(__u64)
27 int page_debug_setup(void *addr, int len, __u64 off, __u64 id)
33 memcpy(addr, (char *)&off, LPDS);
34 memcpy(addr + LPDS, (char *)&id, LPDS);
36 addr += len - LPDS - LPDS;
37 memcpy(addr, (char *)&off, LPDS);
38 memcpy(addr + LPDS, (char *)&id, LPDS);
43 int page_debug_check(char *who, void *addr, int end, __u64 off, __u64 id)
50 ne_off = HTON__u64(off);
52 if (memcmp(addr, (char *)&ne_off, LPDS)) {
53 CERROR("%s: for offset "LPU64" off: "LPX64" != "LPX64"\n",
54 who, off, *(__u64 *)addr, ne_off);
57 if (memcmp(addr + LPDS, (char *)&id, LPDS)) {
58 CERROR("%s: for offset "LPU64" id: "LPX64" != "LPX64"\n",
59 who, off, *(__u64 *)(addr + LPDS), id);
63 addr += end - LPDS - LPDS;
64 if (memcmp(addr, (char *)&ne_off, LPDS)) {
65 CERROR("%s: for offset "LPU64" end off: "LPX64" != "LPX64"\n",
66 who, off, *(__u64 *)addr, ne_off);
69 if (memcmp(addr + LPDS, (char *)&id, LPDS)) {
70 CERROR("%s: for offset "LPU64" end id: "LPX64" != "LPX64"\n",
71 who, off, *(__u64 *)(addr + LPDS), id);
79 void usage(char *prog)
81 fprintf(stderr, "usage: %s file count [[d]{r|w|rw} [pages_per_vec [objid]]]\n",
86 int main(int argc, char **argv)
92 long long end, offset;
94 int flags = O_RDWR | O_CREAT;
98 if (argc < 3 || argc > 6)
101 count = strtoul(argv[2], 0, 0);
103 if (strchr(argv[3], 'r')) {
107 if (strchr(argv[3], 'w')) {
111 if (strchr(argv[3], 'd')) {
113 printf("directing\n");
118 printf("cmd = %x, flags = %x\n", cmd, flags);
121 pg_vec = strtoul(argv[4], 0, 0);
122 len = pg_vec * BLOCKSIZE;
123 end = (long long)count * len;
126 objid = strtoull(argv[5], 0, 0);
127 printf("objid %s = 0x%Lx\n", argv[5], objid);
130 printf("%s: %s on %s(objid 0x"LPX64") for %ldx%ld pages \n",
131 argv[0], flags & O_DIRECT ? "directio" : "i/o",
132 argv[1], objid, count, pg_vec);
134 buf = mmap(0, len, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, 0, 0);
136 fprintf(stderr, "%s: no buffer memory %s\n",
137 argv[0], strerror(errno));
141 fd = open(argv[1], flags);
143 fprintf(stderr, "%s: cannot open %s: %s\n", argv[1],
144 argv[0], strerror(errno));
148 for (offset = 0; offset < end && cmd & WRITE; offset += len) {
151 for (i = 0; i < len; i += BLOCKSIZE)
152 page_debug_setup(buf + i, BLOCKSIZE, offset + i, objid);
154 rc = write(fd, buf, len);
156 for (i = 0; i < len; i += BLOCKSIZE) {
157 if (page_debug_check("write", buf + i, BLOCKSIZE,
163 fprintf(stderr, "%s: write error: %s, rc %d\n",
164 argv[0], strerror(errno), rc);
169 if (lseek(fd, 0, SEEK_SET) != 0) {
170 fprintf(stderr, "%s: cannot seek %s\n",
171 argv[0], strerror(errno));
175 for (offset = 0; offset < end && cmd && READ; offset += len) {
178 rc = read(fd, buf, len);
180 fprintf(stderr, "%s: read error: %s, rc %d\n",
181 argv[0], strerror(errno), rc);
185 for (i = 0; i < len; i += BLOCKSIZE) {
186 if (page_debug_check("read", buf + i, BLOCKSIZE,