Module Name:    src
Committed By:   pooka
Date:           Tue Dec 14 16:40:05 UTC 2010

Modified Files:
        src/usr.bin/rump_allserver: rump_allserver.1 rump_allserver.c

Log Message:
Add -d which can be used to register host-backed block devices in
the rump kernel.

It would be cool if this, and the other options, could be specified
in a config file (plist or other).


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/rump_allserver/rump_allserver.1
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/rump_allserver/rump_allserver.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/rump_allserver/rump_allserver.1
diff -u src/usr.bin/rump_allserver/rump_allserver.1:1.2 src/usr.bin/rump_allserver/rump_allserver.1:1.3
--- src/usr.bin/rump_allserver/rump_allserver.1:1.2	Tue Dec 14 09:39:53 2010
+++ src/usr.bin/rump_allserver/rump_allserver.1	Tue Dec 14 16:40:05 2010
@@ -1,4 +1,4 @@
-.\"	$NetBSD: rump_allserver.1,v 1.2 2010/12/14 09:39:53 wiz Exp $
+.\"	$NetBSD: rump_allserver.1,v 1.3 2010/12/14 16:40:05 pooka Exp $
 .\"
 .\" Copyright (c) 2010 Antti Kantee.  All rights reserved.
 .\"
@@ -33,6 +33,7 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl s
+.Op Fl d Ar drivespec
 .Op Fl l Ar library
 .Op Fl m Ar module
 .Ar url
@@ -59,6 +60,30 @@
 At execution time it is possible to load components from the command
 line as described in the options section.
 .Bl -tag -width indent
+.It Fl d Ar drivespec
+The argument
+.Ar drivespec
+maps a host file a block device in the rump fs namespace.
+The string
+.Ar drivespec
+must be of comma-separated
+.Dq name=value
+format and must contain the following tokens:
+.Bl -tag -width hostpath1234
+.It Ar key
+Block device path in rump namespace.
+This must be specified according to the rules for a key in
+.Xr rump_etfs 3 .
+.It Ar hostpath
+Host file used for storage.
+If the file does not exist, it will be created.
+.It Ar size
+Size of the mapping.
+The host file will be truncated to the size indicated.
+Similar to
+.Xr dd 1 ,
+this argument accepts a suffix as the multiplier for the number.
+.El
 .It Fl l Ar library
 Call
 .Fn dlopen
@@ -102,6 +127,15 @@
 $ rump_server -lrumpvfs -m /modules/tmpfs.kmod unix://sock
 $ env RUMP_SERVER=unix://sock rump.halt
 .Ed
+.Pp
+Start a server with the one gigabyte host file
+.Pa dk.img
+mapped as the block device
+.Pa /dev/dk
+in the rump kernel.
+.Bd -literal -offset indent
+$ rump_allserver -d key=/dev/dk,hostpath=dk.img,size=1g unix://sock
+.Ed
 .Sh SEE ALSO
 .Xr rump.halt 1 ,
 .Xr dlopen 3 ,

Index: src/usr.bin/rump_allserver/rump_allserver.c
diff -u src/usr.bin/rump_allserver/rump_allserver.c:1.8 src/usr.bin/rump_allserver/rump_allserver.c:1.9
--- src/usr.bin/rump_allserver/rump_allserver.c:1.8	Mon Dec 13 14:26:22 2010
+++ src/usr.bin/rump_allserver/rump_allserver.c	Tue Dec 14 16:40:05 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: rump_allserver.c,v 1.8 2010/12/13 14:26:22 pooka Exp $	*/
+/*	$NetBSD: rump_allserver.c,v 1.9 2010/12/14 16:40:05 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -27,7 +27,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: rump_allserver.c,v 1.8 2010/12/13 14:26:22 pooka Exp $");
+__RCSID("$NetBSD: rump_allserver.c,v 1.9 2010/12/14 16:40:05 pooka Exp $");
 #endif /* !lint */
 
 #include <sys/types.h>
@@ -40,6 +40,7 @@
 #include <dlfcn.h>
 #include <err.h>
 #include <errno.h>
