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/recovery_small.c
36 * Lustre Light user test program
46 #include <sys/types.h>
49 #include <sys/queue.h>
56 #include "test_common.h"
58 #define MAX_STRING_SIZE 2048
65 {"MDS_REQUEST", 0x123},
70 static int drop_index = 0;
72 static char mds_server[1024] = {0, };
73 static char ssh_cmd[MAX_STRING_SIZE] = {0,};
75 int do_stat(const char *name, struct stat *buf)
80 rc = lstat(name, &stat);
82 printf("error %d stat %s\n", rc, name);
86 memcpy(buf, &stat, sizeof(*buf));
91 void prepare_reg(const char *path)
95 fd = open(path, O_RDWR|O_CREAT, 00644);
97 printf("error %d create %s\n", fd, path);
103 printf("error %d close %s\n", rc, path);
108 void cleanup_reg(const char *path)
114 printf("error %d unlink %s\n", rc, path);
119 void prepare_dir(const char *path)
123 rc = mkdir(path, 00644);
125 printf("error %d mkdir %s\n", rc, path);
130 void cleanup_dir(const char *path)
136 printf("error %d unlink %s\n", rc, path);
143 char cmd[MAX_STRING_SIZE]; \
146 if (drop_arr[drop_index].name) { \
147 printf("server drops next %s\n", drop_arr[drop_index].name); \
149 "%s %s \"lctl set_param fail_loc=%lu\"", \
150 ssh_cmd, mds_server, drop_arr[drop_index].code); \
151 if ((rc = system(cmd)) != 0) { \
152 rc = WEXITSTATUS(rc); \
153 printf("error excuting remote command: %d\n", rc); \
163 if (drop_arr[drop_index].name) { \
164 sprintf(cmd, "%s %s \"lctl set_param fail_loc=0\"", \
165 ssh_cmd, mds_server); \
166 if (!system(cmd)) {} \
174 sprintf(buf, "===== START: %s ", (str)); \
177 memset(buf+len, '=', 100-len); \
186 printf("----- END TEST successfully ---"); \
187 printf("-----------------------------"); \
188 printf("-------------------\n"); \
194 char *path="/mnt/lustre/test_t1";
195 ENTRY("create/delete");
208 char *path="/mnt/lustre/test_t2";
209 ENTRY("mkdir/rmdir");
222 char *path="/mnt/lustre/test_t3";
223 ENTRY("regular stat");
227 t_check_stat(path, NULL);
235 char *path="/mnt/lustre/test_t4";
240 t_check_stat(path, NULL);
248 char *path="/mnt/lustre/test_t5";
249 const int bufsize = 4096;
250 char wbuf[bufsize], rbuf[bufsize];
253 ENTRY("sequential page aligned file I/O");
259 for (i = 0; i < npages; i++ ) {
260 memset(wbuf, i, bufsize);
261 rc = write(fd, wbuf, bufsize);
263 printf("write error %d (i = %d)\n", rc, i);
267 printf("succefully write %d pages\n", npages);
269 lseek(fd, 0, SEEK_SET);
271 for (i = 0; i < npages; i++ ) {
272 memset(rbuf, 0, bufsize);
273 rc = read(fd, rbuf, bufsize);
275 printf("read error %d (i = %d)\n", rc, i);
279 printf("succefully read & verified %d pages\n", npages);
289 char *path="/mnt/lustre/test_t6";
290 char *path2="/mnt/lustre/test_t6_link";
295 t_symlink(path, path2);
297 t_check_stat(path2, NULL);
305 char *path="/mnt/lustre/test_t7";
309 t_mknod(path, S_IFCHR | 0644, 5, 4);
311 t_check_stat(path, NULL);
316 extern int libcfs_debug;
317 extern int libcfs_subsystem_debug;
319 extern void __liblustre_setup_(void);
320 extern void __liblustre_cleanup_(void);
322 void usage(const char *cmd)
324 printf("Usage: \t%s -s mds_hostname --target mdsnid:/mdsname/profile\n", cmd);
325 printf(" \t%s -s mds_hostname --dumpfile dumpfile\n", cmd);
329 int main(int argc, char * argv[])
333 static struct option long_opts[] = {
335 {"dumpfile", 1, 0, 0},
340 if (argc < 3 - (getenv(ENV_LUSTRE_MNTTGT)||getenv(ENV_LUSTRE_DUMPFILE)))
343 while ((c = getopt_long(argc, argv, "s:", long_opts, &opt_index)) != -1) {
349 if (!strcmp(long_opts[opt_index].name, "target")) {
350 setenv(ENV_LUSTRE_MNTTGT, optarg, 1);
351 } else if (!strcmp(long_opts[opt_index].name, "dumpfile")) {
352 setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);
353 } else if (!strcmp(long_opts[opt_index].name, "ssh")) {
354 safe_strncpy(ssh_cmd, optarg, MAX_STRING_SIZE);
360 safe_strncpy(mds_server, optarg, MAX_STRING_SIZE);
370 if (strlen(mds_server) == 0)
373 /* default to using ssh */
374 if (!strlen(ssh_cmd)) {
375 safe_strncpy(ssh_cmd, "ssh", MAX_STRING_SIZE);
378 sprintf(cmd, "%s %s cat /dev/null", ssh_cmd, mds_server);
380 printf("Can't access server node: %s using method: %s\n", mds_server, ssh_cmd);
384 setenv(ENV_LUSTRE_TIMEOUT, "5", 1);
386 __liblustre_setup_();
388 while (drop_arr[drop_index].name) {
402 printf("liblustre is about shutdown\n");
403 __liblustre_cleanup_();
405 printf("complete successfully\n");