Whamcloud - gitweb
LU-1187 tests: Add mntfmt/mntcount/mdtcount to mdsrate
authorwangdi <di.wang@whamcloud.com>
Mon, 19 Nov 2012 13:38:26 +0000 (05:38 -0800)
committerOleg Drokin <green@whamcloud.com>
Sat, 19 Jan 2013 00:06:56 +0000 (19:06 -0500)
Add mntfmt, mntcount and mdtcount to parameters of mdsrate, so
it can do multiple mount or DNE tests.

Signed-off-by: wang di <di.wang@whamcloud.com>
Change-Id: Ie3859ab13ef1ed680e645883611c5f8c9ea4e4a5
Reviewed-on: http://review.whamcloud.com/4614
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/tests/mpi/mdsrate.c

index affb0f4..1132d28 100644 (file)
@@ -63,6 +63,9 @@ enum {
         VERBOSE  = 'V',
         DEBUG    = 'v',
         HELP     = 'h',
+       MNT      = 'M',
+       MNTCOUNT = 'N',
+       MDTCOUNT = 'T',
 };
 
 struct option longOpts[] = {
@@ -90,7 +93,10 @@ struct option longOpts[] = {
         {"verbose",       0, NULL, VERBOSE    },
         {"debug",         0, NULL, DEBUG      },
         {"help",          0, NULL, HELP       },
-        { 0,              0, NULL, 0          }
+       {"mdtcount",      1, NULL, MDTCOUNT   },
+       {"mntcount",      1, NULL, MNTCOUNT   },
+       {"mntfmt",        1, NULL, MNT        },
+       { 0,              0, NULL, 0          }
 };
 
 int foo1, foo2;
@@ -114,6 +120,7 @@ struct dirent *dir_entry;
 int    nfiles;
 char   filefmt[PATH_MAX];
 char   filename[PATH_MAX];
+char   path[PATH_MAX];
 int    stripes = -1;
 int    begin;
 int    beginsave;
@@ -129,6 +136,9 @@ int    ignore;
 int    verbose;
 int    debug;
 struct stat statbuf;
+int    mnt_count = -1;
+int    mdt_count = 1;
+char  *mntfmt;
 
 #define dmesg if (debug) printf
 
@@ -157,7 +167,8 @@ char *usage_msg = "usage: %s\n"
                   "    [ --dirfmt <str> ] [ --ndirs  <num> ]\n"
                   "    [ --filefmt <str> ] [ --stripes <num> ]\n"
                   "    [ --random_order [--seed <num> | --seedfile <file>] ]\n"
-                  "    [ --readdir_order ]\n";
+                 "    [ --readdir_order ] [ --mntfmt <str> ]\n"
+                 "    [ --mntcount <num> ] [ --mdtcount <num> ]\n";
 
 static void
 usage(FILE *stream, char *fmt, ...)
@@ -413,6 +424,26 @@ process_args(int argc, char *argv[])
                         break;
                 case HELP:
                         usage(stdout, NULL);
+                       break;
+               case MNT:
+                       if (strlen(optarg) > (PATH_MAX - 16))
+                               fatal(0, "--mnt too long\n");
+                       mntfmt = optarg;
+                       break;
+               case MNTCOUNT:
+                       mnt_count = strtol(optarg, &endptr, 0);
+                       if ((*endptr != 0) || (mnt_count <= 0)) {
+                               fatal(0, "Invalid --mnt_count value %s.\n",
+                                     optarg);
+                       }
+                       break;
+               case MDTCOUNT:
+                       mdt_count = strtol(optarg, &endptr, 0);
+                       if ((*endptr != 0) || (mdt_count <= 0)) {
+                               fatal(0, "Invalid --mdt_count value %s.\n",
+                                     optarg);
+                       }
+                       break;
                 default:
                         usage(stderr, "unrecognized option: '%c'.\n", optopt);
                 }
@@ -422,6 +453,12 @@ process_args(int argc, char *argv[])
                 usage(stderr, "too many arguments %d >= %d.\n", optind, argc);
         }
 
+       if ((mnt_count != -1 && mntfmt == NULL) ||
+           (mnt_count == -1 && mntfmt != NULL)) {
+               usage(stderr, "mnt_count and mntfmt must be specified at the "
+                            "same time\n");
+       }
+
         if (mode == CREATE || mode == MKNOD || mode == UNLINK || mode == STAT) {
                 if (seconds != 0) {
                         if (nfiles == 0)
@@ -485,6 +522,11 @@ process_args(int argc, char *argv[])
         if ((end > tmpend) || (end <= 0))
                 end -= dirthreads;
 
+       /* make sure mnt_count <= nthreads, otherwise it might div 0 in
+        * the following test */
+       if (mnt_count > nthreads)
+               mnt_count = nthreads;
+
         begin += offset;
         if (begin < 0)
                 begin = INT_MAX;
@@ -497,17 +539,38 @@ process_args(int argc, char *argv[])
         if (dirfmt == NULL) {
                 strcpy(dir, ".");
         } else {
-                sprintf(dir, dirfmt, dirnum);
-
-                sprintf(mkdir_cmd, "/bin/mkdir -p %s", dir);
-                #ifdef _LIGHTWEIGHT_KERNEL
-                        printf("NOTICE: not running system(%s)\n", mkdir_cmd);
-                #else
-                        rc = system(mkdir_cmd);
-                        if (rc) {
-                                fatal(myrank, "'%s' failed.\n", mkdir_cmd);
-                        }
-                #endif
+               int dir_len = 0;
+
+               if (mntfmt != NULL) {
+                       sprintf(dir, mntfmt, (myrank / (nthreads/mnt_count)));
+                       strcat(dir, "/");
+                       dir_len = strlen(dir);
+               }
+               sprintf(dir + dir_len, dirfmt, dirnum);
+
+               if (mdt_count > 1) {
+                       struct stat sb;
+                       if (stat(dir, &sb) == 0) {
+                               if (!S_ISDIR(sb.st_mode))
+                                       fatal(myrank, "'%s' is not dir\n", dir);
+                       } else if (errno == ENOENT) {
+                               sprintf(mkdir_cmd, "lfs mkdir -i %d %s",
+                                       myrank % mdt_count, dir);
+                       } else {
+                               fatal(myrank, "'%s' stat failed\n", dir);
+                       }
+               } else {
+                       sprintf(mkdir_cmd, "mkdir -p %s", dir);
+               }
+
+               dmesg("%d: %s\n", myrank, mkdir_cmd);
+#ifdef _LIGHTWEIGHT_KERNEL
+               printf("NOTICE: not running system(%s)\n", mkdir_cmd);
+#else
+               rc = system(mkdir_cmd);
+               if (rc)
+                       fatal(myrank, "'%s' failed.\n", mkdir_cmd);
+#endif
 
                 rc = chdir(dir);
                 if (rc) {