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 gettimeofday(&start, NULL); \
77 sprintf(buf, "===== START %s: %s %ld", __FUNCTION__, \
78 (str), (long)start.tv_sec); \
81 memset(buf+len, '=', 100-len); \
90 struct timeval stop; \
91 char buf[100] = { '\0' }; \
92 int len = sizeof(buf) - 1; \
94 gettimeofday(&stop, NULL); \
95 usec = (stop.tv_sec - start.tv_sec) * 1000000 + \
96 (stop.tv_usec - start.tv_usec); \
97 len = snprintf(buf, len, \
98 "===== END TEST %s: successfully (%gs)", \
99 __FUNCTION__, (double)usec / 1000000); \
101 memset(buf+len, '=', sizeof(buf) - len); \
109 #define MAX_PATH_LENGTH 4096
113 char path[MAX_PATH_LENGTH] = "";
115 ENTER("touch+unlink");
116 snprintf(path, MAX_PATH_LENGTH, "%s/test_t1", lustre_path);
119 printf("touch+unlink %s\n", path);
128 char path[MAX_PATH_LENGTH] = "";
130 ENTER("mkdir/rmdir");
131 snprintf(path, MAX_PATH_LENGTH, "%s/test_t2", lustre_path);
140 char path[MAX_PATH_LENGTH] = "";
142 ENTER("regular stat");
143 snprintf(path, MAX_PATH_LENGTH, "%s/test_t3", lustre_path);
146 t_check_stat(path, NULL);
153 char path[MAX_PATH_LENGTH] = "";
156 snprintf(path, MAX_PATH_LENGTH, "%s/test_t4", lustre_path);
159 t_check_stat(path, NULL);
166 char path[MAX_PATH_LENGTH] = "";
167 char path2[MAX_PATH_LENGTH] = "";
170 snprintf(path, MAX_PATH_LENGTH, "%s/test_t6", lustre_path);
171 snprintf(path2, MAX_PATH_LENGTH, "%s/test_t6_link", lustre_path);
174 t_symlink(path, path2);
175 t_check_stat(path2, NULL);
183 char path[MAX_PATH_LENGTH] = "";
184 char path2[MAX_PATH_LENGTH] = "";
185 char cwd[MAX_PATH_LENGTH] = "";
189 ENTER("symlink + chdir and open");
190 snprintf(path, MAX_PATH_LENGTH, "%s/test_t6b", lustre_path);
191 snprintf(path2, MAX_PATH_LENGTH, "%s/test_t6b_link", lustre_path);
194 t_symlink(path, path2);
195 t_check_stat(path2, NULL);
197 tmp = getcwd(cwd, MAX_PATH_LENGTH);
199 fprintf(stderr, "current path too long to fit in "
200 "MAX_PATH_LENGTH?\n");
218 char path[MAX_PATH_LENGTH] = "";
222 snprintf(path, MAX_PATH_LENGTH, "%s/test_t7", lustre_path);
224 if (geteuid() != 0) {
225 rc = mknod(path, S_IFCHR | 0644, (5<<8 | 4));
226 if (rc != -1 || errno != EPERM) {
227 printf("mknod shouldn't success: rc %d, errno %d\n",
231 t_mknod(path, S_IFCHR | 0644, 5, 4);
232 t_check_stat(path, NULL);
240 char path[MAX_PATH_LENGTH] = "";
243 snprintf(path, MAX_PATH_LENGTH, "%s/test_t8", lustre_path);
247 t_chmod_raw(path, 0700);
248 t_check_stat(path, NULL);
253 t_chmod_raw(path, 0700);
254 t_check_stat(path, NULL);
262 char path[MAX_PATH_LENGTH] = "";
263 char path2[MAX_PATH_LENGTH] = "";
266 snprintf(path, MAX_PATH_LENGTH, "%s/test_t9", lustre_path);
267 snprintf(path2, MAX_PATH_LENGTH, "%s/test_t9_link", lustre_path);
271 t_check_stat(path, NULL);
272 t_check_stat(path2, NULL);
280 char dir1[MAX_PATH_LENGTH] = "";
281 char dir2[MAX_PATH_LENGTH] = "";
282 char path1[MAX_PATH_LENGTH] = "";
283 char path2[MAX_PATH_LENGTH] = "";
284 char rename1[MAX_PATH_LENGTH] = "";
285 char rename2[MAX_PATH_LENGTH] = "";
286 char rename3[MAX_PATH_LENGTH] = "";
289 snprintf(dir1, MAX_PATH_LENGTH, "%s/test_t10_dir1", lustre_path);
290 snprintf(dir2, MAX_PATH_LENGTH, "%s/test_t10_dir2", lustre_path);
291 snprintf(path1, MAX_PATH_LENGTH, "%s/test_t10_reg1", lustre_path);
292 snprintf(path2, MAX_PATH_LENGTH, "%s/test_t10_reg2", lustre_path);
293 snprintf(rename1, MAX_PATH_LENGTH, "%s/test_t10_dir1/rename1", lustre_path);
294 snprintf(rename2, MAX_PATH_LENGTH, "%s/test_t10_dir2/rename2", lustre_path);
295 snprintf(rename3, MAX_PATH_LENGTH, "%s/test_t10_dir2/rename3", lustre_path);
301 t_rename(path1, rename1);
302 t_rename(path2, rename2);
303 t_rename(rename1, rename2);
304 t_rename(dir1, rename3);
313 char *base=lustre_path;
314 char path[MAX_PATH_LENGTH], path2[MAX_PATH_LENGTH];
315 int i, j, level = 5, nreg = 5;
318 safe_strncpy(path, base, MAX_PATH_LENGTH);
320 for (i = 0; i < level; i++) {
321 for (j = 0; j < nreg; j++) {
322 sprintf(path2, "%s/file%d", path, j);
326 strcat(path, "/dir");
330 for (i = level; i > 0; i--) {
331 safe_strncpy(path, base, MAX_PATH_LENGTH);
332 for (j = 1; j < i; j++)
333 strcat(path, "/dir");
335 for (j = 0; j < nreg; j++) {
336 sprintf(path2, "%s/file%d", path, j);
340 strcat(path, "/dir");
349 char dir[MAX_PATH_LENGTH] = "";
352 ENTER("empty directory readdir");
353 snprintf(dir, MAX_PATH_LENGTH, "%s/test_t12_dir", lustre_path);
357 t_ls(fd, buf, sizeof(buf));
365 char dir[MAX_PATH_LENGTH] = "";
368 const int nfiles = 20;
369 char *prefix = "test13_filename_prefix_";
371 ENTER("multiple entries directory readdir");
372 snprintf(dir, MAX_PATH_LENGTH, "%s/test_t13_dir/", lustre_path);
375 printf("Creating %d files...\n", nfiles);
376 for (i = 0; i < nfiles; i++) {
377 sprintf(path, "%s%s%05d", dir, prefix, i);
381 t_ls(fd, buf, sizeof(buf));
383 printf("Cleanup...\n");
384 for (i = 0; i < nfiles; i++) {
385 sprintf(path, "%s%s%05d", dir, prefix, i);
394 char dir[MAX_PATH_LENGTH] = "";
397 const int nfiles = 256;
398 char *prefix = "test14_filename_long_prefix_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA___";
400 int fd, i, rc, pos, index;
402 ENTER(">1 block(4k) directory readdir");
403 snprintf(dir, MAX_PATH_LENGTH, "%s/test_t14_dir/", lustre_path);
405 rc = mkdir(dir, 0755);
406 if (rc < 0 && errno != EEXIST) {
407 printf("mkdir(%s) error: %s\n", dir, strerror(errno));
410 printf("Creating %d files...\n", nfiles);
411 for (i = 0; i < nfiles; i++) {
412 sprintf(path, "%s%s%05d", dir, prefix, i);
416 printf("Listing...\n");
418 while ((rc = getdirentries64(fd, buf, 1024, &base)) > 0) {
423 ent = (void *) buf + pos;
424 item = (char *) ent->d_name;
425 if (!strcmp(item, ".") || !strcmp(item, ".."))
427 if (strstr(item, prefix) != item) {
428 printf("found bad name %s\n", item);
431 printf("[%03d]: %s\t",
432 index++, item + strlen(prefix));
434 pos += ent->d_reclen;
439 printf("getdents error %d\n", rc);
442 if (index != nfiles) {
443 printf("get %d files != %d\n", index, nfiles);
447 printf("Cleanup...\n");
448 for (i = 0; i < nfiles; i++) {
449 sprintf(path, "%s%s%05d", dir, prefix, i);
458 char file[MAX_PATH_LENGTH] = "";
460 ENTER("open-stat-close");
461 snprintf(file, MAX_PATH_LENGTH, "%s/test_t15_file", lustre_path);
465 t_check_stat(file, NULL);
473 char file[MAX_PATH_LENGTH] = "";
474 ENTER("small-write-read");
475 snprintf(file, MAX_PATH_LENGTH, "%s/test_t16_file", lustre_path);
477 t_echo_create(file, "aaaaaaaaaaaaaaaaaaaaaa");
478 t_grep(file, "aaaaaaaaaaaaaaaaaaaaaa");
485 char file[MAX_PATH_LENGTH] = "";
487 ENTER("open-unlink without close");
488 snprintf(file, MAX_PATH_LENGTH, "%s/test_t17_file", lustre_path);
490 fd = open(file, O_WRONLY | O_CREAT, 0666);
492 printf("failed to create file: %s\n", strerror(errno));
501 char file[MAX_PATH_LENGTH] = "";
504 struct stat statbuf[3];
505 ENTER("write should change mtime/ctime");
506 snprintf(file, MAX_PATH_LENGTH, "%s/test_t18_file", lustre_path);
508 for (i = 0; i < 3; i++) {
509 fd = open(file, O_RDWR|O_CREAT|O_APPEND, (mode_t)0666);
511 printf("error open file: %s\n", strerror(errno));
514 if (write(fd, buf, sizeof(buf)) != sizeof(buf)) {
515 printf("error write file\n");
519 if(stat(file, &statbuf[i]) != 0) {
520 printf("Error stat\n");
523 printf("ctime %lu, mtime %lu\n",
524 statbuf[i].st_ctime, statbuf[i].st_mtime);
528 for (i = 1; i < 3; i++) {
529 if ((statbuf[i].st_ctime <= statbuf[i-1].st_ctime) ||
530 (statbuf[i].st_mtime <= statbuf[i-1].st_mtime)) {
531 printf("time error\n");
541 char file[MAX_PATH_LENGTH] = "";
543 struct stat statbuf[3];
544 ENTER("utime should change mtime/atime/ctime");
545 snprintf(file, MAX_PATH_LENGTH, "%s/test_t18b_file", lustre_path);
548 for (i = 0; i < 3; i++) {
550 if(stat(file, &statbuf[i]) != 0) {
551 printf("Error stat\n");
554 printf("atime %lu, mtime %lu, ctime %lu\n",
555 statbuf[i].st_atime, statbuf[i].st_mtime,
556 statbuf[i].st_ctime);
560 for (i = 1; i < 3; i++) {
561 if ((statbuf[i].st_atime <= statbuf[i-1].st_atime) ||
562 (statbuf[i].st_mtime <= statbuf[i-1].st_mtime) ||
563 (statbuf[i].st_ctime <= statbuf[i-1].st_ctime)) {
564 printf("time error\n");
572 static int check_file_size(char *file, long long size)
576 if (stat(file, &statbuf) != 0) {
577 printf("Error stat(%s)\n", file);
580 if (statbuf.st_size != size) {
581 printf("size of %s: %lld != %lld\n", file,
582 (long long)statbuf.st_size, (long long )size);
590 char file[MAX_PATH_LENGTH] = "";
593 ENTER("open(O_TRUNC) should truncate file to 0-length");
594 snprintf(file, MAX_PATH_LENGTH, "%s/test_t19_file", lustre_path);
596 t_echo_create(file, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
598 fd = open(file, O_RDWR|O_CREAT|O_TRUNC, (mode_t)0666);
600 printf("error open file: %s\n", strerror(errno));
604 result = check_file_size(file, 0);
613 char file[MAX_PATH_LENGTH] = "";
618 ENTER("trap app's general bad pointer for file i/o");
619 snprintf(file, MAX_PATH_LENGTH, "%s/test_t20_file", lustre_path);
621 fd = open(file, O_RDWR|O_CREAT, (mode_t)0666);
623 printf("error open file: %s\n", strerror(errno));
627 ret = write(fd, NULL, 20);
628 if (ret != -1 || errno != EFAULT) {
629 printf("write 1: ret %lld, errno %d\n", (long long)ret, errno);
632 ret = write(fd, (void *)-1, 20);
633 if (ret != -1 || errno != EFAULT) {
634 printf("write 2: ret %lld, errno %d\n", (long long)ret, errno);
637 iov[0].iov_base = NULL;
639 iov[1].iov_base = (void *)-1;
641 ret = writev(fd, iov, 2);
642 if (ret != -1 || errno != EFAULT) {
643 printf("writev 1: ret %lld, errno %d\n", (long long)ret, errno);
646 iov[0].iov_base = NULL;
648 iov[1].iov_base = buf;
649 iov[1].iov_len = sizeof(buf);
650 ret = writev(fd, iov, 2);
651 if (ret != sizeof(buf)) {
652 printf("writev 2: ret %lld, error %d\n", (long long)ret, errno);
655 lseek(fd, 0, SEEK_SET);
657 ret = read(fd, NULL, 20);
658 if (ret != -1 || errno != EFAULT) {
659 printf("read 1: ret %lld, errno %d\n", (long long)ret, errno);
662 ret = read(fd, (void *)-1, 20);
663 if (ret != -1 || errno != EFAULT) {
664 printf("read 2: ret %lld, error %d\n", (long long)ret, errno);
667 iov[0].iov_base = NULL;
669 iov[1].iov_base = (void *)-1;
671 ret = readv(fd, iov, 2);
672 if (ret != -1 || errno != EFAULT) {
673 printf("readv 1: ret %lld, error %d\n", (long long)ret, errno);
676 iov[0].iov_base = NULL;
678 iov[1].iov_base = buf;
679 iov[1].iov_len = sizeof(buf);
680 ret = readv(fd, iov, 2);
681 if (ret != sizeof(buf)) {
682 printf("readv 2: ret %lld, error %d\n", (long long)ret, errno);
693 char file[MAX_PATH_LENGTH] = "";
695 struct flock lock = {
697 .l_whence = SEEK_SET,
700 ENTER("basic fcntl support");
701 snprintf(file, MAX_PATH_LENGTH, "%s/test_t21_file", lustre_path);
703 fd = open(file, O_RDWR|O_CREAT, (mode_t)0666);
705 printf("error open file: %s\n", file);
709 t_fcntl(fd, F_SETFL, O_APPEND);
710 if (!(ret = t_fcntl(fd, F_GETFL)) & O_APPEND) {
711 printf("error get flag: ret %x\n", ret);
715 t_fcntl(fd, F_SETLK, &lock);
716 t_fcntl(fd, F_GETLK, &lock);
717 lock.l_type = F_WRLCK;
718 t_fcntl(fd, F_SETLKW, &lock);
719 t_fcntl(fd, F_GETLK, &lock);
720 lock.l_type = F_UNLCK;
721 t_fcntl(fd, F_SETLK, &lock);
730 char file[MAX_PATH_LENGTH] = "";
732 char *str = "1234567890";
735 ENTER("make sure O_APPEND take effect");
736 snprintf(file, MAX_PATH_LENGTH, "%s/test_t22_file", lustre_path);
738 fd = open(file, O_TRUNC|O_RDWR|O_CREAT|O_APPEND, (mode_t)0666);
740 printf("error open file: %s\n", strerror(errno));
744 lseek(fd, 100, SEEK_SET);
745 ret = write(fd, str, strlen(str));
746 if (ret != strlen(str)) {
747 printf("write 1: ret %lld, errno %d\n", (long long)ret, errno);
751 lseek(fd, 0, SEEK_SET);
752 ret = read(fd, buf, sizeof(buf));
753 if (ret != strlen(str)) {
754 printf("read 1: ret %lld\n", (long long)ret);
758 if (memcmp(buf, str, strlen(str))) {
759 printf("read 1 data err\n");
763 if (fcntl(fd, F_SETFL, 0)) {
764 printf("fcntl err: %s\n", strerror(errno));
768 lseek(fd, 100, SEEK_SET);
769 ret = write(fd, str, strlen(str));
770 if (ret != strlen(str)) {
771 printf("write 2: ret %lld, errno %d\n", (long long)ret, errno);
775 lseek(fd, 100, SEEK_SET);
776 ret = read(fd, buf, sizeof(buf));
777 if (ret != strlen(str)) {
778 printf("read 2: ret %lld\n", (long long)ret);
782 if (memcmp(buf, str, strlen(str))) {
783 printf("read 2 data err\n");
794 char path[MAX_PATH_LENGTH];
799 ENTER("handle seek > 2GB");
800 snprintf(path, MAX_PATH_LENGTH, "%s/f%s", lustre_path, name);
802 fd = open(path, O_WRONLY | O_CREAT | O_LARGEFILE, 0666);
804 printf("failed to create file %s: %s\n", path, strerror(errno));
808 off = 2048ULL * 1024 * 1024 - buf_size / 2;
809 ret = lseek(fd, off, SEEK_SET);
811 printf("seek error for initial %llu != %llu\n",
812 ret, (long long)off);
816 ret = write(fd, buf_alloc, buf_size);
817 if (ret != buf_size) {
818 printf("write error for %d != %llubytes @ %llu\n",
819 buf_size, ret, (long long)off);
825 ret = lseek(fd, off, SEEK_SET);
827 printf("seek < 2GB error for %llu != %llu\n",
828 ret, (long long)off);
830 perror("seek < 2GB");
834 ret = lseek(fd, off + buf_size - 2, SEEK_SET);
835 if (ret != off + buf_size - 2) {
836 printf("seek > 2GB error for %llu != %llu\n",
837 ret, (long long)off);
839 perror("seek > 2GB");
843 ret = lseek(fd, -buf_size + 2, SEEK_CUR);
845 printf("relative seek error for %d %llu != %llu\n",
846 -buf_size + 2, ret, (unsigned long long) off);
848 perror("relative seek");
852 ret = lseek(fd, 0, SEEK_END);
853 if (ret != off + buf_size) {
854 printf("end seek error for %llu != %llu\n",
855 ret, (long long)off + buf_size);
861 ret = lseek(fd, 0, SEEK_SET);
863 printf("seek 0 error for %llu != 0\n", ret);
869 off = 2048ULL * 1024 * 1024, SEEK_SET;
870 ret = lseek(fd, off, SEEK_SET);
872 printf("seek 2GB error for %llu != %llu\n", ret, (unsigned long long) off);
883 /* pos: i/o start from
884 * xfer: npages per transfer
886 static int pages_io(int xfer, loff_t pos)
888 char path[MAX_PATH_LENGTH] = "";
890 int check_sum[_npages] = {0,}, *buf;
891 int fd, rc, i, j, data_error = 0;
892 struct timeval tw1, tw2, tr1, tr2;
896 snprintf(path, MAX_PATH_LENGTH, "%s/test_t50", lustre_path);
898 memset(buf_alloc, 0, buf_size);
900 /* create sample data */
901 for (i = 0, buf = buf_alloc; i < _npages; i++) {
902 for (j = 0; j < CFS_PAGE_SIZE/sizeof(int); j++, buf++) {
907 /* compute checksum */
908 for (i = 0, buf = buf_alloc; i < _npages; i++) {
909 for (j = 0; j < CFS_PAGE_SIZE/sizeof(int); j++, buf++) {
910 check_sum[i] += *buf;
920 ret = lseek(fd, pos, SEEK_SET);
922 perror("write seek");
925 gettimeofday(&tw1, NULL);
926 for (i = 0, buf = buf_alloc; i < _npages;
927 i += xfer, buf += xfer * CFS_PAGE_SIZE / sizeof(int)) {
928 rc = write(fd, buf, CFS_PAGE_SIZE * xfer);
929 if (rc != CFS_PAGE_SIZE * xfer) {
930 printf("write error (i %d, rc %d): %s\n", i, rc,
935 gettimeofday(&tw2, NULL);
937 memset(buf_alloc, 0, buf_size);
940 ret = lseek(fd, pos, SEEK_SET);
945 gettimeofday(&tr1, NULL);
946 for (i = 0, buf = buf_alloc; i < _npages;
947 i += xfer, buf += xfer * CFS_PAGE_SIZE / sizeof(int)) {
948 rc = read(fd, buf, CFS_PAGE_SIZE * xfer);
949 if (rc != CFS_PAGE_SIZE * xfer) {
950 printf("read error (i %d, rc %d): %s\n", i, rc,
955 gettimeofday(&tr2, NULL);
957 /* compute checksum */
958 for (i = 0, buf = buf_alloc; i < _npages; i++) {
960 for (j = 0; j < CFS_PAGE_SIZE/sizeof(int); j++, buf++) {
963 if (sum != check_sum[i]) {
965 printf("chunk %d checksum error expected %#x got %#x\n",
966 i, check_sum[i], sum);
972 tw = (tw2.tv_sec - tw1.tv_sec) * 1000000 + (tw2.tv_usec - tw1.tv_usec);
973 tr = (tr2.tv_sec - tr1.tv_sec) * 1000000 + (tr2.tv_usec - tr1.tv_usec);
974 printf(" (R:%.3fM/s, W:%.3fM/s)\n",
975 (_npages * CFS_PAGE_SIZE) / (tw / 1000000.0) / (1024 * 1024),
976 (_npages * CFS_PAGE_SIZE) / (tr / 1000000.0) / (1024 * 1024));
989 ENTER("4k aligned i/o sanity");
990 while (np <= _npages) {
991 printf("%3d per xfer(total %d)...\t", np, _npages);
993 if (pages_io(np, offset) != 0)
1000 int t50b(char *name)
1002 loff_t off_array[] = {1, 17, 255, 258, 4095, 4097, 8191,
1003 1024*1024*1024*1024ULL};
1007 ENTER("4k un-aligned i/o sanity");
1008 for (i = 0; i < sizeof(off_array)/sizeof(loff_t); i++) {
1009 offset = off_array[i];
1010 printf("16 per xfer(total %d), offset %10lld...\t",
1012 if (pages_io(16, offset) != 0)
1025 * truncate(2) checks.
1029 char file[MAX_PATH_LENGTH] = "";
1034 ENTER("truncate() should truncate file to proper length");
1035 snprintf(file, MAX_PATH_LENGTH, "%s/test_t51_file", lustre_path);
1037 for (size = 0; size < T51_NR * T51_STEP; size += T51_STEP) {
1038 t_echo_create(file, "");
1039 if (truncate(file, size) != 0) {
1040 printf("\nerror truncating file: %s\n",strerror(errno));
1043 result = check_file_size(file, size);
1048 t_echo_create(file, "");
1049 fd = open(file, O_RDWR|O_CREAT, (mode_t)0666);
1051 printf("\nerror open file: %s\n", strerror(errno));
1054 if (ftruncate(fd, size) != 0) {
1055 printf("\nerror ftruncating file:%s\n",strerror(errno));
1059 result = check_file_size(file, size);
1063 if (size % (T51_STEP * (T51_NR / 75)) == 0) {
1072 * check atime update during read
1076 char file[MAX_PATH_LENGTH] = "";
1078 struct stat statbuf;
1083 ENTER("atime should be updated during read");
1084 snprintf(file, MAX_PATH_LENGTH, "%s/test_t52_file", lustre_path);
1086 t_echo_create(file, "check atime update during read");
1087 fd = open(file, O_RDONLY);
1089 printf("\nerror open file: %s\n", strerror(errno));
1092 stat(file, &statbuf);
1093 printf("st_atime=%s", ctime(&statbuf.st_atime));
1094 atime = statbuf.st_atime;
1095 for (i = 0; i < 3; i++) {
1098 /* should not ignore read(2)'s return value */
1099 num_read = read(fd, buf, sizeof(buf));
1100 if (num_read < 0 ) {
1101 printf("read from %s: %s\n", file, strerror(errno));
1104 stat(file, &statbuf);
1105 printf("st_atime=%s", ctime(&statbuf.st_atime));
1106 diff = statbuf.st_atime - atime;
1108 printf("atime doesn't updated! failed!\n");
1113 atime = statbuf.st_atime;
1120 #define NEW_TIME 10000
1123 char file[MAX_PATH_LENGTH] = "";
1124 struct utimbuf times; /* struct. buffer for utime() */
1125 struct stat stat_buf; /* struct buffer to hold file info. */
1126 time_t mtime, atime;
1128 ENTER("mtime/atime should be updated by utime() call");
1129 snprintf(file, MAX_PATH_LENGTH, "%s/test_t53_file", lustre_path);
1131 t_echo_create(file, "check mtime/atime update by utime() call");
1133 /* Initialize the modification and access time in the times arg */
1134 times.actime = NEW_TIME+10;
1135 times.modtime = NEW_TIME;
1137 /* file modification/access time */
1138 utime(file, ×);
1140 if (stat(file, &stat_buf) < 0) {
1141 printf("stat(2) of %s failed, error:%d %s\n",
1142 file, errno, strerror(errno));
1144 mtime = stat_buf.st_mtime;
1145 atime = stat_buf.st_atime;
1147 if ((mtime == NEW_TIME) && (atime == NEW_TIME + 10)) {
1152 printf("mod time %ld, expected %ld\n", mtime, (long)NEW_TIME);
1153 printf("acc time %ld, expected %ld\n", atime, (long)NEW_TIME + 10);
1161 char file[MAX_PATH_LENGTH] = "";
1165 ENTER("fcntl should return 0 when succeed in getting flock");
1166 snprintf(file, MAX_PATH_LENGTH, "%s/test_t54_file", lustre_path);
1168 t_echo_create(file, "fcntl should return 0 when succeed");
1170 fd = open(file, O_RDWR);
1172 printf("\nerror open file: %s\n", strerror(errno));
1175 lock.l_type = F_WRLCK;
1179 if ((err = t_fcntl(fd, F_SETLKW, &lock)) != 0) {
1180 fprintf(stderr, "fcntl returned: %d (%s)\n",
1181 err, strerror(err));
1187 lock.l_type = F_UNLCK;
1188 t_fcntl(fd, F_SETLKW, &lock);
1194 /* for O_DIRECTORY */
1199 #define STRIPE_SIZE (2048 * 2048)
1200 #define STRIPE_OFFSET 0
1201 #define STRIPE_COUNT 1
1204 char path[MAX_PATH_LENGTH] = "";
1205 char file[MAX_PATH_LENGTH] = "";
1206 struct lov_user_md *lum = NULL;
1207 struct lov_user_ost_data *lo = NULL;
1208 int index, fd, buflen, rc;
1210 ENTER("setstripe/getstripe");
1211 snprintf(path, MAX_PATH_LENGTH, "%s/test_t55", lustre_path);
1212 snprintf(file, MAX_PATH_LENGTH, "%s/test_t55/file_t55", lustre_path);
1214 buflen = sizeof(struct lov_user_md);
1215 buflen += STRIPE_COUNT * sizeof(struct lov_user_ost_data);
1216 lum = (struct lov_user_md *)malloc(buflen);
1218 printf("out of memory!\n");
1221 memset(lum, 0, buflen);
1224 rc = llapi_file_create(path, STRIPE_SIZE, STRIPE_OFFSET,
1225 STRIPE_COUNT, LOV_PATTERN_RAID0);
1227 printf("llapi_file_create failed: rc = %d (%s) \n",
1234 fd = open(file, O_CREAT | O_RDWR, 0644);
1236 printf("open file(%s) failed: rc = %d (%s) \n)",
1237 file, fd, strerror(errno));
1243 lum->lmm_magic = LOV_USER_MAGIC;
1244 lum->lmm_stripe_count = STRIPE_COUNT;
1245 rc = ioctl(fd, LL_IOC_LOV_GETSTRIPE, lum);
1247 printf("dir:ioctl(LL_IOC_LOV_GETSTRIPE) failed: rc = %d(%s)\n",
1248 rc, strerror(errno));
1259 printf("lmm_magic: 0x%08X\n", lum->lmm_magic);
1260 printf("lmm_object_id: "LPX64"\n", lum->lmm_object_id);
1261 printf("lmm_object_gr: "LPX64"\n", lum->lmm_object_gr);
1262 printf("lmm_stripe_count: %u\n", (int)lum->lmm_stripe_count);
1263 printf("lmm_stripe_size: %u\n", lum->lmm_stripe_size);
1264 printf("lmm_stripe_pattern: %x\n", lum->lmm_pattern);
1266 for (index = 0; index < lum->lmm_stripe_count; index++) {
1267 lo = lum->lmm_objects + index;
1268 printf("object %d:\n", index);
1269 printf("\tobject_gr: "LPX64"\n", lo->l_object_gr);
1270 printf("\tobject_id: "LPX64"\n", lo->l_object_id);
1271 printf("\tost_gen: %#x\n", lo->l_ost_gen);
1272 printf("\tost_idx: %u\n", lo->l_ost_idx);
1276 if (lum->lmm_magic != LOV_USER_MAGIC ||
1277 lum->lmm_pattern != LOV_PATTERN_RAID0 ||
1278 lum->lmm_stripe_size != STRIPE_SIZE ||
1279 lum->lmm_objects[0].l_ost_idx != STRIPE_OFFSET ||
1280 lum->lmm_stripe_count != STRIPE_COUNT) {
1281 printf("incorrect striping information!\n");
1289 /* setstripe on regular file */
1290 rc = llapi_file_create(file, STRIPE_SIZE, STRIPE_OFFSET,
1291 STRIPE_COUNT, LOV_PATTERN_RAID0);
1293 printf("llapi_file_create failed: rc = %d (%s) \n",
1300 fd = open(file, O_RDWR, 0644);
1302 printf("failed to open(%s): rc = %d (%s)\n",
1303 file, fd, strerror(errno));
1310 lum->lmm_magic = LOV_USER_MAGIC;
1311 lum->lmm_stripe_count = STRIPE_COUNT;
1312 rc = ioctl(fd, LL_IOC_LOV_GETSTRIPE, lum);
1314 printf("file:ioctl(LL_IOC_LOV_GETSTRIPE) failed: rc = %d(%s)\n",
1315 rc, strerror(errno));
1325 printf("lmm_magic: 0x%08X\n", lum->lmm_magic);
1326 printf("lmm_object_id: "LPX64"\n", lum->lmm_object_id);
1327 printf("lmm_object_gr: "LPX64"\n", lum->lmm_object_gr);
1328 printf("lmm_stripe_count: %u\n", (int)lum->lmm_stripe_count);
1329 printf("lmm_stripe_size: %u\n", lum->lmm_stripe_size);
1330 printf("lmm_stripe_pattern: %x\n", lum->lmm_pattern);
1332 for (index = 0; index < lum->lmm_stripe_count; index++) {
1333 lo = lum->lmm_objects + index;
1334 printf("object %d:\n", index);
1335 printf("\tobject_gr: "LPX64"\n", lo->l_object_gr);
1336 printf("\tobject_id: "LPX64"\n", lo->l_object_id);
1337 printf("\tost_gen: %#x\n", lo->l_ost_gen);
1338 printf("\tost_idx: %u\n", lo->l_ost_idx);
1342 if (lum->lmm_magic != LOV_USER_MAGIC ||
1343 lum->lmm_pattern != LOV_PATTERN_RAID0 ||
1344 lum->lmm_stripe_size != STRIPE_SIZE ||
1345 lum->lmm_objects[0].l_ost_idx != STRIPE_OFFSET ||
1346 lum->lmm_stripe_count != STRIPE_COUNT) {
1347 printf("incorrect striping information!\n");
1361 * getdirentries should return -1 and set errno to EINVAL when the size
1362 * specified as an argument is too small to contain at least one entry
1363 * (see bugzilla ticket 12229)
1373 ENTER("getdirentries should fail if nbytes is too small");
1375 /* Set count to be very small. The result should be EINVAL */
1378 /* open the directory and call getdirentries */
1379 fd = t_opendir(lustre_path);
1381 rc = getdirentries(fd, (char *)&dir, nbytes, &basep);
1384 printf("Test failed: getdirentries returned %lld\n",
1389 if (errno != EINVAL) {
1390 printf("Test failed: getdirentries returned %lld but errno is "
1391 "set to %d (should be EINVAL)\n", (long long)rc, errno);
1400 extern void __liblustre_setup_(void);
1401 extern void __liblustre_cleanup_(void);
1404 void usage(char *cmd)
1407 "usage: %s [-o test][-e test][-v] --target mgsnid:/fsname\n",
1409 printf(" %s --dumpfile dumpfile\n", cmd);
1414 int (*test)(char *name);
1451 int main(int argc, char * const argv[])
1453 struct testlist *test;
1454 int opt_index, c, rc = 0, numonly = 0, numexcept = 0;
1455 char *only[100], *except[100];
1456 static struct option long_opts[] = {
1457 {"dumpfile", 1, 0, 'd'},
1458 {"only", 1, 0, 'o'},
1459 {"except", 1, 0, 'e'},
1460 {"target", 1, 0, 't'},
1461 {"verbose", 1, 0, 'v'},
1465 while ((c = getopt_long(argc, argv, "d:e:o:t:v", long_opts, &opt_index)) != -1) {
1468 setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);
1472 printf("Not running test(s): ");
1473 printf("%s ", optarg);
1474 except[numexcept++] = optarg;
1478 printf("Only running test(s): ");
1479 printf("%s ", optarg);
1480 only[numonly++] = optarg;
1483 setenv(ENV_LUSTRE_MNTTGT, optarg, 1);
1494 if (getenv(ENV_LUSTRE_MNTTGT) == NULL &&
1495 getenv(ENV_LUSTRE_DUMPFILE) == NULL)
1503 __liblustre_setup_();
1505 buf_size = _npages * CFS_PAGE_SIZE;
1507 printf("allocating %d bytes buffer\n", buf_size);
1508 buf_alloc = calloc(1, buf_size);
1509 if (buf_alloc == NULL) {
1510 fprintf(stderr, "error allocating %d\n", buf_size);
1514 for (test = testlist; test->test != NULL; test++) {
1518 if (numexcept > 0) {
1519 len = strlen(test->name);
1520 for (i = 0; i < numexcept; i++) {
1521 olen = strlen(except[i]);
1526 if (strncmp(except[i], test->name, olen) == 0) {
1527 switch(test->name[olen]) {
1528 case '0': case '1': case '2': case '3':
1529 case '4': case '5': case '6': case '7':
1542 len = strlen(test->name);
1543 for (i = 0; i < numonly; i++) {
1544 olen = strlen(only[i]);
1549 if (strncmp(only[i], test->name, olen) == 0) {
1550 switch(test->name[olen]) {
1551 case '0': case '1': case '2': case '3':
1552 case '4': case '5': case '6': case '7':
1562 if (run && (rc = (test->test)(test->name)) != 0)
1568 printf("liblustre is about to shutdown\n");
1569 __liblustre_cleanup_();
1571 printf("complete successfully\n");