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/recovery_small.c
38 * Lustre Light user test program
48 #include <sys/types.h>
51 #include <sys/queue.h>
58 #include "test_common.h"
60 #define MAX_STRING_SIZE 2048
67 {"MDS_REQUEST", 0x123},
72 static int drop_index = 0;
74 static char mds_server[1024] = {0, };
75 static char ssh_cmd[MAX_STRING_SIZE] = {0,};
77 int do_stat(const char *name, struct stat *buf)
82 rc = lstat(name, &stat);
84 printf("error %d stat %s\n", rc, name);
88 memcpy(buf, &stat, sizeof(*buf));
93 void prepare_reg(const char *path)
97 fd = open(path, O_RDWR|O_CREAT, 00644);
99 printf("error %d create %s\n", fd, path);
105 printf("error %d close %s\n", rc, path);
110 void cleanup_reg(const char *path)
116 printf("error %d unlink %s\n", rc, path);
121 void prepare_dir(const char *path)
125 rc = mkdir(path, 00644);
127 printf("error %d mkdir %s\n", rc, path);
132 void cleanup_dir(const char *path)
138 printf("error %d unlink %s\n", rc, path);
145 char cmd[MAX_STRING_SIZE]; \
148 if (drop_arr[drop_index].name) { \
149 printf("server drops next %s\n", drop_arr[drop_index].name); \
151 "%s %s \"echo %lu > /proc/sys/lustre/fail_loc\"", \
152 ssh_cmd, mds_server, drop_arr[drop_index].code); \
153 if ((rc = system(cmd)) != 0) { \
154 rc = WEXITSTATUS(rc); \
155 printf("error excuting remote command: %d\n", rc); \
165 if (drop_arr[drop_index].name) { \
166 sprintf(cmd, "%s %s \"echo 0 > /proc/sys/lustre/fail_loc\"", \
167 ssh_cmd, mds_server); \
168 if (!system(cmd)) {} \
176 sprintf(buf, "===== START: %s ", (str)); \
179 memset(buf+len, '=', 100-len); \
188 printf("----- END TEST successfully ---"); \
189 printf("-----------------------------"); \
190 printf("-------------------\n"); \
196 char *path="/mnt/lustre/test_t1";
197 ENTRY("create/delete");
210 char *path="/mnt/lustre/test_t2";
211 ENTRY("mkdir/rmdir");
224 char *path="/mnt/lustre/test_t3";
225 ENTRY("regular stat");
229 t_check_stat(path, NULL);
237 char *path="/mnt/lustre/test_t4";
242 t_check_stat(path, NULL);
250 char *path="/mnt/lustre/test_t5";
251 const int bufsize = 4096;
252 char wbuf[bufsize], rbuf[bufsize];
255 ENTRY("sequential page aligned file I/O");
261 for (i = 0; i < npages; i++ ) {
262 memset(wbuf, i, bufsize);
263 rc = write(fd, wbuf, bufsize);
265 printf("write error %d (i = %d)\n", rc, i);
269 printf("succefully write %d pages\n", npages);
271 lseek(fd, 0, SEEK_SET);
273 for (i = 0; i < npages; i++ ) {
274 memset(rbuf, 0, bufsize);
275 rc = read(fd, rbuf, bufsize);
277 printf("read error %d (i = %d)\n", rc, i);
281 printf("succefully read & verified %d pages\n", npages);
291 char *path="/mnt/lustre/test_t6";
292 char *path2="/mnt/lustre/test_t6_link";
297 t_symlink(path, path2);
299 t_check_stat(path2, NULL);
307 char *path="/mnt/lustre/test_t7";
311 t_mknod(path, S_IFCHR | 0644, 5, 4);
313 t_check_stat(path, NULL);
318 extern int libcfs_debug;
319 extern int libcfs_subsystem_debug;
321 extern void __liblustre_setup_(void);
322 extern void __liblustre_cleanup_(void);
324 void usage(const char *cmd)
326 printf("Usage: \t%s -s mds_hostname --target mdsnid:/mdsname/profile\n", cmd);
327 printf(" \t%s -s mds_hostname --dumpfile dumpfile\n", cmd);
331 int main(int argc, char * argv[])
335 static struct option long_opts[] = {
337 {"dumpfile", 1, 0, 0},
342 if (argc < 3 - (getenv(ENV_LUSTRE_MNTTGT)||getenv(ENV_LUSTRE_DUMPFILE)))
345 while ((c = getopt_long(argc, argv, "s:", long_opts, &opt_index)) != -1) {
351 if (!strcmp(long_opts[opt_index].name, "target")) {
352 setenv(ENV_LUSTRE_MNTTGT, optarg, 1);
353 } else if (!strcmp(long_opts[opt_index].name, "dumpfile")) {
354 setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);
355 } else if (!strcmp(long_opts[opt_index].name, "ssh")) {
356 safe_strncpy(ssh_cmd, optarg, MAX_STRING_SIZE);
362 safe_strncpy(mds_server, optarg, MAX_STRING_SIZE);
372 if (strlen(mds_server) == 0)
375 /* default to using ssh */
376 if (!strlen(ssh_cmd)) {
377 safe_strncpy(ssh_cmd, "ssh", MAX_STRING_SIZE);
380 sprintf(cmd, "%s %s cat /dev/null", ssh_cmd, mds_server);
382 printf("Can't access server node: %s using method: %s\n", mds_server, ssh_cmd);
386 setenv(ENV_LUSTRE_TIMEOUT, "5", 1);
388 __liblustre_setup_();
390 while (drop_arr[drop_index].name) {
404 printf("liblustre is about shutdown\n");
405 __liblustre_cleanup_();
407 printf("complete successfully\n");