From eaefa9c411a80e8271697adfe562f9c21456a8f5 Mon Sep 17 00:00:00 2001 From: ericm Date: Fri, 14 Nov 2003 09:37:33 +0000 Subject: [PATCH] liblustre: add more test in replay_single, and some other adjustment. --- lustre/liblustre/recovery_small.c | 6 +-- lustre/liblustre/replay_single.c | 79 ++++++++++++++++++++++++++++++++++++--- lustre/liblustre/test_common.c | 41 ++++++++++++++++++++ lustre/liblustre/test_common.h | 2 + 4 files changed, 119 insertions(+), 9 deletions(-) diff --git a/lustre/liblustre/recovery_small.c b/lustre/liblustre/recovery_small.c index 71ba546..b1292c2 100644 --- a/lustre/liblustre/recovery_small.c +++ b/lustre/liblustre/recovery_small.c @@ -51,7 +51,7 @@ static struct { static int drop_index = 0; -static char mds_server[1024]; +static char mds_server[1024] = {0, }; int do_stat(const char *name, struct stat *buf) { @@ -309,7 +309,7 @@ void usage(const char *cmd) int main(int argc, char * argv[]) { int opt_index, c; - char cmd[1024] = {0,}; + char cmd[1024]; static struct option long_opts[] = { {"target", 1, 0, 0}, {"dumpfile", 1, 0, 0}, @@ -344,7 +344,7 @@ int main(int argc, char * argv[]) if (optind != argc) usage(argv[0]); - if (strlen(cmd) == 0) + if (strlen(mds_server) == 0) usage(argv[0]); sprintf(cmd, "ssh %s cat /dev/null", mds_server); diff --git a/lustre/liblustre/replay_single.c b/lustre/liblustre/replay_single.c index 9bc4270..267e838 100755 --- a/lustre/liblustre/replay_single.c +++ b/lustre/liblustre/replay_single.c @@ -89,6 +89,14 @@ static void mds_failover() printf("-------------------\n"); \ } while (0) +void t0() +{ + ENTRY("empty replay"); + replay_barrier(); + mds_failover(); + LEAVE(); +} + void t1() { char *path="/mnt/lustre/f1"; @@ -102,7 +110,7 @@ void t1() LEAVE(); } -void t1a() +void t2a() { char *path="/mnt/lustre/f1a"; ENTRY("touch"); @@ -115,7 +123,63 @@ void t1a() LEAVE(); } -void t2() +void t2b() +{ + char *path="/mnt/lustre/f1a"; + ENTRY("mcreate+touch"); + + t_create(path); + replay_barrier(); + t_touch(path); + mds_failover(); + t_check_stat(path, NULL); + t_unlink(path); + LEAVE(); +} + + +void t3() +{ + char *base="/mnt/lustre/f3_"; + char path[100]; + char str[100]; + char buf[100]; + int i; + ENTRY("10 create/delete"); + + replay_barrier(); + for (i = 0; i < 10; i++) { + sprintf(path, "%s%d\n", base, i); + sprintf(str, "TEST#%d CONTENT\n", i); + t_echo_create(path, str); + } + mds_failover(); + for (i = 0; i < 10; i++) { + sprintf(path, "%s%d\n", base, i); + sprintf(str, "TEST#%d CONTENT\n", i); + t_pread_once(path, buf, 100, 0); + if (!strstr(buf, str)) { + printf("f%d: content error !\n", i); + exit(-1); + } + } + replay_barrier(); + for (i = 0; i < 10; i++) { + sprintf(path, "%s%d\n", base, i); + t_unlink(path); + } + mds_failover(); + for (i = 0; i < 10; i++) { + sprintf(path, "%s%d\n", base, i); + if (!stat(path, NULL)) { + printf("f%d still exist!\n", i); + exit(-1); + } + } + LEAVE(); +} + +void t4() { char *dir="/mnt/lustre/d2"; char *path="/mnt/lustre/d2/f2"; @@ -132,7 +196,7 @@ void t2() LEAVE(); } -void t3() +void t5() { char *dir="/mnt/lustre/d3"; char *path="/mnt/lustre/d3/f3"; @@ -149,7 +213,7 @@ void t3() LEAVE(); } -void t4() +void t6() { char *path="/mnt/lustre/f4"; int fd; @@ -245,11 +309,14 @@ int main(int argc, char * const argv[]) __liblustre_setup_(); + t0(); t1(); - t1a(); - t2(); + t2a(); + t2b(); t3(); t4(); + t5(); + t6(); printf("liblustre is about shutdown\n"); __liblustre_cleanup_(); diff --git a/lustre/liblustre/test_common.c b/lustre/liblustre/test_common.c index 78c19aa..21f088d 100644 --- a/lustre/liblustre/test_common.c +++ b/lustre/liblustre/test_common.c @@ -206,3 +206,44 @@ int t_check_stat(const char *name, struct stat *buf) return 0; } + +void t_echo_create(const char *path, const char *str) +{ + int fd, rc; + + fd = open(path, O_RDWR|O_CREAT, 0644); + if (fd < 0) { + printf("open(%s) error: %s\n", path, strerror(errno)); + EXIT(fd); + } + + if (write(fd, str, strlen(str)+1) != strlen(str)+1) { + printf("write(%s) error: %s\n", path, strerror(errno)); + EXIT(fd); + } + + rc = close(fd); + if (rc) { + printf("close(%s) error: %s\n", path, strerror(errno)); + EXIT(rc); + } +} + +int t_pread_once(const char *path, char *buf, size_t size, off_t offset) +{ + int fd; + int rc; + + memset(buf, 0, size); + + fd = t_open_readonly(path); + if (lseek(fd, offset, SEEK_SET) == -1) { + printf("pread_once: seek to %lu error: %s\n", + offset, strerror(errno)); + EXIT(fd); + } + + rc = read(fd, buf, size); + close(fd); + return rc; +} diff --git a/lustre/liblustre/test_common.h b/lustre/liblustre/test_common.h index 6628b4d..aee0552 100644 --- a/lustre/liblustre/test_common.h +++ b/lustre/liblustre/test_common.h @@ -22,5 +22,7 @@ int t_open_readonly(const char *path); int t_open(const char *path); void t_close(int fd); int t_check_stat(const char *name, struct stat *buf); +void t_echo_create(const char *path, const char *str); +int t_pread_once(const char *path, char *buf, size_t size, off_t offset); #endif -- 1.8.3.1