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 cpu_to_le64(v) (v)
21 #define le64_to_cpu(v) (v)
32 #define LPDS sizeof(__u64)
33 int page_debug_setup(void *addr, int len, __u64 off, __u64 id)
35 off = cpu_to_le64(off);
37 memcpy(addr, (char *)&off, LPDS);
38 memcpy(addr + LPDS, (char *)&id, LPDS);
40 addr += len - LPDS - LPDS;
41 memcpy(addr, (char *)&off, LPDS);
42 memcpy(addr + LPDS, (char *)&id, LPDS);
47 int page_debug_check(char *who, void *addr, int size, __u64 off, __u64 id)
52 ne_off = le64_to_cpu(off);
54 if (memcmp(addr, (char *)&ne_off, LPDS)) {
55 CERROR("%s: for offset "LPU64" off: "LPX64" != "LPX64"\n",
56 who, off, *(__u64 *)addr, ne_off);
59 if (memcmp(addr + LPDS, (char *)&id, LPDS)) {
60 CERROR("%s: for offset "LPU64" id: "LPX64" != "LPX64"\n",
61 who, off, *(__u64 *)(addr + LPDS), id);
65 addr += size - LPDS - LPDS;
66 if (memcmp(addr, (char *)&ne_off, LPDS)) {
67 CERROR("%s: for offset "LPU64" end off: "LPX64" != "LPX64"\n",
68 who, off, *(__u64 *)addr, ne_off);
71 if (memcmp(addr + LPDS, (char *)&id, LPDS)) {
72 CERROR("%s: for offset "LPU64" end id: "LPX64" != "LPX64"\n",
73 who, off, *(__u64 *)(addr + LPDS), id);
81 void usage(char *prog)
84 "usage: %s file count [[d]{r|w|rw} [pages_per_vec [objid]]]\n",
89 int main(int argc, char **argv)
93 long long count, last, offset;
102 if (argc < 3 || argc > 6)
105 count = strtoull(argv[2], &end, 0);
107 fprintf(stderr, "%s: invalid count '%s'\n", argv[0], argv[2]);
111 if (strchr(argv[3], 'r')) {
115 if (strchr(argv[3], 'w')) {
117 flags = O_RDWR | O_CREAT;
119 if (strchr(argv[3], 'd')) {
126 flags = O_RDWR | O_CREAT | O_DIRECT;
130 pg_vec = strtoul(argv[4], &end, 0);
132 fprintf(stderr, "%s: invalid pages_per_vec '%s'\n",
139 objid = strtoull(argv[5], &end, 0);
141 fprintf(stderr, "%s: invalid objid '%s'\n",
147 printf("%s: %s on %s(objid "LPX64") for "LPU64"x%ld pages \n",
148 argv[0], flags & O_DIRECT ? "directio" : "i/o",
149 argv[1], objid, count, pg_vec);
151 fd = open(argv[1], flags | O_LARGEFILE);
153 fprintf(stderr, "%s: cannot open %s: %s\n", argv[0],
154 argv[1], strerror(errno));
160 fprintf(stderr, "%s: cannot stat %s: %s\n", argv[0],
161 argv[1], strerror(errno));
165 len = pg_vec * st.st_blksize;
166 last = (long long)count * len;
168 buf = mmap(0, len, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, 0, 0);
170 fprintf(stderr, "%s: no buffer memory %s\n",
171 argv[0], strerror(errno));
175 for (offset = 0; offset < last && cmd & WRITE; offset += len) {
178 for (i = 0; i < len; i += st.st_blksize)
179 page_debug_setup(buf + i, st.st_blksize, offset + i,
182 rc = write(fd, buf, len);
184 for (i = 0; i < len; i += st.st_blksize) {
185 if (page_debug_check("write", buf + i, st.st_blksize,
191 fprintf(stderr, "%s: write error: %s, rc %d != %ld\n",
192 argv[0], strerror(errno), rc, len);
197 if (lseek(fd, 0, SEEK_SET) != 0) {
198 fprintf(stderr, "%s: cannot seek %s\n",
199 argv[0], strerror(errno));
203 for (offset = 0; offset < last && cmd & READ; offset += len) {
206 rc = read(fd, buf, len);
208 fprintf(stderr, "%s: read error: %s, rc %d != %ld\n",
209 argv[0], strerror(errno), rc, len);
213 for (i = 0; i < len; i += st.st_blksize) {
214 if (page_debug_check("read", buf + i, st.st_blksize,