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>
41 #include "test_common.h"
43 extern char *lustre_path;
49 sprintf(buf, "===== START: %s ", (str)); \
52 memset(buf+len, '=', 100-len); \
61 printf("----- END TEST successfully ---"); \
62 printf("-----------------------------"); \
63 printf("-------------------\n"); \
66 #define MAX_PATH_LENGTH 4096
70 char path[MAX_PATH_LENGTH] = "";
72 ENTRY("create/delete");
73 snprintf(path, MAX_PATH_LENGTH, "%s/test_t1", lustre_path);
82 char path[MAX_PATH_LENGTH] = "";
85 snprintf(path, MAX_PATH_LENGTH, "%s/test_t2", lustre_path);
94 char path[MAX_PATH_LENGTH] = "";
96 ENTRY("regular stat");
97 snprintf(path, MAX_PATH_LENGTH, "%s/test_t3", lustre_path);
100 t_check_stat(path, NULL);
107 char path[MAX_PATH_LENGTH] = "";
110 snprintf(path, MAX_PATH_LENGTH, "%s/test_t4", lustre_path);
113 t_check_stat(path, NULL);
120 char path[MAX_PATH_LENGTH] = "";
121 char path2[MAX_PATH_LENGTH] = "";
124 snprintf(path, MAX_PATH_LENGTH, "%s/test_t6", lustre_path);
125 snprintf(path2, MAX_PATH_LENGTH, "%s/test_t6_link", lustre_path);
128 t_symlink(path, path2);
129 t_check_stat(path2, NULL);
137 char path[MAX_PATH_LENGTH] = "";
141 snprintf(path, MAX_PATH_LENGTH, "%s/test_t7", lustre_path);
143 if (geteuid() != 0) {
144 rc = mknod(path, S_IFCHR | 0644, (5<<8 | 4));
145 if (rc != -1 || errno != EPERM) {
146 printf("mknod shouldn't success: rc %d, errno %d\n",
150 t_mknod(path, S_IFCHR | 0644, 5, 4);
151 t_check_stat(path, NULL);
159 char path[MAX_PATH_LENGTH] = "";
162 snprintf(path, MAX_PATH_LENGTH, "%s/test_t8", lustre_path);
165 t_chmod_raw(path, 0700);
166 t_check_stat(path, NULL);
173 char path[MAX_PATH_LENGTH] = "";
174 char path2[MAX_PATH_LENGTH] = "";
177 snprintf(path, MAX_PATH_LENGTH, "%s/test_t9", lustre_path);
178 snprintf(path2, MAX_PATH_LENGTH, "%s/test_t9_link", lustre_path);
182 t_check_stat(path, NULL);
183 t_check_stat(path2, NULL);
191 char dir1[MAX_PATH_LENGTH] = "";
192 char dir2[MAX_PATH_LENGTH] = "";
193 char path1[MAX_PATH_LENGTH] = "";
194 char path2[MAX_PATH_LENGTH] = "";
195 char rename1[MAX_PATH_LENGTH] = "";
196 char rename2[MAX_PATH_LENGTH] = "";
197 char rename3[MAX_PATH_LENGTH] = "";
200 snprintf(dir1, MAX_PATH_LENGTH, "%s/test_t10_dir1", lustre_path);
201 snprintf(dir2, MAX_PATH_LENGTH, "%s/test_t10_dir2", lustre_path);
202 snprintf(path1, MAX_PATH_LENGTH, "%s/test_t10_reg1", lustre_path);
203 snprintf(path2, MAX_PATH_LENGTH, "%s/test_t10_reg2", lustre_path);
204 snprintf(rename1, MAX_PATH_LENGTH, "%s/test_t10_dir1/rename1", lustre_path);
205 snprintf(rename2, MAX_PATH_LENGTH, "%s/test_t10_dir2/rename2", lustre_path);
206 snprintf(rename3, MAX_PATH_LENGTH, "%s/test_t10_dir2/rename3", lustre_path);
212 t_rename(path1, rename1);
213 t_rename(path2, rename2);
214 t_rename(rename1, rename2);
215 t_rename(dir1, rename3);
224 char *base=lustre_path;
225 char path[MAX_PATH_LENGTH], path2[MAX_PATH_LENGTH];
226 int i, j, level = 5, nreg = 5;
229 safe_strncpy(path, base, MAX_PATH_LENGTH);
231 for (i = 0; i < level; i++) {
232 for (j = 0; j < nreg; j++) {
233 sprintf(path2, "%s/file%d", path, j);
237 strcat(path, "/dir");
241 for (i = level; i > 0; i--) {
242 safe_strncpy(path, base, MAX_PATH_LENGTH);
243 for (j = 1; j < i; j++)
244 strcat(path, "/dir");
246 for (j = 0; j < nreg; j++) {
247 sprintf(path2, "%s/file%d", path, j);
251 strcat(path, "/dir");
260 char dir[MAX_PATH_LENGTH] = "";
263 ENTRY("empty directory readdir");
264 snprintf(dir, MAX_PATH_LENGTH, "%s/test_t12_dir", lustre_path);
268 t_ls(fd, buf, sizeof(buf));
276 char dir[MAX_PATH_LENGTH] = "";
279 const int nfiles = 20;
280 char *prefix = "test13_filename_prefix_";
282 ENTRY("multiple entries directory readdir");
283 snprintf(dir, MAX_PATH_LENGTH, "%s/test_t13_dir/", lustre_path);
286 printf("Creating %d files...\n", nfiles);
287 for (i = 0; i < nfiles; i++) {
288 sprintf(name, "%s%s%05d", dir, prefix, i);
292 t_ls(fd, buf, sizeof(buf));
294 printf("Cleanup...\n");
295 for (i = 0; i < nfiles; i++) {
296 sprintf(name, "%s%s%05d", dir, prefix, i);
305 char dir[MAX_PATH_LENGTH] = "";
308 const int nfiles = 256;
309 char *prefix = "test14_filename_long_prefix_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA___";
310 struct dirent64 *ent;
311 int fd, i, rc, pos, index;
313 ENTRY(">1 block(4k) directory readdir");
314 snprintf(dir, MAX_PATH_LENGTH, "%s/test_t14_dir/", lustre_path);
317 printf("Creating %d files...\n", nfiles);
318 for (i = 0; i < nfiles; i++) {
319 sprintf(name, "%s%s%05d", dir, prefix, i);
323 printf("Listing...\n");
325 while ((rc = getdirentries64(fd, buf, 1024, &base)) > 0) {
330 ent = (struct dirent64 *) ((char*) buf + pos);
331 item = (char *) ent->d_name;
332 if (!strcmp(item, ".") || !strcmp(item, ".."))
334 if (strstr(item, prefix) != item) {
335 printf("found bad name %s\n", item);
338 printf("[%03d]: %s\n",
339 index++, item + strlen(prefix));
341 pos += ent->d_reclen;
345 printf("getdents error %d\n", rc);
348 if (index != nfiles) {
349 printf("get %d files != %d\n", index, nfiles);
353 printf("Cleanup...\n");
354 for (i = 0; i < nfiles; i++) {
355 sprintf(name, "%s%s%05d", dir, prefix, i);
364 char file[MAX_PATH_LENGTH] = "";
366 ENTRY("open-stat-close");
367 snprintf(file, MAX_PATH_LENGTH, "%s/test_t15_file", lustre_path);
371 t_check_stat(file, NULL);
379 char file[MAX_PATH_LENGTH] = "";
380 ENTRY("small-write-read");
381 snprintf(file, MAX_PATH_LENGTH, "%s/test_t16_file", lustre_path);
383 t_echo_create(file, "aaaaaaaaaaaaaaaaaaaaaa");
384 t_grep(file, "aaaaaaaaaaaaaaaaaaaaaa");
391 char file[MAX_PATH_LENGTH] = "";
393 ENTRY("open-unlink without close");
394 snprintf(file, MAX_PATH_LENGTH, "%s/test_t17_file", lustre_path);
396 fd = open(file, O_WRONLY | O_CREAT, 0666);
398 printf("failed to create file: %s\n", strerror(errno));
407 char file[MAX_PATH_LENGTH] = "";
410 struct stat statbuf[3];
411 ENTRY("write should change mtime/atime");
412 snprintf(file, MAX_PATH_LENGTH, "%s/test_t18_file", lustre_path);
414 for (i = 0; i < 3; i++) {
415 fd = open(file, O_RDWR|O_CREAT|O_APPEND, (mode_t)0666);
417 printf("error open file: %s\n", strerror(errno));
420 if (write(fd, buf, sizeof(buf)) != sizeof(buf)) {
421 printf("error write file\n");
425 if(stat(file, &statbuf[i]) != 0) {
426 printf("Error stat\n");
429 printf("mtime %lu, ctime %lu\n",
430 statbuf[i].st_atime, statbuf[i].st_mtime);
434 for (i = 1; i < 3; i++) {
435 if ((statbuf[i].st_atime <= statbuf[i-1].st_atime) ||
436 (statbuf[i].st_mtime <= statbuf[i-1].st_mtime)) {
437 printf("time error\n");
447 char file[MAX_PATH_LENGTH] = "";
450 ENTRY("open(O_TRUNC) should trancate file to 0-length");
451 snprintf(file, MAX_PATH_LENGTH, "%s/test_t19_file", lustre_path);
453 t_echo_create(file, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
455 fd = open(file, O_RDWR|O_CREAT|O_TRUNC, (mode_t)0666);
457 printf("error open file: %s\n", strerror(errno));
461 if(stat(file, &statbuf) != 0) {
462 printf("Error stat\n");
465 if (statbuf.st_size != 0) {
466 printf("size %ld is not zero\n", statbuf.st_size);
475 char file[MAX_PATH_LENGTH] = "";
480 ENTRY("trap app's general bad pointer for file i/o");
481 snprintf(file, MAX_PATH_LENGTH, "%s/test_t20_file", lustre_path);
483 fd = open(file, O_RDWR|O_CREAT, (mode_t)0666);
485 printf("error open file: %s\n", strerror(errno));
489 ret = write(fd, NULL, 20);
490 if (ret != -1 || errno != EFAULT) {
491 printf("write 1: ret %ld, errno %d\n", ret, errno);
494 ret = write(fd, (void *)-1, 20);
495 if (ret != -1 || errno != EFAULT) {
496 printf("write 2: ret %ld, errno %d\n", ret, errno);
499 iov[0].iov_base = NULL;
501 iov[1].iov_base = (void *)-1;
503 ret = writev(fd, iov, 2);
504 if (ret != -1 || errno != EFAULT) {
505 printf("writev 1: ret %ld, errno %d\n", ret, errno);
508 iov[0].iov_base = NULL;
510 iov[1].iov_base = buf;
511 iov[1].iov_len = sizeof(buf);
512 ret = writev(fd, iov, 2);
513 if (ret != sizeof(buf)) {
514 printf("write 3 ret %ld, error %d\n", ret, errno);
517 lseek(fd, 0, SEEK_SET);
519 ret = read(fd, NULL, 20);
520 if (ret != -1 || errno != EFAULT) {
521 printf("read 1: ret %ld, errno %d\n", ret, errno);
524 ret = read(fd, (void *)-1, 20);
525 if (ret != -1 || errno != EFAULT) {
526 printf("read 2: ret %ld, errno %d\n", ret, errno);
529 iov[0].iov_base = NULL;
531 iov[1].iov_base = (void *)-1;
533 ret = readv(fd, iov, 2);
534 if (ret != -1 || errno != EFAULT) {
535 printf("readv 1: ret %ld, errno %d\n", ret, errno);
538 iov[0].iov_base = NULL;
540 iov[1].iov_base = buf;
541 iov[1].iov_len = sizeof(buf);
542 ret = readv(fd, iov, 2);
543 if (ret != sizeof(buf)) {
544 printf("read 3 ret %ld, error %d\n", ret, errno);
555 char file[MAX_PATH_LENGTH] = "";
557 ENTRY("basic fcntl support");
558 snprintf(file, MAX_PATH_LENGTH, "%s/test_t21_file", lustre_path);
560 fd = open(file, O_RDWR|O_CREAT, (mode_t)0666);
562 printf("error open file: %s\n", strerror(errno));
565 if (fcntl(fd, F_SETFL, O_APPEND)) {
566 printf("error set flag: %s\n", strerror(errno));
569 if ((ret = fcntl(fd, F_GETFL)) != O_APPEND) {
570 printf("error get flag: ret %x\n", ret);
581 char file[MAX_PATH_LENGTH] = "";
583 char *str = "1234567890";
586 ENTRY("make sure O_APPEND take effect");
587 snprintf(file, MAX_PATH_LENGTH, "%s/test_t22_file", lustre_path);
589 fd = open(file, O_RDWR|O_CREAT|O_APPEND, (mode_t)0666);
591 printf("error open file: %s\n", strerror(errno));
595 lseek(fd, 100, SEEK_SET);
596 ret = write(fd, str, strlen(str));
597 if (ret != strlen(str)) {
598 printf("write 1: ret %ld, errno %d\n", ret, errno);
602 lseek(fd, 0, SEEK_SET);
603 ret = read(fd, buf, sizeof(buf));
604 if (ret != strlen(str)) {
605 printf("read 1 got %ld\n", ret);
609 if (memcmp(buf, str, strlen(str))) {
610 printf("read 1 data err\n");
614 if (fcntl(fd, F_SETFL, 0)) {
615 printf("fcntl err: %s\n", strerror(errno));
619 lseek(fd, 100, SEEK_SET);
620 ret = write(fd, str, strlen(str));
621 if (ret != strlen(str)) {
622 printf("write 2: ret %ld, errno %d\n", ret, errno);
626 lseek(fd, 100, SEEK_SET);
627 ret = read(fd, buf, sizeof(buf));
628 if (ret != strlen(str)) {
629 printf("read 2 got %ld\n", ret);
633 if (memcmp(buf, str, strlen(str))) {
634 printf("read 2 data err\n");
644 #define PAGE_SIZE (4096)
645 #define _npages (2048)
647 static int _buffer[_npages][PAGE_SIZE/sizeof(int)];
649 /* pos: i/o start from
650 * xfer: npages per transfer
652 static void pages_io(int xfer, loff_t pos)
654 char path[MAX_PATH_LENGTH] = "";
656 int check_sum[_npages] = {0,};
657 int fd, rc, i, j, data_error = 0;
658 struct timeval tw1, tw2, tr1, tr2;
661 snprintf(path, MAX_PATH_LENGTH, "%s/test_t50", lustre_path);
662 memset(_buffer, 0, sizeof(_buffer));
664 /* create sample data */
665 for (i = 0; i < _npages; i++) {
666 for (j = 0; j < PAGE_SIZE/sizeof(int); j++) {
667 _buffer[i][j] = rand();
671 /* compute checksum */
672 for (i = 0; i < _npages; i++) {
673 for (j = 0; j < PAGE_SIZE/sizeof(int); j++) {
674 check_sum[i] += _buffer[i][j];
683 lseek(fd, pos, SEEK_SET);
684 gettimeofday(&tw1, NULL);
685 for (i = 0; i < _npages; i += xfer) {
686 rc = write(fd, _buffer[i], PAGE_SIZE * xfer);
687 if (rc != PAGE_SIZE * xfer) {
688 printf("write error %d (i = %d)\n", rc, i);
692 gettimeofday(&tw2, NULL);
694 memset(_buffer, 0, sizeof(_buffer));
697 lseek(fd, pos, SEEK_SET);
698 gettimeofday(&tr1, NULL);
699 for (i = 0; i < _npages; i += xfer) {
700 rc = read(fd, _buffer[i], PAGE_SIZE * xfer);
701 if (rc != PAGE_SIZE * xfer) {
702 printf("read error %d (i = %d)\n", rc, i);
706 gettimeofday(&tr2, NULL);
708 /* compute checksum */
709 for (i = 0; i < _npages; i++) {
711 for (j = 0; j < PAGE_SIZE/sizeof(int); j++) {
712 sum += _buffer[i][j];
714 if (sum != check_sum[i]) {
716 printf("chunk %d checksum error: expected 0x%x, get 0x%x\n",
717 i, check_sum[i], sum);
723 tw = (tw2.tv_sec - tw1.tv_sec) * 1000000 + (tw2.tv_usec - tw1.tv_usec);
724 tr = (tr2.tv_sec - tr1.tv_sec) * 1000000 + (tr2.tv_usec - tr1.tv_usec);
725 printf(" (R:%.3fM/s, W:%.3fM/s)\n",
726 (_npages * PAGE_SIZE) / (tw / 1000000.0) / (1024 * 1024),
727 (_npages * PAGE_SIZE) / (tr / 1000000.0) / (1024 * 1024));
735 loff_t off_array[] = {1, 17, 255, 258, 4095, 4097, 8191,
736 1024*1024*1024*1024ULL};
740 ENTRY("4k aligned i/o sanity");
741 while (np <= _npages) {
742 printf("%3d per xfer(total %d)...\t", np, _npages);
743 pages_io(np, offset);
748 ENTRY("4k un-aligned i/o sanity");
749 for (i = 0; i < sizeof(off_array)/sizeof(loff_t); i++) {
750 offset = off_array[i];
751 printf("16 per xfer(total %d), offset %10lld...\t",
753 pages_io(16, offset);
758 extern void __liblustre_setup_(void);
759 extern void __liblustre_cleanup_(void);
761 void usage(char *cmd)
763 printf("Usage: \t%s --target mdsnid:/mdsname/profile\n", cmd);
764 printf(" \t%s --dumpfile dumpfile\n", cmd);
768 int main(int argc, char * const argv[])
771 static struct option long_opts[] = {
773 {"dumpfile", 1, 0, 0},
780 while ((c = getopt_long(argc, argv, "", long_opts, &opt_index)) != -1) {
786 if (!strcmp(long_opts[opt_index].name, "target")) {
787 setenv(ENV_LUSTRE_MNTTGT, optarg, 1);
788 } else if (!strcmp(long_opts[opt_index].name, "dumpfile")) {
789 setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);
802 __liblustre_setup_();
827 printf("liblustre is about shutdown\n");
828 __liblustre_cleanup_();
830 printf("complete successfully\n");