From f12449c72130061905dfa9f1a52c8488066ee2fb Mon Sep 17 00:00:00 2001 From: braam <braam> Date: Sun, 12 May 2002 01:08:41 +0000 Subject: [PATCH] - test programs for directio, writing and opening - phase 2 ha assistance program --- lustre/tests/directio.c | 58 ++++++++++++++++++++++++++++++++++++++ lustre/tests/openme.c | 23 +++++++++++++++ lustre/tests/writeme.c | 32 +++++++++++++++++++++ lustre/utils/ha_assist2.sh | 33 ++++++++++++++++++++++ 4 files changed, 146 insertions(+) create mode 100644 lustre/tests/directio.c create mode 100644 lustre/tests/openme.c create mode 100644 lustre/tests/writeme.c create mode 100755 lustre/utils/ha_assist2.sh diff --git a/lustre/tests/directio.c b/lustre/tests/directio.c new file mode 100644 index 0000000000..b531c50c94 --- /dev/null +++ b/lustre/tests/directio.c @@ -0,0 +1,58 @@ +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <fcntl.h> +#include <stdlib.h> +#include <errno.h> +#include <sys/mman.h> + +// not correctly in the headers yet!! +#define O_DIRECT 040000 /* direct disk access hint */ + +int main(int argc, char **argv) +{ + int fd; + char *buf; + int pages; + int rc; + + if (argc != 3) { + printf("Usage: %s file nr_pages\n", argv[0]); + return 1; + } + + pages = strtoul(argv[2], 0, 0); + printf("directio on %s for %d pages \n", argv[1], pages); + + buf = mmap(0, pages * 4096, PROT_READ|PROT_WRITE, + MAP_PRIVATE|MAP_ANON, 0, 0); + if (!buf) { + printf("No memory %s\n", strerror(errno)); + return 1; + } + + fd = open(argv[1], O_DIRECT | O_RDWR | O_CREAT); + if (fd == -1) { + printf("Cannot open %s: %s\n", argv[1], strerror(errno)); + return 1; + } + + rc = read(fd, buf, pages * 4096); + if (rc != pages * 4096) { + printf("Read error: %s, rc %d\n", strerror(errno), rc); + return 1; + } + + if ( lseek(fd, 0, SEEK_SET) != 0 ) { + printf("Cannot seek %s\n", strerror(errno)); + return 1; + } + + rc = write(fd, buf, pages * 4096); + if (rc != pages * 4096) { + printf("Write error %s\n", strerror(errno)); + return 1; + } + + return 0; +} diff --git a/lustre/tests/openme.c b/lustre/tests/openme.c new file mode 100644 index 0000000000..9a1f3f3638 --- /dev/null +++ b/lustre/tests/openme.c @@ -0,0 +1,23 @@ +#include <fcntl.h> +#include <unistd.h> +#include <stdlib.h> +#include <stdio.h> + +int main(int argc, char **argv) +{ + int fd; + + if (argc != 2) { + printf("Usage openme <filename>\n"); + exit(1); + } + + fd = open(argv[1], O_RDONLY | O_CREAT, 0600); + if (fd == -1) { + printf("Error opening %s\n", argv[1]); + exit(1); + } + + sleep(10000000); + return 0; +} diff --git a/lustre/tests/writeme.c b/lustre/tests/writeme.c new file mode 100644 index 0000000000..ab8692f842 --- /dev/null +++ b/lustre/tests/writeme.c @@ -0,0 +1,32 @@ +#include <fcntl.h> +#include <unistd.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +int main(int argc, char **argv) +{ + int fd, rc; + int i = 0; + char buf[4096]; + + memset(buf, 0, 4096); + + if (argc != 2) { + printf("Usage openme <filename>\n"); + exit(1); + } + + fd = open(argv[1], O_RDWR | O_CREAT, 0600); + if (fd == -1) { + printf("Error opening %s\n", argv[1]); + exit(1); + } + + while (1) { + sprintf(buf, "write %d\n", i); + rc = write(fd, buf, sizeof(buf)); + sleep(1); + } + return 0; +} diff --git a/lustre/utils/ha_assist2.sh b/lustre/utils/ha_assist2.sh new file mode 100755 index 0000000000..5cf61b2119 --- /dev/null +++ b/lustre/utils/ha_assist2.sh @@ -0,0 +1,33 @@ +#!/bin/bash +set -vx +date +echo "ha assist checking for problems" +sleep 3 +if [ ! -e /tmp/halog ]; then + echo "no problems, exiting" + exit +fi + +echo "removing /tmp/halog" +rm /tmp/halog + +echo secondary start `date` +echo "- please supply a new mds" + + +/usr/src/portals/linux/utils/ptlctl <<EOF3 +setup tcp +close_uuid mds +del_uuid mds +connect localhost 1234 +add_uuid mds +quit +EOF3 + +echo "connected to new MDS!" + +/usr/src/obd/utils/obdctl <<EOF2 +name2dev RPCDEV +newconn +quit +EOF2 -- GitLab