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 "test_common.h"
44 #include <lustre/lustre_user.h>
47 #define PAGE_SIZE getpagesize()
49 #define _npages (2048)
56 extern char *lustre_path;
62 sprintf(buf, "===== START %s: %s ", __FUNCTION__, (str)); \
65 memset(buf+len, '=', 100-len); \
70 gettimeofday(&start, NULL); \
75 struct timeval stop; \
76 char buf[100] = { '\0' }; \
77 int len = sizeof(buf) - 1; \
79 gettimeofday(&stop, NULL); \
80 usec = (stop.tv_sec - start.tv_sec) * 1000000 + \
81 (stop.tv_usec - start.tv_usec); \
82 len = snprintf(buf, len, \
83 "===== END TEST %s: successfully (%gs)", \
84 __FUNCTION__, (double)usec / 1000000); \
86 memset(buf+len, '=', sizeof(buf) - len); \
94 #define MAX_PATH_LENGTH 4096
98 char path[MAX_PATH_LENGTH] = "";
100 snprintf(path, MAX_PATH_LENGTH, "%s/test_t1", lustre_path);
103 printf("touch+unlink %s\n", path);
112 char path[MAX_PATH_LENGTH] = "";
114 ENTRY("mkdir/rmdir");
115 snprintf(path, MAX_PATH_LENGTH, "%s/test_t2", lustre_path);
124 char path[MAX_PATH_LENGTH] = "";
126 ENTRY("regular stat");
127 snprintf(path, MAX_PATH_LENGTH, "%s/test_t3", lustre_path);
130 t_check_stat(path, NULL);
137 char path[MAX_PATH_LENGTH] = "";
140 snprintf(path, MAX_PATH_LENGTH, "%s/test_t4", lustre_path);
143 t_check_stat(path, NULL);
150 char path[MAX_PATH_LENGTH] = "";
151 char path2[MAX_PATH_LENGTH] = "";
154 snprintf(path, MAX_PATH_LENGTH, "%s/test_t6", lustre_path);
155 snprintf(path2, MAX_PATH_LENGTH, "%s/test_t6_link", lustre_path);
158 t_symlink(path, path2);
159 t_check_stat(path2, NULL);
167 char path[MAX_PATH_LENGTH] = "";
168 char path2[MAX_PATH_LENGTH] = "";
169 char cwd[MAX_PATH_LENGTH] = "";
173 ENTRY("symlink + chdir and open");
174 snprintf(path, MAX_PATH_LENGTH, "%s/test_t6b", lustre_path);
175 snprintf(path2, MAX_PATH_LENGTH, "%s/test_t6b_link", lustre_path);
178 t_symlink(path, path2);
179 t_check_stat(path2, NULL);
181 tmp = getcwd(cwd, MAX_PATH_LENGTH);
183 fprintf(stderr, "current path too long to fit in "
184 "MAX_PATH_LENGTH?\n");
202 char path[MAX_PATH_LENGTH] = "";
206 snprintf(path, MAX_PATH_LENGTH, "%s/test_t7", lustre_path);
208 if (geteuid() != 0) {
209 rc = mknod(path, S_IFCHR | 0644, (5<<8 | 4));
210 if (rc != -1 || errno != EPERM) {
211 printf("mknod shouldn't success: rc %d, errno %d\n",
215 t_mknod(path, S_IFCHR | 0644, 5, 4);
216 t_check_stat(path, NULL);
224 char path[MAX_PATH_LENGTH] = "";
227 snprintf(path, MAX_PATH_LENGTH, "%s/test_t8", lustre_path);
231 t_chmod_raw(path, 0700);
232 t_check_stat(path, NULL);
237 t_chmod_raw(path, 0700);
238 t_check_stat(path, NULL);
246 char path[MAX_PATH_LENGTH] = "";
247 char path2[MAX_PATH_LENGTH] = "";
250 snprintf(path, MAX_PATH_LENGTH, "%s/test_t9", lustre_path);
251 snprintf(path2, MAX_PATH_LENGTH, "%s/test_t9_link", lustre_path);
255 t_check_stat(path, NULL);
256 t_check_stat(path2, NULL);
264 char dir1[MAX_PATH_LENGTH] = "";
265 char dir2[MAX_PATH_LENGTH] = "";
266 char path1[MAX_PATH_LENGTH] = "";
267 char path2[MAX_PATH_LENGTH] = "";
268 char rename1[MAX_PATH_LENGTH] = "";
269 char rename2[MAX_PATH_LENGTH] = "";
270 char rename3[MAX_PATH_LENGTH] = "";
273 snprintf(dir1, MAX_PATH_LENGTH, "%s/test_t10_dir1", lustre_path);
274 snprintf(dir2, MAX_PATH_LENGTH, "%s/test_t10_dir2", lustre_path);
275 snprintf(path1, MAX_PATH_LENGTH, "%s/test_t10_reg1", lustre_path);
276 snprintf(path2, MAX_PATH_LENGTH, "%s/test_t10_reg2", lustre_path);
277 snprintf(rename1, MAX_PATH_LENGTH, "%s/test_t10_dir1/rename1", lustre_path);
278 snprintf(rename2, MAX_PATH_LENGTH, "%s/test_t10_dir2/rename2", lustre_path);
279 snprintf(rename3, MAX_PATH_LENGTH, "%s/test_t10_dir2/rename3", lustre_path);
285 t_rename(path1, rename1);
286 t_rename(path2, rename2);
287 t_rename(rename1, rename2);
288 t_rename(dir1, rename3);
297 char *base=lustre_path;
298 char path[MAX_PATH_LENGTH], path2[MAX_PATH_LENGTH];
299 int i, j, level = 5, nreg = 5;
302 safe_strncpy(path, base, MAX_PATH_LENGTH);
304 for (i = 0; i < level; i++) {
305 for (j = 0; j < nreg; j++) {
306 sprintf(path2, "%s/file%d", path, j);
310 strcat(path, "/dir");
314 for (i = level; i > 0; i--) {
315 safe_strncpy(path, base, MAX_PATH_LENGTH);
316 for (j = 1; j < i; j++)
317 strcat(path, "/dir");
319 for (j = 0; j < nreg; j++) {
320 sprintf(path2, "%s/file%d", path, j);
324 strcat(path, "/dir");
333 char dir[MAX_PATH_LENGTH] = "";
336 ENTRY("empty directory readdir");
337 snprintf(dir, MAX_PATH_LENGTH, "%s/test_t12_dir", lustre_path);
341 t_ls(fd, buf, sizeof(buf));
349 char dir[MAX_PATH_LENGTH] = "";
352 const int nfiles = 20;
353 char *prefix = "test13_filename_prefix_";
355 ENTRY("multiple entries directory readdir");
356 snprintf(dir, MAX_PATH_LENGTH, "%s/test_t13_dir/", lustre_path);
359 printf("Creating %d files...\n", nfiles);
360 for (i = 0; i < nfiles; i++) {
361 sprintf(path, "%s%s%05d", dir, prefix, i);
365 t_ls(fd, buf, sizeof(buf));
367 printf("Cleanup...\n");
368 for (i = 0; i < nfiles; i++) {
369 sprintf(path, "%s%s%05d", dir, prefix, i);
378 char dir[MAX_PATH_LENGTH] = "";
381 const int nfiles = 256;
382 char *prefix = "test14_filename_long_prefix_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA___";
383 struct dirent64 *ent;
384 int fd, i, rc, pos, index;
386 ENTRY(">1 block(4k) directory readdir");
387 snprintf(dir, MAX_PATH_LENGTH, "%s/test_t14_dir/", lustre_path);
389 rc = mkdir(dir, 0755);
390 if (rc < 0 && errno != EEXIST) {
391 printf("mkdir(%s) error: %s\n", dir, strerror(errno));
394 printf("Creating %d files...\n", nfiles);
395 for (i = 0; i < nfiles; i++) {
396 sprintf(path, "%s%s%05d", dir, prefix, i);
400 printf("Listing...\n");
402 while ((rc = getdirentries64(fd, buf, 1024, &base)) > 0) {
407 ent = (struct dirent64 *) ((char*) buf + pos);
408 item = (char *) ent->d_name;
409 if (!strcmp(item, ".") || !strcmp(item, ".."))
411 if (strstr(item, prefix) != item) {
412 printf("found bad name %s\n", item);
415 printf("[%03d]: %s\n",
416 index++, item + strlen(prefix));
418 pos += ent->d_reclen;
422 printf("getdents error %d\n", rc);
425 if (index != nfiles) {
426 printf("get %d files != %d\n", index, nfiles);
430 printf("Cleanup...\n");
431 for (i = 0; i < nfiles; i++) {
432 sprintf(path, "%s%s%05d", dir, prefix, i);
441 char file[MAX_PATH_LENGTH] = "";
443 ENTRY("open-stat-close");
444 snprintf(file, MAX_PATH_LENGTH, "%s/test_t15_file", lustre_path);
448 t_check_stat(file, NULL);
456 char file[MAX_PATH_LENGTH] = "";
457 ENTRY("small-write-read");
458 snprintf(file, MAX_PATH_LENGTH, "%s/test_t16_file", lustre_path);
460 t_echo_create(file, "aaaaaaaaaaaaaaaaaaaaaa");
461 t_grep(file, "aaaaaaaaaaaaaaaaaaaaaa");
468 char file[MAX_PATH_LENGTH] = "";
470 ENTRY("open-unlink without close");
471 snprintf(file, MAX_PATH_LENGTH, "%s/test_t17_file", lustre_path);
473 fd = open(file, O_WRONLY | O_CREAT, 0666);
475 printf("failed to create file: %s\n", strerror(errno));
484 char file[MAX_PATH_LENGTH] = "";
487 struct stat statbuf[3];
488 ENTRY("write should change mtime/ctime");
489 snprintf(file, MAX_PATH_LENGTH, "%s/test_t18_file", lustre_path);
491 for (i = 0; i < 3; i++) {
492 fd = open(file, O_RDWR|O_CREAT|O_APPEND, (mode_t)0666);
494 printf("error open file: %s\n", strerror(errno));
497 if (write(fd, buf, sizeof(buf)) != sizeof(buf)) {
498 printf("error write file\n");
502 if(stat(file, &statbuf[i]) != 0) {
503 printf("Error stat\n");
506 printf("ctime %lu, mtime %lu\n",
507 statbuf[i].st_ctime, statbuf[i].st_mtime);
511 for (i = 1; i < 3; i++) {
512 if ((statbuf[i].st_ctime <= statbuf[i-1].st_ctime) ||
513 (statbuf[i].st_mtime <= statbuf[i-1].st_mtime)) {
514 printf("time error\n");
524 char file[MAX_PATH_LENGTH] = "";
527 struct stat statbuf[3];
528 ENTRY("utime should change mtime/atime/ctime");
529 snprintf(file, MAX_PATH_LENGTH, "%s/test_t18b_file", lustre_path);
532 for (i = 0; i < 3; i++) {
534 if(stat(file, &statbuf[i]) != 0) {
535 printf("Error stat\n");
538 printf("atime %lu, mtime %lu, ctime %lu\n",
539 statbuf[i].st_atime, statbuf[i].st_mtime,
540 statbuf[i].st_ctime);
544 for (i = 1; i < 3; i++) {
545 if ((statbuf[i].st_atime <= statbuf[i-1].st_atime) ||
546 (statbuf[i].st_mtime <= statbuf[i-1].st_mtime) ||
547 (statbuf[i].st_ctime <= statbuf[i-1].st_ctime)) {
548 printf("time error\n");
556 static int check_file_size(char *file, off_t size)
560 if (stat(file, &statbuf) != 0) {
561 printf("Error stat(%s)\n", file);
564 if (statbuf.st_size != size) {
565 printf("size of %s: %ld != %ld\n", file, statbuf.st_size, size);
573 char file[MAX_PATH_LENGTH] = "";
576 ENTRY("open(O_TRUNC) should truncate file to 0-length");
577 snprintf(file, MAX_PATH_LENGTH, "%s/test_t19_file", lustre_path);
579 t_echo_create(file, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
581 fd = open(file, O_RDWR|O_CREAT|O_TRUNC, (mode_t)0666);
583 printf("error open file: %s\n", strerror(errno));
587 result = check_file_size(file, 0);
596 char file[MAX_PATH_LENGTH] = "";
601 ENTRY("trap app's general bad pointer for file i/o");
602 snprintf(file, MAX_PATH_LENGTH, "%s/test_t20_file", lustre_path);
604 fd = open(file, O_RDWR|O_CREAT, (mode_t)0666);
606 printf("error open file: %s\n", strerror(errno));
610 ret = write(fd, NULL, 20);
611 if (ret != -1 || errno != EFAULT) {
612 printf("write 1: ret %ld, errno %d\n", ret, errno);
615 ret = write(fd, (void *)-1, 20);
616 if (ret != -1 || errno != EFAULT) {
617 printf("write 2: ret %ld, errno %d\n", ret, errno);
620 iov[0].iov_base = NULL;
622 iov[1].iov_base = (void *)-1;
624 ret = writev(fd, iov, 2);
625 if (ret != -1 || errno != EFAULT) {
626 printf("writev 1: ret %ld, errno %d\n", ret, errno);
629 iov[0].iov_base = NULL;
631 iov[1].iov_base = buf;
632 iov[1].iov_len = sizeof(buf);
633 ret = writev(fd, iov, 2);
634 if (ret != sizeof(buf)) {
635 printf("write 3 ret %ld, error %d\n", ret, errno);
638 lseek(fd, 0, SEEK_SET);
640 ret = read(fd, NULL, 20);
641 if (ret != -1 || errno != EFAULT) {
642 printf("read 1: ret %ld, errno %d\n", ret, errno);
645 ret = read(fd, (void *)-1, 20);
646 if (ret != -1 || errno != EFAULT) {
647 printf("read 2: ret %ld, errno %d\n", ret, errno);
650 iov[0].iov_base = NULL;
652 iov[1].iov_base = (void *)-1;
654 ret = readv(fd, iov, 2);
655 if (ret != -1 || errno != EFAULT) {
656 printf("readv 1: ret %ld, errno %d\n", ret, errno);
659 iov[0].iov_base = NULL;
661 iov[1].iov_base = buf;
662 iov[1].iov_len = sizeof(buf);
663 ret = readv(fd, iov, 2);
664 if (ret != sizeof(buf)) {
665 printf("read 3 ret %ld, error %d\n", ret, errno);
676 char file[MAX_PATH_LENGTH] = "";
678 struct flock lock = {
680 .l_whence = SEEK_SET,
683 ENTRY("basic fcntl support");
684 snprintf(file, MAX_PATH_LENGTH, "%s/test_t21_file", lustre_path);
686 fd = open(file, O_RDWR|O_CREAT, (mode_t)0666);
688 printf("error open file: %m\n", file);
692 t_fcntl(fd, F_SETFL, O_APPEND);
693 if (!(ret = t_fcntl(fd, F_GETFL)) & O_APPEND) {
694 printf("error get flag: ret %x\n", ret);
698 t_fcntl(fd, F_SETLK, &lock);
699 t_fcntl(fd, F_GETLK, &lock);
700 lock.l_type = F_WRLCK;
701 t_fcntl(fd, F_SETLKW, &lock);
702 t_fcntl(fd, F_GETLK, &lock);
703 lock.l_type = F_UNLCK;
704 t_fcntl(fd, F_SETLK, &lock);
713 char file[MAX_PATH_LENGTH] = "";
715 char *str = "1234567890";
718 ENTRY("make sure O_APPEND take effect");
719 snprintf(file, MAX_PATH_LENGTH, "%s/test_t22_file", lustre_path);
721 fd = open(file, O_RDWR|O_CREAT|O_APPEND, (mode_t)0666);
723 printf("error open file: %s\n", strerror(errno));
727 lseek(fd, 100, SEEK_SET);
728 ret = write(fd, str, strlen(str));
729 if (ret != strlen(str)) {
730 printf("write 1: ret %ld, errno %d\n", ret, errno);
734 lseek(fd, 0, SEEK_SET);
735 ret = read(fd, buf, sizeof(buf));
736 if (ret != strlen(str)) {
737 printf("read 1 got %ld\n", ret);
741 if (memcmp(buf, str, strlen(str))) {
742 printf("read 1 data err\n");
746 if (fcntl(fd, F_SETFL, 0)) {
747 printf("fcntl err: %s\n", strerror(errno));
751 lseek(fd, 100, SEEK_SET);
752 ret = write(fd, str, strlen(str));
753 if (ret != strlen(str)) {
754 printf("write 2: ret %ld, errno %d\n", ret, errno);
758 lseek(fd, 100, SEEK_SET);
759 ret = read(fd, buf, sizeof(buf));
760 if (ret != strlen(str)) {
761 printf("read 2 got %ld\n", ret);
765 if (memcmp(buf, str, strlen(str))) {
766 printf("read 2 data err\n");
777 char path[MAX_PATH_LENGTH];
782 ENTRY("handle seek > 2GB");
783 snprintf(path, MAX_PATH_LENGTH, "%s/f%s", lustre_path, name);
785 fd = open(path, O_WRONLY | O_CREAT | O_LARGEFILE, 0666);
787 printf("failed to create file %s: %s\n", path, strerror(errno));
791 off = 2048ULL * 1024 * 1024 - buf_size / 2;
792 ret = lseek(fd, off, SEEK_SET);
794 printf("seek error for initial %llu != %llu\n",
795 ret, (long long)off);
799 ret = write(fd, buf_alloc, buf_size);
800 if (ret != buf_size) {
801 printf("write error for %d != %llubytes @ %llu\n",
802 buf_size, ret, (long long)off);
808 ret = lseek(fd, off, SEEK_SET);
810 printf("seek < 2GB error for %llu != %llu\n",
811 ret, (long long)off);
813 perror("seek < 2GB");
817 ret = lseek(fd, off + buf_size - 2, SEEK_SET);
818 if (ret != off + buf_size - 2) {
819 printf("seek > 2GB error for %llu != %llu\n",
820 ret, (long long)off);
822 perror("seek > 2GB");
826 ret = lseek(fd, -buf_size + 2, SEEK_CUR);
828 printf("relative seek error for %d %llu != %llu\n",
829 -buf_size + 2, ret, off);
831 perror("relative seek");
835 ret = lseek(fd, 0, SEEK_END);
836 if (ret != off + buf_size) {
837 printf("end seek error for %llu != %llu\n",
838 ret, (long long)off + buf_size);
844 ret = lseek(fd, 0, SEEK_SET);
846 printf("seek 0 error for %llu != 0\n", ret);
852 off = 2048ULL * 1024 * 1024, SEEK_SET;
853 ret = lseek(fd, off, SEEK_SET);
855 printf("seek 2GB error for %llu != %llu\n", ret, off);
866 /* pos: i/o start from
867 * xfer: npages per transfer
869 static int pages_io(int xfer, loff_t pos)
871 char path[MAX_PATH_LENGTH] = "";
873 int check_sum[_npages] = {0,}, *buf;
874 int fd, rc, i, j, data_error = 0;
875 struct timeval tw1, tw2, tr1, tr2;
879 snprintf(path, MAX_PATH_LENGTH, "%s/test_t50", lustre_path);
881 memset(buf_alloc, 0, buf_size);
883 /* create sample data */
884 for (i = 0, buf = buf_alloc; i < _npages; i++) {
885 for (j = 0; j < PAGE_SIZE/sizeof(int); j++, buf++) {
890 /* compute checksum */
891 for (i = 0, buf = buf_alloc; i < _npages; i++) {
892 for (j = 0; j < PAGE_SIZE/sizeof(int); j++, buf++) {
893 check_sum[i] += *buf;
903 ret = lseek(fd, pos, SEEK_SET);
905 perror("write seek");
908 gettimeofday(&tw1, NULL);
909 for (i = 0, buf = buf_alloc; i < _npages;
910 i += xfer, buf += xfer * PAGE_SIZE / sizeof(int)) {
911 rc = write(fd, buf, PAGE_SIZE * xfer);
912 if (rc != PAGE_SIZE * xfer) {
913 printf("write error (i %d, rc %d): %s\n", i, rc,
918 gettimeofday(&tw2, NULL);
920 memset(buf_alloc, 0, buf_size);
923 ret = lseek(fd, pos, SEEK_SET);
928 gettimeofday(&tr1, NULL);
929 for (i = 0, buf = buf_alloc; i < _npages;
930 i += xfer, buf += xfer * PAGE_SIZE / sizeof(int)) {
931 rc = read(fd, buf, PAGE_SIZE * xfer);
932 if (rc != PAGE_SIZE * xfer) {
933 printf("read error (i %d, rc %d): %s\n", i, rc,
938 gettimeofday(&tr2, NULL);
940 /* compute checksum */
941 for (i = 0, buf = buf_alloc; i < _npages; i++) {
943 for (j = 0; j < PAGE_SIZE/sizeof(int); j++, buf++) {
946 if (sum != check_sum[i]) {
948 printf("chunk %d checksum error expected %#x got %#x\n",
949 i, check_sum[i], sum);
955 tw = (tw2.tv_sec - tw1.tv_sec) * 1000000 + (tw2.tv_usec - tw1.tv_usec);
956 tr = (tr2.tv_sec - tr1.tv_sec) * 1000000 + (tr2.tv_usec - tr1.tv_usec);
957 printf(" (R:%.3fM/s, W:%.3fM/s)\n",
958 (_npages * PAGE_SIZE) / (tw / 1000000.0) / (1024 * 1024),
959 (_npages * PAGE_SIZE) / (tr / 1000000.0) / (1024 * 1024));
972 ENTRY("4k aligned i/o sanity");
973 while (np <= _npages) {
974 printf("%3d per xfer(total %d)...\t", np, _npages);
976 if (pages_io(np, offset) != 0)
985 loff_t off_array[] = {1, 17, 255, 258, 4095, 4097, 8191,
986 1024*1024*1024*1024ULL};
990 ENTRY("4k un-aligned i/o sanity");
991 for (i = 0; i < sizeof(off_array)/sizeof(loff_t); i++) {
992 offset = off_array[i];
993 printf("16 per xfer(total %d), offset %10lld...\t",
995 if (pages_io(16, offset) != 0)
1008 * truncate(2) checks.
1012 char file[MAX_PATH_LENGTH] = "";
1017 ENTRY("truncate() should truncate file to proper length");
1018 snprintf(file, MAX_PATH_LENGTH, "%s/test_t51_file", lustre_path);
1020 for (size = 0; size < T51_NR * T51_STEP; size += T51_STEP) {
1021 t_echo_create(file, "");
1022 if (truncate(file, size) != 0) {
1023 printf("\nerror truncating file: %s\n",strerror(errno));
1026 result = check_file_size(file, size);
1031 t_echo_create(file, "");
1032 fd = open(file, O_RDWR|O_CREAT, (mode_t)0666);
1034 printf("\nerror open file: %s\n", strerror(errno));
1037 if (ftruncate(fd, size) != 0) {
1038 printf("\nerror ftruncating file:%s\n",strerror(errno));
1042 result = check_file_size(file, size);
1046 if (size % (T51_STEP * (T51_NR / 75)) == 0) {
1055 * check atime update during read
1059 char file[MAX_PATH_LENGTH] = "";
1061 struct stat statbuf;
1066 ENTRY("atime should be updated during read");
1067 snprintf(file, MAX_PATH_LENGTH, "%s/test_t52_file", lustre_path);
1069 t_echo_create(file, "check atime update during read");
1070 fd = open(file, O_RDONLY);
1072 printf("\nerror open file: %s\n", strerror(errno));
1075 stat(file, &statbuf);
1076 printf("st_atime=%s", ctime(&statbuf.st_atime));
1077 atime = statbuf.st_atime;
1078 for (i = 0; i < 3; i++) {
1080 read(fd, buf, sizeof(buf));
1081 stat(file, &statbuf);
1082 printf("st_atime=%s", ctime(&statbuf.st_atime));
1083 diff = statbuf.st_atime - atime;
1085 printf("atime doesn't updated! failed!\n");
1090 atime = statbuf.st_atime;
1097 #define NEW_TIME 10000
1100 char file[MAX_PATH_LENGTH] = "";
1101 struct utimbuf times; /* struct. buffer for utime() */
1102 struct stat stat_buf; /* struct buffer to hold file info. */
1103 time_t mtime, atime;
1105 ENTRY("mtime/atime should be updated by utime() call");
1106 snprintf(file, MAX_PATH_LENGTH, "%s/test_t53_file", lustre_path);
1108 t_echo_create(file, "check mtime/atime update by utime() call");
1110 /* Initialize the modification and access time in the times arg */
1111 times.actime = NEW_TIME+10;
1112 times.modtime = NEW_TIME;
1114 /* file modification/access time */
1115 utime(file, ×);
1117 if (stat(file, &stat_buf) < 0) {
1118 printf("stat(2) of %s failed, error:%d %s\n",
1119 file, errno, strerror(errno));
1121 mtime = stat_buf.st_mtime;
1122 atime = stat_buf.st_atime;
1124 if ((mtime == NEW_TIME) && (atime == NEW_TIME + 10)) {
1129 printf("mod time %ld, expected %ld\n", mtime, (long)NEW_TIME);
1130 printf("acc time %ld, expected %ld\n", atime, (long)NEW_TIME + 10);
1138 char file[MAX_PATH_LENGTH] = "";
1142 ENTRY("fcntl should return 0 when succeed in getting flock");
1143 snprintf(file, MAX_PATH_LENGTH, "%s/test_t54_file", lustre_path);
1145 t_echo_create(file, "fcntl should return 0 when succeed");
1147 fd = open(file, O_RDWR);
1149 printf("\nerror open file: %s\n", strerror(errno));
1152 lock.l_type = F_WRLCK;
1156 if ((err = t_fcntl(fd, F_SETLKW, &lock)) != 0) {
1157 fprintf(stderr, "fcntl returned: %d (%s)\n",
1158 err, strerror(err));
1164 lock.l_type = F_UNLCK;
1165 t_fcntl(fd, F_SETLKW, &lock);
1171 /* for O_DIRECTORY */
1174 #define STRIPE_SIZE (2048 * 2048)
1175 #define STRIPE_OFFSET 0
1176 #define STRIPE_COUNT 1
1179 char path[MAX_PATH_LENGTH] = "";
1180 char file[MAX_PATH_LENGTH] = "";
1181 struct lov_user_md *lum = NULL;
1182 struct lov_user_ost_data *lo = NULL;
1183 int index, fd, buflen, rc;
1185 ENTRY("setstripe/getstripe");
1186 snprintf(path, MAX_PATH_LENGTH, "%s/test_t55", lustre_path);
1187 snprintf(file, MAX_PATH_LENGTH, "%s/test_t55/file_t55", lustre_path);
1189 buflen = sizeof(struct lov_user_md);
1190 buflen += STRIPE_COUNT * sizeof(struct lov_user_ost_data);
1191 lum = (struct lov_user_md *)malloc(buflen);
1193 printf("out of memory!\n");
1196 memset(lum, 0, buflen);
1199 rc = llapi_file_create(path, STRIPE_SIZE, STRIPE_OFFSET,
1200 STRIPE_COUNT, LOV_PATTERN_RAID0);
1202 printf("llapi_file_create failed: rc = %d (%s) \n",
1209 fd = open(file, O_CREAT | O_RDWR, 0644);
1211 printf("open file(%s) failed: rc = %d (%s) \n)",
1212 file, fd, strerror(errno));
1218 lum->lmm_magic = LOV_USER_MAGIC;
1219 lum->lmm_stripe_count = STRIPE_COUNT;
1220 rc = ioctl(fd, LL_IOC_LOV_GETSTRIPE, lum);
1222 printf("dir:ioctl(LL_IOC_LOV_GETSTRIPE) failed: rc = %d(%s)\n",
1223 rc, strerror(errno));
1234 printf("lmm_magic: 0x%08X\n", lum->lmm_magic);
1235 printf("lmm_object_id: "LPX64"\n", lum->lmm_object_id);
1236 printf("lmm_object_gr: "LPX64"\n", lum->lmm_object_gr);
1237 printf("lmm_stripe_count: %u\n", (int)lum->lmm_stripe_count);
1238 printf("lmm_stripe_size: %u\n", lum->lmm_stripe_size);
1239 printf("lmm_stripe_pattern: %x\n", lum->lmm_pattern);
1241 for (index = 0; index < lum->lmm_stripe_count; index++) {
1242 lo = lum->lmm_objects + index;
1243 printf("object %d:\n", index);
1244 printf("\tobject_gr: "LPX64"\n", lo->l_object_gr);
1245 printf("\tobject_id: "LPX64"\n", lo->l_object_id);
1246 printf("\tost_gen: "LPX64"\n", lo->l_ost_gen);
1247 printf("\tost_idx: %u\n", lo->l_ost_idx);
1251 if (lum->lmm_magic != LOV_USER_MAGIC ||
1252 lum->lmm_pattern != LOV_PATTERN_RAID0 ||
1253 lum->lmm_stripe_size != STRIPE_SIZE ||
1254 lum->lmm_objects[0].l_ost_idx != STRIPE_OFFSET ||
1255 lum->lmm_stripe_count != STRIPE_COUNT) {
1256 printf("incorrect striping information!\n");
1264 /* setstripe on regular file */
1265 rc = llapi_file_create(file, STRIPE_SIZE, STRIPE_OFFSET,
1266 STRIPE_COUNT, LOV_PATTERN_RAID0);
1268 printf("llapi_file_create failed: rc = %d (%s) \n",
1275 fd = open(file, O_RDWR, 0644);
1277 printf("failed to open(%s): rc = %d (%s)\n",
1278 file, fd, strerror(errno));
1285 lum->lmm_magic = LOV_USER_MAGIC;
1286 lum->lmm_stripe_count = STRIPE_COUNT;
1287 rc = ioctl(fd, LL_IOC_LOV_GETSTRIPE, lum);
1289 printf("file:ioctl(LL_IOC_LOV_GETSTRIPE) failed: rc = %d(%s)\n",
1290 rc, strerror(errno));
1300 printf("lmm_magic: 0x%08X\n", lum->lmm_magic);
1301 printf("lmm_object_id: "LPX64"\n", lum->lmm_object_id);
1302 printf("lmm_object_gr: "LPX64"\n", lum->lmm_object_gr);
1303 printf("lmm_stripe_count: %u\n", (int)lum->lmm_stripe_count);
1304 printf("lmm_stripe_size: %u\n", lum->lmm_stripe_size);
1305 printf("lmm_stripe_pattern: %x\n", lum->lmm_pattern);
1307 for (index = 0; index < lum->lmm_stripe_count; index++) {
1308 lo = lum->lmm_objects + index;
1309 printf("object %d:\n", index);
1310 printf("\tobject_gr: "LPX64"\n", lo->l_object_gr);
1311 printf("\tobject_id: "LPX64"\n", lo->l_object_id);
1312 printf("\tost_gen: "LPX64"\n", lo->l_ost_gen);
1313 printf("\tost_idx: %u\n", lo->l_ost_idx);
1317 if (lum->lmm_magic != LOV_USER_MAGIC ||
1318 lum->lmm_pattern != LOV_PATTERN_RAID0 ||
1319 lum->lmm_stripe_size != STRIPE_SIZE ||
1320 lum->lmm_objects[0].l_ost_idx != STRIPE_OFFSET ||
1321 lum->lmm_stripe_count != STRIPE_COUNT) {
1322 printf("incorrect striping information!\n");
1335 extern void __liblustre_setup_(void);
1336 extern void __liblustre_cleanup_(void);
1339 void usage(char *cmd)
1342 "usage: %s [--only {test}] --target mgsnid:/fsname\n",
1344 printf(" %s --dumpfile dumpfile\n", cmd);
1349 int (*test)(char *name);
1385 int main(int argc, char * const argv[])
1387 struct testlist *test;
1388 int opt_index, c, rc = 0, numonly = 0;
1390 static struct option long_opts[] = {
1391 {"dumpfile", 1, 0, 'd'},
1392 {"only", 1, 0, 'o'},
1393 {"target", 1, 0, 't'},
1394 {"verbose", 1, 0, 'v'},
1398 while ((c = getopt_long(argc, argv, "d:o:t:v", long_opts, &opt_index)) != -1) {
1401 setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);
1405 printf("Only running test(s): ");
1406 printf("%s ", optarg);
1407 only[numonly++] = optarg;
1410 setenv(ENV_LUSTRE_MNTTGT, optarg, 1);
1421 if (getenv(ENV_LUSTRE_MNTTGT) == NULL &&
1422 getenv(ENV_LUSTRE_DUMPFILE) == NULL)
1430 __liblustre_setup_();
1432 buf_size = _npages * PAGE_SIZE;
1434 printf("allocating %d bytes buffer\n", buf_size);
1435 buf_alloc = calloc(1, buf_size);
1436 if (buf_alloc == NULL) {
1437 fprintf(stderr, "error allocating %d\n", buf_size);
1441 for (test = testlist; test->test != NULL; test++) {
1448 len = strlen(test->name);
1449 for (i = 0; i < numonly; i++) {
1450 int olen = strlen(only[i]);
1455 if (strncmp(only[i], test->name, olen) == 0) {
1456 switch(test->name[olen]) {
1457 case '0': case '1': case '2': case '3':
1458 case '4': case '5': case '6': case '7':
1468 if (run && (rc = (test->test)(test->name)) != 0)
1474 printf("liblustre is about to shutdown\n");
1475 __liblustre_cleanup_();
1477 printf("complete successfully\n");