From 1aba0dbed1efdd29039aebc82b13c4b0c3a44b70 Mon Sep 17 00:00:00 2001 From: pooka Date: Fri, 27 Jul 2007 09:46:27 +0000 Subject: [PATCH] Track memory mappings. Close file handles already in close() if there are no active mappings, otherwise do the standard inactive() run. --- usr.sbin/puffs/mount_psshfs/node.c | 65 +++++++++++++++++++++++----- usr.sbin/puffs/mount_psshfs/psshfs.c | 6 ++- usr.sbin/puffs/mount_psshfs/psshfs.h | 5 ++- 3 files changed, 62 insertions(+), 14 deletions(-) diff --git a/usr.sbin/puffs/mount_psshfs/node.c b/usr.sbin/puffs/mount_psshfs/node.c index e7b0cccfa036..3686fe831f60 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.35 2007/07/19 10:14:53 pooka Exp $ */ +/* $NetBSD: node.c,v 1.36 2007/07/27 09:46:27 pooka Exp $ */ /* * Copyright (c) 2006 Antti Kantee. All Rights Reserved. @@ -27,7 +27,7 @@ #include #ifndef lint -__RCSID("$NetBSD: node.c,v 1.35 2007/07/19 10:14:53 pooka Exp $"); +__RCSID("$NetBSD: node.c,v 1.36 2007/07/27 09:46:27 pooka Exp $"); #endif /* !lint */ #include @@ -200,6 +200,21 @@ psshfs_node_create(struct puffs_cc *pcc, void *opc, struct puffs_newinfo *pni, PSSHFSRETURN(rv); } +int +psshfs_node_mmap(struct puffs_cc* pcc, void *opc, vm_prot_t prot, + const struct puffs_cred *pcr, const struct puffs_cid *pcid) +{ + struct puffs_node *pn = opc; + struct psshfs_node *psn = pn->pn_data; + + if (prot & (VM_PROT_READ | VM_PROT_EXECUTE)) + psn->stat |= PSN_READMAP; + if (prot & VM_PROT_WRITE) + psn->stat |= PSN_WRITEMAP; + + return 0; +} + int psshfs_node_open(struct puffs_cc *pcc, void *opc, int mode, const struct puffs_cred *pcr, const struct puffs_cid *pcid) @@ -237,22 +252,22 @@ psshfs_node_open(struct puffs_cc *pcc, void *opc, int mode, } out: + if (rv == 0) + psn->opencount++; + PSSHFSRETURN(rv); } -int -psshfs_node_inactive(struct puffs_cc *pcc, void *opc, - const struct puffs_cid *pcid) +static int +closehandles(struct puffs_cc *pcc, struct psshfs_node *psn) { - struct psshfs_ctx *pctx = puffs_cc_getspecific(pcc); struct puffs_usermount *pu = puffs_cc_getusermount(pcc); - struct puffs_node *pn = opc; - struct psshfs_node *psn = pn->pn_data; - uint32_t reqid = NEXTREQ(pctx); + struct psshfs_ctx *pctx = puffs_cc_getspecific(pcc); struct puffs_framebuf *pb1, *pb2; + uint32_t reqid = NEXTREQ(pctx); int rv; - if (psn->fhand_r) { + if ((psn->stat & PSN_READMAP) == 0 && psn->fhand_r) { pb1 = psbuf_makeout(); psbuf_req_data(pb1, SSH_FXP_CLOSE, reqid, psn->fhand_r, psn->fhand_r_len); @@ -260,7 +275,7 @@ psshfs_node_inactive(struct puffs_cc *pcc, void *opc, free(psn->fhand_r); psn->fhand_r = NULL; } - if (psn->fhand_w) { + if ((psn->stat & PSN_WRITEMAP) == 0 && psn->fhand_w) { pb2 = psbuf_makeout(); psbuf_req_data(pb2, SSH_FXP_CLOSE, reqid, psn->fhand_w, psn->fhand_w_len); @@ -270,6 +285,34 @@ psshfs_node_inactive(struct puffs_cc *pcc, void *opc, } out: + return rv; +} + +int +psshfs_node_close(struct puffs_cc *pcc, void *opc, int flags, + const struct puffs_cred *pcr, const struct puffs_cid *pcid) +{ + struct puffs_node *pn = opc; + struct psshfs_node *psn = pn->pn_data; + + assert(psn->opencount != 0); + if (--psn->opencount == 0) + closehandles(pcc, psn); + + return 0; +} + +int +psshfs_node_inactive(struct puffs_cc *pcc, void *opc, + const struct puffs_cid *pcid) +{ + struct puffs_node *pn = opc; + struct psshfs_node *psn = pn->pn_data; + + assert(psn->opencount == 0); + psn->stat &= ~(PSN_READMAP | PSN_WRITEMAP); + closehandles(pcc, psn); + return 0; } diff --git a/usr.sbin/puffs/mount_psshfs/psshfs.c b/usr.sbin/puffs/mount_psshfs/psshfs.c index 2526a45fb4e0..8ae6390e484d 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.33 2007/07/17 11:34:54 pooka Exp $ */ +/* $NetBSD: psshfs.c,v 1.34 2007/07/27 09:46:27 pooka Exp $ */ /* * Copyright (c) 2006 Antti Kantee. All Rights Reserved. @@ -41,7 +41,7 @@ #include #ifndef lint -__RCSID("$NetBSD: psshfs.c,v 1.33 2007/07/17 11:34:54 pooka Exp $"); +__RCSID("$NetBSD: psshfs.c,v 1.34 2007/07/27 09:46:27 pooka Exp $"); #endif /* !lint */ #include @@ -157,6 +157,8 @@ main(int argc, char *argv[]) PUFFSOP_SET(pops, psshfs, node, lookup); PUFFSOP_SET(pops, psshfs, node, create); PUFFSOP_SET(pops, psshfs, node, open); + PUFFSOP_SET(pops, psshfs, node, close); + PUFFSOP_SET(pops, psshfs, node, mmap); PUFFSOP_SET(pops, psshfs, node, inactive); PUFFSOP_SET(pops, psshfs, node, readdir); PUFFSOP_SET(pops, psshfs, node, getattr); diff --git a/usr.sbin/puffs/mount_psshfs/psshfs.h b/usr.sbin/puffs/mount_psshfs/psshfs.h index 4f9c28f3855c..ed8648c860a3 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.21 2007/07/07 21:14:27 pooka Exp $ */ +/* $NetBSD: psshfs.h,v 1.22 2007/07/27 09:46:28 pooka Exp $ */ /* * Copyright (c) 2006, 2007 Antti Kantee. All Rights Reserved. @@ -115,6 +115,7 @@ struct psshfs_node { int childcount; int stat; + int opencount; time_t attrread; struct puffs_framebuf *getattr_pb; @@ -126,6 +127,8 @@ struct psshfs_node { }; #define PSN_RECLAIMED 0x01 #define PSN_HASFH 0x02 +#define PSN_READMAP 0x04 +#define PSN_WRITEMAP 0x08 struct psshfs_ctx { int sshfd;