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.
31 #include <sys/types.h>
34 #include <sys/queue.h>
40 #include "test_common.h"
42 #define MAX_STRING_SIZE 2048
44 static char mds_server[MAX_STRING_SIZE] = {0,};
45 static char barrier_script[MAX_STRING_SIZE] = {0,};
46 static char failover_script[MAX_STRING_SIZE] = {0,};
47 static char barrier_cmd[MAX_STRING_SIZE] = {0,};
48 static char failover_cmd[MAX_STRING_SIZE] = {0,};
49 static char ssh_cmd[MAX_STRING_SIZE] = {0,};
51 static void replay_barrier()
55 if ((rc = system(barrier_cmd))) {
56 printf("excute barrier error: %d\n", rc);
61 static void mds_failover()
65 if ((rc = system(failover_cmd))) {
66 printf("excute failover error: %d\n", rc);
76 sprintf(buf, "===== START: %s ", (str)); \
79 memset(buf+len, '=', 100-len); \
88 printf("----- END TEST successfully ---"); \
89 printf("-----------------------------"); \
90 printf("-------------------\n"); \
95 char *path="/mnt/lustre/f0";
96 ENTRY("empty replay");
99 t_check_stat_fail("/mnt/lustre/f0");
105 char *path="/mnt/lustre/f1";
106 ENTRY("simple create");
111 t_check_stat(path, NULL);
118 char *path="/mnt/lustre/f2a";
124 t_check_stat(path, NULL);
131 char *path="/mnt/lustre/f2b";
132 ENTRY("mcreate+touch");
138 t_check_stat(path, NULL);
144 void n_create_delete(int nfiles)
146 char *base="/mnt/lustre/f3_";
152 for (i = 0; i < nfiles; i++) {
153 sprintf(path, "%s%d\n", base, i);
154 sprintf(str, "TEST#%d CONTENT\n", i);
155 t_echo_create(path, str);
158 for (i = 0; i < nfiles; i++) {
159 sprintf(path, "%s%d\n", base, i);
160 sprintf(str, "TEST#%d CONTENT\n", i);
164 for (i = 0; i < nfiles; i++) {
165 sprintf(path, "%s%d\n", base, i);
169 for (i = 0; i < nfiles; i++) {
170 sprintf(path, "%s%d\n", base, i);
171 t_check_stat_fail(path);
178 ENTRY("10 create/delete");
185 ENTRY("30 create/delete(>1'st block precreated)");
192 char *dir="/mnt/lustre/d4";
193 char *path="/mnt/lustre/d4/f1";
194 ENTRY("mkdir + contained create");
200 t_check_stat(dir, NULL);
201 t_check_stat(path, NULL);
202 sleep(2); /* wait for log process thread */
208 t_check_stat_fail(dir);
209 t_check_stat_fail(path);
215 char *dir="/mnt/lustre/d5";
216 char *path="/mnt/lustre/d5/f1";
217 ENTRY("mkdir |X| contained create");
223 t_check_stat(dir, NULL);
224 t_check_stat(path, NULL);
232 char *path="/mnt/lustre/f6";
234 ENTRY("open |X| close");
241 t_check_stat(path, NULL);
249 char *path="/mnt/lustre/f7";
250 char *path2="/mnt/lustre/f7-2";
251 ENTRY("create |X| rename unlink");
255 t_rename(path, path2);
257 t_check_stat_fail(path);
258 t_check_stat(path2, NULL);
264 char *path="/mnt/lustre/f8";
265 char *path2="/mnt/lustre/f8-2";
266 ENTRY("create open write rename |X| create-old-name read");
269 t_echo_create(path, "old");
270 t_rename(path, path2);
272 t_echo_create(path, "new");
275 t_grep(path2, "old");
282 char *path="/mnt/lustre/f9";
283 char *path2="/mnt/lustre/f9-2";
284 ENTRY("|X| open(O_CREAT), unlink, touch new, unlink new");
291 t_check_stat_fail(path);
292 t_check_stat(path2, NULL);
298 char *path="/mnt/lustre/f10";
299 char *path2="/mnt/lustre/f10-2";
300 ENTRY("|X| mcreate, open write, rename");
304 t_echo_create(path, "old");
305 t_rename(path, path2);
306 t_grep(path2, "old");
308 t_grep(path2, "old");
312 extern int libcfs_debug;
313 extern int libcfs_subsystem_debug;
315 extern void __liblustre_setup_(void);
316 extern void __liblustre_cleanup_(void);
318 void usage(const char *cmd)
320 printf("Usage: \t%s --target mdsnid:/mdsname/profile -s mds_hostname "
321 "-b \"barrier cmd\" -f \"failover cmd\" [--rsh \"rsh_cmd\"]\n", cmd);
322 printf(" \t%s --dumpfile dumpfile -s mds_hostname -b \"barrier cmd\" "
323 "-f \"failover cmd\" [--rsh \"rsh_cmd\"]\n", cmd);
329 char cmd[MAX_STRING_SIZE];
331 sprintf(cmd, "%s %s cat /dev/null", ssh_cmd, mds_server);
333 printf("Can't access server node: %s using method: %s\n", mds_server, ssh_cmd);
338 int main(int argc, char * const argv[])
341 static struct option long_opts[] = {
343 {"dumpfile", 1, 0, 0},
348 if (argc < 4 - (getenv(ENV_LUSTRE_MNTTGT)||getenv(ENV_LUSTRE_DUMPFILE)))
351 while ((c = getopt_long(argc, argv, "s:b:f:", long_opts, &opt_index)) != -1) {
357 if (!strcmp(long_opts[opt_index].name, "target")) {
358 setenv(ENV_LUSTRE_MNTTGT, optarg, 1);
359 } else if (!strcmp(long_opts[opt_index].name, "dumpfile")) {
360 setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);
361 } else if (!strcmp(long_opts[opt_index].name, "ssh")) {
362 safe_strncpy(ssh_cmd, optarg, MAX_STRING_SIZE);
368 safe_strncpy(mds_server, optarg, MAX_STRING_SIZE);
371 safe_strncpy(barrier_script, optarg, MAX_STRING_SIZE);
374 safe_strncpy(failover_script, optarg, MAX_STRING_SIZE);
383 if (!strlen(mds_server) || !strlen(barrier_script) ||
384 !strlen(failover_script))
387 /* default to using ssh */
388 if (!strlen(ssh_cmd)) {
389 safe_strncpy(ssh_cmd, "ssh", MAX_STRING_SIZE);
394 /* prepare remote command */
395 sprintf(barrier_cmd, "%s %s \"%s\"",
396 ssh_cmd, mds_server, barrier_script);
397 sprintf(failover_cmd, "%s %s \"%s\"",
398 ssh_cmd, mds_server, failover_script);
400 setenv(ENV_LUSTRE_TIMEOUT, "10", 1);
402 __liblustre_setup_();
418 printf("liblustre is about shutdown\n");
419 __liblustre_cleanup_();
421 printf("complete successfully\n");