1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
46 #include <sys/types.h>
50 int main(int argc, char **argv)
55 int blocks, seek_blocks;
63 if (argc < 5 || argc > 6) {
64 printf("Usage: %s <read/write/rdwr/readhole> file seek nr_blocks [blocksize]\n", argv[0]);
68 if (!strcmp(argv[1], "read"))
70 else if (!strcmp(argv[1], "write"))
72 else if (!strcmp(argv[1], "rdwr"))
74 else if (!strcmp(argv[1], "readhole")) {
78 printf("Usage: %s <read/write/rdwr> file seek nr_blocks [blocksize]\n", argv[0]);
83 seek_blocks = strtoul(argv[3], 0, 0);
84 blocks = strtoul(argv[4], 0, 0);
86 printf("Usage: %s <read/write/rdwr> file seek nr_blocks [blocksize]\n", argv[0]);
90 fd = open(fname, O_LARGEFILE | O_DIRECT | O_RDWR | O_CREAT, 0644);
92 printf("Cannot open %s: %s\n", fname, strerror(errno));
97 st.st_blksize = strtoul(argv[5], 0, 0);
98 else if (fstat64(fd, &st) < 0) {
99 printf("Cannot stat %s: %s\n", fname, strerror(errno));
103 printf("directio on %s for %dx%lu bytes \n", fname, blocks,
106 seek = (off64_t)seek_blocks * (off64_t)st.st_blksize;
107 len = blocks * st.st_blksize;
109 wbuf = mmap(0, len, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, 0, 0);
110 if (wbuf == MAP_FAILED) {
111 printf("No memory %s\n", strerror(errno));
114 memset(wbuf, pad, len);
116 if (action == O_WRONLY || action == O_RDWR) {
117 if (lseek64(fd, seek, SEEK_SET) < 0) {
118 printf("lseek64 failed: %s\n", strerror(errno));
122 rc = write(fd, wbuf, len);
124 printf("Write error %s (rc = %d, len = %ld)\n",
125 strerror(errno), rc, len);
130 if (action == O_RDONLY || action == O_RDWR) {
133 if (lseek64(fd, seek, SEEK_SET) < 0) {
134 printf("Cannot seek %s\n", strerror(errno));
138 rbuf =mmap(0,len,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,0,0);
139 if (rbuf == MAP_FAILED) {
140 printf("No memory %s\n", strerror(errno));
144 rc = read(fd, rbuf, len);
146 printf("Read error: %s rc = %d\n",strerror(errno),rc);
150 if (memcmp(wbuf, rbuf, len)) {
151 printf("Data mismatch\n");
158 #else /* !O_DIRECT */
159 #warning O_DIRECT not defined, directio test will fail
160 printf("O_DIRECT not defined\n");
162 #endif /* !O_DIRECT */