puffs_vfsops.c revision 1.16.2.5 1 1.16.2.5 yamt /* $NetBSD: puffs_vfsops.c,v 1.16.2.5 2007/10/27 11:35:12 yamt Exp $ */
2 1.16.2.2 yamt
3 1.16.2.2 yamt /*
4 1.16.2.2 yamt * Copyright (c) 2005, 2006 Antti Kantee. All Rights Reserved.
5 1.16.2.2 yamt *
6 1.16.2.2 yamt * Development of this software was supported by the
7 1.16.2.2 yamt * Google Summer of Code program and the Ulla Tuominen Foundation.
8 1.16.2.2 yamt * The Google SoC project was mentored by Bill Studenmund.
9 1.16.2.2 yamt *
10 1.16.2.2 yamt * Redistribution and use in source and binary forms, with or without
11 1.16.2.2 yamt * modification, are permitted provided that the following conditions
12 1.16.2.2 yamt * are met:
13 1.16.2.2 yamt * 1. Redistributions of source code must retain the above copyright
14 1.16.2.2 yamt * notice, this list of conditions and the following disclaimer.
15 1.16.2.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
16 1.16.2.2 yamt * notice, this list of conditions and the following disclaimer in the
17 1.16.2.2 yamt * documentation and/or other materials provided with the distribution.
18 1.16.2.2 yamt *
19 1.16.2.2 yamt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
20 1.16.2.2 yamt * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 1.16.2.2 yamt * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 1.16.2.2 yamt * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 1.16.2.2 yamt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.16.2.2 yamt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 1.16.2.2 yamt * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.16.2.2 yamt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.16.2.2 yamt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.16.2.2 yamt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.16.2.2 yamt * SUCH DAMAGE.
30 1.16.2.2 yamt */
31 1.16.2.2 yamt
32 1.16.2.2 yamt #include <sys/cdefs.h>
33 1.16.2.5 yamt __KERNEL_RCSID(0, "$NetBSD: puffs_vfsops.c,v 1.16.2.5 2007/10/27 11:35:12 yamt Exp $");
34 1.16.2.2 yamt
35 1.16.2.2 yamt #include <sys/param.h>
36 1.16.2.2 yamt #include <sys/mount.h>
37 1.16.2.2 yamt #include <sys/malloc.h>
38 1.16.2.2 yamt #include <sys/extattr.h>
39 1.16.2.2 yamt #include <sys/queue.h>
40 1.16.2.2 yamt #include <sys/vnode.h>
41 1.16.2.2 yamt #include <sys/dirent.h>
42 1.16.2.2 yamt #include <sys/kauth.h>
43 1.16.2.3 yamt #include <sys/fstrans.h>
44 1.16.2.4 yamt #include <sys/proc.h>
45 1.16.2.2 yamt
46 1.16.2.2 yamt #include <lib/libkern/libkern.h>
47 1.16.2.2 yamt
48 1.16.2.2 yamt #include <fs/puffs/puffs_msgif.h>
49 1.16.2.2 yamt #include <fs/puffs/puffs_sys.h>
50 1.16.2.2 yamt
51 1.16.2.4 yamt #include <nfs/nfsproto.h> /* for fh sizes */
52 1.16.2.4 yamt
53 1.16.2.2 yamt VFS_PROTOS(puffs);
54 1.16.2.2 yamt
55 1.16.2.4 yamt MALLOC_JUSTDEFINE(M_PUFFS, "puffs", "Pass-to-Userspace Framework File System");
56 1.16.2.2 yamt
57 1.16.2.3 yamt #ifndef PUFFS_PNODEBUCKETS
58 1.16.2.3 yamt #define PUFFS_PNODEBUCKETS 256
59 1.16.2.3 yamt #endif
60 1.16.2.3 yamt #ifndef PUFFS_MAXPNODEBUCKETS
61 1.16.2.4 yamt #define PUFFS_MAXPNODEBUCKETS 8192
62 1.16.2.3 yamt #endif
63 1.16.2.4 yamt int puffs_pnodebuckets_default = PUFFS_PNODEBUCKETS;
64 1.16.2.4 yamt int puffs_maxpnodebuckets = PUFFS_MAXPNODEBUCKETS;
65 1.16.2.3 yamt
66 1.16.2.2 yamt int
67 1.16.2.4 yamt puffs_mount(struct mount *mp, const char *path, void *data, size_t *data_len,
68 1.16.2.4 yamt struct lwp *l)
69 1.16.2.2 yamt {
70 1.16.2.3 yamt struct puffs_mount *pmp = NULL;
71 1.16.2.4 yamt struct puffs_kargs *args;
72 1.16.2.4 yamt char fstype[_VFS_NAMELEN];
73 1.16.2.4 yamt char *p;
74 1.16.2.3 yamt int error = 0, i;
75 1.16.2.2 yamt
76 1.16.2.4 yamt if (*data_len < sizeof *args)
77 1.16.2.4 yamt return EINVAL;
78 1.16.2.4 yamt
79 1.16.2.2 yamt if (mp->mnt_flag & MNT_GETARGS) {
80 1.16.2.2 yamt pmp = MPTOPUFFSMP(mp);
81 1.16.2.4 yamt *(struct puffs_kargs *)data = pmp->pmp_args;
82 1.16.2.4 yamt *data_len = sizeof *args;
83 1.16.2.4 yamt return 0;
84 1.16.2.2 yamt }
85 1.16.2.2 yamt
86 1.16.2.2 yamt /* update is not supported currently */
87 1.16.2.2 yamt if (mp->mnt_flag & MNT_UPDATE)
88 1.16.2.2 yamt return EOPNOTSUPP;
89 1.16.2.2 yamt
90 1.16.2.2 yamt /*
91 1.16.2.2 yamt * We need the file system name
92 1.16.2.2 yamt */
93 1.16.2.2 yamt if (!data)
94 1.16.2.2 yamt return EINVAL;
95 1.16.2.2 yamt
96 1.16.2.4 yamt MALLOC(args, struct puffs_kargs *, sizeof(struct puffs_kargs),
97 1.16.2.3 yamt M_PUFFS, M_WAITOK);
98 1.16.2.3 yamt
99 1.16.2.4 yamt *args = *(struct puffs_kargs *)data;
100 1.16.2.3 yamt
101 1.16.2.3 yamt /* devel phase */
102 1.16.2.3 yamt if (args->pa_vers != (PUFFSVERSION | PUFFSDEVELVERS)) {
103 1.16.2.5 yamt printf("puffs_mount: development version mismatch: "
104 1.16.2.5 yamt "kernel %d, lib %d\n",
105 1.16.2.5 yamt PUFFSVERSION, args->pa_vers & ~PUFFSDEVELVERS);
106 1.16.2.3 yamt error = EINVAL;
107 1.16.2.3 yamt goto out;
108 1.16.2.3 yamt }
109 1.16.2.2 yamt
110 1.16.2.4 yamt if ((args->pa_flags & ~PUFFS_KFLAG_MASK) != 0) {
111 1.16.2.4 yamt printf("puffs_mount: invalid KFLAGs 0x%x\n", args->pa_flags);
112 1.16.2.4 yamt error = EINVAL;
113 1.16.2.4 yamt goto out;
114 1.16.2.4 yamt }
115 1.16.2.4 yamt if ((args->pa_fhflags & ~PUFFS_FHFLAG_MASK) != 0) {
116 1.16.2.4 yamt printf("puffs_mount: invalid FHFLAGs 0x%x\n", args->pa_fhflags);
117 1.16.2.4 yamt error = EINVAL;
118 1.16.2.4 yamt goto out;
119 1.16.2.4 yamt }
120 1.16.2.4 yamt
121 1.16.2.4 yamt /* use dummy value for passthrough */
122 1.16.2.4 yamt if (args->pa_fhflags & PUFFS_FHFLAG_PASSTHROUGH)
123 1.16.2.4 yamt args->pa_fhsize = sizeof(struct fid);
124 1.16.2.4 yamt
125 1.16.2.4 yamt /* sanitize file handle length */
126 1.16.2.4 yamt if (PUFFS_TOFHSIZE(args->pa_fhsize) > FHANDLE_SIZE_MAX) {
127 1.16.2.4 yamt printf("puffs_mount: handle size %zu too large\n",
128 1.16.2.4 yamt args->pa_fhsize);
129 1.16.2.4 yamt error = EINVAL;
130 1.16.2.4 yamt goto out;
131 1.16.2.4 yamt }
132 1.16.2.4 yamt /* sanity check file handle max sizes */
133 1.16.2.4 yamt if (args->pa_fhsize && args->pa_fhflags & PUFFS_FHFLAG_PROTOMASK) {
134 1.16.2.4 yamt size_t kfhsize = PUFFS_TOFHSIZE(args->pa_fhsize);
135 1.16.2.4 yamt
136 1.16.2.4 yamt if (args->pa_fhflags & PUFFS_FHFLAG_NFSV2) {
137 1.16.2.4 yamt if (NFSX_FHTOOBIG_P(kfhsize, 0)) {
138 1.16.2.4 yamt printf("puffs_mount: fhsize larger than "
139 1.16.2.4 yamt "NFSv2 max %d\n",
140 1.16.2.4 yamt PUFFS_FROMFHSIZE(NFSX_V2FH));
141 1.16.2.4 yamt error = EINVAL;
142 1.16.2.4 yamt goto out;
143 1.16.2.4 yamt }
144 1.16.2.4 yamt }
145 1.16.2.4 yamt
146 1.16.2.4 yamt if (args->pa_fhflags & PUFFS_FHFLAG_NFSV3) {
147 1.16.2.4 yamt if (NFSX_FHTOOBIG_P(kfhsize, 1)) {
148 1.16.2.4 yamt printf("puffs_mount: fhsize larger than "
149 1.16.2.4 yamt "NFSv3 max %d\n",
150 1.16.2.4 yamt PUFFS_FROMFHSIZE(NFSX_V3FHMAX));
151 1.16.2.4 yamt error = EINVAL;
152 1.16.2.4 yamt goto out;
153 1.16.2.4 yamt }
154 1.16.2.4 yamt }
155 1.16.2.4 yamt }
156 1.16.2.4 yamt
157 1.16.2.4 yamt /* don't allow non-printing characters (like my sweet umlauts.. snif) */
158 1.16.2.4 yamt args->pa_typename[sizeof(args->pa_typename)-1] = '\0';
159 1.16.2.4 yamt for (p = args->pa_typename; *p; p++)
160 1.16.2.4 yamt if (*p < ' ' || *p > '~')
161 1.16.2.4 yamt *p = '.';
162 1.16.2.4 yamt
163 1.16.2.4 yamt args->pa_mntfromname[sizeof(args->pa_mntfromname)-1] = '\0';
164 1.16.2.4 yamt for (p = args->pa_mntfromname; *p; p++)
165 1.16.2.4 yamt if (*p < ' ' || *p > '~')
166 1.16.2.4 yamt *p = '.';
167 1.16.2.2 yamt
168 1.16.2.2 yamt /* build real name */
169 1.16.2.4 yamt (void)strlcpy(fstype, PUFFS_TYPEPREFIX, sizeof(fstype));
170 1.16.2.4 yamt (void)strlcat(fstype, args->pa_typename, sizeof(fstype));
171 1.16.2.2 yamt
172 1.16.2.2 yamt /* inform user server if it got the max request size it wanted */
173 1.16.2.5 yamt if (args->pa_maxmsglen == 0 || args->pa_maxmsglen > PUFFS_MSG_MAXSIZE)
174 1.16.2.5 yamt args->pa_maxmsglen = PUFFS_MSG_MAXSIZE;
175 1.16.2.5 yamt else if (args->pa_maxmsglen < 2*PUFFS_MSGSTRUCT_MAX)
176 1.16.2.5 yamt args->pa_maxmsglen = 2*PUFFS_MSGSTRUCT_MAX;
177 1.16.2.5 yamt
178 1.16.2.4 yamt (void)strlcpy(args->pa_typename, fstype, sizeof(args->pa_typename));
179 1.16.2.4 yamt
180 1.16.2.4 yamt if (args->pa_nhashbuckets == 0)
181 1.16.2.4 yamt args->pa_nhashbuckets = puffs_pnodebuckets_default;
182 1.16.2.4 yamt if (args->pa_nhashbuckets < 1)
183 1.16.2.4 yamt args->pa_nhashbuckets = 1;
184 1.16.2.4 yamt if (args->pa_nhashbuckets > PUFFS_MAXPNODEBUCKETS) {
185 1.16.2.4 yamt args->pa_nhashbuckets = puffs_maxpnodebuckets;
186 1.16.2.4 yamt printf("puffs_mount: using %d hash buckets. "
187 1.16.2.4 yamt "adjust puffs_maxpnodebuckets for more\n",
188 1.16.2.4 yamt puffs_maxpnodebuckets);
189 1.16.2.4 yamt }
190 1.16.2.2 yamt
191 1.16.2.4 yamt error = set_statvfs_info(path, UIO_USERSPACE, args->pa_mntfromname,
192 1.16.2.4 yamt UIO_SYSSPACE, fstype, mp, l);
193 1.16.2.2 yamt if (error)
194 1.16.2.3 yamt goto out;
195 1.16.2.2 yamt mp->mnt_stat.f_iosize = DEV_BSIZE;
196 1.16.2.2 yamt
197 1.16.2.4 yamt /*
198 1.16.2.4 yamt * We can't handle the VFS_STATVFS() mount_domount() does
199 1.16.2.4 yamt * after VFS_MOUNT() because we'd deadlock, so handle it
200 1.16.2.4 yamt * here already.
201 1.16.2.4 yamt */
202 1.16.2.4 yamt copy_statvfs_info(&args->pa_svfsb, mp);
203 1.16.2.4 yamt (void)memcpy(&mp->mnt_stat, &args->pa_svfsb, sizeof(mp->mnt_stat));
204 1.16.2.4 yamt
205 1.16.2.2 yamt MALLOC(pmp, struct puffs_mount *, sizeof(struct puffs_mount),
206 1.16.2.2 yamt M_PUFFS, M_WAITOK | M_ZERO);
207 1.16.2.2 yamt
208 1.16.2.2 yamt mp->mnt_fs_bshift = DEV_BSHIFT;
209 1.16.2.2 yamt mp->mnt_dev_bshift = DEV_BSHIFT;
210 1.16.2.2 yamt mp->mnt_flag &= ~MNT_LOCAL; /* we don't really know, so ... */
211 1.16.2.2 yamt mp->mnt_data = pmp;
212 1.16.2.3 yamt mp->mnt_iflag |= IMNT_HAS_TRANS;
213 1.16.2.2 yamt
214 1.16.2.2 yamt pmp->pmp_status = PUFFSTAT_MOUNTING;
215 1.16.2.2 yamt pmp->pmp_mp = mp;
216 1.16.2.5 yamt pmp->pmp_msg_maxsize = args->pa_maxmsglen;
217 1.16.2.3 yamt pmp->pmp_args = *args;
218 1.16.2.3 yamt
219 1.16.2.4 yamt pmp->pmp_npnodehash = args->pa_nhashbuckets;
220 1.16.2.3 yamt pmp->pmp_pnodehash = malloc
221 1.16.2.3 yamt (sizeof(struct puffs_pnode_hashlist *) * pmp->pmp_npnodehash,
222 1.16.2.3 yamt M_PUFFS, M_WAITOK);
223 1.16.2.3 yamt for (i = 0; i < pmp->pmp_npnodehash; i++)
224 1.16.2.3 yamt LIST_INIT(&pmp->pmp_pnodehash[i]);
225 1.16.2.5 yamt LIST_INIT(&pmp->pmp_newcookie);
226 1.16.2.2 yamt
227 1.16.2.2 yamt /*
228 1.16.2.2 yamt * Inform the fileops processing code that we have a mountpoint.
229 1.16.2.2 yamt * If it doesn't know about anyone with our pid/fd having the
230 1.16.2.2 yamt * device open, punt
231 1.16.2.2 yamt */
232 1.16.2.3 yamt if (puffs_setpmp(l->l_proc->p_pid, args->pa_fd, pmp)) {
233 1.16.2.3 yamt error = ENOENT;
234 1.16.2.3 yamt goto out;
235 1.16.2.2 yamt }
236 1.16.2.2 yamt
237 1.16.2.4 yamt /* XXX: check parameters */
238 1.16.2.4 yamt pmp->pmp_root_cookie = args->pa_root_cookie;
239 1.16.2.4 yamt pmp->pmp_root_vtype = args->pa_root_vtype;
240 1.16.2.4 yamt pmp->pmp_root_vsize = args->pa_root_vsize;
241 1.16.2.4 yamt pmp->pmp_root_rdev = args->pa_root_rdev;
242 1.16.2.4 yamt
243 1.16.2.4 yamt mutex_init(&pmp->pmp_lock, MUTEX_DEFAULT, IPL_NONE);
244 1.16.2.5 yamt cv_init(&pmp->pmp_msg_waiter_cv, "puffsget");
245 1.16.2.4 yamt cv_init(&pmp->pmp_refcount_cv, "puffsref");
246 1.16.2.4 yamt cv_init(&pmp->pmp_unmounting_cv, "puffsum");
247 1.16.2.5 yamt TAILQ_INIT(&pmp->pmp_msg_touser);
248 1.16.2.5 yamt TAILQ_INIT(&pmp->pmp_msg_replywait);
249 1.16.2.2 yamt
250 1.16.2.2 yamt DPRINTF(("puffs_mount: mount point at %p, puffs specific at %p\n",
251 1.16.2.2 yamt mp, MPTOPUFFSMP(mp)));
252 1.16.2.2 yamt
253 1.16.2.2 yamt vfs_getnewfsid(mp);
254 1.16.2.2 yamt
255 1.16.2.3 yamt out:
256 1.16.2.3 yamt if (error && pmp && pmp->pmp_pnodehash)
257 1.16.2.3 yamt free(pmp->pmp_pnodehash, M_PUFFS);
258 1.16.2.3 yamt if (error && pmp)
259 1.16.2.3 yamt FREE(pmp, M_PUFFS);
260 1.16.2.3 yamt FREE(args, M_PUFFS);
261 1.16.2.3 yamt return error;
262 1.16.2.2 yamt }
263 1.16.2.2 yamt
264 1.16.2.2 yamt int
265 1.16.2.4 yamt puffs_start(struct mount *mp, int flags, struct lwp *l)
266 1.16.2.2 yamt {
267 1.16.2.4 yamt struct puffs_mount *pmp = MPTOPUFFSMP(mp);
268 1.16.2.2 yamt
269 1.16.2.4 yamt KASSERT(pmp->pmp_status == PUFFSTAT_MOUNTING);
270 1.16.2.2 yamt pmp->pmp_status = PUFFSTAT_RUNNING;
271 1.16.2.2 yamt
272 1.16.2.2 yamt return 0;
273 1.16.2.2 yamt }
274 1.16.2.2 yamt
275 1.16.2.2 yamt int
276 1.16.2.2 yamt puffs_unmount(struct mount *mp, int mntflags, struct lwp *l)
277 1.16.2.2 yamt {
278 1.16.2.5 yamt PUFFS_MSG_VARS(vfs, unmount);
279 1.16.2.2 yamt struct puffs_mount *pmp;
280 1.16.2.2 yamt int error, force;
281 1.16.2.2 yamt
282 1.16.2.2 yamt error = 0;
283 1.16.2.2 yamt force = mntflags & MNT_FORCE;
284 1.16.2.2 yamt pmp = MPTOPUFFSMP(mp);
285 1.16.2.2 yamt
286 1.16.2.2 yamt DPRINTF(("puffs_unmount: detach filesystem from vfs, current "
287 1.16.2.2 yamt "status 0x%x\n", pmp->pmp_status));
288 1.16.2.2 yamt
289 1.16.2.2 yamt /*
290 1.16.2.2 yamt * flush all the vnodes. VOP_RECLAIM() takes care that the
291 1.16.2.2 yamt * root vnode does not get flushed until unmount. The
292 1.16.2.2 yamt * userspace root node cookie is stored in the mount
293 1.16.2.2 yamt * structure, so we can always re-instantiate a root vnode,
294 1.16.2.2 yamt * should userspace unmount decide it doesn't want to
295 1.16.2.2 yamt * cooperate.
296 1.16.2.2 yamt */
297 1.16.2.2 yamt error = vflush(mp, NULLVP, force ? FORCECLOSE : 0);
298 1.16.2.2 yamt if (error)
299 1.16.2.2 yamt goto out;
300 1.16.2.2 yamt
301 1.16.2.2 yamt /*
302 1.16.2.2 yamt * If we are not DYING, we should ask userspace's opinion
303 1.16.2.2 yamt * about the situation
304 1.16.2.2 yamt */
305 1.16.2.4 yamt mutex_enter(&pmp->pmp_lock);
306 1.16.2.2 yamt if (pmp->pmp_status != PUFFSTAT_DYING) {
307 1.16.2.2 yamt pmp->pmp_unmounting = 1;
308 1.16.2.4 yamt mutex_exit(&pmp->pmp_lock);
309 1.16.2.2 yamt
310 1.16.2.5 yamt PUFFS_MSG_ALLOC(vfs, unmount);
311 1.16.2.5 yamt unmount_msg->pvfsr_flags = mntflags;
312 1.16.2.5 yamt puffs_cidcvt(&unmount_msg->pvfsr_cid, l);
313 1.16.2.5 yamt
314 1.16.2.5 yamt error = puffs_msg_vfs(pmp, park_unmount, PUFFS_VFS_UNMOUNT);
315 1.16.2.5 yamt PUFFS_MSG_RELEASE(unmount);
316 1.16.2.2 yamt
317 1.16.2.5 yamt error = checkerr(pmp, error, __func__);
318 1.16.2.2 yamt DPRINTF(("puffs_unmount: error %d force %d\n", error, force));
319 1.16.2.2 yamt
320 1.16.2.4 yamt mutex_enter(&pmp->pmp_lock);
321 1.16.2.2 yamt pmp->pmp_unmounting = 0;
322 1.16.2.4 yamt cv_broadcast(&pmp->pmp_unmounting_cv);
323 1.16.2.2 yamt }
324 1.16.2.2 yamt
325 1.16.2.2 yamt /*
326 1.16.2.2 yamt * if userspace cooperated or we really need to die,
327 1.16.2.2 yamt * screw what userland thinks and just die.
328 1.16.2.2 yamt */
329 1.16.2.2 yamt if (error == 0 || force) {
330 1.16.2.3 yamt /* tell waiters & other resources to go unwait themselves */
331 1.16.2.3 yamt puffs_userdead(pmp);
332 1.16.2.2 yamt puffs_nukebypmp(pmp);
333 1.16.2.3 yamt
334 1.16.2.3 yamt /*
335 1.16.2.4 yamt * Wait until there are no more users for the mount resource.
336 1.16.2.4 yamt * Notice that this is hooked against transport_close
337 1.16.2.4 yamt * and return from touser. In an ideal world, it would
338 1.16.2.4 yamt * be hooked against final return from all operations.
339 1.16.2.4 yamt * But currently it works well enough, since nobody
340 1.16.2.4 yamt * does weird blocking voodoo after return from touser().
341 1.16.2.3 yamt */
342 1.16.2.4 yamt while (pmp->pmp_refcount != 0)
343 1.16.2.4 yamt cv_wait(&pmp->pmp_refcount_cv, &pmp->pmp_lock);
344 1.16.2.4 yamt mutex_exit(&pmp->pmp_lock);
345 1.16.2.3 yamt
346 1.16.2.3 yamt /* free resources now that we hopefully have no waiters left */
347 1.16.2.4 yamt cv_destroy(&pmp->pmp_unmounting_cv);
348 1.16.2.4 yamt cv_destroy(&pmp->pmp_refcount_cv);
349 1.16.2.5 yamt cv_destroy(&pmp->pmp_msg_waiter_cv);
350 1.16.2.4 yamt mutex_destroy(&pmp->pmp_lock);
351 1.16.2.4 yamt
352 1.16.2.3 yamt free(pmp->pmp_pnodehash, M_PUFFS);
353 1.16.2.2 yamt FREE(pmp, M_PUFFS);
354 1.16.2.2 yamt error = 0;
355 1.16.2.2 yamt } else {
356 1.16.2.4 yamt mutex_exit(&pmp->pmp_lock);
357 1.16.2.2 yamt }
358 1.16.2.2 yamt
359 1.16.2.2 yamt out:
360 1.16.2.2 yamt DPRINTF(("puffs_unmount: return %d\n", error));
361 1.16.2.2 yamt return error;
362 1.16.2.2 yamt }
363 1.16.2.2 yamt
364 1.16.2.2 yamt /*
365 1.16.2.2 yamt * This doesn't need to travel to userspace
366 1.16.2.2 yamt */
367 1.16.2.2 yamt int
368 1.16.2.2 yamt puffs_root(struct mount *mp, struct vnode **vpp)
369 1.16.2.2 yamt {
370 1.16.2.4 yamt struct puffs_mount *pmp = MPTOPUFFSMP(mp);
371 1.16.2.5 yamt int rv;
372 1.16.2.2 yamt
373 1.16.2.5 yamt rv = puffs_cookie2vnode(pmp, pmp->pmp_root_cookie, 1, 1, vpp);
374 1.16.2.5 yamt KASSERT(rv != PUFFS_NOSUCHCOOKIE);
375 1.16.2.5 yamt return rv;
376 1.16.2.2 yamt }
377 1.16.2.2 yamt
378 1.16.2.2 yamt int
379 1.16.2.2 yamt puffs_statvfs(struct mount *mp, struct statvfs *sbp, struct lwp *l)
380 1.16.2.2 yamt {
381 1.16.2.5 yamt PUFFS_MSG_VARS(vfs, statvfs);
382 1.16.2.2 yamt struct puffs_mount *pmp;
383 1.16.2.2 yamt int error = 0;
384 1.16.2.2 yamt
385 1.16.2.2 yamt pmp = MPTOPUFFSMP(mp);
386 1.16.2.2 yamt
387 1.16.2.2 yamt /*
388 1.16.2.2 yamt * If we are mounting, it means that the userspace counterpart
389 1.16.2.2 yamt * is calling mount(2), but mount(2) also calls statvfs. So
390 1.16.2.2 yamt * requesting statvfs from userspace would mean a deadlock.
391 1.16.2.2 yamt * Compensate.
392 1.16.2.2 yamt */
393 1.16.2.2 yamt if (pmp->pmp_status == PUFFSTAT_MOUNTING)
394 1.16.2.2 yamt return EINPROGRESS;
395 1.16.2.2 yamt
396 1.16.2.5 yamt PUFFS_MSG_ALLOC(vfs, statvfs);
397 1.16.2.5 yamt puffs_cidcvt(&statvfs_msg->pvfsr_cid, l);
398 1.16.2.5 yamt
399 1.16.2.5 yamt error = puffs_msg_vfs(pmp, park_statvfs, PUFFS_VFS_STATVFS);
400 1.16.2.5 yamt error = checkerr(pmp, error, __func__);
401 1.16.2.5 yamt statvfs_msg->pvfsr_sb.f_iosize = DEV_BSIZE;
402 1.16.2.2 yamt
403 1.16.2.2 yamt /*
404 1.16.2.2 yamt * Try to produce a sensible result even in the event
405 1.16.2.2 yamt * of userspace error.
406 1.16.2.2 yamt *
407 1.16.2.2 yamt * XXX: cache the copy in non-error case
408 1.16.2.2 yamt */
409 1.16.2.2 yamt if (!error) {
410 1.16.2.5 yamt copy_statvfs_info(&statvfs_msg->pvfsr_sb, mp);
411 1.16.2.5 yamt (void)memcpy(sbp, &statvfs_msg->pvfsr_sb,
412 1.16.2.2 yamt sizeof(struct statvfs));
413 1.16.2.2 yamt } else {
414 1.16.2.2 yamt copy_statvfs_info(sbp, mp);
415 1.16.2.2 yamt }
416 1.16.2.2 yamt
417 1.16.2.5 yamt PUFFS_MSG_RELEASE(statvfs);
418 1.16.2.2 yamt return error;
419 1.16.2.2 yamt }
420 1.16.2.2 yamt
421 1.16.2.3 yamt static int
422 1.16.2.4 yamt pageflush(struct mount *mp, kauth_cred_t cred,
423 1.16.2.4 yamt int waitfor, int suspending, struct lwp *l)
424 1.16.2.3 yamt {
425 1.16.2.3 yamt struct puffs_node *pn;
426 1.16.2.3 yamt struct vnode *vp, *nvp;
427 1.16.2.4 yamt int error, rv;
428 1.16.2.3 yamt
429 1.16.2.3 yamt KASSERT(((waitfor == MNT_WAIT) && suspending) == 0);
430 1.16.2.3 yamt KASSERT((suspending == 0)
431 1.16.2.3 yamt || (fstrans_is_owner(mp)
432 1.16.2.3 yamt && fstrans_getstate(mp) == FSTRANS_SUSPENDING));
433 1.16.2.3 yamt
434 1.16.2.3 yamt error = 0;
435 1.16.2.3 yamt
436 1.16.2.3 yamt /*
437 1.16.2.3 yamt * Sync all cached data from regular vnodes (which are not
438 1.16.2.3 yamt * currently locked, see below). After this we call VFS_SYNC
439 1.16.2.3 yamt * for the fs server, which should handle data and metadata for
440 1.16.2.3 yamt * all the nodes it knows to exist.
441 1.16.2.3 yamt */
442 1.16.2.3 yamt simple_lock(&mntvnode_slock);
443 1.16.2.3 yamt loop:
444 1.16.2.3 yamt for (vp = TAILQ_FIRST(&mp->mnt_vnodelist); vp; vp = nvp) {
445 1.16.2.3 yamt /* check if we're on the right list */
446 1.16.2.3 yamt if (vp->v_mount != mp)
447 1.16.2.3 yamt goto loop;
448 1.16.2.3 yamt
449 1.16.2.3 yamt simple_lock(&vp->v_interlock);
450 1.16.2.3 yamt pn = VPTOPP(vp);
451 1.16.2.3 yamt nvp = TAILQ_NEXT(vp, v_mntvnodes);
452 1.16.2.3 yamt
453 1.16.2.3 yamt if (vp->v_type != VREG || UVM_OBJ_IS_CLEAN(&vp->v_uobj)) {
454 1.16.2.3 yamt simple_unlock(&vp->v_interlock);
455 1.16.2.3 yamt continue;
456 1.16.2.3 yamt }
457 1.16.2.3 yamt
458 1.16.2.3 yamt simple_unlock(&mntvnode_slock);
459 1.16.2.3 yamt
460 1.16.2.3 yamt /*
461 1.16.2.3 yamt * Here we try to get a reference to the vnode and to
462 1.16.2.3 yamt * lock it. This is mostly cargo-culted, but I will
463 1.16.2.3 yamt * offer an explanation to why I believe this might
464 1.16.2.3 yamt * actually do the right thing.
465 1.16.2.3 yamt *
466 1.16.2.3 yamt * If the vnode is a goner, we quite obviously don't need
467 1.16.2.3 yamt * to sync it.
468 1.16.2.3 yamt *
469 1.16.2.3 yamt * If the vnode was busy, we don't need to sync it because
470 1.16.2.3 yamt * this is never called with MNT_WAIT except from
471 1.16.2.3 yamt * dounmount(), when we are wait-flushing all the dirty
472 1.16.2.3 yamt * vnodes through other routes in any case. So there,
473 1.16.2.3 yamt * sync() doesn't actually sync. Happy now?
474 1.16.2.3 yamt *
475 1.16.2.3 yamt * NOTE: if we're suspending, vget() does NOT lock.
476 1.16.2.3 yamt * See puffs_lock() for details.
477 1.16.2.3 yamt */
478 1.16.2.3 yamt rv = vget(vp, LK_EXCLUSIVE | LK_NOWAIT | LK_INTERLOCK);
479 1.16.2.3 yamt if (rv) {
480 1.16.2.3 yamt simple_lock(&mntvnode_slock);
481 1.16.2.3 yamt if (rv == ENOENT)
482 1.16.2.3 yamt goto loop;
483 1.16.2.3 yamt continue;
484 1.16.2.3 yamt }
485 1.16.2.3 yamt
486 1.16.2.3 yamt /*
487 1.16.2.3 yamt * Thread information to puffs_strategy() through the
488 1.16.2.3 yamt * pnode flags: we want to issue the putpages operations
489 1.16.2.3 yamt * as FAF if we're suspending, since it's very probable
490 1.16.2.3 yamt * that our execution context is that of the userspace
491 1.16.2.3 yamt * daemon. We can do this because:
492 1.16.2.3 yamt * + we send the "going to suspend" prior to this part
493 1.16.2.3 yamt * + if any of the writes fails in userspace, it's the
494 1.16.2.3 yamt * file system server's problem to decide if this was a
495 1.16.2.3 yamt * failed snapshot when it gets the "snapshot complete"
496 1.16.2.3 yamt * notification.
497 1.16.2.3 yamt * + if any of the writes fail in the kernel already, we
498 1.16.2.3 yamt * immediately fail *and* notify the user server of
499 1.16.2.3 yamt * failure.
500 1.16.2.3 yamt *
501 1.16.2.3 yamt * We also do FAFs if we're called from the syncer. This
502 1.16.2.3 yamt * is just general optimization for trickle sync: no need
503 1.16.2.3 yamt * to really guarantee that the stuff ended on backing
504 1.16.2.3 yamt * storage.
505 1.16.2.3 yamt * TODO: Maybe also hint the user server of this twist?
506 1.16.2.3 yamt */
507 1.16.2.4 yamt if (suspending || waitfor == MNT_LAZY) {
508 1.16.2.4 yamt simple_lock(&vp->v_interlock);
509 1.16.2.3 yamt pn->pn_stat |= PNODE_SUSPEND;
510 1.16.2.4 yamt simple_unlock(&vp->v_interlock);
511 1.16.2.4 yamt }
512 1.16.2.4 yamt rv = VOP_FSYNC(vp, cred, waitfor, 0, 0, l);
513 1.16.2.3 yamt if (suspending || waitfor == MNT_LAZY) {
514 1.16.2.3 yamt simple_lock(&vp->v_interlock);
515 1.16.2.3 yamt pn->pn_stat &= ~PNODE_SUSPEND;
516 1.16.2.3 yamt simple_unlock(&vp->v_interlock);
517 1.16.2.3 yamt }
518 1.16.2.3 yamt if (rv)
519 1.16.2.3 yamt error = rv;
520 1.16.2.3 yamt vput(vp);
521 1.16.2.3 yamt simple_lock(&mntvnode_slock);
522 1.16.2.3 yamt }
523 1.16.2.3 yamt simple_unlock(&mntvnode_slock);
524 1.16.2.3 yamt
525 1.16.2.3 yamt return error;
526 1.16.2.3 yamt }
527 1.16.2.3 yamt
528 1.16.2.2 yamt int
529 1.16.2.2 yamt puffs_sync(struct mount *mp, int waitfor, struct kauth_cred *cred,
530 1.16.2.2 yamt struct lwp *l)
531 1.16.2.2 yamt {
532 1.16.2.5 yamt PUFFS_MSG_VARS(vfs, sync);
533 1.16.2.5 yamt struct puffs_mount *pmp = MPTOPUFFSMP(mp);
534 1.16.2.3 yamt int error, rv;
535 1.16.2.2 yamt
536 1.16.2.4 yamt error = pageflush(mp, cred, waitfor, 0, l);
537 1.16.2.3 yamt
538 1.16.2.3 yamt /* sync fs */
539 1.16.2.5 yamt PUFFS_MSG_ALLOC(vfs, sync);
540 1.16.2.5 yamt sync_msg->pvfsr_waitfor = waitfor;
541 1.16.2.5 yamt puffs_credcvt(&sync_msg->pvfsr_cred, cred);
542 1.16.2.5 yamt puffs_cidcvt(&sync_msg->pvfsr_cid, l);
543 1.16.2.2 yamt
544 1.16.2.5 yamt rv = puffs_msg_vfs(pmp, park_sync, PUFFS_VFS_SYNC);
545 1.16.2.5 yamt rv = checkerr(pmp, rv, __func__);
546 1.16.2.3 yamt if (rv)
547 1.16.2.3 yamt error = rv;
548 1.16.2.2 yamt
549 1.16.2.5 yamt PUFFS_MSG_RELEASE(sync);
550 1.16.2.2 yamt return error;
551 1.16.2.2 yamt }
552 1.16.2.2 yamt
553 1.16.2.2 yamt int
554 1.16.2.4 yamt puffs_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
555 1.16.2.2 yamt {
556 1.16.2.5 yamt PUFFS_MSG_VARS(vfs, fhtonode);
557 1.16.2.4 yamt struct puffs_mount *pmp = MPTOPUFFSMP(mp);
558 1.16.2.4 yamt struct vnode *vp;
559 1.16.2.4 yamt void *fhdata;
560 1.16.2.4 yamt size_t argsize, fhlen;
561 1.16.2.4 yamt int error;
562 1.16.2.2 yamt
563 1.16.2.4 yamt if (pmp->pmp_args.pa_fhsize == 0)
564 1.16.2.4 yamt return EOPNOTSUPP;
565 1.16.2.2 yamt
566 1.16.2.4 yamt if (pmp->pmp_args.pa_fhflags & PUFFS_FHFLAG_PASSTHROUGH) {
567 1.16.2.4 yamt fhlen = fhp->fid_len;
568 1.16.2.4 yamt fhdata = fhp;
569 1.16.2.4 yamt } else {
570 1.16.2.4 yamt fhlen = PUFFS_FROMFHSIZE(fhp->fid_len);
571 1.16.2.4 yamt fhdata = fhp->fid_data;
572 1.16.2.2 yamt
573 1.16.2.4 yamt if (pmp->pmp_args.pa_fhflags & PUFFS_FHFLAG_DYNAMIC) {
574 1.16.2.4 yamt if (pmp->pmp_args.pa_fhsize < fhlen)
575 1.16.2.4 yamt return EINVAL;
576 1.16.2.4 yamt } else {
577 1.16.2.4 yamt if (pmp->pmp_args.pa_fhsize != fhlen)
578 1.16.2.4 yamt return EINVAL;
579 1.16.2.4 yamt }
580 1.16.2.4 yamt }
581 1.16.2.4 yamt
582 1.16.2.5 yamt argsize = sizeof(struct puffs_vfsmsg_fhtonode) + fhlen;
583 1.16.2.5 yamt puffs_msgmem_alloc(argsize, &park_fhtonode, (void **)&fhtonode_msg, 1);
584 1.16.2.5 yamt fhtonode_msg->pvfsr_dsize = fhlen;
585 1.16.2.5 yamt memcpy(fhtonode_msg->pvfsr_data, fhdata, fhlen);
586 1.16.2.4 yamt
587 1.16.2.5 yamt error = puffs_msg_vfs(pmp, park_fhtonode, PUFFS_VFS_FHTOVP);
588 1.16.2.5 yamt error = checkerr(pmp, error, __func__);
589 1.16.2.4 yamt if (error)
590 1.16.2.4 yamt goto out;
591 1.16.2.4 yamt
592 1.16.2.5 yamt error = puffs_cookie2vnode(pmp, fhtonode_msg->pvfsr_fhcookie, 1,1,&vp);
593 1.16.2.4 yamt DPRINTF(("puffs_fhtovp: got cookie %p, existing vnode %p\n",
594 1.16.2.5 yamt fhtonode_msg->pvfsr_fhcookie, vp));
595 1.16.2.5 yamt if (error == PUFFS_NOSUCHCOOKIE) {
596 1.16.2.5 yamt error = puffs_getvnode(mp, fhtonode_msg->pvfsr_fhcookie,
597 1.16.2.5 yamt fhtonode_msg->pvfsr_vtype, fhtonode_msg->pvfsr_size,
598 1.16.2.5 yamt fhtonode_msg->pvfsr_rdev, &vp);
599 1.16.2.4 yamt if (error)
600 1.16.2.4 yamt goto out;
601 1.16.2.4 yamt vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
602 1.16.2.5 yamt } else if (error) {
603 1.16.2.5 yamt goto out;
604 1.16.2.4 yamt }
605 1.16.2.4 yamt
606 1.16.2.4 yamt *vpp = vp;
607 1.16.2.4 yamt out:
608 1.16.2.5 yamt puffs_msgmem_release(park_fhtonode);
609 1.16.2.4 yamt return error;
610 1.16.2.2 yamt }
611 1.16.2.2 yamt
612 1.16.2.2 yamt int
613 1.16.2.4 yamt puffs_vptofh(struct vnode *vp, struct fid *fhp, size_t *fh_size)
614 1.16.2.2 yamt {
615 1.16.2.5 yamt PUFFS_MSG_VARS(vfs, nodetofh);
616 1.16.2.4 yamt struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
617 1.16.2.4 yamt size_t argsize, fhlen;
618 1.16.2.4 yamt int error;
619 1.16.2.2 yamt
620 1.16.2.4 yamt if (pmp->pmp_args.pa_fhsize == 0)
621 1.16.2.4 yamt return EOPNOTSUPP;
622 1.16.2.4 yamt
623 1.16.2.4 yamt /* if file handles are static len, we can test len immediately */
624 1.16.2.4 yamt if (((pmp->pmp_args.pa_fhflags & PUFFS_FHFLAG_DYNAMIC) == 0)
625 1.16.2.4 yamt && ((pmp->pmp_args.pa_fhflags & PUFFS_FHFLAG_PASSTHROUGH) == 0)
626 1.16.2.4 yamt && (PUFFS_FROMFHSIZE(*fh_size) < pmp->pmp_args.pa_fhsize)) {
627 1.16.2.4 yamt *fh_size = PUFFS_TOFHSIZE(pmp->pmp_args.pa_fhsize);
628 1.16.2.4 yamt return E2BIG;
629 1.16.2.4 yamt }
630 1.16.2.4 yamt
631 1.16.2.4 yamt if (pmp->pmp_args.pa_fhflags & PUFFS_FHFLAG_PASSTHROUGH)
632 1.16.2.4 yamt fhlen = *fh_size;
633 1.16.2.4 yamt else
634 1.16.2.4 yamt fhlen = PUFFS_FROMFHSIZE(*fh_size);
635 1.16.2.4 yamt
636 1.16.2.5 yamt argsize = sizeof(struct puffs_vfsmsg_nodetofh) + fhlen;
637 1.16.2.5 yamt puffs_msgmem_alloc(argsize, &park_nodetofh, (void **)&nodetofh_msg, 1);
638 1.16.2.5 yamt nodetofh_msg->pvfsr_fhcookie = VPTOPNC(vp);
639 1.16.2.5 yamt nodetofh_msg->pvfsr_dsize = fhlen;
640 1.16.2.4 yamt
641 1.16.2.5 yamt error = puffs_msg_vfs(pmp, park_nodetofh, PUFFS_VFS_VPTOFH);
642 1.16.2.5 yamt error = checkerr(pmp, error, __func__);
643 1.16.2.4 yamt
644 1.16.2.4 yamt if (pmp->pmp_args.pa_fhflags & PUFFS_FHFLAG_PASSTHROUGH)
645 1.16.2.5 yamt fhlen = nodetofh_msg->pvfsr_dsize;
646 1.16.2.4 yamt else if (pmp->pmp_args.pa_fhflags & PUFFS_FHFLAG_DYNAMIC)
647 1.16.2.5 yamt fhlen = PUFFS_TOFHSIZE(nodetofh_msg->pvfsr_dsize);
648 1.16.2.4 yamt else
649 1.16.2.4 yamt fhlen = PUFFS_TOFHSIZE(pmp->pmp_args.pa_fhsize);
650 1.16.2.4 yamt
651 1.16.2.4 yamt if (error) {
652 1.16.2.4 yamt if (error == E2BIG)
653 1.16.2.4 yamt *fh_size = fhlen;
654 1.16.2.4 yamt goto out;
655 1.16.2.4 yamt }
656 1.16.2.4 yamt
657 1.16.2.4 yamt if (fhlen > FHANDLE_SIZE_MAX) {
658 1.16.2.5 yamt puffs_msg_errnotify(pmp, PUFFS_ERR_VPTOFH, E2BIG,
659 1.16.2.5 yamt "file handle too big", VPTOPNC(vp));
660 1.16.2.5 yamt error = EPROTO;
661 1.16.2.4 yamt goto out;
662 1.16.2.4 yamt }
663 1.16.2.4 yamt
664 1.16.2.4 yamt if (*fh_size < fhlen) {
665 1.16.2.4 yamt *fh_size = fhlen;
666 1.16.2.4 yamt error = E2BIG;
667 1.16.2.4 yamt goto out;
668 1.16.2.4 yamt }
669 1.16.2.4 yamt *fh_size = fhlen;
670 1.16.2.4 yamt
671 1.16.2.4 yamt if (fhp) {
672 1.16.2.4 yamt if (pmp->pmp_args.pa_fhflags & PUFFS_FHFLAG_PASSTHROUGH) {
673 1.16.2.5 yamt memcpy(fhp, nodetofh_msg->pvfsr_data, fhlen);
674 1.16.2.4 yamt } else {
675 1.16.2.4 yamt fhp->fid_len = *fh_size;
676 1.16.2.5 yamt memcpy(fhp->fid_data, nodetofh_msg->pvfsr_data,
677 1.16.2.5 yamt nodetofh_msg->pvfsr_dsize);
678 1.16.2.4 yamt }
679 1.16.2.4 yamt }
680 1.16.2.4 yamt
681 1.16.2.4 yamt out:
682 1.16.2.5 yamt puffs_msgmem_release(park_nodetofh);
683 1.16.2.4 yamt return error;
684 1.16.2.2 yamt }
685 1.16.2.2 yamt
686 1.16.2.2 yamt void
687 1.16.2.2 yamt puffs_init()
688 1.16.2.2 yamt {
689 1.16.2.2 yamt
690 1.16.2.5 yamt /* some checks depend on this */
691 1.16.2.5 yamt KASSERT(VNOVAL == VSIZENOTSET);
692 1.16.2.5 yamt
693 1.16.2.2 yamt malloc_type_attach(M_PUFFS);
694 1.16.2.2 yamt
695 1.16.2.4 yamt pool_init(&puffs_pnpool, sizeof(struct puffs_node), 0, 0, 0,
696 1.16.2.4 yamt "puffpnpl", &pool_allocator_nointr, IPL_NONE);
697 1.16.2.4 yamt puffs_transport_init();
698 1.16.2.4 yamt puffs_msgif_init();
699 1.16.2.2 yamt }
700 1.16.2.2 yamt
701 1.16.2.2 yamt void
702 1.16.2.2 yamt puffs_done()
703 1.16.2.2 yamt {
704 1.16.2.2 yamt
705 1.16.2.4 yamt puffs_msgif_destroy();
706 1.16.2.4 yamt puffs_transport_destroy();
707 1.16.2.2 yamt pool_destroy(&puffs_pnpool);
708 1.16.2.2 yamt
709 1.16.2.4 yamt malloc_type_detach(M_PUFFS);
710 1.16.2.2 yamt }
711 1.16.2.2 yamt
712 1.16.2.2 yamt int
713 1.16.2.2 yamt puffs_snapshot(struct mount *mp, struct vnode *vp, struct timespec *ts)
714 1.16.2.2 yamt {
715 1.16.2.2 yamt
716 1.16.2.2 yamt return EOPNOTSUPP;
717 1.16.2.2 yamt }
718 1.16.2.2 yamt
719 1.16.2.3 yamt int
720 1.16.2.3 yamt puffs_suspendctl(struct mount *mp, int cmd)
721 1.16.2.3 yamt {
722 1.16.2.5 yamt PUFFS_MSG_VARS(vfs, suspend);
723 1.16.2.3 yamt struct puffs_mount *pmp;
724 1.16.2.3 yamt int error;
725 1.16.2.3 yamt
726 1.16.2.3 yamt pmp = MPTOPUFFSMP(mp);
727 1.16.2.3 yamt switch (cmd) {
728 1.16.2.3 yamt case SUSPEND_SUSPEND:
729 1.16.2.3 yamt DPRINTF(("puffs_suspendctl: suspending\n"));
730 1.16.2.3 yamt if ((error = fstrans_setstate(mp, FSTRANS_SUSPENDING)) != 0)
731 1.16.2.3 yamt break;
732 1.16.2.5 yamt PUFFS_MSG_ALLOC(vfs, suspend);
733 1.16.2.5 yamt puffs_msg_setfaf(park_suspend);
734 1.16.2.5 yamt suspend_msg->pvfsr_status = PUFFS_SUSPEND_START;
735 1.16.2.5 yamt puffs_msg_vfs(pmp, park_suspend, PUFFS_VFS_SUSPEND);
736 1.16.2.5 yamt PUFFS_MSG_RELEASE(suspend);
737 1.16.2.3 yamt
738 1.16.2.4 yamt error = pageflush(mp, FSCRED, 0, 1, curlwp);
739 1.16.2.3 yamt if (error == 0)
740 1.16.2.3 yamt error = fstrans_setstate(mp, FSTRANS_SUSPENDED);
741 1.16.2.3 yamt
742 1.16.2.3 yamt if (error != 0) {
743 1.16.2.5 yamt PUFFS_MSG_ALLOC(vfs, suspend);
744 1.16.2.5 yamt puffs_msg_setfaf(park_suspend);
745 1.16.2.5 yamt suspend_msg->pvfsr_status = PUFFS_SUSPEND_ERROR;
746 1.16.2.5 yamt puffs_msg_vfs(pmp, park_suspend, PUFFS_VFS_SUSPEND);
747 1.16.2.5 yamt PUFFS_MSG_RELEASE(suspend);
748 1.16.2.3 yamt (void) fstrans_setstate(mp, FSTRANS_NORMAL);
749 1.16.2.3 yamt break;
750 1.16.2.3 yamt }
751 1.16.2.3 yamt
752 1.16.2.5 yamt PUFFS_MSG_ALLOC(vfs, suspend);
753 1.16.2.5 yamt puffs_msg_setfaf(park_suspend);
754 1.16.2.5 yamt suspend_msg->pvfsr_status = PUFFS_SUSPEND_SUSPENDED;
755 1.16.2.5 yamt puffs_msg_vfs(pmp, park_suspend, PUFFS_VFS_SUSPEND);
756 1.16.2.5 yamt PUFFS_MSG_RELEASE(suspend);
757 1.16.2.3 yamt
758 1.16.2.3 yamt break;
759 1.16.2.3 yamt
760 1.16.2.3 yamt case SUSPEND_RESUME:
761 1.16.2.3 yamt DPRINTF(("puffs_suspendctl: resume\n"));
762 1.16.2.3 yamt error = 0;
763 1.16.2.3 yamt (void) fstrans_setstate(mp, FSTRANS_NORMAL);
764 1.16.2.5 yamt PUFFS_MSG_ALLOC(vfs, suspend);
765 1.16.2.5 yamt puffs_msg_setfaf(park_suspend);
766 1.16.2.5 yamt suspend_msg->pvfsr_status = PUFFS_SUSPEND_RESUME;
767 1.16.2.5 yamt puffs_msg_vfs(pmp, park_suspend, PUFFS_VFS_SUSPEND);
768 1.16.2.5 yamt PUFFS_MSG_RELEASE(suspend);
769 1.16.2.3 yamt break;
770 1.16.2.3 yamt
771 1.16.2.3 yamt default:
772 1.16.2.3 yamt error = EINVAL;
773 1.16.2.3 yamt break;
774 1.16.2.3 yamt }
775 1.16.2.3 yamt
776 1.16.2.3 yamt DPRINTF(("puffs_suspendctl: return %d\n", error));
777 1.16.2.3 yamt return error;
778 1.16.2.3 yamt }
779 1.16.2.3 yamt
780 1.16.2.2 yamt const struct vnodeopv_desc * const puffs_vnodeopv_descs[] = {
781 1.16.2.2 yamt &puffs_vnodeop_opv_desc,
782 1.16.2.2 yamt &puffs_specop_opv_desc,
783 1.16.2.2 yamt &puffs_fifoop_opv_desc,
784 1.16.2.2 yamt &puffs_msgop_opv_desc,
785 1.16.2.2 yamt NULL,
786 1.16.2.2 yamt };
787 1.16.2.2 yamt
788 1.16.2.2 yamt struct vfsops puffs_vfsops = {
789 1.16.2.2 yamt MOUNT_PUFFS,
790 1.16.2.4 yamt sizeof (struct puffs_kargs),
791 1.16.2.2 yamt puffs_mount, /* mount */
792 1.16.2.2 yamt puffs_start, /* start */
793 1.16.2.2 yamt puffs_unmount, /* unmount */
794 1.16.2.2 yamt puffs_root, /* root */
795 1.16.2.4 yamt (void *)eopnotsupp, /* quotactl */
796 1.16.2.2 yamt puffs_statvfs, /* statvfs */
797 1.16.2.2 yamt puffs_sync, /* sync */
798 1.16.2.4 yamt (void *)eopnotsupp, /* vget */
799 1.16.2.4 yamt puffs_fhtovp, /* fhtovp */
800 1.16.2.4 yamt puffs_vptofh, /* vptofh */
801 1.16.2.2 yamt puffs_init, /* init */
802 1.16.2.2 yamt NULL, /* reinit */
803 1.16.2.2 yamt puffs_done, /* done */
804 1.16.2.2 yamt NULL, /* mountroot */
805 1.16.2.2 yamt puffs_snapshot, /* snapshot */
806 1.16.2.2 yamt vfs_stdextattrctl, /* extattrctl */
807 1.16.2.3 yamt puffs_suspendctl, /* suspendctl */
808 1.16.2.2 yamt puffs_vnodeopv_descs, /* vnodeops */
809 1.16.2.2 yamt 0, /* refcount */
810 1.16.2.2 yamt { NULL, NULL }
811 1.16.2.2 yamt };
812 1.16.2.2 yamt VFS_ATTACH(puffs_vfsops);
813