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 (c) 2003, 2010, Oracle and/or its affiliates. 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/replay_single.c
38 * Lustre Light user test program
48 #include <sys/types.h>
51 #include <sys/queue.h>
57 #include "test_common.h"
59 #define MAX_STRING_SIZE 2048
61 static char mds_server[MAX_STRING_SIZE] = {0,};
62 static char barrier_script[MAX_STRING_SIZE] = {0,};
63 static char failover_script[MAX_STRING_SIZE] = {0,};
64 static char barrier_cmd[MAX_STRING_SIZE] = {0,};
65 static char failover_cmd[MAX_STRING_SIZE] = {0,};
66 static char ssh_cmd[MAX_STRING_SIZE] = {0,};
68 static void replay_barrier()
72 if ((rc = system(barrier_cmd))) {
73 printf("excute barrier error: %d\n", rc);
78 static void mds_failover()
82 if ((rc = system(failover_cmd))) {
83 printf("excute failover error: %d\n", rc);
93 sprintf(buf, "===== START: %s ", (str)); \
96 memset(buf+len, '=', 100-len); \
105 printf("----- END TEST successfully ---"); \
106 printf("-----------------------------"); \
107 printf("-------------------\n"); \
112 char *path="/mnt/lustre/f0";
113 ENTRY("empty replay");
117 t_check_stat_fail(path);
123 char *path="/mnt/lustre/f1";
124 ENTRY("simple create");
129 t_check_stat(path, NULL);
136 char *path="/mnt/lustre/f2a";
142 t_check_stat(path, NULL);
149 char *path="/mnt/lustre/f2b";
150 ENTRY("mcreate+touch");
156 t_check_stat(path, NULL);
162 void n_create_delete(int nfiles)
164 char *base="/mnt/lustre/f3_";
170 for (i = 0; i < nfiles; i++) {
171 sprintf(path, "%s%d\n", base, i);
172 sprintf(str, "TEST#%d CONTENT\n", i);
173 t_echo_create(path, str);
176 for (i = 0; i < nfiles; i++) {
177 sprintf(path, "%s%d\n", base, i);
178 sprintf(str, "TEST#%d CONTENT\n", i);
182 for (i = 0; i < nfiles; i++) {
183 sprintf(path, "%s%d\n", base, i);
187 for (i = 0; i < nfiles; i++) {
188 sprintf(path, "%s%d\n", base, i);
189 t_check_stat_fail(path);
196 ENTRY("10 create/delete");
203 ENTRY("30 create/delete(>1'st block precreated)");
210 char *dir="/mnt/lustre/d4";
211 char *path="/mnt/lustre/d4/f1";
212 ENTRY("mkdir + contained create");
218 t_check_stat(dir, NULL);
219 t_check_stat(path, NULL);
220 sleep(2); /* wait for log process thread */
226 t_check_stat_fail(dir);
227 t_check_stat_fail(path);
233 char *dir="/mnt/lustre/d5";
234 char *path="/mnt/lustre/d5/f1";
235 ENTRY("mkdir |X| contained create");
241 t_check_stat(dir, NULL);
242 t_check_stat(path, NULL);
250 char *path="/mnt/lustre/f6";
252 ENTRY("open |X| close");
259 t_check_stat(path, NULL);
267 char *path="/mnt/lustre/f7";
268 char *path2="/mnt/lustre/f7-2";
269 ENTRY("create |X| rename unlink");
273 t_rename(path, path2);
275 t_check_stat_fail(path);
276 t_check_stat(path2, NULL);
282 char *path="/mnt/lustre/f8";
283 char *path2="/mnt/lustre/f8-2";
284 ENTRY("create open write rename |X| create-old-name read");
287 t_echo_create(path, "old");
288 t_rename(path, path2);
290 t_echo_create(path, "new");
293 t_grep(path2, "old");
300 char *path="/mnt/lustre/f9";
301 char *path2="/mnt/lustre/f9-2";
302 ENTRY("|X| open(O_CREAT), unlink, touch new, unlink new");
309 t_check_stat_fail(path);
310 t_check_stat(path2, NULL);
316 char *path="/mnt/lustre/f10";
317 char *path2="/mnt/lustre/f10-2";
318 ENTRY("|X| mcreate, open write, rename");
322 t_echo_create(path, "old");
323 t_rename(path, path2);
324 t_grep(path2, "old");
326 t_grep(path2, "old");
330 extern int libcfs_debug;
331 extern int libcfs_subsystem_debug;
333 extern void __liblustre_setup_(void);
334 extern void __liblustre_cleanup_(void);
336 void usage(const char *cmd)
338 printf("Usage: \t%s --target mdsnid:/mdsname/profile -s mds_hostname "
339 "-b \"barrier cmd\" -f \"failover cmd\" [--rsh \"rsh_cmd\"]\n", cmd);
340 printf(" \t%s --dumpfile dumpfile -s mds_hostname -b \"barrier cmd\" "
341 "-f \"failover cmd\" [--rsh \"rsh_cmd\"]\n", cmd);
347 char cmd[MAX_STRING_SIZE];
349 sprintf(cmd, "%s %s cat /dev/null", ssh_cmd, mds_server);
351 printf("Can't access server node: %s using method: %s\n", mds_server, ssh_cmd);
356 int main(int argc, char * const argv[])
359 static struct option long_opts[] = {
361 {"dumpfile", 1, 0, 0},
366 if (argc < 4 - (getenv(ENV_LUSTRE_MNTTGT)||getenv(ENV_LUSTRE_DUMPFILE)))
369 while ((c = getopt_long(argc, argv, "s:b:f:", long_opts, &opt_index)) != -1) {
375 if (!strcmp(long_opts[opt_index].name, "target")) {
376 setenv(ENV_LUSTRE_MNTTGT, optarg, 1);
377 } else if (!strcmp(long_opts[opt_index].name, "dumpfile")) {
378 setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);
379 } else if (!strcmp(long_opts[opt_index].name, "ssh")) {
380 safe_strncpy(ssh_cmd, optarg, MAX_STRING_SIZE);
386 safe_strncpy(mds_server, optarg, MAX_STRING_SIZE);
389 safe_strncpy(barrier_script, optarg, MAX_STRING_SIZE);
392 safe_strncpy(failover_script, optarg, MAX_STRING_SIZE);
401 if (!strlen(mds_server) || !strlen(barrier_script) ||
402 !strlen(failover_script))
405 /* default to using ssh */
406 if (!strlen(ssh_cmd)) {
407 safe_strncpy(ssh_cmd, "ssh", MAX_STRING_SIZE);
412 /* prepare remote command */
413 sprintf(barrier_cmd, "%s %s \"%s\"",
414 ssh_cmd, mds_server, barrier_script);
415 sprintf(failover_cmd, "%s %s \"%s\"",
416 ssh_cmd, mds_server, failover_script);
418 setenv(ENV_LUSTRE_TIMEOUT, "10", 1);
420 __liblustre_setup_();
436 printf("liblustre is about shutdown\n");
437 __liblustre_cleanup_();
439 printf("complete successfully\n");