int t8(char *name) { char path[MAX_PATH_LENGTH] = ""; ENTER("chmod"); snprintf(path, MAX_PATH_LENGTH, "%s/test_t8", lustre_path); /* Check file. */ t_touch(path); t_chmod_raw(path, 0700); t_check_stat(path, NULL); t_unlink(path); /* Check dir. */ t_mkdir(path); t_chmod_raw(path, 0700); t_check_stat(path, NULL); t_rmdir(path); LEAVE(); }
int t7(char *name) { char path[MAX_PATH_LENGTH] = ""; int rc; ENTER("mknod"); snprintf(path, MAX_PATH_LENGTH, "%s/test_t7", lustre_path); if (geteuid() != 0) { rc = mknod(path, S_IFCHR | 0644, (5<<8 | 4)); if (rc != -1 || errno != EPERM) { printf("mknod shouldn't success: rc %d, errno %d\n", rc, errno); } } else { t_mknod(path, S_IFCHR | 0644, 5, 4); t_check_stat(path, NULL); t_unlink(path); } LEAVE(); }
int t19(char *name) { char file[MAX_PATH_LENGTH] = ""; int fd; int result; ENTER("open(O_TRUNC) should truncate file to 0-length"); snprintf(file, MAX_PATH_LENGTH, "%s/test_t19_file", lustre_path); t_echo_create(file, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); fd = open(file, O_RDWR|O_CREAT|O_TRUNC, (mode_t)0666); if (fd < 0) { printf("error open file: %s\n", strerror(errno)); return(-1); } close(fd); result = check_file_size(file, 0); if (result != 0) return result; t_unlink(file); LEAVE(); }
int t18(char *name) { char file[MAX_PATH_LENGTH] = ""; char buf[128]; int fd, i; struct stat statbuf[3]; ENTER("write should change mtime/ctime"); snprintf(file, MAX_PATH_LENGTH, "%s/test_t18_file", lustre_path); for (i = 0; i < 3; i++) { fd = open(file, O_RDWR|O_CREAT|O_APPEND, (mode_t)0666); if (fd < 0) { printf("error open file: %s\n", strerror(errno)); return(-1); } if (write(fd, buf, sizeof(buf)) != sizeof(buf)) { printf("error write file\n"); return(-1); } close(fd); if(stat(file, &statbuf[i]) != 0) { printf("Error stat\n"); return(1); } printf("ctime %lu, mtime %lu\n", statbuf[i].st_ctime, statbuf[i].st_mtime); sleep(2); } for (i = 1; i < 3; i++) { if ((statbuf[i].st_ctime <= statbuf[i-1].st_ctime) || (statbuf[i].st_mtime <= statbuf[i-1].st_mtime)) { printf("time error\n"); return(-1); } } t_unlink(file); LEAVE(); }
void t4() { char *dir="/mnt/lustre/d4"; char *path="/mnt/lustre/d4/f1"; ENTRY("mkdir + contained create"); replay_barrier(); t_mkdir(dir); t_create(path); mds_failover(); t_check_stat(dir, NULL); t_check_stat(path, NULL); sleep(2); /* wait for log process thread */ replay_barrier(); t_unlink(path); t_rmdir(dir); mds_failover(); t_check_stat_fail(dir); t_check_stat_fail(path); LEAVE(); }
int t21(char *name) { char file[MAX_PATH_LENGTH] = ""; int fd, ret; struct flock lock = { .l_type = F_RDLCK, .l_whence = SEEK_SET, }; ENTER("basic fcntl support"); snprintf(file, MAX_PATH_LENGTH, "%s/test_t21_file", lustre_path); fd = open(file, O_RDWR|O_CREAT, (mode_t)0666); if (fd < 0) { printf("error open file: %s\n", file); return(-1); } t_fcntl(fd, F_SETFL, O_APPEND); ret = t_fcntl(fd, F_GETFL); if ((ret & O_APPEND) == 0) { printf("error get flag: ret %o\n", ret); return(-1); } t_fcntl(fd, F_SETLK, &lock); t_fcntl(fd, F_GETLK, &lock); lock.l_type = F_WRLCK; t_fcntl(fd, F_SETLKW, &lock); t_fcntl(fd, F_GETLK, &lock); lock.l_type = F_UNLCK; t_fcntl(fd, F_SETLK, &lock); close(fd); t_unlink(file); LEAVE(); }
int op_unlink(const int extra_flag) { // 当前大文件不支持undelete int ret = TFS_ERROR; int64_t file_size = 0; file_size = 0; // conceal ret = t_unlink(tfs_name, NULL, &file_size, CONCEAL); if (ret != TFS_SUCCESS) { printf("conceal file fail, ret: %d\n", ret); return ret; } else { printf("conceal file size : %" PRI64_PREFIX "d\n", file_size); } file_size = 0; // reveal ret = t_unlink(tfs_name, NULL, &file_size, REVEAL); if (ret != TFS_SUCCESS) { printf("reveal file fail, ret: %d\n", ret); return ret; } else { printf("reveal file size : %" PRI64_PREFIX "d\n", file_size); } file_size = 0; // conceal ret = t_unlink(tfs_name, NULL, &file_size, CONCEAL); if (ret != TFS_SUCCESS) { printf("conceal file fail, ret: %d\n", ret); return ret; } else { printf("conceal file size : %" PRI64_PREFIX "d\n", file_size); } file_size = 0; // delete ret = t_unlink(tfs_name, NULL, &file_size, DELETE); if (ret != TFS_SUCCESS) { printf("delete file fail, ret: %d\n", ret); return ret; } else { printf("delete file size : %" PRI64_PREFIX "d\n", file_size); } // undelete if (extra_flag != T_LARGE) { file_size = 0; ret = t_unlink(tfs_name, NULL, &file_size, UNDELETE); if(ret != TFS_SUCCESS) { printf("undelete file fail,, ret: %d\n", ret); return ret; } else { printf("undelete file size : %" PRI64_PREFIX "d\n", file_size); } } return TFS_SUCCESS; }
/* 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 < CFS_PAGE_SIZE/sizeof(int); j++, buf++) { *buf = rand(); } } /* compute checksum */ for (i = 0, buf = buf_alloc; i < _npages; i++) { for (j = 0; j < CFS_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 * CFS_PAGE_SIZE / sizeof(int)) { rc = write(fd, buf, CFS_PAGE_SIZE * xfer); if (rc != CFS_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 * CFS_PAGE_SIZE / sizeof(int)) { rc = read(fd, buf, CFS_PAGE_SIZE * xfer); if (rc != CFS_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 < CFS_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 * CFS_PAGE_SIZE) / (tw / 1000000.0) / (1024 * 1024), (_npages * CFS_PAGE_SIZE) / (tr / 1000000.0) / (1024 * 1024)); if (data_error) return 1; return 0; }
int t23(char *name) { char path[MAX_PATH_LENGTH]; int fd; long long ret; loff_t off; ENTER("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(); }
int t22(char *name) { char file[MAX_PATH_LENGTH] = ""; int fd; char *str = "1234567890"; char buf[100]; long ret; ENTER("make sure O_APPEND take effect"); snprintf(file, MAX_PATH_LENGTH, "%s/test_t22_file", lustre_path); fd = open(file, O_TRUNC|O_RDWR|O_CREAT|O_APPEND, (mode_t)0666); if (fd < 0) { printf("error open file: %s\n", strerror(errno)); return(-1); } lseek(fd, 100, SEEK_SET); ret = write(fd, str, strlen(str)); if (ret != strlen(str)) { printf("write 1: ret %lld, errno %d\n", (long long)ret, errno); return(1); } lseek(fd, 0, SEEK_SET); ret = read(fd, buf, sizeof(buf)); if (ret != strlen(str)) { printf("read 1: ret %lld\n", (long long)ret); return(1); } if (memcmp(buf, str, strlen(str))) { printf("read 1 data err\n"); return(1); } if (fcntl(fd, F_SETFL, 0)) { printf("fcntl err: %s\n", strerror(errno)); return(1); } lseek(fd, 100, SEEK_SET); ret = write(fd, str, strlen(str)); if (ret != strlen(str)) { printf("write 2: ret %lld, errno %d\n", (long long)ret, errno); return(1); } lseek(fd, 100, SEEK_SET); ret = read(fd, buf, sizeof(buf)); if (ret != strlen(str)) { printf("read 2: ret %lld\n", (long long)ret); return(1); } if (memcmp(buf, str, strlen(str))) { printf("read 2 data err\n"); return(1); } close(fd); t_unlink(file); LEAVE(); }
int t20(char *name) { char file[MAX_PATH_LENGTH] = ""; int fd; struct iovec iov[2]; char buf[100]; long ret; ENTER("trap app's general bad pointer for file i/o"); snprintf(file, MAX_PATH_LENGTH, "%s/test_t20_file", lustre_path); fd = open(file, O_RDWR|O_CREAT, (mode_t)0666); if (fd < 0) { printf("error open file: %s\n", strerror(errno)); return(-1); } ret = write(fd, NULL, 20); if (ret != -1 || errno != EFAULT) { printf("write 1: ret %lld, errno %d\n", (long long)ret, errno); return(1); } ret = write(fd, (void *)-1, 20); if (ret != -1 || errno != EFAULT) { printf("write 2: ret %lld, errno %d\n", (long long)ret, errno); return(1); } iov[0].iov_base = NULL; iov[0].iov_len = 10; iov[1].iov_base = (void *)-1; iov[1].iov_len = 10; ret = writev(fd, iov, 2); if (ret != -1 || errno != EFAULT) { printf("writev 1: ret %lld, errno %d\n", (long long)ret, errno); return(1); } iov[0].iov_base = NULL; iov[0].iov_len = 0; iov[1].iov_base = buf; iov[1].iov_len = sizeof(buf); ret = writev(fd, iov, 2); if (ret != sizeof(buf)) { printf("writev 2: ret %lld, error %d\n", (long long)ret, errno); return(1); } lseek(fd, 0, SEEK_SET); ret = read(fd, NULL, 20); if (ret != -1 || errno != EFAULT) { printf("read 1: ret %lld, errno %d\n", (long long)ret, errno); return(1); } ret = read(fd, (void *)-1, 20); if (ret != -1 || errno != EFAULT) { printf("read 2: ret %lld, error %d\n", (long long)ret, errno); return(1); } iov[0].iov_base = NULL; iov[0].iov_len = 10; iov[1].iov_base = (void *)-1; iov[1].iov_len = 10; ret = readv(fd, iov, 2); if (ret != -1 || errno != EFAULT) { printf("readv 1: ret %lld, error %d\n", (long long)ret, errno); return(1); } iov[0].iov_base = NULL; iov[0].iov_len = 0; iov[1].iov_base = buf; iov[1].iov_len = sizeof(buf); ret = readv(fd, iov, 2); if (ret != sizeof(buf)) { printf("readv 2: ret %lld, error %d\n", (long long)ret, errno); return(1); } close(fd); t_unlink(file); LEAVE(); }
int t14(char *name) { char dir[MAX_PATH_LENGTH] = ""; char path[1024]; char buf[1024]; const int nfiles = 256; char *prefix = "test14_filename_long_prefix_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA___"; cfs_dirent_t *ent; int fd, i, rc, pos, index; loff_t base = 0; ENTER(">1 block(4k) directory readdir"); snprintf(dir, MAX_PATH_LENGTH, "%s/test_t14_dir/", lustre_path); rc = mkdir(dir, 0755); if (rc < 0 && errno != EEXIST) { printf("mkdir(%s) error: %s\n", dir, strerror(errno)); exit(1); } printf("Creating %d files...\n", nfiles); for (i = 0; i < nfiles; i++) { sprintf(path, "%s%s%05d", dir, prefix, i); t_touch(path); } fd = t_opendir(dir); printf("Listing...\n"); index = 0; while ((rc = getdirentries64(fd, buf, 1024, &base)) > 0) { pos = 0; while (pos < rc) { char *item; ent = (void *) buf + pos; item = (char *) ent->d_name; if (!strcmp(item, ".") || !strcmp(item, "..")) goto iter; if (strstr(item, prefix) != item) { printf("found bad name %s\n", item); return(-1); } printf("[%03d]: %s\t", index++, item + strlen(prefix)); iter: pos += ent->d_reclen; } } printf("\n"); if (rc < 0) { printf("getdents error %d\n", rc); return(-1); } if (index != nfiles) { printf("get %d files != %d\n", index, nfiles); return(-1); } t_close(fd); printf("Cleanup...\n"); for (i = 0; i < nfiles; i++) { sprintf(path, "%s%s%05d", dir, prefix, i); t_unlink(path); } t_rmdir(dir); LEAVE(); }
int t55(char *name) { char path[MAX_PATH_LENGTH] = ""; char file[MAX_PATH_LENGTH] = ""; struct lov_user_md *lum = NULL; struct lov_user_ost_data *lo = NULL; int index, fd, buflen, rc; ENTER("setstripe/getstripe"); snprintf(path, MAX_PATH_LENGTH, "%s/test_t55", lustre_path); snprintf(file, MAX_PATH_LENGTH, "%s/test_t55/file_t55", lustre_path); buflen = sizeof(struct lov_user_md); buflen += STRIPE_COUNT * sizeof(struct lov_user_ost_data); lum = (struct lov_user_md *)malloc(buflen); if (!lum) { printf("out of memory!\n"); return -1; } memset(lum, 0, buflen); t_mkdir(path); rc = llapi_file_create(path, STRIPE_SIZE, STRIPE_OFFSET, STRIPE_COUNT, LOV_PATTERN_RAID0); if (rc) { printf("llapi_file_create failed: rc = %d (%s) \n", rc, strerror(-rc)); t_rmdir(path); free(lum); return -1; } fd = open(file, O_CREAT | O_RDWR, 0644); if (fd < 0) { printf("open file(%s) failed: rc = %d (%s) \n)", file, fd, strerror(errno)); t_rmdir(path); free(lum); return -1; } lum->lmm_magic = LOV_USER_MAGIC; lum->lmm_stripe_count = STRIPE_COUNT; rc = ioctl(fd, LL_IOC_LOV_GETSTRIPE, lum); if (rc) { printf("dir:ioctl(LL_IOC_LOV_GETSTRIPE) failed: rc = %d(%s)\n", rc, strerror(errno)); close(fd); t_unlink(file); t_rmdir(path); free(lum); return -1; } close(fd); if (opt_verbose) { printf("lmm_magic: 0x%08X\n", lum->lmm_magic); printf("lmm_object_id: "LPX64"\n", lum->lmm_object_id); printf("lmm_object_seq: "LPX64"\n", lum->lmm_object_seq); printf("lmm_stripe_count: %u\n", (int)lum->lmm_stripe_count); printf("lmm_stripe_size: %u\n", lum->lmm_stripe_size); printf("lmm_stripe_pattern: %x\n", lum->lmm_pattern); for (index = 0; index < lum->lmm_stripe_count; index++) { lo = lum->lmm_objects + index; printf("object %d:\n", index); printf("\tobject_seq: "LPX64"\n", lo->l_object_seq); printf("\tobject_id: "LPX64"\n", lo->l_object_id); printf("\tost_gen: %#x\n", lo->l_ost_gen); printf("\tost_idx: %u\n", lo->l_ost_idx); } } if (lum->lmm_magic != LOV_USER_MAGIC || lum->lmm_pattern != LOV_PATTERN_RAID0 || lum->lmm_stripe_size != STRIPE_SIZE || lum->lmm_objects[0].l_ost_idx != STRIPE_OFFSET || lum->lmm_stripe_count != STRIPE_COUNT) { printf("incorrect striping information!\n"); t_unlink(file); t_rmdir(path); free(lum); return -1; } t_unlink(file); /* setstripe on regular file */ rc = llapi_file_create(file, STRIPE_SIZE, STRIPE_OFFSET, STRIPE_COUNT, LOV_PATTERN_RAID0); if (rc) { printf("llapi_file_create failed: rc = %d (%s) \n", rc, strerror(-rc)); t_unlink(file); t_rmdir(path); free(lum); return -1; } fd = open(file, O_RDWR, 0644); if (fd < 0) { printf("failed to open(%s): rc = %d (%s)\n", file, fd, strerror(errno)); t_unlink(file); t_rmdir(path); free(lum); return -1; } lum->lmm_magic = LOV_USER_MAGIC; lum->lmm_stripe_count = STRIPE_COUNT; rc = ioctl(fd, LL_IOC_LOV_GETSTRIPE, lum); if (rc) { printf("file:ioctl(LL_IOC_LOV_GETSTRIPE) failed: rc = %d(%s)\n", rc, strerror(errno)); close(fd); t_unlink(file); t_rmdir(path); free(lum); return -1; } close(fd); if (opt_verbose) { printf("lmm_magic: 0x%08X\n", lum->lmm_magic); printf("lmm_object_id: "LPX64"\n", lum->lmm_object_id); printf("lmm_object_seq: "LPX64"\n", lum->lmm_object_seq); printf("lmm_stripe_count: %u\n", (int)lum->lmm_stripe_count); printf("lmm_stripe_size: %u\n", lum->lmm_stripe_size); printf("lmm_stripe_pattern: %x\n", lum->lmm_pattern); for (index = 0; index < lum->lmm_stripe_count; index++) { lo = lum->lmm_objects + index; printf("object %d:\n", index); printf("\tobject_seq: "LPX64"\n", lo->l_object_seq); printf("\tobject_id: "LPX64"\n", lo->l_object_id); printf("\tost_gen: %#x\n", lo->l_ost_gen); printf("\tost_idx: %u\n", lo->l_ost_idx); } } if (lum->lmm_magic != LOV_USER_MAGIC || lum->lmm_pattern != LOV_PATTERN_RAID0 || lum->lmm_stripe_size != STRIPE_SIZE || lum->lmm_objects[0].l_ost_idx != STRIPE_OFFSET || lum->lmm_stripe_count != STRIPE_COUNT) { printf("incorrect striping information!\n"); t_unlink(file); t_rmdir(path); free(lum); return -1; } t_unlink(file); t_rmdir(path); free(lum); LEAVE(); }