Whamcloud - gitweb
LU-6142 llite: Fix style issues under lustre/llite
[fs/lustre-release.git] / lustre / tests / rename_many.c
index faf5085..7522072 100644 (file)
@@ -1,3 +1,32 @@
+/*
+ * 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) 2004, 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/
+ */
+
 #define PATH_LENGTH 35
 #include <math.h>
 #include <signal.h>
@@ -30,7 +59,7 @@ int creat_errors;
 int rename_errors;
 int unlink_errors;
 
-void usage(const char *progname)
+static void usage(const char *progname)
 {
        fprintf(stderr, "usage: %s [-n numfiles] [-s seed] [-v] [-x] [dir]\n"
                "\t-c: only do the create step of first loop\n"
@@ -42,7 +71,8 @@ void usage(const char *progname)
                "\t-x: don't exit on error\n", progname);
 }
 
-void handler(int sig) {
+static void handler(int sig)
+{
        static long last_time;
        long now = time(0);
 
@@ -71,12 +101,12 @@ extern int optind;
 int main(int argc, char *argv[])
 {
        unsigned long n;
-       char msg[100], c, *end = NULL;
+       char msg[100], *end = NULL;
        int h1, h2;
-       int i;
+       int i, c;
 
        while ((c = getopt(argc, argv, "cf:n:rs:vx")) != EOF) {
-               switch(c) {
+               switch (c) {
                case 'c':
                        ++opt_create_only;
                        break;
@@ -85,7 +115,8 @@ int main(int argc, char *argv[])
                        if (i && end != NULL && *end == '\0') {
                                file_count = i;
                        } else {
-                               fprintf(stderr, "bad file count '%s'\n",optarg);
+                               fprintf(stderr, "bad file count '%s'\n",
+                                       optarg);
                                usage(argv[0]);
                                return 1;
                        }
@@ -95,7 +126,8 @@ int main(int argc, char *argv[])
                        if (i && end != NULL && *end == '\0') {
                                loop_count = i;
                        } else {
-                               fprintf(stderr, "bad loop count '%s'\n",optarg);
+                               fprintf(stderr, "bad loop count '%s'\n",
+                                       optarg);
                                usage(argv[0]);
                                return 1;
                        }
@@ -108,9 +140,8 @@ int main(int argc, char *argv[])
                        if (end && *end == '\0') {
                                seed = i;
                        } else {
-                               fprintf(stderr, "bad seed '%s'\n", optarg);
-                               usage(argv[0]);
-                               return 1;
+                               seed = random();
+                               fprintf(stderr, "using random seed %u\n", seed);
                        }
                        break;
                case 'v':
@@ -128,7 +159,7 @@ int main(int argc, char *argv[])
        names = malloc(sizeof(struct names) * file_count);
        if (names == NULL) {
                perror("calloc");
-               return(1);
+               return 1;
        }
 
        h2 = sprintf(msg, "%x", file_count); /* just to figure length */
@@ -152,23 +183,24 @@ int main(int argc, char *argv[])
                return 1;
        } else if (argv[optind] != NULL) {
                if (chdir(argv[optind]) < 0) {
-                       sprintf(msg, "chdir '%s'\n", argv[optind]);
+                       snprintf(msg, sizeof(msg),
+                                "chdir '%s'\n", argv[optind]);
                        perror(msg);
                        return 2;
                }
        }
 
        while (!stop && loop_count != 0 && loops < loop_count) {
-               int j,k,l,m;
+               int j, k, l, m;
 
                srand(seed + loops);
-               if (mkdir("tmp", S_IRWXU) == -1) {
+               if (mkdir("tmp", 0700) == -1) {
                        perror("mkdir tmp");
-                       return(1);
+                       return 1;
                }
                if (chdir("tmp") == -1) {
                        perror("chdir tmp");
-                       return(1);
+                       return 1;
                }
 
                for (i = 0; i < file_count ; i++) {
@@ -184,7 +216,7 @@ int main(int argc, char *argv[])
                }
 
                for (i = 0; i < file_count; i++) {
-                       if (mknod(names[i].from, S_IFREG | S_IRWXU, 0) == -1) {
+                       if (mknod(names[i].from, S_IFREG | 0700, 0) == -1) {
                                sprintf(msg, "loop %d.%d: creat %s",
                                        loops, i, names[i].from);
                                perror(msg);
@@ -224,18 +256,18 @@ int main(int argc, char *argv[])
 
                if (chdir("..") == -1) {
                        perror("chdir ..");
-                       return(1);
+                       return 1;
                }
 
                if (rmdir("tmp") == -1) {
                        if (chdir("tmp") == -1) {
                                perror("chdir tmp 2");
-                               return(1);
+                               return 1;
                        }
                        for (i = 0; i < file_count; i++) {
                                if (unlink(names[i].from) != -1) {
-                                       fprintf(stderr, "loop %d.%d: "
-                                               "unexpected file %s\n",
+                                       fprintf(stderr,
+                                               "loop %d.%d: unexpected file %s\n",
                                                loops, i, names[i].to);
                                        unlink_errors++;
                                        if (!opt_exit_on_err)
@@ -244,11 +276,11 @@ int main(int argc, char *argv[])
                        }
                        if (chdir("..") == -1) {
                                perror("chdir .. 2");
-                               return(1);
+                               return 1;
                        }
                        if (rmdir("tmp") == -1) {
                                perror("rmdir tmp");
-                               return(1);
+                               return 1;
                        }
                }
 
@@ -259,5 +291,5 @@ int main(int argc, char *argv[])
 
        if (!opt_verbose)
                handler(0);
-       return(0);
+       return 0;
 }