From 1a5d77acb99fc92385d9827ab2a75e972548ebd2 Mon Sep 17 00:00:00 2001 From: haad Date: Fri, 4 Dec 2009 22:18:30 +0000 Subject: [PATCH] Add small testing program which uses RUMP libdm to test device-mapper functionality in userspace. --- share/examples/rump/dmtest/Makefile | 16 +++++ share/examples/rump/dmtest/dmt.c | 86 ++++++++++++++++++++++++++ share/examples/rump/dmtest/prop1.plist | 20 ++++++ share/examples/rump/dmtest/prop2.plist | 20 ++++++ 4 files changed, 142 insertions(+) create mode 100644 share/examples/rump/dmtest/Makefile create mode 100644 share/examples/rump/dmtest/dmt.c create mode 100644 share/examples/rump/dmtest/prop1.plist create mode 100644 share/examples/rump/dmtest/prop2.plist diff --git a/share/examples/rump/dmtest/Makefile b/share/examples/rump/dmtest/Makefile new file mode 100644 index 000000000000..8a8db8134841 --- /dev/null +++ b/share/examples/rump/dmtest/Makefile @@ -0,0 +1,16 @@ +# $NetBSD: Makefile,v 1.1 2009/12/04 22:18:30 haad Exp $ +PROG= dmt +SRCS= dmt.c + +DPADD= ${LIBUTIL} +LDADD= -lutil +MKMAN= no + +CFLAGS+= -g -fno-inline + +CPPFLAGS+= -DRUMP_ACTION -DRUMP_SYS_IOCTL -DRUMP_SYS_CLOSE -I${NETBSDSRCDIR}/sys/dev/dm +LDADD+= -lrumpdev_disk -lrumpdev_dm -lrumpdev -lprop +LDADD+= -lrumpvfs -lrump -lrumpuser -lpthread +DBG= -g + +.include diff --git a/share/examples/rump/dmtest/dmt.c b/share/examples/rump/dmtest/dmt.c new file mode 100644 index 000000000000..ca450c7247c8 --- /dev/null +++ b/share/examples/rump/dmtest/dmt.c @@ -0,0 +1,86 @@ +/* $NetBSD: dmt.c,v 1.1 2009/12/04 22:18:30 haad Exp $ + +/* + * Copyright (c) 2009 Adam Hamsik. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +int +main(int argc,char *argv[]) +{ + int fd; + int err; + + prop_dictionary_t dict_in, dict_out; + struct plistref prefp; + char *xml; + + err = rump_init(); + + if (err != 0) + printf("rump_init failed with %s\n", strerror(err)); + + fd = rump_sys_open("/dev/mapper/control", O_RDWR, 0); + if (fd == -1) + printf("Cannot open control device.\n"); + + dict_in = prop_dictionary_internalize_from_file("prop2.plist"); + dict_out = prop_dictionary_create(); + + prop_dictionary_externalize_to_pref(dict_in, &prefp); + + err = rump_sys_ioctl(fd, NETBSD_DM_IOCTL, &prefp); + if ( err != 0) + printf("ioctl failed %d\n", err); + + dict_out = prop_dictionary_internalize(prefp.pref_plist); + + xml = prop_dictionary_externalize(dict_out); + printf("%s\n",xml); + + close(fd); +} diff --git a/share/examples/rump/dmtest/prop1.plist b/share/examples/rump/dmtest/prop1.plist new file mode 100644 index 000000000000..e40e53ebdd51 --- /dev/null +++ b/share/examples/rump/dmtest/prop1.plist @@ -0,0 +1,20 @@ + + + + + cmd_data + + command + version + event_nr + 0x0 + flags + 0x4 + version + + 0x4 + 0x0 + 0x0 + + + \ No newline at end of file diff --git a/share/examples/rump/dmtest/prop2.plist b/share/examples/rump/dmtest/prop2.plist new file mode 100644 index 000000000000..f029dfb469b4 --- /dev/null +++ b/share/examples/rump/dmtest/prop2.plist @@ -0,0 +1,20 @@ + + + + + cmd_data + + command + targets + event_nr + 0x0 + flags + 0x4 + version + + 0x4 + 0x1 + 0x0 + + + \ No newline at end of file