Whamcloud - gitweb
Program to create/destroy many files.
authoradilger <adilger>
Fri, 4 Oct 2002 05:20:52 +0000 (05:20 +0000)
committeradilger <adilger>
Fri, 4 Oct 2002 05:20:52 +0000 (05:20 +0000)
lustre/tests/.cvsignore
lustre/tests/Makefile.am
lustre/tests/createdestroy.c [new file with mode: 0644]

index 1acdc7b..f2ce028 100644 (file)
@@ -20,3 +20,4 @@ fsx
 test_brw
 newfile
 openclose
+createdestroy
index aa5663b..9646b90 100644 (file)
@@ -24,7 +24,8 @@ noinst_SCRIPTS = fs.sh intent-test.sh intent-test2.sh leak_finder.pl \
 pkglib_SCRIPTS = common.sh
 pkgcfg_DATA = lustre.cfg
 noinst_PROGRAMS = openunlink testreq truncate directio openme writeme mcreate
-noinst_PROGRAMS += munlink tchmod toexcl fsx test_brw openclose #ldaptest 
+noinst_PROGRAMS += munlink tchmod toexcl fsx test_brw openclose createdestroy
+# noinst_PROGRAMS += ldaptest 
 
 # ldaptest_SOURCES = ldaptest.c
 tchmod_SOURCES = tchmod.c
@@ -40,5 +41,6 @@ writeme_SOURCES = writeme.c
 fsx_SOURCES = fsx.c
 test_brw_SOURCES = test_brw.c
 openclose_SOURCES = openclose.c
+createdestroy_SOURCES = createdestroy.c
 
 include $(top_srcdir)/Rules
diff --git a/lustre/tests/createdestroy.c b/lustre/tests/createdestroy.c
new file mode 100644 (file)
index 0000000..93ecb11
--- /dev/null
@@ -0,0 +1,108 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+#include <sys/wait.h>
+
+int main(int argc, char *argv[])
+{
+        char filename[1024];
+        unsigned long count, i;
+       int thread = 0;
+       int threads = 0;
+       int rc;
+
+        if (argc < 3 || argc > 4) {
+                fprintf(stderr, "usage: %s <filename> <iterations> [threads]\n",
+                       argv[0]);
+                exit(1);
+        }
+
+        count = strtoul(argv[2], NULL, 0);
+       if (argc == 4)
+               threads = strtoul(argv[3], NULL, 0);
+
+        for (i = 1; i <= threads; i++) {
+                rc = fork();
+                if (rc < 0) {
+                        fprintf(stderr, "error: %s: #%ld - %s\n", argv[0], i,
+                                strerror(rc = errno));
+                        break;
+                } else if (rc == 0) {
+                        thread = i;
+                        argv[2] = "--device";
+                        break;
+                } else
+                        printf("%s: thread #%ld (PID %d) started\n",
+                               argv[0], i, rc);
+                rc = 0;
+        }
+
+        if (threads && thread == 0) {  /* parent process */
+                int live_threads = threads;
+
+                while (live_threads > 0) {
+                        int status;
+                        pid_t ret;
+
+                        ret = waitpid(0, &status, 0);
+                        if (ret == 0) {
+                                continue;
+                        }
+
+                        if (ret < 0) {
+                                fprintf(stderr, "error: %s: wait - %s\n",
+                                        argv[0], strerror(errno));
+                                if (!rc)
+                                        rc = errno;
+                        } else {
+                                /*
+                                 * This is a hack.  We _should_ be able to use
+                                 * WIFEXITED(status) to see if there was an
+                                 * error, but it appears to be broken and it
+                                 * always returns 1 (OK).  See wait(2).
+                                 */
+                                int err = WEXITSTATUS(status);
+                                if (err || WIFSIGNALED(status))
+                                        fprintf(stderr,
+                                                "%s: PID %d had rc=%d\n",
+                                                argv[0], ret, err);
+                                if (!rc)
+                                        rc = err;
+
+                                live_threads--;
+                        }
+                }
+       } else {
+               for (i = 0; i < count; i++) {
+                       if (threads)
+                               sprintf(filename, "%s-%d-%ld",
+                                       argv[1], thread, i);
+                       else
+                               sprintf(filename, "%s-%ld", argv[1], i);
+
+                       rc = mknod(filename, S_IFREG, 0);
+                       if (rc < 0) {
+                               fprintf(stderr, "mknod(%s): %s\n",
+                                       filename, strerror(errno));
+                               rc = errno;
+                               break;
+                       }
+                       if (unlink(filename) < 0) {
+                               fprintf(stderr, "unlink(%s): %s\n",
+                                       filename, strerror(errno));
+                               rc = errno;
+                               break;
+                       }
+               }
+               if (threads)
+                       printf("Thread %d done: rc = %d\n", thread, rc);
+               else
+                       printf("Done: rc = %d\n", rc);
+       }
+        return rc;
+}