Open the kernel descriptor as part of mount(), not init(). Then
it doesn't matter if someone fork()s or does other tricks between init() and mount() (and besides, now it's where it logically should be).
This commit is contained in:
parent
210515ea9c
commit
a02fe51bef
|
@ -1,4 +1,4 @@
|
|||
.\" $NetBSD: puffs.3,v 1.31 2007/11/05 17:48:17 pooka Exp $
|
||||
.\" $NetBSD: puffs.3,v 1.32 2007/11/06 15:09:07 pooka Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2006, 2007 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 July 18, 2007
|
||||
.Dd November 6, 2007
|
||||
.Dt PUFFS 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
|
@ -254,11 +254,14 @@ and
|
|||
.Xr kqueue 2
|
||||
are all examples of acceptable operations.
|
||||
.It Fn puffs_setblockingmode "pu" "mode"
|
||||
Sets the library to blocking or non-blocking mode.
|
||||
Sets the file system upstream access to blocking or non-blocking mode.
|
||||
Acceptable values for the argument are
|
||||
.Dv PUFFSDEV_BLOCK
|
||||
and
|
||||
.Dv PUFFSDEV_NONBLOCK .
|
||||
.Pp
|
||||
This routine can be called only after calling
|
||||
.Fn puffs_mount .
|
||||
.It Fn puffs_getstate "pu"
|
||||
Returns the state of the file system.
|
||||
It is maintained by the framework and is mostly useful for the framework
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: puffs.c,v 1.73 2007/11/05 17:48:17 pooka Exp $ */
|
||||
/* $NetBSD: puffs.c,v 1.74 2007/11/06 15:09:08 pooka Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2005, 2006, 2007 Antti Kantee. All Rights Reserved.
|
||||
|
@ -31,7 +31,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#if !defined(lint)
|
||||
__RCSID("$NetBSD: puffs.c,v 1.73 2007/11/05 17:48:17 pooka Exp $");
|
||||
__RCSID("$NetBSD: puffs.c,v 1.74 2007/11/06 15:09:08 pooka Exp $");
|
||||
#endif /* !lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
|
@ -124,6 +124,8 @@ puffs_setblockingmode(struct puffs_usermount *pu, int mode)
|
|||
{
|
||||
int rv, x;
|
||||
|
||||
assert(puffs_getstate(pu) == PUFFS_STATE_RUNNING);
|
||||
|
||||
if (mode != PUFFSDEV_BLOCK && mode != PUFFSDEV_NONBLOCK) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
|
@ -345,7 +347,7 @@ puffs_mount(struct puffs_usermount *pu, const char *dir, int mntflags,
|
|||
void *cookie)
|
||||
{
|
||||
char rp[MAXPATHLEN];
|
||||
int rv;
|
||||
int rv, fd;
|
||||
|
||||
#if 1
|
||||
/* XXXkludgehere */
|
||||
|
@ -362,6 +364,16 @@ puffs_mount(struct puffs_usermount *pu, const char *dir, int mntflags,
|
|||
warnx("puffs_mount: using \"%s\" instead.", rp);
|
||||
}
|
||||
|
||||
fd = open(_PATH_PUFFS, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
warnx("puffs_mount: cannot open %s", _PATH_PUFFS);
|
||||
return -1;
|
||||
}
|
||||
if (fd <= 2)
|
||||
warnx("puffs_init: device fd %d (<= 2), sure this is "
|
||||
"what you want?", fd);
|
||||
|
||||
pu->pu_kargp->pa_fd = pu->pu_fd = fd;
|
||||
pu->pu_kargp->pa_root_cookie = cookie;
|
||||
if ((rv = mount(MOUNT_PUFFS, rp, mntflags,
|
||||
pu->pu_kargp, sizeof(struct puffs_kargs))) == -1)
|
||||
|
@ -385,7 +397,7 @@ _puffs_init(int develv, struct puffs_ops *pops, const char *mntfromname,
|
|||
{
|
||||
struct puffs_usermount *pu;
|
||||
struct puffs_kargs *pargs;
|
||||
int sverrno, fd;
|
||||
int sverrno;
|
||||
|
||||
if (develv != PUFFS_DEVEL_LIBVERSION) {
|
||||
warnx("puffs_init: mounting with lib version %d, need %d",
|
||||
|
@ -394,15 +406,6 @@ _puffs_init(int develv, struct puffs_ops *pops, const char *mntfromname,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
fd = open(_PATH_PUFFS, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
warnx("puffs_init: cannot open %s", _PATH_PUFFS);
|
||||
return NULL;
|
||||
}
|
||||
if (fd <= 2)
|
||||
warnx("puffs_init: device fd %d (<= 2), sure this is "
|
||||
"what you want?", fd);
|
||||
|
||||
pu = malloc(sizeof(struct puffs_usermount));
|
||||
if (pu == NULL)
|
||||
goto failfree;
|
||||
|
@ -415,7 +418,6 @@ _puffs_init(int develv, struct puffs_ops *pops, const char *mntfromname,
|
|||
|
||||
pargs->pa_vers = PUFFSDEVELVERS | PUFFSVERSION;
|
||||
pargs->pa_flags = PUFFS_FLAG_KERN(pflags);
|
||||
pargs->pa_fd = pu->pu_fd = fd;
|
||||
fillvnopmask(pops, pargs->pa_vnopmask);
|
||||
(void)strlcpy(pargs->pa_typename, puffsname,
|
||||
sizeof(pargs->pa_typename));
|
||||
|
@ -459,7 +461,6 @@ _puffs_init(int develv, struct puffs_ops *pops, const char *mntfromname,
|
|||
failfree:
|
||||
/* can't unmount() from here for obvious reasons */
|
||||
sverrno = errno;
|
||||
close(fd);
|
||||
free(pu);
|
||||
errno = sverrno;
|
||||
return NULL;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: ninepuffs.c,v 1.20 2007/11/05 17:54:32 pooka Exp $ */
|
||||
/* $NetBSD: ninepuffs.c,v 1.21 2007/11/06 15:09:08 pooka Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
|
||||
|
@ -31,7 +31,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: ninepuffs.c,v 1.20 2007/11/05 17:54:32 pooka Exp $");
|
||||
__RCSID("$NetBSD: ninepuffs.c,v 1.21 2007/11/06 15:09:08 pooka Exp $");
|
||||
#endif /* !lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
@ -209,9 +209,6 @@ main(int argc, char *argv[])
|
|||
exit(1);
|
||||
}
|
||||
|
||||
if (puffs_setblockingmode(pu, PUFFSDEV_NONBLOCK) == -1)
|
||||
err(1, "setblockingmode");
|
||||
|
||||
puffs_framev_init(pu, p9pbuf_read, p9pbuf_write, p9pbuf_cmp, NULL,
|
||||
puffs_framev_unmountonclose);
|
||||
if (puffs_framev_addfd(pu, p9p.servsock,
|
||||
|
@ -224,6 +221,9 @@ main(int argc, char *argv[])
|
|||
|
||||
if (puffs_mount(pu, argv[1], mntflags, pn_root) == -1)
|
||||
err(1, "puffs_mount");
|
||||
if (puffs_setblockingmode(pu, PUFFSDEV_NONBLOCK) == -1)
|
||||
err(1, "setblockingmode");
|
||||
|
||||
if (puffs_mainloop(pu) == -1)
|
||||
err(1, "mainloop");
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: psshfs.c,v 1.38 2007/11/05 17:54:32 pooka Exp $ */
|
||||
/* $NetBSD: psshfs.c,v 1.39 2007/11/06 15:09:08 pooka Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2006 Antti Kantee. All Rights Reserved.
|
||||
|
@ -41,7 +41,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: psshfs.c,v 1.38 2007/11/05 17:54:32 pooka Exp $");
|
||||
__RCSID("$NetBSD: psshfs.c,v 1.39 2007/11/06 15:09:08 pooka Exp $");
|
||||
#endif /* !lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
@ -200,8 +200,6 @@ main(int argc, char *argv[])
|
|||
|
||||
pssh_connect(&pctx, sshargs);
|
||||
|
||||
if (puffs_setblockingmode(pu, PUFFSDEV_NONBLOCK) == -1)
|
||||
err(1, "setblockingmode");
|
||||
if (exportfs)
|
||||
puffs_setfhsize(pu, sizeof(struct psshfs_fid),
|
||||
PUFFS_FHFLAG_NFSV2 | PUFFS_FHFLAG_NFSV3);
|
||||
|
@ -224,6 +222,9 @@ main(int argc, char *argv[])
|
|||
|
||||
if (puffs_mount(pu, argv[1], mntflags, puffs_getroot(pu)) == -1)
|
||||
err(1, "puffs_mount");
|
||||
if (puffs_setblockingmode(pu, PUFFSDEV_NONBLOCK) == -1)
|
||||
err(1, "setblockingmode");
|
||||
|
||||
if (puffs_mainloop(pu) == -1)
|
||||
err(1, "mainloop");
|
||||
|
||||
|
|
Loading…
Reference in New Issue