Deleted Added
full compact
geom_slice.c (107116) geom_slice.c (107522)
1/*-
2 * Copyright (c) 2002 Poul-Henning Kamp
3 * Copyright (c) 2002 Networks Associates Technology, Inc.
4 * All rights reserved.
5 *
6 * This software was developed for the FreeBSD Project by Poul-Henning Kamp
7 * and NAI Labs, the Security Research Division of Network Associates, Inc.
8 * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the

--- 18 unchanged lines hidden (view full) ---

27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
1/*-
2 * Copyright (c) 2002 Poul-Henning Kamp
3 * Copyright (c) 2002 Networks Associates Technology, Inc.
4 * All rights reserved.
5 *
6 * This software was developed for the FreeBSD Project by Poul-Henning Kamp
7 * and NAI Labs, the Security Research Division of Network Associates, Inc.
8 * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the

--- 18 unchanged lines hidden (view full) ---

27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * $FreeBSD: head/sys/geom/geom_slice.c 107116 2002-11-20 20:12:52Z phk $
35 * $FreeBSD: head/sys/geom/geom_slice.c 107522 2002-12-02 19:59:25Z phk $
36 */
37
38
39#include <sys/param.h>
40#include <sys/stdint.h>
41#ifndef _KERNEL
42#include <stdio.h>
43#include <unistd.h>

--- 72 unchanged lines hidden (view full) ---

116 de++;
117 /* ... and let go of it on last close */
118 if ((cp->acr + dr) == 0 && (cp->acw + dw) == 0 && (cp->ace + de) == 1)
119 de--;
120 error = g_access_rel(cp, dr, dw, de);
121 return (error);
122}
123
36 */
37
38
39#include <sys/param.h>
40#include <sys/stdint.h>
41#ifndef _KERNEL
42#include <stdio.h>
43#include <unistd.h>

--- 72 unchanged lines hidden (view full) ---

