1502 Remove conversion cruft from manpages
[unleashed.git] / usr / src / man / man9e / ks_snapshot.9e
blobf096a675574a3a9383842b77836278cae1874dad
1 '\" te
2 .\"  Copyright (c) 2002, Sun Microsystems, Inc. All Rights Reserved
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH KS_SNAPSHOT 9E "Dec 4, 2002"
7 .SH NAME
8 ks_snapshot \- take a snapshot of kstat data
9 .SH SYNOPSIS
10 .LP
11 .nf
12 #include <sys/types.h>
13 #include <sys/kstat.h>
14 #include <sys/ddi.h>
15 #include <sys/sunddi.h>
19 \fBint prefix\fR\fB_ks_snapshot\fR(\fBkstat_t *\fR\fIksp\fR, \fBvoid *\fR\fIbuf\fR, \fBint\fR \fIrw\fR);
20 .fi
22 .SH INTERFACE LEVEL
23 .sp
24 .LP
25 Solaris DDI specific (Solaris DDI).
26 .SH PARAMETERS
27 .sp
28 .ne 2
29 .na
30 \fB\fIksp\fR \fR
31 .ad
32 .RS 8n
33 Pointer to a \fBkstat\fR(9S) structure.
34 .RE
36 .sp
37 .ne 2
38 .na
39 \fB\fIbuf\fR \fR
40 .ad
41 .RS 8n
42 Pointer to a buffer to copy the snapshot into.
43 .RE
45 .sp
46 .ne 2
47 .na
48 \fB\fIrw\fR \fR
49 .ad
50 .RS 8n
51 Read/Write flag. Possible values are:
52 .sp
53 .ne 2
54 .na
55 \fB\fBKSTAT_READ\fR\fR
56 .ad
57 .RS 15n
58 Copy driver statistics from the driver to the buffer.
59 .RE
61 .sp
62 .ne 2
63 .na
64 \fB\fBKSTAT_WRITE\fR\fR
65 .ad
66 .RS 15n
67 Copy statistics from the buffer to the driver.
68 .RE
70 .RE
72 .SH DESCRIPTION
73 .sp
74 .LP
75 The \fBkstat\fR mechanism allows for an optional \fBks_snapshot()\fR function
76 to copy \fBkstat\fR data. This is the routine that is called to marshall the
77 \fBkstat\fR data to be copied to user-land. A driver can opt to use a custom
78 snapshot routine rather than the default snapshot routine; to take advantage of
79 this feature, set the \fBks_snapshot\fR field before calling
80 \fBkstat_install\fR(9F).
81 .sp
82 .LP
83 The \fBks_snapshot()\fR function must have the following structure:
84 .sp
85 .in +2
86 .nf
87 static int
88 xx_kstat_snapshot(kstat_t *ksp, void *buf, int rw)
90      if (rw == KSTAT_WRITE) {
91 /* set the native stats to the values in buf */
92 /* return EACCES if you don't support this */
93      } else {
94 /* copy the kstat-specific data into buf */
95      }
96      return (0);
98 .fi
99 .in -2
104 In general, the \fBks_snapshot()\fR routine might need to refer to
105 provider-private data; for example, it might need a pointer to the provider's
106 raw statistics. The \fBks_private\fR field is available for this purpose. Its
107 use is entirely at the provider's discretion.
110 No \fBkstat\fR locking should be done inside the \fBks_update()\fR routine. The
111 caller will already be holding the \fBkstat\fR's \fBks_lock\fR (to ensure
112 consistent data) and will prevent the \fBkstat\fR from being removed.
113 .RS +4
116 \fBks_snaptime\fR must be set (via \fBgethrtime\fR(9F)) to timestamp the
117 data.
119 .RS +4
122 Data gets copied from the \fBkstat\fR to the buffer on \fBKSTAT_READ\fR, and
123 from the buffer to the \fBkstat\fR on \fBKSTAT_WRITE\fR.
125 .SH RETURN VALUES
127 .ne 2
129 \fB\fB0\fR\fR
131 .RS 10n
132 Success
136 .ne 2
138 \fB\fBEACCES\fR\fR
140 .RS 10n
141 If \fBKSTAT_WRITE\fR is not allowed
145 .ne 2
147 \fB\fBEIO\fR\fR
149 .RS 10n
150 For any other error
153 .SH CONTEXT
156 This function is called from user context only.
157 .SH EXAMPLES
159 \fBExample 1 \fRNamed \fBkstat\fRs with Long Strings (\fBKSTAT_DATA_STRING\fR)
161 .in +2
163 static int
164 xxx_kstat_snapshot(kstat_t *ksp, void *buf, int rw)
166     if (rw == KSTAT_WRITE) {
167          return (EACCES);
168     } else {
169          kstat_named_t *knp = buf;
170          char *end = knp + ksp->ks_ndata;
171          uint_t i;
173          bcopy(ksp->ks_data, buf,
174                  sizeof (kstat_named_t) * ksp->ks_ndata);
176  * Now copy the strings to the end of the buffer, and
177  * update the pointers appropriately.
178  */
179          for (i = 0; i < ksp->ks_ndata; i++, knp++)
180                  if (knp->data_type == KSTAT_DATA_STRING &&
181                      KSTAT_NAMED_STR_PTR(knp) != NULL) {
182                          bcopy(KSTAT_NAMED_STR_PTR(knp), end,
183                                  KSTAT_NAMED_STR_BUFLEN(knp));
184                          KSTAT_NAMED_STR_PTR(knp) = end;
185                          end += KSTAT_NAMED_STR_BUFLEN(knp);
186                  }
187     }
188     return (0);
191 .in -2
194 .SH SEE ALSO
197 \fBks_update\fR(9E), \fBkstat_create\fR(9F), \fBkstat_install\fR(9F),
198 \fBkstat\fR(9S)
201 \fIWriting Device Drivers\fR