4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 021110-1307, USA
24 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
25 * Use is subject to license terms.
27 * Copyright (c) 2014, 2017, Intel Corporation.
30 * This file is part of Lustre, http://www.lustre.org/
36 #include <sys/types.h>
45 #include <lustre/lustreapi.h>
51 #define ACT_READHOLE 8
57 printf("usage: rwv -f filename <-r|-w> [-a] [-z] [-d] [-v]");
58 printf(" [-s offset] [-o[outf]] -n iovcnt SIZE1 SIZE2 SIZE3...\n");
59 printf("-a append IO (O_APPEND)\n");
60 printf("-r file read (O_RDONLY)\n");
61 printf("-w file write (O_WRONLY)\n");
62 printf("-s set the start pos of the read/write test\n");
63 printf("-z test for read hitting hole\n");
64 printf("-d create flags (O_LOV_DELAY_CREATE)\n");
65 printf("-v verify the data content of read\n");
66 printf("-o write the file content of read to an optional file\n");
69 int data_verify(struct iovec *iov, int iovcnt, char c)
73 for (i = 0; i < iovcnt; i++) {
74 size_t count = iov[i].iov_len;
75 char *s = iov[i].iov_base;
77 for (; count > 0; ++s, count--) {
79 printf("Data mismatch %x: %x\n", *s, c);
87 int main(int argc, char **argv)
99 unsigned long len = 0;
103 while ((c = getopt(argc, argv, "f:n:s:rwahvdzo::")) != -1) {
109 iovcnt = strtoul(optarg, &end, 0);
111 printf("Bad iov count: %s\n", optarg);
114 if (iovcnt > UIO_MAXIOV || iovcnt <= 0) {
115 printf("Wrong iov count\n");
121 offset = strtoull(optarg, &end, 0);
123 printf("Bad seek offset: %s\n", optarg);
129 flags |= O_WRONLY | O_CREAT;
139 flags |= O_LOV_DELAY_CREATE;
151 out_fd = open(optarg, O_WRONLY | O_CREAT, 0644);
153 out_fd = fileno(stdout);
161 if (act == ACT_NONE) {
166 if ((act & ACT_READ) && (act & ACT_WRITE)) {
167 printf("Read and write test should be exclusive\n");
171 if (act & ACT_OUTPUT && (!(act & ACT_READ) || out_fd < 0)) {
172 printf("-o not in read mode or cannot open the output file");
176 if (argc - optind < iovcnt) {
177 printf("Not enough parameters for iov size\n");
181 iov = (struct iovec *)malloc(iovcnt * sizeof(struct iovec));
183 printf("No memory %s\n", strerror(errno));
187 for (c = 0; c < iovcnt; c++) {
188 struct iovec *iv = &iov[c];
190 iv->iov_len = strtoul(argv[optind++], &end, 0);
192 printf("Error iov size\n");
196 iv->iov_base = mmap(NULL, iv->iov_len, PROT_READ | PROT_WRITE,
197 MAP_PRIVATE | MAP_ANON, 0, 0);
198 if (iv->iov_base == MAP_FAILED) {
199 printf("No memory %s\n", strerror(errno));
204 memset(iv->iov_base, pad, iv->iov_len);
208 fd = open(fname, O_LARGEFILE | flags, 0644);
210 printf("Cannot open %s:%s\n", fname, strerror(errno));
214 if ((act & ACT_SEEK) && (lseek64(fd, offset, SEEK_SET) < 0)) {
215 printf("Cannot seek %s\n", strerror(errno));
220 if (act & ACT_WRITE) {
221 rc = writev(fd, iov, iovcnt);
223 printf("Write error: %s (rc = %d, len = %ld)\n",
224 strerror(errno), rc, len);
228 } else if (act & ACT_READ) {
229 rc = readv(fd, iov, iovcnt);
231 printf("Read error: %s rc = %d\n", strerror(errno), rc);
236 /* It should return zeroed buf if the read hits hole.*/
237 if (((act & ACT_READHOLE) || (act & ACT_VERIFY)) &&
238 data_verify(iov, iovcnt, pad)) {
243 if (act & ACT_OUTPUT) {
244 rc = writev(out_fd, iov, iovcnt);
246 printf("write error: %s rc = %d\n",
247 strerror(errno), rc);