* catch up with kernel changes

* better error handling when mounting
This commit is contained in:
pooka 2006-11-09 13:11:01 +00:00
parent 098590e87e
commit 80ce20607e
2 changed files with 41 additions and 32 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: puffs.c,v 1.5 2006/11/07 22:10:53 pooka Exp $ */ /* $NetBSD: puffs.c,v 1.6 2006/11/09 13:11:01 pooka Exp $ */
/* /*
* Copyright (c) 2005, 2006 Antti Kantee. All Rights Reserved. * Copyright (c) 2005, 2006 Antti Kantee. All Rights Reserved.
@ -34,7 +34,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#if !defined(lint) #if !defined(lint)
__RCSID("$NetBSD: puffs.c,v 1.5 2006/11/07 22:10:53 pooka Exp $"); __RCSID("$NetBSD: puffs.c,v 1.6 2006/11/09 13:11:01 pooka Exp $");
#endif /* !lint */ #endif /* !lint */
#include <sys/param.h> #include <sys/param.h>
@ -52,22 +52,20 @@ __RCSID("$NetBSD: puffs.c,v 1.5 2006/11/07 22:10:53 pooka Exp $");
static int puffcall(struct puffs_usermount *, struct puffs_req *); static int puffcall(struct puffs_usermount *, struct puffs_req *);
#define eret(a) do {errno=(a);goto failfree;}while/*NOTREACHED*/(/*CONSTCOND*/0)
struct puffs_usermount * struct puffs_usermount *
puffs_mount(struct puffs_vfsops *pvfs, struct puffs_vnops *pvn, puffs_mount(struct puffs_vfsops *pvfs, struct puffs_vnops *pvn,
const char *dir, int mntflags, const char *puffsname, const char *dir, int mntflags, const char *puffsname,
uint32_t pflags, size_t maxreqlen) uint32_t pflags, size_t maxreqlen)
{ {
struct puffs_startreq sreq;
struct puffs_args pargs; struct puffs_args pargs;
struct puffs_vfsreq_start sreq;
struct puffs_usermount *pu; struct puffs_usermount *pu;
int fd; int fd = 0, rv;
pu = NULL; if (pvfs->puffs_mount == NULL) {
errno = EINVAL;
if (pvfs->puffs_start == NULL) return NULL;
eret(EINVAL); }
fd = open("/dev/puffs", O_RDONLY); fd = open("/dev/puffs", O_RDONLY);
if (fd == -1) if (fd == -1)
@ -81,29 +79,44 @@ puffs_mount(struct puffs_vfsops *pvfs, struct puffs_vnops *pvn,
pu = malloc(sizeof(struct puffs_usermount)); pu = malloc(sizeof(struct puffs_usermount));
if (!pu) if (!pu)
eret(ENOMEM); return NULL;
pu->pu_flags = pflags; pu->pu_flags = pflags;
pu->pu_pvfs = *pvfs; pu->pu_pvfs = *pvfs;
pu->pu_pvn = *pvn; pu->pu_pvn = *pvn;
pu->pu_fd = fd; pu->pu_fd = fd;
if ((pu->pu_rootpath = strdup(dir)) == NULL) if ((pu->pu_rootpath = strdup(dir)) == NULL)
eret(ENOMEM); goto failfree;
LIST_INIT(&pu->pu_pnodelst); LIST_INIT(&pu->pu_pnodelst);
if (mount(MOUNT_PUFFS, dir, mntflags, &pargs) == -1) if (mount(MOUNT_PUFFS, dir, mntflags, &pargs) == -1)
return NULL; goto failfree;
pu->pu_maxreqlen = pargs.pa_maxreqlen; pu->pu_maxreqlen = pargs.pa_maxreqlen;
if (pu->pu_pvfs.puffs_start(pu, &sreq) != 0) if ((rv = pu->pu_pvfs.puffs_mount(pu, &sreq.psr_cookie)) != 0) {
return NULL; errno = rv;
goto failfree;
}
/* tell kernel we're flying */ /* tell kernel we're flying */
if (ioctl(pu->pu_fd, PUFFSMOUNTOP, &sreq) == -1) if (ioctl(pu->pu_fd, PUFFSSTARTOP, &sreq) == -1)
return NULL; goto failfree;
/* finally, store fsidx and call start if appropriate */
pu->pu_fsidx = sreq.psr_fsidx;
if (pu->pu_pvfs.puffs_start) {
if ((rv = pu->pu_pvfs.puffs_start(pu)) != 0) {
errno = rv;
goto failfree;
}
}
return pu; return pu;
failfree: failfree:
/* can't unmount() from here for obvious reasons */
if (fd)
close(fd);
free(pu); free(pu);
return NULL; return NULL;
} }
@ -156,11 +169,11 @@ puffs_getselectable(struct puffs_usermount *pu)
} }
int int
puffs_setblockingmode(struct puffs_usermount *pu, int block) puffs_setblockingmode(struct puffs_usermount *pu, int mode)
{ {
int x; int x;
x = !block; x = mode;
return ioctl(pu->pu_fd, FIONBIO, &x); return ioctl(pu->pu_fd, FIONBIO, &x);
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: puffs.h,v 1.4 2006/11/07 22:10:53 pooka Exp $ */ /* $NetBSD: puffs.h,v 1.5 2006/11/09 13:11:01 pooka Exp $ */
/* /*
* Copyright (c) 2005, 2006 Antti Kantee. All Rights Reserved. * Copyright (c) 2005, 2006 Antti Kantee. All Rights Reserved.
@ -73,8 +73,8 @@ struct puffs_node {
/* callbacks for operations */ /* callbacks for operations */
struct puffs_vfsops { struct puffs_vfsops {
int (*puffs_start)(struct puffs_usermount *, int (*puffs_mount)(struct puffs_usermount *, void **);
struct puffs_vfsreq_start *); int (*puffs_start)(struct puffs_usermount *);
int (*puffs_unmount)(struct puffs_usermount *, int, pid_t); int (*puffs_unmount)(struct puffs_usermount *, int, pid_t);
int (*puffs_statvfs)(struct puffs_usermount *, int (*puffs_statvfs)(struct puffs_usermount *,
struct statvfs *, pid_t); struct statvfs *, pid_t);
@ -138,10 +138,6 @@ struct puffs_vnops {
void *, int, int *); void *, int, int *);
int (*puffs_advlock)(struct puffs_usermount *, int (*puffs_advlock)(struct puffs_usermount *,
void *, void *, int, struct flock *, int); void *, void *, int, struct flock *, int);
int (*puffs_getpages)(struct puffs_usermount *,
void *, struct puffs_vnreq_getpages *);
int (*puffs_putpages)(struct puffs_usermount *,
void *, struct puffs_vnreq_putpages *);
int (*puffs_getextattr)(struct puffs_usermount *, int (*puffs_getextattr)(struct puffs_usermount *,
void *, struct puffs_vnreq_getextattr *); void *, struct puffs_vnreq_getextattr *);
int (*puffs_setextattr)(struct puffs_usermount *, int (*puffs_setextattr)(struct puffs_usermount *,
@ -173,6 +169,7 @@ struct puffs_usermount {
struct puffs_node *pu_rootnode; struct puffs_node *pu_rootnode;
const char * pu_rootpath; const char * pu_rootpath;
fsid_t pu_fsidx;
LIST_HEAD(, puffs_node) pu_pnodelst; LIST_HEAD(, puffs_node) pu_pnodelst;
int pu_wcnt; int pu_wcnt;
@ -190,6 +187,9 @@ int puffs_getselectable(struct puffs_usermount *);
int puffs_setblockingmode(struct puffs_usermount *, int); int puffs_setblockingmode(struct puffs_usermount *, int);
void puffs_dummyops(struct puffs_vnops *); void puffs_dummyops(struct puffs_vnops *);
#define PUFFSDEV_BLOCK 0
#define PUFFSDEV_NONBLOCK 1
struct puffs_node * puffs_newpnode(struct puffs_usermount *, void *, struct puffs_node * puffs_newpnode(struct puffs_usermount *, void *,
enum vtype); enum vtype);
void puffs_putpnode(struct puffs_node *); void puffs_putpnode(struct puffs_node *);
@ -225,8 +225,8 @@ int puffs_cred_isjuggernaut(const struct puffs_cred *pcr);
#define PUFFSVFS_PROTOS(fsname) \ #define PUFFSVFS_PROTOS(fsname) \
int fsname##_start(struct puffs_usermount *, \ int fsname##_mount(struct puffs_usermount *, void **); \
struct puffs_vfsreq_start *); \ int fsname##_start(struct puffs_usermount *); \
int fsname##_unmount(struct puffs_usermount *, int, pid_t); \ int fsname##_unmount(struct puffs_usermount *, int, pid_t); \
int fsname##_statvfs(struct puffs_usermount *, \ int fsname##_statvfs(struct puffs_usermount *, \
struct statvfs *, pid_t); \ struct statvfs *, pid_t); \
@ -294,10 +294,6 @@ int puffs_cred_isjuggernaut(const struct puffs_cred *pcr);
void *, int, int *); \ void *, int, int *); \
int fsname##_advlock(struct puffs_usermount *, \ int fsname##_advlock(struct puffs_usermount *, \
void *, void *, int, struct flock *, int); \ void *, void *, int, struct flock *, int); \
int fsname##_getpages(struct puffs_usermount *, \
void *, struct puffs_vnreq_getpages *); \
int fsname##_putpages(struct puffs_usermount *, \
void *, struct puffs_vnreq_putpages *); \
int fsname##_getextattr(struct puffs_usermount *, \ int fsname##_getextattr(struct puffs_usermount *, \
void *, struct puffs_vnreq_getextattr *); \ void *, struct puffs_vnreq_getextattr *); \
int fsname##_setextattr(struct puffs_usermount *, \ int fsname##_setextattr(struct puffs_usermount *, \