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>
39 #include "test_common.h"
45 sprintf(buf, "===== START: %s ", (str)); \
48 memset(buf+len, '=', 100-len); \
57 printf("----- END TEST successfully ---"); \
58 printf("-----------------------------"); \
59 printf("-------------------\n"); \
62 #define MAX_PATH_LENGTH 4096
66 char *path="/mnt/lustre/test_t1";
67 ENTRY("create/delete");
76 char *path="/mnt/lustre/test_t2";
86 char *path="/mnt/lustre/test_t3";
87 ENTRY("regular stat");
90 t_check_stat(path, NULL);
97 char *path="/mnt/lustre/test_t4";
101 t_check_stat(path, NULL);
108 char *path="/mnt/lustre/test_t6";
109 char *path2="/mnt/lustre/test_t6_link";
113 t_symlink(path, path2);
114 t_check_stat(path2, NULL);
122 char *path="/mnt/lustre/test_t7";
126 if (geteuid() != 0) {
127 rc = mknod(path, S_IFCHR | 0644, (5<<8 | 4));
128 if (rc != -1 || errno != EPERM) {
129 printf("mknod shouldn't success: rc %d, errno %d\n",
133 t_mknod(path, S_IFCHR | 0644, 5, 4);
134 t_check_stat(path, NULL);
142 char *path="/mnt/lustre/test_t8";
146 t_chmod_raw(path, 0700);
147 t_check_stat(path, NULL);
154 char *path="/mnt/lustre/test_t9";
155 char *path2="/mnt/lustre/test_t9_link";
160 t_check_stat(path, NULL);
161 t_check_stat(path2, NULL);
169 char *dir1="/mnt/lustre/test_t10_dir1";
170 char *dir2="/mnt/lustre/test_t10_dir2";
171 char *path1="/mnt/lustre/test_t10_reg1";
172 char *path2="/mnt/lustre/test_t10_reg2";
173 char *rename1="/mnt/lustre/test_t10_dir1/rename1";
174 char *rename2="/mnt/lustre/test_t10_dir2/rename2";
175 char *rename3="/mnt/lustre/test_t10_dir2/rename3";
182 t_rename(path1, rename1);
183 t_rename(path2, rename2);
184 t_rename(rename1, rename2);
185 t_rename(dir1, rename3);
194 char *base="/mnt/lustre";
195 char path[MAX_PATH_LENGTH], path2[MAX_PATH_LENGTH];
196 int i, j, level = 5, nreg = 5;
199 safe_strncpy(path, base, MAX_PATH_LENGTH);
201 for (i = 0; i < level; i++) {
202 for (j = 0; j < nreg; j++) {
203 sprintf(path2, "%s/file%d", path, j);
207 strcat(path, "/dir");
211 for (i = level; i > 0; i--) {
212 safe_strncpy(path, base, MAX_PATH_LENGTH);
213 for (j = 1; j < i; j++)
214 strcat(path, "/dir");
216 for (j = 0; j < nreg; j++) {
217 sprintf(path2, "%s/file%d", path, j);
221 strcat(path, "/dir");
230 char *dir="/mnt/lustre/test_t12_dir";
233 ENTRY("empty directory readdir");
237 t_ls(fd, buf, sizeof(buf));
245 char *dir="/mnt/lustre/test_t13_dir/";
248 const int nfiles = 20;
249 char *prefix = "test13_filename_prefix_";
251 ENTRY("multiple entries directory readdir");
254 printf("Creating %d files...\n", nfiles);
255 for (i = 0; i < nfiles; i++) {
256 sprintf(name, "%s%s%05d", dir, prefix, i);
260 t_ls(fd, buf, sizeof(buf));
262 printf("Cleanup...\n");
263 for (i = 0; i < nfiles; i++) {
264 sprintf(name, "%s%s%05d", dir, prefix, i);
273 char *dir="/mnt/lustre/test_t14_dir/";
276 const int nfiles = 256;
277 char *prefix = "test14_filename_long_prefix_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA___";
278 struct dirent64 *ent;
279 int fd, i, rc, pos, index;
281 ENTRY(">1 block(4k) directory readdir");
284 printf("Creating %d files...\n", nfiles);
285 for (i = 0; i < nfiles; i++) {
286 sprintf(name, "%s%s%05d", dir, prefix, i);
290 printf("Listing...\n");
292 while ((rc = getdirentries64(fd, buf, 1024, &base)) > 0) {
297 ent = (struct dirent64 *) ((char*) buf + pos);
298 item = (char *) ent->d_name;
299 if (!strcmp(item, ".") || !strcmp(item, ".."))
301 if (strstr(item, prefix) != item) {
302 printf("found bad name %s\n", item);
305 printf("[%03d]: %s\n",
306 index++, item + strlen(prefix));
308 pos += ent->d_reclen;
312 printf("getdents error %d\n", rc);
315 if (index != nfiles) {
316 printf("get %d files != %d\n", index, nfiles);
320 printf("Cleanup...\n");
321 for (i = 0; i < nfiles; i++) {
322 sprintf(name, "%s%s%05d", dir, prefix, i);
331 char *file = "/mnt/lustre/test_t15_file";
333 ENTRY("open-stat-close");
337 t_check_stat(file, NULL);
345 char *file = "/mnt/lustre/test_t16_file";
347 ENTRY("small-write-read");
349 t_echo_create(file, "aaaaaaaaaaaaaaaaaaaaaa");
350 t_grep(file, "aaaaaaaaaaaaaaaaaaaaaa");
357 char *file = "/mnt/lustre/test_t17_file";
359 ENTRY("open-unlink without close");
361 fd = open(file, O_WRONLY | O_CREAT, 0666);
363 printf("failed to create file: %s\n", strerror(errno));
372 char *file = "/mnt/lustre/test_t18_file";
375 struct stat statbuf[3];
376 ENTRY("write should change mtime/atime");
378 for (i = 0; i < 3; i++) {
379 fd = open(file, O_RDWR|O_CREAT|O_APPEND, (mode_t)0666);
381 printf("error open file: %s\n", strerror(errno));
384 if (write(fd, buf, sizeof(buf)) != sizeof(buf)) {
385 printf("error write file\n");
389 if(stat(file, &statbuf[i]) != 0) {
390 printf("Error stat\n");
393 printf("mtime %ld, ctime %d\n",
394 statbuf[i].st_atime, statbuf[i].st_mtime);
398 for (i = 1; i < 3; i++) {
399 if ((statbuf[i].st_atime <= statbuf[i-1].st_atime) ||
400 (statbuf[i].st_mtime <= statbuf[i-1].st_mtime)) {
401 printf("time error\n");
408 #define PAGE_SIZE (4096)
409 #define _npages (2048)
411 static int _buffer[_npages][PAGE_SIZE/sizeof(int)];
413 /* pos: i/o start from
414 * xfer: npages per transfer
416 static void pages_io(int xfer, loff_t pos)
418 char *path="/mnt/lustre/test_t50";
419 int check_sum[_npages] = {0,};
421 struct timeval tw1, tw2, tr1, tr2;
424 memset(_buffer, 0, sizeof(_buffer));
426 /* create sample data */
427 for (i = 0; i < _npages; i++) {
428 for (j = 0; j < PAGE_SIZE/sizeof(int); j++) {
429 _buffer[i][j] = rand();
433 /* compute checksum */
434 for (i = 0; i < _npages; i++) {
435 for (j = 0; j < PAGE_SIZE/sizeof(int); j++) {
436 check_sum[i] += _buffer[i][j];
445 lseek(fd, pos, SEEK_SET);
446 gettimeofday(&tw1, NULL);
447 for (i = 0; i < _npages; i += xfer) {
448 rc = write(fd, _buffer[i], PAGE_SIZE * xfer);
449 if (rc != PAGE_SIZE * xfer) {
450 printf("write error %d (i = %d)\n", rc, i);
454 gettimeofday(&tw2, NULL);
456 memset(_buffer, 0, sizeof(_buffer));
459 lseek(fd, pos, SEEK_SET);
460 gettimeofday(&tr1, NULL);
461 for (i = 0; i < _npages; i += xfer) {
462 rc = read(fd, _buffer[i], PAGE_SIZE * xfer);
463 if (rc != PAGE_SIZE * xfer) {
464 printf("read error %d (i = %d)\n", rc, i);
468 gettimeofday(&tr2, NULL);
470 /* compute checksum */
471 for (i = 0; i < _npages; i++) {
473 for (j = 0; j < PAGE_SIZE/sizeof(int); j++) {
474 sum += _buffer[i][j];
476 if (sum != check_sum[i]) {
477 printf("chunk %d checksum error: expected 0x%x, get 0x%x\n",
478 i, check_sum[i], sum);
484 tw = (tw2.tv_sec - tw1.tv_sec) * 1000000 + (tw2.tv_usec - tw1.tv_usec);
485 tr = (tr2.tv_sec - tr1.tv_sec) * 1000000 + (tr2.tv_usec - tr1.tv_usec);
486 printf(" (R:%.3fM/s, W:%.3fM/s)\n",
487 (_npages * PAGE_SIZE) / (tw / 1000000.0) / (1024 * 1024),
488 (_npages * PAGE_SIZE) / (tr / 1000000.0) / (1024 * 1024));
494 loff_t off_array[] = {1, 17, 255, 258, 4095, 4097, 8191, 1024*1024*1024*1024ULL};
498 ENTRY("4k aligned i/o sanity");
499 while (np <= _npages) {
500 printf("%3d per xfer(total %d)...\t", np, _npages);
501 pages_io(np, offset);
506 ENTRY("4k un-aligned i/o sanity");
507 for (i = 0; i < sizeof(off_array)/sizeof(loff_t); i++) {
508 offset = off_array[i];
509 printf("16 per xfer(total %d), offset %10lld...\t",
511 pages_io(16, offset);
516 extern void __liblustre_setup_(void);
517 extern void __liblustre_cleanup_(void);
519 void usage(char *cmd)
521 printf("Usage: \t%s --target mdsnid:/mdsname/profile\n", cmd);
522 printf(" \t%s --dumpfile dumpfile\n", cmd);
526 int main(int argc, char * const argv[])
529 static struct option long_opts[] = {
531 {"dumpfile", 1, 0, 0},
538 while ((c = getopt_long(argc, argv, "", long_opts, &opt_index)) != -1) {
544 if (!strcmp(long_opts[opt_index].name, "target")) {
545 setenv(ENV_LUSTRE_MNTTGT, optarg, 1);
546 } else if (!strcmp(long_opts[opt_index].name, "dumpfile")) {
547 setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);
560 __liblustre_setup_();
581 printf("liblustre is about shutdown\n");
582 __liblustre_cleanup_();
584 printf("complete successfully\n");