X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Futils%2Fllverfs.c;h=234508273275dadfdc4211ac26df2034d00a55ed;hb=a8dcf372f430c308d3e96fb506563068d0a80c2d;hp=953f342980ae92bf8361fc5c912800df7476d816;hpb=e3a7c58aebafce40323db54bf6056029e5af4a70;p=fs%2Flustre-release.git diff --git a/lustre/utils/llverfs.c b/lustre/utils/llverfs.c index 953f342..23450827 100644 --- a/lustre/utils/llverfs.c +++ b/lustre/utils/llverfs.c @@ -15,11 +15,7 @@ * * You should have received a copy of the GNU General Public License * 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 - * have any questions. + * http://www.gnu.org/licenses/gpl-2.0.html * * GPL HEADER END */ @@ -27,7 +23,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, Whamcloud, Inc. + * Copyright (c) 2011, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -124,22 +120,20 @@ const int dirmode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; static int isatty_flag; static int perms = S_IRWXU | S_IRGRP | S_IROTH; -static struct option const longopts[] = -{ - { "chunksize", required_argument, 0, 'c' }, - { "help", no_argument, 0, 'h' }, - { "offset", required_argument, 0, 'o' }, - { "long", no_argument, 0, 'l' }, - { "full", no_argument, 0, 'l' }, - { "partial", required_argument, 0, 'p' }, - { "quiet", required_argument, 0, 'q' }, - { "read", no_argument, 0, 'r' }, - { "filesize", no_argument, 0, 's' }, - { "timestamp", required_argument, 0, 't' }, - { "verbose", no_argument, 0, 'v' }, - { "write", no_argument, 0, 'w' }, - { 0, 0, 0, 0} -}; +static struct option const long_opts[] = { + { .val = 'c', .name = "chunksize", .has_arg = required_argument }, + { .val = 'h', .name = "help", .has_arg = no_argument }, + { .val = 'l', .name = "long", .has_arg = no_argument }, + { .val = 'l', .name = "full", .has_arg = no_argument }, + { .val = 'o', .name = "offset", .has_arg = required_argument }, + { .val = 'p', .name = "partial", .has_arg = required_argument }, + { .val = 'q', .name = "quiet", .has_arg = required_argument }, + { .val = 'r', .name = "read", .has_arg = no_argument }, + { .val = 's', .name = "filesize", .has_arg = no_argument }, + { .val = 't', .name = "timestamp", .has_arg = required_argument }, + { .val = 'v', .name = "verbose", .has_arg = no_argument }, + { .val = 'w', .name = "write", .has_arg = no_argument }, + { .name = NULL } }; /* * Usages: displays help information, whenever user supply --help option in @@ -527,6 +521,7 @@ static int dir_write(char *chunk_buf, size_t chunksize, struct timeval start_time; unsigned long long total_bytes; unsigned long long curr_bytes = 0; + int rc = 0; #ifdef HAVE_EXT2FS_EXT2FS_H if (!full && fsetflags(testdir, EXT2_TOPDIR_FL)) @@ -545,7 +540,8 @@ static int dir_write(char *chunk_buf, size_t chunksize, fflush(countfile) != 0) { fprintf(stderr, "\n%s: writing %s failed :%s\n", progname, filecount, strerror(errno)); - return 6; + rc = 6; + goto out; } /* calculate total bytes that need to be written */ @@ -553,7 +549,8 @@ static int dir_write(char *chunk_buf, size_t chunksize, if (total_bytes <= 0) { fprintf(stderr, "\n%s: unable to calculate total bytes\n", progname); - return 7; + rc = 7; + goto out; } if (!full && (dir_num != 0)) @@ -575,7 +572,8 @@ static int dir_write(char *chunk_buf, size_t chunksize, fprintf(stderr, "\n%s: mkdir %s : %s\n", progname, tempdir, strerror(errno)); - return 1; + rc = 1; + goto out; } } dir_num++; @@ -600,8 +598,10 @@ static int dir_write(char *chunk_buf, size_t chunksize, time_st, inode_st, tempfile); close(fd); if (ret < 0) { - if (ret != -ENOSPC) - return 1; + if (ret != -ENOSPC) { + rc = 1; + goto out; + } curr_bytes = total_bytes; break; } @@ -618,7 +618,6 @@ static int dir_write(char *chunk_buf, size_t chunksize, progname, filecount, strerror(errno)); } } - fclose(countfile); if (verbose) { verbose++; @@ -628,7 +627,10 @@ static int dir_write(char *chunk_buf, size_t chunksize, verbose--; } - return 0; +out: + fclose(countfile); + + return rc; } /* @@ -724,7 +726,7 @@ int main(int argc, char **argv) progname = strrchr(argv[0], '/') ? strrchr(argv[0], '/') + 1 : argv[0]; while ((c = getopt_long(argc, argv, "c:hlo:pqrs:t:vw", - longopts, NULL)) != -1) { + long_opts, NULL)) != -1) { switch (c) { case 'c': chunksize = strtoul(optarg, NULL, 0) * ONE_MB; @@ -861,7 +863,8 @@ guess: fprintf(stderr, "Memory allocation failed for chunk_buf\n"); return 4; } - sprintf(filecount, "%s/%s.filecount", testdir, progname); + snprintf(filecount, sizeof(filecount), "%s/%s.filecount", + testdir, progname); if (writeoption) { (void)mkdir(testdir, dirmode);