Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib Migrate from rump private interfaces to syscalls.
details: https://anonhg.NetBSD.org/src/rev/9dc4e3feb128
branches: trunk
changeset: 757611:9dc4e3feb128
user: pooka <pooka%NetBSD.org@localhost>
date: Tue Sep 07 17:16:18 2010 +0000
description:
Migrate from rump private interfaces to syscalls.
diffstat:
lib/libp2k/p2k.c | 14 +--
lib/libukfs/ukfs.c | 163 +++++++++++++++++++++++++++++-----------------------
2 files changed, 97 insertions(+), 80 deletions(-)
diffs (truncated from 427 to 300 lines):
diff -r 3aa077338e38 -r 9dc4e3feb128 lib/libp2k/p2k.c
--- a/lib/libp2k/p2k.c Tue Sep 07 17:14:18 2010 +0000
+++ b/lib/libp2k/p2k.c Tue Sep 07 17:16:18 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: p2k.c,v 1.42 2010/09/01 19:40:35 pooka Exp $ */
+/* $NetBSD: p2k.c,v 1.43 2010/09/07 17:16:19 pooka Exp $ */
/*
* Copyright (c) 2007, 2008, 2009 Antti Kantee. All Rights Reserved.
@@ -420,12 +420,6 @@
rv = -1;
goto out;
}
- if ((rv = rump_pub_vfs_root(p2m->p2m_mp,
- &p2m->p2m_rvp, 0)) != 0) {
- errno = rv;
- rv = -1;
- goto out;
- }
} else {
if (part != ukfs_part_na)
ukfs = ukfs_mount_disk(vfsname, devpath, part,
@@ -438,7 +432,11 @@
ukfs_setspecific(ukfs, p2m);
p2m->p2m_ukfs = ukfs;
p2m->p2m_mp = ukfs_getmp(ukfs);
- p2m->p2m_rvp = ukfs_getrvp(ukfs);
+ }
+ if ((rv = rump_pub_vfs_root(p2m->p2m_mp, &p2m->p2m_rvp, 0)) != 0) {
+ errno = rv;
+ rv = -1;
+ goto out;
}
p2m->p2m_pu = pu;
diff -r 3aa077338e38 -r 9dc4e3feb128 lib/libukfs/ukfs.c
--- a/lib/libukfs/ukfs.c Tue Sep 07 17:14:18 2010 +0000
+++ b/lib/libukfs/ukfs.c Tue Sep 07 17:16:18 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ukfs.c,v 1.53 2010/09/01 19:40:34 pooka Exp $ */
+/* $NetBSD: ukfs.c,v 1.54 2010/09/07 17:16:18 pooka Exp $ */
/*
* Copyright (c) 2007, 2008, 2009 Antti Kantee. All Rights Reserved.
@@ -69,15 +69,18 @@
#define UKFS_MODE_DEFAULT 0555
struct ukfs {
+ pthread_spinlock_t ukfs_spin;
+
struct mount *ukfs_mp;
- struct vnode *ukfs_rvp;
+ struct lwp *ukfs_lwp;
void *ukfs_specific;
- pthread_spinlock_t ukfs_spin;
- struct vnode *ukfs_cdir;
int ukfs_devfd;
+
char *ukfs_devpath;
char *ukfs_mountpath;
+ char *ukfs_cwd;
+
struct ukfs_part *ukfs_part;
};
@@ -91,17 +94,6 @@
return ukfs->ukfs_mp;
}
-struct vnode *
-ukfs_getrvp(struct ukfs *ukfs)
-{
- struct vnode *rvp;
-
- rvp = ukfs->ukfs_rvp;
- rump_pub_vp_incref(rvp);
-
- return rvp;
-}
-
void
ukfs_setspecific(struct ukfs *ukfs, void *priv)
{
@@ -123,32 +115,45 @@
#define pthread_spin_destroy(a)
#endif
-static void
-precall(struct ukfs *ukfs)
+static int
+precall(struct ukfs *ukfs, struct lwp **curlwp)
{
- struct vnode *rvp, *cvp;
+ /* save previous. ensure start from pristine context */
+ *curlwp = rump_pub_lwproc_curlwp();
+ if (*curlwp)
+ rump_pub_lwproc_switch(ukfs->ukfs_lwp);
rump_pub_lwproc_newproc();
- rvp = ukfs_getrvp(ukfs);
- pthread_spin_lock(&ukfs->ukfs_spin);
- cvp = ukfs->ukfs_cdir;
- pthread_spin_unlock(&ukfs->ukfs_spin);
- rump_pub_rcvp_set(rvp, cvp); /* takes refs */
- rump_pub_vp_rele(rvp);
+
+ if (rump_sys_chroot(ukfs->ukfs_mountpath) == -1)
+ return errno;
+ if (rump_sys_chdir(ukfs->ukfs_cwd) == -1)
+ return errno;
+
+ return 0;
}
static void
-postcall(struct ukfs *ukfs)
+postcall(struct lwp *curlwp)
{
- struct vnode *rvp;
-
- rvp = ukfs_getrvp(ukfs);
- rump_pub_rcvp_set(NULL, rvp);
- rump_pub_vp_rele(rvp);
rump_pub_lwproc_releaselwp();
+ if (curlwp)
+ rump_pub_lwproc_switch(curlwp);
}
+#define PRECALL() \
+struct lwp *ukfs_curlwp; \
+do { \
+ int ukfs_rv; \
+ if ((ukfs_rv = precall(ukfs, &ukfs_curlwp)) != 0) { \
+ errno = ukfs_rv; \
+ return -1; \
+ } \
+} while (/*CONSTCOND*/0)
+
+#define POSTCALL() postcall(ukfs_curlwp);
+
struct ukfs_part {
pthread_spinlock_t part_lck;
int part_refcount;
@@ -516,6 +521,7 @@
const char *mountpath, int mntflags, void *arg, size_t alen)
{
struct ukfs *fs = NULL;
+ struct lwp *curlwp;
int rv = 0, devfd = -1;
int mounted = 0;
int regged = 0;
@@ -603,26 +609,25 @@
if (rv) {
goto out;
}
- rv = rump_pub_vfs_root(fs->ukfs_mp, &fs->ukfs_rvp, 0);
- if (rv) {
- goto out;
- }
if (regged) {
fs->ukfs_devpath = strdup(devpath);
}
fs->ukfs_mountpath = strdup(mountpath);
- fs->ukfs_cdir = ukfs_getrvp(fs);
pthread_spin_init(&fs->ukfs_spin, PTHREAD_PROCESS_SHARED);
fs->ukfs_devfd = devfd;
fs->ukfs_part = part;
assert(rv == 0);
+ curlwp = rump_pub_lwproc_curlwp();
+ rump_pub_lwproc_newlwp(0);
+ fs->ukfs_lwp = rump_pub_lwproc_curlwp();
+ fs->ukfs_cwd = strdup("/");
+ rump_pub_lwproc_switch(curlwp);
+
out:
if (rv) {
if (fs) {
- if (fs->ukfs_rvp)
- rump_pub_vp_rele(fs->ukfs_rvp);
free(fs);
fs = NULL;
}
@@ -663,27 +668,28 @@
int
ukfs_release(struct ukfs *fs, int flags)
{
+ struct lwp *curlwp = rump_pub_lwproc_curlwp();
+
+ /* get root lwp */
+ rump_pub_lwproc_switch(fs->ukfs_lwp);
+ rump_pub_lwproc_newproc();
if ((flags & UKFS_RELFLAG_NOUNMOUNT) == 0) {
int rv, mntflag, error;
- ukfs_chdir(fs, "/");
mntflag = 0;
if (flags & UKFS_RELFLAG_FORCE)
mntflag = MNT_FORCE;
- rump_pub_lwproc_newproc();
- rump_pub_vp_rele(fs->ukfs_rvp);
- fs->ukfs_rvp = NULL;
+
rv = rump_sys_unmount(fs->ukfs_mountpath, mntflag);
if (rv == -1) {
error = errno;
- rump_pub_vfs_root(fs->ukfs_mp, &fs->ukfs_rvp, 0);
rump_pub_lwproc_releaselwp();
- ukfs_chdir(fs, fs->ukfs_mountpath);
+ if (curlwp)
+ rump_pub_lwproc_switch(curlwp);
errno = error;
return -1;
}
- rump_pub_lwproc_releaselwp();
}
if (fs->ukfs_devpath) {
@@ -691,6 +697,12 @@
free(fs->ukfs_devpath);
}
free(fs->ukfs_mountpath);
+ free(fs->ukfs_cwd);
+
+ /* release this routine's lwp and ukfs base lwp */
+ rump_pub_lwproc_releaselwp();
+ rump_pub_lwproc_switch(fs->ukfs_lwp);
+ rump_pub_lwproc_releaselwp();
pthread_spin_destroy(&fs->ukfs_spin);
if (fs->ukfs_devfd != -1) {
@@ -700,6 +712,9 @@
ukfs_part_release(fs->ukfs_part);
free(fs);
+ if (curlwp)
+ rump_pub_lwproc_switch(curlwp);
+
return 0;
}
@@ -722,9 +737,9 @@
#define STDCALL(ukfs, thecall) \
int rv = 0; \
\
- precall(ukfs); \
+ PRECALL(); \
rv = thecall; \
- postcall(ukfs); \
+ POSTCALL(); \
return rv;
int
@@ -733,10 +748,10 @@
struct vnode *vp;
int rv;
- precall(ukfs);
+ PRECALL();
rv = rump_pub_namei(RUMP_NAMEI_LOOKUP, RUMP_NAMEI_LOCKLEAF, dirname,
NULL, &vp, NULL);
- postcall(ukfs);
+ POSTCALL();
if (rv == 0) {
RUMP_VOP_UNLOCK(vp);
@@ -794,17 +809,18 @@
struct vnode *vp;
int rv;
- precall(ukfs);
+ PRECALL();
rv = rump_pub_namei(RUMP_NAMEI_LOOKUP, RUMP_NAMEI_LOCKLEAF, dirname,
NULL, &vp, NULL);
- postcall(ukfs);
if (rv) {
+ POSTCALL();
errno = rv;
return -1;
}
rv = getmydents(vp, off, buf, bufsize);
rump_pub_vp_rele(vp);
+ POSTCALL();
return rv;
}
@@ -823,9 +839,9 @@
{
int fd;
- precall(ukfs);
+ PRECALL();
fd = rump_sys_open(filename, flags, 0);
- postcall(ukfs);
+ POSTCALL();
Home |
Main Index |
Thread Index |
Old Index