17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
534709573Sraf * Common Development and Distribution License (the "License").
634709573Sraf * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
2134709573Sraf
227c478bd9Sstevel@tonic-gate /*
2371184387SAmrita Sadhukhan * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
27*a5eb7107SBryan Cantrill /*
28*a5eb7107SBryan Cantrill * Copyright (c) 2014, Joyent, Inc. All rights reserved.
29*a5eb7107SBryan Cantrill */
30*a5eb7107SBryan Cantrill
317c478bd9Sstevel@tonic-gate #include <sys/types.h>
327c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
33aa59c4cbSrsb #include <sys/vfs_opreg.h>
347c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
357c478bd9Sstevel@tonic-gate #include <fs/fs_subr.h>
367c478bd9Sstevel@tonic-gate #include <sys/proc.h>
377c478bd9Sstevel@tonic-gate #include <sys/kstat.h>
387c478bd9Sstevel@tonic-gate #include <sys/port_impl.h>
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate /* local functions */
41da6c28aaSamw static int port_open(struct vnode **, int, cred_t *, caller_context_t *);
42da6c28aaSamw static int port_close(struct vnode *, int, int, offset_t, cred_t *,
43da6c28aaSamw caller_context_t *);
44da6c28aaSamw static int port_getattr(struct vnode *, struct vattr *, int, cred_t *,
45da6c28aaSamw caller_context_t *);
46da6c28aaSamw static int port_access(struct vnode *, int, int, cred_t *, caller_context_t *);
47da6c28aaSamw static int port_realvp(vnode_t *, vnode_t **, caller_context_t *);
48da6c28aaSamw static int port_poll(vnode_t *, short, int, short *, struct pollhead **,
49da6c28aaSamw caller_context_t *);
50da6c28aaSamw static void port_inactive(struct vnode *, cred_t *, caller_context_t *);
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate const fs_operation_def_t port_vnodeops_template[] = {
53aa59c4cbSrsb VOPNAME_OPEN, { .vop_open = port_open },
54aa59c4cbSrsb VOPNAME_CLOSE, { .vop_close = port_close },
55aa59c4cbSrsb VOPNAME_GETATTR, { .vop_getattr = port_getattr },
56aa59c4cbSrsb VOPNAME_ACCESS, { .vop_access = port_access },
57aa59c4cbSrsb VOPNAME_INACTIVE, { .vop_inactive = port_inactive },
58aa59c4cbSrsb VOPNAME_FRLOCK, { .error = fs_error },
59aa59c4cbSrsb VOPNAME_REALVP, { .vop_realvp = port_realvp },
60aa59c4cbSrsb VOPNAME_POLL, { .vop_poll = port_poll },
61aa59c4cbSrsb VOPNAME_PATHCONF, { .error = fs_error },
62aa59c4cbSrsb VOPNAME_DISPOSE, { .error = fs_error },
63aa59c4cbSrsb VOPNAME_GETSECATTR, { .error = fs_error },
64aa59c4cbSrsb VOPNAME_SHRLOCK, { .error = fs_error },
657c478bd9Sstevel@tonic-gate NULL, NULL
667c478bd9Sstevel@tonic-gate };
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate /* ARGSUSED */
697c478bd9Sstevel@tonic-gate static int
port_open(struct vnode ** vpp,int flag,cred_t * cr,caller_context_t * ct)70da6c28aaSamw port_open(struct vnode **vpp, int flag, cred_t *cr, caller_context_t *ct)
717c478bd9Sstevel@tonic-gate {
727c478bd9Sstevel@tonic-gate return (0);
737c478bd9Sstevel@tonic-gate }
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate /*
767c478bd9Sstevel@tonic-gate * port_discard_events() scans the port event queue for events owned
777c478bd9Sstevel@tonic-gate * by current proc. Non-shareable events will be discarded, all other
787c478bd9Sstevel@tonic-gate * events remain in the event queue.
797c478bd9Sstevel@tonic-gate */
807c478bd9Sstevel@tonic-gate void
port_discard_events(port_queue_t * portq)817c478bd9Sstevel@tonic-gate port_discard_events(port_queue_t *portq)
827c478bd9Sstevel@tonic-gate {
837c478bd9Sstevel@tonic-gate port_kevent_t *kevp;
847c478bd9Sstevel@tonic-gate pid_t pid = curproc->p_pid;
857c478bd9Sstevel@tonic-gate
867c478bd9Sstevel@tonic-gate /*
8734709573Sraf * The call to port_block() is required to avoid interaction
8834709573Sraf * with other threads in port_get(n).
897c478bd9Sstevel@tonic-gate */
907c478bd9Sstevel@tonic-gate mutex_enter(&portq->portq_mutex);
9134709573Sraf port_block(portq);
927c478bd9Sstevel@tonic-gate port_push_eventq(portq); /* empty temporary queue */
937c478bd9Sstevel@tonic-gate kevp = list_head(&portq->portq_list);
947c478bd9Sstevel@tonic-gate while (kevp) {
957c478bd9Sstevel@tonic-gate if (kevp->portkev_pid == pid) {
967c478bd9Sstevel@tonic-gate /* own event, check if it is shareable */
977c478bd9Sstevel@tonic-gate if (kevp->portkev_flags & PORT_KEV_NOSHARE)
987c478bd9Sstevel@tonic-gate kevp->portkev_flags |= PORT_KEV_FREE;
997c478bd9Sstevel@tonic-gate }
1007c478bd9Sstevel@tonic-gate kevp = list_next(&portq->portq_list, kevp);
1017c478bd9Sstevel@tonic-gate }
10234709573Sraf port_unblock(portq);
1037c478bd9Sstevel@tonic-gate mutex_exit(&portq->portq_mutex);
1047c478bd9Sstevel@tonic-gate }
1057c478bd9Sstevel@tonic-gate
1067c478bd9Sstevel@tonic-gate /*
1077c478bd9Sstevel@tonic-gate * Called from port_close().
1087c478bd9Sstevel@tonic-gate * Free all kernel events structures which are still in the event queue.
1097c478bd9Sstevel@tonic-gate */
1107c478bd9Sstevel@tonic-gate static void
port_close_events(port_queue_t * portq)1117c478bd9Sstevel@tonic-gate port_close_events(port_queue_t *portq)
1127c478bd9Sstevel@tonic-gate {
1137c478bd9Sstevel@tonic-gate port_kevent_t *pkevp;
1147c478bd9Sstevel@tonic-gate int events; /* ignore events */
1157c478bd9Sstevel@tonic-gate
1167c478bd9Sstevel@tonic-gate mutex_enter(&portq->portq_mutex);
1177c478bd9Sstevel@tonic-gate while (pkevp = list_head(&portq->portq_list)) {
1187c478bd9Sstevel@tonic-gate portq->portq_nent--;
1197c478bd9Sstevel@tonic-gate list_remove(&portq->portq_list, pkevp);
1207c478bd9Sstevel@tonic-gate if (pkevp->portkev_callback) {
1217c478bd9Sstevel@tonic-gate (void) (*pkevp->portkev_callback)(pkevp->portkev_arg,
1227c478bd9Sstevel@tonic-gate &events, pkevp->portkev_pid, PORT_CALLBACK_CLOSE,
1237c478bd9Sstevel@tonic-gate pkevp);
1247c478bd9Sstevel@tonic-gate }
1257c478bd9Sstevel@tonic-gate mutex_exit(&portq->portq_mutex);
1267c478bd9Sstevel@tonic-gate port_free_event_local(pkevp, 0);
1277c478bd9Sstevel@tonic-gate mutex_enter(&portq->portq_mutex);
1287c478bd9Sstevel@tonic-gate }
12911dc39ddSpraks
13011dc39ddSpraks /*
13111dc39ddSpraks * Wait for any thread in pollwakeup(), accessing this port to
13211dc39ddSpraks * finish.
13311dc39ddSpraks */
13411dc39ddSpraks while (portq->portq_flags & PORTQ_POLLWK_PEND) {
13511dc39ddSpraks cv_wait(&portq->portq_closecv, &portq->portq_mutex);
13611dc39ddSpraks }
1377c478bd9Sstevel@tonic-gate mutex_exit(&portq->portq_mutex);
1387c478bd9Sstevel@tonic-gate }
1397c478bd9Sstevel@tonic-gate
1407c478bd9Sstevel@tonic-gate /*
1417c478bd9Sstevel@tonic-gate * The port_close() function is called from standard close(2) when
1427c478bd9Sstevel@tonic-gate * the file descriptor is of type S_IFPORT/VPORT.
1437c478bd9Sstevel@tonic-gate * Port file descriptors behave like standard file descriptors. It means,
1447c478bd9Sstevel@tonic-gate * the port file/vnode is only destroyed on last close.
1457c478bd9Sstevel@tonic-gate * If the reference counter is > 1 then
1467c478bd9Sstevel@tonic-gate * - sources associated with the port will be notified about the close,
1477c478bd9Sstevel@tonic-gate * - objects associated with the port will be dissociated,
1487c478bd9Sstevel@tonic-gate * - pending and delivered events will be discarded.
1497c478bd9Sstevel@tonic-gate * On last close all references and caches will be removed. The vnode itself
1507c478bd9Sstevel@tonic-gate * will be destroyed with VOP_RELE().
1517c478bd9Sstevel@tonic-gate */
1527c478bd9Sstevel@tonic-gate /* ARGSUSED */
1537c478bd9Sstevel@tonic-gate static int
port_close(struct vnode * vp,int flag,int count,offset_t offset,cred_t * cr,caller_context_t * ct)154da6c28aaSamw port_close(struct vnode *vp, int flag, int count, offset_t offset, cred_t *cr,
155da6c28aaSamw caller_context_t *ct)
1567c478bd9Sstevel@tonic-gate {
1577c478bd9Sstevel@tonic-gate port_t *pp;
1587c478bd9Sstevel@tonic-gate port_queue_t *portq;
1597c478bd9Sstevel@tonic-gate port_source_t *ps;
1607c478bd9Sstevel@tonic-gate port_source_t *ps_next;
1617c478bd9Sstevel@tonic-gate int source;
1627c478bd9Sstevel@tonic-gate
1637c478bd9Sstevel@tonic-gate pp = VTOEP(vp);
1647c478bd9Sstevel@tonic-gate mutex_enter(&pp->port_mutex);
1657c478bd9Sstevel@tonic-gate if (pp->port_flags & PORT_CLOSED) {
1667c478bd9Sstevel@tonic-gate mutex_exit(&pp->port_mutex);
1677c478bd9Sstevel@tonic-gate return (0);
1687c478bd9Sstevel@tonic-gate }
1697c478bd9Sstevel@tonic-gate mutex_exit(&pp->port_mutex);
1707c478bd9Sstevel@tonic-gate
1717c478bd9Sstevel@tonic-gate portq = &pp->port_queue;
1727c478bd9Sstevel@tonic-gate if (count > 1) {
1737c478bd9Sstevel@tonic-gate /*
1747c478bd9Sstevel@tonic-gate * It is not the last close.
1757c478bd9Sstevel@tonic-gate * Remove/free all event resources owned by the current proc
1767c478bd9Sstevel@tonic-gate * First notify all with the port associated sources about the
1777c478bd9Sstevel@tonic-gate * close(2). The last argument of the close callback function
1787c478bd9Sstevel@tonic-gate * advises the source about the type of of the close.
1797c478bd9Sstevel@tonic-gate * If the port was set in alert mode by the curren process then
1807c478bd9Sstevel@tonic-gate * remove the alert mode.
1817c478bd9Sstevel@tonic-gate */
1827c478bd9Sstevel@tonic-gate
1837c478bd9Sstevel@tonic-gate /* check alert mode of the port */
1847c478bd9Sstevel@tonic-gate mutex_enter(&portq->portq_mutex);
1857c478bd9Sstevel@tonic-gate if ((portq->portq_flags & PORTQ_ALERT) &&
1867c478bd9Sstevel@tonic-gate (portq->portq_alert.portal_pid == curproc->p_pid))
1877c478bd9Sstevel@tonic-gate portq->portq_flags &= ~PORTQ_ALERT;
1887c478bd9Sstevel@tonic-gate mutex_exit(&portq->portq_mutex);
1897c478bd9Sstevel@tonic-gate
1907c478bd9Sstevel@tonic-gate /* notify all event sources about port_close() */
1917c478bd9Sstevel@tonic-gate mutex_enter(&portq->portq_source_mutex);
1927c478bd9Sstevel@tonic-gate for (source = 0; source < PORT_SCACHE_SIZE; source++) {
1937c478bd9Sstevel@tonic-gate ps = portq->portq_scache[PORT_SHASH(source)];
1947c478bd9Sstevel@tonic-gate for (; ps != NULL; ps = ps->portsrc_next) {
1957c478bd9Sstevel@tonic-gate if (ps->portsrc_close != NULL)
1967c478bd9Sstevel@tonic-gate (*ps->portsrc_close)
1977c478bd9Sstevel@tonic-gate (ps->portsrc_closearg, pp->port_fd,
1987c478bd9Sstevel@tonic-gate curproc->p_pid, 0);
1997c478bd9Sstevel@tonic-gate }
2007c478bd9Sstevel@tonic-gate }
2017c478bd9Sstevel@tonic-gate mutex_exit(&portq->portq_source_mutex);
2027c478bd9Sstevel@tonic-gate port_discard_events(&pp->port_queue);
2037c478bd9Sstevel@tonic-gate return (0);
2047c478bd9Sstevel@tonic-gate }
2057c478bd9Sstevel@tonic-gate
2067c478bd9Sstevel@tonic-gate /*
2077c478bd9Sstevel@tonic-gate * We are executing the last close of the port -> discard everything
2087c478bd9Sstevel@tonic-gate * Make sure that all threads/processes accessing this port leave
2097c478bd9Sstevel@tonic-gate * the kernel immediately.
2107c478bd9Sstevel@tonic-gate */
2117c478bd9Sstevel@tonic-gate
2127c478bd9Sstevel@tonic-gate mutex_enter(&portq->portq_mutex);
2137c478bd9Sstevel@tonic-gate portq->portq_flags |= PORTQ_CLOSE;
2147c478bd9Sstevel@tonic-gate while (portq->portq_thrcnt > 0) {
2157c478bd9Sstevel@tonic-gate if (portq->portq_thread != NULL)
2167c478bd9Sstevel@tonic-gate cv_signal(&portq->portq_thread->portget_cv);
2177c478bd9Sstevel@tonic-gate cv_wait(&portq->portq_closecv, &portq->portq_mutex);
2187c478bd9Sstevel@tonic-gate }
2197c478bd9Sstevel@tonic-gate mutex_exit(&portq->portq_mutex);
2207c478bd9Sstevel@tonic-gate
2217c478bd9Sstevel@tonic-gate /*
2227c478bd9Sstevel@tonic-gate * Send "last close" message to associated sources.
2237c478bd9Sstevel@tonic-gate * - new event allocation requests are being denied since uf_file entry
2247c478bd9Sstevel@tonic-gate * was set to NULL in closeandsetf().
2257c478bd9Sstevel@tonic-gate * - all still allocated event structures must be returned to the
2267c478bd9Sstevel@tonic-gate * port immediately:
2277c478bd9Sstevel@tonic-gate * - call port_free_event(*event) or
2287c478bd9Sstevel@tonic-gate * - call port_send_event(*event) to complete event operations
2297c478bd9Sstevel@tonic-gate * which need activities in a dedicated process environment.
2307c478bd9Sstevel@tonic-gate * The port_close() function waits until all allocated event structures
2317c478bd9Sstevel@tonic-gate * are delivered back to the port.
2327c478bd9Sstevel@tonic-gate */
2337c478bd9Sstevel@tonic-gate
2347c478bd9Sstevel@tonic-gate mutex_enter(&portq->portq_source_mutex);
2357c478bd9Sstevel@tonic-gate for (source = 0; source < PORT_SCACHE_SIZE; source++) {
2367c478bd9Sstevel@tonic-gate ps = portq->portq_scache[PORT_SHASH(source)];
2377c478bd9Sstevel@tonic-gate for (; ps != NULL; ps = ps_next) {
2387c478bd9Sstevel@tonic-gate ps_next = ps->portsrc_next;
2397c478bd9Sstevel@tonic-gate if (ps->portsrc_close != NULL)
2407c478bd9Sstevel@tonic-gate (*ps->portsrc_close)(ps->portsrc_closearg,
2417c478bd9Sstevel@tonic-gate pp->port_fd, curproc->p_pid, 1);
2427c478bd9Sstevel@tonic-gate kmem_free(ps, sizeof (port_source_t));
2437c478bd9Sstevel@tonic-gate }
2447c478bd9Sstevel@tonic-gate }
2457c478bd9Sstevel@tonic-gate kmem_free(portq->portq_scache,
2467c478bd9Sstevel@tonic-gate PORT_SCACHE_SIZE * sizeof (port_source_t *));
2477c478bd9Sstevel@tonic-gate portq->portq_scache = NULL;
2487c478bd9Sstevel@tonic-gate mutex_exit(&portq->portq_source_mutex);
2497c478bd9Sstevel@tonic-gate
2507c478bd9Sstevel@tonic-gate mutex_enter(&portq->portq_mutex);
2517c478bd9Sstevel@tonic-gate /* Wait for outstanding events */
2527c478bd9Sstevel@tonic-gate while (pp->port_curr > portq->portq_nent)
2537c478bd9Sstevel@tonic-gate cv_wait(&portq->portq_closecv, &portq->portq_mutex);
2547c478bd9Sstevel@tonic-gate mutex_exit(&portq->portq_mutex);
2557c478bd9Sstevel@tonic-gate
2567c478bd9Sstevel@tonic-gate /*
2577c478bd9Sstevel@tonic-gate * If PORT_SOURCE_FD objects were not associated with the port then
2587c478bd9Sstevel@tonic-gate * it is necessary to free the port_fdcache structure here.
2597c478bd9Sstevel@tonic-gate */
2607c478bd9Sstevel@tonic-gate
2617c478bd9Sstevel@tonic-gate if (portq->portq_pcp != NULL) {
2627c478bd9Sstevel@tonic-gate mutex_destroy(&portq->portq_pcp->pc_lock);
2637c478bd9Sstevel@tonic-gate kmem_free(portq->portq_pcp, sizeof (port_fdcache_t));
2647c478bd9Sstevel@tonic-gate portq->portq_pcp = NULL;
2657c478bd9Sstevel@tonic-gate }
2667c478bd9Sstevel@tonic-gate
2677c478bd9Sstevel@tonic-gate /*
2687c478bd9Sstevel@tonic-gate * Now all events are passed back to the port,
2697c478bd9Sstevel@tonic-gate * discard remaining events in the port queue
2707c478bd9Sstevel@tonic-gate */
2717c478bd9Sstevel@tonic-gate
2727c478bd9Sstevel@tonic-gate port_close_events(portq);
2737c478bd9Sstevel@tonic-gate return (0);
2747c478bd9Sstevel@tonic-gate }
2757c478bd9Sstevel@tonic-gate
2767c478bd9Sstevel@tonic-gate /*
2777c478bd9Sstevel@tonic-gate * The port_poll() function is the VOP_POLL() entry of event ports.
2787c478bd9Sstevel@tonic-gate * Event ports return:
2797c478bd9Sstevel@tonic-gate * POLLIN : events are available in the event queue
2807c478bd9Sstevel@tonic-gate * POLLOUT : event queue can still accept events
2817c478bd9Sstevel@tonic-gate */
2827c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2837c478bd9Sstevel@tonic-gate static int
port_poll(vnode_t * vp,short events,int anyyet,short * reventsp,struct pollhead ** phpp,caller_context_t * ct)2847c478bd9Sstevel@tonic-gate port_poll(vnode_t *vp, short events, int anyyet, short *reventsp,
285da6c28aaSamw struct pollhead **phpp, caller_context_t *ct)
2867c478bd9Sstevel@tonic-gate {
2877c478bd9Sstevel@tonic-gate port_t *pp;
2887c478bd9Sstevel@tonic-gate port_queue_t *portq;
2897c478bd9Sstevel@tonic-gate short levents;
2907c478bd9Sstevel@tonic-gate
2917c478bd9Sstevel@tonic-gate pp = VTOEP(vp);
2927c478bd9Sstevel@tonic-gate portq = &pp->port_queue;
2937c478bd9Sstevel@tonic-gate levents = 0;
2947c478bd9Sstevel@tonic-gate mutex_enter(&portq->portq_mutex);
2957c478bd9Sstevel@tonic-gate if (portq->portq_nent)
2967c478bd9Sstevel@tonic-gate levents = POLLIN;
2977c478bd9Sstevel@tonic-gate if (pp->port_curr < pp->port_max_events)
2987c478bd9Sstevel@tonic-gate levents |= POLLOUT;
2997c478bd9Sstevel@tonic-gate levents &= events;
3007c478bd9Sstevel@tonic-gate *reventsp = levents;
301*a5eb7107SBryan Cantrill if ((levents == 0 && !anyyet) || (events & POLLET)) {
3027c478bd9Sstevel@tonic-gate *phpp = &pp->port_pollhd;
303*a5eb7107SBryan Cantrill portq->portq_flags |= events & POLLIN ? PORTQ_POLLIN : 0;
304*a5eb7107SBryan Cantrill portq->portq_flags |= events & POLLOUT ? PORTQ_POLLOUT : 0;
3057c478bd9Sstevel@tonic-gate }
3067c478bd9Sstevel@tonic-gate mutex_exit(&portq->portq_mutex);
3077c478bd9Sstevel@tonic-gate return (0);
3087c478bd9Sstevel@tonic-gate }
3097c478bd9Sstevel@tonic-gate
3107c478bd9Sstevel@tonic-gate
3117c478bd9Sstevel@tonic-gate /* ARGSUSED */
3127c478bd9Sstevel@tonic-gate static int
port_getattr(struct vnode * vp,struct vattr * vap,int flags,cred_t * cr,caller_context_t * ct)313da6c28aaSamw port_getattr(struct vnode *vp, struct vattr *vap, int flags, cred_t *cr,
314da6c28aaSamw caller_context_t *ct)
3157c478bd9Sstevel@tonic-gate {
3167c478bd9Sstevel@tonic-gate port_t *pp;
3177c478bd9Sstevel@tonic-gate extern dev_t portdev;
3187c478bd9Sstevel@tonic-gate
3197c478bd9Sstevel@tonic-gate pp = VTOEP(vp);
3207c478bd9Sstevel@tonic-gate
3217c478bd9Sstevel@tonic-gate vap->va_type = vp->v_type; /* vnode type (for create) */
3227c478bd9Sstevel@tonic-gate vap->va_mode = 0; /* file access mode */
3237c478bd9Sstevel@tonic-gate vap->va_uid = pp->port_uid; /* owner user id */
3247c478bd9Sstevel@tonic-gate vap->va_gid = pp->port_gid; /* owner group id */
3257c478bd9Sstevel@tonic-gate vap->va_fsid = portdev; /* file system id */
3267c478bd9Sstevel@tonic-gate vap->va_nodeid = (ino64_t)0; /* node id */
3277c478bd9Sstevel@tonic-gate vap->va_nlink = vp->v_count; /* number of references to file */
3287c478bd9Sstevel@tonic-gate vap->va_size = (u_offset_t)pp->port_queue.portq_nent; /* file size */
3297c478bd9Sstevel@tonic-gate vap->va_atime = pp->port_ctime; /* time of last access */
3307c478bd9Sstevel@tonic-gate vap->va_mtime = pp->port_ctime; /* time of last modification */
3317c478bd9Sstevel@tonic-gate vap->va_ctime = pp->port_ctime; /* time file ``created'' */
3327c478bd9Sstevel@tonic-gate vap->va_rdev = portdev; /* device the file represents */
3337c478bd9Sstevel@tonic-gate vap->va_blksize = 0; /* fundamental block size */
3347c478bd9Sstevel@tonic-gate vap->va_nblocks = (fsblkcnt64_t)0; /* # of blocks allocated */
3357c478bd9Sstevel@tonic-gate vap->va_seq = 0; /* sequence number */
3367c478bd9Sstevel@tonic-gate
3377c478bd9Sstevel@tonic-gate return (0);
3387c478bd9Sstevel@tonic-gate }
3397c478bd9Sstevel@tonic-gate
3407c478bd9Sstevel@tonic-gate /*
3417c478bd9Sstevel@tonic-gate * Destroy the port.
3427c478bd9Sstevel@tonic-gate */
3437c478bd9Sstevel@tonic-gate /* ARGSUSED */
3447c478bd9Sstevel@tonic-gate static void
port_inactive(struct vnode * vp,cred_t * cr,caller_context_t * ct)345da6c28aaSamw port_inactive(struct vnode *vp, cred_t *cr, caller_context_t *ct)
3467c478bd9Sstevel@tonic-gate {
3477c478bd9Sstevel@tonic-gate port_t *pp = VTOEP(vp);
3487c478bd9Sstevel@tonic-gate extern port_kstat_t port_kstat;
3497c478bd9Sstevel@tonic-gate
3507c478bd9Sstevel@tonic-gate mutex_enter(&port_control.pc_mutex);
3517c478bd9Sstevel@tonic-gate port_control.pc_nents--;
3527c478bd9Sstevel@tonic-gate curproc->p_portcnt--;
3537c478bd9Sstevel@tonic-gate port_kstat.pks_ports.value.ui32--;
3547c478bd9Sstevel@tonic-gate mutex_exit(&port_control.pc_mutex);
3557c478bd9Sstevel@tonic-gate vn_free(vp);
3567c478bd9Sstevel@tonic-gate mutex_destroy(&pp->port_mutex);
3577c478bd9Sstevel@tonic-gate mutex_destroy(&pp->port_queue.portq_mutex);
3587c478bd9Sstevel@tonic-gate mutex_destroy(&pp->port_queue.portq_source_mutex);
3597c478bd9Sstevel@tonic-gate kmem_free(pp, sizeof (port_t));
3607c478bd9Sstevel@tonic-gate }
3617c478bd9Sstevel@tonic-gate
3627c478bd9Sstevel@tonic-gate /* ARGSUSED */
3637c478bd9Sstevel@tonic-gate static int
port_access(struct vnode * vp,int mode,int flags,cred_t * cr,caller_context_t * ct)364da6c28aaSamw port_access(struct vnode *vp, int mode, int flags, cred_t *cr,
365da6c28aaSamw caller_context_t *ct)
3667c478bd9Sstevel@tonic-gate {
3677c478bd9Sstevel@tonic-gate return (0);
3687c478bd9Sstevel@tonic-gate }
3697c478bd9Sstevel@tonic-gate
3707c478bd9Sstevel@tonic-gate /* ARGSUSED */
3717c478bd9Sstevel@tonic-gate static int
port_realvp(vnode_t * vp,vnode_t ** vpp,caller_context_t * ct)372da6c28aaSamw port_realvp(vnode_t *vp, vnode_t **vpp, caller_context_t *ct)
3737c478bd9Sstevel@tonic-gate {
3747c478bd9Sstevel@tonic-gate *vpp = vp;
3757c478bd9Sstevel@tonic-gate return (0);
3767c478bd9Sstevel@tonic-gate }
377