Whamcloud - gitweb
LU-1538 tests: fix test cases when OST is full
[fs/lustre-release.git] / lustre / tests / multiop.c
old mode 100755 (executable)
new mode 100644 (file)
index 8772224..9ed0522
@@ -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) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  */
 /*
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/mman.h>
+#include <sys/vfs.h>
 #include <signal.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <lustre/liblustreapi.h>
+#include <semaphore.h>
+
+#include <lustre/lustreapi.h>
 
 #define T1 "write data before unlink\n"
 #define T2 "write data after unlink\n"
 char msg[] = "yabba dabba doo, I'm coming for you, I live in a shoe, I don't know what to do.\n'Bigger, bigger,and bigger yet!' cried the Creator.  'You are not yet substantial enough for my boundless intents!'  And ever greater and greater the object became, until all was lost 'neath its momentus bulk.\n";
 char *buf, *buf_align;
 int bufsize = 0;
+sem_t sem;
 #define ALIGN 65535
 
-char usage[] = 
+char usage[] =
 "Usage: %s filename command-sequence\n"
 "    command-sequence items:\n"
 "        c  close\n"
 "        C[num] create with optional stripes\n"
 "        d  mkdir\n"
 "        D  open(O_DIRECTORY)\n"
+"        f  statfs\n"
+"        G gid get grouplock\n"
+"        g gid put grouplock\n"
 "        L  link\n"
 "        l  symlink\n"
 "        m  mknod\n"
@@ -78,6 +83,7 @@ char usage[] =
 "        T[num] ftruncate [optional position, default 0]\n"
 "        u  unlink\n"
 "        U  munmap\n"
+"        v  verbose\n"
 "        w[num] write optional length\n"
 "        W  write entire mmap-ed region\n"
 "        y  fsync\n"
@@ -85,10 +91,19 @@ char usage[] =
 "        z[num] seek [optional position, default 0]\n"
 "        _  wait for signal\n";
 
-static int usr1_received;
 void usr1_handler(int unused)
 {
-        usr1_received = 1;
+        int saved_errno = errno;
+
+        /*
+         * signal(7): POSIX.1-2004 ...requires an implementation to guarantee
+         * that the following functions can be safely called inside a signal
+         * handler:
+         *            sem_post()
+         */
+        sem_post(&sem);
+
+        errno = saved_errno;
 }
 
 static const char *
@@ -166,41 +181,42 @@ int get_flags(char *data, int *rflags)
 }
 
 #define POP_ARG() (pop_arg(argc, argv))
-#define min(a,b) ((a)>(b)?(b):(a))
 
 int main(int argc, char **argv)
 {
         char *fname, *commands;
         const char *newfile;
         struct stat st;
+        struct statfs stfs;
         size_t mmap_len = 0, i;
         unsigned char *mmap_ptr = NULL, junk = 0;
         int rc, len, fd = -1;
         int flags;
         int save_errno;
         int verbose = 0;
+        int gid = 0;
 
         if (argc < 3) {
                 fprintf(stderr, usage, argv[0]);
                 exit(1);
         }
 
-        signal(SIGUSR1, usr1_handler);
+        memset(&st, 0, sizeof(st));
+        sem_init(&sem, 0, 0);
+        /* use sigaction instead of signal to avoid SA_ONESHOT semantics */
+        sigaction(SIGUSR1, &(const struct sigaction){.sa_handler = &usr1_handler},
+                  NULL);
 
         fname = argv[1];
 
         for (commands = argv[2]; *commands; commands++) {
                 switch (*commands) {
                 case '_':
-                        if (usr1_received == 0) {
-                                if (verbose) {
-                                        printf("PAUSING\n");
-                                        fflush(stdout);
-                                }
-                                pause();
+                        if (verbose) {
+                                printf("PAUSING\n");
+                                fflush(stdout);
                         }
-                        usr1_received = 0;
-                        signal(SIGUSR1, usr1_handler);
+                        while (sem_wait(&sem) == -1 && errno == EINTR);
                         break;
                 case 'c':
                         if (close(fd) == -1) {
@@ -235,6 +251,29 @@ int main(int argc, char **argv)
                                 exit(save_errno);
                         }
                         break;
+                case 'f':
+                        if (statfs(fname, &stfs) == -1) {
+                                save_errno = errno;
+                                perror("statfs()");
+                                exit(save_errno);
+                        }
+                        break;
+                case 'G':
+                        gid = atoi(commands+1);
+                        if (ioctl(fd, LL_IOC_GROUP_LOCK, gid) == -1) {
+                                save_errno = errno;
+                                perror("ioctl(GROUP_LOCK)");
+                                exit(save_errno);
+                        }
+                        break;
+                case 'g':
+                        gid = atoi(commands+1);
+                        if (ioctl(fd, LL_IOC_GROUP_UNLOCK, gid) == -1) {
+                                save_errno = errno;
+                                perror("ioctl(GROUP_UNLOCK)");
+                                exit(save_errno);
+                        }
+                        break;
                 case 'l':
                         newfile = POP_ARG();
                         if (!newfile)
@@ -263,6 +302,11 @@ int main(int argc, char **argv)
                         }
                         break;
                 case 'M':
+                        if (st.st_size == 0) {
+                                fprintf(stderr, "mmap without preceeding stat, or on"
+                                        " zero length file.\n");
+                                exit(-1);
+                        }
                         mmap_len = st.st_size;
                         mmap_ptr = mmap(NULL, mmap_len, PROT_WRITE | PROT_READ,
                                         MAP_SHARED, fd, 0);
@@ -293,7 +337,10 @@ int main(int argc, char **argv)
                 case 'o':
                         len = get_flags(commands+1, &flags);
                         commands += len;
-                        fd = open(fname, flags);
+                        if (flags & O_CREAT)
+                                fd = open(fname, flags, 0666);
+                        else
+                                fd = open(fname, flags);
                         if (fd == -1) {
                                 save_errno = errno;
                                 perror("open");
@@ -322,10 +369,15 @@ int main(int argc, char **argv)
                                         perror("read");
                                         exit(save_errno);
                                 }
-                                if (rc < len)
-                                        fprintf(stderr, "short read: %u/%u\n",
-                                                rc, len);
+                               if (rc < len) {
+                                       fprintf(stderr, "short read: %u/%u\n",
+                                               rc, len);
+                                       if (rc == 0)
+                                               exit(ENODATA);
+                               }
                                 len -= rc;
+                                if (verbose >= 2)
+                                        printf("%.*s\n", rc, buf_align);
                         }
                         break;
                 case 'R':
@@ -377,7 +429,7 @@ int main(int argc, char **argv)
                         }
                         break;
                 case 'v':
-                        verbose = 1;
+                        verbose++;
                         break;
                 case 'w':
                         len = atoi(commands+1);