summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkn <kn@openbsd.org>2019-11-30 03:30:29 +0000
committerkn <kn@openbsd.org>2019-11-30 03:30:29 +0000
commit15a1baa2dcaff887ce31186e1275b33041343de1 (patch)
tree57cdca3cf86b8ef8554cf704b8f4a0760ca5c5e2
parentDocument new flag and output arrangement better (diff)
downloadwireguard-openbsd-15a1baa2dcaff887ce31186e1275b33041343de1.tar.xz
wireguard-openbsd-15a1baa2dcaff887ce31186e1275b33041343de1.zip
Add create-vdisk command
Analogue to amd64's vmctl create, this command creates sparse disk image files of the given size. This is less error prone than creating full files with dd(1), but comes with other caveats - still, it is worth having around. Further refinements yet to come; vmctl and ldomctl should also behave more alike in the future, as briefly discussed with kettenis and deraadt.
-rw-r--r--usr.sbin/ldomctl/ldom.conf.59
-rw-r--r--usr.sbin/ldomctl/ldomctl.818
-rw-r--r--usr.sbin/ldomctl/ldomctl.c54
3 files changed, 72 insertions, 9 deletions
diff --git a/usr.sbin/ldomctl/ldom.conf.5 b/usr.sbin/ldomctl/ldom.conf.5
index 0c478b74fed..c17a2ddef5c 100644
--- a/usr.sbin/ldomctl/ldom.conf.5
+++ b/usr.sbin/ldomctl/ldom.conf.5
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ldom.conf.5,v 1.7 2019/11/28 18:40:42 kn Exp $
+.\" $OpenBSD: ldom.conf.5,v 1.8 2019/11/30 03:30:29 kn Exp $
.\"
.\" Copyright (c) 2012 Mark Kettenis <kettenis@openbsd.org>
.\"
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: November 28 2019 $
+.Dd $Mdocdate: November 30 2019 $
.Dt LDOM.CONF 5 sparc64
.Os
.Sh NAME
@@ -59,8 +59,9 @@ for a list of OpenPROM variables.
The specified file is used to back a virtual disk of the guest
domain.
.Ar file
-can be a block device node or a disk image file created with
-.Xr dd 1 .
+can be a block device node or a disk image file created with the
+.Cm create-vdisk
+command.
This keyword can be used multiple times.
.It Ic vnet Op Brq Ar keyword Ns = Ns Ar value ...
Assign a
diff --git a/usr.sbin/ldomctl/ldomctl.8 b/usr.sbin/ldomctl/ldomctl.8
index 6a3820200ad..b1f1cd3e5b9 100644
--- a/usr.sbin/ldomctl/ldomctl.8
+++ b/usr.sbin/ldomctl/ldomctl.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ldomctl.8,v 1.18 2019/11/28 18:03:33 kn Exp $
+.\" $OpenBSD: ldomctl.8,v 1.19 2019/11/30 03:30:29 kn Exp $
.\"
.\" Copyright (c) 2012 Mark Kettenis <kettenis@openbsd.org>
.\"
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: November 28 2019 $
+.Dd $Mdocdate: November 30 2019 $
.Dt LDOMCTL 8 sparc64
.Os
.Sh NAME
@@ -34,6 +34,16 @@ information about domains running on the system.
.Pp
The following commands are available:
.Bl -tag -width Ds
+.It Cm create-vdisk Fl s Ar size Ar file
+Create a virtual disk image with the specified
+.Ar file
+path and
+.Ar size ,
+in bytes.
+.Ar size
+can be specified with a human-readable scale, using the format described in
+.Xr scan_scaled 3 ,
+e.g. 512M.
.It Cm console Ar domain
Using
.Xr cu 1
@@ -119,8 +129,8 @@ openbsd [next]
.Pp
Create a virtual disk image for each guest domain:
.Bd -literal -offset indent
-# dd if=/dev/zero of=/home/puffy/vdisk0 bs=1m count=8192
-# dd if=/dev/zero of=/home/salmah/vdisk0 bs=1m count=8192
+# ldomctl create-vdisk -s 8G /home/puffy/vdisk0
+# ldomctl create-vdisk -s 8G /home/salmah/vdisk0
.Ed
.Pp
The minirootfs install media can be used to boot guest domains:
diff --git a/usr.sbin/ldomctl/ldomctl.c b/usr.sbin/ldomctl/ldomctl.c
index 359f8b8c571..b74dcbccbeb 100644
--- a/usr.sbin/ldomctl/ldomctl.c
+++ b/usr.sbin/ldomctl/ldomctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldomctl.c,v 1.27 2019/11/28 18:40:42 kn Exp $ */
+/* $OpenBSD: ldomctl.c,v 1.28 2019/11/30 03:30:29 kn Exp $ */
/*
* Copyright (c) 2012 Mark Kettenis
@@ -18,12 +18,15 @@
#include <sys/types.h>
#include <sys/ioctl.h>
+#include <sys/stat.h>
#include <err.h>
+#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#include <util.h>
#include "ds.h"
#include "hvctl.h"
@@ -53,6 +56,7 @@ void list(int argc, char **argv);
void list_io(int argc, char **argv);
void xselect(int argc, char **argv);
void delete(int argc, char **argv);
+void create_vdisk(int argc, char **argv);
void guest_start(int argc, char **argv);
void guest_stop(int argc, char **argv);
void guest_panic(int argc, char **argv);
@@ -67,6 +71,7 @@ struct command commands[] = {
{ "list-io", list_io },
{ "select", xselect },
{ "delete", delete },
+ { "create-vdisk", create_vdisk },
{ "start", guest_start },
{ "stop", guest_stop },
{ "panic", guest_panic },
@@ -117,6 +122,9 @@ main(int argc, char **argv)
if (cmdp->cmd_name == NULL)
usage();
+ if (strcmp(argv[0], "create-vdisk") == 0)
+ goto skip_hv;
+
hv_open();
/*
@@ -153,6 +161,7 @@ main(int argc, char **argv)
add_guest(prop->d.arc.node);
}
+skip_hv:
(cmdp->cmd_func)(argc, argv);
exit(EXIT_SUCCESS);
@@ -165,6 +174,7 @@ usage(void)
"\t%1$s download directory\n"
"\t%1$s dump|list|list-io\n"
"\t%1$s init-system file\n"
+ "\t%1$s create-vdisk -s size file\n"
"\t%1$s console|panic|start|status|stop [domain]\n", getprogname());
exit(EXIT_FAILURE);
}
@@ -350,6 +360,48 @@ delete(int argc, char **argv)
}
void
+create_vdisk(int argc, char **argv)
+{
+ int ch, fd, save_errno;
+ long long imgsize;
+ const char *imgfile_path;
+
+ while ((ch = getopt(argc, argv, "s:")) != -1) {
+ switch (ch) {
+ case 's':
+ if (scan_scaled(optarg, &imgsize) == -1)
+ err(1, "invalid size: %s", optarg);
+ break;
+ default:
+ usage();
+ }
+ }
+ argc -= optind;
+ argv += optind;
+
+ if (argc != 1)
+ usage();
+
+ imgfile_path = argv[0];
+
+ /* Refuse to overwrite an existing image */
+ if ((fd = open(imgfile_path, O_RDWR | O_CREAT | O_TRUNC | O_EXCL,
+ S_IRUSR | S_IWUSR)) == -1)
+ err(1, "open");
+
+ /* Extend to desired size */
+ if (ftruncate(fd, (off_t)imgsize) == -1) {
+ save_errno = errno;
+ close(fd);
+ unlink(imgfile_path);
+ errno = save_errno;
+ err(1, "ftruncate");
+ }
+
+ close(fd);
+}
+
+void
download(int argc, char **argv)
{
struct ds_conn *dc;