Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/nvmmctl Add nvmmctl, with two commands for now.
details: https://anonhg.NetBSD.org/src/rev/a234fde0d4eb
branches: trunk
changeset: 966378:a234fde0d4eb
user: maxv <maxv%NetBSD.org@localhost>
date: Mon Oct 28 13:04:18 2019 +0000
description:
Add nvmmctl, with two commands for now.
diffstat:
distrib/sets/lists/base/md.amd64 | 3 +-
distrib/sets/lists/man/mi | 5 +-
share/mk/bsd.hostprog.mk | 3 +-
usr.sbin/Makefile | 4 +-
usr.sbin/nvmmctl/Makefile | 16 +++
usr.sbin/nvmmctl/nvmmctl.8 | 63 +++++++++++++
usr.sbin/nvmmctl/nvmmctl.c | 180 +++++++++++++++++++++++++++++++++++++++
7 files changed, 270 insertions(+), 4 deletions(-)
diffs (truncated from 353 to 300 lines):
diff -r 4c56541e34da -r a234fde0d4eb distrib/sets/lists/base/md.amd64
--- a/distrib/sets/lists/base/md.amd64 Mon Oct 28 10:43:08 2019 +0000
+++ b/distrib/sets/lists/base/md.amd64 Mon Oct 28 13:04:18 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: md.amd64,v 1.280 2019/08/26 04:49:45 kamil Exp $
+# $NetBSD: md.amd64,v 1.281 2019/10/28 13:04:18 maxv Exp $
./dev/lms0 base-obsolete obsolete
./dev/mms0 base-obsolete obsolete
./libexec/ld.elf_so-i386 base-sys-shlib compat,pic
@@ -71,3 +71,4 @@
./usr/mdec/pxeboot_ia32_com0.bin base-obsolete obsolete
./usr/sbin/acpidump base-sysutil-bin
./usr/sbin/amldb base-sysutil-bin
+./usr/sbin/nvmmctl base-sysutil-bin
diff -r 4c56541e34da -r a234fde0d4eb distrib/sets/lists/man/mi
--- a/distrib/sets/lists/man/mi Mon Oct 28 10:43:08 2019 +0000
+++ b/distrib/sets/lists/man/mi Mon Oct 28 13:04:18 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1659 2019/10/28 02:56:40 ozaki-r Exp $
+# $NetBSD: mi,v 1.1660 2019/10/28 13:04:18 maxv Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -2873,6 +2873,7 @@
./usr/share/man/cat8/ntptime.0 man-ntp-catman .cat
./usr/share/man/cat8/ntptrace.0 man-ntp-catman .cat
./usr/share/man/cat8/nvmectl.0 man-sysutil-catman .cat
+./usr/share/man/cat8/nvmmctl.0 man-sysutil-catman .cat
./usr/share/man/cat8/ofctl.0 man-sysutil-catman .cat
./usr/share/man/cat8/ofppc/MAKEDEV.0 man-obsolete obsolete
./usr/share/man/cat8/ofppc/makedev.0 man-obsolete obsolete
@@ -5823,6 +5824,7 @@
./usr/share/man/html8/ntptime.html man-ntp-htmlman html
./usr/share/man/html8/ntptrace.html man-ntp-htmlman html
./usr/share/man/html8/nvmectl.html man-sysutil-htmlman html
+./usr/share/man/html8/nvmmctl.html man-sysutil-htmlman html
./usr/share/man/html8/ofctl.html man-sysutil-htmlman html
./usr/share/man/html8/oqmgr.html man-postfix-htmlman postfix,html
./usr/share/man/html8/pac.html man-sysutil-htmlman html
@@ -8997,6 +8999,7 @@
./usr/share/man/man8/ntptime.8 man-ntp-man .man
./usr/share/man/man8/ntptrace.8 man-ntp-man .man
./usr/share/man/man8/nvmectl.8 man-sysutil-man .man
+./usr/share/man/man8/nvmmctl.8 man-sysutil-man .man
./usr/share/man/man8/ofctl.8 man-sysutil-man .man
./usr/share/man/man8/ofppc/MAKEDEV.8 man-obsolete obsolete
./usr/share/man/man8/ofppc/makedev.8 man-obsolete obsolete
diff -r 4c56541e34da -r a234fde0d4eb share/mk/bsd.hostprog.mk
--- a/share/mk/bsd.hostprog.mk Mon Oct 28 10:43:08 2019 +0000
+++ b/share/mk/bsd.hostprog.mk Mon Oct 28 13:04:18 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: bsd.hostprog.mk,v 1.81 2019/01/21 21:11:54 christos Exp $
+# $NetBSD: bsd.hostprog.mk,v 1.82 2019/10/28 13:04:19 maxv Exp $
# @(#)bsd.prog.mk 8.2 (Berkeley) 4/2/94
.include <bsd.hostinit.mk>
@@ -39,6 +39,7 @@
LIBMENU?= /usr/lib/libmenu.a
LIBMP?= /usr/lib/libmp.a
LIBNTP?= /usr/lib/libntp.a
+LIBNVMM?= /usr/lib/libnvmm.a
LIBOBJC?= /usr/lib/libobjc.a
LIBP2K?= /usr/lib/libp2k.a
LIBPANEL?= /usr/lib/libpanel.a
diff -r 4c56541e34da -r a234fde0d4eb usr.sbin/Makefile
--- a/usr.sbin/Makefile Mon Oct 28 10:43:08 2019 +0000
+++ b/usr.sbin/Makefile Mon Oct 28 13:04:18 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.281 2019/10/15 18:33:23 christos Exp $
+# $NetBSD: Makefile,v 1.282 2019/10/28 13:04:18 maxv Exp $
# from: @(#)Makefile 5.20 (Berkeley) 6/12/93
.include <bsd.own.mk>
@@ -54,6 +54,8 @@
SUBDIR+= racoon racoonctl
+SUBDIR+= nvmmctl
+
# NPF
.if (${MKNPF} != "no")
SUBDIR+=npf
diff -r 4c56541e34da -r a234fde0d4eb usr.sbin/nvmmctl/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/nvmmctl/Makefile Mon Oct 28 13:04:18 2019 +0000
@@ -0,0 +1,16 @@
+# $NetBSD: Makefile,v 1.1 2019/10/28 13:04:18 maxv Exp $
+
+.include <bsd.own.mk>
+
+MAN= nvmmctl.8
+
+.if (${MACHINE_ARCH} == "x86_64")
+PROG= nvmmctl
+SRCS= nvmmctl.c
+
+CPPFLAGS+=-D_KERNTYPES
+LDADD+=-lutil -lnvmm
+DPADD+=${LIBUTIL} ${LIBNVMM}
+.endif
+
+.include <bsd.prog.mk>
diff -r 4c56541e34da -r a234fde0d4eb usr.sbin/nvmmctl/nvmmctl.8
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/nvmmctl/nvmmctl.8 Mon Oct 28 13:04:18 2019 +0000
@@ -0,0 +1,63 @@
+.\" $NetBSD: nvmmctl.8,v 1.1 2019/10/28 13:04:18 maxv Exp $
+.\"
+.\" Copyright (c) 2019 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Maxime Villard.
+.\"
+.\" 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``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 FOUNDATION 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.
+.\"
+.Dd October 27, 2019
+.Dt NVMMCTL 8
+.Os
+.Sh NAME
+.Nm nvmmctl
+.Nd program to control virtual machines
+.Sh SYNOPSIS
+.Nm nvmmctl
+.Ar command
+.Op Ar arguments
+.Sh DESCRIPTION
+The
+.Nm
+command can be used to control and inspect the state of virtual machines in the
+system.
+.Pp
+The first argument,
+.Ar command ,
+specifies the action to take.
+Valid commands are:
+.Bl -tag -width XXXXXXXX
+.It identify
+Display the capabilities of the system.
+.It list
+Display information on each virtual machine registered in the system.
+.El
+.Sh SEE ALSO
+.Xr nvmm 4 ,
+.Xr libnvmm 3
+.Sh AUTHORS
+The
+.Nm
+tool was written by
+.An Maxime Villard .
diff -r 4c56541e34da -r a234fde0d4eb usr.sbin/nvmmctl/nvmmctl.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/nvmmctl/nvmmctl.c Mon Oct 28 13:04:18 2019 +0000
@@ -0,0 +1,180 @@
+/* $NetBSD: nvmmctl.c,v 1.1 2019/10/28 13:04:18 maxv Exp $ */
+
+/*
+ * Copyright (c) 2019 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Maxime Villard.
+ *
+ * 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``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 FOUNDATION 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 <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: nvmmctl.c,v 1.1 2019/10/28 13:04:18 maxv Exp $");
+#endif /* not lint */
+
+#include <sys/param.h>
+
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <string.h>
+#include <unistd.h>
+#include <time.h>
+#include <util.h>
+#include <nvmm.h>
+
+#include <x86/specialreg.h>
+
+__dead static void usage(void);
+static void nvmm_identify(char **);
+static void nvmm_list(char **);
+
+static struct cmdtab {
+ const char *label;
+ bool takesargs;
+ bool argsoptional;
+ void (*func)(char **);
+} const nvmm_cmdtab[] = {
+ { "identify", false, false, nvmm_identify },
+ { "list", false, false, nvmm_list },
+ { NULL, false, false, NULL },
+};
+
+static struct nvmm_capability cap;
+
+int
+main(int argc, char **argv)
+{
+ const struct cmdtab *ct;
+
+ argc -= 1;
+ argv += 1;
+ if (argc < 1)
+ usage();
+
+ for (ct = nvmm_cmdtab; ct->label != NULL; ct++) {
+ if (strcmp(argv[0], ct->label) == 0) {
+ if (!ct->argsoptional &&
+ ((ct->takesargs == 0) ^ (argv[1] == NULL)))
+ {
+ usage();
+ }
+ (*ct->func)(argv + 1);
+ break;
+ }
+ }
+
+ if (ct->label == NULL)
+ errx(EXIT_FAILURE, "unknown command ``%s''", argv[0]);
+
+ exit(EXIT_SUCCESS);
+ /* NOTREACHED */
+}
+
+static void
+usage(void)
+{
+ const char *progname = getprogname();
+
+ fprintf(stderr, "usage: %s identify\n", progname);
+ fprintf(stderr, " %s list\n", progname);
+ exit(EXIT_FAILURE);
+ /* NOTREACHED */
+}
+
+#define MACH_CONF_FLAGS "\20"
+#define VCPU_CONF_FLAGS "\20" "\1" "CPUID" "\2" "TPR"
+
+static void
+nvmm_identify(char **argv)
+{
+ char buf[256], ram[4+1];
+
+ if (nvmm_init() == -1)
+ err(EXIT_FAILURE, "nvmm_init failed");
+ if (nvmm_capability(&cap) == -1)
+ err(EXIT_FAILURE, "nvmm_capability failed");
+
+ printf("nvmm: Kernel API version %u\n", cap.version);
+ printf("nvmm: State size %u\n", cap.state_size);
+ printf("nvmm: Max machines %u\n", cap.max_machines);
+ printf("nvmm: Max VCPUs per machine %u\n", cap.max_vcpus);
Home |
Main Index |
Thread Index |
Old Index