Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/rump Allow to set size and host file offset for etfs fil...
details: https://anonhg.NetBSD.org/src/rev/7db8b8721870
branches: trunk
changeset: 747966:7db8b8721870
user: pooka <pooka%NetBSD.org@localhost>
date: Wed Oct 07 09:17:54 2009 +0000
description:
Allow to set size and host file offset for etfs files and rumpblk.
diffstat:
sys/rump/include/rump/rump.h | 5 ++-
sys/rump/librump/rumpvfs/rump_vfs_private.h | 5 +-
sys/rump/librump/rumpvfs/rumpblk.c | 54 +++++++++++++++++++---------
sys/rump/librump/rumpvfs/rumpfs.c | 51 +++++++++++++++++++++++---
4 files changed, 88 insertions(+), 27 deletions(-)
diffs (277 lines):
diff -r 786a063ff73c -r 7db8b8721870 sys/rump/include/rump/rump.h
--- a/sys/rump/include/rump/rump.h Wed Oct 07 08:47:47 2009 +0000
+++ b/sys/rump/include/rump/rump.h Wed Oct 07 09:17:54 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rump.h,v 1.25 2009/10/06 16:23:03 pooka Exp $ */
+/* $NetBSD: rump.h,v 1.26 2009/10/07 09:17:54 pooka Exp $ */
/*
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
@@ -95,7 +95,10 @@
void rump_getvninfo(struct vnode *, enum vtype *, off_t * /*XXX*/, dev_t *);
enum rump_etfs_type { RUMP_ETFS_REG, RUMP_ETFS_BLK, RUMP_ETFS_CHR };
+#define RUMP_ETFS_SIZE_ENDOFF ((uint64_t)-1)
int rump_etfs_register(const char *, const char *, enum rump_etfs_type);
+int rump_etfs_register_withsize(const char *, const char *,
+ enum rump_etfs_type, uint64_t, uint64_t);
int rump_etfs_remove(const char *);
struct vfsops *rump_vfslist_iterate(struct vfsops *);
diff -r 786a063ff73c -r 7db8b8721870 sys/rump/librump/rumpvfs/rump_vfs_private.h
--- a/sys/rump/librump/rumpvfs/rump_vfs_private.h Wed Oct 07 08:47:47 2009 +0000
+++ b/sys/rump/librump/rumpvfs/rump_vfs_private.h Wed Oct 07 09:17:54 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rump_vfs_private.h,v 1.4 2009/09/06 20:42:25 pooka Exp $ */
+/* $NetBSD: rump_vfs_private.h,v 1.5 2009/10/07 09:17:54 pooka Exp $ */
/*
* Copyright (c) 2008 Antti Kantee. All Rights Reserved.
@@ -34,7 +34,8 @@
void rumpfs_init(void);
#define RUMPBLK 254
-int rumpblk_register(const char *, devminor_t *);
+#define RUMPBLK_SIZENOTSET ((uint64_t)-1)
+int rumpblk_register(const char *, devminor_t *, uint64_t, uint64_t);
int rumpblk_init(void);
void rump_biodone(void *, size_t, int);
diff -r 786a063ff73c -r 7db8b8721870 sys/rump/librump/rumpvfs/rumpblk.c
--- a/sys/rump/librump/rumpvfs/rumpblk.c Wed Oct 07 08:47:47 2009 +0000
+++ b/sys/rump/librump/rumpvfs/rumpblk.c Wed Oct 07 09:17:54 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rumpblk.c,v 1.26 2009/10/06 13:05:44 pooka Exp $ */
+/* $NetBSD: rumpblk.c,v 1.27 2009/10/07 09:17:54 pooka Exp $ */
/*
* Copyright (c) 2009 Antti Kantee. All Rights Reserved.
@@ -43,7 +43,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rumpblk.c,v 1.26 2009/10/06 13:05:44 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rumpblk.c,v 1.27 2009/10/07 09:17:54 pooka Exp $");
#include <sys/param.h>
#include <sys/buf.h>
@@ -94,6 +94,8 @@
int rblk_dfd;
#endif
uint64_t rblk_size;
+ uint64_t rblk_hostoffset;
+ int rblk_ftype;
/* for mmap */
int rblk_mmflags;
@@ -327,14 +329,24 @@
/* XXX: no deregister */
int
-rumpblk_register(const char *path, devminor_t *dmin)
+rumpblk_register(const char *path, devminor_t *dmin,
+ uint64_t offset, uint64_t size)
{
+ struct rblkdev *rblk;
uint64_t flen;
size_t len;
- int ftype, error, i;
+ int ftype, error, dummy, i;
+ int fd;
- if (rumpuser_getfileinfo(path, &flen, &ftype, &error))
+ /* devices might not report correct size unless they're open */
+ fd = rumpuser_open(path, O_RDONLY, &error);
+ if (fd == -1)
return error;
+ rumpuser_getfileinfo(path, &flen, &ftype, &error);
+ rumpuser_close(fd, &dummy);
+ if (error)
+ return error;
+
/* verify host file is of supported type */
if (!(ftype == RUMPUSER_FT_REG
|| ftype == RUMPUSER_FT_BLK
@@ -358,10 +370,20 @@
return EBUSY;
}
+ rblk = &minors[i];
len = strlen(path);
- minors[i].rblk_path = malloc(len + 1, M_TEMP, M_WAITOK);
- strcpy(minors[i].rblk_path, path);
- minors[i].rblk_fd = -1;
+ rblk->rblk_path = malloc(len + 1, M_TEMP, M_WAITOK);
+ strcpy(rblk->rblk_path, path);
+ rblk->rblk_fd = -1;
+ rblk->rblk_hostoffset = offset;
+ if (size == RUMPBLK_SIZENOTSET) {
+ KASSERT(size + offset <= flen);
+ rblk->rblk_size = size;
+ } else {
+ KASSERT(offset < flen);
+ rblk->rblk_size = flen - offset;
+ }
+ rblk->rblk_ftype = ftype;
mutex_exit(&rumpblk_lock);
*dmin = i;
@@ -373,20 +395,18 @@
{
struct rblkdev *rblk = &minors[minor(dev)];
uint64_t fsize;
- int ft, dummy;
+ int dummy;
int error, fd;
+ if (rblk->rblk_path == NULL)
+ return ENXIO;
+
if (rblk->rblk_fd != -1)
return 0; /* XXX: refcount, open mode */
fd = rumpuser_open(rblk->rblk_path, OFLAGS(flag), &error);
if (error)
return error;
- if (rumpuser_getfileinfo(rblk->rblk_path, &fsize, &ft, &error) == -1) {
- rumpuser_close(fd, &dummy);
- return error;
- }
-
#ifdef HAS_ODIRECT
rblk->rblk_dfd = rumpuser_open(rblk->rblk_path,
OFLAGS(flag) | O_DIRECT, &error);
@@ -394,7 +414,7 @@
return error;
#endif
- if (ft == RUMPUSER_FT_REG) {
+ if (rblk->rblk_ftype == RUMPUSER_FT_REG) {
struct blkwin *win;
int i, winsize;
@@ -413,7 +433,6 @@
}
TAILQ_INIT(&rblk->rblk_lruq);
- rblk->rblk_size = fsize;
rblk->rblk_fd = fd;
for (i = 0; i < memwincnt && i * memwinsize < fsize; i++) {
@@ -541,13 +560,14 @@
}
off = bp->b_blkno << DEV_BSHIFT;
+ off += rblk->rblk_hostoffset;
/*
* Do bounds checking if we're working on a file. Otherwise
* invalid file systems might attempt to read beyond EOF. This
* is bad(tm) especially on mmapped images. This is essentially
* the kernel bounds_check() routines.
*/
- if (rblk->rblk_size && off + bp->b_bcount > rblk->rblk_size) {
+ if (off + bp->b_bcount > rblk->rblk_size) {
int64_t sz = rblk->rblk_size - off;
/* EOF */
diff -r 786a063ff73c -r 7db8b8721870 sys/rump/librump/rumpvfs/rumpfs.c
--- a/sys/rump/librump/rumpvfs/rumpfs.c Wed Oct 07 08:47:47 2009 +0000
+++ b/sys/rump/librump/rumpvfs/rumpfs.c Wed Oct 07 09:17:54 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rumpfs.c,v 1.24 2009/10/04 16:31:08 pooka Exp $ */
+/* $NetBSD: rumpfs.c,v 1.25 2009/10/07 09:17:54 pooka Exp $ */
/*
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
@@ -28,7 +28,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rumpfs.c,v 1.24 2009/10/04 16:31:08 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rumpfs.c,v 1.25 2009/10/07 09:17:54 pooka Exp $");
#include <sys/param.h>
#include <sys/atomic.h>
@@ -199,9 +199,9 @@
return rv;
}
-int
-rump_etfs_register(const char *key, const char *hostpath,
- enum rump_etfs_type ftype)
+static int
+doregister(const char *key, const char *hostpath,
+ enum rump_etfs_type ftype, uint64_t begin, uint64_t size)
{
struct etfs *et;
struct rumpfs_node *rn_dummy;
@@ -213,8 +213,16 @@
if (rumpuser_getfileinfo(hostpath, &fsize, &hft, &error))
return error;
+ /* check that we give sensible arguments */
+ if (begin > fsize)
+ return EINVAL;
+ if (size == RUMP_ETFS_SIZE_ENDOFF)
+ size = fsize - begin;
+ if (begin + size > fsize)
+ return EINVAL;
+
if (ftype == RUMP_ETFS_BLK || ftype == RUMP_ETFS_CHR) {
- error = rumpblk_register(hostpath, &dmin);
+ error = rumpblk_register(hostpath, &dmin, begin, size);
if (error != 0) {
return error;
}
@@ -224,7 +232,7 @@
et = kmem_alloc(sizeof(*et), KM_SLEEP);
strcpy(et->et_key, key);
et->et_keylen = strlen(et->et_key);
- et->et_rn = makeprivate(ettype_to_vtype(ftype), rdev, fsize, hostpath);
+ et->et_rn = makeprivate(ettype_to_vtype(ftype), rdev, size, hostpath);
mutex_enter(&etfs_lock);
if (etfs_find(key, &rn_dummy)) {
@@ -240,6 +248,33 @@
}
int
+rump_etfs_register(const char *key, const char *hostpath,
+ enum rump_etfs_type ftype)
+{
+
+ return doregister(key, hostpath, ftype, 0, RUMP_ETFS_SIZE_ENDOFF);
+}
+
+int
+rump_etfs_register_withsize(const char *key, const char *hostpath,
+ enum rump_etfs_type ftype, uint64_t begin, uint64_t size)
+{
+
+ /*
+ * Check that we're mapping at block offsets. I guess this
+ * is not technically necessary except for BLK/CHR backends
+ * (i.e. what getfileinfo() returns, not ftype) and can be
+ * removed later if there are problems.
+ */
+ if ((begin & (DEV_BSIZE-1)) != 0)
+ return EINVAL;
+ if (size != RUMP_ETFS_SIZE_ENDOFF && (size & (DEV_BSIZE-1)) != 0)
+ return EINVAL;
+
+ return doregister(key, hostpath, ftype, begin, size);
+}
+
+int
rump_etfs_remove(const char *key)
{
struct etfs *et;
@@ -688,6 +723,8 @@
struct rumpfs_node *rn;
int rv;
+ CTASSERT(RUMP_ETFS_SIZE_ENDOFF == RUMPBLK_SIZENOTSET);
+
mutex_init(&reclock, MUTEX_DEFAULT, IPL_NONE);
mutex_init(&etfs_lock, MUTEX_DEFAULT, IPL_NONE);
Home |
Main Index |
Thread Index |
Old Index