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>
35 #include <sys/queue.h>
42 #include <sys/ioctl.h>
44 #include "test_common.h"
46 #include <lustre/liblustreapi.h>
49 #define PAGE_SIZE getpagesize()
51 #define _npages (2048)
58 extern char *lustre_path;
64 sprintf(buf, "===== START %s: %s ", __FUNCTION__, (str)); \
67 memset(buf+len, '=', 100-len); \
72 gettimeofday(&start, NULL); \
77 struct timeval stop; \
78 char buf[100] = { '\0' }; \
79 int len = sizeof(buf) - 1; \
81 gettimeofday(&stop, NULL); \
82 usec = (stop.tv_sec - start.tv_sec) * 1000000 + \
83 (stop.tv_usec - start.tv_usec); \
84 len = snprintf(buf, len, \
85 "===== END TEST %s: successfully (%gs)", \
86 __FUNCTION__, (double)usec / 1000000); \
88 memset(buf+len, '=', sizeof(buf) - len); \
96 #define MAX_PATH_LENGTH 4096
100 char path[MAX_PATH_LENGTH] = "";
102 snprintf(path, MAX_PATH_LENGTH, "%s/test_t1", lustre_path);
105 printf("touch+unlink %s\n", path);
114 char path[MAX_PATH_LENGTH] = "";
116 ENTRY("mkdir/rmdir");
117 snprintf(path, MAX_PATH_LENGTH, "%s/test_t2", lustre_path);
126 char path[MAX_PATH_LENGTH] = "";
128 ENTRY("regular stat");
129 snprintf(path, MAX_PATH_LENGTH, "%s/test_t3", lustre_path);
132 t_check_stat(path, NULL);
139 char path[MAX_PATH_LENGTH] = "";
142 snprintf(path, MAX_PATH_LENGTH, "%s/test_t4", lustre_path);
145 t_check_stat(path, NULL);
152 char path[MAX_PATH_LENGTH] = "";
153 char path2[MAX_PATH_LENGTH] = "";
156 snprintf(path, MAX_PATH_LENGTH, "%s/test_t6", lustre_path);
157 snprintf(path2, MAX_PATH_LENGTH, "%s/test_t6_link", lustre_path);
160 t_symlink(path, path2);
161 t_check_stat(path2, NULL);
169 char path[MAX_PATH_LENGTH] = "";
170 char path2[MAX_PATH_LENGTH] = "";
171 char cwd[MAX_PATH_LENGTH] = "";
175 ENTRY("symlink + chdir and open");
176 snprintf(path, MAX_PATH_LENGTH, "%s/test_t6b", lustre_path);
177 snprintf(path2, MAX_PATH_LENGTH, "%s/test_t6b_link", lustre_path);
180 t_symlink(path, path2);
181 t_check_stat(path2, NULL);
183 tmp = getcwd(cwd, MAX_PATH_LENGTH);
185 fprintf(stderr, "current path too long to fit in "
186 "MAX_PATH_LENGTH?\n");
204 char path[MAX_PATH_LENGTH] = "";
208 snprintf(path, MAX_PATH_LENGTH, "%s/test_t7", lustre_path);
210 if (geteuid() != 0) {
211 rc = mknod(path, S_IFCHR | 0644, (5<<8 | 4));
212 if (rc != -1 || errno != EPERM) {
213 printf("mknod shouldn't success: rc %d, errno %d\n",
217 t_mknod(path, S_IFCHR | 0644, 5, 4);
218 t_check_stat(path, NULL);
226 char path[MAX_PATH_LENGTH] = "";
229 snprintf(path, MAX_PATH_LENGTH, "%s/test_t8", lustre_path);
233 t_chmod_raw(path, 0700);
234 t_check_stat(path, NULL);
239 t_chmod_raw(path, 0700);
240 t_check_stat(path, NULL);
248 char path[MAX_PATH_LENGTH] = "";
249 char path2[MAX_PATH_LENGTH] = "";
252 snprintf(path, MAX_PATH_LENGTH, "%s/test_t9", lustre_path);
253 snprintf(path2, MAX_PATH_LENGTH, "%s/test_t9_link", lustre_path);
257 t_check_stat(path, NULL);
258 t_check_stat(path2, NULL);
266 char dir1[MAX_PATH_LENGTH] = "";
267 char dir2[MAX_PATH_LENGTH] = "";
268 char path1[MAX_PATH_LENGTH] = "";
269 char path2[MAX_PATH_LENGTH] = "";
270 char rename1[MAX_PATH_LENGTH] = "";
271 char rename2[MAX_PATH_LENGTH] = "";
272 char rename3[MAX_PATH_LENGTH] = "";
275 snprintf(dir1, MAX_PATH_LENGTH, "%s/test_t10_dir1", lustre_path);
276 snprintf(dir2, MAX_PATH_LENGTH, "%s/test_t10_dir2", lustre_path);
277 snprintf(path1, MAX_PATH_LENGTH, "%s/test_t10_reg1", lustre_path);
278 snprintf(path2, MAX_PATH_LENGTH, "%s/test_t10_reg2", lustre_path);
279 snprintf(rename1, MAX_PATH_LENGTH, "%s/test_t10_dir1/rename1", lustre_path);
280 snprintf(rename2, MAX_PATH_LENGTH, "%s/test_t10_dir2/rename2", lustre_path);
281 snprintf(rename3, MAX_PATH_LENGTH, "%s/test_t10_dir2/rename3", lustre_path);
287 t_rename(path1, rename1);
288 t_rename(path2, rename2);
289 t_rename(rename1, rename2);
290 t_rename(dir1, rename3);
299 char *base=lustre_path;
300 char path[MAX_PATH_LENGTH], path2[MAX_PATH_LENGTH];
301 int i, j, level = 5, nreg = 5;
304 safe_strncpy(path, base, MAX_PATH_LENGTH);
306 for (i = 0; i < level; i++) {
307 for (j = 0; j < nreg; j++) {
308 sprintf(path2, "%s/file%d", path, j);
312 strcat(path, "/dir");
316 for (i = level; i > 0; i--) {
317 safe_strncpy(path, base, MAX_PATH_LENGTH);
318 for (j = 1; j < i; j++)
319 strcat(path, "/dir");
321 for (j = 0; j < nreg; j++) {
322 sprintf(path2, "%s/file%d", path, j);
326 strcat(path, "/dir");
335 char dir[MAX_PATH_LENGTH] = "";
338 ENTRY("empty directory readdir");
339 snprintf(dir, MAX_PATH_LENGTH, "%s/test_t12_dir", lustre_path);
343 t_ls(fd, buf, sizeof(buf));
351 char dir[MAX_PATH_LENGTH] = "";
354 const int nfiles = 20;
355 char *prefix = "test13_filename_prefix_";
357 ENTRY("multiple entries directory readdir");
358 snprintf(dir, MAX_PATH_LENGTH, "%s/test_t13_dir/", lustre_path);
361 printf("Creating %d files...\n", nfiles);
362 for (i = 0; i < nfiles; i++) {
363 sprintf(path, "%s%s%05d", dir, prefix, i);
367 t_ls(fd, buf, sizeof(buf));
369 printf("Cleanup...\n");
370 for (i = 0; i < nfiles; i++) {
371 sprintf(path, "%s%s%05d", dir, prefix, i);
380 char dir[MAX_PATH_LENGTH] = "";
383 const int nfiles = 256;
384 char *prefix = "test14_filename_long_prefix_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA___";
385 struct dirent64 *ent;
386 int fd, i, rc, pos, index;
388 ENTRY(">1 block(4k) directory readdir");
389 snprintf(dir, MAX_PATH_LENGTH, "%s/test_t14_dir/", lustre_path);
391 rc = mkdir(dir, 0755);
392 if (rc < 0 && errno != EEXIST) {
393 printf("mkdir(%s) error: %s\n", dir, strerror(errno));
396 printf("Creating %d files...\n", nfiles);
397 for (i = 0; i < nfiles; i++) {
398 sprintf(path, "%s%s%05d", dir, prefix, i);
402 printf("Listing...\n");
404 while ((rc = getdirentries64(fd, buf, 1024, &base)) > 0) {
409 ent = (struct dirent64 *) ((char*) buf + pos);
410 item = (char *) ent->d_name;
411 if (!strcmp(item, ".") || !strcmp(item, ".."))
413 if (strstr(item, prefix) != item) {
414 printf("found bad name %s\n", item);
417 printf("[%03d]: %s\n",
418 index++, item + strlen(prefix));
420 pos += ent->d_reclen;
424 printf("getdents error %d\n", rc);
427 if (index != nfiles) {
428 printf("get %d files != %d\n", index, nfiles);
432 printf("Cleanup...\n");
433 for (i = 0; i < nfiles; i++) {
434 sprintf(path, "%s%s%05d", dir, prefix, i);
443 char file[MAX_PATH_LENGTH] = "";
445 ENTRY("open-stat-close");
446 snprintf(file, MAX_PATH_LENGTH, "%s/test_t15_file", lustre_path);
450 t_check_stat(file, NULL);
458 char file[MAX_PATH_LENGTH] = "";
459 ENTRY("small-write-read");
460 snprintf(file, MAX_PATH_LENGTH, "%s/test_t16_file", lustre_path);
462 t_echo_create(file, "aaaaaaaaaaaaaaaaaaaaaa");
463 t_grep(file, "aaaaaaaaaaaaaaaaaaaaaa");
470 char file[MAX_PATH_LENGTH] = "";
472 ENTRY("open-unlink without close");
473 snprintf(file, MAX_PATH_LENGTH, "%s/test_t17_file", lustre_path);
475 fd = open(file, O_WRONLY | O_CREAT, 0666);
477 printf("failed to create file: %s\n", strerror(errno));
486 char file[MAX_PATH_LENGTH] = "";
489 struct stat statbuf[3];
490 ENTRY("write should change mtime/ctime");
491 snprintf(file, MAX_PATH_LENGTH, "%s/test_t18_file", lustre_path);
493 for (i = 0; i < 3; i++) {
494 fd = open(file, O_RDWR|O_CREAT|O_APPEND, (mode_t)0666);
496 printf("error open file: %s\n", strerror(errno));
499 if (write(fd, buf, sizeof(buf)) != sizeof(buf)) {
500 printf("error write file\n");
504 if(stat(file, &statbuf[i]) != 0) {
505 printf("Error stat\n");
508 printf("ctime %lu, mtime %lu\n",
509 statbuf[i].st_ctime, statbuf[i].st_mtime);
513 for (i = 1; i < 3; i++) {
514 if ((statbuf[i].st_ctime <= statbuf[i-1].st_ctime) ||
515 (statbuf[i].st_mtime <= statbuf[i-1].st_mtime)) {
516 printf("time error\n");
526 char file[MAX_PATH_LENGTH] = "";
528 struct stat statbuf[3];
529 ENTRY("utime should change mtime/atime/ctime");
530 snprintf(file, MAX_PATH_LENGTH, "%s/test_t18b_file", lustre_path);
533 for (i = 0; i < 3; i++) {
535 if(stat(file, &statbuf[i]) != 0) {
536 printf("Error stat\n");
539 printf("atime %lu, mtime %lu, ctime %lu\n",
540 statbuf[i].st_atime, statbuf[i].st_mtime,
541 statbuf[i].st_ctime);
545 for (i = 1; i < 3; i++) {
546 if ((statbuf[i].st_atime <= statbuf[i-1].st_atime) ||
547 (statbuf[i].st_mtime <= statbuf[i-1].st_mtime) ||
548 (statbuf[i].st_ctime <= statbuf[i-1].st_ctime)) {
549 printf("time error\n");
557 static int check_file_size(char *file, long long size)
561 if (stat(file, &statbuf) != 0) {
562 printf("Error stat(%s)\n", file);
565 if (statbuf.st_size != size) {
566 printf("size of %s: %ld != %lld\n", file, statbuf.st_size, size);
574 char file[MAX_PATH_LENGTH] = "";
577 ENTRY("open(O_TRUNC) should truncate file to 0-length");
578 snprintf(file, MAX_PATH_LENGTH, "%s/test_t19_file", lustre_path);
580 t_echo_create(file, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
582 fd = open(file, O_RDWR|O_CREAT|O_TRUNC, (mode_t)0666);
584 printf("error open file: %s\n", strerror(errno));
588 result = check_file_size(file, 0);
597 char file[MAX_PATH_LENGTH] = "";
602 ENTRY("trap app's general bad pointer for file i/o");
603 snprintf(file, MAX_PATH_LENGTH, "%s/test_t20_file", lustre_path);
605 fd = open(file, O_RDWR|O_CREAT, (mode_t)0666);
607 printf("error open file: %s\n", strerror(errno));
611 ret = write(fd, NULL, 20);
612 if (ret != -1 || errno != EFAULT) {
613 printf("write 1: ret %ld, errno %d\n", ret, errno);
616 ret = write(fd, (void *)-1, 20);
617 if (ret != -1 || errno != EFAULT) {
618 printf("write 2: ret %ld, errno %d\n", ret, errno);
621 iov[0].iov_base = NULL;
623 iov[1].iov_base = (void *)-1;
625 ret = writev(fd, iov, 2);
626 if (ret != -1 || errno != EFAULT) {
627 printf("writev 1: ret %ld, errno %d\n", ret, errno);
630 iov[0].iov_base = NULL;
632 iov[1].iov_base = buf;
633 iov[1].iov_len = sizeof(buf);
634 ret = writev(fd, iov, 2);
635 if (ret != sizeof(buf)) {
636 printf("write 3 ret %ld, error %d\n", ret, errno);
639 lseek(fd, 0, SEEK_SET);
641 ret = read(fd, NULL, 20);
642 if (ret != -1 || errno != EFAULT) {
643 printf("read 1: ret %ld, errno %d\n", ret, errno);
646 ret = read(fd, (void *)-1, 20);
647 if (ret != -1 || errno != EFAULT) {
648 printf("read 2: ret %ld, errno %d\n", ret, errno);
651 iov[0].iov_base = NULL;
653 iov[1].iov_base = (void *)-1;
655 ret = readv(fd, iov, 2);
656 if (ret != -1 || errno != EFAULT) {
657 printf("readv 1: ret %ld, errno %d\n", ret, errno);
660 iov[0].iov_base = NULL;
662 iov[1].iov_base = buf;
663 iov[1].iov_len = sizeof(buf);
664 ret = readv(fd, iov, 2);
665 if (ret != sizeof(buf)) {
666 printf("read 3 ret %ld, error %d\n", ret, errno);
677 char file[MAX_PATH_LENGTH] = "";
679 struct flock lock = {
681 .l_whence = SEEK_SET,
684 ENTRY("basic fcntl support");
685 snprintf(file, MAX_PATH_LENGTH, "%s/test_t21_file", lustre_path);
687 fd = open(file, O_RDWR|O_CREAT, (mode_t)0666);
689 printf("error open file: %s\n", file);
693 t_fcntl(fd, F_SETFL, O_APPEND);
694 if (!(ret = t_fcntl(fd, F_GETFL)) & O_APPEND) {
695 printf("error get flag: ret %x\n", ret);
699 t_fcntl(fd, F_SETLK, &lock);
700 t_fcntl(fd, F_GETLK, &lock);
701 lock.l_type = F_WRLCK;
702 t_fcntl(fd, F_SETLKW, &lock);
703 t_fcntl(fd, F_GETLK, &lock);
704 lock.l_type = F_UNLCK;
705 t_fcntl(fd, F_SETLK, &lock);
714 char file[MAX_PATH_LENGTH] = "";
716 char *str = "1234567890";
719 ENTRY("make sure O_APPEND take effect");
720 snprintf(file, MAX_PATH_LENGTH, "%s/test_t22_file", lustre_path);
722 fd = open(file, O_RDWR|O_CREAT|O_APPEND, (mode_t)0666);
724 printf("error open file: %s\n", strerror(errno));
728 lseek(fd, 100, SEEK_SET);
729 ret = write(fd, str, strlen(str));
730 if (ret != strlen(str)) {
731 printf("write 1: ret %ld, errno %d\n", ret, errno);
735 lseek(fd, 0, SEEK_SET);
736 ret = read(fd, buf, sizeof(buf));
737 if (ret != strlen(str)) {
738 printf("read 1 got %ld\n", ret);
742 if (memcmp(buf, str, strlen(str))) {
743 printf("read 1 data err\n");
747 if (fcntl(fd, F_SETFL, 0)) {
748 printf("fcntl err: %s\n", strerror(errno));
752 lseek(fd, 100, SEEK_SET);
753 ret = write(fd, str, strlen(str));
754 if (ret != strlen(str)) {
755 printf("write 2: ret %ld, errno %d\n", ret, errno);
759 lseek(fd, 100, SEEK_SET);
760 ret = read(fd, buf, sizeof(buf));
761 if (ret != strlen(str)) {
762 printf("read 2 got %ld\n", ret);
766 if (memcmp(buf, str, strlen(str))) {
767 printf("read 2 data err\n");
778 char path[MAX_PATH_LENGTH];
783 ENTRY("handle seek > 2GB");
784 snprintf(path, MAX_PATH_LENGTH, "%s/f%s", lustre_path, name);
786 fd = open(path, O_WRONLY | O_CREAT | O_LARGEFILE, 0666);
788 printf("failed to create file %s: %s\n", path, strerror(errno));
792 off = 2048ULL * 1024 * 1024 - buf_size / 2;
793 ret = lseek(fd, off, SEEK_SET);
795 printf("seek error for initial %llu != %llu\n",
796 ret, (long long)off);
800 ret = write(fd, buf_alloc, buf_size);
801 if (ret != buf_size) {
802 printf("write error for %d != %llubytes @ %llu\n",
803 buf_size, ret, (long long)off);
809 ret = lseek(fd, off, SEEK_SET);
811 printf("seek < 2GB error for %llu != %llu\n",
812 ret, (long long)off);
814 perror("seek < 2GB");
818 ret = lseek(fd, off + buf_size - 2, SEEK_SET);
819 if (ret != off + buf_size - 2) {
820 printf("seek > 2GB error for %llu != %llu\n",
821 ret, (long long)off);
823 perror("seek > 2GB");
827 ret = lseek(fd, -buf_size + 2, SEEK_CUR);
829 printf("relative seek error for %d %llu != %llu\n",
830 -buf_size + 2, ret, off);
832 perror("relative seek");
836 ret = lseek(fd, 0, SEEK_END);
837 if (ret != off + buf_size) {
838 printf("end seek error for %llu != %llu\n",
839 ret, (long long)off + buf_size);
845 ret = lseek(fd, 0, SEEK_SET);
847 printf("seek 0 error for %llu != 0\n", ret);
853 off = 2048ULL * 1024 * 1024, SEEK_SET;
854 ret = lseek(fd, off, SEEK_SET);
856 printf("seek 2GB error for %llu != %llu\n", ret, off);
867 /* pos: i/o start from
868 * xfer: npages per transfer
870 static int pages_io(int xfer, loff_t pos)
872 char path[MAX_PATH_LENGTH] = "";
874 int check_sum[_npages] = {0,}, *buf;
875 int fd, rc, i, j, data_error = 0;
876 struct timeval tw1, tw2, tr1, tr2;
880 snprintf(path, MAX_PATH_LENGTH, "%s/test_t50", lustre_path);
882 memset(buf_alloc, 0, buf_size);
884 /* create sample data */
885 for (i = 0, buf = buf_alloc; i < _npages; i++) {
886 for (j = 0; j < PAGE_SIZE/sizeof(int); j++, buf++) {
891 /* compute checksum */
892 for (i = 0, buf = buf_alloc; i < _npages; i++) {
893 for (j = 0; j < PAGE_SIZE/sizeof(int); j++, buf++) {
894 check_sum[i] += *buf;
904 ret = lseek(fd, pos, SEEK_SET);
906 perror("write seek");
909 gettimeofday(&tw1, NULL);
910 for (i = 0, buf = buf_alloc; i < _npages;
911 i += xfer, buf += xfer * PAGE_SIZE / sizeof(int)) {
912 rc = write(fd, buf, PAGE_SIZE * xfer);
913 if (rc != PAGE_SIZE * xfer) {
914 printf("write error (i %d, rc %d): %s\n", i, rc,
919 gettimeofday(&tw2, NULL);
921 memset(buf_alloc, 0, buf_size);
924 ret = lseek(fd, pos, SEEK_SET);
929 gettimeofday(&tr1, NULL);
930 for (i = 0, buf = buf_alloc; i < _npages;
931 i += xfer, buf += xfer * PAGE_SIZE / sizeof(int)) {
932 rc = read(fd, buf, PAGE_SIZE * xfer);
933 if (rc != PAGE_SIZE * xfer) {
934 printf("read error (i %d, rc %d): %s\n", i, rc,
939 gettimeofday(&tr2, NULL);
941 /* compute checksum */
942 for (i = 0, buf = buf_alloc; i < _npages; i++) {
944 for (j = 0; j < PAGE_SIZE/sizeof(int); j++, buf++) {
947 if (sum != check_sum[i]) {
949 printf("chunk %d checksum error expected %#x got %#x\n",
950 i, check_sum[i], sum);
956 tw = (tw2.tv_sec - tw1.tv_sec) * 1000000 + (tw2.tv_usec - tw1.tv_usec);
957 tr = (tr2.tv_sec - tr1.tv_sec) * 1000000 + (tr2.tv_usec - tr1.tv_usec);
958 printf(" (R:%.3fM/s, W:%.3fM/s)\n",
959 (_npages * PAGE_SIZE) / (tw / 1000000.0) / (1024 * 1024),
960 (_npages * PAGE_SIZE) / (tr / 1000000.0) / (1024 * 1024));
973 ENTRY("4k aligned i/o sanity");
974 while (np <= _npages) {
975 printf("%3d per xfer(total %d)...\t", np, _npages);
977 if (pages_io(np, offset) != 0)
986 loff_t off_array[] = {1, 17, 255, 258, 4095, 4097, 8191,
987 1024*1024*1024*1024ULL};
991 ENTRY("4k un-aligned i/o sanity");
992 for (i = 0; i < sizeof(off_array)/sizeof(loff_t); i++) {
993 offset = off_array[i];
994 printf("16 per xfer(total %d), offset %10lld...\t",
996 if (pages_io(16, offset) != 0)
1009 * truncate(2) checks.
1013 char file[MAX_PATH_LENGTH] = "";
1018 ENTRY("truncate() should truncate file to proper length");
1019 snprintf(file, MAX_PATH_LENGTH, "%s/test_t51_file", lustre_path);
1021 for (size = 0; size < T51_NR * T51_STEP; size += T51_STEP) {
1022 t_echo_create(file, "");
1023 if (truncate(file, size) != 0) {
1024 printf("\nerror truncating file: %s\n",strerror(errno));
1027 result = check_file_size(file, size);
1032 t_echo_create(file, "");
1033 fd = open(file, O_RDWR|O_CREAT, (mode_t)0666);
1035 printf("\nerror open file: %s\n", strerror(errno));
1038 if (ftruncate(fd, size) != 0) {
1039 printf("\nerror ftruncating file:%s\n",strerror(errno));
1043 result = check_file_size(file, size);
1047 if (size % (T51_STEP * (T51_NR / 75)) == 0) {
1056 * check atime update during read
1060 char file[MAX_PATH_LENGTH] = "";
1062 struct stat statbuf;
1067 ENTRY("atime should be updated during read");
1068 snprintf(file, MAX_PATH_LENGTH, "%s/test_t52_file", lustre_path);
1070 t_echo_create(file, "check atime update during read");
1071 fd = open(file, O_RDONLY);
1073 printf("\nerror open file: %s\n", strerror(errno));
1076 stat(file, &statbuf);
1077 printf("st_atime=%s", ctime(&statbuf.st_atime));
1078 atime = statbuf.st_atime;
1079 for (i = 0; i < 3; i++) {
1081 read(fd, buf, sizeof(buf));
1082 stat(file, &statbuf);
1083 printf("st_atime=%s", ctime(&statbuf.st_atime));
1084 diff = statbuf.st_atime - atime;
1086 printf("atime doesn't updated! failed!\n");
1091 atime = statbuf.st_atime;
1098 #define NEW_TIME 10000
1101 char file[MAX_PATH_LENGTH] = "";
1102 struct utimbuf times; /* struct. buffer for utime() */
1103 struct stat stat_buf; /* struct buffer to hold file info. */
1104 time_t mtime, atime;
1106 ENTRY("mtime/atime should be updated by utime() call");
1107 snprintf(file, MAX_PATH_LENGTH, "%s/test_t53_file", lustre_path);
1109 t_echo_create(file, "check mtime/atime update by utime() call");
1111 /* Initialize the modification and access time in the times arg */
1112 times.actime = NEW_TIME+10;
1113 times.modtime = NEW_TIME;
1115 /* file modification/access time */
1116 utime(file, ×);
1118 if (stat(file, &stat_buf) < 0) {
1119 printf("stat(2) of %s failed, error:%d %s\n",
1120 file, errno, strerror(errno));
1122 mtime = stat_buf.st_mtime;
1123 atime = stat_buf.st_atime;
1125 if ((mtime == NEW_TIME) && (atime == NEW_TIME + 10)) {
1130 printf("mod time %ld, expected %ld\n", mtime, (long)NEW_TIME);
1131 printf("acc time %ld, expected %ld\n", atime, (long)NEW_TIME + 10);
1139 char file[MAX_PATH_LENGTH] = "";
1143 ENTRY("fcntl should return 0 when succeed in getting flock");
1144 snprintf(file, MAX_PATH_LENGTH, "%s/test_t54_file", lustre_path);
1146 t_echo_create(file, "fcntl should return 0 when succeed");
1148 fd = open(file, O_RDWR);
1150 printf("\nerror open file: %s\n", strerror(errno));
1153 lock.l_type = F_WRLCK;
1157 if ((err = t_fcntl(fd, F_SETLKW, &lock)) != 0) {
1158 fprintf(stderr, "fcntl returned: %d (%s)\n",
1159 err, strerror(err));
1165 lock.l_type = F_UNLCK;
1166 t_fcntl(fd, F_SETLKW, &lock);
1172 /* for O_DIRECTORY */
1177 #define STRIPE_SIZE (2048 * 2048)
1178 #define STRIPE_OFFSET 0
1179 #define STRIPE_COUNT 1
1182 char path[MAX_PATH_LENGTH] = "";
1183 char file[MAX_PATH_LENGTH] = "";
1184 struct lov_user_md *lum = NULL;
1185 struct lov_user_ost_data *lo = NULL;
1186 int index, fd, buflen, rc;
1188 ENTRY("setstripe/getstripe");
1189 snprintf(path, MAX_PATH_LENGTH, "%s/test_t55", lustre_path);
1190 snprintf(file, MAX_PATH_LENGTH, "%s/test_t55/file_t55", lustre_path);
1192 buflen = sizeof(struct lov_user_md);
1193 buflen += STRIPE_COUNT * sizeof(struct lov_user_ost_data);
1194 lum = (struct lov_user_md *)malloc(buflen);
1196 printf("out of memory!\n");
1199 memset(lum, 0, buflen);
1202 rc = llapi_file_create(path, STRIPE_SIZE, STRIPE_OFFSET,
1203 STRIPE_COUNT, LOV_PATTERN_RAID0);
1205 printf("llapi_file_create failed: rc = %d (%s) \n",
1212 fd = open(file, O_CREAT | O_RDWR, 0644);
1214 printf("open file(%s) failed: rc = %d (%s) \n)",
1215 file, fd, strerror(errno));
1221 lum->lmm_magic = LOV_USER_MAGIC;
1222 lum->lmm_stripe_count = STRIPE_COUNT;
1223 rc = ioctl(fd, LL_IOC_LOV_GETSTRIPE, lum);
1225 printf("dir:ioctl(LL_IOC_LOV_GETSTRIPE) failed: rc = %d(%s)\n",
1226 rc, strerror(errno));
1237 printf("lmm_magic: 0x%08X\n", lum->lmm_magic);
1238 printf("lmm_object_id: "LPX64"\n", lum->lmm_object_id);
1239 printf("lmm_object_gr: "LPX64"\n", lum->lmm_object_gr);
1240 printf("lmm_stripe_count: %u\n", (int)lum->lmm_stripe_count);
1241 printf("lmm_stripe_size: %u\n", lum->lmm_stripe_size);
1242 printf("lmm_stripe_pattern: %x\n", lum->lmm_pattern);
1244 for (index = 0; index < lum->lmm_stripe_count; index++) {
1245 lo = lum->lmm_objects + index;
1246 printf("object %d:\n", index);
1247 printf("\tobject_gr: "LPX64"\n", lo->l_object_gr);
1248 printf("\tobject_id: "LPX64"\n", lo->l_object_id);
1249 printf("\tost_gen: %#x\n", lo->l_ost_gen);
1250 printf("\tost_idx: %u\n", lo->l_ost_idx);
1254 if (lum->lmm_magic != LOV_USER_MAGIC ||
1255 lum->lmm_pattern != LOV_PATTERN_RAID0 ||
1256 lum->lmm_stripe_size != STRIPE_SIZE ||
1257 lum->lmm_objects[0].l_ost_idx != STRIPE_OFFSET ||
1258 lum->lmm_stripe_count != STRIPE_COUNT) {
1259 printf("incorrect striping information!\n");
1267 /* setstripe on regular file */
1268 rc = llapi_file_create(file, STRIPE_SIZE, STRIPE_OFFSET,
1269 STRIPE_COUNT, LOV_PATTERN_RAID0);
1271 printf("llapi_file_create failed: rc = %d (%s) \n",
1278 fd = open(file, O_RDWR, 0644);
1280 printf("failed to open(%s): rc = %d (%s)\n",
1281 file, fd, strerror(errno));
1288 lum->lmm_magic = LOV_USER_MAGIC;
1289 lum->lmm_stripe_count = STRIPE_COUNT;
1290 rc = ioctl(fd, LL_IOC_LOV_GETSTRIPE, lum);
1292 printf("file:ioctl(LL_IOC_LOV_GETSTRIPE) failed: rc = %d(%s)\n",
1293 rc, strerror(errno));
1303 printf("lmm_magic: 0x%08X\n", lum->lmm_magic);
1304 printf("lmm_object_id: "LPX64"\n", lum->lmm_object_id);
1305 printf("lmm_object_gr: "LPX64"\n", lum->lmm_object_gr);
1306 printf("lmm_stripe_count: %u\n", (int)lum->lmm_stripe_count);
1307 printf("lmm_stripe_size: %u\n", lum->lmm_stripe_size);
1308 printf("lmm_stripe_pattern: %x\n", lum->lmm_pattern);
1310 for (index = 0; index < lum->lmm_stripe_count; index++) {
1311 lo = lum->lmm_objects + index;
1312 printf("object %d:\n", index);
1313 printf("\tobject_gr: "LPX64"\n", lo->l_object_gr);
1314 printf("\tobject_id: "LPX64"\n", lo->l_object_id);
1315 printf("\tost_gen: %#x\n", lo->l_ost_gen);
1316 printf("\tost_idx: %u\n", lo->l_ost_idx);
1320 if (lum->lmm_magic != LOV_USER_MAGIC ||
1321 lum->lmm_pattern != LOV_PATTERN_RAID0 ||
1322 lum->lmm_stripe_size != STRIPE_SIZE ||
1323 lum->lmm_objects[0].l_ost_idx != STRIPE_OFFSET ||
1324 lum->lmm_stripe_count != STRIPE_COUNT) {
1325 printf("incorrect striping information!\n");
1339 * getdirentries should return -1 and set errno to EINVAL when the size
1340 * specified as an argument is too small to contain at least one entry
1341 * (see bugzilla ticket 12229)
1351 ENTRY("getdirentries should fail if nbytes is too small");
1353 /* Set count to be very small. The result should be EINVAL */
1356 /* open the directory and call getdirentries */
1357 fd = t_opendir(lustre_path);
1359 rc = getdirentries(fd, (char *)&dir, nbytes, &basep);
1362 printf("Test failed: getdirentries returned %d\n", rc);
1366 if (errno != EINVAL) {
1367 printf("Test failed: getdirentries returned %d but errno is set"
1368 " to %d (should be EINVAL)\n", rc, errno);
1377 extern void __liblustre_setup_(void);
1378 extern void __liblustre_cleanup_(void);
1381 void usage(char *cmd)
1384 "usage: %s [--only {test}] --target mgsnid:/fsname\n",
1386 printf(" %s --dumpfile dumpfile\n", cmd);
1391 int (*test)(char *name);
1428 int main(int argc, char * const argv[])
1430 struct testlist *test;
1431 int opt_index, c, rc = 0, numonly = 0;
1433 static struct option long_opts[] = {
1434 {"dumpfile", 1, 0, 'd'},
1435 {"only", 1, 0, 'o'},
1436 {"target", 1, 0, 't'},
1437 {"verbose", 1, 0, 'v'},
1441 while ((c = getopt_long(argc, argv, "d:o:t:v", long_opts, &opt_index)) != -1) {
1444 setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);
1448 printf("Only running test(s): ");
1449 printf("%s ", optarg);
1450 only[numonly++] = optarg;
1453 setenv(ENV_LUSTRE_MNTTGT, optarg, 1);
1464 if (getenv(ENV_LUSTRE_MNTTGT) == NULL &&
1465 getenv(ENV_LUSTRE_DUMPFILE) == NULL)
1473 __liblustre_setup_();
1475 buf_size = _npages * PAGE_SIZE;
1477 printf("allocating %d bytes buffer\n", buf_size);
1478 buf_alloc = calloc(1, buf_size);
1479 if (buf_alloc == NULL) {
1480 fprintf(stderr, "error allocating %d\n", buf_size);
1484 for (test = testlist; test->test != NULL; test++) {
1491 len = strlen(test->name);
1492 for (i = 0; i < numonly; i++) {
1493 int olen = strlen(only[i]);
1498 if (strncmp(only[i], test->name, olen) == 0) {
1499 switch(test->name[olen]) {
1500 case '0': case '1': case '2': case '3':
1501 case '4': case '5': case '6': case '7':
1511 if (run && (rc = (test->test)(test->name)) != 0)
1517 printf("liblustre is about to shutdown\n");
1518 __liblustre_cleanup_();
1520 printf("complete successfully\n");