Print this page
2916 DTrace in a zone should be able to access fds[]
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libdtrace/common/io.d.in
+++ new/usr/src/lib/libdtrace/common/io.d.in
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 -#pragma ident "%Z%%M% %I% %E% SMI"
26 +/*
27 + * Copyright (c) 2012, Joyent, Inc. All rights reserved.
28 + */
27 29
28 30 #pragma D depends_on module unix
29 31 #pragma D depends_on provider io
30 32
31 33 inline int B_BUSY = @B_BUSY@;
32 34 #pragma D binding "1.0" B_BUSY
33 35 inline int B_DONE = @B_DONE@;
34 36 #pragma D binding "1.0" B_DONE
35 37 inline int B_ERROR = @B_ERROR@;
36 38 #pragma D binding "1.0" B_ERROR
37 39 inline int B_PAGEIO = @B_PAGEIO@;
38 40 #pragma D binding "1.0" B_PAGEIO
39 41 inline int B_PHYS = @B_PHYS@;
40 42 #pragma D binding "1.0" B_PHYS
41 43 inline int B_READ = @B_READ@;
42 44 #pragma D binding "1.0" B_READ
43 45 inline int B_WRITE = @B_WRITE@;
44 46 #pragma D binding "1.0" B_WRITE
45 47 inline int B_ASYNC = @B_ASYNC@;
46 48 #pragma D binding "1.0" B_ASYNC
47 49
48 50 typedef struct bufinfo {
49 51 int b_flags; /* buffer status */
50 52 size_t b_bcount; /* number of bytes */
51 53 caddr_t b_addr; /* buffer address */
52 54 uint64_t b_lblkno; /* block # on device */
53 55 uint64_t b_blkno; /* expanded block # on device */
54 56 size_t b_resid; /* # of bytes not transferred */
55 57 size_t b_bufsize; /* size of allocated buffer */
56 58 caddr_t b_iodone; /* I/O completion routine */
57 59 int b_error; /* expanded error field */
58 60 dev_t b_edev; /* extended device */
59 61 } bufinfo_t;
60 62
61 63 #pragma D binding "1.0" translator
62 64 translator bufinfo_t < struct buf *B > {
63 65 b_flags = B->b_flags;
64 66 b_addr = B->b_un.b_addr;
65 67 b_bcount = B->b_bcount;
66 68 b_lblkno = B->_b_blkno._f;
67 69 b_blkno = sizeof (long) == 8 ? B->_b_blkno._f : B->_b_blkno._p._l;
68 70 b_resid = B->b_resid;
69 71 b_bufsize = B->b_bufsize;
70 72 b_iodone = (caddr_t)B->b_iodone;
71 73 b_error = B->b_error;
72 74 b_edev = B->b_edev;
73 75 };
74 76
75 77 typedef struct devinfo {
76 78 int dev_major; /* major number */
77 79 int dev_minor; /* minor number */
78 80 int dev_instance; /* instance number */
79 81 string dev_name; /* name of device */
80 82 string dev_statname; /* name of device + instance/minor */
81 83 string dev_pathname; /* pathname of device */
82 84 } devinfo_t;
83 85
84 86 #pragma D binding "1.0" translator
85 87 translator devinfo_t < struct buf *B > {
86 88 dev_major = B->b_dip != NULL ? getmajor(B->b_edev) :
87 89 getmajor(B->b_file->v_vfsp->vfs_dev);
88 90 dev_minor = B->b_dip != NULL ? getminor(B->b_edev) :
89 91 getminor(B->b_file->v_vfsp->vfs_dev);
90 92 dev_instance = B->b_dip == NULL ?
91 93 getminor(B->b_file->v_vfsp->vfs_dev) :
92 94 ((struct dev_info *)B->b_dip)->devi_instance;
93 95 dev_name = B->b_dip == NULL ? "nfs" :
94 96 stringof(`devnamesp[getmajor(B->b_edev)].dn_name);
95 97 dev_statname = strjoin(B->b_dip == NULL ? "nfs" :
96 98 stringof(`devnamesp[getmajor(B->b_edev)].dn_name),
97 99 lltostr(B->b_dip == NULL ? getminor(B->b_file->v_vfsp->vfs_dev) :
98 100 ((struct dev_info *)B->b_dip)->devi_instance == 0 &&
99 101 ((struct dev_info *)B->b_dip)->devi_parent != NULL &&
100 102 ((struct dev_info *)B->b_dip)->devi_parent->devi_node_name ==
101 103 "pseudo" ? getminor(B->b_edev) :
102 104 ((struct dev_info *)B->b_dip)->devi_instance));
103 105 dev_pathname = B->b_dip == NULL ? "<nfs>" :
104 106 ddi_pathname(B->b_dip, getminor(B->b_edev));
105 107 };
106 108
107 109 typedef struct fileinfo {
108 110 string fi_name; /* name (basename of fi_pathname) */
109 111 string fi_dirname; /* directory (dirname of fi_pathname) */
110 112 string fi_pathname; /* full pathname */
111 113 offset_t fi_offset; /* offset within file */
112 114 string fi_fs; /* filesystem */
113 115 string fi_mount; /* mount point of file system */
114 116 int fi_oflags; /* open(2) flags for file descriptor */
115 117 } fileinfo_t;
116 118
117 119 #pragma D binding "1.0" translator
118 120 translator fileinfo_t < struct buf *B > {
119 121 fi_name = B->b_file == NULL ? "<none>" :
120 122 B->b_file->v_path == NULL ? "<unknown>" :
121 123 basename(cleanpath(B->b_file->v_path));
122 124 fi_dirname = B->b_file == NULL ? "<none>" :
123 125 B->b_file->v_path == NULL ? "<unknown>" :
124 126 dirname(cleanpath(B->b_file->v_path));
125 127 fi_pathname = B->b_file == NULL ? "<none>" :
126 128 B->b_file->v_path == NULL ? "<unknown>" :
127 129 cleanpath(B->b_file->v_path);
128 130 fi_offset = B->b_offset;
129 131 fi_fs = B->b_file == NULL ? "<none>" :
130 132 stringof(B->b_file->v_op->vnop_name);
131 133 fi_mount = B->b_file == NULL ? "<none>" :
132 134 B->b_file->v_vfsp->vfs_vnodecovered == NULL ? "/" :
133 135 B->b_file->v_vfsp->vfs_vnodecovered->v_path == NULL ? "<unknown>" :
134 136 cleanpath(B->b_file->v_vfsp->vfs_vnodecovered->v_path);
135 137 fi_oflags = 0;
136 138 };
137 139
138 140 /*
139 141 * The following inline constants can be used to examine fi_oflags when using
140 142 * the fds[] array or a translated fileinfo_t. Note that the various open
141 143 * flags behave as a bit-field *except* for O_RDONLY, O_WRONLY, and O_RDWR.
142 144 * To test the open mode, you write code similar to that used with the fcntl(2)
143 145 * F_GET[X]FL command, such as: if ((fi_oflags & O_ACCMODE) == O_WRONLY).
144 146 */
145 147 inline int O_ACCMODE = @O_ACCMODE@;
146 148 #pragma D binding "1.1" O_ACCMODE
147 149
148 150 inline int O_RDONLY = @O_RDONLY@;
149 151 #pragma D binding "1.1" O_RDONLY
150 152 inline int O_WRONLY = @O_WRONLY@;
151 153 #pragma D binding "1.1" O_WRONLY
152 154 inline int O_RDWR = @O_RDWR@;
153 155 #pragma D binding "1.1" O_RDWR
154 156
155 157 inline int O_APPEND = @O_APPEND@;
156 158 #pragma D binding "1.1" O_APPEND
157 159 inline int O_CREAT = @O_CREAT@;
158 160 #pragma D binding "1.1" O_CREAT
159 161 inline int O_DSYNC = @O_DSYNC@;
160 162 #pragma D binding "1.1" O_DSYNC
161 163 inline int O_EXCL = @O_EXCL@;
162 164 #pragma D binding "1.1" O_EXCL
163 165 inline int O_LARGEFILE = @O_LARGEFILE@;
164 166 #pragma D binding "1.1" O_LARGEFILE
165 167 inline int O_NOCTTY = @O_NOCTTY@;
166 168 #pragma D binding "1.1" O_NOCTTY
167 169 inline int O_NONBLOCK = @O_NONBLOCK@;
168 170 #pragma D binding "1.1" O_NONBLOCK
169 171 inline int O_NDELAY = @O_NDELAY@;
170 172 #pragma D binding "1.1" O_NDELAY
171 173 inline int O_RSYNC = @O_RSYNC@;
172 174 #pragma D binding "1.1" O_RSYNC
173 175 inline int O_SYNC = @O_SYNC@;
174 176 #pragma D binding "1.1" O_SYNC
175 177 inline int O_TRUNC = @O_TRUNC@;
176 178 #pragma D binding "1.1" O_TRUNC
177 179 inline int O_XATTR = @O_XATTR@;
178 180 #pragma D binding "1.1" O_XATTR
179 181
180 182 #pragma D binding "1.1" translator
181 183 translator fileinfo_t < struct file *F > {
182 184 fi_name = F == NULL ? "<none>" :
183 185 F->f_vnode->v_path == NULL ? "<unknown>" :
184 186 basename(cleanpath(F->f_vnode->v_path));
185 187 fi_dirname = F == NULL ? "<none>" :
186 188 F->f_vnode->v_path == NULL ? "<unknown>" :
187 189 dirname(cleanpath(F->f_vnode->v_path));
188 190 fi_pathname = F == NULL ? "<none>" :
189 191 F->f_vnode->v_path == NULL ? "<unknown>" :
↓ open down ↓ |
153 lines elided |
↑ open up ↑ |
190 192 cleanpath(F->f_vnode->v_path);
191 193 fi_offset = F == NULL ? 0 : F->f_offset;
192 194 fi_fs = F == NULL ? "<none>" : stringof(F->f_vnode->v_op->vnop_name);
193 195 fi_mount = F == NULL ? "<none>" :
194 196 F->f_vnode->v_vfsp->vfs_vnodecovered == NULL ? "/" :
195 197 F->f_vnode->v_vfsp->vfs_vnodecovered->v_path == NULL ? "<unknown>" :
196 198 cleanpath(F->f_vnode->v_vfsp->vfs_vnodecovered->v_path);
197 199 fi_oflags = F == NULL ? 0 : F->f_flag + (int)@FOPEN@;
198 200 };
199 201
200 -inline fileinfo_t fds[int fd] = xlate <fileinfo_t> (
201 - fd >= 0 && fd < curthread->t_procp->p_user.u_finfo.fi_nfiles ?
202 - curthread->t_procp->p_user.u_finfo.fi_list[fd].uf_file : NULL);
202 +inline fileinfo_t fds[int fd] = xlate <fileinfo_t> (getf(fd));
203 203
204 204 #pragma D attributes Stable/Stable/Common fds
205 205 #pragma D binding "1.1" fds
206 206
207 207 #pragma D binding "1.2" translator
208 208 translator fileinfo_t < struct vnode *V > {
209 209 fi_name = V->v_path == NULL ? "<unknown>" :
210 210 basename(cleanpath(V->v_path));
211 211 fi_dirname = V->v_path == NULL ? "<unknown>" :
212 212 dirname(cleanpath(V->v_path));
213 213 fi_pathname = V->v_path == NULL ? "<unknown>" : cleanpath(V->v_path);
214 214 fi_fs = stringof(V->v_op->vnop_name);
215 215 fi_mount = V->v_vfsp->vfs_vnodecovered == NULL ? "/" :
216 216 V->v_vfsp->vfs_vnodecovered->v_path == NULL ? "<unknown>" :
217 217 cleanpath(V->v_vfsp->vfs_vnodecovered->v_path);
218 218 };
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX