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 <lustre/lustreapi.h>
65 void rw_file(char *name, long stride, unsigned int seed)
67 char filename[MAX_FILENAME_LEN];
68 char errmsg[MAX_FILENAME_LEN+20];
70 struct lov_user_md lum = {0};
71 int fd, rc, i, bad = 0, root = 0;
73 long page_size = sysconf(_SC_PAGESIZE);
75 sprintf(filename, "%s/%s", testdir, name);
78 remove_file_or_dir(filename);
80 lum.lmm_magic = LOV_USER_MAGIC;
81 lum.lmm_stripe_size = 0;
82 lum.lmm_stripe_count = 0;
83 lum.lmm_stripe_offset = -1;
85 fd = open(filename, O_CREAT | O_RDWR | O_LOV_DELAY_CREATE,
88 sprintf(errmsg, "open of file %s", filename);
92 rc = ioctl(fd, LL_IOC_LOV_SETSTRIPE, &lum);
94 sprintf(errmsg, "ioctl SETSTRIPE of file %s", filename);
98 if (close(fd) == -1) {
99 sprintf(errmsg, "close of file %s", filename);
104 MPI_Barrier(MPI_COMM_WORLD);
109 while (stride < page_size/2) {
111 stride -= stride % 16;
114 stride %= 2 * lum.lmm_stripe_size;
118 MPI_Barrier(MPI_COMM_WORLD);
120 MPI_Bcast(&stride, 1, MPI_LONG, root, MPI_COMM_WORLD);
123 MPI_Barrier(MPI_COMM_WORLD);
125 buf = (char *)malloc(stride);
127 sprintf(errmsg, "malloc of buf with size %ld", stride);
132 fd = open(filename, O_RDWR);
134 sprintf(errmsg, "open of file %s", filename);
139 fill_stride(buf, stride, 0, off);
140 rc = write(fd, buf, stride);
142 sprintf(errmsg, "write of file %s return %d",
148 while (off < size * stride) {
149 fill_stride(buf, stride, 0x8080808080808080ULL, off);
150 rc = write(fd, buf, stride);
152 sprintf(errmsg, "write of file %s return %d",
160 if (close(fd) == -1) {
161 sprintf(errmsg, "close of file %s", filename);
166 MPI_Barrier(MPI_COMM_WORLD);
168 o_buf = (char *)malloc(stride);
170 sprintf(errmsg, "malloc of o_buf with size %ld", stride);
174 fd = open(filename, O_RDWR);
176 sprintf(errmsg, "open of file %s", filename);
181 for (i = 1; i < size; ++i) {
183 rc = lseek(fd, off, SEEK_SET);
185 sprintf(errmsg, "lseek of file %s return %d",
190 rc = read(fd, buf, stride);
193 fill_stride(o_buf, rc, i - 1, off);
194 dump_diff(o_buf, buf, rc, off);
196 sprintf(errmsg, "read of file %s return %d",
201 fill_stride(o_buf, stride, i - 1, off);
202 if (memcmp(o_buf, buf, stride) != 0) {
203 dump_diff(o_buf, buf, stride, off);
205 sprintf(errmsg, "Error: diff data read from %s",
214 fill_stride(buf, stride, i, off);
215 rc = write(fd, buf, stride);
217 sprintf(errmsg, "write of file %s return %d",
223 MPI_Barrier(MPI_COMM_WORLD);
226 if (close(fd) == -1) {
227 sprintf(errmsg, "close of file %s", filename);
231 MPI_Barrier(MPI_COMM_WORLD);
234 fd = open(filename, O_RDONLY);
236 sprintf(errmsg, "open of file %s", filename);
241 for (i = 0; i < size; ++i) {
242 rc = read(fd, buf, stride);
245 fill_stride(o_buf, rc, i, off);
246 dump_diff(o_buf, buf, rc, off);
248 sprintf(errmsg, "read of file %s", filename);
252 fill_stride(o_buf, stride, i, off);
253 if (memcmp(o_buf, buf, stride) != 0) {
255 dump_diff(o_buf, buf, stride, off);
261 sprintf(errmsg, "Error: diff data read from %s", filename);
266 MPI_Barrier(MPI_COMM_WORLD);
267 fprintf(stderr, "passed barrier 5\n");
273 void cascading_rw(long stride, unsigned int seed)
279 rw_file("cascading_rw", stride, seed);
283 remove_file("cascading_rw");
287 void usage(char *proc)
292 printf("Usage: %s [-h] -d <testdir> [-s \"1024\"]\n", proc);
293 printf(" [-n \"13\"] [-e \"12345\"]\n");
294 printf(" [-v] [-V #] [-g]\n");
295 printf("\t-h: prints this help message\n");
296 printf("\t-d: the directory in which the tests will run\n");
297 printf("\t-s: process stride size\n");
298 printf("\t-n: repeat test # times\n");
299 printf("\t-n: random seed, used to re-create previous runs\n");
300 printf("\t-v: increase the verbositly level by 1\n");
301 printf("\t-V: select a specific verbosity level\n");
302 printf("\t-g: debug mode\n");
306 if (i) MPI_Finalize();
310 int main(int argc, char *argv[])
312 int i, iterations = 16, c;
314 unsigned int seed = 0;
316 /* Check for -h parameter before MPI_Init so the binary can be
317 called directly, without, for instance, mpirun */
318 for (i = 1; i < argc; ++i) {
319 if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help"))
323 MPI_Init(&argc, &argv);
324 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
325 MPI_Comm_size(MPI_COMM_WORLD, &size);
327 /* Parse command line options */
329 c = getopt(argc, argv, "d:e:ghn:s:vV:");
338 seed = (unsigned int)atoi(optarg);
347 iterations = atoi(optarg);
350 stride = atol(optarg);
356 verbose = atoi(optarg);
362 printf("%s is running with %d process(es) %s\n",
363 argv[0], size, debug ? "in DEBUG mode" : "\b\b");
367 "There should be at least 3 process to run the test!\n");
368 MPI_Abort(MPI_COMM_WORLD, 2);
371 if (testdir == NULL && rank == 0) {
372 fprintf(stderr, "Please specify a test directory! (\"%s -h\" for help)\n",
374 MPI_Abort(MPI_COMM_WORLD, 2);
379 for (i = 0; i < iterations; ++i) {
381 printf("%s: Running test #%s(iter %d)\n",
382 timestamp(), argv[0], i);
384 cascading_rw(stride, seed);
385 MPI_Barrier(MPI_COMM_WORLD);
389 printf("%s: All tests passed!\n", timestamp());