+#include <fcntl.h>
 #include <semaphore.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -50,7 +51,8 @@
 usage(void)
 {
 
-	fprintf(stderr, "usage: %s [args] bindurl\n", getprogname());
+	fprintf(stderr, "usage: %s [-d drivespec] [-l libs] [-m modules] [-s] "
+	    "bindurl\n", getprogname());
 	exit(1);
 }
 
@@ -72,20 +74,88 @@
 	sem_post(&sigsem);
 }
 
+static const char *const disktokens[] = {
+#define DKEY 0
+	"key",
+#define DFILE 1
+	"hostpath",
+#define DSIZE 2
+	"size",
+	NULL
+};
+
+struct etfsreg {
+	const char *key;
+	const char *hostpath;
+	off_t flen;
+	enum rump_etfs_type type;
+};
+
 int
 main(int argc, char *argv[])
 {
 	const char *serverurl;
 	char **modarray = NULL;
 	unsigned nmods = 0, curmod = 0, i;
+	struct etfsreg *etfs = NULL;
+	unsigned netfs = 0, curetfs = 0;
 	int error;
 	int ch, sflag;
 
 	setprogname(argv[0]);
 
 	sflag = 0;
-	while ((ch = getopt(argc, argv, "l:m:s")) != -1) {
+	while ((ch = getopt(argc, argv, "d:l:m:s")) != -1) {
 		switch (ch) {
+		case 'd': {
+			char *options, *value;
+			char *key, *hostpath;
+			long long flen;
+
+			flen = 0;
+			key = hostpath = NULL;
+			options = optarg;
+			while (*options) {
+				switch (getsubopt(&options,
+				    __UNCONST(disktokens), &value)) {
+				case DKEY:
+					key = value;
+					break;
+				case DFILE:
+					hostpath = value;
+					break;
+				case DSIZE:
+					/* XXX: off_t max? */
+					flen = strsuftoll("-d size", value,
+					    0, LLONG_MAX);
+					break;
+				default:
+					fprintf(stderr, "invalid dtoken\n");
+					usage();
+					break;
+				}
+			}
+
+			if (key == NULL || hostpath == NULL || flen == 0) {
+				fprintf(stderr, "incomplete drivespec\n");
+				usage();
+			}
+
+			if (netfs - curetfs == 0) {
+				etfs = realloc(etfs, (netfs+16)*sizeof(*etfs));
+				if (etfs == NULL)
+					err(1, "realloc etfs");
+				netfs += 16;
+			}
+
+			etfs[curetfs].key = key;
+			etfs[curetfs].hostpath = hostpath;
+			etfs[curetfs].flen = flen;
+			etfs[curetfs].type = RUMP_ETFS_BLK;
+			curetfs++;
+
+			break;
+		}
 		case 'l':
 			if (dlopen(optarg, RTLD_LAZY|RTLD_GLOBAL) == NULL) {
 				char pb[MAXPATHLEN];
@@ -135,6 +205,7 @@
 	if (error)
 		die(sflag, error, "rump init failed");
 
+	/* load modules */
 	for (i = 0; i < curmod; i++) {
 		struct modctl_load ml;
 
@@ -147,6 +218,23 @@
 		if (rump_sys_modctl(MODCTL_LOAD, &ml) == -1)
 			die(sflag, errno, "module load failed");
 		rump_pub_etfs_remove(ETFSKEY);
+#undef ETFSKEY
+	}
+
+	/* register host drives */
+	for (i = 0; i < curetfs; i++) {
+		int fd;
+
+		fd = open(etfs[i].hostpath, O_RDWR | O_CREAT, 0755);
+		if (fd == -1)
+			die(sflag, error, "etfs hostpath create");
+		if (ftruncate(fd, etfs[i].flen) == -1)
+			die(sflag, error, "truncate");
+		close(fd);
+
+		if ((error = rump_pub_etfs_register(etfs[i].key,
+		    etfs[i].hostpath, etfs[i].type)) != 0)
+			die(sflag, error, "etfs register");
 	}
 
 	error = rump_init_server(serverurl);

Reply via email to