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>
57 #include "test_common.h"
59 #define MAX_STRING_SIZE 2048
66 {"MDS_REQUEST", 0x123},
71 static int drop_index = 0;
73 static char mds_server[1024] = {0, };
74 static char ssh_cmd[MAX_STRING_SIZE] = {0,};
76 int do_stat(const char *name, struct stat *buf)
81 rc = lstat(name, &stat);
83 printf("error %d stat %s\n", rc, name);
87 memcpy(buf, &stat, sizeof(*buf));
92 void prepare_reg(const char *path)
96 fd = open(path, O_RDWR|O_CREAT, 00644);
98 printf("error %d create %s\n", fd, path);
104 printf("error %d close %s\n", rc, path);
109 void cleanup_reg(const char *path)
115 printf("error %d unlink %s\n", rc, path);
120 void prepare_dir(const char *path)
124 rc = mkdir(path, 00644);
126 printf("error %d mkdir %s\n", rc, path);
131 void cleanup_dir(const char *path)
137 printf("error %d unlink %s\n", rc, path);
144 char cmd[MAX_STRING_SIZE]; \
147 if (drop_arr[drop_index].name) { \
148 printf("server drops next %s\n", drop_arr[drop_index].name); \
150 "%s %s \"echo %lu > /proc/sys/lustre/fail_loc\"", \
151 ssh_cmd, mds_server, drop_arr[drop_index].code); \
152 if ((rc = system(cmd))) { \
153 printf("error excuting remote command: %d\n", rc); \
163 if (drop_arr[drop_index].name) { \
164 sprintf(cmd, "%s %s \"echo 0 > /proc/sys/lustre/fail_loc\"", \
165 ssh_cmd, mds_server); \
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");