4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
27 * This file is part of Lustre, http://www.lustre.org/
28 * Lustre is a trademark of Sun Microsystems, Inc.
30 * lustre/tests/mpi/cascading_rw.c
32 * Author: You Feng <youfeng@clusterfs.com>
40 #include <sys/types.h>
41 #include <asm/types.h>
45 #include <sys/ioctl.h>
49 #include <lustre/lustreapi.h>
61 void rw_file(char *name, long stride, unsigned int seed)
63 char filename[MAX_FILENAME_LEN];
65 struct lov_user_md lum = {0};
66 int fd, rc, i, bad = 0, root = 0;
68 long page_size = sysconf(_SC_PAGESIZE);
70 sprintf(filename, "%s/%s", testdir, name);
73 remove_file_or_dir(filename);
75 lum.lmm_magic = LOV_USER_MAGIC;
76 lum.lmm_stripe_size = 0;
77 lum.lmm_stripe_count = 0;
78 lum.lmm_stripe_offset = -1;
80 fd = open(filename, O_CREAT | O_RDWR | O_LOV_DELAY_CREATE,
83 FAILF("open of file %s", filename);
85 rc = ioctl(fd, LL_IOC_LOV_SETSTRIPE, &lum);
87 FAILF("ioctl SETSTRIPE of file %s", filename);
90 FAILF("close of file %s", filename);
93 MPI_Barrier(MPI_COMM_WORLD);
98 while (stride < page_size/2) {
100 stride -= stride % 16;
103 stride %= 2 * lum.lmm_stripe_size;
107 MPI_Barrier(MPI_COMM_WORLD);
109 MPI_Bcast(&stride, 1, MPI_LONG, root, MPI_COMM_WORLD);
112 MPI_Barrier(MPI_COMM_WORLD);
114 buf = (char *)malloc(stride);
116 FAILF("malloc of buf with size %ld", stride);
119 fd = open(filename, O_RDWR);
121 FAILF("open of file %s", filename);
124 fill_stride(buf, stride, 0, off);
125 rc = write(fd, buf, stride);
127 FAILF("write of file %s return %d", filename, rc);
130 while (off < size * stride) {
131 fill_stride(buf, stride, 0x8080808080808080ULL, off);
132 rc = write(fd, buf, stride);
134 FAILF("write of file %s return %d",
140 FAILF("close of file %s", filename);
143 MPI_Barrier(MPI_COMM_WORLD);
145 o_buf = (char *)malloc(stride);
147 FAILF("malloc of o_buf with size %ld", stride);
149 fd = open(filename, O_RDWR);
151 FAILF("open of file %s", filename);
154 for (i = 1; i < size; ++i) {
156 rc = lseek(fd, off, SEEK_SET);
158 FAILF("lseek of file %s return %d",
161 rc = read(fd, buf, stride);
164 fill_stride(o_buf, rc, i - 1, off);
165 dump_diff(o_buf, buf, rc, off);
167 FAILF("read of file %s return %d",
171 fill_stride(o_buf, stride, i - 1, off);
172 if (memcmp(o_buf, buf, stride) != 0) {
173 dump_diff(o_buf, buf, stride, off);
175 FAILF("Error: diff data read from %s",
183 fill_stride(buf, stride, i, off);
184 rc = write(fd, buf, stride);
186 FAILF("write of file %s return %d",
190 MPI_Barrier(MPI_COMM_WORLD);
194 FAILF("close of file %s", filename);
196 MPI_Barrier(MPI_COMM_WORLD);
199 fd = open(filename, O_RDONLY);
201 FAILF("open of file %s", filename);
204 for (i = 0; i < size; ++i) {
205 rc = read(fd, buf, stride);
208 fill_stride(o_buf, rc, i, off);
209 dump_diff(o_buf, buf, rc, off);
211 FAILF("read of file %s", filename);
214 fill_stride(o_buf, stride, i, off);
215 if (memcmp(o_buf, buf, stride) != 0) {
217 dump_diff(o_buf, buf, stride, off);
223 FAILF("Error: diff data read from %s", filename);
227 MPI_Barrier(MPI_COMM_WORLD);
228 fprintf(stderr, "passed barrier 5\n");
234 void cascading_rw(long stride, unsigned int seed)
240 rw_file("cascading_rw", stride, seed);
244 remove_file("cascading_rw");
248 void usage(char *proc)
253 printf("Usage: %s [-h] -d <testdir> [-s \"1024\"]\n", proc);
254 printf(" [-n \"13\"] [-e \"12345\"]\n");
255 printf(" [-v] [-V #] [-g]\n");
256 printf("\t-h: prints this help message\n");
257 printf("\t-d: the directory in which the tests will run\n");
258 printf("\t-s: process stride size\n");
259 printf("\t-n: repeat test # times\n");
260 printf("\t-n: random seed, used to re-create previous runs\n");
261 printf("\t-v: increase the verbositly level by 1\n");
262 printf("\t-V: select a specific verbosity level\n");
263 printf("\t-g: debug mode\n");
272 int main(int argc, char *argv[])
274 int i, iterations = 16, c;
276 unsigned int seed = 0;
279 * Check for -h parameter before MPI_Init so the binary can be
280 * called directly, without, for instance, mpirun
282 for (i = 1; i < argc; ++i) {
283 if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help"))
287 MPI_Init(&argc, &argv);
288 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
289 MPI_Comm_size(MPI_COMM_WORLD, &size);
291 /* Parse command line options */
293 c = getopt(argc, argv, "d:e:ghn:s:vV:");
302 seed = (unsigned int)atoi(optarg);
311 iterations = atoi(optarg);
314 stride = atol(optarg);
320 verbose = atoi(optarg);
326 printf("%s is running with %d process(es) %s\n",
327 argv[0], size, debug ? "in DEBUG mode" : "\b\b");
331 "There should be at least 3 process to run the test!\n");
332 MPI_Abort(MPI_COMM_WORLD, 2);
335 if (testdir == NULL && rank == 0) {
337 "Please specify a test directory! (\"%s -h\" for help)\n",
339 MPI_Abort(MPI_COMM_WORLD, 2);
344 for (i = 0; i < iterations; ++i) {
346 printf("%s: Running test #%s(iter %d)\n",
347 timestamp(), argv[0], i);
349 cascading_rw(stride, seed);
350 MPI_Barrier(MPI_COMM_WORLD);
354 printf("%s: All tests passed!\n", timestamp());