4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
28
29 #include <sys/types.h>
30 #include <sys/sysmacros.h>
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/errno.h>
34 #include <sys/signal.h>
35 #include <sys/cred.h>
36 #include <sys/user.h>
37 #include <sys/conf.h>
38 #include <sys/vfs.h>
39 #include <sys/vnode.h>
40 #include <sys/pathname.h>
41 #include <sys/file.h>
42 #include <sys/proc.h>
43 #include <sys/var.h>
44 #include <sys/cpuvar.h>
45 #include <sys/open.h>
46 #include <sys/cmn_err.h>
47 #include <sys/priocntl.h>
48 #include <sys/procset.h>
49 #include <sys/prsystm.h>
50 #include <sys/debug.h>
51 #include <sys/kmem.h>
52 #include <sys/atomic.h>
53 #include <sys/fcntl.h>
54 #include <sys/poll.h>
55 #include <sys/rctl.h>
56 #include <sys/port_impl.h>
57
58 #include <c2/audit.h>
59 #include <sys/nbmlock.h>
60
61 #ifdef DEBUG
62
63 static uint32_t afd_maxfd; /* # of entries in maximum allocated array */
64 static uint32_t afd_alloc; /* count of kmem_alloc()s */
65 static uint32_t afd_free; /* count of kmem_free()s */
66 static uint32_t afd_wait; /* count of waits on non-zero ref count */
67 #define MAXFD(x) (afd_maxfd = ((afd_maxfd >= (x))? afd_maxfd : (x)))
68 #define COUNT(x) atomic_add_32(&x, 1)
69
70 #else /* DEBUG */
71
72 #define MAXFD(x)
73 #define COUNT(x)
74
75 #endif /* DEBUG */
76
935
936 mutex_enter(&fp->f_tlock);
937
938 ASSERT(fp->f_count > 0);
939
940 count = fp->f_count--;
941 flag = fp->f_flag;
942 offset = fp->f_offset;
943
944 vp = fp->f_vnode;
945
946 error = VOP_CLOSE(vp, flag, count, offset, fp->f_cred, NULL);
947
948 if (count > 1) {
949 mutex_exit(&fp->f_tlock);
950 return (error);
951 }
952 ASSERT(fp->f_count == 0);
953 mutex_exit(&fp->f_tlock);
954
955 VN_RELE(vp);
956 /*
957 * deallocate resources to audit_data
958 */
959 if (audit_active)
960 audit_unfalloc(fp);
961 crfree(fp->f_cred);
962 kmem_cache_free(file_cache, fp);
963 return (error);
964 }
965
966 /*
967 * This is a combination of ufalloc() and setf().
968 */
969 int
970 ufalloc_file(int start, file_t *fp)
971 {
972 proc_t *p = curproc;
973 uf_info_t *fip = P_FINFO(p);
974 int filelimit;
|
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2012, Joyent Inc. All rights reserved.
25 */
26
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
29
30 #include <sys/types.h>
31 #include <sys/sysmacros.h>
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/errno.h>
35 #include <sys/signal.h>
36 #include <sys/cred.h>
37 #include <sys/user.h>
38 #include <sys/conf.h>
39 #include <sys/vfs.h>
40 #include <sys/vnode.h>
41 #include <sys/pathname.h>
42 #include <sys/file.h>
43 #include <sys/proc.h>
44 #include <sys/var.h>
45 #include <sys/cpuvar.h>
46 #include <sys/open.h>
47 #include <sys/cmn_err.h>
48 #include <sys/priocntl.h>
49 #include <sys/procset.h>
50 #include <sys/prsystm.h>
51 #include <sys/debug.h>
52 #include <sys/kmem.h>
53 #include <sys/atomic.h>
54 #include <sys/fcntl.h>
55 #include <sys/poll.h>
56 #include <sys/rctl.h>
57 #include <sys/port_impl.h>
58 #include <sys/dtrace.h>
59
60 #include <c2/audit.h>
61 #include <sys/nbmlock.h>
62
63 #ifdef DEBUG
64
65 static uint32_t afd_maxfd; /* # of entries in maximum allocated array */
66 static uint32_t afd_alloc; /* count of kmem_alloc()s */
67 static uint32_t afd_free; /* count of kmem_free()s */
68 static uint32_t afd_wait; /* count of waits on non-zero ref count */
69 #define MAXFD(x) (afd_maxfd = ((afd_maxfd >= (x))? afd_maxfd : (x)))
70 #define COUNT(x) atomic_add_32(&x, 1)
71
72 #else /* DEBUG */
73
74 #define MAXFD(x)
75 #define COUNT(x)
76
77 #endif /* DEBUG */
78
937
938 mutex_enter(&fp->f_tlock);
939
940 ASSERT(fp->f_count > 0);
941
942 count = fp->f_count--;
943 flag = fp->f_flag;
944 offset = fp->f_offset;
945
946 vp = fp->f_vnode;
947
948 error = VOP_CLOSE(vp, flag, count, offset, fp->f_cred, NULL);
949
950 if (count > 1) {
951 mutex_exit(&fp->f_tlock);
952 return (error);
953 }
954 ASSERT(fp->f_count == 0);
955 mutex_exit(&fp->f_tlock);
956
957 /*
958 * If DTrace has getf() subroutines active, it will set dtrace_closef
959 * to point to code that implements a barrier with respect to probe
960 * context. This must be called before the file_t is freed (and the
961 * vnode that it refers to is released) -- but it must be after the
962 * file_t has been removed from the uf_entry_t. That is, there must
963 * be no way for a racing getf() in probe context to yield the fp that
964 * we're operating upon.
965 */
966 if (dtrace_closef != NULL)
967 (*dtrace_closef)();
968
969 VN_RELE(vp);
970 /*
971 * deallocate resources to audit_data
972 */
973 if (audit_active)
974 audit_unfalloc(fp);
975 crfree(fp->f_cred);
976 kmem_cache_free(file_cache, fp);
977 return (error);
978 }
979
980 /*
981 * This is a combination of ufalloc() and setf().
982 */
983 int
984 ufalloc_file(int start, file_t *fp)
985 {
986 proc_t *p = curproc;
987 uf_info_t *fip = P_FINFO(p);
988 int filelimit;
|