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];
64 char errmsg[MAX_FILENAME_LEN+20];
66 struct lov_user_md lum = {0};
67 int fd, rc, i, bad = 0, root = 0;
69 long page_size = sysconf(_SC_PAGESIZE);
71 sprintf(filename, "%s/%s", testdir, name);
74 remove_file_or_dir(filename);
76 lum.lmm_magic = LOV_USER_MAGIC;
77 lum.lmm_stripe_size = 0;
78 lum.lmm_stripe_count = 0;
79 lum.lmm_stripe_offset = -1;
81 fd = open(filename, O_CREAT | O_RDWR | O_LOV_DELAY_CREATE,
84 sprintf(errmsg, "open of file %s", filename);
88 rc = ioctl(fd, LL_IOC_LOV_SETSTRIPE, &lum);
90 sprintf(errmsg, "ioctl SETSTRIPE of file %s", filename);
94 if (close(fd) == -1) {
95 sprintf(errmsg, "close of file %s", filename);
100 MPI_Barrier(MPI_COMM_WORLD);
105 while (stride < page_size/2) {
107 stride -= stride % 16;
110 stride %= 2 * lum.lmm_stripe_size;
114 MPI_Barrier(MPI_COMM_WORLD);
116 MPI_Bcast(&stride, 1, MPI_LONG, root, MPI_COMM_WORLD);
119 MPI_Barrier(MPI_COMM_WORLD);
121 buf = (char *)malloc(stride);
123 sprintf(errmsg, "malloc of buf with size %ld", stride);
128 fd = open(filename, O_RDWR);
130 sprintf(errmsg, "open of file %s", filename);
135 fill_stride(buf, stride, 0, off);
136 rc = write(fd, buf, stride);
138 sprintf(errmsg, "write of file %s return %d",
144 while (off < size * stride) {
145 fill_stride(buf, stride, 0x8080808080808080ULL, off);
146 rc = write(fd, buf, stride);
148 sprintf(errmsg, "write of file %s return %d",
156 if (close(fd) == -1) {
157 sprintf(errmsg, "close of file %s", filename);
162 MPI_Barrier(MPI_COMM_WORLD);
164 o_buf = (char *)malloc(stride);
166 sprintf(errmsg, "malloc of o_buf with size %ld", stride);
170 fd = open(filename, O_RDWR);
172 sprintf(errmsg, "open of file %s", filename);
177 for (i = 1; i < size; ++i) {
179 rc = lseek(fd, off, SEEK_SET);
181 sprintf(errmsg, "lseek of file %s return %d",
186 rc = read(fd, buf, stride);
189 fill_stride(o_buf, rc, i - 1, off);
190 dump_diff(o_buf, buf, rc, off);
192 sprintf(errmsg, "read of file %s return %d",
197 fill_stride(o_buf, stride, i - 1, off);
198 if (memcmp(o_buf, buf, stride) != 0) {
199 dump_diff(o_buf, buf, stride, off);
201 sprintf(errmsg, "Error: diff data read from %s",
210 fill_stride(buf, stride, i, off);
211 rc = write(fd, buf, stride);
213 sprintf(errmsg, "write of file %s return %d",
219 MPI_Barrier(MPI_COMM_WORLD);
222 if (close(fd) == -1) {
223 sprintf(errmsg, "close of file %s", filename);
227 MPI_Barrier(MPI_COMM_WORLD);
230 fd = open(filename, O_RDONLY);
232 sprintf(errmsg, "open of file %s", filename);
237 for (i = 0; i < size; ++i) {
238 rc = read(fd, buf, stride);
241 fill_stride(o_buf, rc, i, off);
242 dump_diff(o_buf, buf, rc, off);
244 sprintf(errmsg, "read of file %s", filename);
248 fill_stride(o_buf, stride, i, off);
249 if (memcmp(o_buf, buf, stride) != 0) {
251 dump_diff(o_buf, buf, stride, off);
257 sprintf(errmsg, "Error: diff data read from %s", filename);
262 MPI_Barrier(MPI_COMM_WORLD);
263 fprintf(stderr, "passed barrier 5\n");
269 void cascading_rw(long stride, unsigned int seed)
275 rw_file("cascading_rw", stride, seed);
279 remove_file("cascading_rw");
283 void usage(char *proc)
288 printf("Usage: %s [-h] -d <testdir> [-s \"1024\"]\n", proc);
289 printf(" [-n \"13\"] [-e \"12345\"]\n");
290 printf(" [-v] [-V #] [-g]\n");
291 printf("\t-h: prints this help message\n");
292 printf("\t-d: the directory in which the tests will run\n");
293 printf("\t-s: process stride size\n");
294 printf("\t-n: repeat test # times\n");
295 printf("\t-n: random seed, used to re-create previous runs\n");
296 printf("\t-v: increase the verbositly level by 1\n");
297 printf("\t-V: select a specific verbosity level\n");
298 printf("\t-g: debug mode\n");
302 if (i) MPI_Finalize();
306 int main(int argc, char *argv[])
308 int i, iterations = 16, c;
310 unsigned int seed = 0;
312 /* Check for -h parameter before MPI_Init so the binary can be
313 called directly, without, for instance, mpirun */
314 for (i = 1; i < argc; ++i) {
315 if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help"))
319 MPI_Init(&argc, &argv);
320 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
321 MPI_Comm_size(MPI_COMM_WORLD, &size);
323 /* Parse command line options */
325 c = getopt(argc, argv, "d:e:ghn:s:vV:");
334 seed = (unsigned int)atoi(optarg);
343 iterations = atoi(optarg);
346 stride = atol(optarg);
352 verbose = atoi(optarg);
358 printf("%s is running with %d process(es) %s\n",
359 argv[0], size, debug ? "in DEBUG mode" : "\b\b");
363 "There should be at least 3 process to run the test!\n");
364 MPI_Abort(MPI_COMM_WORLD, 2);
367 if (testdir == NULL && rank == 0) {
368 fprintf(stderr, "Please specify a test directory! (\"%s -h\" for help)\n",
370 MPI_Abort(MPI_COMM_WORLD, 2);
375 for (i = 0; i < iterations; ++i) {
377 printf("%s: Running test #%s(iter %d)\n",
378 timestamp(), argv[0], i);
380 cascading_rw(stride, seed);
381 MPI_Barrier(MPI_COMM_WORLD);
385 printf("%s: All tests passed!\n", timestamp());