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 snprintf(path, MAX_PATH_LENGTH, "%s/test_t1", lustre_path);
100 printf("touch+unlink %s\n", path);
109 char path[MAX_PATH_LENGTH] = "";
111 ENTER("mkdir/rmdir");
112 snprintf(path, MAX_PATH_LENGTH, "%s/test_t2", lustre_path);
121 char path[MAX_PATH_LENGTH] = "";
123 ENTER("regular stat");
124 snprintf(path, MAX_PATH_LENGTH, "%s/test_t3", lustre_path);
127 t_check_stat(path, NULL);
134 char path[MAX_PATH_LENGTH] = "";
137 snprintf(path, MAX_PATH_LENGTH, "%s/test_t4", lustre_path);
140 t_check_stat(path, NULL);
147 char path[MAX_PATH_LENGTH] = "";
148 char path2[MAX_PATH_LENGTH] = "";
151 snprintf(path, MAX_PATH_LENGTH, "%s/test_t6", lustre_path);
152 snprintf(path2, MAX_PATH_LENGTH, "%s/test_t6_link", lustre_path);
155 t_symlink(path, path2);
156 t_check_stat(path2, NULL);
164 char path[MAX_PATH_LENGTH] = "";
165 char path2[MAX_PATH_LENGTH] = "";
166 char cwd[MAX_PATH_LENGTH] = "";
170 ENTER("symlink + chdir and open");
171 snprintf(path, MAX_PATH_LENGTH, "%s/test_t6b", lustre_path);
172 snprintf(path2, MAX_PATH_LENGTH, "%s/test_t6b_link", lustre_path);
175 t_symlink(path, path2);
176 t_check_stat(path2, NULL);
178 tmp = getcwd(cwd, MAX_PATH_LENGTH);
180 fprintf(stderr, "current path too long to fit in "
181 "MAX_PATH_LENGTH?\n");
199 char path[MAX_PATH_LENGTH] = "";
203 snprintf(path, MAX_PATH_LENGTH, "%s/test_t7", lustre_path);
205 if (geteuid() != 0) {
206 rc = mknod(path, S_IFCHR | 0644, (5<<8 | 4));
207 if (rc != -1 || errno != EPERM) {
208 printf("mknod shouldn't success: rc %d, errno %d\n",
212 t_mknod(path, S_IFCHR | 0644, 5, 4);
213 t_check_stat(path, NULL);
221 char path[MAX_PATH_LENGTH] = "";
224 snprintf(path, MAX_PATH_LENGTH, "%s/test_t8", lustre_path);
228 t_chmod_raw(path, 0700);
229 t_check_stat(path, NULL);
234 t_chmod_raw(path, 0700);
235 t_check_stat(path, NULL);
243 char path[MAX_PATH_LENGTH] = "";
244 char path2[MAX_PATH_LENGTH] = "";
247 snprintf(path, MAX_PATH_LENGTH, "%s/test_t9", lustre_path);
248 snprintf(path2, MAX_PATH_LENGTH, "%s/test_t9_link", lustre_path);
252 t_check_stat(path, NULL);
253 t_check_stat(path2, NULL);
261 char dir1[MAX_PATH_LENGTH] = "";
262 char dir2[MAX_PATH_LENGTH] = "";
263 char path1[MAX_PATH_LENGTH] = "";
264 char path2[MAX_PATH_LENGTH] = "";
265 char rename1[MAX_PATH_LENGTH] = "";
266 char rename2[MAX_PATH_LENGTH] = "";
267 char rename3[MAX_PATH_LENGTH] = "";
270 snprintf(dir1, MAX_PATH_LENGTH, "%s/test_t10_dir1", lustre_path);
271 snprintf(dir2, MAX_PATH_LENGTH, "%s/test_t10_dir2", lustre_path);
272 snprintf(path1, MAX_PATH_LENGTH, "%s/test_t10_reg1", lustre_path);
273 snprintf(path2, MAX_PATH_LENGTH, "%s/test_t10_reg2", lustre_path);
274 snprintf(rename1, MAX_PATH_LENGTH, "%s/test_t10_dir1/rename1", lustre_path);
275 snprintf(rename2, MAX_PATH_LENGTH, "%s/test_t10_dir2/rename2", lustre_path);
276 snprintf(rename3, MAX_PATH_LENGTH, "%s/test_t10_dir2/rename3", lustre_path);
282 t_rename(path1, rename1);
283 t_rename(path2, rename2);
284 t_rename(rename1, rename2);
285 t_rename(dir1, rename3);
294 char *base=lustre_path;
295 char path[MAX_PATH_LENGTH], path2[MAX_PATH_LENGTH];
296 int i, j, level = 5, nreg = 5;
299 safe_strncpy(path, base, MAX_PATH_LENGTH);
301 for (i = 0; i < level; i++) {
302 for (j = 0; j < nreg; j++) {
303 sprintf(path2, "%s/file%d", path, j);
307 strcat(path, "/dir");
311 for (i = level; i > 0; i--) {
312 safe_strncpy(path, base, MAX_PATH_LENGTH);
313 for (j = 1; j < i; j++)
314 strcat(path, "/dir");
316 for (j = 0; j < nreg; j++) {
317 sprintf(path2, "%s/file%d", path, j);
321 strcat(path, "/dir");
330 char dir[MAX_PATH_LENGTH] = "";
333 ENTER("empty directory readdir");
334 snprintf(dir, MAX_PATH_LENGTH, "%s/test_t12_dir", lustre_path);
338 t_ls(fd, buf, sizeof(buf));
346 char dir[MAX_PATH_LENGTH] = "";
349 const int nfiles = 20;
350 char *prefix = "test13_filename_prefix_";
352 ENTER("multiple entries directory readdir");
353 snprintf(dir, MAX_PATH_LENGTH, "%s/test_t13_dir/", lustre_path);
356 printf("Creating %d files...\n", nfiles);
357 for (i = 0; i < nfiles; i++) {
358 sprintf(path, "%s%s%05d", dir, prefix, i);
362 t_ls(fd, buf, sizeof(buf));
364 printf("Cleanup...\n");
365 for (i = 0; i < nfiles; i++) {
366 sprintf(path, "%s%s%05d", dir, prefix, i);
375 char dir[MAX_PATH_LENGTH] = "";
378 const int nfiles = 256;
379 char *prefix = "test14_filename_long_prefix_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA___";
381 int fd, i, rc, pos, index;
383 ENTER(">1 block(4k) directory readdir");
384 snprintf(dir, MAX_PATH_LENGTH, "%s/test_t14_dir/", lustre_path);
386 rc = mkdir(dir, 0755);
387 if (rc < 0 && errno != EEXIST) {
388 printf("mkdir(%s) error: %s\n", dir, strerror(errno));
391 printf("Creating %d files...\n", nfiles);
392 for (i = 0; i < nfiles; i++) {
393 sprintf(path, "%s%s%05d", dir, prefix, i);
397 printf("Listing...\n");
399 while ((rc = getdirentries64(fd, buf, 1024, &base)) > 0) {
404 ent = (void *) buf + pos;
405 item = (char *) ent->d_name;
406 if (!strcmp(item, ".") || !strcmp(item, ".."))
408 if (strstr(item, prefix) != item) {
409 printf("found bad name %s\n", item);
412 printf("[%03d]: %s\n",
413 index++, item + strlen(prefix));
415 pos += ent->d_reclen;
419 printf("getdents error %d\n", rc);
422 if (index != nfiles) {
423 printf("get %d files != %d\n", index, nfiles);
427 printf("Cleanup...\n");
428 for (i = 0; i < nfiles; i++) {
429 sprintf(path, "%s%s%05d", dir, prefix, i);
438 char file[MAX_PATH_LENGTH] = "";
440 ENTER("open-stat-close");
441 snprintf(file, MAX_PATH_LENGTH, "%s/test_t15_file", lustre_path);
445 t_check_stat(file, NULL);
453 char file[MAX_PATH_LENGTH] = "";
454 ENTER("small-write-read");
455 snprintf(file, MAX_PATH_LENGTH, "%s/test_t16_file", lustre_path);
457 t_echo_create(file, "aaaaaaaaaaaaaaaaaaaaaa");
458 t_grep(file, "aaaaaaaaaaaaaaaaaaaaaa");
465 char file[MAX_PATH_LENGTH] = "";
467 ENTER("open-unlink without close");
468 snprintf(file, MAX_PATH_LENGTH, "%s/test_t17_file", lustre_path);
470 fd = open(file, O_WRONLY | O_CREAT, 0666);
472 printf("failed to create file: %s\n", strerror(errno));
481 char file[MAX_PATH_LENGTH] = "";
484 struct stat statbuf[3];
485 ENTER("write should change mtime/ctime");
486 snprintf(file, MAX_PATH_LENGTH, "%s/test_t18_file", lustre_path);
488 for (i = 0; i < 3; i++) {
489 fd = open(file, O_RDWR|O_CREAT|O_APPEND, (mode_t)0666);
491 printf("error open file: %s\n", strerror(errno));
494 if (write(fd, buf, sizeof(buf)) != sizeof(buf)) {
495 printf("error write file\n");
499 if(stat(file, &statbuf[i]) != 0) {
500 printf("Error stat\n");
503 printf("ctime %lu, mtime %lu\n",
504 statbuf[i].st_ctime, statbuf[i].st_mtime);
508 for (i = 1; i < 3; i++) {
509 if ((statbuf[i].st_ctime <= statbuf[i-1].st_ctime) ||
510 (statbuf[i].st_mtime <= statbuf[i-1].st_mtime)) {
511 printf("time error\n");
521 char file[MAX_PATH_LENGTH] = "";
523 struct stat statbuf[3];
524 ENTER("utime should change mtime/atime/ctime");
525 snprintf(file, MAX_PATH_LENGTH, "%s/test_t18b_file", lustre_path);
528 for (i = 0; i < 3; i++) {
530 if(stat(file, &statbuf[i]) != 0) {
531 printf("Error stat\n");
534 printf("atime %lu, mtime %lu, ctime %lu\n",
535 statbuf[i].st_atime, statbuf[i].st_mtime,
536 statbuf[i].st_ctime);
540 for (i = 1; i < 3; i++) {
541 if ((statbuf[i].st_atime <= statbuf[i-1].st_atime) ||
542 (statbuf[i].st_mtime <= statbuf[i-1].st_mtime) ||
543 (statbuf[i].st_ctime <= statbuf[i-1].st_ctime)) {
544 printf("time error\n");
552 static int check_file_size(char *file, long long size)
556 if (stat(file, &statbuf) != 0) {
557 printf("Error stat(%s)\n", file);
560 if (statbuf.st_size != size) {
561 printf("size of %s: %ld != %lld\n", file, statbuf.st_size, size);
569 char file[MAX_PATH_LENGTH] = "";
572 ENTER("open(O_TRUNC) should truncate file to 0-length");
573 snprintf(file, MAX_PATH_LENGTH, "%s/test_t19_file", lustre_path);
575 t_echo_create(file, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
577 fd = open(file, O_RDWR|O_CREAT|O_TRUNC, (mode_t)0666);
579 printf("error open file: %s\n", strerror(errno));
583 result = check_file_size(file, 0);
592 char file[MAX_PATH_LENGTH] = "";
597 ENTER("trap app's general bad pointer for file i/o");
598 snprintf(file, MAX_PATH_LENGTH, "%s/test_t20_file", lustre_path);
600 fd = open(file, O_RDWR|O_CREAT, (mode_t)0666);
602 printf("error open file: %s\n", strerror(errno));
606 ret = write(fd, NULL, 20);
607 if (ret != -1 || errno != EFAULT) {
608 printf("write 1: ret %ld, errno %d\n", ret, errno);
611 ret = write(fd, (void *)-1, 20);
612 if (ret != -1 || errno != EFAULT) {
613 printf("write 2: ret %ld, errno %d\n", ret, errno);
616 iov[0].iov_base = NULL;
618 iov[1].iov_base = (void *)-1;
620 ret = writev(fd, iov, 2);
621 if (ret != -1 || errno != EFAULT) {
622 printf("writev 1: ret %ld, errno %d\n", ret, errno);
625 iov[0].iov_base = NULL;
627 iov[1].iov_base = buf;
628 iov[1].iov_len = sizeof(buf);
629 ret = writev(fd, iov, 2);
630 if (ret != sizeof(buf)) {
631 printf("write 3 ret %ld, error %d\n", ret, errno);
634 lseek(fd, 0, SEEK_SET);
636 ret = read(fd, NULL, 20);
637 if (ret != -1 || errno != EFAULT) {
638 printf("read 1: ret %ld, errno %d\n", ret, errno);
641 ret = read(fd, (void *)-1, 20);
642 if (ret != -1 || errno != EFAULT) {
643 printf("read 2: ret %ld, errno %d\n", ret, errno);
646 iov[0].iov_base = NULL;
648 iov[1].iov_base = (void *)-1;
650 ret = readv(fd, iov, 2);
651 if (ret != -1 || errno != EFAULT) {
652 printf("readv 1: ret %ld, errno %d\n", ret, errno);
655 iov[0].iov_base = NULL;
657 iov[1].iov_base = buf;
658 iov[1].iov_len = sizeof(buf);
659 ret = readv(fd, iov, 2);
660 if (ret != sizeof(buf)) {
661 printf("read 3 ret %ld, error %d\n", ret, errno);
672 char file[MAX_PATH_LENGTH] = "";
674 struct flock lock = {
676 .l_whence = SEEK_SET,
679 ENTER("basic fcntl support");
680 snprintf(file, MAX_PATH_LENGTH, "%s/test_t21_file", lustre_path);
682 fd = open(file, O_RDWR|O_CREAT, (mode_t)0666);
684 printf("error open file: %s\n", file);
688 t_fcntl(fd, F_SETFL, O_APPEND);
689 if (!(ret = t_fcntl(fd, F_GETFL)) & O_APPEND) {
690 printf("error get flag: ret %x\n", ret);
694 t_fcntl(fd, F_SETLK, &lock);
695 t_fcntl(fd, F_GETLK, &lock);
696 lock.l_type = F_WRLCK;
697 t_fcntl(fd, F_SETLKW, &lock);
698 t_fcntl(fd, F_GETLK, &lock);
699 lock.l_type = F_UNLCK;
700 t_fcntl(fd, F_SETLK, &lock);
709 char file[MAX_PATH_LENGTH] = "";
711 char *str = "1234567890";
714 ENTER("make sure O_APPEND take effect");
715 snprintf(file, MAX_PATH_LENGTH, "%s/test_t22_file", lustre_path);
717 fd = open(file, O_RDWR|O_CREAT|O_APPEND, (mode_t)0666);
719 printf("error open file: %s\n", strerror(errno));
723 lseek(fd, 100, SEEK_SET);
724 ret = write(fd, str, strlen(str));
725 if (ret != strlen(str)) {
726 printf("write 1: ret %ld, errno %d\n", ret, errno);
730 lseek(fd, 0, SEEK_SET);
731 ret = read(fd, buf, sizeof(buf));
732 if (ret != strlen(str)) {
733 printf("read 1 got %ld\n", ret);
737 if (memcmp(buf, str, strlen(str))) {
738 printf("read 1 data err\n");
742 if (fcntl(fd, F_SETFL, 0)) {
743 printf("fcntl err: %s\n", strerror(errno));
747 lseek(fd, 100, SEEK_SET);
748 ret = write(fd, str, strlen(str));
749 if (ret != strlen(str)) {
750 printf("write 2: ret %ld, errno %d\n", ret, errno);
754 lseek(fd, 100, SEEK_SET);
755 ret = read(fd, buf, sizeof(buf));
756 if (ret != strlen(str)) {
757 printf("read 2 got %ld\n", ret);
761 if (memcmp(buf, str, strlen(str))) {
762 printf("read 2 data err\n");
773 char path[MAX_PATH_LENGTH];
778 ENTER("handle seek > 2GB");
779 snprintf(path, MAX_PATH_LENGTH, "%s/f%s", lustre_path, name);
781 fd = open(path, O_WRONLY | O_CREAT | O_LARGEFILE, 0666);
783 printf("failed to create file %s: %s\n", path, strerror(errno));
787 off = 2048ULL * 1024 * 1024 - buf_size / 2;
788 ret = lseek(fd, off, SEEK_SET);
790 printf("seek error for initial %llu != %llu\n",
791 ret, (long long)off);
795 ret = write(fd, buf_alloc, buf_size);
796 if (ret != buf_size) {
797 printf("write error for %d != %llubytes @ %llu\n",
798 buf_size, ret, (long long)off);
804 ret = lseek(fd, off, SEEK_SET);
806 printf("seek < 2GB error for %llu != %llu\n",
807 ret, (long long)off);
809 perror("seek < 2GB");
813 ret = lseek(fd, off + buf_size - 2, SEEK_SET);
814 if (ret != off + buf_size - 2) {
815 printf("seek > 2GB error for %llu != %llu\n",
816 ret, (long long)off);
818 perror("seek > 2GB");
822 ret = lseek(fd, -buf_size + 2, SEEK_CUR);
824 printf("relative seek error for %d %llu != %llu\n",
825 -buf_size + 2, ret, off);
827 perror("relative seek");
831 ret = lseek(fd, 0, SEEK_END);
832 if (ret != off + buf_size) {
833 printf("end seek error for %llu != %llu\n",
834 ret, (long long)off + buf_size);
840 ret = lseek(fd, 0, SEEK_SET);
842 printf("seek 0 error for %llu != 0\n", ret);
848 off = 2048ULL * 1024 * 1024, SEEK_SET;
849 ret = lseek(fd, off, SEEK_SET);
851 printf("seek 2GB error for %llu != %llu\n", ret, off);
862 /* pos: i/o start from
863 * xfer: npages per transfer
865 static int pages_io(int xfer, loff_t pos)
867 char path[MAX_PATH_LENGTH] = "";
869 int check_sum[_npages] = {0,}, *buf;
870 int fd, rc, i, j, data_error = 0;
871 struct timeval tw1, tw2, tr1, tr2;
875 snprintf(path, MAX_PATH_LENGTH, "%s/test_t50", lustre_path);
877 memset(buf_alloc, 0, buf_size);
879 /* create sample data */
880 for (i = 0, buf = buf_alloc; i < _npages; i++) {
881 for (j = 0; j < PAGE_SIZE/sizeof(int); j++, buf++) {
886 /* compute checksum */
887 for (i = 0, buf = buf_alloc; i < _npages; i++) {
888 for (j = 0; j < PAGE_SIZE/sizeof(int); j++, buf++) {
889 check_sum[i] += *buf;
899 ret = lseek(fd, pos, SEEK_SET);
901 perror("write seek");
904 gettimeofday(&tw1, NULL);
905 for (i = 0, buf = buf_alloc; i < _npages;
906 i += xfer, buf += xfer * PAGE_SIZE / sizeof(int)) {
907 rc = write(fd, buf, PAGE_SIZE * xfer);
908 if (rc != PAGE_SIZE * xfer) {
909 printf("write error (i %d, rc %d): %s\n", i, rc,
914 gettimeofday(&tw2, NULL);
916 memset(buf_alloc, 0, buf_size);
919 ret = lseek(fd, pos, SEEK_SET);
924 gettimeofday(&tr1, NULL);
925 for (i = 0, buf = buf_alloc; i < _npages;
926 i += xfer, buf += xfer * PAGE_SIZE / sizeof(int)) {
927 rc = read(fd, buf, PAGE_SIZE * xfer);
928 if (rc != PAGE_SIZE * xfer) {
929 printf("read error (i %d, rc %d): %s\n", i, rc,
934 gettimeofday(&tr2, NULL);
936 /* compute checksum */
937 for (i = 0, buf = buf_alloc; i < _npages; i++) {
939 for (j = 0; j < PAGE_SIZE/sizeof(int); j++, buf++) {
942 if (sum != check_sum[i]) {
944 printf("chunk %d checksum error expected %#x got %#x\n",
945 i, check_sum[i], sum);
951 tw = (tw2.tv_sec - tw1.tv_sec) * 1000000 + (tw2.tv_usec - tw1.tv_usec);
952 tr = (tr2.tv_sec - tr1.tv_sec) * 1000000 + (tr2.tv_usec - tr1.tv_usec);
953 printf(" (R:%.3fM/s, W:%.3fM/s)\n",
954 (_npages * PAGE_SIZE) / (tw / 1000000.0) / (1024 * 1024),
955 (_npages * PAGE_SIZE) / (tr / 1000000.0) / (1024 * 1024));
968 ENTER("4k aligned i/o sanity");
969 while (np <= _npages) {
970 printf("%3d per xfer(total %d)...\t", np, _npages);
972 if (pages_io(np, offset) != 0)
981 loff_t off_array[] = {1, 17, 255, 258, 4095, 4097, 8191,
982 1024*1024*1024*1024ULL};
986 ENTER("4k un-aligned i/o sanity");
987 for (i = 0; i < sizeof(off_array)/sizeof(loff_t); i++) {
988 offset = off_array[i];
989 printf("16 per xfer(total %d), offset %10lld...\t",
991 if (pages_io(16, offset) != 0)
1004 * truncate(2) checks.
1008 char file[MAX_PATH_LENGTH] = "";
1013 ENTER("truncate() should truncate file to proper length");
1014 snprintf(file, MAX_PATH_LENGTH, "%s/test_t51_file", lustre_path);
1016 for (size = 0; size < T51_NR * T51_STEP; size += T51_STEP) {
1017 t_echo_create(file, "");
1018 if (truncate(file, size) != 0) {
1019 printf("\nerror truncating file: %s\n",strerror(errno));
1022 result = check_file_size(file, size);
1027 t_echo_create(file, "");
1028 fd = open(file, O_RDWR|O_CREAT, (mode_t)0666);
1030 printf("\nerror open file: %s\n", strerror(errno));
1033 if (ftruncate(fd, size) != 0) {
1034 printf("\nerror ftruncating file:%s\n",strerror(errno));
1038 result = check_file_size(file, size);
1042 if (size % (T51_STEP * (T51_NR / 75)) == 0) {
1051 * check atime update during read
1055 char file[MAX_PATH_LENGTH] = "";
1057 struct stat statbuf;
1062 ENTER("atime should be updated during read");
1063 snprintf(file, MAX_PATH_LENGTH, "%s/test_t52_file", lustre_path);
1065 t_echo_create(file, "check atime update during read");
1066 fd = open(file, O_RDONLY);
1068 printf("\nerror open file: %s\n", strerror(errno));
1071 stat(file, &statbuf);
1072 printf("st_atime=%s", ctime(&statbuf.st_atime));
1073 atime = statbuf.st_atime;
1074 for (i = 0; i < 3; i++) {
1076 read(fd, buf, sizeof(buf));
1077 stat(file, &statbuf);
1078 printf("st_atime=%s", ctime(&statbuf.st_atime));
1079 diff = statbuf.st_atime - atime;
1081 printf("atime doesn't updated! failed!\n");
1086 atime = statbuf.st_atime;
1093 #define NEW_TIME 10000
1096 char file[MAX_PATH_LENGTH] = "";
1097 struct utimbuf times; /* struct. buffer for utime() */
1098 struct stat stat_buf; /* struct buffer to hold file info. */
1099 time_t mtime, atime;
1101 ENTER("mtime/atime should be updated by utime() call");
1102 snprintf(file, MAX_PATH_LENGTH, "%s/test_t53_file", lustre_path);
1104 t_echo_create(file, "check mtime/atime update by utime() call");
1106 /* Initialize the modification and access time in the times arg */
1107 times.actime = NEW_TIME+10;
1108 times.modtime = NEW_TIME;
1110 /* file modification/access time */
1111 utime(file, ×);
1113 if (stat(file, &stat_buf) < 0) {
1114 printf("stat(2) of %s failed, error:%d %s\n",
1115 file, errno, strerror(errno));
1117 mtime = stat_buf.st_mtime;
1118 atime = stat_buf.st_atime;
1120 if ((mtime == NEW_TIME) && (atime == NEW_TIME + 10)) {
1125 printf("mod time %ld, expected %ld\n", mtime, (long)NEW_TIME);
1126 printf("acc time %ld, expected %ld\n", atime, (long)NEW_TIME + 10);
1134 char file[MAX_PATH_LENGTH] = "";
1138 ENTER("fcntl should return 0 when succeed in getting flock");
1139 snprintf(file, MAX_PATH_LENGTH, "%s/test_t54_file", lustre_path);
1141 t_echo_create(file, "fcntl should return 0 when succeed");
1143 fd = open(file, O_RDWR);
1145 printf("\nerror open file: %s\n", strerror(errno));
1148 lock.l_type = F_WRLCK;
1152 if ((err = t_fcntl(fd, F_SETLKW, &lock)) != 0) {
1153 fprintf(stderr, "fcntl returned: %d (%s)\n",
1154 err, strerror(err));
1160 lock.l_type = F_UNLCK;
1161 t_fcntl(fd, F_SETLKW, &lock);
1167 /* for O_DIRECTORY */
1172 #define STRIPE_SIZE (2048 * 2048)
1173 #define STRIPE_OFFSET 0
1174 #define STRIPE_COUNT 1
1177 char path[MAX_PATH_LENGTH] = "";
1178 char file[MAX_PATH_LENGTH] = "";
1179 struct lov_user_md *lum = NULL;
1180 struct lov_user_ost_data *lo = NULL;
1181 int index, fd, buflen, rc;
1183 ENTER("setstripe/getstripe");
1184 snprintf(path, MAX_PATH_LENGTH, "%s/test_t55", lustre_path);
1185 snprintf(file, MAX_PATH_LENGTH, "%s/test_t55/file_t55", lustre_path);
1187 buflen = sizeof(struct lov_user_md);
1188 buflen += STRIPE_COUNT * sizeof(struct lov_user_ost_data);
1189 lum = (struct lov_user_md *)malloc(buflen);
1191 printf("out of memory!\n");
1194 memset(lum, 0, buflen);
1197 rc = llapi_file_create(path, STRIPE_SIZE, STRIPE_OFFSET,
1198 STRIPE_COUNT, LOV_PATTERN_RAID0);
1200 printf("llapi_file_create failed: rc = %d (%s) \n",
1207 fd = open(file, O_CREAT | O_RDWR, 0644);
1209 printf("open file(%s) failed: rc = %d (%s) \n)",
1210 file, fd, strerror(errno));
1216 lum->lmm_magic = LOV_USER_MAGIC;
1217 lum->lmm_stripe_count = STRIPE_COUNT;
1218 rc = ioctl(fd, LL_IOC_LOV_GETSTRIPE, lum);
1220 printf("dir:ioctl(LL_IOC_LOV_GETSTRIPE) failed: rc = %d(%s)\n",
1221 rc, strerror(errno));
1232 printf("lmm_magic: 0x%08X\n", lum->lmm_magic);
1233 printf("lmm_object_id: "LPX64"\n", lum->lmm_object_id);
1234 printf("lmm_object_gr: "LPX64"\n", lum->lmm_object_gr);
1235 printf("lmm_stripe_count: %u\n", (int)lum->lmm_stripe_count);
1236 printf("lmm_stripe_size: %u\n", lum->lmm_stripe_size);
1237 printf("lmm_stripe_pattern: %x\n", lum->lmm_pattern);
1239 for (index = 0; index < lum->lmm_stripe_count; index++) {
1240 lo = lum->lmm_objects + index;
1241 printf("object %d:\n", index);
1242 printf("\tobject_gr: "LPX64"\n", lo->l_object_gr);
1243 printf("\tobject_id: "LPX64"\n", lo->l_object_id);
1244 printf("\tost_gen: %#x\n", lo->l_ost_gen);
1245 printf("\tost_idx: %u\n", lo->l_ost_idx);
1249 if (lum->lmm_magic != LOV_USER_MAGIC ||
1250 lum->lmm_pattern != LOV_PATTERN_RAID0 ||
1251 lum->lmm_stripe_size != STRIPE_SIZE ||
1252 lum->lmm_objects[0].l_ost_idx != STRIPE_OFFSET ||
1253 lum->lmm_stripe_count != STRIPE_COUNT) {
1254 printf("incorrect striping information!\n");
1262 /* setstripe on regular file */
1263 rc = llapi_file_create(file, STRIPE_SIZE, STRIPE_OFFSET,
1264 STRIPE_COUNT, LOV_PATTERN_RAID0);
1266 printf("llapi_file_create failed: rc = %d (%s) \n",
1273 fd = open(file, O_RDWR, 0644);
1275 printf("failed to open(%s): rc = %d (%s)\n",
1276 file, fd, strerror(errno));
1283 lum->lmm_magic = LOV_USER_MAGIC;
1284 lum->lmm_stripe_count = STRIPE_COUNT;
1285 rc = ioctl(fd, LL_IOC_LOV_GETSTRIPE, lum);
1287 printf("file:ioctl(LL_IOC_LOV_GETSTRIPE) failed: rc = %d(%s)\n",
1288 rc, strerror(errno));
1298 printf("lmm_magic: 0x%08X\n", lum->lmm_magic);
1299 printf("lmm_object_id: "LPX64"\n", lum->lmm_object_id);
1300 printf("lmm_object_gr: "LPX64"\n", lum->lmm_object_gr);
1301 printf("lmm_stripe_count: %u\n", (int)lum->lmm_stripe_count);
1302 printf("lmm_stripe_size: %u\n", lum->lmm_stripe_size);
1303 printf("lmm_stripe_pattern: %x\n", lum->lmm_pattern);
1305 for (index = 0; index < lum->lmm_stripe_count; index++) {
1306 lo = lum->lmm_objects + index;
1307 printf("object %d:\n", index);
1308 printf("\tobject_gr: "LPX64"\n", lo->l_object_gr);
1309 printf("\tobject_id: "LPX64"\n", lo->l_object_id);
1310 printf("\tost_gen: %#x\n", lo->l_ost_gen);
1311 printf("\tost_idx: %u\n", lo->l_ost_idx);
1315 if (lum->lmm_magic != LOV_USER_MAGIC ||
1316 lum->lmm_pattern != LOV_PATTERN_RAID0 ||
1317 lum->lmm_stripe_size != STRIPE_SIZE ||
1318 lum->lmm_objects[0].l_ost_idx != STRIPE_OFFSET ||
1319 lum->lmm_stripe_count != STRIPE_COUNT) {
1320 printf("incorrect striping information!\n");
1334 * getdirentries should return -1 and set errno to EINVAL when the size
1335 * specified as an argument is too small to contain at least one entry
1336 * (see bugzilla ticket 12229)
1346 ENTER("getdirentries should fail if nbytes is too small");
1348 /* Set count to be very small. The result should be EINVAL */
1351 /* open the directory and call getdirentries */
1352 fd = t_opendir(lustre_path);
1354 rc = getdirentries(fd, (char *)&dir, nbytes, &basep);
1357 printf("Test failed: getdirentries returned %ld\n", rc);
1361 if (errno != EINVAL) {
1362 printf("Test failed: getdirentries returned %ld but errno is set"
1363 " to %d (should be EINVAL)\n", rc, errno);
1372 extern void __liblustre_setup_(void);
1373 extern void __liblustre_cleanup_(void);
1376 void usage(char *cmd)
1379 "usage: %s [--only {test}] --target mgsnid:/fsname\n",
1381 printf(" %s --dumpfile dumpfile\n", cmd);
1386 int (*test)(char *name);
1423 int main(int argc, char * const argv[])
1425 struct testlist *test;
1426 int opt_index, c, rc = 0, numonly = 0;
1428 static struct option long_opts[] = {
1429 {"dumpfile", 1, 0, 'd'},
1430 {"only", 1, 0, 'o'},
1431 {"target", 1, 0, 't'},
1432 {"verbose", 1, 0, 'v'},
1436 while ((c = getopt_long(argc, argv, "d:o:t:v", long_opts, &opt_index)) != -1) {
1439 setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);
1443 printf("Only running test(s): ");
1444 printf("%s ", optarg);
1445 only[numonly++] = optarg;
1448 setenv(ENV_LUSTRE_MNTTGT, optarg, 1);
1459 if (getenv(ENV_LUSTRE_MNTTGT) == NULL &&
1460 getenv(ENV_LUSTRE_DUMPFILE) == NULL)
1468 __liblustre_setup_();
1470 buf_size = _npages * PAGE_SIZE;
1472 printf("allocating %d bytes buffer\n", buf_size);
1473 buf_alloc = calloc(1, buf_size);
1474 if (buf_alloc == NULL) {
1475 fprintf(stderr, "error allocating %d\n", buf_size);
1479 for (test = testlist; test->test != NULL; test++) {
1486 len = strlen(test->name);
1487 for (i = 0; i < numonly; i++) {
1488 int olen = strlen(only[i]);
1493 if (strncmp(only[i], test->name, olen) == 0) {
1494 switch(test->name[olen]) {
1495 case '0': case '1': case '2': case '3':
1496 case '4': case '5': case '6': case '7':
1506 if (run && (rc = (test->test)(test->name)) != 0)
1512 printf("liblustre is about to shutdown\n");
1513 __liblustre_cleanup_();
1515 printf("complete successfully\n");