📄 sanity.c
字号:
return(1); } if (memcmp(buf, str, strlen(str))) { printf("read 2 data err\n"); return(1); } close(fd); t_unlink(file); LEAVE();}int t23(char *name){ char path[MAX_PATH_LENGTH]; int fd; long long ret; loff_t off; ENTRY("handle seek > 2GB"); snprintf(path, MAX_PATH_LENGTH, "%s/f%s", lustre_path, name); fd = open(path, O_WRONLY | O_CREAT | O_LARGEFILE, 0666); if (fd < 0) { printf("failed to create file %s: %s\n", path, strerror(errno)); return(-1); } off = 2048ULL * 1024 * 1024 - buf_size / 2; ret = lseek(fd, off, SEEK_SET); if (ret != off) { printf("seek error for initial %llu != %llu\n", ret, (long long)off); return -1; } ret = write(fd, buf_alloc, buf_size); if (ret != buf_size) { printf("write error for %d != %llubytes @ %llu\n", buf_size, ret, (long long)off); if (ret == -1) perror("write"); return -1; } ret = lseek(fd, off, SEEK_SET); if (ret != off) { printf("seek < 2GB error for %llu != %llu\n", ret, (long long)off); if (ret == -1) perror("seek < 2GB"); return -1; } ret = lseek(fd, off + buf_size - 2, SEEK_SET); if (ret != off + buf_size - 2) { printf("seek > 2GB error for %llu != %llu\n", ret, (long long)off); if (ret == -1) perror("seek > 2GB"); return -1; } ret = lseek(fd, -buf_size + 2, SEEK_CUR); if (ret != off) { printf("relative seek error for %d %llu != %llu\n", -buf_size + 2, ret, (unsigned long long) off); if (ret == -1) perror("relative seek"); return -1; } ret = lseek(fd, 0, SEEK_END); if (ret != off + buf_size) { printf("end seek error for %llu != %llu\n", ret, (long long)off + buf_size); if (ret == -1) perror("end seek"); return -1; } ret = lseek(fd, 0, SEEK_SET); if (ret != 0) { printf("seek 0 error for %llu != 0\n", ret); if (ret == -1) perror("seek 0"); return -1; } off = 2048ULL * 1024 * 1024, SEEK_SET; ret = lseek(fd, off, SEEK_SET); if (ret != off) { printf("seek 2GB error for %llu != %llu\n", ret, (unsigned long long) off); if (ret == -1) perror("seek 2GB"); return -1; } close(fd); t_unlink(path); LEAVE();}/* pos: i/o start from * xfer: npages per transfer */static int pages_io(int xfer, loff_t pos){ char path[MAX_PATH_LENGTH] = ""; int check_sum[_npages] = {0,}, *buf; int fd, rc, i, j, data_error = 0; struct timeval tw1, tw2, tr1, tr2; double tw, tr; loff_t ret; snprintf(path, MAX_PATH_LENGTH, "%s/test_t50", lustre_path); memset(buf_alloc, 0, buf_size); /* create sample data */ for (i = 0, buf = buf_alloc; i < _npages; i++) { for (j = 0; j < PAGE_SIZE/sizeof(int); j++, buf++) { *buf = rand(); } } /* compute checksum */ for (i = 0, buf = buf_alloc; i < _npages; i++) { for (j = 0; j < PAGE_SIZE/sizeof(int); j++, buf++) { check_sum[i] += *buf; } } unlink(path); t_touch(path); fd = t_open(path); /* write */ ret = lseek(fd, pos, SEEK_SET); if (ret != pos) { perror("write seek"); return 1; } gettimeofday(&tw1, NULL); for (i = 0, buf = buf_alloc; i < _npages; i += xfer, buf += xfer * PAGE_SIZE / sizeof(int)) { rc = write(fd, buf, PAGE_SIZE * xfer); if (rc != PAGE_SIZE * xfer) { printf("write error (i %d, rc %d): %s\n", i, rc, strerror(errno)); return(1); } } gettimeofday(&tw2, NULL); memset(buf_alloc, 0, buf_size); /* read */ ret = lseek(fd, pos, SEEK_SET); if (ret != pos) { perror("read seek"); return 1; } gettimeofday(&tr1, NULL); for (i = 0, buf = buf_alloc; i < _npages; i += xfer, buf += xfer * PAGE_SIZE / sizeof(int)) { rc = read(fd, buf, PAGE_SIZE * xfer); if (rc != PAGE_SIZE * xfer) { printf("read error (i %d, rc %d): %s\n", i, rc, strerror(errno)); return(1); } } gettimeofday(&tr2, NULL); /* compute checksum */ for (i = 0, buf = buf_alloc; i < _npages; i++) { int sum = 0; for (j = 0; j < PAGE_SIZE/sizeof(int); j++, buf++) { sum += *buf; } if (sum != check_sum[i]) { data_error = 1; printf("chunk %d checksum error expected %#x got %#x\n", i, check_sum[i], sum); } } t_close(fd); t_unlink(path); tw = (tw2.tv_sec - tw1.tv_sec) * 1000000 + (tw2.tv_usec - tw1.tv_usec); tr = (tr2.tv_sec - tr1.tv_sec) * 1000000 + (tr2.tv_usec - tr1.tv_usec); printf(" (R:%.3fM/s, W:%.3fM/s)\n", (_npages * PAGE_SIZE) / (tw / 1000000.0) / (1024 * 1024), (_npages * PAGE_SIZE) / (tr / 1000000.0) / (1024 * 1024)); if (data_error) return 1; return 0;}int t50(char *name){ int np = 1; loff_t offset = 0; ENTRY("4k aligned i/o sanity"); while (np <= _npages) { printf("%3d per xfer(total %d)...\t", np, _npages); fflush(stdout); if (pages_io(np, offset) != 0) return 1; np += np; } LEAVE();}int t50b(char *name){ loff_t off_array[] = {1, 17, 255, 258, 4095, 4097, 8191, 1024*1024*1024*1024ULL}; int i; loff_t offset; ENTRY("4k un-aligned i/o sanity"); for (i = 0; i < sizeof(off_array)/sizeof(loff_t); i++) { offset = off_array[i]; printf("16 per xfer(total %d), offset %10lld...\t", _npages, (unsigned long long) offset); if (pages_io(16, offset) != 0) return 1; } LEAVE();}enum { T51_STEP = 42, T51_NR = 1000};/* * truncate(2) checks. */int t51(char *name){ char file[MAX_PATH_LENGTH] = ""; int fd; off_t size; int result; ENTRY("truncate() should truncate file to proper length"); snprintf(file, MAX_PATH_LENGTH, "%s/test_t51_file", lustre_path); for (size = 0; size < T51_NR * T51_STEP; size += T51_STEP) { t_echo_create(file, ""); if (truncate(file, size) != 0) { printf("\nerror truncating file: %s\n",strerror(errno)); return(-1); } result = check_file_size(file, size); if (result != 0) return result; t_unlink(file); t_echo_create(file, ""); fd = open(file, O_RDWR|O_CREAT, (mode_t)0666); if (fd < 0) { printf("\nerror open file: %s\n", strerror(errno)); return(-1); } if (ftruncate(fd, size) != 0) { printf("\nerror ftruncating file:%s\n",strerror(errno)); return(-1); } close(fd); result = check_file_size(file, size); if (result != 0) return result; t_unlink(file); if (size % (T51_STEP * (T51_NR / 75)) == 0) { printf("."); fflush(stdout); } } printf("\n"); LEAVE();}/* * check atime update during read */int t52(char *name){ char file[MAX_PATH_LENGTH] = ""; char buf[16]; struct stat statbuf; time_t atime; time_t diff; int fd, i; ENTRY("atime should be updated during read"); snprintf(file, MAX_PATH_LENGTH, "%s/test_t52_file", lustre_path); t_echo_create(file, "check atime update during read"); fd = open(file, O_RDONLY); if (fd < 0) { printf("\nerror open file: %s\n", strerror(errno)); return(-1); } stat(file, &statbuf); printf("st_atime=%s", ctime(&statbuf.st_atime)); atime = statbuf.st_atime; for (i = 0; i < 3; i++) { sleep(2); read(fd, buf, sizeof(buf)); stat(file, &statbuf); printf("st_atime=%s", ctime(&statbuf.st_atime)); diff = statbuf.st_atime - atime; if (diff <= 0) { printf("atime doesn't updated! failed!\n"); close(fd); t_unlink(file); return -1; } atime = statbuf.st_atime; } close(fd); t_unlink(file); LEAVE();}#define NEW_TIME 10000int t53(char *name){ char file[MAX_PATH_LENGTH] = ""; struct utimbuf times; /* struct. buffer for utime() */ struct stat stat_buf; /* struct buffer to hold file info. */ time_t mtime, atime; ENTRY("mtime/atime should be updated by utime() call"); snprintf(file, MAX_PATH_LENGTH, "%s/test_t53_file", lustre_path); t_echo_create(file, "check mtime/atime update by utime() call"); /* Initialize the modification and access time in the times arg */ times.actime = NEW_TIME+10; times.modtime = NEW_TIME; /* file modification/access time */ utime(file, ×); if (stat(file, &stat_buf) < 0) { printf("stat(2) of %s failed, error:%d %s\n", file, errno, strerror(errno)); } mtime = stat_buf.st_mtime; atime = stat_buf.st_atime; if ((mtime == NEW_TIME) && (atime == NEW_TIME + 10)) { t_unlink(file); LEAVE(); } printf("mod time %ld, expected %ld\n", mtime, (long)NEW_TIME); printf("acc time %ld, expected %ld\n", atime, (long)NEW_TIME + 10); t_unlink(file); return (-1);}int t54(char *name){ char file[MAX_PATH_LENGTH] = ""; struct flock lock; int fd, err; ENTRY("fcntl should return 0 when succeed in getting flock");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -