Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/librumpuser Split out file and memory access in librumpuser



details:   https://anonhg.NetBSD.org/src/rev/9b886e4d0c5b
branches:  trunk
changeset: 330463:9b886e4d0c5b
user:      justin <justin%NetBSD.org@localhost>
date:      Wed Jul 09 23:41:40 2014 +0000

description:
Split out file and memory access in librumpuser

This allows alternate implementations to reuse these parts, and the file
parts will at the next hypercall revision be moved to their own driver.

Discussed with pooka@

diffstat:

 lib/librumpuser/Makefile        |    3 +-
 lib/librumpuser/rumpuser.c      |  360 +---------------------------------------
 lib/librumpuser/rumpuser_file.c |  339 +++++++++++++++++++++++++++++++++++++
 lib/librumpuser/rumpuser_mem.c  |  109 ++++++++++++
 4 files changed, 453 insertions(+), 358 deletions(-)

diffs (truncated from 862 to 300 lines):

diff -r 0736ecdf4b09 -r 9b886e4d0c5b lib/librumpuser/Makefile
--- a/lib/librumpuser/Makefile  Wed Jul 09 20:22:55 2014 +0000
+++ b/lib/librumpuser/Makefile  Wed Jul 09 23:41:40 2014 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.18 2014/06/17 08:42:35 alnsn Exp $
+#      $NetBSD: Makefile,v 1.19 2014/07/09 23:41:40 justin Exp $
 #
 
 .include <bsd.own.mk>
@@ -20,6 +20,7 @@
 SRCS=          rumpuser.c
 SRCS+=         rumpuser_pth.c
 SRCS+=         rumpuser_component.c rumpuser_bio.c
+SRCS+=         rumpuser_file.c rumpuser_mem.c
 
 SRCS+=         rumpuser_errtrans.c rumpuser_sigtrans.c
 
diff -r 0736ecdf4b09 -r 9b886e4d0c5b lib/librumpuser/rumpuser.c
--- a/lib/librumpuser/rumpuser.c        Wed Jul 09 20:22:55 2014 +0000
+++ b/lib/librumpuser/rumpuser.c        Wed Jul 09 23:41:40 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rumpuser.c,v 1.59 2014/04/02 13:54:42 pooka Exp $      */
+/*     $NetBSD: rumpuser.c,v 1.60 2014/07/09 23:41:40 justin Exp $     */
 
 /*
  * Copyright (c) 2007-2010 Antti Kantee.  All Rights Reserved.
@@ -28,34 +28,16 @@
 #include "rumpuser_port.h"
 
 #if !defined(lint)
-__RCSID("$NetBSD: rumpuser.c,v 1.59 2014/04/02 13:54:42 pooka Exp $");
+__RCSID("$NetBSD: rumpuser.c,v 1.60 2014/07/09 23:41:40 justin Exp $");
 #endif /* !lint */
 
-#include <sys/ioctl.h>
-#include <sys/mman.h>
-#include <sys/uio.h>
 #include <sys/stat.h>
 #include <sys/time.h>
-
-#ifdef __NetBSD__
-#include <sys/disk.h>
-#include <sys/disklabel.h>
-#include <sys/dkio.h>
-#endif
-
-#if defined(__NetBSD__) || defined(__FreeBSD__) || \
-    defined(__DragonFly__) || defined(__APPLE__)
-#define        __BSD__
-#endif
-
-#if defined(__BSD__)
-#include <sys/sysctl.h>
-#endif
+#include <sys/types.h>
 
 #include <assert.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <netdb.h>
 #include <signal.h>
 #include <stdarg.h>
 #include <stdint.h>
@@ -103,342 +85,6 @@
 }
 
 int
