Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / tests / multiop.c
index 63a6f08..765c00b 100755 (executable)
@@ -1,7 +1,9 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  */
+#ifndef _GNU_SOURCE
 #define _GNU_SOURCE /* pull in O_DIRECTORY in bits/fcntl.h */
+#endif
 #include <stdio.h>
 #include <fcntl.h>
 #include <string.h>
 #include <signal.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <lustre/liblustreapi.h>
 
 #define T1 "write data before unlink\n"
 #define T2 "write data after unlink\n"
-char buf[] = "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 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;
+#define ALIGN 65535
 
 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"
 "        L  link\n"
@@ -164,6 +171,16 @@ int main(int argc, char **argv)
                         }
                         fd = -1;
                         break;
+                case 'C':
+                        len = atoi(commands+1);
+                        fd = llapi_file_open(fname, O_CREAT | O_WRONLY, 0644,
+                                             0, 0, len, 0);
+                        if (fd == -1) {
+                                save_errno = errno;
+                                perror("create stripe file");
+                                exit(save_errno);
+                        }
+                        break;
                 case 'd':
                         if (mkdir(fname, 0755) == -1) {
                                 save_errno = errno;
@@ -248,21 +265,28 @@ int main(int argc, char **argv)
                         len = atoi(commands+1);
                         if (len <= 0)
                                 len = 1;
-                        while(len > 0) {
-                                if (read(fd, &buf,
-                                         min(len,sizeof(buf))) == -1) {
+                        if (bufsize < len) {
+                                buf = realloc(buf, len + ALIGN);
+                                if (buf == NULL) {
                                         save_errno = errno;
-                                        perror("read");
+                                        perror("allocating buf for read\n");
                                         exit(save_errno);
                                 }
-                                len -= sizeof(buf);
+                                bufsize = len;
+                                buf_align = (char *)((long)(buf + ALIGN) &
+                                                     ~ALIGN);
                         }
-                        break;
-                case 'S':
-                        if (fstat(fd, &st) == -1) {
-                                save_errno = errno;
-                                perror("fstat");
-                                exit(save_errno);
+                        while (len > 0) {
+                                rc = read(fd, buf_align, len);
+                                if (rc == -1) {
+                                        save_errno = errno;
+                                        perror("read");
+                                        exit(save_errno);
+                                }
+                                if (rc < len)
+                                        fprintf(stderr, "short read: %u/%u\n",
+                                                rc, len);
+                                len -= rc;
                         }
                         break;
                 case 'R':
@@ -276,6 +300,13 @@ int main(int argc, char **argv)
                                 exit(save_errno);
                         }
                         break;
+                case 'S':
+                        if (fstat(fd, &st) == -1) {
+                                save_errno = errno;
+                                perror("fstat");
+                                exit(save_errno);
+                        }
+                        break;
                 case 't':
                         if (fchmod(fd, 0) == -1) {
                                 save_errno = errno;
@@ -310,15 +341,29 @@ int main(int argc, char **argv)
                         len = atoi(commands+1);
                         if (len <= 0)
                                 len = 1;
-                        while(len > 0) {
-                                if ((rc = write(fd, buf,
-                                                min(len, sizeof(buf))))
-                                    == -1) {
+                        if (bufsize < len) {
+                                buf = realloc(buf, len + ALIGN);
+                                if (buf == NULL) {
+                                        save_errno = errno;
+                                        perror("allocating buf for write\n");
+                                        exit(save_errno);
+                                }
+                                bufsize = len;
+                                buf_align = (char *)((long)(buf + ALIGN) &
+                                                     ~ALIGN);
+                                strncpy(buf_align, msg, bufsize);
+                        }
+                        while (len > 0) {
+                                rc = write(fd, buf_align, len);
+                                if (rc == -1) {
                                         save_errno = errno;
                                         perror("write");
                                         exit(save_errno);
                                 }
-                                len -= sizeof(buf);
+                                if (rc < len)
+                                        fprintf(stderr, "short write: %u/%u\n",
+                                                rc, len);
+                                len -= rc;
                         }
                         break;
                 case 'W':
@@ -364,5 +409,8 @@ int main(int argc, char **argv)
                 }
         }
 
+        if (buf)
+                free(buf);
+
         return 0;
 }