[PATCH v3 4/4] samples: mic: Add sample VOP userspace

From: Vincent Whitchurch
Date: Wed Apr 03 2019 - 06:48:00 EST


Add a sample userspace program which can be used with the VOP framework
with vop-loopback and non-MIC hardware.

For example, the following commands can be used to test networking over
vop-loopback. (IPv6 is used with zone indices to force traffic through
the interfaces instead of short-circuit delivery, since both interfaces
are on the same system.)

# modprobe vop_loopback
# ./vopd &

Setup host interface:
# ip a a dev mic0 scope link fe80::0
# ip link set dev mic0 up

Setup guest interface:
# ip a a dev eth1 scope link fe80::1
# ip link set dev eth1 up

Ping from host to guest:
# ping6 fe80::1%mic0

Ping from guest to host:
# ping6 fe80::0%eth1

Signed-off-by: Vincent Whitchurch <vincent.whitchurch@xxxxxxxx>
---
samples/mic/mpssd/.gitignore | 1 +
samples/mic/mpssd/Makefile | 5 ++++-
samples/mic/mpssd/vopd.c | 25 +++++++++++++++++++++++++
3 files changed, 30 insertions(+), 1 deletion(-)
create mode 100644 samples/mic/mpssd/vopd.c

diff --git a/samples/mic/mpssd/.gitignore b/samples/mic/mpssd/.gitignore
index 8b7c72f07c92..34c001135abb 100644
--- a/samples/mic/mpssd/.gitignore
+++ b/samples/mic/mpssd/.gitignore
@@ -1 +1,2 @@
mpssd
+vopd
diff --git a/samples/mic/mpssd/Makefile b/samples/mic/mpssd/Makefile
index bc94054dbe2b..b94b18de5a43 100644
--- a/samples/mic/mpssd/Makefile
+++ b/samples/mic/mpssd/Makefile
@@ -5,7 +5,7 @@ ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/)

ifeq ($(ARCH),x86)

-PROGS := mpssd
+PROGS := mpssd vopd
CC = $(CROSS_COMPILE)gcc
CFLAGS := -I../../../usr/include -I../../../tools/include

@@ -17,6 +17,9 @@ all: $(PROGS)
mpssd: mpssd.c sysfs.c vop.o
$(CC) $(CFLAGS) $^ -o $@ -lpthread

+vopd: vopd.c vop.o
+ $(CC) $(CFLAGS) $^ -o $@ -lpthread
+
install:
install mpssd /usr/sbin/mpssd
install micctrl /usr/sbin/micctrl
diff --git a/samples/mic/mpssd/vopd.c b/samples/mic/mpssd/vopd.c
new file mode 100644
index 000000000000..48c1877fed28
--- /dev/null
+++ b/samples/mic/mpssd/vopd.c
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <stdio.h>
+
+#include "mpssd.h"
+
+void mpsslog(char *format, ...)
+{
+ va_list args;
+
+ va_start(args, format);
+ vprintf(format, args);
+ va_end(args);
+}
+
+int main(int argc, char *argv[])
+{
+ struct mic_info themic = {
+ .name = "mic",
+ };
+
+ serve_virtio(&themic, &themic);
+
+ return 0;
+}
--
2.20.0