11 // not correctly in the headers yet!!
14 #define O_DIRECT 040000 /* direct disk access hint */
17 #define CERROR(fmt, arg...) fprintf(stderr, fmt, ## arg)
19 #define __u64 long long
20 #define HTON__u64(v) (v)
31 #define LPDS sizeof(__u64)
32 int page_debug_setup(void *addr, int len, __u64 off, __u64 id)
36 memcpy(addr, (char *)&off, LPDS);
37 memcpy(addr + LPDS, (char *)&id, LPDS);
39 addr += len - LPDS - LPDS;
40 memcpy(addr, (char *)&off, LPDS);
41 memcpy(addr + LPDS, (char *)&id, LPDS);
46 int page_debug_check(char *who, void *addr, int size, __u64 off, __u64 id)
51 ne_off = HTON__u64(off);
53 if (memcmp(addr, (char *)&ne_off, LPDS)) {
54 CERROR("%s: for offset "LPU64" off: "LPX64" != "LPX64"\n",
55 who, off, *(__u64 *)addr, ne_off);
58 if (memcmp(addr + LPDS, (char *)&id, LPDS)) {
59 CERROR("%s: for offset "LPU64" id: "LPX64" != "LPX64"\n",
60 who, off, *(__u64 *)(addr + LPDS), id);
64 addr += size - LPDS - LPDS;
65 if (memcmp(addr, (char *)&ne_off, LPDS)) {
66 CERROR("%s: for offset "LPU64" end off: "LPX64" != "LPX64"\n",
67 who, off, *(__u64 *)addr, ne_off);
70 if (memcmp(addr + LPDS, (char *)&id, LPDS)) {
71 CERROR("%s: for offset "LPU64" end id: "LPX64" != "LPX64"\n",
72 who, off, *(__u64 *)(addr + LPDS), id);
80 void usage(char *prog)
83 "usage: %s file count [[d]{r|w|rw} [pages_per_vec [objid]]]\n",
88 int main(int argc, char **argv)
92 long long count, last, offset;
101 if (argc < 3 || argc > 6)
104 count = strtoull(argv[2], &end, 0);
106 fprintf(stderr, "%s: invalid count '%s'\n", argv[0], argv[2]);
110 if (strchr(argv[3], 'r')) {
114 if (strchr(argv[3], 'w')) {
116 flags = O_RDWR | O_CREAT;
118 if (strchr(argv[3], 'd')) {
125 flags = O_RDWR | O_CREAT | O_DIRECT;
129 pg_vec = strtoul(argv[4], &end, 0);
131 fprintf(stderr, "%s: invalid pages_per_vec '%s'\n",
138 objid = strtoull(argv[5], &end, 0);
140 fprintf(stderr, "%s: invalid objid '%s'\n",
146 printf("%s: %s on %s(objid "LPX64") for "LPU64"x%ld pages \n",
147 argv[0], flags & O_DIRECT ? "directio" : "i/o",
148 argv[1], objid, count, pg_vec);
150 fd = open(argv[1], flags | O_LARGEFILE);
152 fprintf(stderr, "%s: cannot open %s: %s\n", argv[0],
153 argv[1], strerror(errno));
159 fprintf(stderr, "%s: cannot stat %s: %s\n", argv[0],
160 argv[1], strerror(errno));
164 len = pg_vec * st.st_blksize;
165 last = (long long)count * len;
167 buf = mmap(0, len, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, 0, 0);
169 fprintf(stderr, "%s: no buffer memory %s\n",
170 argv[0], strerror(errno));
174 for (offset = 0; offset < last && cmd & WRITE; offset += len) {
177 for (i = 0; i < len; i += st.st_blksize)
178 page_debug_setup(buf + i, st.st_blksize, offset + i,
181 rc = write(fd, buf, len);
183 for (i = 0; i < len; i += st.st_blksize) {
184 if (page_debug_check("write", buf + i, st.st_blksize,
190 fprintf(stderr, "%s: write error: %s, rc %d != %ld\n",
191 argv[0], strerror(errno), rc, len);
196 if (lseek(fd, 0, SEEK_SET) != 0) {
197 fprintf(stderr, "%s: cannot seek %s\n",
198 argv[0], strerror(errno));
202 for (offset = 0; offset < last && cmd && READ; offset += len) {
205 rc = read(fd, buf, len);
207 fprintf(stderr, "%s: read error: %s, rc %d != %ld\n",
208 argv[0], strerror(errno), rc, len);
212 for (i = 0; i < len; i += st.st_blksize) {
213 if (page_debug_check("read", buf + i, st.st_blksize,