1 /* $NetBSD: puffs_vfsops.c,v 1.84 2009/12/07 20:57:55 pooka Exp $ */
4 * Copyright (c) 2005, 2006 Antti Kantee. All Rights Reserved.
6 * Development of this software was supported by the
7 * Google Summer of Code program and the Ulla Tuominen Foundation.
8 * The Google SoC project was mentored by Bill Studenmund.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
20 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
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
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: puffs_vfsops.c,v 1.84 2009/12/07 20:57:55 pooka Exp $");
35 #include <sys/param.h>
36 #include <sys/mount.h>
37 #include <sys/malloc.h>
38 #include <sys/extattr.h>
39 #include <sys/queue.h>
40 #include <sys/vnode.h>
41 #include <sys/dirent.h>
42 #include <sys/kauth.h>
44 #include <sys/module.h>
45 #include <sys/kthread.h>
47 #include <dev/putter/putter_sys.h>
49 #include <miscfs/genfs/genfs.h>
51 #include <fs/puffs/puffs_msgif.h>
52 #include <fs/puffs/puffs_sys.h>
54 #include <lib/libkern/libkern.h>
56 #include <nfs/nfsproto.h> /* for fh sizes */
58 MODULE(MODULE_CLASS_VFS
, puffs
, "putter");
60 VFS_PROTOS(puffs_vfsop
);
62 #ifndef PUFFS_PNODEBUCKETS
63 #define PUFFS_PNODEBUCKETS 256
65 #ifndef PUFFS_MAXPNODEBUCKETS
66 #define PUFFS_MAXPNODEBUCKETS 8192
68 int puffs_pnodebuckets_default
= PUFFS_PNODEBUCKETS
;
69 int puffs_maxpnodebuckets
= PUFFS_MAXPNODEBUCKETS
;
71 #define BUCKETALLOC(a) (sizeof(struct puffs_pnode_hashlist *) * (a))
73 static struct putter_ops puffs_putter
= {
74 .pop_getout
= puffs_msgif_getout
,
75 .pop_releaseout
= puffs_msgif_releaseout
,
76 .pop_waitcount
= puffs_msgif_waitcount
,
77 .pop_dispatch
= puffs_msgif_dispatch
,
78 .pop_close
= puffs_msgif_close
,
82 puffs_vfsop_mount(struct mount
*mp
, const char *path
, void *data
,
85 struct puffs_mount
*pmp
= NULL
;
86 struct puffs_kargs
*args
;
87 char fstype
[_VFS_NAMELEN
];
90 pid_t mntpid
= curlwp
->l_proc
->p_pid
;
92 if (*data_len
< sizeof *args
)
95 if (mp
->mnt_flag
& MNT_GETARGS
) {
96 pmp
= MPTOPUFFSMP(mp
);
97 *(struct puffs_kargs
*)data
= pmp
->pmp_args
;
98 *data_len
= sizeof *args
;
102 /* update is not supported currently */
103 if (mp
->mnt_flag
& MNT_UPDATE
)
107 * We need the file system name
112 args
= (struct puffs_kargs
*)data
;
115 if (args
->pa_vers
!= (PUFFSVERSION
| PUFFSDEVELVERS
)) {
116 printf("puffs_mount: development version mismatch: "
117 "kernel %d, lib %d\n",
118 PUFFSVERSION
, args
->pa_vers
& ~PUFFSDEVELVERS
);
123 if ((args
->pa_flags
& ~PUFFS_KFLAG_MASK
) != 0) {
124 printf("puffs_mount: invalid KFLAGs 0x%x\n", args
->pa_flags
);
128 if ((args
->pa_fhflags
& ~PUFFS_FHFLAG_MASK
) != 0) {
129 printf("puffs_mount: invalid FHFLAGs 0x%x\n", args
->pa_fhflags
);
134 /* use dummy value for passthrough */
135 if (args
->pa_fhflags
& PUFFS_FHFLAG_PASSTHROUGH
)
136 args
->pa_fhsize
= sizeof(struct fid
);
138 /* sanitize file handle length */
139 if (PUFFS_TOFHSIZE(args
->pa_fhsize
) > FHANDLE_SIZE_MAX
) {
140 printf("puffs_mount: handle size %zu too large\n",
145 /* sanity check file handle max sizes */
146 if (args
->pa_fhsize
&& args
->pa_fhflags
& PUFFS_FHFLAG_PROTOMASK
) {
147 size_t kfhsize
= PUFFS_TOFHSIZE(args
->pa_fhsize
);
149 if (args
->pa_fhflags
& PUFFS_FHFLAG_NFSV2
) {
150 if (NFSX_FHTOOBIG_P(kfhsize
, 0)) {
151 printf("puffs_mount: fhsize larger than "
153 PUFFS_FROMFHSIZE(NFSX_V2FH
));
159 if (args
->pa_fhflags
& PUFFS_FHFLAG_NFSV3
) {
160 if (NFSX_FHTOOBIG_P(kfhsize
, 1)) {
161 printf("puffs_mount: fhsize larger than "
163 PUFFS_FROMFHSIZE(NFSX_V3FHMAX
));
170 /* don't allow non-printing characters (like my sweet umlauts.. snif) */
171 args
->pa_typename
[sizeof(args
->pa_typename
)-1] = '\0';
172 for (p
= args
->pa_typename
; *p
; p
++)
173 if (*p
< ' ' || *p
> '~')
176 args
->pa_mntfromname
[sizeof(args
->pa_mntfromname
)-1] = '\0';
177 for (p
= args
->pa_mntfromname
; *p
; p
++)
178 if (*p
< ' ' || *p
> '~')
181 /* build real name */
182 (void)strlcpy(fstype
, PUFFS_TYPEPREFIX
, sizeof(fstype
));
183 (void)strlcat(fstype
, args
->pa_typename
, sizeof(fstype
));
185 /* inform user server if it got the max request size it wanted */
186 if (args
->pa_maxmsglen
== 0 || args
->pa_maxmsglen
> PUFFS_MSG_MAXSIZE
)
187 args
->pa_maxmsglen
= PUFFS_MSG_MAXSIZE
;
188 else if (args
->pa_maxmsglen
< 2*PUFFS_MSGSTRUCT_MAX
)
189 args
->pa_maxmsglen
= 2*PUFFS_MSGSTRUCT_MAX
;
191 (void)strlcpy(args
->pa_typename
, fstype
, sizeof(args
->pa_typename
));
193 if (args
->pa_nhashbuckets
== 0)
194 args
->pa_nhashbuckets
= puffs_pnodebuckets_default
;
195 if (args
->pa_nhashbuckets
< 1)
196 args
->pa_nhashbuckets
= 1;
197 if (args
->pa_nhashbuckets
> PUFFS_MAXPNODEBUCKETS
) {
198 args
->pa_nhashbuckets
= puffs_maxpnodebuckets
;
199 printf("puffs_mount: using %d hash buckets. "
200 "adjust puffs_maxpnodebuckets for more\n",
201 puffs_maxpnodebuckets
);
204 error
= set_statvfs_info(path
, UIO_USERSPACE
, args
->pa_mntfromname
,
205 UIO_SYSSPACE
, fstype
, mp
, curlwp
);
208 mp
->mnt_stat
.f_iosize
= DEV_BSIZE
;
211 * We can't handle the VFS_STATVFS() mount_domount() does
212 * after VFS_MOUNT() because we'd deadlock, so handle it
215 copy_statvfs_info(&args
->pa_svfsb
, mp
);
216 (void)memcpy(&mp
->mnt_stat
, &args
->pa_svfsb
, sizeof(mp
->mnt_stat
));
218 pmp
= kmem_zalloc(sizeof(struct puffs_mount
), KM_SLEEP
);
220 mp
->mnt_fs_bshift
= DEV_BSHIFT
;
221 mp
->mnt_dev_bshift
= DEV_BSHIFT
;
222 mp
->mnt_flag
&= ~MNT_LOCAL
; /* we don't really know, so ... */
225 pmp
->pmp_status
= PUFFSTAT_MOUNTING
;
227 pmp
->pmp_msg_maxsize
= args
->pa_maxmsglen
;
228 pmp
->pmp_args
= *args
;
230 pmp
->pmp_npnodehash
= args
->pa_nhashbuckets
;
231 pmp
->pmp_pnodehash
= kmem_alloc(BUCKETALLOC(pmp
->pmp_npnodehash
), KM_SLEEP
);
232 for (i
= 0; i
< pmp
->pmp_npnodehash
; i
++)
233 LIST_INIT(&pmp
->pmp_pnodehash
[i
]);
234 LIST_INIT(&pmp
->pmp_newcookie
);
237 * Inform the fileops processing code that we have a mountpoint.
238 * If it doesn't know about anyone with our pid/fd having the
242 = putter_attach(mntpid
, args
->pa_fd
, pmp
, &puffs_putter
)) == NULL
) {
247 /* XXX: check parameters */
248 pmp
->pmp_root_cookie
= args
->pa_root_cookie
;
249 pmp
->pmp_root_vtype
= args
->pa_root_vtype
;
250 pmp
->pmp_root_vsize
= args
->pa_root_vsize
;
251 pmp
->pmp_root_rdev
= args
->pa_root_rdev
;
253 mutex_init(&pmp
->pmp_lock
, MUTEX_DEFAULT
, IPL_NONE
);
254 mutex_init(&pmp
->pmp_sopmtx
, MUTEX_DEFAULT
, IPL_NONE
);
255 cv_init(&pmp
->pmp_msg_waiter_cv
, "puffsget");
256 cv_init(&pmp
->pmp_refcount_cv
, "puffsref");
257 cv_init(&pmp
->pmp_unmounting_cv
, "puffsum");
258 cv_init(&pmp
->pmp_sopcv
, "puffsop");
259 TAILQ_INIT(&pmp
->pmp_msg_touser
);
260 TAILQ_INIT(&pmp
->pmp_msg_replywait
);
261 TAILQ_INIT(&pmp
->pmp_sopreqs
);
263 if ((error
= kthread_create(PRI_NONE
, KTHREAD_MPSAFE
, NULL
,
264 puffs_sop_thread
, pmp
, NULL
, "puffsop")) != 0)
266 pmp
->pmp_sopthrcount
= 1;
268 DPRINTF(("puffs_mount: mount point at %p, puffs specific at %p\n",
269 mp
, MPTOPUFFSMP(mp
)));
274 if (error
&& pmp
&& pmp
->pmp_pi
)
275 putter_detach(pmp
->pmp_pi
);
276 if (error
&& pmp
&& pmp
->pmp_pnodehash
)
277 kmem_free(pmp
->pmp_pnodehash
, BUCKETALLOC(pmp
->pmp_npnodehash
));
279 kmem_free(pmp
, sizeof(struct puffs_mount
));
284 puffs_vfsop_start(struct mount
*mp
, int flags
)
286 struct puffs_mount
*pmp
= MPTOPUFFSMP(mp
);
288 KASSERT(pmp
->pmp_status
== PUFFSTAT_MOUNTING
);
289 pmp
->pmp_status
= PUFFSTAT_RUNNING
;
295 puffs_vfsop_unmount(struct mount
*mp
, int mntflags
)
297 PUFFS_MSG_VARS(vfs
, unmount
);
298 struct puffs_mount
*pmp
;
302 force
= mntflags
& MNT_FORCE
;
303 pmp
= MPTOPUFFSMP(mp
);
305 DPRINTF(("puffs_unmount: detach filesystem from vfs, current "
306 "status 0x%x\n", pmp
->pmp_status
));
309 * flush all the vnodes. VOP_RECLAIM() takes care that the
310 * root vnode does not get flushed until unmount. The
311 * userspace root node cookie is stored in the mount
312 * structure, so we can always re-instantiate a root vnode,
313 * should userspace unmount decide it doesn't want to
316 error
= vflush(mp
, NULLVP
, force
? FORCECLOSE
: 0);
321 * If we are not DYING, we should ask userspace's opinion
322 * about the situation
324 mutex_enter(&pmp
->pmp_lock
);
325 if (pmp
->pmp_status
!= PUFFSTAT_DYING
) {
326 pmp
->pmp_unmounting
= 1;
327 mutex_exit(&pmp
->pmp_lock
);
329 PUFFS_MSG_ALLOC(vfs
, unmount
);
330 puffs_msg_setinfo(park_unmount
,
331 PUFFSOP_VFS
, PUFFS_VFS_UNMOUNT
, NULL
);
332 unmount_msg
->pvfsr_flags
= mntflags
;
334 PUFFS_MSG_ENQUEUEWAIT(pmp
, park_unmount
, error
);
335 PUFFS_MSG_RELEASE(unmount
);
337 error
= checkerr(pmp
, error
, __func__
);
338 DPRINTF(("puffs_unmount: error %d force %d\n", error
, force
));
340 mutex_enter(&pmp
->pmp_lock
);
341 pmp
->pmp_unmounting
= 0;
342 cv_broadcast(&pmp
->pmp_unmounting_cv
);
346 * if userspace cooperated or we really need to die,
347 * screw what userland thinks and just die.
349 if (error
== 0 || force
) {
350 struct puffs_sopreq
*psopr
;
352 /* tell waiters & other resources to go unwait themselves */
354 putter_detach(pmp
->pmp_pi
);
357 * Wait until there are no more users for the mount resource.
358 * Notice that this is hooked against transport_close
359 * and return from touser. In an ideal world, it would
360 * be hooked against final return from all operations.
361 * But currently it works well enough, since nobody
362 * does weird blocking voodoo after return from touser().
364 while (pmp
->pmp_refcount
!= 0)
365 cv_wait(&pmp
->pmp_refcount_cv
, &pmp
->pmp_lock
);
366 mutex_exit(&pmp
->pmp_lock
);
369 * Release kernel thread now that there is nothing
370 * it would be wanting to lock.
372 psopr
= kmem_alloc(sizeof(*psopr
), KM_SLEEP
);
373 psopr
->psopr_sopreq
= PUFFS_SOPREQSYS_EXIT
;
374 mutex_enter(&pmp
->pmp_sopmtx
);
375 TAILQ_INSERT_TAIL(&pmp
->pmp_sopreqs
, psopr
, psopr_entries
);
376 cv_signal(&pmp
->pmp_sopcv
);
377 while (pmp
->pmp_sopthrcount
> 0)
378 cv_wait(&pmp
->pmp_sopcv
, &pmp
->pmp_sopmtx
);
379 mutex_exit(&pmp
->pmp_sopmtx
);
381 /* free resources now that we hopefully have no waiters left */
382 cv_destroy(&pmp
->pmp_unmounting_cv
);
383 cv_destroy(&pmp
->pmp_refcount_cv
);
384 cv_destroy(&pmp
->pmp_msg_waiter_cv
);
385 cv_destroy(&pmp
->pmp_sopcv
);
386 mutex_destroy(&pmp
->pmp_lock
);
387 mutex_destroy(&pmp
->pmp_sopmtx
);
389 kmem_free(pmp
->pmp_pnodehash
, BUCKETALLOC(pmp
->pmp_npnodehash
));
390 kmem_free(pmp
, sizeof(struct puffs_mount
));
393 mutex_exit(&pmp
->pmp_lock
);
397 DPRINTF(("puffs_unmount: return %d\n", error
));
402 * This doesn't need to travel to userspace
405 puffs_vfsop_root(struct mount
*mp
, struct vnode
**vpp
)
407 struct puffs_mount
*pmp
= MPTOPUFFSMP(mp
);
410 rv
= puffs_cookie2vnode(pmp
, pmp
->pmp_root_cookie
, 1, 1, vpp
);
411 KASSERT(rv
!= PUFFS_NOSUCHCOOKIE
);
416 puffs_vfsop_statvfs(struct mount
*mp
, struct statvfs
*sbp
)
418 PUFFS_MSG_VARS(vfs
, statvfs
);
419 struct puffs_mount
*pmp
;
422 pmp
= MPTOPUFFSMP(mp
);
425 * If we are mounting, it means that the userspace counterpart
426 * is calling mount(2), but mount(2) also calls statvfs. So
427 * requesting statvfs from userspace would mean a deadlock.
430 if (pmp
->pmp_status
== PUFFSTAT_MOUNTING
)
433 PUFFS_MSG_ALLOC(vfs
, statvfs
);
434 puffs_msg_setinfo(park_statvfs
, PUFFSOP_VFS
, PUFFS_VFS_STATVFS
, NULL
);
436 PUFFS_MSG_ENQUEUEWAIT(pmp
, park_statvfs
, error
);
437 error
= checkerr(pmp
, error
, __func__
);
438 statvfs_msg
->pvfsr_sb
.f_iosize
= DEV_BSIZE
;
441 * Try to produce a sensible result even in the event
442 * of userspace error.
444 * XXX: cache the copy in non-error case
447 copy_statvfs_info(&statvfs_msg
->pvfsr_sb
, mp
);
448 (void)memcpy(sbp
, &statvfs_msg
->pvfsr_sb
,
449 sizeof(struct statvfs
));
451 copy_statvfs_info(sbp
, mp
);
454 PUFFS_MSG_RELEASE(statvfs
);
459 pageflush(struct mount
*mp
, kauth_cred_t cred
, int waitfor
)
461 struct puffs_node
*pn
;
462 struct vnode
*vp
, *mvp
;
467 /* Allocate a marker vnode. */
468 if ((mvp
= vnalloc(mp
)) == NULL
)
472 * Sync all cached data from regular vnodes (which are not
473 * currently locked, see below). After this we call VFS_SYNC
474 * for the fs server, which should handle data and metadata for
475 * all the nodes it knows to exist.
477 mutex_enter(&mntvnode_lock
);
479 for (vp
= TAILQ_FIRST(&mp
->mnt_vnodelist
); vp
; vp
= vunmark(mvp
)) {
481 if (vp
->v_mount
!= mp
|| vismarker(vp
))
484 mutex_enter(&vp
->v_interlock
);
486 if (vp
->v_type
!= VREG
|| UVM_OBJ_IS_CLEAN(&vp
->v_uobj
)) {
487 mutex_exit(&vp
->v_interlock
);
491 mutex_exit(&mntvnode_lock
);
494 * Here we try to get a reference to the vnode and to
495 * lock it. This is mostly cargo-culted, but I will
496 * offer an explanation to why I believe this might
497 * actually do the right thing.
499 * If the vnode is a goner, we quite obviously don't need
502 * If the vnode was busy, we don't need to sync it because
503 * this is never called with MNT_WAIT except from
504 * dounmount(), when we are wait-flushing all the dirty
505 * vnodes through other routes in any case. So there,
506 * sync() doesn't actually sync. Happy now?
508 rv
= vget(vp
, LK_EXCLUSIVE
| LK_NOWAIT
| LK_INTERLOCK
);
510 mutex_enter(&mntvnode_lock
);
518 /* hmm.. is the FAF thing entirely sensible? */
519 if (waitfor
== MNT_LAZY
) {
520 mutex_enter(&vp
->v_interlock
);
521 pn
->pn_stat
|= PNODE_FAF
;
522 mutex_exit(&vp
->v_interlock
);
524 rv
= VOP_FSYNC(vp
, cred
, waitfor
, 0, 0);
525 if (waitfor
== MNT_LAZY
) {
526 mutex_enter(&vp
->v_interlock
);
527 pn
->pn_stat
&= ~PNODE_FAF
;
528 mutex_exit(&vp
->v_interlock
);
533 mutex_enter(&mntvnode_lock
);
535 mutex_exit(&mntvnode_lock
);
542 puffs_vfsop_sync(struct mount
*mp
, int waitfor
, struct kauth_cred
*cred
)
544 PUFFS_MSG_VARS(vfs
, sync
);
545 struct puffs_mount
*pmp
= MPTOPUFFSMP(mp
);
548 error
= pageflush(mp
, cred
, waitfor
);
551 PUFFS_MSG_ALLOC(vfs
, sync
);
552 sync_msg
->pvfsr_waitfor
= waitfor
;
553 puffs_credcvt(&sync_msg
->pvfsr_cred
, cred
);
554 puffs_msg_setinfo(park_sync
, PUFFSOP_VFS
, PUFFS_VFS_SYNC
, NULL
);
556 PUFFS_MSG_ENQUEUEWAIT(pmp
, park_sync
, rv
);
557 rv
= checkerr(pmp
, rv
, __func__
);
561 PUFFS_MSG_RELEASE(sync
);
566 puffs_vfsop_fhtovp(struct mount
*mp
, struct fid
*fhp
, struct vnode
**vpp
)
568 PUFFS_MSG_VARS(vfs
, fhtonode
);
569 struct puffs_mount
*pmp
= MPTOPUFFSMP(mp
);
572 size_t argsize
, fhlen
;
575 if (pmp
->pmp_args
.pa_fhsize
== 0)
578 if (pmp
->pmp_args
.pa_fhflags
& PUFFS_FHFLAG_PASSTHROUGH
) {
579 fhlen
= fhp
->fid_len
;
582 fhlen
= PUFFS_FROMFHSIZE(fhp
->fid_len
);
583 fhdata
= fhp
->fid_data
;
585 if (pmp
->pmp_args
.pa_fhflags
& PUFFS_FHFLAG_DYNAMIC
) {
586 if (pmp
->pmp_args
.pa_fhsize
< fhlen
)
589 if (pmp
->pmp_args
.pa_fhsize
!= fhlen
)
594 argsize
= sizeof(struct puffs_vfsmsg_fhtonode
) + fhlen
;
595 puffs_msgmem_alloc(argsize
, &park_fhtonode
, (void *)&fhtonode_msg
, 1);
596 fhtonode_msg
->pvfsr_dsize
= fhlen
;
597 memcpy(fhtonode_msg
->pvfsr_data
, fhdata
, fhlen
);
598 puffs_msg_setinfo(park_fhtonode
, PUFFSOP_VFS
, PUFFS_VFS_FHTOVP
, NULL
);
600 PUFFS_MSG_ENQUEUEWAIT(pmp
, park_fhtonode
, error
);
601 error
= checkerr(pmp
, error
, __func__
);
605 error
= puffs_cookie2vnode(pmp
, fhtonode_msg
->pvfsr_fhcookie
, 1,1,&vp
);
606 DPRINTF(("puffs_fhtovp: got cookie %p, existing vnode %p\n",
607 fhtonode_msg
->pvfsr_fhcookie
, vp
));
608 if (error
== PUFFS_NOSUCHCOOKIE
) {
609 error
= puffs_getvnode(mp
, fhtonode_msg
->pvfsr_fhcookie
,
610 fhtonode_msg
->pvfsr_vtype
, fhtonode_msg
->pvfsr_size
,
611 fhtonode_msg
->pvfsr_rdev
, &vp
);
614 vn_lock(vp
, LK_EXCLUSIVE
| LK_RETRY
);
621 puffs_msgmem_release(park_fhtonode
);
626 puffs_vfsop_vptofh(struct vnode
*vp
, struct fid
*fhp
, size_t *fh_size
)
628 PUFFS_MSG_VARS(vfs
, nodetofh
);
629 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
630 size_t argsize
, fhlen
;
633 if (pmp
->pmp_args
.pa_fhsize
== 0)
636 /* if file handles are static len, we can test len immediately */
637 if (((pmp
->pmp_args
.pa_fhflags
& PUFFS_FHFLAG_DYNAMIC
) == 0)
638 && ((pmp
->pmp_args
.pa_fhflags
& PUFFS_FHFLAG_PASSTHROUGH
) == 0)
639 && (PUFFS_FROMFHSIZE(*fh_size
) < pmp
->pmp_args
.pa_fhsize
)) {
640 *fh_size
= PUFFS_TOFHSIZE(pmp
->pmp_args
.pa_fhsize
);
644 if (pmp
->pmp_args
.pa_fhflags
& PUFFS_FHFLAG_PASSTHROUGH
)
647 fhlen
= PUFFS_FROMFHSIZE(*fh_size
);
649 argsize
= sizeof(struct puffs_vfsmsg_nodetofh
) + fhlen
;
650 puffs_msgmem_alloc(argsize
, &park_nodetofh
, (void *)&nodetofh_msg
, 1);
651 nodetofh_msg
->pvfsr_fhcookie
= VPTOPNC(vp
);
652 nodetofh_msg
->pvfsr_dsize
= fhlen
;
653 puffs_msg_setinfo(park_nodetofh
, PUFFSOP_VFS
, PUFFS_VFS_VPTOFH
, NULL
);
655 PUFFS_MSG_ENQUEUEWAIT(pmp
, park_nodetofh
, error
);
656 error
= checkerr(pmp
, error
, __func__
);
658 if (pmp
->pmp_args
.pa_fhflags
& PUFFS_FHFLAG_PASSTHROUGH
)
659 fhlen
= nodetofh_msg
->pvfsr_dsize
;
660 else if (pmp
->pmp_args
.pa_fhflags
& PUFFS_FHFLAG_DYNAMIC
)
661 fhlen
= PUFFS_TOFHSIZE(nodetofh_msg
->pvfsr_dsize
);
663 fhlen
= PUFFS_TOFHSIZE(pmp
->pmp_args
.pa_fhsize
);
671 if (fhlen
> FHANDLE_SIZE_MAX
) {
672 puffs_senderr(pmp
, PUFFS_ERR_VPTOFH
, E2BIG
,
673 "file handle too big", VPTOPNC(vp
));
678 if (*fh_size
< fhlen
) {
686 if (pmp
->pmp_args
.pa_fhflags
& PUFFS_FHFLAG_PASSTHROUGH
) {
687 memcpy(fhp
, nodetofh_msg
->pvfsr_data
, fhlen
);
689 fhp
->fid_len
= *fh_size
;
690 memcpy(fhp
->fid_data
, nodetofh_msg
->pvfsr_data
,
691 nodetofh_msg
->pvfsr_dsize
);
696 puffs_msgmem_release(park_nodetofh
);
701 puffs_vfsop_init(void)
704 /* some checks depend on this */
705 KASSERT(VNOVAL
== VSIZENOTSET
);
707 pool_init(&puffs_pnpool
, sizeof(struct puffs_node
), 0, 0, 0,
708 "puffpnpl", &pool_allocator_nointr
, IPL_NONE
);
713 puffs_vfsop_done(void)
716 puffs_msgif_destroy();
717 pool_destroy(&puffs_pnpool
);
721 puffs_vfsop_snapshot(struct mount
*mp
, struct vnode
*vp
, struct timespec
*ts
)
727 const struct vnodeopv_desc
* const puffs_vnodeopv_descs
[] = {
728 &puffs_vnodeop_opv_desc
,
729 &puffs_specop_opv_desc
,
730 &puffs_fifoop_opv_desc
,
731 &puffs_msgop_opv_desc
,
735 struct vfsops puffs_vfsops
= {
737 sizeof (struct puffs_kargs
),
738 puffs_vfsop_mount
, /* mount */
739 puffs_vfsop_start
, /* start */
740 puffs_vfsop_unmount
, /* unmount */
741 puffs_vfsop_root
, /* root */
742 (void *)eopnotsupp
, /* quotactl */
743 puffs_vfsop_statvfs
, /* statvfs */
744 puffs_vfsop_sync
, /* sync */
745 (void *)eopnotsupp
, /* vget */
746 puffs_vfsop_fhtovp
, /* fhtovp */
747 puffs_vfsop_vptofh
, /* vptofh */
748 puffs_vfsop_init
, /* init */
750 puffs_vfsop_done
, /* done */
751 NULL
, /* mountroot */
752 puffs_vfsop_snapshot
, /* snapshot */
753 vfs_stdextattrctl
, /* extattrctl */
754 (void *)eopnotsupp
, /* suspendctl */
755 genfs_renamelock_enter
,
756 genfs_renamelock_exit
,
758 puffs_vnodeopv_descs
, /* vnodeops */
764 puffs_modcmd(modcmd_t cmd
, void *arg
)
768 case MODULE_CMD_INIT
:
769 return vfs_attach(&puffs_vfsops
);
770 case MODULE_CMD_FINI
:
771 return vfs_detach(&puffs_vfsops
);