1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
15 #include <liblustre.h>
16 #include <lnet/lnetctl.h>
18 #include <lustre_lib.h>
20 #include <lustre/liblustreapi.h>
26 #define ACT_READHOLE 8
31 printf("usage: rwv -f filename <-r|-w> [-a] [-z] [-d] [-v]"
32 "[-s offset] -n iovcnt SIZE1 SIZE2 SIZE3...\n");
33 printf("-a append IO (O_APPEND)\n");
34 printf("-r file read (O_RDONLY)\n");
35 printf("-w file write (O_WRONLY)\n");
36 printf("-s set the start pos of the read/write test\n");
37 printf("-z test for read hitting hole\n");
38 printf("-d create flags (O_LOV_DELAY_CREATE)\n");
39 printf("-v verify the data content of read\n");
42 int data_verify(struct iovec *iov, int iovcnt, char c)
46 for (i = 0; i < iovcnt; i++) {
47 size_t count = iov[i].iov_len;
48 char *s = iov[i].iov_base;
50 for (; count > 0; ++s, count--) {
52 printf("Data mismatch %x: %x\n", *s, c);
60 int main(int argc, char** argv)
71 unsigned long len = 0;
75 while ((c = getopt(argc, argv, "f:n:s:rwahvdz")) != -1) {
81 iovcnt = strtoul(optarg, &end, 0);
83 printf("Bad iov count: %s\n", optarg);
86 if (iovcnt > UIO_MAXIOV || iovcnt <= 0) {
87 printf("Wrong iov count\n");
93 offset = strtoull(optarg, &end, 0);
95 printf("Bad seek offset: %s\n", optarg);
109 flags |= O_LOV_DELAY_CREATE;
124 if (act == ACT_NONE) {
129 if ((act & ACT_READ) && (act & ACT_WRITE)) {
130 printf("Read and write test should be exclusive\n");
134 if (argc - optind < iovcnt) {
135 printf("Not enough parameters for iov size\n");
139 iov = (struct iovec *)malloc(iovcnt * sizeof(struct iovec));
141 printf("No memory %s\n", strerror(errno));
145 for (c = 0; c < iovcnt; c++) {
146 struct iovec *iv = &iov[c];
148 iv->iov_len = strtoul(argv[optind++], &end, 0);
150 printf("Error iov size\n");
153 iv->iov_base = mmap(NULL, iv->iov_len, PROT_READ | PROT_WRITE,
154 MAP_PRIVATE | MAP_ANON, 0, 0);
155 if (iv->iov_base == MAP_FAILED) {
156 printf("No memory %s\n", strerror(errno));
160 memset(iv->iov_base, pad, iv->iov_len);
164 fd = open(fname, O_LARGEFILE | O_RDWR | O_CREAT | flags, 0644);
166 printf("Cannot open %s:%s\n", fname, strerror(errno));
170 if ((act & ACT_SEEK) && (lseek64(fd, offset, SEEK_SET) < 0)) {
171 printf("Cannot seek %s\n", strerror(errno));
175 if (act & ACT_WRITE) {
176 rc = writev(fd, iov, iovcnt);
178 printf("Write error: %s (rc = %d, len = %ld)\n",
179 strerror(errno), rc, len);
182 } else if (act & ACT_READ) {
183 rc = readv(fd, iov, iovcnt);
185 printf("Read error: %s rc = %d\n", strerror(errno), rc);
189 /* It should return zeroed buf if the read hits hole.*/
190 if (((act & ACT_READHOLE) || (act & ACT_VERIFY)) &&
191 data_verify(iov, iovcnt, pad))