2 .\" Copyright (c) 2009 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 BIOCLONE 9F "Jan 16, 2006"
8 bioclone \- clone another buffer
13 #include <sys/sunddi.h>
15 \fBstruct buf *\fR\fBbioclone\fR(\fBstruct buf\fR \fI*bp\fR, \fBoff_t\fR \fIoff\fR, \fBsize_t\fR \fIlen\fR, \fBdev_t\fR \fIdev\fR,
16 \fBdaddr_t\fR \fIblkno\fR, \fBint (\fR\fI*iodone\fR) (struct buf \fI*\fR), \fBstruct buf\fR \fI*bp_mem\fR,
17 \fBint\fR \fIsleepflag\fR);
23 Solaris DDI specific (Solaris DDI).
31 Pointer to the \fBbuf\fR(9S) structure describing the original \fBI/O\fR
41 Offset within original \fBI/O\fR request where new \fBI/O\fR request should
51 Length of the \fBI/O \fRrequest.
69 Block number on device.
78 Specific \fBbiodone\fR(9F) routine.
87 Pointer to a buffer structure to be filled in or \fBNULL. \fR
96 Determines whether caller can sleep for memory. Possible flags are
97 \fBKM_SLEEP\fR to allow sleeping until memory is available, or \fBKM_NOSLEEP\fR
98 to return \fINULL\fR immediately if memory is not available.
104 The \fBbioclone()\fR function returns an initialized buffer to perform
105 \fBI/O\fR to a portion of another buffer. The new buffer will be set up to
106 perform \fBI/O\fR to the range within the original \fBI/O\fR request specified
107 by the parameters \fIoff\fR and \fIlen\fR. An offset \fB0\fR starts the new
108 \fBI/O\fR request at the same address as the original request. \fIoff\fR +
109 \fIlen\fR must not exceed \fIb_bcount,\fR the length of the original request.
110 The device number \fIdev\fR specifies the device to which the buffer is to
111 perform \fBI/O\fR. \fIblkno\fR is the block number on device. It will be
112 assigned to the \fIb_blkno\fR field of the cloned buffer structure.
113 \fIiodone\fR lets the driver identify a specific \fBbiodone\fR(9F) routine to
114 be called by the driver when the \fBI/O\fR is complete. \fIbp_mem\fR determines
115 from where the space for the buffer should be allocated. If \fIbp_mem\fR is
116 \fBNULL\fR, \fBbioclone()\fR will allocate a new buffer using
117 \fBgetrbuf\fR(9F). If \fIsleepflag\fR is set to \fBKM_SLEEP\fR, the driver may
118 sleep until space is freed up. If \fIsleepflag\fR is set to \fBKM_NOSLEEP\fR,
119 the driver will not sleep. In either case, a pointer to the allocated space is
120 returned or \fINULL\fR to indicate that no space was available. After the
121 transfer is completed, the buffer has to be freed using \fBfreerbuf\fR(9F). If
122 \fIbp_mem\fR is not \fINULL\fR, it will be used as the space for the buffer
123 structure. The driver has to ensure that \fIbp_mem\fR is initialized properly
124 either using \fBgetrbuf\fR(9F) or \fBbioinit\fR(9F).
127 If the original buffer is mapped into the kernel virtual address space using
128 \fBbp_mapin\fR(9F) before calling \fBbioclone()\fR, a clone buffer will share
129 the kernel mapping of the original buffer. An additional \fBbp_mapin()\fR to
130 get a kernel mapping for the clone buffer is not necessary.
133 The driver has to ensure that the original buffer is not freed while any of the
134 clone buffers is still performing \fBI/O\fR. The \fBbiodone()\fR function has
135 to be called on all clone buffers \fBbefore\fR it is called on the original
140 The \fBbioclone()\fR function returns a pointer to the initialized buffer
141 header, or \fBNULL\fR if no space is available.
145 The \fBbioclone()\fR function can be called from user, interrup, or interrupt
146 context. Drivers must not allow \fBbioclone()\fR to sleep if called from an
150 \fBExample 1 \fRUsing \fBbioclone()\fR for Disk Striping
153 A device driver can use \fBbioclone()\fR for disk striping. For each disk in
154 the stripe, a clone buffer is created which performs \fBI/O\fR to a portion of
161 stripe_strategy(struct buf *bp)
165 bp_1 = bioclone(bp_orig, 0, size_1, dev_1, blkno_1,
166 stripe_done, NULL, KM_SLEEP);
169 bp_n = bioclone(bp_orig, offset_n, size_n, dev_n,
170 blkno_n, stripe_done, NULL, KM_SLEEP);
172 /* submit bp_1 ... bp_n to device */
182 * get bp of completed subrequest. biodone(9F) will
190 stripe_done(struct buf *bp)
207 \fBbiodone\fR(9F), \fBbp_mapin\fR(9F), \fBfreerbuf\fR(9F), \fBgetrbuf\fR(9F),
211 \fIWriting Device Drivers\fR