Support nfs exporting.

Now, when I say support, I mean "support", due to the limitations
of the backend.  File handles are valid only for one session, since
nodes can only be identified by pathnames and pathnames don't (all)
fit into the nfs file handle space.  Additionally, we can't detect
if a pathname is completely replaced by another file (if it's done
via some other route that through our mount, of course).  But then
again, that's an inherent problem with sshfs even without nfs.
This commit is contained in:
pooka 2007-04-12 20:42:46 +00:00
parent b67bcdf35b
commit bf4e539fe8
4 changed files with 94 additions and 8 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: fs.c,v 1.4 2007/04/12 15:09:02 pooka Exp $ */
/* $NetBSD: fs.c,v 1.5 2007/04/12 20:42:46 pooka Exp $ */
/*
* Copyright (c) 2006 Antti Kantee. All Rights Reserved.
@ -30,10 +30,11 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: fs.c,v 1.4 2007/04/12 15:09:02 pooka Exp $");
__RCSID("$NetBSD: fs.c,v 1.5 2007/04/12 20:42:46 pooka Exp $");
#endif /* !lint */
#include <err.h>
#include <errno.h>
#include <puffs.h>
#include <signal.h>
#include <stdio.h>
@ -159,3 +160,57 @@ psshfs_fs_unmount(struct puffs_cc *pcc, int flags, pid_t pid)
close(pctx->sshfd);
return 0;
}
int
psshfs_fs_nodetofh(struct puffs_cc *pcc, void *cookie,
void *fid, size_t *fidsize)
{
struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
struct psshfs_ctx *pctx = puffs_getspecific(pu);
struct puffs_node *pn = cookie;
struct psshfs_node *psn = pn->pn_data;
struct psshfs_fid *pf = fid;
pf->mounttime = pctx->mounttime;
pf->node = pn;
psn->hasfh = 1;
return 0;
}
int
psshfs_fs_fhtonode(struct puffs_cc *pcc, void *fid, size_t fidsize,
void **fcookie, enum vtype *ftype, voff_t *fsize, dev_t *fdev)
{
struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
struct psshfs_ctx *pctx = puffs_getspecific(pu);
struct psshfs_fid *pf = fid;
struct puffs_node *pn = pf->node;
struct psshfs_node *psn;
int rv;
if (pf->mounttime != pctx->mounttime)
return EINVAL;
if (pn == 0)
return EINVAL;
psn = pn->pn_data;
if (psn->hasfh == 0)
return EINVAL;
/* update node attributes */
rv = getnodeattr(pcc, pn);
if (rv) {
psn->hasfh = 0;
if (psn->reclaimed == 2)
psshfs_node_reclaim(pcc, pn, 0);
return EINVAL;
}
*fcookie = pn;
*ftype = pn->pn_va.va_type;
*fsize = pn->pn_va.va_size;
return 0;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: node.c,v 1.16 2007/04/12 15:09:02 pooka Exp $ */
/* $NetBSD: node.c,v 1.17 2007/04/12 20:42:46 pooka Exp $ */
/*
* Copyright (c) 2006 Antti Kantee. All Rights Reserved.
@ -30,7 +30,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: node.c,v 1.16 2007/04/12 15:09:02 pooka Exp $");
__RCSID("$NetBSD: node.c,v 1.17 2007/04/12 20:42:46 pooka Exp $");
#endif /* !lint */
#include <assert.h>
@ -222,6 +222,7 @@ psshfs_node_readdir(struct puffs_cc *pcc, void *opc, struct dirent *dent,
struct psshfs_dir *pd;
int i, rv;
*ncookies = 0;
rv = sftp_readdir(pcc, pctx, pn);
if (rv)
return rv;
@ -233,7 +234,13 @@ psshfs_node_readdir(struct puffs_cc *pcc, void *opc, struct dirent *dent,
if (!puffs_nextdent(&dent, pd->entryname,
pd->va.va_fileid, puffs_vtype2dt(pd->va.va_type), reslen))
break;
if (cookies) {
*(cookies++) = (off_t)i;
(*ncookies)++;
}
}
if (i == psn->dentnext)
*eofflag = 1;
*readoff = i;
return 0;
@ -623,6 +630,15 @@ psshfs_node_reclaim(struct puffs_cc *pcc, void *opc, pid_t pid)
struct puffs_node *pn = opc, *pn_next, *pn_root;
struct psshfs_node *psn = pn->pn_data;
/*
* don't reclaim if we have file handle issued, otherwise
* we can't do fhtonode
*/
if (psn->hasfh) {
psn->reclaimed = 2;
return 0;
}
psn->reclaimed = 1;
pn_root = puffs_getroot(pu);
for (; pn != pn_root; pn = pn_next) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: psshfs.c,v 1.10 2007/04/12 15:09:02 pooka Exp $ */
/* $NetBSD: psshfs.c,v 1.11 2007/04/12 20:42:46 pooka Exp $ */
/*
* Copyright (c) 2006 Antti Kantee. All Rights Reserved.
@ -57,7 +57,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: psshfs.c,v 1.10 2007/04/12 15:09:02 pooka Exp $");
__RCSID("$NetBSD: psshfs.c,v 1.11 2007/04/12 20:42:46 pooka Exp $");
#endif /* !lint */
#include <sys/types.h>
@ -109,8 +109,11 @@ main(int argc, char *argv[])
mntflags = pflags = 0;
detach = 1;
while ((ch = getopt(argc, argv, "o:s")) != -1) {
while ((ch = getopt(argc, argv, "eo:s")) != -1) {
switch (ch) {
case 'e':
pflags |= PUFFS_KFLAG_CANEXPORT;
break;
case 'o':
mp = getmntopts(optarg, puffsmopts, &mntflags, &pflags);
if (mp == NULL)
@ -144,6 +147,8 @@ main(int argc, char *argv[])
PUFFSOP_SET(pops, psshfs, fs, unmount);
PUFFSOP_SETFSNOP(pops, sync); /* XXX */
PUFFSOP_SETFSNOP(pops, statvfs);
PUFFSOP_SET(pops, psshfs, fs, nodetofh);
PUFFSOP_SET(pops, psshfs, fs, fhtonode);
PUFFSOP_SET(pops, psshfs, node, lookup);
PUFFSOP_SET(pops, psshfs, node, create);
@ -163,6 +168,7 @@ main(int argc, char *argv[])
memset(&pctx, 0, sizeof(pctx));
TAILQ_INIT(&pctx.outbufq);
TAILQ_INIT(&pctx.req_queue);
pctx.mounttime = time(NULL);
userhost = argv[0];
hostpath = strchr(userhost, ':');

View File

@ -1,4 +1,4 @@
/* $NetBSD: psshfs.h,v 1.8 2007/04/12 15:09:02 pooka Exp $ */
/* $NetBSD: psshfs.h,v 1.9 2007/04/12 20:42:46 pooka Exp $ */
/*
* Copyright (c) 2006 Antti Kantee. All Rights Reserved.
@ -75,6 +75,11 @@ struct psshfs_dir {
time_t attrread;
};
struct psshfs_fid {
time_t mounttime;
struct puffs_node *node;
};
struct psshfs_node {
struct puffs_node *parent;
@ -84,6 +89,7 @@ struct psshfs_node {
time_t dentread;
int childcount;
int reclaimed;
int hasfh;
time_t attrread;
};
@ -150,6 +156,9 @@ struct psshfs_ctx {
struct psshfs_node psn_root;
ino_t nextino;
int canexport;
time_t mounttime;
TAILQ_HEAD(, psbuf) outbufq;
TAILQ_HEAD(, psbuf) req_queue;
};