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"
42 #define MAX_STRING_SIZE 2048
49 {"MDS_REQUEST", 0x123},
54 static int drop_index = 0;
56 static char mds_server[1024] = {0, };
57 static char ssh_cmd[MAX_STRING_SIZE] = {0,};
59 int do_stat(const char *name, struct stat *buf)
64 rc = lstat(name, &stat);
66 printf("error %d stat %s\n", rc, name);
70 memcpy(buf, &stat, sizeof(*buf));
75 void prepare_reg(const char *path)
79 fd = open(path, O_RDWR|O_CREAT, 00644);
81 printf("error %d create %s\n", fd, path);
87 printf("error %d close %s\n", rc, path);
92 void cleanup_reg(const char *path)
98 printf("error %d unlink %s\n", rc, path);
103 void prepare_dir(const char *path)
107 rc = mkdir(path, 00644);
109 printf("error %d mkdir %s\n", rc, path);
114 void cleanup_dir(const char *path)
120 printf("error %d unlink %s\n", rc, path);
127 char cmd[MAX_STRING_SIZE]; \
130 if (drop_arr[drop_index].name) { \
131 printf("server drops next %s\n", drop_arr[drop_index].name); \
133 "%s %s \"echo %lu > /proc/sys/lustre/fail_loc\"", \
134 ssh_cmd, mds_server, drop_arr[drop_index].code); \
136 printf("error excuting remote command: %d\n", rc); \
146 if (drop_arr[drop_index].name) { \
147 sprintf(cmd, "%s %s \"echo 0 > /proc/sys/lustre/fail_loc\"", \
148 ssh_cmd, mds_server); \
157 sprintf(buf, "===== START: %s ", (str)); \
160 memset(buf+len, '=', 100-len); \
169 printf("----- END TEST successfully ---"); \
170 printf("-----------------------------"); \
171 printf("-------------------\n"); \
177 char *path="/mnt/lustre/test_t1";
178 ENTRY("create/delete");
191 char *path="/mnt/lustre/test_t2";
192 ENTRY("mkdir/rmdir");
205 char *path="/mnt/lustre/test_t3";
206 ENTRY("regular stat");
210 t_check_stat(path, NULL);
218 char *path="/mnt/lustre/test_t4";
223 t_check_stat(path, NULL);
231 char *path="/mnt/lustre/test_t5";
232 const int bufsize = 4096;
233 char wbuf[bufsize], rbuf[bufsize];
236 ENTRY("sequential page aligned file I/O");
242 for (i = 0; i < npages; i++ ) {
243 memset(wbuf, i, bufsize);
244 rc = write(fd, wbuf, bufsize);
246 printf("write error %d (i = %d)\n", rc, i);
250 printf("succefully write %d pages\n", npages);
252 lseek(fd, 0, SEEK_SET);
254 for (i = 0; i < npages; i++ ) {
255 memset(rbuf, 0, bufsize);
256 rc = read(fd, rbuf, bufsize);
258 printf("read error %d (i = %d)\n", rc, i);
262 printf("succefully read & verified %d pages\n", npages);
272 char *path="/mnt/lustre/test_t6";
273 char *path2="/mnt/lustre/test_t6_link";
278 t_symlink(path, path2);
280 t_check_stat(path2, NULL);
288 char *path="/mnt/lustre/test_t7";
292 t_mknod(path, S_IFCHR | 0644, 5, 4);
294 t_check_stat(path, NULL);
299 extern int portal_debug;
300 extern int portal_subsystem_debug;
302 extern void __liblustre_setup_(void);
303 extern void __liblustre_cleanup_(void);
305 void usage(const char *cmd)
307 printf("Usage: \t%s -s mds_hostname --target mdsnid:/mdsname/profile\n", cmd);
308 printf(" \t%s -s mds_hostname --dumpfile dumpfile\n", cmd);
312 int main(int argc, char * argv[])
316 static struct option long_opts[] = {
318 {"dumpfile", 1, 0, 0},
326 while ((c = getopt_long(argc, argv, "s:", long_opts, &opt_index)) != -1) {
332 if (!strcmp(long_opts[opt_index].name, "target")) {
333 setenv(ENV_LUSTRE_MNTTGT, optarg, 1);
334 } else if (!strcmp(long_opts[opt_index].name, "dumpfile")) {
335 setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);
336 } else if (!strcmp(long_opts[opt_index].name, "ssh")) {
337 safe_strncpy(ssh_cmd, optarg, MAX_STRING_SIZE);
343 safe_strncpy(mds_server, optarg, MAX_STRING_SIZE);
353 if (strlen(mds_server) == 0)
356 /* default to using ssh */
357 if (!strlen(ssh_cmd)) {
358 safe_strncpy(ssh_cmd, "ssh", MAX_STRING_SIZE);
361 sprintf(cmd, "%s %s cat /dev/null", ssh_cmd, mds_server);
363 printf("Can't access server node: %s using method: %s\n", mds_server, ssh_cmd);
367 setenv(ENV_LUSTRE_TIMEOUT, "5", 1);
369 __liblustre_setup_();
371 while (drop_arr[drop_index].name) {
385 printf("liblustre is about shutdown\n");
386 __liblustre_cleanup_();
388 printf("complete successfully\n");