1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/liblustre/tests/sanity.c
38 * Lustre Light user test program
42 #define _FILE_OFFSET_BITS 64
49 #include <sys/types.h>
59 #include <liblustre.h>
60 #include "test_common.h"
61 #include <lustre/liblustreapi.h>
63 #define _npages (2048)
70 extern char *lustre_path;
76 sprintf(buf, "===== START %s: %s ", __FUNCTION__, (str)); \
79 memset(buf+len, '=', 100-len); \
84 gettimeofday(&start, NULL); \
89 struct timeval stop; \
90 char buf[100] = { '\0' }; \
91 int len = sizeof(buf) - 1; \
93 gettimeofday(&stop, NULL); \
94 usec = (stop.tv_sec - start.tv_sec) * 1000000 + \
95 (stop.tv_usec - start.tv_usec); \
96 len = snprintf(buf, len, \
97 "===== END TEST %s: successfully (%gs)", \
98 __FUNCTION__, (double)usec / 1000000); \
100 memset(buf+len, '=', sizeof(buf) - len); \
108 #define MAX_PATH_LENGTH 4096
112 char path[MAX_PATH_LENGTH] = "";
114 ENTER("touch+unlink");
115 snprintf(path, MAX_PATH_LENGTH, "%s/test_t1", lustre_path);
118 printf("touch+unlink %s\n", path);
127 char path[MAX_PATH_LENGTH] = "";
129 ENTER("mkdir/rmdir");
130 snprintf(path, MAX_PATH_LENGTH, "%s/test_t2", lustre_path);
139 char path[MAX_PATH_LENGTH] = "";
141 ENTER("regular stat");
142 snprintf(path, MAX_PATH_LENGTH, "%s/test_t3", lustre_path);
145 t_check_stat(path, NULL);
152 char path[MAX_PATH_LENGTH] = "";
155 snprintf(path, MAX_PATH_LENGTH, "%s/test_t4", lustre_path);
158 t_check_stat(path, NULL);
165 char path[MAX_PATH_LENGTH] = "";
166 char path2[MAX_PATH_LENGTH] = "";
169 snprintf(path, MAX_PATH_LENGTH, "%s/test_t6", lustre_path);
170 snprintf(path2, MAX_PATH_LENGTH, "%s/test_t6_link", lustre_path);
173 t_symlink(path, path2);
174 t_check_stat(path2, NULL);
182 char path[MAX_PATH_LENGTH] = "";
183 char path2[MAX_PATH_LENGTH] = "";
184 char cwd[MAX_PATH_LENGTH] = "";
188 ENTER("symlink + chdir and open");
189 snprintf(path, MAX_PATH_LENGTH, "%s/test_t6b", lustre_path);
190 snprintf(path2, MAX_PATH_LENGTH, "%s/test_t6b_link", lustre_path);
193 t_symlink(path, path2);
194 t_check_stat(path2, NULL);
196 tmp = getcwd(cwd, MAX_PATH_LENGTH);
198 fprintf(stderr, "current path too long to fit in "
199 "MAX_PATH_LENGTH?\n");
217 char path[MAX_PATH_LENGTH] = "";
221 snprintf(path, MAX_PATH_LENGTH, "%s/test_t7", lustre_path);
223 if (geteuid() != 0) {
224 rc = mknod(path, S_IFCHR | 0644, (5<<8 | 4));
225 if (rc != -1 || errno != EPERM) {
226 printf("mknod shouldn't success: rc %d, errno %d\n",
230 t_mknod(path, S_IFCHR | 0644, 5, 4);
231 t_check_stat(path, NULL);
239 char path[MAX_PATH_LENGTH] = "";
242 snprintf(path, MAX_PATH_LENGTH, "%s/test_t8", lustre_path);
246 t_chmod_raw(path, 0700);
247 t_check_stat(path, NULL);
252 t_chmod_raw(path, 0700);
253 t_check_stat(path, NULL);
261 char path[MAX_PATH_LENGTH] = "";
262 char path2[MAX_PATH_LENGTH] = "";
265 snprintf(path, MAX_PATH_LENGTH, "%s/test_t9", lustre_path);
266 snprintf(path2, MAX_PATH_LENGTH, "%s/test_t9_link", lustre_path);
270 t_check_stat(path, NULL);
271 t_check_stat(path2, NULL);
279 char dir1[MAX_PATH_LENGTH] = "";
280 char dir2[MAX_PATH_LENGTH] = "";
281 char path1[MAX_PATH_LENGTH] = "";
282 char path2[MAX_PATH_LENGTH] = "";
283 char rename1[MAX_PATH_LENGTH] = "";
284 char rename2[MAX_PATH_LENGTH] = "";
285 char rename3[MAX_PATH_LENGTH] = "";
288 snprintf(dir1, MAX_PATH_LENGTH, "%s/test_t10_dir1", lustre_path);
289 snprintf(dir2, MAX_PATH_LENGTH, "%s/test_t10_dir2", lustre_path);
290 snprintf(path1, MAX_PATH_LENGTH, "%s/test_t10_reg1", lustre_path);
291 snprintf(path2, MAX_PATH_LENGTH, "%s/test_t10_reg2", lustre_path);
292 snprintf(rename1, MAX_PATH_LENGTH, "%s/test_t10_dir1/rename1", lustre_path);
293 snprintf(rename2, MAX_PATH_LENGTH, "%s/test_t10_dir2/rename2", lustre_path);
294 snprintf(rename3, MAX_PATH_LENGTH, "%s/test_t10_dir2/rename3", lustre_path);
300 t_rename(path1, rename1);
301 t_rename(path2, rename2);
302 t_rename(rename1, rename2);
303 t_rename(dir1, rename3);
312 char *base=lustre_path;
313 char path[MAX_PATH_LENGTH], path2[MAX_PATH_LENGTH];
314 int i, j, level = 5, nreg = 5;
317 safe_strncpy(path, base, MAX_PATH_LENGTH);
319 for (i = 0; i < level; i++) {
320 for (j = 0; j < nreg; j++) {
321 sprintf(path2, "%s/file%d", path, j);
325 strcat(path, "/dir");
329 for (i = level; i > 0; i--) {
330 safe_strncpy(path, base, MAX_PATH_LENGTH);
331 for (j = 1; j < i; j++)
332 strcat(path, "/dir");
334 for (j = 0; j < nreg; j++) {
335 sprintf(path2, "%s/file%d", path, j);
339 strcat(path, "/dir");
348 char dir[MAX_PATH_LENGTH] = "";
351 ENTER("empty directory readdir");
352 snprintf(dir, MAX_PATH_LENGTH, "%s/test_t12_dir", lustre_path);
356 t_ls(fd, buf, sizeof(buf));
364 char dir[MAX_PATH_LENGTH] = "";
367 const int nfiles = 20;
368 char *prefix = "test13_filename_prefix_";
370 ENTER("multiple entries directory readdir");
371 snprintf(dir, MAX_PATH_LENGTH, "%s/test_t13_dir/", lustre_path);
374 printf("Creating %d files...\n", nfiles);
375 for (i = 0; i < nfiles; i++) {
376 sprintf(path, "%s%s%05d", dir, prefix, i);
380 t_ls(fd, buf, sizeof(buf));
382 printf("Cleanup...\n");
383 for (i = 0; i < nfiles; i++) {
384 sprintf(path, "%s%s%05d", dir, prefix, i);
393 char dir[MAX_PATH_LENGTH] = "";
396 const int nfiles = 256;
397 char *prefix = "test14_filename_long_prefix_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA___";
399 int fd, i, rc, pos, index;
401 ENTER(">1 block(4k) directory readdir");
402 snprintf(dir, MAX_PATH_LENGTH, "%s/test_t14_dir/", lustre_path);
404 rc = mkdir(dir, 0755);
405 if (rc < 0 && errno != EEXIST) {
406 printf("mkdir(%s) error: %s\n", dir, strerror(errno));
409 printf("Creating %d files...\n", nfiles);
410 for (i = 0; i < nfiles; i++) {
411 sprintf(path, "%s%s%05d", dir, prefix, i);
415 printf("Listing...\n");
417 while ((rc = getdirentries64(fd, buf, 1024, &base)) > 0) {
422 ent = (void *) buf + pos;
423 item = (char *) ent->d_name;
424 if (!strcmp(item, ".") || !strcmp(item, ".."))
426 if (strstr(item, prefix) != item) {
427 printf("found bad name %s\n", item);
430 printf("[%03d]: %s\n",
431 index++, item + strlen(prefix));
433 pos += ent->d_reclen;
437 printf("getdents error %d\n", rc);
440 if (index != nfiles) {
441 printf("get %d files != %d\n", index, nfiles);
445 printf("Cleanup...\n");
446 for (i = 0; i < nfiles; i++) {
447 sprintf(path, "%s%s%05d", dir, prefix, i);
456 char file[MAX_PATH_LENGTH] = "";
458 ENTER("open-stat-close");
459 snprintf(file, MAX_PATH_LENGTH, "%s/test_t15_file", lustre_path);
463 t_check_stat(file, NULL);
471 char file[MAX_PATH_LENGTH] = "";
472 ENTER("small-write-read");
473 snprintf(file, MAX_PATH_LENGTH, "%s/test_t16_file", lustre_path);
475 t_echo_create(file, "aaaaaaaaaaaaaaaaaaaaaa");
476 t_grep(file, "aaaaaaaaaaaaaaaaaaaaaa");
483 char file[MAX_PATH_LENGTH] = "";
485 ENTER("open-unlink without close");
486 snprintf(file, MAX_PATH_LENGTH, "%s/test_t17_file", lustre_path);
488 fd = open(file, O_WRONLY | O_CREAT, 0666);
490 printf("failed to create file: %s\n", strerror(errno));
499 char file[MAX_PATH_LENGTH] = "";
502 struct stat statbuf[3];
503 ENTER("write should change mtime/ctime");
504 snprintf(file, MAX_PATH_LENGTH, "%s/test_t18_file", lustre_path);
506 for (i = 0; i < 3; i++) {
507 fd = open(file, O_RDWR|O_CREAT|O_APPEND, (mode_t)0666);
509 printf("error open file: %s\n", strerror(errno));
512 if (write(fd, buf, sizeof(buf)) != sizeof(buf)) {
513 printf("error write file\n");
517 if(stat(file, &statbuf[i]) != 0) {
518 printf("Error stat\n");
521 printf("ctime %lu, mtime %lu\n",
522 statbuf[i].st_ctime, statbuf[i].st_mtime);
526 for (i = 1; i < 3; i++) {
527 if ((statbuf[i].st_ctime <= statbuf[i-1].st_ctime) ||
528 (statbuf[i].st_mtime <= statbuf[i-1].st_mtime)) {
529 printf("time error\n");
539 char file[MAX_PATH_LENGTH] = "";
541 struct stat statbuf[3];
542 ENTER("utime should change mtime/atime/ctime");
543 snprintf(file, MAX_PATH_LENGTH, "%s/test_t18b_file", lustre_path);
546 for (i = 0; i < 3; i++) {
548 if(stat(file, &statbuf[i]) != 0) {
549 printf("Error stat\n");
552 printf("atime %lu, mtime %lu, ctime %lu\n",
553 statbuf[i].st_atime, statbuf[i].st_mtime,
554 statbuf[i].st_ctime);
558 for (i = 1; i < 3; i++) {
559 if ((statbuf[i].st_atime <= statbuf[i-1].st_atime) ||
560 (statbuf[i].st_mtime <= statbuf[i-1].st_mtime) ||
561 (statbuf[i].st_ctime <= statbuf[i-1].st_ctime)) {
562 printf("time error\n");
570 static int check_file_size(char *file, long long size)
574 if (stat(file, &statbuf) != 0) {
575 printf("Error stat(%s)\n", file);
578 if (statbuf.st_size != size) {
579 printf("size of %s: %ld != %lld\n", file, statbuf.st_size, size);
587 char file[MAX_PATH_LENGTH] = "";
590 ENTER("open(O_TRUNC) should truncate file to 0-length");
591 snprintf(file, MAX_PATH_LENGTH, "%s/test_t19_file", lustre_path);
593 t_echo_create(file, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
595 fd = open(file, O_RDWR|O_CREAT|O_TRUNC, (mode_t)0666);
597 printf("error open file: %s\n", strerror(errno));
601 result = check_file_size(file, 0);
610 char file[MAX_PATH_LENGTH] = "";
615 ENTER("trap app's general bad pointer for file i/o");
616 snprintf(file, MAX_PATH_LENGTH, "%s/test_t20_file", lustre_path);
618 fd = open(file, O_RDWR|O_CREAT, (mode_t)0666);
620 printf("error open file: %s\n", strerror(errno));
624 ret = write(fd, NULL, 20);
625 if (ret != -1 || errno != EFAULT) {
626 printf("write 1: ret %ld, errno %d\n", ret, errno);
629 ret = write(fd, (void *)-1, 20);
630 if (ret != -1 || errno != EFAULT) {
631 printf("write 2: ret %ld, errno %d\n", ret, errno);
634 iov[0].iov_base = NULL;
636 iov[1].iov_base = (void *)-1;
638 ret = writev(fd, iov, 2);
639 if (ret != -1 || errno != EFAULT) {
640 printf("writev 1: ret %ld, errno %d\n", ret, errno);
643 iov[0].iov_base = NULL;
645 iov[1].iov_base = buf;
646 iov[1].iov_len = sizeof(buf);
647 ret = writev(fd, iov, 2);
648 if (ret != sizeof(buf)) {
649 printf("write 3 ret %ld, error %d\n", ret, errno);
652 lseek(fd, 0, SEEK_SET);
654 ret = read(fd, NULL, 20);
655 if (ret != -1 || errno != EFAULT) {
656 printf("read 1: ret %ld, errno %d\n", ret, errno);
659 ret = read(fd, (void *)-1, 20);
660 if (ret != -1 || errno != EFAULT) {
661 printf("read 2: ret %ld, errno %d\n", ret, errno);
664 iov[0].iov_base = NULL;
666 iov[1].iov_base = (void *)-1;
668 ret = readv(fd, iov, 2);
669 if (ret != -1 || errno != EFAULT) {
670 printf("readv 1: ret %ld, errno %d\n", ret, errno);
673 iov[0].iov_base = NULL;
675 iov[1].iov_base = buf;
676 iov[1].iov_len = sizeof(buf);
677 ret = readv(fd, iov, 2);
678 if (ret != sizeof(buf)) {
679 printf("read 3 ret %ld, error %d\n", ret, errno);
690 char file[MAX_PATH_LENGTH] = "";
692 struct flock lock = {
694 .l_whence = SEEK_SET,
697 ENTER("basic fcntl support");
698 snprintf(file, MAX_PATH_LENGTH, "%s/test_t21_file", lustre_path);
700 fd = open(file, O_RDWR|O_CREAT, (mode_t)0666);
702 printf("error open file: %s\n", file);
706 t_fcntl(fd, F_SETFL, O_APPEND);
707 if (!(ret = t_fcntl(fd, F_GETFL)) & O_APPEND) {
708 printf("error get flag: ret %x\n", ret);
712 t_fcntl(fd, F_SETLK, &lock);
713 t_fcntl(fd, F_GETLK, &lock);
714 lock.l_type = F_WRLCK;
715 t_fcntl(fd, F_SETLKW, &lock);
716 t_fcntl(fd, F_GETLK, &lock);
717 lock.l_type = F_UNLCK;
718 t_fcntl(fd, F_SETLK, &lock);
727 char file[MAX_PATH_LENGTH] = "";
729 char *str = "1234567890";
732 ENTER("make sure O_APPEND take effect");
733 snprintf(file, MAX_PATH_LENGTH, "%s/test_t22_file", lustre_path);
735 fd = open(file, O_RDWR|O_CREAT|O_APPEND, (mode_t)0666);
737 printf("error open file: %s\n", strerror(errno));
741 lseek(fd, 100, SEEK_SET);
742 ret = write(fd, str, strlen(str));
743 if (ret != strlen(str)) {
744 printf("write 1: ret %ld, errno %d\n", ret, errno);
748 lseek(fd, 0, SEEK_SET);
749 ret = read(fd, buf, sizeof(buf));
750 if (ret != strlen(str)) {
751 printf("read 1 got %ld\n", ret);
755 if (memcmp(buf, str, strlen(str))) {
756 printf("read 1 data err\n");
760 if (fcntl(fd, F_SETFL, 0)) {
761 printf("fcntl err: %s\n", strerror(errno));
765 lseek(fd, 100, SEEK_SET);
766 ret = write(fd, str, strlen(str));
767 if (ret != strlen(str)) {
768 printf("write 2: ret %ld, errno %d\n", ret, errno);
772 lseek(fd, 100, SEEK_SET);
773 ret = read(fd, buf, sizeof(buf));
774 if (ret != strlen(str)) {
775 printf("read 2 got %ld\n", ret);
779 if (memcmp(buf, str, strlen(str))) {
780 printf("read 2 data err\n");
791 char path[MAX_PATH_LENGTH];
796 ENTER("handle seek > 2GB");
797 snprintf(path, MAX_PATH_LENGTH, "%s/f%s", lustre_path, name);
799 fd = open(path, O_WRONLY | O_CREAT | O_LARGEFILE, 0666);
801 printf("failed to create file %s: %s\n", path, strerror(errno));
805 off = 2048ULL * 1024 * 1024 - buf_size / 2;
806 ret = lseek(fd, off, SEEK_SET);
808 printf("seek error for initial %llu != %llu\n",
809 ret, (long long)off);
813 ret = write(fd, buf_alloc, buf_size);
814 if (ret != buf_size) {
815 printf("write error for %d != %llubytes @ %llu\n",
816 buf_size, ret, (long long)off);
822 ret = lseek(fd, off, SEEK_SET);
824 printf("seek < 2GB error for %llu != %llu\n",
825 ret, (long long)off);
827 perror("seek < 2GB");
831 ret = lseek(fd, off + buf_size - 2, SEEK_SET);
832 if (ret != off + buf_size - 2) {
833 printf("seek > 2GB error for %llu != %llu\n",
834 ret, (long long)off);
836 perror("seek > 2GB");
840 ret = lseek(fd, -buf_size + 2, SEEK_CUR);
842 printf("relative seek error for %d %llu != %llu\n",
843 -buf_size + 2, ret, off);
845 perror("relative seek");
849 ret = lseek(fd, 0, SEEK_END);
850 if (ret != off + buf_size) {
851 printf("end seek error for %llu != %llu\n",
852 ret, (long long)off + buf_size);
858 ret = lseek(fd, 0, SEEK_SET);
860 printf("seek 0 error for %llu != 0\n", ret);
866 off = 2048ULL * 1024 * 1024, SEEK_SET;
867 ret = lseek(fd, off, SEEK_SET);
869 printf("seek 2GB error for %llu != %llu\n", ret, off);
880 /* pos: i/o start from
881 * xfer: npages per transfer
883 static int pages_io(int xfer, loff_t pos)
885 char path[MAX_PATH_LENGTH] = "";
887 int check_sum[_npages] = {0,}, *buf;
888 int fd, rc, i, j, data_error = 0;
889 struct timeval tw1, tw2, tr1, tr2;
893 snprintf(path, MAX_PATH_LENGTH, "%s/test_t50", lustre_path);
895 memset(buf_alloc, 0, buf_size);
897 /* create sample data */
898 for (i = 0, buf = buf_alloc; i < _npages; i++) {
899 for (j = 0; j < CFS_PAGE_SIZE/sizeof(int); j++, buf++) {
904 /* compute checksum */
905 for (i = 0, buf = buf_alloc; i < _npages; i++) {
906 for (j = 0; j < CFS_PAGE_SIZE/sizeof(int); j++, buf++) {
907 check_sum[i] += *buf;
917 ret = lseek(fd, pos, SEEK_SET);
919 perror("write seek");
922 gettimeofday(&tw1, NULL);
923 for (i = 0, buf = buf_alloc; i < _npages;
924 i += xfer, buf += xfer * CFS_PAGE_SIZE / sizeof(int)) {
925 rc = write(fd, buf, CFS_PAGE_SIZE * xfer);
926 if (rc != CFS_PAGE_SIZE * xfer) {
927 printf("write error (i %d, rc %d): %s\n", i, rc,
932 gettimeofday(&tw2, NULL);
934 memset(buf_alloc, 0, buf_size);
937 ret = lseek(fd, pos, SEEK_SET);
942 gettimeofday(&tr1, NULL);
943 for (i = 0, buf = buf_alloc; i < _npages;
944 i += xfer, buf += xfer * CFS_PAGE_SIZE / sizeof(int)) {
945 rc = read(fd, buf, CFS_PAGE_SIZE * xfer);
946 if (rc != CFS_PAGE_SIZE * xfer) {
947 printf("read error (i %d, rc %d): %s\n", i, rc,
952 gettimeofday(&tr2, NULL);
954 /* compute checksum */
955 for (i = 0, buf = buf_alloc; i < _npages; i++) {
957 for (j = 0; j < CFS_PAGE_SIZE/sizeof(int); j++, buf++) {
960 if (sum != check_sum[i]) {
962 printf("chunk %d checksum error expected %#x got %#x\n",
963 i, check_sum[i], sum);
969 tw = (tw2.tv_sec - tw1.tv_sec) * 1000000 + (tw2.tv_usec - tw1.tv_usec);
970 tr = (tr2.tv_sec - tr1.tv_sec) * 1000000 + (tr2.tv_usec - tr1.tv_usec);
971 printf(" (R:%.3fM/s, W:%.3fM/s)\n",
972 (_npages * CFS_PAGE_SIZE) / (tw / 1000000.0) / (1024 * 1024),
973 (_npages * CFS_PAGE_SIZE) / (tr / 1000000.0) / (1024 * 1024));
986 ENTER("4k aligned i/o sanity");
987 while (np <= _npages) {
988 printf("%3d per xfer(total %d)...\t", np, _npages);
990 if (pages_io(np, offset) != 0)
999 loff_t off_array[] = {1, 17, 255, 258, 4095, 4097, 8191,
1000 1024*1024*1024*1024ULL};
1004 ENTER("4k un-aligned i/o sanity");
1005 for (i = 0; i < sizeof(off_array)/sizeof(loff_t); i++) {
1006 offset = off_array[i];
1007 printf("16 per xfer(total %d), offset %10lld...\t",
1009 if (pages_io(16, offset) != 0)
1022 * truncate(2) checks.
1026 char file[MAX_PATH_LENGTH] = "";
1031 ENTER("truncate() should truncate file to proper length");
1032 snprintf(file, MAX_PATH_LENGTH, "%s/test_t51_file", lustre_path);
1034 for (size = 0; size < T51_NR * T51_STEP; size += T51_STEP) {
1035 t_echo_create(file, "");
1036 if (truncate(file, size) != 0) {
1037 printf("\nerror truncating file: %s\n",strerror(errno));
1040 result = check_file_size(file, size);
1045 t_echo_create(file, "");
1046 fd = open(file, O_RDWR|O_CREAT, (mode_t)0666);
1048 printf("\nerror open file: %s\n", strerror(errno));
1051 if (ftruncate(fd, size) != 0) {
1052 printf("\nerror ftruncating file:%s\n",strerror(errno));
1056 result = check_file_size(file, size);
1060 if (size % (T51_STEP * (T51_NR / 75)) == 0) {
1069 * check atime update during read
1073 char file[MAX_PATH_LENGTH] = "";
1075 struct stat statbuf;
1080 ENTER("atime should be updated during read");
1081 snprintf(file, MAX_PATH_LENGTH, "%s/test_t52_file", lustre_path);
1083 t_echo_create(file, "check atime update during read");
1084 fd = open(file, O_RDONLY);
1086 printf("\nerror open file: %s\n", strerror(errno));
1089 stat(file, &statbuf);
1090 printf("st_atime=%s", ctime(&statbuf.st_atime));
1091 atime = statbuf.st_atime;
1092 for (i = 0; i < 3; i++) {
1094 read(fd, buf, sizeof(buf));
1095 stat(file, &statbuf);
1096 printf("st_atime=%s", ctime(&statbuf.st_atime));
1097 diff = statbuf.st_atime - atime;
1099 printf("atime doesn't updated! failed!\n");
1104 atime = statbuf.st_atime;
1111 #define NEW_TIME 10000
1114 char file[MAX_PATH_LENGTH] = "";
1115 struct utimbuf times; /* struct. buffer for utime() */
1116 struct stat stat_buf; /* struct buffer to hold file info. */
1117 time_t mtime, atime;
1119 ENTER("mtime/atime should be updated by utime() call");
1120 snprintf(file, MAX_PATH_LENGTH, "%s/test_t53_file", lustre_path);
1122 t_echo_create(file, "check mtime/atime update by utime() call");
1124 /* Initialize the modification and access time in the times arg */
1125 times.actime = NEW_TIME+10;
1126 times.modtime = NEW_TIME;
1128 /* file modification/access time */
1129 utime(file, ×);
1131 if (stat(file, &stat_buf) < 0) {
1132 printf("stat(2) of %s failed, error:%d %s\n",
1133 file, errno, strerror(errno));
1135 mtime = stat_buf.st_mtime;
1136 atime = stat_buf.st_atime;
1138 if ((mtime == NEW_TIME) && (atime == NEW_TIME + 10)) {
1143 printf("mod time %ld, expected %ld\n", mtime, (long)NEW_TIME);
1144 printf("acc time %ld, expected %ld\n", atime, (long)NEW_TIME + 10);
1152 char file[MAX_PATH_LENGTH] = "";
1156 ENTER("fcntl should return 0 when succeed in getting flock");
1157 snprintf(file, MAX_PATH_LENGTH, "%s/test_t54_file", lustre_path);
1159 t_echo_create(file, "fcntl should return 0 when succeed");
1161 fd = open(file, O_RDWR);
1163 printf("\nerror open file: %s\n", strerror(errno));
1166 lock.l_type = F_WRLCK;
1170 if ((err = t_fcntl(fd, F_SETLKW, &lock)) != 0) {
1171 fprintf(stderr, "fcntl returned: %d (%s)\n",
1172 err, strerror(err));
1178 lock.l_type = F_UNLCK;
1179 t_fcntl(fd, F_SETLKW, &lock);
1185 /* for O_DIRECTORY */
1190 #define STRIPE_SIZE (2048 * 2048)
1191 #define STRIPE_OFFSET 0
1192 #define STRIPE_COUNT 1
1195 char path[MAX_PATH_LENGTH] = "";
1196 char file[MAX_PATH_LENGTH] = "";
1197 struct lov_user_md *lum = NULL;
1198 struct lov_user_ost_data *lo = NULL;
1199 int index, fd, buflen, rc;
1201 ENTER("setstripe/getstripe");
1202 snprintf(path, MAX_PATH_LENGTH, "%s/test_t55", lustre_path);
1203 snprintf(file, MAX_PATH_LENGTH, "%s/test_t55/file_t55", lustre_path);
1205 buflen = sizeof(struct lov_user_md);
1206 buflen += STRIPE_COUNT * sizeof(struct lov_user_ost_data);
1207 lum = (struct lov_user_md *)malloc(buflen);
1209 printf("out of memory!\n");
1212 memset(lum, 0, buflen);
1215 rc = llapi_file_create(path, STRIPE_SIZE, STRIPE_OFFSET,
1216 STRIPE_COUNT, LOV_PATTERN_RAID0);
1218 printf("llapi_file_create failed: rc = %d (%s) \n",
1225 fd = open(file, O_CREAT | O_RDWR, 0644);
1227 printf("open file(%s) failed: rc = %d (%s) \n)",
1228 file, fd, strerror(errno));
1234 lum->lmm_magic = LOV_USER_MAGIC;
1235 lum->lmm_stripe_count = STRIPE_COUNT;
1236 rc = ioctl(fd, LL_IOC_LOV_GETSTRIPE, lum);
1238 printf("dir:ioctl(LL_IOC_LOV_GETSTRIPE) failed: rc = %d(%s)\n",
1239 rc, strerror(errno));
1250 printf("lmm_magic: 0x%08X\n", lum->lmm_magic);
1251 printf("lmm_object_id: "LPX64"\n", lum->lmm_object_id);
1252 printf("lmm_object_gr: "LPX64"\n", lum->lmm_object_gr);
1253 printf("lmm_stripe_count: %u\n", (int)lum->lmm_stripe_count);
1254 printf("lmm_stripe_size: %u\n", lum->lmm_stripe_size);
1255 printf("lmm_stripe_pattern: %x\n", lum->lmm_pattern);
1257 for (index = 0; index < lum->lmm_stripe_count; index++) {
1258 lo = lum->lmm_objects + index;
1259 printf("object %d:\n", index);
1260 printf("\tobject_gr: "LPX64"\n", lo->l_object_gr);
1261 printf("\tobject_id: "LPX64"\n", lo->l_object_id);
1262 printf("\tost_gen: %#x\n", lo->l_ost_gen);
1263 printf("\tost_idx: %u\n", lo->l_ost_idx);
1267 if (lum->lmm_magic != LOV_USER_MAGIC ||
1268 lum->lmm_pattern != LOV_PATTERN_RAID0 ||
1269 lum->lmm_stripe_size != STRIPE_SIZE ||
1270 lum->lmm_objects[0].l_ost_idx != STRIPE_OFFSET ||
1271 lum->lmm_stripe_count != STRIPE_COUNT) {
1272 printf("incorrect striping information!\n");
1280 /* setstripe on regular file */
1281 rc = llapi_file_create(file, STRIPE_SIZE, STRIPE_OFFSET,
1282 STRIPE_COUNT, LOV_PATTERN_RAID0);
1284 printf("llapi_file_create failed: rc = %d (%s) \n",
1291 fd = open(file, O_RDWR, 0644);
1293 printf("failed to open(%s): rc = %d (%s)\n",
1294 file, fd, strerror(errno));
1301 lum->lmm_magic = LOV_USER_MAGIC;
1302 lum->lmm_stripe_count = STRIPE_COUNT;
1303 rc = ioctl(fd, LL_IOC_LOV_GETSTRIPE, lum);
1305 printf("file:ioctl(LL_IOC_LOV_GETSTRIPE) failed: rc = %d(%s)\n",
1306 rc, strerror(errno));
1316 printf("lmm_magic: 0x%08X\n", lum->lmm_magic);
1317 printf("lmm_object_id: "LPX64"\n", lum->lmm_object_id);
1318 printf("lmm_object_gr: "LPX64"\n", lum->lmm_object_gr);
1319 printf("lmm_stripe_count: %u\n", (int)lum->lmm_stripe_count);
1320 printf("lmm_stripe_size: %u\n", lum->lmm_stripe_size);
1321 printf("lmm_stripe_pattern: %x\n", lum->lmm_pattern);
1323 for (index = 0; index < lum->lmm_stripe_count; index++) {
1324 lo = lum->lmm_objects + index;
1325 printf("object %d:\n", index);
1326 printf("\tobject_gr: "LPX64"\n", lo->l_object_gr);
1327 printf("\tobject_id: "LPX64"\n", lo->l_object_id);
1328 printf("\tost_gen: %#x\n", lo->l_ost_gen);
1329 printf("\tost_idx: %u\n", lo->l_ost_idx);
1333 if (lum->lmm_magic != LOV_USER_MAGIC ||
1334 lum->lmm_pattern != LOV_PATTERN_RAID0 ||
1335 lum->lmm_stripe_size != STRIPE_SIZE ||
1336 lum->lmm_objects[0].l_ost_idx != STRIPE_OFFSET ||
1337 lum->lmm_stripe_count != STRIPE_COUNT) {
1338 printf("incorrect striping information!\n");
1352 * getdirentries should return -1 and set errno to EINVAL when the size
1353 * specified as an argument is too small to contain at least one entry
1354 * (see bugzilla ticket 12229)
1364 ENTER("getdirentries should fail if nbytes is too small");
1366 /* Set count to be very small. The result should be EINVAL */
1369 /* open the directory and call getdirentries */
1370 fd = t_opendir(lustre_path);
1372 rc = getdirentries(fd, (char *)&dir, nbytes, &basep);
1375 printf("Test failed: getdirentries returned %ld\n", rc);
1379 if (errno != EINVAL) {
1380 printf("Test failed: getdirentries returned %ld but errno is set"
1381 " to %d (should be EINVAL)\n", rc, errno);
1390 extern void __liblustre_setup_(void);
1391 extern void __liblustre_cleanup_(void);
1394 void usage(char *cmd)
1397 "usage: %s [-o test][-e test][-v] --target mgsnid:/fsname\n",
1399 printf(" %s --dumpfile dumpfile\n", cmd);
1404 int (*test)(char *name);
1441 int main(int argc, char * const argv[])
1443 struct testlist *test;
1444 int opt_index, c, rc = 0, numonly = 0, numexcept = 0;
1445 char *only[100], *except[100];
1446 static struct option long_opts[] = {
1447 {"dumpfile", 1, 0, 'd'},
1448 {"only", 1, 0, 'o'},
1449 {"except", 1, 0, 'e'},
1450 {"target", 1, 0, 't'},
1451 {"verbose", 1, 0, 'v'},
1455 while ((c = getopt_long(argc, argv, "d:e:o:t:v", long_opts, &opt_index)) != -1) {
1458 setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);
1462 printf("Not running test(s): ");
1463 printf("%s ", optarg);
1464 except[numexcept++] = optarg;
1468 printf("Only running test(s): ");
1469 printf("%s ", optarg);
1470 only[numonly++] = optarg;
1473 setenv(ENV_LUSTRE_MNTTGT, optarg, 1);
1484 if (getenv(ENV_LUSTRE_MNTTGT) == NULL &&
1485 getenv(ENV_LUSTRE_DUMPFILE) == NULL)
1493 __liblustre_setup_();
1495 buf_size = _npages * CFS_PAGE_SIZE;
1497 printf("allocating %d bytes buffer\n", buf_size);
1498 buf_alloc = calloc(1, buf_size);
1499 if (buf_alloc == NULL) {
1500 fprintf(stderr, "error allocating %d\n", buf_size);
1504 for (test = testlist; test->test != NULL; test++) {
1508 if (numexcept > 0) {
1509 len = strlen(test->name);
1510 for (i = 0; i < numexcept; i++) {
1511 olen = strlen(except[i]);
1516 if (strncmp(except[i], test->name, olen) == 0) {
1517 switch(test->name[olen]) {
1518 case '0': case '1': case '2': case '3':
1519 case '4': case '5': case '6': case '7':
1532 len = strlen(test->name);
1533 for (i = 0; i < numonly; i++) {
1534 olen = strlen(only[i]);
1539 if (strncmp(only[i], test->name, olen) == 0) {
1540 switch(test->name[olen]) {
1541 case '0': case '1': case '2': case '3':
1542 case '4': case '5': case '6': case '7':
1552 if (run && (rc = (test->test)(test->name)) != 0)
1558 printf("liblustre is about to shutdown\n");
1559 __liblustre_cleanup_();
1561 printf("complete successfully\n");