1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Lustre Light user test program
6 * Copyright (c) 2002, 2003 Cluster File Systems, Inc.
8 * This file is part of Lustre, http://www.lustre.org.
10 * Lustre is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
14 * Lustre is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Lustre; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 #include <sys/types.h>
35 #include <sys/queue.h>
40 #include <test_common.h>
44 /******************************************************************************/
46 * MPI_CHECK will display a custom error message as well as an error string
47 * from the MPI_STATUS and then exit the program
50 #define MPI_CHECK(MPI_STATUS, MSG) do { \
51 char resultString[MPI_MAX_ERROR_STRING]; \
54 if (MPI_STATUS != MPI_SUCCESS) { \
55 fprintf(stdout, "** error **\n"); \
56 fprintf(stdout, "ERROR in %s (line %d): %s.\n", \
57 __FILE__, __LINE__, MSG); \
58 MPI_Error_string(MPI_STATUS, resultString, &resultLength); \
59 fprintf(stdout, "MPI %s\n", resultString); \
60 fprintf(stdout, "** exiting **\n"); \
61 MPI_Abort(MPI_COMM_WORLD, 1); \
65 int numTasks = 0, /* MPI variables */
67 tasksPerNode = 0; /* tasks per node */
72 static char *test_file_name = "/mnt/lustre/test_lock_cancel";
74 extern void __liblustre_setup_(void);
75 extern void __liblustre_cleanup_(void);
79 printf("Usage: \t%s --target mdsnid:/mdsname/profile\n", cmd);
80 printf(" \t%s --dumpfile dumpfile\n", cmd);
84 int main(int argc, char *argv[])
87 static struct option long_opts[] = {
89 {"dumpfile", 1, 0, 0},
99 while ((c = getopt_long(argc, argv, "", long_opts, &opt_index)) != -1) {
105 if (!strcmp(long_opts[opt_index].name, "target")) {
106 setenv(ENV_LUSTRE_MNTTGT, optarg, 1);
107 } else if (!strcmp(long_opts[opt_index].name, "dumpfile")) {
108 setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);
121 __liblustre_setup_();
123 MPI_CHECK(MPI_Init(&argc, &argv), "MPI_Init()");
124 MPI_CHECK(MPI_Comm_size(MPI_COMM_WORLD, &numTasks), "MPI_Comm_size");
125 MPI_CHECK(MPI_Comm_rank(MPI_COMM_WORLD, &rank), "MPI_Comm_rank");
128 printf("this demo can't run on single node!\n");
133 unlink(test_file_name);
136 MPI_Barrier(MPI_COMM_WORLD);
138 printf("Node 1: creating file %s ...\n", test_file_name);
141 fd = open(test_file_name, O_CREAT|O_RDWR, 0755);
143 printf("Node %d: creat file err: %d", rank, fd);
148 printf("Node 1: done creation. perform stat on file %s ...\n", test_file_name);
151 if (stat(test_file_name, &statbuf)) {
152 printf("Node %d: stat file err: %d", rank, fd);
157 printf("Node %d: done stat on file\n", rank);
160 printf("Node %d: waiting node 1 create & stat file\n", rank);
164 MPI_Barrier(MPI_COMM_WORLD);
167 printf("Node 1: file has been create+stat, abort excution here!!!!!!!\n");
173 printf("Node %d: synced with Node 1. sleep 5 seconds...\n", rank);
176 printf("Node %d: wakeup from sleep. perform unlink()...\n", rank);
180 if (unlink(test_file_name)) {
181 printf("Node %d: error unlink file: %d\n", rank, fd);
186 printf("Node %d: successfully unlink file, cost %ld seconds.\n",
187 rank, time2 - time1);
191 __liblustre_cleanup_();
192 printf("Node %d: end sucessfully.\n", rank);