Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin Allow to specify -d hostpath offset, size with diskla...
details: https://anonhg.NetBSD.org/src/rev/e5b8f67407a1
branches: trunk
changeset: 761670:e5b8f67407a1
user: pooka <pooka%NetBSD.org@localhost>
date: Fri Feb 04 20:06:23 2011 +0000
description:
Allow to specify -d hostpath offset,size with disklabel.
diffstat:
usr.bin/rump_allserver/Makefile | 5 +-
usr.bin/rump_allserver/rump_allserver.1 | 13 ++++-
usr.bin/rump_allserver/rump_allserver.c | 69 ++++++++++++++++++++++++++++----
usr.bin/rump_server/Makefile | 4 +-
4 files changed, 75 insertions(+), 16 deletions(-)
diffs (243 lines):
diff -r 6c7103496255 -r e5b8f67407a1 usr.bin/rump_allserver/Makefile
--- a/usr.bin/rump_allserver/Makefile Fri Feb 04 19:58:10 2011 +0000
+++ b/usr.bin/rump_allserver/Makefile Fri Feb 04 20:06:23 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.3 2010/12/13 19:36:34 pooka Exp $
+# $NetBSD: Makefile,v 1.4 2011/02/04 20:06:23 pooka Exp $
#
PROG= rump_allserver
@@ -14,4 +14,7 @@
LDADD+= ${RUMPDEVLDADD} ${RUMPFSLDADD} ${RUMPKERNLDADD} ${RUMPNETLDADD}
LDADD+= -lrumpdev -lrumpvfs -lrumpnet -lrump -lrumpuser -lpthread
+DPADD+= ${LIBUTIL}
+LDADD+= -lutil
+
.include <bsd.prog.mk>
diff -r 6c7103496255 -r e5b8f67407a1 usr.bin/rump_allserver/rump_allserver.1
--- a/usr.bin/rump_allserver/rump_allserver.1 Fri Feb 04 19:58:10 2011 +0000
+++ b/usr.bin/rump_allserver/rump_allserver.1 Fri Feb 04 20:06:23 2011 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: rump_allserver.1,v 1.11 2011/02/03 11:25:27 pooka Exp $
+.\" $NetBSD: rump_allserver.1,v 1.12 2011/02/04 20:06:23 pooka Exp $
.\"
.\" Copyright (c) 2010 Antti Kantee. All rights reserved.
.\"
@@ -23,7 +23,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd February 3, 2011
+.Dd February 4, 2011
.Dt RUMP_SERVER 1
.Os
.Sh NAME
@@ -90,9 +90,16 @@
Similar to
.Xr dd 1 ,
this argument accepts a suffix as the multiplier for the number.
+.It OR
+.It Ar disklabel
+Use a disklabel partition identifier to specify the offset and size
+of the mapping.
+.Ar hostpath
+must contain an existing and valid disklabel within the first 64k.
.El
.Pp
-The following specifier is optional:
+The following specifier is optional and used only if disklabel is
+not specified:
.Bl -tag -width hostpath1234
.It Ar offset
Offset of the mapping.
diff -r 6c7103496255 -r e5b8f67407a1 usr.bin/rump_allserver/rump_allserver.c
--- a/usr.bin/rump_allserver/rump_allserver.c Fri Feb 04 19:58:10 2011 +0000
+++ b/usr.bin/rump_allserver/rump_allserver.c Fri Feb 04 20:06:23 2011 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: rump_allserver.c,v 1.15 2011/02/03 11:25:27 pooka Exp $ */
+/* $NetBSD: rump_allserver.c,v 1.16 2011/02/04 20:06:23 pooka Exp $ */
/*-
- * Copyright (c) 2010 Antti Kantee. All Rights Reserved.
+ * Copyright (c) 2010, 2011 Antti Kantee. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -27,10 +27,11 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: rump_allserver.c,v 1.15 2011/02/03 11:25:27 pooka Exp $");
+__RCSID("$NetBSD: rump_allserver.c,v 1.16 2011/02/04 20:06:23 pooka Exp $");
#endif /* !lint */
#include <sys/types.h>
+#include <sys/disklabel.h>
#include <sys/signal.h>
#include <sys/module.h>
@@ -46,6 +47,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <util.h>
static void
usage(void)
@@ -83,6 +85,8 @@
"size",
#define DOFFSET 3
"offset",
+#define DLABEL 4
+ "disklabel",
NULL
};
@@ -91,6 +95,7 @@
const char *hostpath;
off_t flen;
off_t foffset;
+ char partition;
enum rump_etfs_type type;
};
@@ -123,8 +128,10 @@
char *options, *value;
char *key, *hostpath;
long long flen, foffset;
+ char partition;
flen = foffset = 0;
+ partition = 0;
key = hostpath = NULL;
options = optarg;
while (*options) {
@@ -138,6 +145,7 @@
}
key = value;
break;
+
case DFILE:
if (hostpath != NULL) {
fprintf(stderr,
@@ -146,6 +154,7 @@
}
hostpath = value;
break;
+
case DSIZE:
if (flen != 0) {
fprintf(stderr,
@@ -166,6 +175,23 @@
foffset = strsuftoll("-d offset", value,
0, LLONG_MAX);
break;
+
+ case DLABEL:
+ if (foffset != 0 || flen != 0) {
+ fprintf(stderr,
+ "disklabel needs to be "
+ "used alone\n");
+ usage();
+ }
+ if (strlen(value) != 1 ||
+ *value < 'a' || *value > 'z') {
+ fprintf(stderr,
+ "invalid label part\n");
+ usage();
+ }
+ partition = *value;
+ break;
+
default:
fprintf(stderr, "invalid dtoken\n");
usage();
@@ -173,7 +199,8 @@
}
}
- if (key == NULL || hostpath == NULL || flen == 0) {
+ if (key == NULL || hostpath == NULL ||
+ (flen == 0 && partition == 0)) {
fprintf(stderr, "incomplete drivespec\n");
usage();
}
@@ -189,6 +216,7 @@
etfs[curetfs].hostpath = hostpath;
etfs[curetfs].flen = flen;
etfs[curetfs].foffset = foffset;
+ etfs[curetfs].partition = partition;
etfs[curetfs].type = RUMP_ETFS_BLK;
curetfs++;
@@ -261,25 +289,46 @@
/* register host drives */
for (i = 0; i < curetfs; i++) {
+ char buf[1<<16];
+ struct disklabel dl;
struct stat sb;
- off_t fsize;
+ off_t foffset, flen, fendoff;
int fd;
- fsize = etfs[i].foffset + etfs[i].flen;
fd = open(etfs[i].hostpath, O_RDWR | O_CREAT, 0644);
if (fd == -1)
die(sflag, errno, "etfs hostpath create");
+
+ if (etfs[i].partition) {
+ int partition = etfs[i].partition - 'a';
+
+ pread(fd, buf, sizeof(buf), 0);
+ if (disklabel_scan(&dl, buf, sizeof(buf)))
+ die(sflag, ENOENT, "disklabel not found");
+
+ if (partition >= dl.d_npartitions)
+ die(sflag, ENOENT, "partition not available");
+
+ foffset = dl.d_partitions[partition].p_offset
+ << DEV_BSHIFT;
+ flen = dl.d_partitions[partition].p_size
+ << DEV_BSHIFT;
+ } else {
+ foffset = etfs[i].foffset;
+ flen = etfs[i].flen;
+ }
+ fendoff = foffset + flen;
+
if (fstat(fd, &sb) == -1)
die(sflag, errno, "fstat etfs hostpath");
- if (S_ISREG(sb.st_mode) && sb.st_size < fsize) {
- if (ftruncate(fd, fsize) == -1)
+ if (S_ISREG(sb.st_mode) && sb.st_size < fendoff) {
+ if (ftruncate(fd, fendoff) == -1)
die(sflag, errno, "truncate");
}
close(fd);
if ((error = rump_pub_etfs_register_withsize(etfs[i].key,
- etfs[i].hostpath, etfs[i].type,
- etfs[i].foffset, etfs[i].flen)) != 0)
+ etfs[i].hostpath, etfs[i].type, foffset, flen)) != 0)
die(sflag, error, "etfs register");
}
diff -r 6c7103496255 -r e5b8f67407a1 usr.bin/rump_server/Makefile
--- a/usr.bin/rump_server/Makefile Fri Feb 04 19:58:10 2011 +0000
+++ b/usr.bin/rump_server/Makefile Fri Feb 04 20:06:23 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.2 2010/12/13 19:39:37 pooka Exp $
+# $NetBSD: Makefile,v 1.3 2011/02/04 20:06:23 pooka Exp $
#
.PATH: ${.CURDIR}/../rump_allserver
@@ -7,6 +7,6 @@
SRCS= rump_allserver.c
NOMAN= installed by ../rump_allserver
-LDADD+= -lrump -lrumpuser -lpthread
+LDADD+= -lrump -lrumpuser -lpthread -lutil
.include <bsd.prog.mk>
Home |
Main Index |
Thread Index |
Old Index