X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Ftests%2Fdirectio.c;h=da359b480cd92cfe1952f52199109547e2d1b841;hp=bd463360cd8077812abcac9db1817a0322cd22e2;hb=0585b0fb5895a24f07ca32e830d1fa72b75f4f2b;hpb=70e80ade90af09300396706b8910e196a7928520 diff --git a/lustre/tests/directio.c b/lustre/tests/directio.c index bd46336..da359b4 100644 --- a/lustre/tests/directio.c +++ b/lustre/tests/directio.c @@ -1,6 +1,4 @@ -/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- - * vim:expandtab:shiftwidth=8:tabstop=8: - * +/* * GPL HEADER START * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -16,8 +14,8 @@ * in the LICENSE file that accompanied this code). * * You should have received a copy of the GNU General Public License - * version 2 along with this program; If not, see [sun.com URL with a - * copy of GPLv2]. + * version 2 along with this program; If not, see + * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, * CA 95054 USA or visit www.sun.com if you need additional information or @@ -26,7 +24,7 @@ * GPL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved + * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. */ /* @@ -47,11 +45,23 @@ #include #include +/* return index of the first byte not matching given byte + * or buffer size if all bytes are matching */ +static size_t check_bytes(const char *buf, int byte, size_t len) +{ + const char *p; + + for (p = buf; p < buf + len; p++) + if (*p != byte) + break; + return p - buf; +} + int main(int argc, char **argv) { #ifdef O_DIRECT int fd; - char *wbuf, *fname; + char *buf, *fname; int blocks, seek_blocks; long len; off64_t seek; @@ -106,12 +116,12 @@ int main(int argc, char **argv) seek = (off64_t)seek_blocks * (off64_t)st.st_blksize; len = blocks * st.st_blksize; - wbuf = mmap(0, len, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, 0, 0); - if (wbuf == MAP_FAILED) { + buf = mmap(0, len, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, 0, 0); + if (buf == MAP_FAILED) { printf("No memory %s\n", strerror(errno)); return 1; } - memset(wbuf, pad, len); + memset(buf, pad, len); if (action == O_WRONLY || action == O_RDWR) { if (lseek64(fd, seek, SEEK_SET) < 0) { @@ -119,7 +129,7 @@ int main(int argc, char **argv) return 1; } - rc = write(fd, wbuf, len); + rc = write(fd, buf, len); if (rc != len) { printf("Write error %s (rc = %d, len = %ld)\n", strerror(errno), rc, len); @@ -128,26 +138,19 @@ int main(int argc, char **argv) } if (action == O_RDONLY || action == O_RDWR) { - char *rbuf; - if (lseek64(fd, seek, SEEK_SET) < 0) { printf("Cannot seek %s\n", strerror(errno)); return 1; } - - rbuf =mmap(0,len,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,0,0); - if (rbuf == MAP_FAILED) { - printf("No memory %s\n", strerror(errno)); - return 1; - } - - rc = read(fd, rbuf, len); + /* reset all bytes to something nor 0x0 neither 0xab */ + memset(buf, 0x5e, len); + rc = read(fd, buf, len); if (rc != len) { printf("Read error: %s rc = %d\n",strerror(errno),rc); return 1; } - if (memcmp(wbuf, rbuf, len)) { + if (check_bytes(buf, pad, len) != len) { printf("Data mismatch\n"); return 1; }