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_ost_single.c
36 * Lustre Light user test program
46 #include <sys/types.h>
49 #include <sys/queue.h>
55 #include "test_common.h"
59 static char mds_server[1024] = {0,};
60 static char barrier_script[1024] = {0,};
61 static char failover_script[1024] = {0,};
62 static char barrier_cmd[1024] = {0,};
63 static char failover_cmd[1024] = {0,};
65 static void replay_barrier()
69 if ((rc = system(barrier_cmd))) {
70 printf("excute barrier error: %d\n", rc);
75 static void mds_failover()
79 if ((rc = system(failover_cmd))) {
80 printf("excute failover error: %d\n", rc);
90 sprintf(buf, "===== START: %s ", (str)); \
93 memset(buf+len, '=', 100-len); \
102 printf("----- END TEST successfully ---"); \
103 printf("-----------------------------"); \
104 printf("-------------------\n"); \
109 const int bufsize = 4096;
110 char *path = "/mnt/lustre/rp_ost_t0_file";
113 ENTRY("open-failover-write-verification (no ping involved)");
115 printf("create/open file...\n");
118 printf("OST failover...\n");
122 printf("write file...\n");
123 for (i = 0; i < 20; i++) {
124 memset(buf, i, bufsize);
125 if ((rc = write(fd, buf, bufsize)) != bufsize) {
126 perror("write error after failover");
127 printf("i = %d, rc = %d\n", i, rc);
133 printf("read & verify...\n");
134 lseek(fd, 0, SEEK_SET);
135 for (i = 0; i < 20; i++) {
136 memset(buf, -1, bufsize);
137 if ((rc = read(fd, buf, bufsize)) != bufsize) {
138 perror("read error rc");
139 printf("i = %d, rc = %d\n", i, rc);
142 for (j = 0; j < bufsize; j++) {
144 printf("verify error!\n");
156 const int bufsize = 4096;
157 char *path = "/mnt/lustre/rp_ost_t1_file";
160 ENTRY("open-write-close-open-failover-read (no ping involved)");
162 printf("create/open file...\n");
165 printf("write file...\n");
166 for (i = 0; i < 20; i++) {
167 memset(buf, i, bufsize);
168 if (write(fd, buf, bufsize) != bufsize) {
169 perror("write error");
173 printf("close/reopen...\n");
176 lseek(fd, 0, SEEK_SET);
178 printf("OST failover...\n");
182 printf("read & verify...\n");
183 for (i = 0; i < 20; i++) {
184 memset(buf, -1, bufsize);
185 if (read(fd, buf, bufsize) != bufsize) {
186 perror("read error after failover");
189 for (j = 0; j < bufsize; j++) {
191 printf("verify error after failover\n");
204 char *path = "/mnt/lustre/rp_ost_t2_file";
205 char *str = "xxxxjoiwlsdf98lsjdfsjfoajflsjfajfoaidfojaj08eorje;";
206 ENTRY("empty replay");
211 t_echo_create(path, str);
218 char *path = "/mnt/lustre/rp_ost_t3_file";
219 char *str = "xxxxjoiwlsdf98lsjdfsjfoajflsjfajfoaidfojaj08eorje;";
222 printf("touch to create a file\n");
223 t_echo_create(path, str);
227 printf("read & verify\n");
230 /* XXX have problem without this, seems server side problem XXX */
236 char *path = "/mnt/lustre/rp_ost_t4_file";
240 ENTRY("|X| 10 open(CREAT)s (ping involved)");
242 printf("create %d files\n", count);
243 for (i = 0; i < count; i++) {
244 sprintf(namebuf, "%s%02d", path, i);
245 sprintf(str, "%s-%08d-%08x-AAAAA", "content", i, i);
246 t_echo_create(namebuf, str);
251 printf("read & verify\n");
252 for (i = 0; i < count; i++) {
253 sprintf(namebuf, "%s%02d", path, i);
254 sprintf(str, "%s-%08d-%08x-AAAAA", "content", i, i);
255 t_grep(namebuf, str);
260 extern int libcfs_debug;
261 extern int libcfs_subsystem_debug;
263 extern void __liblustre_setup_(void);
264 extern void __liblustre_cleanup_(void);
266 void usage(const char *cmd)
268 printf("Usage: \t%s --target mdsnid:/mdsname/profile -s ost_hostname "
269 "-b \"barrier cmd\" -f \"failover cmd\"\n", cmd);
270 printf(" \t%s --dumpfile dumpfile -s ost_hostname -b \"barrier cmd\" "
271 "-f \"failover cmd\"\n", cmd);
279 sprintf(cmd, "ssh %s cat /dev/null", mds_server);
281 printf("ssh can't access server node: %s\n", mds_server);
286 int main(int argc, char * const argv[])
289 static struct option long_opts[] = {
291 {"dumpfile", 1, 0, 0},
298 while ((c = getopt_long(argc, argv, "s:b:f:", long_opts, &opt_index)) != -1) {
304 if (!strcmp(long_opts[opt_index].name, "target")) {
305 setenv(ENV_LUSTRE_MNTTGT, optarg, 1);
306 } else if (!strcmp(long_opts[opt_index].name, "dumpfile")) {
307 setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);
313 strcpy(mds_server, optarg);
316 strcpy(barrier_script, optarg);
319 strcpy(failover_script, optarg);
328 if (!strlen(mds_server) || !strlen(barrier_script) ||
329 !strlen(failover_script))
334 /* prepare remote command */
335 sprintf(barrier_cmd, "ssh %s \"%s\"", mds_server, barrier_script);
336 sprintf(failover_cmd, "ssh %s \"%s\"", mds_server, failover_script);
338 setenv(ENV_LUSTRE_TIMEOUT, "5", 1);
340 __liblustre_setup_();
348 printf("liblustre is about shutdown\n");
349 __liblustre_cleanup_();
351 printf("complete successfully\n");