-rumpuser_getfileinfo(const char *path, uint64_t *sizep, int *ftp)
-{
-       struct stat sb;
-       uint64_t size = 0;
-       int needsdev = 0, rv = 0, ft = 0;
-       int fd = -1;
-
-       if (stat(path, &sb) == -1) {
-               rv = errno;
-               goto out;
-       }
-
-       switch (sb.st_mode & S_IFMT) {
-       case S_IFDIR:
-               ft = RUMPUSER_FT_DIR;
-               break;
-       case S_IFREG:
-               ft = RUMPUSER_FT_REG;
-               break;
-       case S_IFBLK:
-               ft = RUMPUSER_FT_BLK;
-               needsdev = 1;
-               break;
-       case S_IFCHR:
-               ft = RUMPUSER_FT_CHR;
-               needsdev = 1;
-               break;
-       default:
-               ft = RUMPUSER_FT_OTHER;
-               break;
-       }
-
-       if (!needsdev) {
-               size = sb.st_size;
-       } else if (sizep) {
-               /*
-                * Welcome to the jungle.  Of course querying the kernel
-                * for a device partition size is supposed to be far from
-                * trivial.  On NetBSD we use ioctl.  On $other platform
-                * we have a problem.  We try "the lseek trick" and just
-                * fail if that fails.  Platform specific code can later
-                * be written here if appropriate.
-                *
-                * On NetBSD we hope and pray that for block devices nobody
-                * else is holding them open, because otherwise the kernel
-                * will not permit us to open it.  Thankfully, this is
-                * usually called only in bootstrap and then we can
-                * forget about it.
-                */
-#ifndef __NetBSD__
-               off_t off;
-
-               fd = open(path, O_RDONLY);
-               if (fd == -1) {
-                       rv = errno;
-                       goto out;
-               }
-
-               off = lseek(fd, 0, SEEK_END);
-               if (off != 0) {
-                       size = off;
-                       goto out;
-               }
-               fprintf(stderr, "error: device size query not implemented on "
-                   "this platform\n");
-               rv = EOPNOTSUPP;
-               goto out;
-#else
-               struct disklabel lab;
-               struct partition *parta;
-               struct dkwedge_info dkw;
-
-               fd = open(path, O_RDONLY);
-               if (fd == -1) {
-                       rv = errno;
-                       goto out;
-               }
-
-               if (ioctl(fd, DIOCGDINFO, &lab) == 0) {
-                       parta = &lab.d_partitions[DISKPART(sb.st_rdev)];
-                       size = (uint64_t)lab.d_secsize * parta->p_size;
-                       goto out;
-               }
-
-               if (ioctl(fd, DIOCGWEDGEINFO, &dkw) == 0) {
-                       /*
-                        * XXX: should use DIOCGDISKINFO to query
-                        * sector size, but that requires proplib,
-                        * so just don't bother for now.  it's nice
-                        * that something as difficult as figuring out
-                        * a partition's size has been made so easy.
-                        */
-                       size = dkw.dkw_size << DEV_BSHIFT;
-                       goto out;
-               }
-
-               rv = errno;
-#endif /* __NetBSD__ */
-       }
-
- out:
-       if (rv == 0 && sizep)
-               *sizep = size;
-       if (rv == 0 && ftp)
-               *ftp = ft;
-       if (fd != -1)
-               close(fd);
-
-       ET(rv);
-}
-
-int
-rumpuser_malloc(size_t howmuch, int alignment, void **memp)
-{
-       void *mem = NULL;
-       int rv;
-
-       if (alignment == 0)
-               alignment = sizeof(void *);
-
-       rv = posix_memalign(&mem, (size_t)alignment, howmuch);
-       if (__predict_false(rv != 0)) {
-               if (rv == EINVAL) {
-                       printf("rumpuser_malloc: invalid alignment %d\n",
-                           alignment);
-                       abort();
-               }
-       }
-
-       *memp = mem;
-       ET(rv);
-}
-
-/*ARGSUSED1*/
-void
-rumpuser_free(void *ptr, size_t size)
-{
-
-       free(ptr);
-}
-
-int
-rumpuser_anonmmap(void *prefaddr, size_t size, int alignbit,
-       int exec, void **memp)
-{
-       void *mem;
-       int prot, rv;
-
-#ifndef MAP_ALIGNED
-#define MAP_ALIGNED(a) 0
-       if (alignbit)
-               fprintf(stderr, "rumpuser_anonmmap: warning, requested "
-                   "alignment not supported by hypervisor\n");
-#endif
-
-       prot = PROT_READ|PROT_WRITE;
-       if (exec)
-               prot |= PROT_EXEC;
-       mem = mmap(prefaddr, size, prot,
-           MAP_PRIVATE | MAP_ANON | MAP_ALIGNED(alignbit), -1, 0);
-       if (mem == MAP_FAILED) {
-               rv = errno;
-       } else {
-               *memp = mem;
-               rv = 0;
-       }
-
-       ET(rv);
-}
-
-void
-rumpuser_unmap(void *addr, size_t len)
-{
-
-       munmap(addr, len);
-}
-
-int
-rumpuser_open(const char *path, int ruflags, int *fdp)
-{
-       int fd, flags, rv;
-
-       switch (ruflags & RUMPUSER_OPEN_ACCMODE) {
-       case RUMPUSER_OPEN_RDONLY:
-               flags = O_RDONLY;
-               break;
-       case RUMPUSER_OPEN_WRONLY:
-               flags = O_WRONLY;
-               break;
-       case RUMPUSER_OPEN_RDWR:
-               flags = O_RDWR;
-               break;
-       default:
-               rv = EINVAL;
-               goto out;
-       }
-
-#define TESTSET(_ru_, _h_) if (ruflags & _ru_) flags |= _h_;
-       TESTSET(RUMPUSER_OPEN_CREATE, O_CREAT);
-       TESTSET(RUMPUSER_OPEN_EXCL, O_EXCL);
-#undef TESTSET
-
-       KLOCK_WRAP(fd = open(path, flags, 0644));
-       if (fd == -1) {
-               rv = errno;
-       } else {
-               *fdp = fd;
-               rv = 0;
-       }
-
- out:
-       ET(rv);
-}
-
-int
-rumpuser_close(int fd)
-{
-       int nlocks;
-
-       rumpkern_unsched(&nlocks, NULL);
-       fsync(fd);
-       close(fd);
-       rumpkern_sched(nlocks, NULL);
-
-       ET(0);
-}
-
-/*
- * Assume "struct rumpuser_iovec" and "struct iovec" are the same.
- * If you encounter POSIX platforms where they aren't, add some
- * translation for iovlen > 1.
- */
-int



Home | Main Index | Thread Index | Old Index