X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Ftests%2Fsmall_write.c;h=26ac6fe7d86fbfcd7a95830347f60e7c36e336c6;hb=b78fb445555916e380b1661546c821df14098596;hp=ebbb2b31a18f493b0d8084c5797495308675aa16;hpb=c5050e412572b00cbe93d8517d2d1f767bebfa92;p=fs%2Flustre-release.git diff --git a/lustre/tests/small_write.c b/lustre/tests/small_write.c index ebbb2b3..26ac6fe 100644 --- a/lustre/tests/small_write.c +++ b/lustre/tests/small_write.c @@ -1,3 +1,33 @@ +/* + * GPL HEADER START + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 only, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License version 2 for more details (a copy is included + * 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 + * http://www.gnu.org/licenses/gpl-2.0.html + * + * GPL HEADER END + */ +/* + * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Use is subject to license terms. + */ +/* + * This file is part of Lustre, http://www.lustre.org/ + * Lustre is a trademark of Sun Microsystems, Inc. + */ + #include #include #include @@ -7,42 +37,44 @@ #include #include +#define GOTO(label, rc) do { rc; goto label; } while (0) + int main (int argc, char **argv) { - int fd, i, rc; + int fd, i, rc = 0; unsigned long bytes, lbytes; struct stat st; char *str, *str2, *readbuf; if (argc != 3) { fprintf(stderr, "usage: %s \n", argv[0]); - return 1; + GOTO(out, rc = 1); } bytes = strtoul(argv[2], NULL, 10); if (!bytes) { printf("No bytes!\n"); - return 1; + GOTO(out, rc = 2); } if (bytes % 2) { printf("Need an even number of bytes!\n"); - return 1; + GOTO(out, rc = 3); } lbytes = 3*bytes/2; str = malloc(bytes+1); if (!str) { printf("No enough memory for %lu bytes.\n", bytes); - return 1; + GOTO(out, rc = 4); } str2 = malloc(lbytes+1); - if (!str) { + if (!str2) { printf("No enough memory for %lu bytes.\n", lbytes); - return 1; + GOTO(out_str, rc = 5); } readbuf = malloc(bytes*2); - if (!str) { + if (!readbuf) { printf("No enough memory for %lu bytes.\n", bytes*2); - return 1; + GOTO(out_str2, rc = 6); } for(i=0; i < bytes; i++) @@ -59,13 +91,13 @@ int main (int argc, char **argv) { fd = open(argv[1], O_CREAT|O_RDWR|O_TRUNC, 0700); if (fd == -1) { printf("Could not open file %s.\n", argv[1]); - return 1; + GOTO(out_readbuf, rc = 7); } rc = write(fd, str, bytes); if (rc != bytes) { printf("Write failed!\n"); - return 1; + GOTO(out_fd, rc = 8); } sleep(1); @@ -74,19 +106,19 @@ int main (int argc, char **argv) { printf("bad file %lu size first write %lu != %lu: rc %d\n", (unsigned long)st.st_ino, (unsigned long)st.st_size, bytes, rc); - return 1; + GOTO(out_fd, rc = 9); } rc = lseek(fd, bytes / 2, SEEK_SET); if (rc != bytes / 2) { printf("Seek failed!\n"); - return 1; + GOTO(out_fd, rc = 10); } rc = write(fd, str, bytes); if (rc != bytes) { printf("Write failed!\n"); - return 1; + GOTO(out_fd, rc = 11); } rc = fstat(fd, &st); @@ -94,13 +126,13 @@ int main (int argc, char **argv) { printf("bad file %lu size second write %lu != %lu: rc %d\n", (unsigned long)st.st_ino, (unsigned long)st.st_size, bytes, rc); - return 1; + GOTO(out_fd, rc = 12); } rc = lseek(fd, 0, SEEK_SET); if (rc != 0) { printf("Seek failed!\n"); - return 1; + GOTO(out_fd, rc = 13); } rc = read(fd, readbuf, bytes * 2); @@ -115,23 +147,29 @@ int main (int argc, char **argv) { printf("bad file size after read %lu != %lu: rc %d\n", (unsigned long)st.st_size, bytes + bytes / 2, rc); - return 1; + GOTO(out_fd, rc = 14); } - return 1; + GOTO(out_fd, rc = 15); } - - fd = close(fd); - if (fd == -1) - return 1; + rc = 0; if (bytes < 320) printf("%s\n%s\n", readbuf, str2); if (strcmp(readbuf, str2)) { printf("No match!\n"); - return 1; + GOTO(out_fd, rc = 16); } printf("Pass!\n"); - return 0; +out_fd: + close(fd); +out_readbuf: + free(readbuf); +out_str2: + free(str2); +out_str: + free(str); +out: + return rc; }