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 2008 Sun Microsystems, Inc. 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>
50 #include <sys/ioctl.h>
58 #include <lustre/liblustreapi.h>
65 void rw_file(char *name, long stride, unsigned int seed)
67 char filename[MAX_FILENAME_LEN];
68 char path[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);
104 strncpy(path, filename, MAX_FILENAME_LEN);
105 rc = llapi_file_get_stripe(path, &lum);
107 sprintf(errmsg, "get stripe of file %s", filename);
112 MPI_Barrier(MPI_COMM_WORLD);
117 while (stride < PAGE_SIZE/2) {
119 stride -= stride % 16;
122 stride %= 2 * lum.lmm_stripe_size;
126 MPI_Barrier(MPI_COMM_WORLD);
128 MPI_Bcast(&stride, 1, MPI_LONG, root, MPI_COMM_WORLD);
131 MPI_Barrier(MPI_COMM_WORLD);
133 buf = (char *)malloc(stride);
135 sprintf(errmsg, "malloc of buf with size %ld", stride);
140 fd = open(filename, O_RDWR);
142 sprintf(errmsg, "open of file %s", filename);
147 fill_stride(buf, stride, 0, off);
148 rc = write(fd, buf, stride);
150 sprintf(errmsg, "write of file %s return %d",
156 while (off < size * stride) {
157 fill_stride(buf, stride, 0x8080808080808080ULL, off);
158 rc = write(fd, buf, stride);
160 sprintf(errmsg, "write of file %s return %d",
168 if (close(fd) == -1) {
169 sprintf(errmsg, "close of file %s", filename);
174 MPI_Barrier(MPI_COMM_WORLD);
176 o_buf = (char *)malloc(stride);
178 sprintf(errmsg, "malloc of o_buf with size %ld", stride);
182 fd = open(filename, O_RDWR);
184 sprintf(errmsg, "open of file %s", filename);
189 for (i = 1; i < size; ++i) {
191 rc = lseek(fd, off, SEEK_SET);
193 sprintf(errmsg, "lseek of file %s return %d",
198 rc = read(fd, buf, stride);
201 fill_stride(o_buf, rc, i - 1, off);
202 dump_diff(o_buf, buf, rc, off);
204 sprintf(errmsg, "read of file %s return %d",
209 fill_stride(o_buf, stride, i - 1, off);
210 if (memcmp(o_buf, buf, stride) != 0) {
211 dump_diff(o_buf, buf, stride, off);
213 sprintf(errmsg, "Error: diff data read from %s",
222 fill_stride(buf, stride, i, off);
223 rc = write(fd, buf, stride);
225 sprintf(errmsg, "write of file %s return %d",
231 MPI_Barrier(MPI_COMM_WORLD);
234 if (close(fd) == -1) {
235 sprintf(errmsg, "close of file %s", filename);
239 MPI_Barrier(MPI_COMM_WORLD);
242 fd = open(filename, O_RDONLY);
244 sprintf(errmsg, "open of file %s", filename);
249 for (i = 0; i < size; ++i) {
250 rc = read(fd, buf, stride);
253 fill_stride(o_buf, rc, i, off);
254 dump_diff(o_buf, buf, rc, off);
256 sprintf(errmsg, "read of file %s", filename);
260 fill_stride(o_buf, stride, i, off);
261 if (memcmp(o_buf, buf, stride) != 0) {
263 dump_diff(o_buf, buf, stride, off);
269 sprintf(errmsg, "Error: diff data read from %s", filename);
274 MPI_Barrier(MPI_COMM_WORLD);
275 fprintf(stderr, "passed barrier 5\n");
281 void cascading_rw(long stride, unsigned int seed)
287 rw_file("cascading_rw", stride, seed);
291 remove_file("cascading_rw");
295 void usage(char *proc)
300 printf("Usage: %s [-h] -d <testdir> [-s \"1024\"]\n", proc);
301 printf(" [-n \"13\"] [-e \"12345\"]\n");
302 printf(" [-v] [-V #] [-g]\n");
303 printf("\t-h: prints this help message\n");
304 printf("\t-d: the directory in which the tests will run\n");
305 printf("\t-s: process stride size\n");
306 printf("\t-n: repeat test # times\n");
307 printf("\t-n: random seed, used to re-create previous runs\n");
308 printf("\t-v: increase the verbositly level by 1\n");
309 printf("\t-V: select a specific verbosity level\n");
310 printf("\t-g: debug mode\n");
314 if (i) MPI_Finalize();
318 int main(int argc, char *argv[])
320 int i, iterations = 16;
323 unsigned int seed = 0;
325 /* Check for -h parameter before MPI_Init so the binary can be
326 called directly, without, for instance, mpirun */
327 for (i = 1; i < argc; ++i) {
328 if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help"))
332 MPI_Init(&argc, &argv);
333 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
334 MPI_Comm_size(MPI_COMM_WORLD, &size);
336 /* Parse command line options */
338 c = getopt(argc, argv, "d:e:ghn:s:vV:");
347 seed = (unsigned int)atoi(optarg);
356 iterations = atoi(optarg);
359 stride = atol(optarg);
365 verbose = atoi(optarg);
371 printf("%s is running with %d process(es) %s\n",
372 argv[0], size, debug ? "in DEBUG mode" : "\b\b");
376 "There should be at least 3 process to run the test!\n");
377 MPI_Abort(MPI_COMM_WORLD, 2);
380 if (testdir == NULL && rank == 0) {
381 fprintf(stderr, "Please specify a test directory! (\"%s -h\" for help)\n",
383 MPI_Abort(MPI_COMM_WORLD, 2);
388 for (i = 0; i < iterations; ++i) {
390 printf("%s: Running test #%s(iter %d)\n",
391 timestamp(), argv[0], i);
393 cascading_rw(stride, seed);
394 MPI_Barrier(MPI_COMM_WORLD);
398 printf("%s: All tests passed!\n", timestamp());