From bf4e539fe8b5575756baa326842211ce81b3ee27 Mon Sep 17 00:00:00 2001 From: pooka Date: Thu, 12 Apr 2007 20:42:46 +0000 Subject: [PATCH] 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. --- usr.sbin/puffs/mount_psshfs/fs.c | 59 +++++++++++++++++++++++++++- usr.sbin/puffs/mount_psshfs/node.c | 20 +++++++++- usr.sbin/puffs/mount_psshfs/psshfs.c | 12 ++++-- usr.sbin/puffs/mount_psshfs/psshfs.h | 11 +++++- 4 files changed, 94 insertions(+), 8 deletions(-) diff --git a/usr.sbin/puffs/mount_psshfs/fs.c b/usr.sbin/puffs/mount_psshfs/fs.c index 1473f2c5ff98..1aeb66b9fa9d 100644 --- a/usr.sbin/puffs/mount_psshfs/fs.c +++ b/usr.sbin/puffs/mount_psshfs/fs.c @@ -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 #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 +#include #include #include #include @@ -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; +} diff --git a/usr.sbin/puffs/mount_psshfs/node.c b/usr.sbin/puffs/mount_psshfs/node.c index 8cd4f7ea25f9..654335c64208 100644 --- a/usr.sbin/puffs/mount_psshfs/node.c +++ b/usr.sbin/puffs/mount_psshfs/node.c @@ -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 #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 @@ -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) { diff --git a/usr.sbin/puffs/mount_psshfs/psshfs.c b/usr.sbin/puffs/mount_psshfs/psshfs.c index 9877fa856868..8f7fb79ccb42 100644 --- a/usr.sbin/puffs/mount_psshfs/psshfs.c +++ b/usr.sbin/puffs/mount_psshfs/psshfs.c @@ -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 #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 @@ -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, ':'); diff --git a/usr.sbin/puffs/mount_psshfs/psshfs.h b/usr.sbin/puffs/mount_psshfs/psshfs.h index 2eb5c2559e6b..3dbad4b508e9 100644 --- a/usr.sbin/puffs/mount_psshfs/psshfs.h +++ b/usr.sbin/puffs/mount_psshfs/psshfs.h @@ -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; };