116 de++;
117 /* ... and let go of it on last close */
118 if ((cp->acr + dr) == 0 && (cp->acw + dw) == 0 && (cp->ace + de) == 1)
119 de--;
120 error = g_access_rel(cp, dr, dw, de);
121 return (error);
122}
123
124void
125g_slice_finish_hot(struct bio *bp)
126{
127 struct bio *bp2;
128 struct g_geom *gp;
129 struct g_consumer *cp;
130 struct g_slicer *gsp;
131 struct g_slice *gsl;
132 int index;
133
134 KASSERT(bp->bio_to != NULL, ("NULL bio_to in g_slice_finish_hot(%p)", bp));
135 KASSERT(bp->bio_from != NULL, ("NULL bio_from in g_slice_finish_hot(%p)", bp));
136 gp = bp->bio_to->geom;
137 gsp = gp->softc;
138 cp = LIST_FIRST(&gp->consumer);
139 KASSERT(cp != NULL, ("NULL consumer in g_slice_finish_hot(%p)", bp));
140 index = bp->bio_to->index;
141 gsl = &gsp->slices[index];
142
143 bp2 = g_clone_bio(bp);
144 if (bp2 == NULL) {
145 g_io_deliver(bp, ENOMEM);
146 return;
147 }
148 if (bp2->bio_offset + bp2->bio_length > gsl->length)
149 bp2->bio_length = gsl->length - bp2->bio_offset;
150 bp2->bio_done = g_std_done;
151 bp2->bio_offset += gsl->offset;
152 g_io_request(bp2, cp);
153 return;
154}
155
124static void
125g_slice_start(struct bio *bp)
126{
127 struct bio *bp2;
128 struct g_provider *pp;
129 struct g_geom *gp;
130 struct g_consumer *cp;
131 struct g_slicer *gsp;
156static void
157g_slice_start(struct bio *bp)
158{
159 struct bio *bp2;
160 struct g_provider *pp;
161 struct g_geom *gp;
162 struct g_consumer *cp;
163 struct g_slicer *gsp;
132 struct g_slice *gsl;
133 int index;
164 struct g_slice *gsl, *gmp;
165 int index, error;
166 u_int m_index;
134 off_t t;
135
136 pp = bp->bio_to;
137 gp = pp->geom;
138 gsp = gp->softc;
139 cp = LIST_FIRST(&gp->consumer);
140 index = pp->index;
141 gsl = &gsp->slices[index];
142 switch(bp->bio_cmd) {
143 case BIO_READ:
144 case BIO_WRITE:
145 case BIO_DELETE:
146 if (bp->bio_offset > gsl->length) {
147 g_io_deliver(bp, EINVAL); /* XXX: EWHAT ? */
148 return;
149 }
167 off_t t;
168
169 pp = bp->bio_to;
170 gp = pp->geom;
171 gsp = gp->softc;
172 cp = LIST_FIRST(&gp->consumer);
173 index = pp->index;
174 gsl = &gsp->slices[index];
175 switch(bp->bio_cmd) {
176 case BIO_READ:
177 case BIO_WRITE:
178 case BIO_DELETE:
179 if (bp->bio_offset > gsl->length) {
180 g_io_deliver(bp, EINVAL); /* XXX: EWHAT ? */
181 return;
182 }
183 /*
184 * Check if we collide with any hot spaces, and call the
185 * method once if so.
186 */
187 for (m_index = 0; m_index < gsp->nhot; m_index++) {
188 gmp = &gsp->hot[m_index];
189 if (bp->bio_offset >= gmp->offset + gmp->length)
190 continue;
191 if (bp->bio_offset + bp->bio_length <= gmp->offset)
192 continue;
193 error = gsp->start(bp);
194 if (error == EJUSTRETURN)
195 return;
196 else if (error) {
197 g_io_deliver(bp, error);
198 return;
199 }
200 break;
201 }
150 bp2 = g_clone_bio(bp);
151 if (bp2 == NULL) {
152 g_io_deliver(bp, ENOMEM);
153 return;
154 }
155 if (bp2->bio_offset + bp2->bio_length > gsl->length)
156 bp2->bio_length = gsl->length - bp2->bio_offset;
157 bp2->bio_done = g_std_done;

--- 67 unchanged lines hidden (view full) ---

225 sbuf_printf(sb, "%s<offset>%ju</offset>\n", indent,
226 (uintmax_t)gsp->slices[pp->index].offset);
227 sbuf_printf(sb, "%s<secoffset>%ju</secoffset>\n", indent,
228 (uintmax_t)gsp->slices[pp->index].offset / 512);
229 }
230}
231
232int
202 bp2 = g_clone_bio(bp);
203 if (bp2 == NULL) {
204 g_io_deliver(bp, ENOMEM);
205 return;
206 }
207 if (bp2->bio_offset + bp2->bio_length > gsl->length)
208 bp2->bio_length = gsl->length - bp2->bio_offset;
209 bp2->bio_done = g_std_done;

--- 67 unchanged lines hidden (view full) ---

277 sbuf_printf(sb, "%s<offset>%ju</offset>\n", indent,
278 (uintmax_t)gsp->slices[pp->index].offset);
279 sbuf_printf(sb, "%s<secoffset>%ju</secoffset>\n", indent,
280 (uintmax_t)gsp->slices[pp->index].offset / 512);
281 }
282}
283
284int
233g_slice_config(struct g_geom *gp, int index, int how, off_t offset, off_t length, u_int sectorsize, char *fmt, ...)
285g_slice_config(struct g_geom *gp, u_int index, int how, off_t offset, off_t length, u_int sectorsize, char *fmt, ...)
234{
235 struct g_provider *pp;
236 struct g_slicer *gsp;
237 struct g_slice *gsl;
238 va_list ap;
239 struct sbuf *sb;
240 int error, acc;
241

--- 54 unchanged lines hidden (view full) ---

296 pp->sectorsize = gsl->sectorsize;
297 gsl->provider = pp;
298 gsp->nprovider++;
299 g_error_provider(pp, 0);
300 sbuf_delete(sb);
301 return(0);
302}
303
286{
287 struct g_provider *pp;
288 struct g_slicer *gsp;
289 struct g_slice *gsl;
290 va_list ap;
291 struct sbuf *sb;
292 int error, acc;
293

--- 54 unchanged lines hidden (view full) ---

348 pp->sectorsize = gsl->sectorsize;
349 gsl->provider = pp;
350 gsp->nprovider++;
351 g_error_provider(pp, 0);
352 sbuf_delete(sb);
353 return(0);
354}
355
356int
357g_slice_conf_hot(struct g_geom *gp, u_int index, off_t offset, off_t length)
358{
359 struct g_slicer *gsp;
360 struct g_slice *gsl, *gsl2;
361
362 g_trace(G_T_TOPOLOGY, "g_slice_conf_hot()");
363 g_topology_assert();
364 gsp = gp->softc;
365 gsl = gsp->hot;
366 if(index >= gsp->nhot) {
367 gsl2 = g_malloc((index + 1) * sizeof *gsl2, M_WAITOK | M_ZERO);
368 if (gsp->hot != NULL)
369 bcopy(gsp->hot, gsl2, gsp->nhot * sizeof *gsl2);
370 gsp->hot = gsl2;
371 if (gsp->hot != NULL)
372 g_free(gsl);
373 gsl = gsl2;
374 gsp->nhot = index + 1;
375 }
376 if (bootverbose)
377 printf("GEOM: Add %s hot[%d] start %jd length %jd end %jd\n",
378 gp->name, index, (intmax_t)offset, (intmax_t)length,
379 (intmax_t)(offset + length - 1));
380 gsl[index].offset = offset;
381 gsl[index].length = length;
382 return (0);
383}
384
304struct g_provider *
305g_slice_addslice(struct g_geom *gp, int index, off_t offset, off_t length, u_int sectorsize, char *fmt, ...)
306{
307 struct g_provider *pp;
308 struct g_slicer *gsp;
309 va_list ap;
310 struct sbuf *sb;
311

--- 17 unchanged lines hidden (view full) ---

329 if (bootverbose)
330 printf("GEOM: Add %s, start %jd length %jd end %jd\n",
331 pp->name, (intmax_t)offset, (intmax_t)length,
332 (intmax_t)(offset + length - 1));
333 return(pp);
334}
335
336struct g_geom *
385struct g_provider *
386g_slice_addslice(struct g_geom *gp, int index, off_t offset, off_t length, u_int sectorsize, char *fmt, ...)
387{
388 struct g_provider *pp;
389 struct g_slicer *gsp;
390 va_list ap;
391 struct sbuf *sb;
392

--- 17 unchanged lines hidden (view full) ---

410 if (bootverbose)
411 printf("GEOM: Add %s, start %jd length %jd end %jd\n",
412 pp->name, (intmax_t)offset, (intmax_t)length,
413 (intmax_t)(offset + length - 1));
414 return(pp);
415}
416
417struct g_geom *
337g_slice_new(struct g_class *mp, int slices, struct g_provider *pp, struct g_consumer **cpp, void *extrap, int extra, g_slice_start_t *start)
418g_slice_new(struct g_class *mp, u_int slices, struct g_provider *pp, struct g_consumer **cpp, void *extrap, int extra, g_slice_start_t *start)
338{
339 struct g_geom *gp;
340 struct g_slicer *gsp;
341 struct g_consumer *cp;
342 void **vp;
343 int error, i;
344
345 g_topology_assert();

--- 38 unchanged lines hidden (view full) ---

384 int error;
385
386 g_trace(G_T_TOPOLOGY, "g_slice_orphan(%p/%s)", cp, cp->provider->name);
387 g_topology_assert();
388 KASSERT(cp->provider->error != 0,
389 ("g_slice_orphan with error == 0"));
390
391 gp = cp->geom;
419{
420 struct g_geom *gp;
421 struct g_slicer *gsp;
422 struct g_consumer *cp;
423 void **vp;
424 int error, i;
425
426 g_topology_assert();

--- 38 unchanged lines hidden (view full) ---

465 int error;
466
467 g_trace(G_T_TOPOLOGY, "g_slice_orphan(%p/%s)", cp, cp->provider->name);
468 g_topology_assert();
469 KASSERT(cp->provider->error != 0,
470 ("g_slice_orphan with error == 0"));
471
472 gp = cp->geom;
473 /* XXX: Not good enough we leak the softc and its suballocations */
392 gp->flags |= G_GEOM_WITHER;
393 error = cp->provider->error;
394 LIST_FOREACH(pp, &gp->provider, provider)
395 g_orphan_provider(pp, error);
396 return;
397}
474 gp->flags |= G_GEOM_WITHER;
475 error = cp->provider->error;
476 LIST_FOREACH(pp, &gp->provider, provider)
477 g_orphan_provider(pp, error);
478 return;
479}