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/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");
116 t_check_stat_fail("/mnt/lustre/f0");
122 char *path="/mnt/lustre/f1";
123 ENTRY("simple create");
128 t_check_stat(path, NULL);
135 char *path="/mnt/lustre/f2a";
141 t_check_stat(path, NULL);
148 char *path="/mnt/lustre/f2b";
149 ENTRY("mcreate+touch");
155 t_check_stat(path, NULL);
161 void n_create_delete(int nfiles)
163 char *base="/mnt/lustre/f3_";
169 for (i = 0; i < nfiles; i++) {
170 sprintf(path, "%s%d\n", base, i);
171 sprintf(str, "TEST#%d CONTENT\n", i);
172 t_echo_create(path, str);
175 for (i = 0; i < nfiles; i++) {
176 sprintf(path, "%s%d\n", base, i);
177 sprintf(str, "TEST#%d CONTENT\n", i);
181 for (i = 0; i < nfiles; i++) {
182 sprintf(path, "%s%d\n", base, i);
186 for (i = 0; i < nfiles; i++) {
187 sprintf(path, "%s%d\n", base, i);
188 t_check_stat_fail(path);
195 ENTRY("10 create/delete");
202 ENTRY("30 create/delete(>1'st block precreated)");
209 char *dir="/mnt/lustre/d4";
210 char *path="/mnt/lustre/d4/f1";
211 ENTRY("mkdir + contained create");
217 t_check_stat(dir, NULL);
218 t_check_stat(path, NULL);
219 sleep(2); /* wait for log process thread */
225 t_check_stat_fail(dir);
226 t_check_stat_fail(path);
232 char *dir="/mnt/lustre/d5";
233 char *path="/mnt/lustre/d5/f1";
234 ENTRY("mkdir |X| contained create");
240 t_check_stat(dir, NULL);
241 t_check_stat(path, NULL);
249 char *path="/mnt/lustre/f6";
251 ENTRY("open |X| close");
258 t_check_stat(path, NULL);
266 char *path="/mnt/lustre/f7";
267 char *path2="/mnt/lustre/f7-2";
268 ENTRY("create |X| rename unlink");
272 t_rename(path, path2);
274 t_check_stat_fail(path);
275 t_check_stat(path2, NULL);
281 char *path="/mnt/lustre/f8";
282 char *path2="/mnt/lustre/f8-2";
283 ENTRY("create open write rename |X| create-old-name read");
286 t_echo_create(path, "old");
287 t_rename(path, path2);
289 t_echo_create(path, "new");
292 t_grep(path2, "old");
299 char *path="/mnt/lustre/f9";
300 char *path2="/mnt/lustre/f9-2";
301 ENTRY("|X| open(O_CREAT), unlink, touch new, unlink new");
308 t_check_stat_fail(path);
309 t_check_stat(path2, NULL);
315 char *path="/mnt/lustre/f10";
316 char *path2="/mnt/lustre/f10-2";
317 ENTRY("|X| mcreate, open write, rename");
321 t_echo_create(path, "old");
322 t_rename(path, path2);
323 t_grep(path2, "old");
325 t_grep(path2, "old");
329 extern int libcfs_debug;
330 extern int libcfs_subsystem_debug;
332 extern void __liblustre_setup_(void);
333 extern void __liblustre_cleanup_(void);
335 void usage(const char *cmd)
337 printf("Usage: \t%s --target mdsnid:/mdsname/profile -s mds_hostname "
338 "-b \"barrier cmd\" -f \"failover cmd\" [--rsh \"rsh_cmd\"]\n", cmd);
339 printf(" \t%s --dumpfile dumpfile -s mds_hostname -b \"barrier cmd\" "
340 "-f \"failover cmd\" [--rsh \"rsh_cmd\"]\n", cmd);
346 char cmd[MAX_STRING_SIZE];
348 sprintf(cmd, "%s %s cat /dev/null", ssh_cmd, mds_server);
350 printf("Can't access server node: %s using method: %s\n", mds_server, ssh_cmd);
355 int main(int argc, char * const argv[])
358 static struct option long_opts[] = {
360 {"dumpfile", 1, 0, 0},
365 if (argc < 4 - (getenv(ENV_LUSTRE_MNTTGT)||getenv(ENV_LUSTRE_DUMPFILE)))
368 while ((c = getopt_long(argc, argv, "s:b:f:", long_opts, &opt_index)) != -1) {
374 if (!strcmp(long_opts[opt_index].name, "target")) {
375 setenv(ENV_LUSTRE_MNTTGT, optarg, 1);
376 } else if (!strcmp(long_opts[opt_index].name, "dumpfile")) {
377 setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);
378 } else if (!strcmp(long_opts[opt_index].name, "ssh")) {
379 safe_strncpy(ssh_cmd, optarg, MAX_STRING_SIZE);
385 safe_strncpy(mds_server, optarg, MAX_STRING_SIZE);
388 safe_strncpy(barrier_script, optarg, MAX_STRING_SIZE);
391 safe_strncpy(failover_script, optarg, MAX_STRING_SIZE);
400 if (!strlen(mds_server) || !strlen(barrier_script) ||
401 !strlen(failover_script))
404 /* default to using ssh */
405 if (!strlen(ssh_cmd)) {
406 safe_strncpy(ssh_cmd, "ssh", MAX_STRING_SIZE);
411 /* prepare remote command */
412 sprintf(barrier_cmd, "%s %s \"%s\"",
413 ssh_cmd, mds_server, barrier_script);
414 sprintf(failover_cmd, "%s %s \"%s\"",
415 ssh_cmd, mds_server, failover_script);
417 setenv(ENV_LUSTRE_TIMEOUT, "10", 1);
419 __liblustre_setup_();
435 printf("liblustre is about shutdown\n");
436 __liblustre_cleanup_();
438 printf("complete successfully\n");