1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Lustre Light user test program
6 * Copyright (c) 2002, 2003 Cluster File Systems, Inc.
8 * This file is part of Lustre, http://www.lustre.org.
10 * Lustre is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
14 * Lustre is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Lustre; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 #include <sys/types.h>
34 #include <sys/queue.h>
40 #include "test_common.h"
44 static char mds_server[1024] = {0,};
45 static char barrier_script[1024] = {0,};
46 static char failover_script[1024] = {0,};
47 static char barrier_cmd[1024] = {0,};
48 static char failover_cmd[1024] = {0,};
50 static void replay_barrier()
54 if ((rc = system(barrier_cmd))) {
55 printf("excute barrier error: %d\n", rc);
60 static void mds_failover()
64 if ((rc = system(failover_cmd))) {
65 printf("excute failover error: %d\n", rc);
75 sprintf(buf, "===== START: %s ", (str)); \
78 memset(buf+len, '=', 100-len); \
87 printf("----- END TEST successfully ---"); \
88 printf("-----------------------------"); \
89 printf("-------------------\n"); \
94 const int bufsize = 4096;
95 char *path = "/mnt/lustre/rp_ost_t0_file";
98 ENTRY("open-failover-write-verification (no ping involved)");
100 printf("create/open file...\n");
103 printf("OST failover...\n");
107 printf("write file...\n");
108 for (i = 0; i < 20; i++) {
109 memset(buf, i, bufsize);
110 if ((rc = write(fd, buf, bufsize)) != bufsize) {
111 perror("write error after failover");
112 printf("i = %d, rc = %d\n", i, rc);
118 printf("read & verify...\n");
119 lseek(fd, 0, SEEK_SET);
120 for (i = 0; i < 20; i++) {
121 memset(buf, -1, bufsize);
122 if ((rc = read(fd, buf, bufsize)) != bufsize) {
123 perror("read error rc");
124 printf("i = %d, rc = %d\n", i, rc);
127 for (j = 0; j < bufsize; j++) {
129 printf("verify error!\n");
141 const int bufsize = 4096;
142 char *path = "/mnt/lustre/rp_ost_t1_file";
145 ENTRY("open-write-close-open-failover-read (no ping involved)");
147 printf("create/open file...\n");
150 printf("write file...\n");
151 for (i = 0; i < 20; i++) {
152 memset(buf, i, bufsize);
153 if (write(fd, buf, bufsize) != bufsize) {
154 perror("write error");
158 printf("close/reopen...\n");
161 lseek(fd, 0, SEEK_SET);
163 printf("OST failover...\n");
167 printf("read & verify...\n");
168 for (i = 0; i < 20; i++) {
169 memset(buf, -1, bufsize);
170 if (read(fd, buf, bufsize) != bufsize) {
171 perror("read error after failover");
174 for (j = 0; j < bufsize; j++) {
176 printf("verify error after failover\n");
189 char *path = "/mnt/lustre/rp_ost_t2_file";
190 char *str = "xxxxjoiwlsdf98lsjdfsjfoajflsjfajfoaidfojaj08eorje;";
191 ENTRY("empty replay");
196 t_echo_create(path, str);
203 char *path = "/mnt/lustre/rp_ost_t3_file";
204 char *str = "xxxxjoiwlsdf98lsjdfsjfoajflsjfajfoaidfojaj08eorje;";
207 printf("touch to create a file\n");
208 t_echo_create(path, str);
212 printf("read & verify\n");
215 /* XXX have problem without this, seems server side problem XXX */
221 char *path = "/mnt/lustre/rp_ost_t4_file";
225 ENTRY("|X| 10 open(CREAT)s (ping involved)");
227 printf("create %d files\n", count);
228 for (i = 0; i < count; i++) {
229 sprintf(namebuf, "%s%02d", path, i);
230 sprintf(str, "%s-%08d-%08x-AAAAA", "content", i, i);
231 t_echo_create(namebuf, str);
236 printf("read & verify\n");
237 for (i = 0; i < count; i++) {
238 sprintf(namebuf, "%s%02d", path, i);
239 sprintf(str, "%s-%08d-%08x-AAAAA", "content", i, i);
240 t_grep(namebuf, str);
245 extern int portal_debug;
246 extern int portal_subsystem_debug;
248 extern void __liblustre_setup_(void);
249 extern void __liblustre_cleanup_(void);
251 void usage(const char *cmd)
253 printf("Usage: \t%s --target mdsnid:/mdsname/profile -s ost_hostname "
254 "-b \"barrier cmd\" -f \"failover cmd\"\n", cmd);
255 printf(" \t%s --dumpfile dumpfile -s ost_hostname -b \"barrier cmd\" "
256 "-f \"failover cmd\"\n", cmd);
264 sprintf(cmd, "ssh %s cat /dev/null", mds_server);
266 printf("ssh can't access server node: %s\n", mds_server);
271 int main(int argc, char * const argv[])
274 static struct option long_opts[] = {
276 {"dumpfile", 1, 0, 0},
283 while ((c = getopt_long(argc, argv, "s:b:f:", long_opts, &opt_index)) != -1) {
289 if (!strcmp(long_opts[opt_index].name, "target")) {
290 setenv(ENV_LUSTRE_MNTTGT, optarg, 1);
291 } else if (!strcmp(long_opts[opt_index].name, "dumpfile")) {
292 setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);
298 strcpy(mds_server, optarg);
301 strcpy(barrier_script, optarg);
304 strcpy(failover_script, optarg);
313 if (!strlen(mds_server) || !strlen(barrier_script) ||
314 !strlen(failover_script))
319 /* prepare remote command */
320 sprintf(barrier_cmd, "ssh %s \"%s\"", mds_server, barrier_script);
321 sprintf(failover_cmd, "ssh %s \"%s\"", mds_server, failover_script);
323 setenv(ENV_LUSTRE_TIMEOUT, "5", 1);
325 __liblustre_setup_();
333 printf("liblustre is about shutdown\n");
334 __liblustre_cleanup_();
336 printf("complete successfully\n");