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) 2003, 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/liblustre/tests/test_lock_cancel.c
36 * Lustre Light user test program
47 #include <sys/types.h>
50 #include <sys/queue.h>
55 #include <../test_common.h>
59 /******************************************************************************/
61 * MPI_CHECK will display a custom error message as well as an error string
62 * from the MPI_STATUS and then exit the program
65 #define MPI_CHECK(MPI_STATUS, MSG) do { \
66 char resultString[MPI_MAX_ERROR_STRING]; \
69 if (MPI_STATUS != MPI_SUCCESS) { \
70 fprintf(stdout, "** error **\n"); \
71 fprintf(stdout, "ERROR in %s (line %d): %s.\n", \
72 __FILE__, __LINE__, MSG); \
73 MPI_Error_string(MPI_STATUS, resultString, &resultLength); \
74 fprintf(stdout, "MPI %s\n", resultString); \
75 fprintf(stdout, "** exiting **\n"); \
76 MPI_Abort(MPI_COMM_WORLD, 1); \
80 int numTasks = 0, /* MPI variables */
82 tasksPerNode = 0; /* tasks per node */
87 static char *test_file_name = "/mnt/lustre/test_lock_cancel";
89 extern void __liblustre_setup_(void);
90 extern void __liblustre_cleanup_(void);
94 printf("Usage: \t%s --target mdsnid:/mdsname/profile\n", cmd);
95 printf(" \t%s --dumpfile dumpfile\n", cmd);
99 int main(int argc, char *argv[])
102 static struct option long_opts[] = {
104 {"dumpfile", 1, 0, 0},
114 while ((c = getopt_long(argc, argv, "", long_opts, &opt_index)) != -1) {
120 if (!strcmp(long_opts[opt_index].name, "target")) {
121 setenv(ENV_LUSTRE_MNTTGT, optarg, 1);
122 } else if (!strcmp(long_opts[opt_index].name, "dumpfile")) {
123 setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);
136 __liblustre_setup_();
138 MPI_CHECK(MPI_Init(&argc, &argv), "MPI_Init()");
139 MPI_CHECK(MPI_Comm_size(MPI_COMM_WORLD, &numTasks), "MPI_Comm_size");
140 MPI_CHECK(MPI_Comm_rank(MPI_COMM_WORLD, &rank), "MPI_Comm_rank");
143 printf("this demo can't run on single node!\n");
148 unlink(test_file_name);
151 MPI_Barrier(MPI_COMM_WORLD);
153 printf("Node 1: creating file %s ...\n", test_file_name);
156 fd = open(test_file_name, O_CREAT|O_RDWR, 0755);
158 printf("Node %d: creat file err: %d", rank, fd);
163 printf("Node 1: done creation. perform stat on file %s ...\n", test_file_name);
166 if (stat(test_file_name, &statbuf)) {
167 printf("Node %d: stat file err: %d", rank, fd);
172 printf("Node %d: done stat on file\n", rank);
175 printf("Node %d: waiting node 1 create & stat file\n", rank);
179 MPI_Barrier(MPI_COMM_WORLD);
182 printf("Node 1: file has been create+stat, abort excution here!!!!!!!\n");
188 printf("Node %d: synced with Node 1. sleep 5 seconds...\n", rank);
191 printf("Node %d: wakeup from sleep. perform unlink()...\n", rank);
195 if (unlink(test_file_name)) {
196 printf("Node %d: error unlink file: %s\n", rank, test_file_name);
201 printf("Node %d: successfully unlink file, cost %ld seconds.\n",
202 rank, time2 - time1);
206 __liblustre_cleanup_();
207 printf("Node %d: end sucessfully.\n", rank);