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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
31 * This file is part of Lustre, http://www.lustre.org/
32 * Lustre is a trademark of Sun Microsystems, Inc.
34 * lustre/tests/mpi/cascading_rw.c
36 * Author: You Feng <youfeng@clusterfs.com>
44 #include <sys/types.h>
45 #include <asm/types.h>
49 #include <sys/ioctl.h>
53 #include <libcfs/libcfs.h>
59 #include <lustre/liblustreapi.h>
66 void rw_file(char *name, long stride, unsigned int seed)
68 char filename[MAX_FILENAME_LEN];
69 char errmsg[MAX_FILENAME_LEN+20];
71 struct lov_user_md lum = {0};
72 int fd, rc, i, bad = 0, root = 0;
74 long page_size = sysconf(_SC_PAGESIZE);
76 sprintf(filename, "%s/%s", testdir, name);
79 remove_file_or_dir(filename);
81 lum.lmm_magic = LOV_USER_MAGIC;
82 lum.lmm_stripe_size = 0;
83 lum.lmm_stripe_count = 0;
84 lum.lmm_stripe_offset = -1;
86 fd = open(filename, O_CREAT | O_RDWR | O_LOV_DELAY_CREATE,
89 sprintf(errmsg, "open of file %s", filename);
93 rc = ioctl(fd, LL_IOC_LOV_SETSTRIPE, &lum);
95 sprintf(errmsg, "ioctl SETSTRIPE of file %s", filename);
99 if (close(fd) == -1) {
100 sprintf(errmsg, "close of file %s", filename);
105 MPI_Barrier(MPI_COMM_WORLD);
110 while (stride < page_size/2) {
112 stride -= stride % 16;
115 stride %= 2 * lum.lmm_stripe_size;
119 MPI_Barrier(MPI_COMM_WORLD);
121 MPI_Bcast(&stride, 1, MPI_LONG, root, MPI_COMM_WORLD);
124 MPI_Barrier(MPI_COMM_WORLD);
126 buf = (char *)malloc(stride);
128 sprintf(errmsg, "malloc of buf with size %ld", stride);
133 fd = open(filename, O_RDWR);
135 sprintf(errmsg, "open of file %s", filename);
140 fill_stride(buf, stride, 0, off);
141 rc = write(fd, buf, stride);
143 sprintf(errmsg, "write of file %s return %d",
149 while (off < size * stride) {
150 fill_stride(buf, stride, 0x8080808080808080ULL, off);
151 rc = write(fd, buf, stride);
153 sprintf(errmsg, "write of file %s return %d",
161 if (close(fd) == -1) {
162 sprintf(errmsg, "close of file %s", filename);
167 MPI_Barrier(MPI_COMM_WORLD);
169 o_buf = (char *)malloc(stride);
171 sprintf(errmsg, "malloc of o_buf with size %ld", stride);
175 fd = open(filename, O_RDWR);
177 sprintf(errmsg, "open of file %s", filename);
182 for (i = 1; i < size; ++i) {
184 rc = lseek(fd, off, SEEK_SET);
186 sprintf(errmsg, "lseek of file %s return %d",
191 rc = read(fd, buf, stride);
194 fill_stride(o_buf, rc, i - 1, off);
195 dump_diff(o_buf, buf, rc, off);
197 sprintf(errmsg, "read of file %s return %d",
202 fill_stride(o_buf, stride, i - 1, off);
203 if (memcmp(o_buf, buf, stride) != 0) {
204 dump_diff(o_buf, buf, stride, off);
206 sprintf(errmsg, "Error: diff data read from %s",
215 fill_stride(buf, stride, i, off);
216 rc = write(fd, buf, stride);
218 sprintf(errmsg, "write of file %s return %d",
224 MPI_Barrier(MPI_COMM_WORLD);
227 if (close(fd) == -1) {
228 sprintf(errmsg, "close of file %s", filename);
232 MPI_Barrier(MPI_COMM_WORLD);
235 fd = open(filename, O_RDONLY);
237 sprintf(errmsg, "open of file %s", filename);
242 for (i = 0; i < size; ++i) {
243 rc = read(fd, buf, stride);
246 fill_stride(o_buf, rc, i, off);
247 dump_diff(o_buf, buf, rc, off);
249 sprintf(errmsg, "read of file %s", filename);
253 fill_stride(o_buf, stride, i, off);
254 if (memcmp(o_buf, buf, stride) != 0) {
256 dump_diff(o_buf, buf, stride, off);
262 sprintf(errmsg, "Error: diff data read from %s", filename);
267 MPI_Barrier(MPI_COMM_WORLD);
268 fprintf(stderr, "passed barrier 5\n");
274 void cascading_rw(long stride, unsigned int seed)
280 rw_file("cascading_rw", stride, seed);
284 remove_file("cascading_rw");
288 void usage(char *proc)
293 printf("Usage: %s [-h] -d <testdir> [-s \"1024\"]\n", proc);
294 printf(" [-n \"13\"] [-e \"12345\"]\n");
295 printf(" [-v] [-V #] [-g]\n");
296 printf("\t-h: prints this help message\n");
297 printf("\t-d: the directory in which the tests will run\n");
298 printf("\t-s: process stride size\n");
299 printf("\t-n: repeat test # times\n");
300 printf("\t-n: random seed, used to re-create previous runs\n");
301 printf("\t-v: increase the verbositly level by 1\n");
302 printf("\t-V: select a specific verbosity level\n");
303 printf("\t-g: debug mode\n");
307 if (i) MPI_Finalize();
311 int main(int argc, char *argv[])
313 int i, iterations = 16, c;
315 unsigned int seed = 0;
317 /* Check for -h parameter before MPI_Init so the binary can be
318 called directly, without, for instance, mpirun */
319 for (i = 1; i < argc; ++i) {
320 if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help"))
324 MPI_Init(&argc, &argv);
325 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
326 MPI_Comm_size(MPI_COMM_WORLD, &size);
328 /* Parse command line options */
330 c = getopt(argc, argv, "d:e:ghn:s:vV:");
339 seed = (unsigned int)atoi(optarg);
348 iterations = atoi(optarg);
351 stride = atol(optarg);
357 verbose = atoi(optarg);
363 printf("%s is running with %d process(es) %s\n",
364 argv[0], size, debug ? "in DEBUG mode" : "\b\b");
368 "There should be at least 3 process to run the test!\n");
369 MPI_Abort(MPI_COMM_WORLD, 2);
372 if (testdir == NULL && rank == 0) {
373 fprintf(stderr, "Please specify a test directory! (\"%s -h\" for help)\n",
375 MPI_Abort(MPI_COMM_WORLD, 2);
380 for (i = 0; i < iterations; ++i) {
382 printf("%s: Running test #%s(iter %d)\n",
383 timestamp(), argv[0], i);
385 cascading_rw(stride, seed);
386 MPI_Barrier(MPI_COMM_WORLD);
390 printf("%s: All tests passed!\n", timestamp());