Thu Mar 20 15:28:03 2008 UTC ()
Reserve enough memory for ops which return more than they receive.


(pooka)
diff -r1.30 -r1.31 src/lib/libpuffs/dispatcher.c

cvs diff -r1.30 -r1.31 src/lib/libpuffs/dispatcher.c (expand / switch to unified diff)

--- src/lib/libpuffs/dispatcher.c 2008/01/28 18:35:50 1.30
+++ src/lib/libpuffs/dispatcher.c 2008/03/20 15:28:03 1.31
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: dispatcher.c,v 1.30 2008/01/28 18:35:50 pooka Exp $ */ 1/* $NetBSD: dispatcher.c,v 1.31 2008/03/20 15:28:03 pooka Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2006, 2007, 2008 Antti Kantee. All Rights Reserved. 4 * Copyright (c) 2006, 2007, 2008 Antti Kantee. All Rights Reserved.
5 * 5 *
6 * Development of this software was supported by the 6 * Development of this software was supported by the
7 * Ulla Tuominen Foundation, the Finnish Cultural Foundation and 7 * Ulla Tuominen Foundation, the Finnish Cultural Foundation and
8 * Research Foundation of Helsinki University of Technology. 8 * Research Foundation of Helsinki University of Technology.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -21,27 +21,27 @@ @@ -21,27 +21,27 @@
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#if !defined(lint) 33#if !defined(lint)
34__RCSID("$NetBSD: dispatcher.c,v 1.30 2008/01/28 18:35:50 pooka Exp $"); 34__RCSID("$NetBSD: dispatcher.c,v 1.31 2008/03/20 15:28:03 pooka Exp $");
35#endif /* !lint */ 35#endif /* !lint */
36 36
37#include <sys/types.h> 37#include <sys/types.h>
38#include <sys/poll.h> 38#include <sys/poll.h>
39 39
40#include <assert.h> 40#include <assert.h>
41#include <errno.h> 41#include <errno.h>
42#ifdef PUFFS_WITH_THREADS 42#ifdef PUFFS_WITH_THREADS
43#include <pthread.h> 43#include <pthread.h>
44#endif 44#endif
45#include <puffs.h> 45#include <puffs.h>
46#include <puffsdump.h> 46#include <puffsdump.h>
47#include <stdio.h> 47#include <stdio.h>
@@ -123,44 +123,62 @@ puffs_dispatch_exec(struct puffs_cc *pcc @@ -123,44 +123,62 @@ puffs_dispatch_exec(struct puffs_cc *pcc
123 } else { 123 } else {
124 rv = 0; 124 rv = 0;
125 } 125 }
126 126
127 return rv; 127 return rv;
128} 128}
129 129
130static void 130static void
131dispatch(struct puffs_cc *pcc) 131dispatch(struct puffs_cc *pcc)
132{ 132{
133 struct puffs_usermount *pu = pcc->pcc_pu; 133 struct puffs_usermount *pu = pcc->pcc_pu;
134 struct puffs_ops *pops = &pu->pu_ops; 134 struct puffs_ops *pops = &pu->pu_ops;
135 struct puffs_req *preq = puffs__framebuf_getdataptr(pcc->pcc_pb); 135 struct puffs_req *preq = puffs__framebuf_getdataptr(pcc->pcc_pb);
136 void *auxbuf = preq; /* help with typecasting */ 136 void *auxbuf; /* help with typecasting */
137 void *opcookie = preq->preq_cookie; 137 void *opcookie;
138 int error, buildpath; 138 int error = 0, buildpath;
 139
 140 /* XXX: smaller hammer, please */
 141 if ((PUFFSOP_OPCLASS(preq->preq_opclass == PUFFSOP_VFS &&
 142 preq->preq_optype == PUFFS_VFS_VPTOFH)) ||
 143 (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_VN &&
 144 (preq->preq_optype == PUFFS_VN_READDIR
 145 || preq->preq_optype == PUFFS_VN_READ))) {
 146 if (puffs_framebuf_reserve_space(pcc->pcc_pb,
 147 PUFFS_MSG_MAXSIZE) == -1)
 148 error = errno;
 149 preq = puffs__framebuf_getdataptr(pcc->pcc_pb);
 150 }
 151
 152 auxbuf = preq;
 153 opcookie = preq->preq_cookie;
139 154
140 assert((pcc->pcc_flags & PCC_DONE) == 0); 155 assert((pcc->pcc_flags & PCC_DONE) == 0);
141 156
142 buildpath = pu->pu_flags & PUFFS_FLAG_BUILDPATH; 157 buildpath = pu->pu_flags & PUFFS_FLAG_BUILDPATH;
143 preq->preq_setbacks = 0; 158 preq->preq_setbacks = 0;
144 159
145 if (pu->pu_flags & PUFFS_FLAG_OPDUMP) 160 if (pu->pu_flags & PUFFS_FLAG_OPDUMP)
146 puffsdump_req(preq); 161 puffsdump_req(preq);
147 162
148 puffs__cc_setcaller(pcc, preq->preq_pid, preq->preq_lid); 163 puffs__cc_setcaller(pcc, preq->preq_pid, preq->preq_lid);
149 164
150 /* pre-operation */ 165 /* pre-operation */
151 if (pu->pu_oppre) 166 if (pu->pu_oppre)
152 pu->pu_oppre(pu); 167 pu->pu_oppre(pu);
153 168
 169 if (error)
 170 goto out;
 171
154 /* Execute actual operation */ 172 /* Execute actual operation */
155 if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_VFS) { 173 if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_VFS) {
156 switch (preq->preq_optype) { 174 switch (preq->preq_optype) {
157 case PUFFS_VFS_UNMOUNT: 175 case PUFFS_VFS_UNMOUNT:
158 { 176 {
159 struct puffs_vfsmsg_unmount *auxt = auxbuf; 177 struct puffs_vfsmsg_unmount *auxt = auxbuf;
160 178
161 PU_SETSTATE(pu, PUFFS_STATE_UNMOUNTING); 179 PU_SETSTATE(pu, PUFFS_STATE_UNMOUNTING);
162 error = pops->puffs_fs_unmount(pu, auxt->pvfsr_flags); 180 error = pops->puffs_fs_unmount(pu, auxt->pvfsr_flags);
163 if (!error) 181 if (!error)
164 PU_SETSTATE(pu, PUFFS_STATE_UNMOUNTED); 182 PU_SETSTATE(pu, PUFFS_STATE_UNMOUNTED);
165 else 183 else
166 PU_SETSTATE(pu, PUFFS_STATE_RUNNING); 184 PU_SETSTATE(pu, PUFFS_STATE_RUNNING);
@@ -889,20 +907,22 @@ dispatch(struct puffs_cc *pcc) @@ -889,20 +907,22 @@ dispatch(struct puffs_cc *pcc)
889 907
890 } else if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_ERROR) { 908 } else if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_ERROR) {
891 struct puffs_error *perr = (void *)preq; 909 struct puffs_error *perr = (void *)preq;
892 910
893 pu->pu_errnotify(pu, preq->preq_optype, 911 pu->pu_errnotify(pu, preq->preq_optype,
894 perr->perr_error, perr->perr_str, preq->preq_cookie); 912 perr->perr_error, perr->perr_str, preq->preq_cookie);
895 error = 0; 913 error = 0;
896 } else { 914 } else {
897 /* 915 /*
898 * I guess the kernel sees this one coming also 916 * I guess the kernel sees this one coming also
899 */ 917 */
900 error = EINVAL; 918 error = EINVAL;
901 } 919 }
 920
 921 out:
902 preq->preq_rv = error; 922 preq->preq_rv = error;
903 923
904 if (pu->pu_oppost) 924 if (pu->pu_oppost)
905 pu->pu_oppost(pu); 925 pu->pu_oppost(pu);
906 926
907 pcc->pcc_flags |= PCC_DONE; 927 pcc->pcc_flags |= PCC_DONE;
908} 928}