Allow to specify -d hostpath offset,size with disklabel.
This commit is contained in:
parent
5cae2aa40c
commit
74135a6c04
@ -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 @@ RUMPTOP=${.CURDIR}/../../sys/rump
|
||||
LDADD+= ${RUMPDEVLDADD} ${RUMPFSLDADD} ${RUMPKERNLDADD} ${RUMPNETLDADD}
|
||||
LDADD+= -lrumpdev -lrumpvfs -lrumpnet -lrump -lrumpuser -lpthread
|
||||
|
||||
DPADD+= ${LIBUTIL}
|
||||
LDADD+= -lutil
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
@ -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 @@ 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.
|
||||
.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.
|
||||
|
@ -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 @@ __RCSID("$NetBSD: rump_allserver.c,v 1.15 2011/02/03 11:25:27 pooka Exp $");
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <util.h>
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
@ -83,6 +85,8 @@ static const char *const disktokens[] = {
|
||||
"size",
|
||||
#define DOFFSET 3
|
||||
"offset",
|
||||
#define DLABEL 4
|
||||
"disklabel",
|
||||
NULL
|
||||
};
|
||||
|
||||
@ -91,6 +95,7 @@ struct etfsreg {
|
||||
const char *hostpath;
|
||||
off_t flen;
|
||||
off_t foffset;
|
||||
char partition;
|
||||
enum rump_etfs_type type;
|
||||
};
|
||||
|
||||
@ -123,8 +128,10 @@ main(int argc, char *argv[])
|
||||
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 @@ main(int argc, char *argv[])
|
||||
}
|
||||
key = value;
|
||||
break;
|
||||
|
||||
case DFILE:
|
||||
if (hostpath != NULL) {
|
||||
fprintf(stderr,
|
||||
@ -146,6 +154,7 @@ main(int argc, char *argv[])
|
||||
}
|
||||
hostpath = value;
|
||||
break;
|
||||
|
||||
case DSIZE:
|
||||
if (flen != 0) {
|
||||
fprintf(stderr,
|
||||
@ -166,6 +175,23 @@ main(int argc, char *argv[])
|
||||
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 @@ main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ main(int argc, char *argv[])
|
||||
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 @@ main(int argc, char *argv[])
|
||||
|
||||
/* 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");
|
||||
}
|
||||
|
||||
|
@ -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 @@ PROG= rump_server
|
||||
SRCS= rump_allserver.c
|
||||
NOMAN= installed by ../rump_allserver
|
||||
|
||||
LDADD+= -lrump -lrumpuser -lpthread
|
||||
LDADD+= -lrump -lrumpuser -lpthread -lutil
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
Loading…
Reference in New Issue
Block a user