Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/dev/md Get rid of the "sleep 1" by using rump_daemoniz...



details:   https://anonhg.NetBSD.org/src/rev/0481ffe27faa
branches:  trunk
changeset: 759147:0481ffe27faa
user:      pooka <pooka%NetBSD.org@localhost>
date:      Tue Nov 30 14:29:05 2010 +0000

description:
Get rid of the "sleep 1" by using rump_daemonize_begin/end().
Notably, md is a little tricky for this, since the ioctl that
configures the service also blocks in the kernel.  Therefore, use
an additional pthread to probe when the service is fully configured
and the server can detach.

Also, rawpart love.

diffstat:

 tests/dev/md/h_mdserv.c |  94 ++++++++++++++++++++++++++++++++++++++++++++----
 tests/dev/md/t_md.sh    |  11 +++--
 2 files changed, 91 insertions(+), 14 deletions(-)

diffs (149 lines):

diff -r 6c4882bcec8f -r 0481ffe27faa tests/dev/md/h_mdserv.c
--- a/tests/dev/md/h_mdserv.c   Tue Nov 30 14:24:40 2010 +0000
+++ b/tests/dev/md/h_mdserv.c   Tue Nov 30 14:29:05 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: h_mdserv.c,v 1.1 2010/11/23 15:38:54 pooka Exp $       */
+/*     $NetBSD: h_mdserv.c,v 1.2 2010/11/30 14:29:05 pooka Exp $       */
 
 #include <sys/types.h>
 #include <sys/mman.h>
@@ -6,28 +6,104 @@
 
 #include <dev/md.h>
 
+#include <err.h>
+#include <errno.h>
 #include <fcntl.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
 #include <unistd.h>
 
 #include <rump/rump.h>
 #include <rump/rump_syscalls.h>
 
-#include "../../h_macros.h"
+#define MDSIZE (1024*1024)
+
+#define REQUIRE(a, msg) if ((a) != 0) err(1, msg);
+
+static void *
+prober(void *arg)
+{
+       int fd, error;
+       char buf[4];
+       ssize_t n;
+
+       fd = rump_sys_open(arg, O_RDONLY);
+       for (;;) {
+               n = rump_sys_read(fd, buf, sizeof(buf));
+
+               switch (n) {
+               case 4:
+                       error = 0;
+                       goto out;
 
-#define MDSIZE (1024*1024)
+               case -1:
+                       if (errno == ENXIO) {
+                               usleep(1000);
+                               continue;
+                       }
+
+                       /* FALLTHROUGH */
+               default:
+                       error = EPIPE;
+                       goto out;
+               }
+       }
+ out:
+
+       error = rump_daemonize_done(error);
+       REQUIRE(error, "rump_daemonize_done");
+
+       if (error)
+               exit(1);
+
+       return NULL;
+}
 
 int
-main(void)
+main(int argc, char *argv[])
 {
+       pthread_t pt;
        struct md_conf md;
-       int fd;
+       int fd, error;
+
+       if (argc != 2)
+               exit(1);
 
        md.md_addr = malloc(MDSIZE);
        md.md_size = MDSIZE;
        md.md_type = MD_UMEM_SERVER;
 
-       RL(rump_init());
-       RL(fd = rump_sys_open("/dev/rmd0d", O_RDWR));
-       RL(rump_sys_ioctl(fd, MD_SETCONF, &md));
-       pause();
+       error = rump_daemonize_begin();
+       REQUIRE(error, "rump_daemonize_begin");
+
+       error = rump_init();
+       REQUIRE(error, "rump_init");
+
+       error = rump_init_server("unix://commsock");
+       REQUIRE(error, "init server");
+
+       if ((fd = rump_sys_open(argv[1], O_RDWR)) == -1)
+               err(1, "open");
+
+       /*
+        * Now, configuring the md driver also causes our process
+        * to start acting as the worker for the md.  Splitting is
+        * into two steps in the driver is not easy, since md is
+        * supposed to be unconfigured when the process dies
+        * (process may exit between calling ioctl1 and ioctl2).
+        * So, start a probe thread which attempt to read the md
+        * and declares the md as configured when the read is
+        * succesful.
+        */
+       error = pthread_create(&pt, NULL, prober, argv[1]);
+       REQUIRE(error, "pthread_create");
+       pthread_detach(pt);
+
+       if (rump_sys_ioctl(fd, MD_SETCONF, &md) == -1) {
+               rump_daemonize_done(errno);
+               exit(1);
+       }
+
+       return 0;
 }
diff -r 6c4882bcec8f -r 0481ffe27faa tests/dev/md/t_md.sh
--- a/tests/dev/md/t_md.sh      Tue Nov 30 14:24:40 2010 +0000
+++ b/tests/dev/md/t_md.sh      Tue Nov 30 14:29:05 2010 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: t_md.sh,v 1.1 2010/11/23 15:38:54 pooka Exp $
+#      $NetBSD: t_md.sh,v 1.2 2010/11/30 14:29:05 pooka Exp $
 #
 # Copyright (c) 2010 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -35,12 +35,13 @@
 basic_body()
 {
 
-       RUMPSOCK=unix://commsock
-       env RUMP_SP_SERVER=${RUMPSOCK} $(atf_get_srcdir)/h_mdserv &
+       # Scope out raw part.  This is actually the *host* raw partition,
+       # but just let it slide for now, since they *should* be the same.
+       rawpart=`sysctl -n kern.rawpartition | tr '01234' 'abcde'`
 
-       sleep 1 # XXX: wait for server to start
+       atf_check -s exit:0 $(atf_get_srcdir)/h_mdserv /dev/rmd0${rawpart}
 
-       export RUMP_SP_CLIENT=${RUMPSOCK}
+       export RUMP_SERVER=unix://commsock
        atf_check -s exit:0 -e ignore dd if=/bin/ls rof=/dev/rmd0d seek=100 count=10
        atf_check -s exit:0 -e ignore dd of=testfile rif=/dev/rmd0d skip=100 count=10
        atf_check -s exit:0 -e ignore -o file:testfile dd if=/bin/ls count=10



Home | Main Index | Thread Index | Old Index