From f31c60c9732818d8fc357ac0d94243f5f2f4952f Mon Sep 17 00:00:00 2001 From: wangdi Date: Mon, 19 Nov 2012 05:38:26 -0800 Subject: [PATCH] LU-1187 tests: Add mntfmt/mntcount/mdtcount to mdsrate Add mntfmt, mntcount and mdtcount to parameters of mdsrate, so it can do multiple mount or DNE tests. Signed-off-by: wang di Change-Id: Ie3859ab13ef1ed680e645883611c5f8c9ea4e4a5 Reviewed-on: http://review.whamcloud.com/4614 Tested-by: Hudson Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin --- lustre/tests/mpi/mdsrate.c | 89 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 76 insertions(+), 13 deletions(-) diff --git a/lustre/tests/mpi/mdsrate.c b/lustre/tests/mpi/mdsrate.c index affb0f4..1132d28 100644 --- a/lustre/tests/mpi/mdsrate.c +++ b/lustre/tests/mpi/mdsrate.c @@ -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 ] [ --ndirs ]\n" " [ --filefmt ] [ --stripes ]\n" " [ --random_order [--seed | --seedfile ] ]\n" - " [ --readdir_order ]\n"; + " [ --readdir_order ] [ --mntfmt ]\n" + " [ --mntcount ] [ --mdtcount ]\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) { -- 1.8.3.1