1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/tests/mpi/cascading_rw.c
38 * Author: You Feng <youfeng@clusterfs.com>
46 #include <sys/types.h>
47 #include <asm/types.h>
51 #include <sys/ioctl.h>
55 #include <libcfs/libcfs.h>
61 #include <lustre/liblustreapi.h>
68 void rw_file(char *name, long stride, unsigned int seed)
70 char filename[MAX_FILENAME_LEN];
71 char errmsg[MAX_FILENAME_LEN+20];
73 struct lov_user_md lum = {0};
74 int fd, rc, i, bad = 0, root = 0;
76 long page_size = sysconf(_SC_PAGESIZE);
78 sprintf(filename, "%s/%s", testdir, name);
81 remove_file_or_dir(filename);
83 lum.lmm_magic = LOV_USER_MAGIC;
84 lum.lmm_stripe_size = 0;
85 lum.lmm_stripe_count = 0;
86 lum.lmm_stripe_offset = -1;
88 fd = open(filename, O_CREAT | O_RDWR | O_LOV_DELAY_CREATE,
91 sprintf(errmsg, "open of file %s", filename);
95 rc = ioctl(fd, LL_IOC_LOV_SETSTRIPE, &lum);
97 sprintf(errmsg, "ioctl SETSTRIPE of file %s", filename);
101 if (close(fd) == -1) {
102 sprintf(errmsg, "close of file %s", filename);
107 MPI_Barrier(MPI_COMM_WORLD);
112 while (stride < page_size/2) {
114 stride -= stride % 16;
117 stride %= 2 * lum.lmm_stripe_size;
121 MPI_Barrier(MPI_COMM_WORLD);
123 MPI_Bcast(&stride, 1, MPI_LONG, root, MPI_COMM_WORLD);
126 MPI_Barrier(MPI_COMM_WORLD);
128 buf = (char *)malloc(stride);
130 sprintf(errmsg, "malloc of buf with size %ld", stride);
135 fd = open(filename, O_RDWR);
137 sprintf(errmsg, "open of file %s", filename);
142 fill_stride(buf, stride, 0, off);
143 rc = write(fd, buf, stride);
145 sprintf(errmsg, "write of file %s return %d",
151 while (off < size * stride) {
152 fill_stride(buf, stride, 0x8080808080808080ULL, off);
153 rc = write(fd, buf, stride);
155 sprintf(errmsg, "write of file %s return %d",
163 if (close(fd) == -1) {
164 sprintf(errmsg, "close of file %s", filename);
169 MPI_Barrier(MPI_COMM_WORLD);
171 o_buf = (char *)malloc(stride);
173 sprintf(errmsg, "malloc of o_buf with size %ld", stride);
177 fd = open(filename, O_RDWR);
179 sprintf(errmsg, "open of file %s", filename);
184 for (i = 1; i < size; ++i) {
186 rc = lseek(fd, off, SEEK_SET);
188 sprintf(errmsg, "lseek of file %s return %d",
193 rc = read(fd, buf, stride);
196 fill_stride(o_buf, rc, i - 1, off);
197 dump_diff(o_buf, buf, rc, off);
199 sprintf(errmsg, "read of file %s return %d",
204 fill_stride(o_buf, stride, i - 1, off);
205 if (memcmp(o_buf, buf, stride) != 0) {
206 dump_diff(o_buf, buf, stride, off);
208 sprintf(errmsg, "Error: diff data read from %s",
217 fill_stride(buf, stride, i, off);
218 rc = write(fd, buf, stride);
220 sprintf(errmsg, "write of file %s return %d",
226 MPI_Barrier(MPI_COMM_WORLD);
229 if (close(fd) == -1) {
230 sprintf(errmsg, "close of file %s", filename);
234 MPI_Barrier(MPI_COMM_WORLD);
237 fd = open(filename, O_RDONLY);
239 sprintf(errmsg, "open of file %s", filename);
244 for (i = 0; i < size; ++i) {
245 rc = read(fd, buf, stride);
248 fill_stride(o_buf, rc, i, off);
249 dump_diff(o_buf, buf, rc, off);
251 sprintf(errmsg, "read of file %s", filename);
255 fill_stride(o_buf, stride, i, off);
256 if (memcmp(o_buf, buf, stride) != 0) {
258 dump_diff(o_buf, buf, stride, off);
264 sprintf(errmsg, "Error: diff data read from %s", filename);
269 MPI_Barrier(MPI_COMM_WORLD);
270 fprintf(stderr, "passed barrier 5\n");
276 void cascading_rw(long stride, unsigned int seed)
282 rw_file("cascading_rw", stride, seed);
286 remove_file("cascading_rw");
290 void usage(char *proc)
295 printf("Usage: %s [-h] -d <testdir> [-s \"1024\"]\n", proc);
296 printf(" [-n \"13\"] [-e \"12345\"]\n");
297 printf(" [-v] [-V #] [-g]\n");
298 printf("\t-h: prints this help message\n");
299 printf("\t-d: the directory in which the tests will run\n");
300 printf("\t-s: process stride size\n");
301 printf("\t-n: repeat test # times\n");
302 printf("\t-n: random seed, used to re-create previous runs\n");
303 printf("\t-v: increase the verbositly level by 1\n");
304 printf("\t-V: select a specific verbosity level\n");
305 printf("\t-g: debug mode\n");
309 if (i) MPI_Finalize();
313 int main(int argc, char *argv[])
315 int i, iterations = 16, c;
317 unsigned int seed = 0;
319 /* Check for -h parameter before MPI_Init so the binary can be
320 called directly, without, for instance, mpirun */
321 for (i = 1; i < argc; ++i) {
322 if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help"))
326 MPI_Init(&argc, &argv);
327 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
328 MPI_Comm_size(MPI_COMM_WORLD, &size);
330 /* Parse command line options */
332 c = getopt(argc, argv, "d:e:ghn:s:vV:");
341 seed = (unsigned int)atoi(optarg);
350 iterations = atoi(optarg);
353 stride = atol(optarg);
359 verbose = atoi(optarg);
365 printf("%s is running with %d process(es) %s\n",
366 argv[0], size, debug ? "in DEBUG mode" : "\b\b");
370 "There should be at least 3 process to run the test!\n");
371 MPI_Abort(MPI_COMM_WORLD, 2);
374 if (testdir == NULL && rank == 0) {
375 fprintf(stderr, "Please specify a test directory! (\"%s -h\" for help)\n",
377 MPI_Abort(MPI_COMM_WORLD, 2);
382 for (i = 0; i < iterations; ++i) {
384 printf("%s: Running test #%s(iter %d)\n",
385 timestamp(), argv[0], i);
387 cascading_rw(stride, seed);
388 MPI_Barrier(MPI_COMM_WORLD);
392 printf("%s: All tests passed!\n", timestamp());