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/replay_single.c
36 * Lustre Light user test program
46 #include <sys/types.h>
49 #include <sys/queue.h>
55 #include "test_common.h"
57 #define MAX_STRING_SIZE 2048
59 static char mds_server[MAX_STRING_SIZE] = {0,};
60 static char barrier_script[MAX_STRING_SIZE] = {0,};
61 static char failover_script[MAX_STRING_SIZE] = {0,};
62 static char barrier_cmd[MAX_STRING_SIZE] = {0,};
63 static char failover_cmd[MAX_STRING_SIZE] = {0,};
64 static char ssh_cmd[MAX_STRING_SIZE] = {0,};
66 static void replay_barrier()
70 if ((rc = system(barrier_cmd))) {
71 printf("excute barrier error: %d\n", rc);
76 static void mds_failover()
80 if ((rc = system(failover_cmd))) {
81 printf("excute failover error: %d\n", rc);
91 sprintf(buf, "===== START: %s ", (str)); \
94 memset(buf+len, '=', 100-len); \
103 printf("----- END TEST successfully ---"); \
104 printf("-----------------------------"); \
105 printf("-------------------\n"); \
110 char *path="/mnt/lustre/f0";
111 ENTRY("empty replay");
115 t_check_stat_fail(path);
121 char *path="/mnt/lustre/f1";
122 ENTRY("simple create");
127 t_check_stat(path, NULL);
134 char *path="/mnt/lustre/f2a";
140 t_check_stat(path, NULL);
147 char *path="/mnt/lustre/f2b";
148 ENTRY("mcreate+touch");
154 t_check_stat(path, NULL);
160 void n_create_delete(int nfiles)
162 char *base="/mnt/lustre/f3_";
168 for (i = 0; i < nfiles; i++) {
169 sprintf(path, "%s%d\n", base, i);
170 sprintf(str, "TEST#%d CONTENT\n", i);
171 t_echo_create(path, str);
174 for (i = 0; i < nfiles; i++) {
175 sprintf(path, "%s%d\n", base, i);
176 sprintf(str, "TEST#%d CONTENT\n", i);
180 for (i = 0; i < nfiles; i++) {
181 sprintf(path, "%s%d\n", base, i);
185 for (i = 0; i < nfiles; i++) {
186 sprintf(path, "%s%d\n", base, i);
187 t_check_stat_fail(path);
194 ENTRY("10 create/delete");
201 ENTRY("30 create/delete(>1'st block precreated)");
208 char *dir="/mnt/lustre/d4";
209 char *path="/mnt/lustre/d4/f1";
210 ENTRY("mkdir + contained create");
216 t_check_stat(dir, NULL);
217 t_check_stat(path, NULL);
218 sleep(2); /* wait for log process thread */
224 t_check_stat_fail(dir);
225 t_check_stat_fail(path);
231 char *dir="/mnt/lustre/d5";
232 char *path="/mnt/lustre/d5/f1";
233 ENTRY("mkdir |X| contained create");
239 t_check_stat(dir, NULL);
240 t_check_stat(path, NULL);
248 char *path="/mnt/lustre/f6";
250 ENTRY("open |X| close");
257 t_check_stat(path, NULL);
265 char *path="/mnt/lustre/f7";
266 char *path2="/mnt/lustre/f7-2";
267 ENTRY("create |X| rename unlink");
271 t_rename(path, path2);
273 t_check_stat_fail(path);
274 t_check_stat(path2, NULL);
280 char *path="/mnt/lustre/f8";
281 char *path2="/mnt/lustre/f8-2";
282 ENTRY("create open write rename |X| create-old-name read");
285 t_echo_create(path, "old");
286 t_rename(path, path2);
288 t_echo_create(path, "new");
291 t_grep(path2, "old");
298 char *path="/mnt/lustre/f9";
299 char *path2="/mnt/lustre/f9-2";
300 ENTRY("|X| open(O_CREAT), unlink, touch new, unlink new");
307 t_check_stat_fail(path);
308 t_check_stat(path2, NULL);
314 char *path="/mnt/lustre/f10";
315 char *path2="/mnt/lustre/f10-2";
316 ENTRY("|X| mcreate, open write, rename");
320 t_echo_create(path, "old");
321 t_rename(path, path2);
322 t_grep(path2, "old");
324 t_grep(path2, "old");
328 extern int libcfs_debug;
329 extern int libcfs_subsystem_debug;
331 extern void __liblustre_setup_(void);
332 extern void __liblustre_cleanup_(void);
334 void usage(const char *cmd)
336 printf("Usage: \t%s --target mdsnid:/mdsname/profile -s mds_hostname "
337 "-b \"barrier cmd\" -f \"failover cmd\" [--rsh \"rsh_cmd\"]\n", cmd);
338 printf(" \t%s --dumpfile dumpfile -s mds_hostname -b \"barrier cmd\" "
339 "-f \"failover cmd\" [--rsh \"rsh_cmd\"]\n", cmd);
345 char cmd[MAX_STRING_SIZE];
347 sprintf(cmd, "%s %s cat /dev/null", ssh_cmd, mds_server);
349 printf("Can't access server node: %s using method: %s\n", mds_server, ssh_cmd);
354 int main(int argc, char * const argv[])
357 static struct option long_opts[] = {
359 {"dumpfile", 1, 0, 0},
364 if (argc < 4 - (getenv(ENV_LUSTRE_MNTTGT)||getenv(ENV_LUSTRE_DUMPFILE)))
367 while ((c = getopt_long(argc, argv, "s:b:f:", long_opts, &opt_index)) != -1) {
373 if (!strcmp(long_opts[opt_index].name, "target")) {
374 setenv(ENV_LUSTRE_MNTTGT, optarg, 1);
375 } else if (!strcmp(long_opts[opt_index].name, "dumpfile")) {
376 setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);
377 } else if (!strcmp(long_opts[opt_index].name, "ssh")) {
378 safe_strncpy(ssh_cmd, optarg, MAX_STRING_SIZE);
384 safe_strncpy(mds_server, optarg, MAX_STRING_SIZE);
387 safe_strncpy(barrier_script, optarg, MAX_STRING_SIZE);
390 safe_strncpy(failover_script, optarg, MAX_STRING_SIZE);
399 if (!strlen(mds_server) || !strlen(barrier_script) ||
400 !strlen(failover_script))
403 /* default to using ssh */
404 if (!strlen(ssh_cmd)) {
405 safe_strncpy(ssh_cmd, "ssh", MAX_STRING_SIZE);
410 /* prepare remote command */
411 sprintf(barrier_cmd, "%s %s \"%s\"",
412 ssh_cmd, mds_server, barrier_script);
413 sprintf(failover_cmd, "%s %s \"%s\"",
414 ssh_cmd, mds_server, failover_script);
416 setenv(ENV_LUSTRE_TIMEOUT, "10", 1);
418 __liblustre_setup_();
434 printf("liblustre is about shutdown\n");
435 __liblustre_cleanup_();
437 printf("complete successfully\n");