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.
25 #define _FILE_OFFSET_BITS 64
32 #include <sys/types.h>
42 #include <liblustre.h>
43 #include "test_common.h"
44 #include <lustre/liblustreapi.h>
46 #define _npages (2048)
53 extern char *lustre_path;
59 sprintf(buf, "===== START %s: %s ", __FUNCTION__, (str)); \
62 memset(buf+len, '=', 100-len); \
67 gettimeofday(&start, NULL); \
72 struct timeval stop; \
73 char buf[100] = { '\0' }; \
74 int len = sizeof(buf) - 1; \
76 gettimeofday(&stop, NULL); \
77 usec = (stop.tv_sec - start.tv_sec) * 1000000 + \
78 (stop.tv_usec - start.tv_usec); \
79 len = snprintf(buf, len, \
80 "===== END TEST %s: successfully (%gs)", \
81 __FUNCTION__, (double)usec / 1000000); \
83 memset(buf+len, '=', sizeof(buf) - len); \
91 #define MAX_PATH_LENGTH 4096
95 char path[MAX_PATH_LENGTH] = "";
97 ENTER("touch+unlink");
98 snprintf(path, MAX_PATH_LENGTH, "%s/test_t1", lustre_path);
101 printf("touch+unlink %s\n", path);
110 char path[MAX_PATH_LENGTH] = "";
112 ENTER("mkdir/rmdir");
113 snprintf(path, MAX_PATH_LENGTH, "%s/test_t2", lustre_path);
122 char path[MAX_PATH_LENGTH] = "";
124 ENTER("regular stat");
125 snprintf(path, MAX_PATH_LENGTH, "%s/test_t3", lustre_path);
128 t_check_stat(path, NULL);
135 char path[MAX_PATH_LENGTH] = "";
138 snprintf(path, MAX_PATH_LENGTH, "%s/test_t4", lustre_path);
141 t_check_stat(path, NULL);
148 char path[MAX_PATH_LENGTH] = "";
149 char path2[MAX_PATH_LENGTH] = "";
152 snprintf(path, MAX_PATH_LENGTH, "%s/test_t6", lustre_path);
153 snprintf(path2, MAX_PATH_LENGTH, "%s/test_t6_link", lustre_path);
156 t_symlink(path, path2);
157 t_check_stat(path2, NULL);
165 char path[MAX_PATH_LENGTH] = "";
166 char path2[MAX_PATH_LENGTH] = "";
167 char cwd[MAX_PATH_LENGTH] = "";
171 ENTER("symlink + chdir and open");
172 snprintf(path, MAX_PATH_LENGTH, "%s/test_t6b", lustre_path);
173 snprintf(path2, MAX_PATH_LENGTH, "%s/test_t6b_link", lustre_path);
176 t_symlink(path, path2);
177 t_check_stat(path2, NULL);
179 tmp = getcwd(cwd, MAX_PATH_LENGTH);
181 fprintf(stderr, "current path too long to fit in "
182 "MAX_PATH_LENGTH?\n");
200 char path[MAX_PATH_LENGTH] = "";
204 snprintf(path, MAX_PATH_LENGTH, "%s/test_t7", lustre_path);
206 if (geteuid() != 0) {
207 rc = mknod(path, S_IFCHR | 0644, (5<<8 | 4));
208 if (rc != -1 || errno != EPERM) {
209 printf("mknod shouldn't success: rc %d, errno %d\n",
213 t_mknod(path, S_IFCHR | 0644, 5, 4);
214 t_check_stat(path, NULL);
222 char path[MAX_PATH_LENGTH] = "";
225 snprintf(path, MAX_PATH_LENGTH, "%s/test_t8", lustre_path);
229 t_chmod_raw(path, 0700);
230 t_check_stat(path, NULL);
235 t_chmod_raw(path, 0700);
236 t_check_stat(path, NULL);
244 char path[MAX_PATH_LENGTH] = "";
245 char path2[MAX_PATH_LENGTH] = "";
248 snprintf(path, MAX_PATH_LENGTH, "%s/test_t9", lustre_path);
249 snprintf(path2, MAX_PATH_LENGTH, "%s/test_t9_link", lustre_path);
253 t_check_stat(path, NULL);
254 t_check_stat(path2, NULL);
262 char dir1[MAX_PATH_LENGTH] = "";
263 char dir2[MAX_PATH_LENGTH] = "";
264 char path1[MAX_PATH_LENGTH] = "";
265 char path2[MAX_PATH_LENGTH] = "";
266 char rename1[MAX_PATH_LENGTH] = "";
267 char rename2[MAX_PATH_LENGTH] = "";
268 char rename3[MAX_PATH_LENGTH] = "";
271 snprintf(dir1, MAX_PATH_LENGTH, "%s/test_t10_dir1", lustre_path);
272 snprintf(dir2, MAX_PATH_LENGTH, "%s/test_t10_dir2", lustre_path);
273 snprintf(path1, MAX_PATH_LENGTH, "%s/test_t10_reg1", lustre_path);
274 snprintf(path2, MAX_PATH_LENGTH, "%s/test_t10_reg2", lustre_path);
275 snprintf(rename1, MAX_PATH_LENGTH, "%s/test_t10_dir1/rename1", lustre_path);
276 snprintf(rename2, MAX_PATH_LENGTH, "%s/test_t10_dir2/rename2", lustre_path);
277 snprintf(rename3, MAX_PATH_LENGTH, "%s/test_t10_dir2/rename3", lustre_path);
283 t_rename(path1, rename1);
284 t_rename(path2, rename2);
285 t_rename(rename1, rename2);
286 t_rename(dir1, rename3);
295 char *base=lustre_path;
296 char path[MAX_PATH_LENGTH], path2[MAX_PATH_LENGTH];
297 int i, j, level = 5, nreg = 5;
300 safe_strncpy(path, base, MAX_PATH_LENGTH);
302 for (i = 0; i < level; i++) {
303 for (j = 0; j < nreg; j++) {
304 sprintf(path2, "%s/file%d", path, j);
308 strcat(path, "/dir");
312 for (i = level; i > 0; i--) {
313 safe_strncpy(path, base, MAX_PATH_LENGTH);
314 for (j = 1; j < i; j++)
315 strcat(path, "/dir");
317 for (j = 0; j < nreg; j++) {
318 sprintf(path2, "%s/file%d", path, j);
322 strcat(path, "/dir");
331 char dir[MAX_PATH_LENGTH] = "";
334 ENTER("empty directory readdir");
335 snprintf(dir, MAX_PATH_LENGTH, "%s/test_t12_dir", lustre_path);
339 t_ls(fd, buf, sizeof(buf));
347 char dir[MAX_PATH_LENGTH] = "";
350 const int nfiles = 20;
351 char *prefix = "test13_filename_prefix_";
353 ENTER("multiple entries directory readdir");
354 snprintf(dir, MAX_PATH_LENGTH, "%s/test_t13_dir/", lustre_path);
357 printf("Creating %d files...\n", nfiles);
358 for (i = 0; i < nfiles; i++) {
359 sprintf(path, "%s%s%05d", dir, prefix, i);
363 t_ls(fd, buf, sizeof(buf));
365 printf("Cleanup...\n");
366 for (i = 0; i < nfiles; i++) {
367 sprintf(path, "%s%s%05d", dir, prefix, i);
376 char dir[MAX_PATH_LENGTH] = "";
379 const int nfiles = 256;
380 char *prefix = "test14_filename_long_prefix_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA___";
382 int fd, i, rc, pos, index;
384 ENTER(">1 block(4k) directory readdir");
385 snprintf(dir, MAX_PATH_LENGTH, "%s/test_t14_dir/", lustre_path);
387 rc = mkdir(dir, 0755);
388 if (rc < 0 && errno != EEXIST) {
389 printf("mkdir(%s) error: %s\n", dir, strerror(errno));
392 printf("Creating %d files...\n", nfiles);
393 for (i = 0; i < nfiles; i++) {
394 sprintf(path, "%s%s%05d", dir, prefix, i);
398 printf("Listing...\n");
400 while ((rc = getdirentries64(fd, buf, 1024, &base)) > 0) {
405 ent = (void *) buf + pos;
406 item = (char *) ent->d_name;
407 if (!strcmp(item, ".") || !strcmp(item, ".."))
409 if (strstr(item, prefix) != item) {
410 printf("found bad name %s\n", item);
413 printf("[%03d]: %s\n",
414 index++, item + strlen(prefix));
416 pos += ent->d_reclen;
420 printf("getdents error %d\n", rc);
423 if (index != nfiles) {
424 printf("get %d files != %d\n", index, nfiles);
428 printf("Cleanup...\n");
429 for (i = 0; i < nfiles; i++) {
430 sprintf(path, "%s%s%05d", dir, prefix, i);
439 char file[MAX_PATH_LENGTH] = "";
441 ENTER("open-stat-close");
442 snprintf(file, MAX_PATH_LENGTH, "%s/test_t15_file", lustre_path);
446 t_check_stat(file, NULL);
454 char file[MAX_PATH_LENGTH] = "";
455 ENTER("small-write-read");
456 snprintf(file, MAX_PATH_LENGTH, "%s/test_t16_file", lustre_path);
458 t_echo_create(file, "aaaaaaaaaaaaaaaaaaaaaa");
459 t_grep(file, "aaaaaaaaaaaaaaaaaaaaaa");
466 char file[MAX_PATH_LENGTH] = "";
468 ENTER("open-unlink without close");
469 snprintf(file, MAX_PATH_LENGTH, "%s/test_t17_file", lustre_path);
471 fd = open(file, O_WRONLY | O_CREAT, 0666);
473 printf("failed to create file: %s\n", strerror(errno));
482 char file[MAX_PATH_LENGTH] = "";
485 struct stat statbuf[3];
486 ENTER("write should change mtime/ctime");
487 snprintf(file, MAX_PATH_LENGTH, "%s/test_t18_file", lustre_path);
489 for (i = 0; i < 3; i++) {
490 fd = open(file, O_RDWR|O_CREAT|O_APPEND, (mode_t)0666);
492 printf("error open file: %s\n", strerror(errno));
495 if (write(fd, buf, sizeof(buf)) != sizeof(buf)) {
496 printf("error write file\n");
500 if(stat(file, &statbuf[i]) != 0) {
501 printf("Error stat\n");
504 printf("ctime %lu, mtime %lu\n",
505 statbuf[i].st_ctime, statbuf[i].st_mtime);
509 for (i = 1; i < 3; i++) {
510 if ((statbuf[i].st_ctime <= statbuf[i-1].st_ctime) ||
511 (statbuf[i].st_mtime <= statbuf[i-1].st_mtime)) {
512 printf("time error\n");
522 char file[MAX_PATH_LENGTH] = "";
524 struct stat statbuf[3];
525 ENTER("utime should change mtime/atime/ctime");
526 snprintf(file, MAX_PATH_LENGTH, "%s/test_t18b_file", lustre_path);
529 for (i = 0; i < 3; i++) {
531 if(stat(file, &statbuf[i]) != 0) {
532 printf("Error stat\n");
535 printf("atime %lu, mtime %lu, ctime %lu\n",
536 statbuf[i].st_atime, statbuf[i].st_mtime,
537 statbuf[i].st_ctime);
541 for (i = 1; i < 3; i++) {
542 if ((statbuf[i].st_atime <= statbuf[i-1].st_atime) ||
543 (statbuf[i].st_mtime <= statbuf[i-1].st_mtime) ||
544 (statbuf[i].st_ctime <= statbuf[i-1].st_ctime)) {
545 printf("time error\n");
553 static int check_file_size(char *file, long long size)
557 if (stat(file, &statbuf) != 0) {
558 printf("Error stat(%s)\n", file);
561 if (statbuf.st_size != size) {
562 printf("size of %s: %ld != %lld\n", file, statbuf.st_size, size);
570 char file[MAX_PATH_LENGTH] = "";
573 ENTER("open(O_TRUNC) should truncate file to 0-length");
574 snprintf(file, MAX_PATH_LENGTH, "%s/test_t19_file", lustre_path);
576 t_echo_create(file, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
578 fd = open(file, O_RDWR|O_CREAT|O_TRUNC, (mode_t)0666);
580 printf("error open file: %s\n", strerror(errno));
584 result = check_file_size(file, 0);
593 char file[MAX_PATH_LENGTH] = "";
598 ENTER("trap app's general bad pointer for file i/o");
599 snprintf(file, MAX_PATH_LENGTH, "%s/test_t20_file", lustre_path);
601 fd = open(file, O_RDWR|O_CREAT, (mode_t)0666);
603 printf("error open file: %s\n", strerror(errno));
607 ret = write(fd, NULL, 20);
608 if (ret != -1 || errno != EFAULT) {
609 printf("write 1: ret %ld, errno %d\n", ret, errno);
612 ret = write(fd, (void *)-1, 20);
613 if (ret != -1 || errno != EFAULT) {
614 printf("write 2: ret %ld, errno %d\n", ret, errno);
617 iov[0].iov_base = NULL;
619 iov[1].iov_base = (void *)-1;
621 ret = writev(fd, iov, 2);
622 if (ret != -1 || errno != EFAULT) {
623 printf("writev 1: ret %ld, errno %d\n", ret, errno);
626 iov[0].iov_base = NULL;
628 iov[1].iov_base = buf;
629 iov[1].iov_len = sizeof(buf);
630 ret = writev(fd, iov, 2);
631 if (ret != sizeof(buf)) {
632 printf("write 3 ret %ld, error %d\n", ret, errno);
635 lseek(fd, 0, SEEK_SET);
637 ret = read(fd, NULL, 20);
638 if (ret != -1 || errno != EFAULT) {
639 printf("read 1: ret %ld, errno %d\n", ret, errno);
642 ret = read(fd, (void *)-1, 20);
643 if (ret != -1 || errno != EFAULT) {
644 printf("read 2: ret %ld, errno %d\n", ret, errno);
647 iov[0].iov_base = NULL;
649 iov[1].iov_base = (void *)-1;
651 ret = readv(fd, iov, 2);
652 if (ret != -1 || errno != EFAULT) {
653 printf("readv 1: ret %ld, errno %d\n", ret, errno);
656 iov[0].iov_base = NULL;
658 iov[1].iov_base = buf;
659 iov[1].iov_len = sizeof(buf);
660 ret = readv(fd, iov, 2);
661 if (ret != sizeof(buf)) {
662 printf("read 3 ret %ld, error %d\n", ret, errno);
673 char file[MAX_PATH_LENGTH] = "";
675 struct flock lock = {
677 .l_whence = SEEK_SET,
680 ENTER("basic fcntl support");
681 snprintf(file, MAX_PATH_LENGTH, "%s/test_t21_file", lustre_path);
683 fd = open(file, O_RDWR|O_CREAT, (mode_t)0666);
685 printf("error open file: %s\n", file);
689 t_fcntl(fd, F_SETFL, O_APPEND);
690 if (!(ret = t_fcntl(fd, F_GETFL)) & O_APPEND) {
691 printf("error get flag: ret %x\n", ret);
695 t_fcntl(fd, F_SETLK, &lock);
696 t_fcntl(fd, F_GETLK, &lock);
697 lock.l_type = F_WRLCK;
698 t_fcntl(fd, F_SETLKW, &lock);
699 t_fcntl(fd, F_GETLK, &lock);
700 lock.l_type = F_UNLCK;
701 t_fcntl(fd, F_SETLK, &lock);
710 char file[MAX_PATH_LENGTH] = "";
712 char *str = "1234567890";
715 ENTER("make sure O_APPEND take effect");
716 snprintf(file, MAX_PATH_LENGTH, "%s/test_t22_file", lustre_path);
718 fd = open(file, O_RDWR|O_CREAT|O_APPEND, (mode_t)0666);
720 printf("error open file: %s\n", strerror(errno));
724 lseek(fd, 100, SEEK_SET);
725 ret = write(fd, str, strlen(str));
726 if (ret != strlen(str)) {
727 printf("write 1: ret %ld, errno %d\n", ret, errno);
731 lseek(fd, 0, SEEK_SET);
732 ret = read(fd, buf, sizeof(buf));
733 if (ret != strlen(str)) {
734 printf("read 1 got %ld\n", ret);
738 if (memcmp(buf, str, strlen(str))) {
739 printf("read 1 data err\n");
743 if (fcntl(fd, F_SETFL, 0)) {
744 printf("fcntl err: %s\n", strerror(errno));
748 lseek(fd, 100, SEEK_SET);
749 ret = write(fd, str, strlen(str));
750 if (ret != strlen(str)) {
751 printf("write 2: ret %ld, errno %d\n", ret, errno);
755 lseek(fd, 100, SEEK_SET);
756 ret = read(fd, buf, sizeof(buf));
757 if (ret != strlen(str)) {
758 printf("read 2 got %ld\n", ret);
762 if (memcmp(buf, str, strlen(str))) {
763 printf("read 2 data err\n");
774 char path[MAX_PATH_LENGTH];
779 ENTER("handle seek > 2GB");
780 snprintf(path, MAX_PATH_LENGTH, "%s/f%s", lustre_path, name);
782 fd = open(path, O_WRONLY | O_CREAT | O_LARGEFILE, 0666);
784 printf("failed to create file %s: %s\n", path, strerror(errno));
788 off = 2048ULL * 1024 * 1024 - buf_size / 2;
789 ret = lseek(fd, off, SEEK_SET);
791 printf("seek error for initial %llu != %llu\n",
792 ret, (long long)off);
796 ret = write(fd, buf_alloc, buf_size);
797 if (ret != buf_size) {
798 printf("write error for %d != %llubytes @ %llu\n",
799 buf_size, ret, (long long)off);
805 ret = lseek(fd, off, SEEK_SET);
807 printf("seek < 2GB error for %llu != %llu\n",
808 ret, (long long)off);
810 perror("seek < 2GB");
814 ret = lseek(fd, off + buf_size - 2, SEEK_SET);
815 if (ret != off + buf_size - 2) {
816 printf("seek > 2GB error for %llu != %llu\n",
817 ret, (long long)off);
819 perror("seek > 2GB");
823 ret = lseek(fd, -buf_size + 2, SEEK_CUR);
825 printf("relative seek error for %d %llu != %llu\n",
826 -buf_size + 2, ret, off);
828 perror("relative seek");
832 ret = lseek(fd, 0, SEEK_END);
833 if (ret != off + buf_size) {
834 printf("end seek error for %llu != %llu\n",
835 ret, (long long)off + buf_size);
841 ret = lseek(fd, 0, SEEK_SET);
843 printf("seek 0 error for %llu != 0\n", ret);
849 off = 2048ULL * 1024 * 1024, SEEK_SET;
850 ret = lseek(fd, off, SEEK_SET);
852 printf("seek 2GB error for %llu != %llu\n", ret, off);
863 /* pos: i/o start from
864 * xfer: npages per transfer
866 static int pages_io(int xfer, loff_t pos)
868 char path[MAX_PATH_LENGTH] = "";
870 int check_sum[_npages] = {0,}, *buf;
871 int fd, rc, i, j, data_error = 0;
872 struct timeval tw1, tw2, tr1, tr2;
876 snprintf(path, MAX_PATH_LENGTH, "%s/test_t50", lustre_path);
878 memset(buf_alloc, 0, buf_size);
880 /* create sample data */
881 for (i = 0, buf = buf_alloc; i < _npages; i++) {
882 for (j = 0; j < CFS_PAGE_SIZE/sizeof(int); j++, buf++) {
887 /* compute checksum */
888 for (i = 0, buf = buf_alloc; i < _npages; i++) {
889 for (j = 0; j < CFS_PAGE_SIZE/sizeof(int); j++, buf++) {
890 check_sum[i] += *buf;
900 ret = lseek(fd, pos, SEEK_SET);
902 perror("write seek");
905 gettimeofday(&tw1, NULL);
906 for (i = 0, buf = buf_alloc; i < _npages;
907 i += xfer, buf += xfer * CFS_PAGE_SIZE / sizeof(int)) {
908 rc = write(fd, buf, CFS_PAGE_SIZE * xfer);
909 if (rc != CFS_PAGE_SIZE * xfer) {
910 printf("write error (i %d, rc %d): %s\n", i, rc,
915 gettimeofday(&tw2, NULL);
917 memset(buf_alloc, 0, buf_size);
920 ret = lseek(fd, pos, SEEK_SET);
925 gettimeofday(&tr1, NULL);
926 for (i = 0, buf = buf_alloc; i < _npages;
927 i += xfer, buf += xfer * CFS_PAGE_SIZE / sizeof(int)) {
928 rc = read(fd, buf, CFS_PAGE_SIZE * xfer);
929 if (rc != CFS_PAGE_SIZE * xfer) {
930 printf("read error (i %d, rc %d): %s\n", i, rc,
935 gettimeofday(&tr2, NULL);
937 /* compute checksum */
938 for (i = 0, buf = buf_alloc; i < _npages; i++) {
940 for (j = 0; j < CFS_PAGE_SIZE/sizeof(int); j++, buf++) {
943 if (sum != check_sum[i]) {
945 printf("chunk %d checksum error expected %#x got %#x\n",
946 i, check_sum[i], sum);
952 tw = (tw2.tv_sec - tw1.tv_sec) * 1000000 + (tw2.tv_usec - tw1.tv_usec);
953 tr = (tr2.tv_sec - tr1.tv_sec) * 1000000 + (tr2.tv_usec - tr1.tv_usec);
954 printf(" (R:%.3fM/s, W:%.3fM/s)\n",
955 (_npages * CFS_PAGE_SIZE) / (tw / 1000000.0) / (1024 * 1024),
956 (_npages * CFS_PAGE_SIZE) / (tr / 1000000.0) / (1024 * 1024));
969 ENTER("4k aligned i/o sanity");
970 while (np <= _npages) {
971 printf("%3d per xfer(total %d)...\t", np, _npages);
973 if (pages_io(np, offset) != 0)
982 loff_t off_array[] = {1, 17, 255, 258, 4095, 4097, 8191,
983 1024*1024*1024*1024ULL};
987 ENTER("4k un-aligned i/o sanity");
988 for (i = 0; i < sizeof(off_array)/sizeof(loff_t); i++) {
989 offset = off_array[i];
990 printf("16 per xfer(total %d), offset %10lld...\t",
992 if (pages_io(16, offset) != 0)
1005 * truncate(2) checks.
1009 char file[MAX_PATH_LENGTH] = "";
1014 ENTER("truncate() should truncate file to proper length");
1015 snprintf(file, MAX_PATH_LENGTH, "%s/test_t51_file", lustre_path);
1017 for (size = 0; size < T51_NR * T51_STEP; size += T51_STEP) {
1018 t_echo_create(file, "");
1019 if (truncate(file, size) != 0) {
1020 printf("\nerror truncating file: %s\n",strerror(errno));
1023 result = check_file_size(file, size);
1028 t_echo_create(file, "");
1029 fd = open(file, O_RDWR|O_CREAT, (mode_t)0666);
1031 printf("\nerror open file: %s\n", strerror(errno));
1034 if (ftruncate(fd, size) != 0) {
1035 printf("\nerror ftruncating file:%s\n",strerror(errno));
1039 result = check_file_size(file, size);
1043 if (size % (T51_STEP * (T51_NR / 75)) == 0) {
1052 * check atime update during read
1056 char file[MAX_PATH_LENGTH] = "";
1058 struct stat statbuf;
1063 ENTER("atime should be updated during read");
1064 snprintf(file, MAX_PATH_LENGTH, "%s/test_t52_file", lustre_path);
1066 t_echo_create(file, "check atime update during read");
1067 fd = open(file, O_RDONLY);
1069 printf("\nerror open file: %s\n", strerror(errno));
1072 stat(file, &statbuf);
1073 printf("st_atime=%s", ctime(&statbuf.st_atime));
1074 atime = statbuf.st_atime;
1075 for (i = 0; i < 3; i++) {
1077 read(fd, buf, sizeof(buf));
1078 stat(file, &statbuf);
1079 printf("st_atime=%s", ctime(&statbuf.st_atime));
1080 diff = statbuf.st_atime - atime;
1082 printf("atime doesn't updated! failed!\n");
1087 atime = statbuf.st_atime;
1094 #define NEW_TIME 10000
1097 char file[MAX_PATH_LENGTH] = "";
1098 struct utimbuf times; /* struct. buffer for utime() */
1099 struct stat stat_buf; /* struct buffer to hold file info. */
1100 time_t mtime, atime;
1102 ENTER("mtime/atime should be updated by utime() call");
1103 snprintf(file, MAX_PATH_LENGTH, "%s/test_t53_file", lustre_path);
1105 t_echo_create(file, "check mtime/atime update by utime() call");
1107 /* Initialize the modification and access time in the times arg */
1108 times.actime = NEW_TIME+10;
1109 times.modtime = NEW_TIME;
1111 /* file modification/access time */
1112 utime(file, ×);
1114 if (stat(file, &stat_buf) < 0) {
1115 printf("stat(2) of %s failed, error:%d %s\n",
1116 file, errno, strerror(errno));
1118 mtime = stat_buf.st_mtime;
1119 atime = stat_buf.st_atime;
1121 if ((mtime == NEW_TIME) && (atime == NEW_TIME + 10)) {
1126 printf("mod time %ld, expected %ld\n", mtime, (long)NEW_TIME);
1127 printf("acc time %ld, expected %ld\n", atime, (long)NEW_TIME + 10);
1135 char file[MAX_PATH_LENGTH] = "";
1139 ENTER("fcntl should return 0 when succeed in getting flock");
1140 snprintf(file, MAX_PATH_LENGTH, "%s/test_t54_file", lustre_path);
1142 t_echo_create(file, "fcntl should return 0 when succeed");
1144 fd = open(file, O_RDWR);
1146 printf("\nerror open file: %s\n", strerror(errno));
1149 lock.l_type = F_WRLCK;
1153 if ((err = t_fcntl(fd, F_SETLKW, &lock)) != 0) {
1154 fprintf(stderr, "fcntl returned: %d (%s)\n",
1155 err, strerror(err));
1161 lock.l_type = F_UNLCK;
1162 t_fcntl(fd, F_SETLKW, &lock);
1168 /* for O_DIRECTORY */
1173 #define STRIPE_SIZE (2048 * 2048)
1174 #define STRIPE_OFFSET 0
1175 #define STRIPE_COUNT 1
1178 char path[MAX_PATH_LENGTH] = "";
1179 char file[MAX_PATH_LENGTH] = "";
1180 struct lov_user_md *lum = NULL;
1181 struct lov_user_ost_data *lo = NULL;
1182 int index, fd, buflen, rc;
1184 ENTER("setstripe/getstripe");
1185 snprintf(path, MAX_PATH_LENGTH, "%s/test_t55", lustre_path);
1186 snprintf(file, MAX_PATH_LENGTH, "%s/test_t55/file_t55", lustre_path);
1188 buflen = sizeof(struct lov_user_md);
1189 buflen += STRIPE_COUNT * sizeof(struct lov_user_ost_data);
1190 lum = (struct lov_user_md *)malloc(buflen);
1192 printf("out of memory!\n");
1195 memset(lum, 0, buflen);
1198 rc = llapi_file_create(path, STRIPE_SIZE, STRIPE_OFFSET,
1199 STRIPE_COUNT, LOV_PATTERN_RAID0);
1201 printf("llapi_file_create failed: rc = %d (%s) \n",
1208 fd = open(file, O_CREAT | O_RDWR, 0644);
1210 printf("open file(%s) failed: rc = %d (%s) \n)",
1211 file, fd, strerror(errno));
1217 lum->lmm_magic = LOV_USER_MAGIC;
1218 lum->lmm_stripe_count = STRIPE_COUNT;
1219 rc = ioctl(fd, LL_IOC_LOV_GETSTRIPE, lum);
1221 printf("dir:ioctl(LL_IOC_LOV_GETSTRIPE) failed: rc = %d(%s)\n",
1222 rc, strerror(errno));
1233 printf("lmm_magic: 0x%08X\n", lum->lmm_magic);
1234 printf("lmm_object_id: "LPX64"\n", lum->lmm_object_id);
1235 printf("lmm_object_gr: "LPX64"\n", lum->lmm_object_gr);
1236 printf("lmm_stripe_count: %u\n", (int)lum->lmm_stripe_count);
1237 printf("lmm_stripe_size: %u\n", lum->lmm_stripe_size);
1238 printf("lmm_stripe_pattern: %x\n", lum->lmm_pattern);
1240 for (index = 0; index < lum->lmm_stripe_count; index++) {
1241 lo = lum->lmm_objects + index;
1242 printf("object %d:\n", index);
1243 printf("\tobject_gr: "LPX64"\n", lo->l_object_gr);
1244 printf("\tobject_id: "LPX64"\n", lo->l_object_id);
1245 printf("\tost_gen: %#x\n", lo->l_ost_gen);
1246 printf("\tost_idx: %u\n", lo->l_ost_idx);
1250 if (lum->lmm_magic != LOV_USER_MAGIC ||
1251 lum->lmm_pattern != LOV_PATTERN_RAID0 ||
1252 lum->lmm_stripe_size != STRIPE_SIZE ||
1253 lum->lmm_objects[0].l_ost_idx != STRIPE_OFFSET ||
1254 lum->lmm_stripe_count != STRIPE_COUNT) {
1255 printf("incorrect striping information!\n");
1263 /* setstripe on regular file */
1264 rc = llapi_file_create(file, STRIPE_SIZE, STRIPE_OFFSET,
1265 STRIPE_COUNT, LOV_PATTERN_RAID0);
1267 printf("llapi_file_create failed: rc = %d (%s) \n",
1274 fd = open(file, O_RDWR, 0644);
1276 printf("failed to open(%s): rc = %d (%s)\n",
1277 file, fd, strerror(errno));
1284 lum->lmm_magic = LOV_USER_MAGIC;
1285 lum->lmm_stripe_count = STRIPE_COUNT;
1286 rc = ioctl(fd, LL_IOC_LOV_GETSTRIPE, lum);
1288 printf("file:ioctl(LL_IOC_LOV_GETSTRIPE) failed: rc = %d(%s)\n",
1289 rc, strerror(errno));
1299 printf("lmm_magic: 0x%08X\n", lum->lmm_magic);
1300 printf("lmm_object_id: "LPX64"\n", lum->lmm_object_id);
1301 printf("lmm_object_gr: "LPX64"\n", lum->lmm_object_gr);
1302 printf("lmm_stripe_count: %u\n", (int)lum->lmm_stripe_count);
1303 printf("lmm_stripe_size: %u\n", lum->lmm_stripe_size);
1304 printf("lmm_stripe_pattern: %x\n", lum->lmm_pattern);
1306 for (index = 0; index < lum->lmm_stripe_count; index++) {
1307 lo = lum->lmm_objects + index;
1308 printf("object %d:\n", index);
1309 printf("\tobject_gr: "LPX64"\n", lo->l_object_gr);
1310 printf("\tobject_id: "LPX64"\n", lo->l_object_id);
1311 printf("\tost_gen: %#x\n", lo->l_ost_gen);
1312 printf("\tost_idx: %u\n", lo->l_ost_idx);
1316 if (lum->lmm_magic != LOV_USER_MAGIC ||
1317 lum->lmm_pattern != LOV_PATTERN_RAID0 ||
1318 lum->lmm_stripe_size != STRIPE_SIZE ||
1319 lum->lmm_objects[0].l_ost_idx != STRIPE_OFFSET ||
1320 lum->lmm_stripe_count != STRIPE_COUNT) {
1321 printf("incorrect striping information!\n");
1335 * getdirentries should return -1 and set errno to EINVAL when the size
1336 * specified as an argument is too small to contain at least one entry
1337 * (see bugzilla ticket 12229)
1347 ENTER("getdirentries should fail if nbytes is too small");
1349 /* Set count to be very small. The result should be EINVAL */
1352 /* open the directory and call getdirentries */
1353 fd = t_opendir(lustre_path);
1355 rc = getdirentries(fd, (char *)&dir, nbytes, &basep);
1358 printf("Test failed: getdirentries returned %ld\n", rc);
1362 if (errno != EINVAL) {
1363 printf("Test failed: getdirentries returned %ld but errno is set"
1364 " to %d (should be EINVAL)\n", rc, errno);
1373 extern void __liblustre_setup_(void);
1374 extern void __liblustre_cleanup_(void);
1377 void usage(char *cmd)
1380 "usage: %s [-o test][-e test][-v] --target mgsnid:/fsname\n",
1382 printf(" %s --dumpfile dumpfile\n", cmd);
1387 int (*test)(char *name);
1424 int main(int argc, char * const argv[])
1426 struct testlist *test;
1427 int opt_index, c, rc = 0, numonly = 0, numexcept = 0;
1428 char *only[100], *except[100];
1429 static struct option long_opts[] = {
1430 {"dumpfile", 1, 0, 'd'},
1431 {"only", 1, 0, 'o'},
1432 {"except", 1, 0, 'e'},
1433 {"target", 1, 0, 't'},
1434 {"verbose", 1, 0, 'v'},
1438 while ((c = getopt_long(argc, argv, "d:e:o:t:v", long_opts, &opt_index)) != -1) {
1441 setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);
1445 printf("Not running test(s): ");
1446 printf("%s ", optarg);
1447 except[numexcept++] = optarg;
1451 printf("Only running test(s): ");
1452 printf("%s ", optarg);
1453 only[numonly++] = optarg;
1456 setenv(ENV_LUSTRE_MNTTGT, optarg, 1);
1467 if (getenv(ENV_LUSTRE_MNTTGT) == NULL &&
1468 getenv(ENV_LUSTRE_DUMPFILE) == NULL)
1476 __liblustre_setup_();
1478 buf_size = _npages * CFS_PAGE_SIZE;
1480 printf("allocating %d bytes buffer\n", buf_size);
1481 buf_alloc = calloc(1, buf_size);
1482 if (buf_alloc == NULL) {
1483 fprintf(stderr, "error allocating %d\n", buf_size);
1487 for (test = testlist; test->test != NULL; test++) {
1491 if (numexcept > 0) {
1492 len = strlen(test->name);
1493 for (i = 0; i < numexcept; i++) {
1494 olen = strlen(except[i]);
1499 if (strncmp(except[i], test->name, olen) == 0) {
1500 switch(test->name[olen]) {
1501 case '0': case '1': case '2': case '3':
1502 case '4': case '5': case '6': case '7':
1515 len = strlen(test->name);
1516 for (i = 0; i < numonly; i++) {
1517 olen = strlen(only[i]);
1522 if (strncmp(only[i], test->name, olen) == 0) {
1523 switch(test->name[olen]) {
1524 case '0': case '1': case '2': case '3':
1525 case '4': case '5': case '6': case '7':
1535 if (run && (rc = (test->test)(test->name)) != 0)
1541 printf("liblustre is about to shutdown\n");
1542 __liblustre_cleanup_();
1544 printf("complete successfully\n");