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_ost_single.c
38 * Lustre Light user test program
48 #include <sys/types.h>
51 #include <sys/queue.h>
57 #include "test_common.h"
61 static char mds_server[1024] = {0,};
62 static char barrier_script[1024] = {0,};
63 static char failover_script[1024] = {0,};
64 static char barrier_cmd[1024] = {0,};
65 static char failover_cmd[1024] = {0,};
67 static void replay_barrier()
71 if ((rc = system(barrier_cmd))) {
72 printf("excute barrier error: %d\n", rc);
77 static void mds_failover()
81 if ((rc = system(failover_cmd))) {
82 printf("excute failover error: %d\n", rc);
92 sprintf(buf, "===== START: %s ", (str)); \
95 memset(buf+len, '=', 100-len); \
104 printf("----- END TEST successfully ---"); \
105 printf("-----------------------------"); \
106 printf("-------------------\n"); \
111 const int bufsize = 4096;
112 char *path = "/mnt/lustre/rp_ost_t0_file";
115 ENTRY("open-failover-write-verification (no ping involved)");
117 printf("create/open file...\n");
120 printf("OST failover...\n");
124 printf("write file...\n");
125 for (i = 0; i < 20; i++) {
126 memset(buf, i, bufsize);
127 if ((rc = write(fd, buf, bufsize)) != bufsize) {
128 perror("write error after failover");
129 printf("i = %d, rc = %d\n", i, rc);
135 printf("read & verify...\n");
136 lseek(fd, 0, SEEK_SET);
137 for (i = 0; i < 20; i++) {
138 memset(buf, -1, bufsize);
139 if ((rc = read(fd, buf, bufsize)) != bufsize) {
140 perror("read error rc");
141 printf("i = %d, rc = %d\n", i, rc);
144 for (j = 0; j < bufsize; j++) {
146 printf("verify error!\n");
158 const int bufsize = 4096;
159 char *path = "/mnt/lustre/rp_ost_t1_file";
162 ENTRY("open-write-close-open-failover-read (no ping involved)");
164 printf("create/open file...\n");
167 printf("write file...\n");
168 for (i = 0; i < 20; i++) {
169 memset(buf, i, bufsize);
170 if (write(fd, buf, bufsize) != bufsize) {
171 perror("write error");
175 printf("close/reopen...\n");
178 lseek(fd, 0, SEEK_SET);
180 printf("OST failover...\n");
184 printf("read & verify...\n");
185 for (i = 0; i < 20; i++) {
186 memset(buf, -1, bufsize);
187 if (read(fd, buf, bufsize) != bufsize) {
188 perror("read error after failover");
191 for (j = 0; j < bufsize; j++) {
193 printf("verify error after failover\n");
206 char *path = "/mnt/lustre/rp_ost_t2_file";
207 char *str = "xxxxjoiwlsdf98lsjdfsjfoajflsjfajfoaidfojaj08eorje;";
208 ENTRY("empty replay");
213 t_echo_create(path, str);
220 char *path = "/mnt/lustre/rp_ost_t3_file";
221 char *str = "xxxxjoiwlsdf98lsjdfsjfoajflsjfajfoaidfojaj08eorje;";
224 printf("touch to create a file\n");
225 t_echo_create(path, str);
229 printf("read & verify\n");
232 /* XXX have problem without this, seems server side problem XXX */
238 char *path = "/mnt/lustre/rp_ost_t4_file";
242 ENTRY("|X| 10 open(CREAT)s (ping involved)");
244 printf("create %d files\n", count);
245 for (i = 0; i < count; i++) {
246 sprintf(namebuf, "%s%02d", path, i);
247 sprintf(str, "%s-%08d-%08x-AAAAA", "content", i, i);
248 t_echo_create(namebuf, str);
253 printf("read & verify\n");
254 for (i = 0; i < count; i++) {
255 sprintf(namebuf, "%s%02d", path, i);
256 sprintf(str, "%s-%08d-%08x-AAAAA", "content", i, i);
257 t_grep(namebuf, str);
262 extern int libcfs_debug;
263 extern int libcfs_subsystem_debug;
265 extern void __liblustre_setup_(void);
266 extern void __liblustre_cleanup_(void);
268 void usage(const char *cmd)
270 printf("Usage: \t%s --target mdsnid:/mdsname/profile -s ost_hostname "
271 "-b \"barrier cmd\" -f \"failover cmd\"\n", cmd);
272 printf(" \t%s --dumpfile dumpfile -s ost_hostname -b \"barrier cmd\" "
273 "-f \"failover cmd\"\n", cmd);
281 sprintf(cmd, "ssh %s cat /dev/null", mds_server);
283 printf("ssh can't access server node: %s\n", mds_server);
288 int main(int argc, char * const argv[])
291 static struct option long_opts[] = {
293 {"dumpfile", 1, 0, 0},
300 while ((c = getopt_long(argc, argv, "s:b:f:", long_opts, &opt_index)) != -1) {
306 if (!strcmp(long_opts[opt_index].name, "target")) {
307 setenv(ENV_LUSTRE_MNTTGT, optarg, 1);
308 } else if (!strcmp(long_opts[opt_index].name, "dumpfile")) {
309 setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);
315 strcpy(mds_server, optarg);
318 strcpy(barrier_script, optarg);
321 strcpy(failover_script, optarg);
330 if (!strlen(mds_server) || !strlen(barrier_script) ||
331 !strlen(failover_script))
336 /* prepare remote command */
337 sprintf(barrier_cmd, "ssh %s \"%s\"", mds_server, barrier_script);
338 sprintf(failover_cmd, "ssh %s \"%s\"", mds_server, failover_script);
340 setenv(ENV_LUSTRE_TIMEOUT, "5", 1);
342 __liblustre_setup_();
350 printf("liblustre is about shutdown\n");
351 __liblustre_cleanup_();
353 printf("complete successfully\n");