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/
29 * lustre/tests/mpi/cascading_rw.c
31 * Author: You Feng <youfeng@clusterfs.com>
39 #include <sys/types.h>
40 #include <asm/types.h>
44 #include <sys/ioctl.h>
48 #include <lustre/lustreapi.h>
60 void rw_file(char *name, long stride, unsigned int seed)
62 char filename[MAX_FILENAME_LEN];
64 struct lov_user_md lum = {0};
65 int fd, rc, i, bad = 0, root = 0;
67 long page_size = sysconf(_SC_PAGESIZE);
69 sprintf(filename, "%s/%s", testdir, name);
72 remove_file_or_dir(filename);
74 lum.lmm_magic = LOV_USER_MAGIC;
75 lum.lmm_stripe_size = 0;
76 lum.lmm_stripe_count = 0;
77 lum.lmm_stripe_offset = -1;
79 fd = open(filename, O_CREAT | O_RDWR | O_LOV_DELAY_CREATE,
82 FAILF("open of file %s", filename);
84 rc = ioctl(fd, LL_IOC_LOV_SETSTRIPE, &lum);
86 FAILF("ioctl SETSTRIPE of file %s", filename);
89 FAILF("close of file %s", filename);
92 MPI_Barrier(MPI_COMM_WORLD);
97 while (stride < page_size/2) {
99 stride -= stride % 16;
102 stride %= 2 * lum.lmm_stripe_size;
106 MPI_Barrier(MPI_COMM_WORLD);
108 MPI_Bcast(&stride, 1, MPI_LONG, root, MPI_COMM_WORLD);
111 MPI_Barrier(MPI_COMM_WORLD);
113 buf = (char *)malloc(stride);
115 FAILF("malloc of buf with size %ld", stride);
118 fd = open(filename, O_RDWR);
120 FAILF("open of file %s", filename);
123 fill_stride(buf, stride, 0, off);
124 rc = write(fd, buf, stride);
126 FAILF("write of file %s return %d", filename, rc);
129 while (off < size * stride) {
130 fill_stride(buf, stride, 0x8080808080808080ULL, off);
131 rc = write(fd, buf, stride);
133 FAILF("write of file %s return %d",
139 FAILF("close of file %s", filename);
142 MPI_Barrier(MPI_COMM_WORLD);
144 o_buf = (char *)malloc(stride);
146 FAILF("malloc of o_buf with size %ld", stride);
148 fd = open(filename, O_RDWR);
150 FAILF("open of file %s", filename);
153 for (i = 1; i < size; ++i) {
155 rc = lseek(fd, off, SEEK_SET);
157 FAILF("lseek of file %s return %d",
160 rc = read(fd, buf, stride);
163 fill_stride(o_buf, rc, i - 1, off);
164 dump_diff(o_buf, buf, rc, off);
166 FAILF("read of file %s return %d",
170 fill_stride(o_buf, stride, i - 1, off);
171 if (memcmp(o_buf, buf, stride) != 0) {
172 dump_diff(o_buf, buf, stride, off);
174 FAILF("Error: diff data read from %s",
182 fill_stride(buf, stride, i, off);
183 rc = write(fd, buf, stride);
185 FAILF("write of file %s return %d",
189 MPI_Barrier(MPI_COMM_WORLD);
193 FAILF("close of file %s", filename);
195 MPI_Barrier(MPI_COMM_WORLD);
198 fd = open(filename, O_RDONLY);
200 FAILF("open of file %s", filename);
203 for (i = 0; i < size; ++i) {
204 rc = read(fd, buf, stride);
207 fill_stride(o_buf, rc, i, off);
208 dump_diff(o_buf, buf, rc, off);
210 FAILF("read of file %s", filename);
213 fill_stride(o_buf, stride, i, off);
214 if (memcmp(o_buf, buf, stride) != 0) {
216 dump_diff(o_buf, buf, stride, off);
222 FAILF("Error: diff data read from %s", filename);
226 MPI_Barrier(MPI_COMM_WORLD);
227 fprintf(stderr, "passed barrier 5\n");
233 void cascading_rw(long stride, unsigned int seed)
239 rw_file("cascading_rw", stride, seed);
243 remove_file("cascading_rw");
247 void usage(char *proc)
252 printf("Usage: %s [-h] -d <testdir> [-s \"1024\"]\n", proc);
253 printf(" [-n \"13\"] [-e \"12345\"]\n");
254 printf(" [-v] [-V #] [-g]\n");
255 printf("\t-h: prints this help message\n");
256 printf("\t-d: the directory in which the tests will run\n");
257 printf("\t-s: process stride size\n");
258 printf("\t-n: repeat test # times\n");
259 printf("\t-n: random seed, used to re-create previous runs\n");
260 printf("\t-v: increase the verbositly level by 1\n");
261 printf("\t-V: select a specific verbosity level\n");
262 printf("\t-g: debug mode\n");
271 int main(int argc, char *argv[])
273 int i, iterations = 16, c;
275 unsigned int seed = 0;
278 * Check for -h parameter before MPI_Init so the binary can be
279 * called directly, without, for instance, mpirun
281 for (i = 1; i < argc; ++i) {
282 if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help"))
286 MPI_Init(&argc, &argv);
287 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
288 MPI_Comm_size(MPI_COMM_WORLD, &size);
290 /* Parse command line options */
292 c = getopt(argc, argv, "d:e:ghn:s:vV:");
301 seed = (unsigned int)atoi(optarg);
310 iterations = atoi(optarg);
313 stride = atol(optarg);
319 verbose = atoi(optarg);
325 printf("%s is running with %d process(es) %s\n",
326 argv[0], size, debug ? "in DEBUG mode" : "\b\b");
330 "There should be at least 3 process to run the test!\n");
331 MPI_Abort(MPI_COMM_WORLD, 2);
334 if (testdir == NULL && rank == 0) {
336 "Please specify a test directory! (\"%s -h\" for help)\n",
338 MPI_Abort(MPI_COMM_WORLD, 2);
343 for (i = 0; i < iterations; ++i) {
345 printf("%s: Running test #%s(iter %d)\n",
346 timestamp(), argv[0], i);
348 cascading_rw(stride, seed);
349 MPI_Barrier(MPI_COMM_WORLD);
353 printf("%s: All tests passed!\n", timestamp());