From afcdfe0e612ec80d9435b174b9eb1a7092aec4cb Mon Sep 17 00:00:00 2001 From: lsy Date: Thu, 16 Sep 2004 02:15:36 +0000 Subject: [PATCH] b= 4582 r= adilger@clusterfs.com change hard-coded pathname in liblustre sanity test to env value. --- lustre/liblustre/tests/sanity.c | 101 ++++++++++++++++++++++++++++------------ 1 file changed, 71 insertions(+), 30 deletions(-) diff --git a/lustre/liblustre/tests/sanity.c b/lustre/liblustre/tests/sanity.c index 204a88f..7178fbb 100644 --- a/lustre/liblustre/tests/sanity.c +++ b/lustre/liblustre/tests/sanity.c @@ -39,6 +39,8 @@ #include "test_common.h" +extern char *lustre_path; + #define ENTRY(str) \ do { \ char buf[100]; \ @@ -64,8 +66,10 @@ void t1() { - char *path="/mnt/lustre/test_t1"; + char path[MAX_PATH_LENGTH] = ""; + ENTRY("create/delete"); + snprintf(path, MAX_PATH_LENGTH, "%s/test_t1", lustre_path); t_touch(path); t_unlink(path); @@ -74,8 +78,10 @@ void t1() void t2() { - char *path="/mnt/lustre/test_t2"; + char path[MAX_PATH_LENGTH] = ""; + ENTRY("mkdir/rmdir"); + snprintf(path, MAX_PATH_LENGTH, "%s/test_t2", lustre_path); t_mkdir(path); t_rmdir(path); @@ -84,8 +90,10 @@ void t2() void t3() { - char *path="/mnt/lustre/test_t3"; + char path[MAX_PATH_LENGTH] = ""; + ENTRY("regular stat"); + snprintf(path, MAX_PATH_LENGTH, "%s/test_t3", lustre_path); t_touch(path); t_check_stat(path, NULL); @@ -95,8 +103,10 @@ void t3() void t4() { - char *path="/mnt/lustre/test_t4"; + char path[MAX_PATH_LENGTH] = ""; + ENTRY("dir stat"); + snprintf(path, MAX_PATH_LENGTH, "%s/test_t4", lustre_path); t_mkdir(path); t_check_stat(path, NULL); @@ -106,9 +116,12 @@ void t4() void t6() { - char *path="/mnt/lustre/test_t6"; - char *path2="/mnt/lustre/test_t6_link"; + char path[MAX_PATH_LENGTH] = ""; + char path2[MAX_PATH_LENGTH] = ""; + ENTRY("symlink"); + snprintf(path, MAX_PATH_LENGTH, "%s/test_t6", lustre_path); + snprintf(path2, MAX_PATH_LENGTH, "%s/test_t6_link", lustre_path); t_touch(path); t_symlink(path, path2); @@ -120,9 +133,11 @@ void t6() void t7() { - char *path="/mnt/lustre/test_t7"; + char path[MAX_PATH_LENGTH] = ""; int rc; + ENTRY("mknod"); + snprintf(path, MAX_PATH_LENGTH, "%s/test_t7", lustre_path); if (geteuid() != 0) { rc = mknod(path, S_IFCHR | 0644, (5<<8 | 4)); @@ -140,8 +155,10 @@ void t7() void t8() { - char *path="/mnt/lustre/test_t8"; + char path[MAX_PATH_LENGTH] = ""; + ENTRY("chmod"); + snprintf(path, MAX_PATH_LENGTH, "%s/test_t8", lustre_path); t_touch(path); t_chmod_raw(path, 0700); @@ -152,9 +169,12 @@ void t8() void t9() { - char *path="/mnt/lustre/test_t9"; - char *path2="/mnt/lustre/test_t9_link"; + char path[MAX_PATH_LENGTH] = ""; + char path2[MAX_PATH_LENGTH] = ""; + ENTRY("hard link"); + snprintf(path, MAX_PATH_LENGTH, "%s/test_t9", lustre_path); + snprintf(path2, MAX_PATH_LENGTH, "%s/test_t9_link", lustre_path); t_touch(path); t_link(path, path2); @@ -167,14 +187,22 @@ void t9() void t10() { - char *dir1="/mnt/lustre/test_t10_dir1"; - char *dir2="/mnt/lustre/test_t10_dir2"; - char *path1="/mnt/lustre/test_t10_reg1"; - char *path2="/mnt/lustre/test_t10_reg2"; - char *rename1="/mnt/lustre/test_t10_dir1/rename1"; - char *rename2="/mnt/lustre/test_t10_dir2/rename2"; - char *rename3="/mnt/lustre/test_t10_dir2/rename3"; + char dir1[MAX_PATH_LENGTH] = ""; + char dir2[MAX_PATH_LENGTH] = ""; + char path1[MAX_PATH_LENGTH] = ""; + char path2[MAX_PATH_LENGTH] = ""; + char rename1[MAX_PATH_LENGTH] = ""; + char rename2[MAX_PATH_LENGTH] = ""; + char rename3[MAX_PATH_LENGTH] = ""; + ENTRY("rename"); + snprintf(dir1, MAX_PATH_LENGTH, "%s/test_t10_dir1", lustre_path); + snprintf(dir2, MAX_PATH_LENGTH, "%s/test_t10_dir2", lustre_path); + snprintf(path1, MAX_PATH_LENGTH, "%s/test_t10_reg1", lustre_path); + snprintf(path2, MAX_PATH_LENGTH, "%s/test_t10_reg2", lustre_path); + snprintf(rename1, MAX_PATH_LENGTH, "%s/test_t10_dir1/rename1", lustre_path); + snprintf(rename2, MAX_PATH_LENGTH, "%s/test_t10_dir1/rename2", lustre_path); + snprintf(rename3, MAX_PATH_LENGTH, "%s/test_t10_dir1/rename3", lustre_path); t_mkdir(dir1); t_mkdir(dir2); @@ -192,7 +220,7 @@ void t10() void t11() { - char *base="/mnt/lustre"; + char *base=lustre_path; char path[MAX_PATH_LENGTH], path2[MAX_PATH_LENGTH]; int i, j, level = 5, nreg = 5; ENTRY("deep tree"); @@ -228,10 +256,11 @@ void t11() void t12() { - char *dir="/mnt/lustre/test_t12_dir"; + char dir[MAX_PATH_LENGTH] = ""; char buf[1024*128]; int fd; ENTRY("empty directory readdir"); + snprintf(dir, MAX_PATH_LENGTH, "%s/test_t12_dir", lustre_path); t_mkdir(dir); fd = t_opendir(dir); @@ -243,13 +272,14 @@ void t12() void t13() { - char *dir="/mnt/lustre/test_t13_dir/"; + char dir[MAX_PATH_LENGTH] = ""; char name[1024]; char buf[1024]; const int nfiles = 20; char *prefix = "test13_filename_prefix_"; int fd, i; ENTRY("multiple entries directory readdir"); + snprintf(dir, MAX_PATH_LENGTH, "%s/test_t13_dir/", lustre_path); t_mkdir(dir); printf("Creating %d files...\n", nfiles); @@ -271,7 +301,7 @@ void t13() void t14() { - char *dir="/mnt/lustre/test_t14_dir/"; + char dir[MAX_PATH_LENGTH] = ""; char name[1024]; char buf[1024]; const int nfiles = 256; @@ -280,6 +310,7 @@ void t14() int fd, i, rc, pos, index; loff_t base = 0; ENTRY(">1 block(4k) directory readdir"); + snprintf(dir, MAX_PATH_LENGTH, "%s/test_t14_dir/", lustre_path); t_mkdir(dir); printf("Creating %d files...\n", nfiles); @@ -329,9 +360,10 @@ iter: void t15() { - char *file = "/mnt/lustre/test_t15_file"; + char file[MAX_PATH_LENGTH] = ""; int fd; ENTRY("open-stat-close"); + snprintf(file, MAX_PATH_LENGTH, "%s/test_t15_file", lustre_path); t_touch(file); fd = t_open(file); @@ -343,9 +375,10 @@ void t15() void t16() { - char *file = "/mnt/lustre/test_t16_file"; + char file[MAX_PATH_LENGTH] = ""; int fd; ENTRY("small-write-read"); + snprintf(file, MAX_PATH_LENGTH, "%s/test_t16_file", lustre_path); t_echo_create(file, "aaaaaaaaaaaaaaaaaaaaaa"); t_grep(file, "aaaaaaaaaaaaaaaaaaaaaa"); @@ -355,9 +388,10 @@ void t16() void t17() { - char *file = "/mnt/lustre/test_t17_file"; + char file[MAX_PATH_LENGTH] = ""; int fd; ENTRY("open-unlink without close"); + snprintf(file, MAX_PATH_LENGTH, "%s/test_t17_file", lustre_path); fd = open(file, O_WRONLY | O_CREAT, 0666); if (fd < 0) { @@ -370,11 +404,12 @@ void t17() void t18() { - char *file = "/mnt/lustre/test_t18_file"; + char file[MAX_PATH_LENGTH] = ""; char buf[128]; int fd, i; struct stat statbuf[3]; ENTRY("write should change mtime/atime"); + 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); @@ -409,10 +444,11 @@ void t18() void t19() { - char *file = "/mnt/lustre/test_t19_file"; + char file[MAX_PATH_LENGTH] = ""; int fd; struct stat statbuf; ENTRY("open(O_TRUNC) should trancate file to 0-length"); + snprintf(file, MAX_PATH_LENGTH, "%s/test_t19_file", lustre_path); t_echo_create(file, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); @@ -436,12 +472,13 @@ void t19() void t20() { - char *file = "/mnt/lustre/test_t20_file"; + char file[MAX_PATH_LENGTH] = ""; int fd; struct iovec iov[2]; char buf[100]; ssize_t ret; ENTRY("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) { @@ -515,9 +552,10 @@ void t20() void t21() { - char *file = "/mnt/lustre/test_t21_file"; + char file[MAX_PATH_LENGTH] = ""; int fd, ret; ENTRY("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) { @@ -540,12 +578,13 @@ void t21() void t22() { - char *file = "/mnt/lustre/test_t22_file"; + char file[MAX_PATH_LENGTH] = ""; int fd; char *str = "1234567890"; char buf[100]; ssize_t ret; ENTRY("make sure O_APPEND take effect"); + snprintf(file, MAX_PATH_LENGTH, "%s/test_t22_file", lustre_path); fd = open(file, O_RDWR|O_CREAT|O_APPEND, (mode_t)0666); if (fd < 0) { @@ -612,12 +651,14 @@ static int _buffer[_npages][PAGE_SIZE/sizeof(int)]; */ static void pages_io(int xfer, loff_t pos) { - char *path="/mnt/lustre/test_t50"; + char path[MAX_PATH_LENGTH] = ""; + int check_sum[_npages] = {0,}; int fd, rc, i, j, data_error = 0; struct timeval tw1, tw2, tr1, tr2; double tw, tr; + snprintf(path, MAX_PATH_LENGTH, "%s/test_t50", lustre_path); memset(_buffer, 0, sizeof(_buffer)); /* create sample data */ -- 1.8.3.1