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/liblustre/tests/test_lock_cancel.c
38 * Lustre Light user test program
49 #include <sys/types.h>
52 #include <sys/queue.h>
57 #include <test_common.h>
61 /******************************************************************************/
63 * MPI_CHECK will display a custom error message as well as an error string
64 * from the MPI_STATUS and then exit the program
67 #define MPI_CHECK(MPI_STATUS, MSG) do { \
68 char resultString[MPI_MAX_ERROR_STRING]; \
71 if (MPI_STATUS != MPI_SUCCESS) { \
72 fprintf(stdout, "** error **\n"); \
73 fprintf(stdout, "ERROR in %s (line %d): %s.\n", \
74 __FILE__, __LINE__, MSG); \
75 MPI_Error_string(MPI_STATUS, resultString, &resultLength); \
76 fprintf(stdout, "MPI %s\n", resultString); \
77 fprintf(stdout, "** exiting **\n"); \
78 MPI_Abort(MPI_COMM_WORLD, 1); \
82 int numTasks = 0, /* MPI variables */
84 tasksPerNode = 0; /* tasks per node */
89 static char *test_file_name = "/mnt/lustre/test_lock_cancel";
91 extern void __liblustre_setup_(void);
92 extern void __liblustre_cleanup_(void);
96 printf("Usage: \t%s --target mdsnid:/mdsname/profile\n", cmd);
97 printf(" \t%s --dumpfile dumpfile\n", cmd);
101 int main(int argc, char *argv[])
104 static struct option long_opts[] = {
106 {"dumpfile", 1, 0, 0},
116 while ((c = getopt_long(argc, argv, "", long_opts, &opt_index)) != -1) {
122 if (!strcmp(long_opts[opt_index].name, "target")) {
123 setenv(ENV_LUSTRE_MNTTGT, optarg, 1);
124 } else if (!strcmp(long_opts[opt_index].name, "dumpfile")) {
125 setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);
138 __liblustre_setup_();
140 MPI_CHECK(MPI_Init(&argc, &argv), "MPI_Init()");
141 MPI_CHECK(MPI_Comm_size(MPI_COMM_WORLD, &numTasks), "MPI_Comm_size");
142 MPI_CHECK(MPI_Comm_rank(MPI_COMM_WORLD, &rank), "MPI_Comm_rank");
145 printf("this demo can't run on single node!\n");
150 unlink(test_file_name);
153 MPI_Barrier(MPI_COMM_WORLD);
155 printf("Node 1: creating file %s ...\n", test_file_name);
158 fd = open(test_file_name, O_CREAT|O_RDWR, 0755);
160 printf("Node %d: creat file err: %d", rank, fd);
165 printf("Node 1: done creation. perform stat on file %s ...\n", test_file_name);
168 if (stat(test_file_name, &statbuf)) {
169 printf("Node %d: stat file err: %d", rank, fd);
174 printf("Node %d: done stat on file\n", rank);
177 printf("Node %d: waiting node 1 create & stat file\n", rank);
181 MPI_Barrier(MPI_COMM_WORLD);
184 printf("Node 1: file has been create+stat, abort excution here!!!!!!!\n");
190 printf("Node %d: synced with Node 1. sleep 5 seconds...\n", rank);
193 printf("Node %d: wakeup from sleep. perform unlink()...\n", rank);
197 if (unlink(test_file_name)) {
198 printf("Node %d: error unlink file: %d\n", rank, fd);
203 printf("Node %d: successfully unlink file, cost %ld seconds.\n",
204 rank, time2 - time1);
208 __liblustre_cleanup_();
209 printf("Node %d: end sucessfully.\n", rank);