Deleted Added
full compact
g_gate.c (128835) g_gate.c (128881)
1/*-
2 * Copyright (c) 2004 Pawel Jakub Dawidek <pjd@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 2004 Pawel Jakub Dawidek <pjd@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/geom/gate/g_gate.c 128835 2004-05-02 17:57:49Z pjd $
26 * $FreeBSD: head/sys/geom/gate/g_gate.c 128881 2004-05-03 18:06:24Z pjd $
27 */
28
29#include <sys/param.h>
30#include <sys/systm.h>
31#include <sys/bio.h>
32#include <sys/conf.h>
33#include <sys/kernel.h>
34#include <sys/kthread.h>

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

375 (ggio->gctl_flags & G_GATE_FLAG_WRITEONLY) != 0) {
376 G_GATE_DEBUG(1, "Invalid flags.");
377 return (EINVAL);
378 }
379 if (ggio->gctl_unit < -1) {
380 G_GATE_DEBUG(1, "Invalid unit number.");
381 return (EINVAL);
382 }
27 */
28
29#include <sys/param.h>
30#include <sys/systm.h>
31#include <sys/bio.h>
32#include <sys/conf.h>
33#include <sys/kernel.h>
34#include <sys/kthread.h>

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

375 (ggio->gctl_flags & G_GATE_FLAG_WRITEONLY) != 0) {
376 G_GATE_DEBUG(1, "Invalid flags.");
377 return (EINVAL);
378 }
379 if (ggio->gctl_unit < -1) {
380 G_GATE_DEBUG(1, "Invalid unit number.");
381 return (EINVAL);
382 }
383 ggio->gctl_unit = g_gate_getunit(ggio->gctl_unit);
384 if (ggio->gctl_unit == -1)
385 return (EBUSY);
386
387 sc = malloc(sizeof(*sc), M_GATE, M_WAITOK | M_ZERO);
388 sc->sc_flags = (ggio->gctl_flags & G_GATE_USERFLAGS);
389 strlcpy(sc->sc_info, ggio->gctl_info, sizeof(sc->sc_info));
390 sc->sc_seq = 0;
391 bioq_init(&sc->sc_inqueue);
392 mtx_init(&sc->sc_inqueue_mtx, "gg:inqueue", NULL, MTX_DEF);
393 bioq_init(&sc->sc_outqueue);
394 mtx_init(&sc->sc_outqueue_mtx, "gg:outqueue", NULL, MTX_DEF);
395 sc->sc_queue_count = 0;
396 sc->sc_queue_size = ggio->gctl_maxcount;
397 if (sc->sc_queue_size > G_GATE_MAX_QUEUE_SIZE)
398 sc->sc_queue_size = G_GATE_MAX_QUEUE_SIZE;
399 sc->sc_timeout = ggio->gctl_timeout;
383
384 sc = malloc(sizeof(*sc), M_GATE, M_WAITOK | M_ZERO);
385 sc->sc_flags = (ggio->gctl_flags & G_GATE_USERFLAGS);
386 strlcpy(sc->sc_info, ggio->gctl_info, sizeof(sc->sc_info));
387 sc->sc_seq = 0;
388 bioq_init(&sc->sc_inqueue);
389 mtx_init(&sc->sc_inqueue_mtx, "gg:inqueue", NULL, MTX_DEF);
390 bioq_init(&sc->sc_outqueue);
391 mtx_init(&sc->sc_outqueue_mtx, "gg:outqueue", NULL, MTX_DEF);
392 sc->sc_queue_count = 0;
393 sc->sc_queue_size = ggio->gctl_maxcount;
394 if (sc->sc_queue_size > G_GATE_MAX_QUEUE_SIZE)
395 sc->sc_queue_size = G_GATE_MAX_QUEUE_SIZE;
396 sc->sc_timeout = ggio->gctl_timeout;
397 callout_init(&sc->sc_callout, CALLOUT_MPSAFE);
400 mtx_lock(&g_gate_list_mtx);
398 mtx_lock(&g_gate_list_mtx);
399 ggio->gctl_unit = g_gate_getunit(ggio->gctl_unit);
400 if (ggio->gctl_unit == -1) {
401 mtx_destroy(&sc->sc_inqueue_mtx);
402 mtx_destroy(&sc->sc_outqueue_mtx);
403 free(sc, M_GATE);
404 return (EBUSY);
405 }
401 sc->sc_unit = ggio->gctl_unit;
406 sc->sc_unit = ggio->gctl_unit;
402 callout_init(&sc->sc_callout, CALLOUT_MPSAFE);
403 LIST_INSERT_HEAD(&g_gate_list, sc, sc_next);
404 mtx_unlock(&g_gate_list_mtx);
405
406 DROP_GIANT();
407 g_topology_lock();
408 gp = g_new_geomf(&g_gate_class, "%s%d", G_GATE_PROVIDER_NAME,
409 sc->sc_unit);
410 gp->start = g_gate_start;

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

485 return (0);
486 }
487 if ((sc->sc_flags & G_GATE_FLAG_DESTROY) != 0) {
488 g_gate_release(sc);
489 ggio->gctl_error = ECANCELED;
490 return (0);
491 }
492 }
407 LIST_INSERT_HEAD(&g_gate_list, sc, sc_next);
408 mtx_unlock(&g_gate_list_mtx);
409
410 DROP_GIANT();
411 g_topology_lock();
412 gp = g_new_geomf(&g_gate_class, "%s%d", G_GATE_PROVIDER_NAME,
413 sc->sc_unit);
414 gp->start = g_gate_start;

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

489 return (0);
490 }
491 if ((sc->sc_flags & G_GATE_FLAG_DESTROY) != 0) {
492 g_gate_release(sc);
493 ggio->gctl_error = ECANCELED;
494 return (0);
495 }
496 }
497 ggio->gctl_cmd = bp->bio_cmd;
493 if ((bp->bio_cmd == BIO_DELETE || bp->bio_cmd == BIO_WRITE) &&
494 bp->bio_length > ggio->gctl_length) {
495 mtx_unlock(&sc->sc_inqueue_mtx);
496 g_gate_release(sc);
497 ggio->gctl_length = bp->bio_length;
498 ggio->gctl_error = ENOMEM;
499 return (0);
500 }
501 bioq_remove(&sc->sc_inqueue, bp);
502 atomic_subtract_rel_32(&sc->sc_queue_count, 1);
503 mtx_unlock(&sc->sc_inqueue_mtx);
504 ggio->gctl_seq = (uintptr_t)bp->bio_driver1;
498 if ((bp->bio_cmd == BIO_DELETE || bp->bio_cmd == BIO_WRITE) &&
499 bp->bio_length > ggio->gctl_length) {
500 mtx_unlock(&sc->sc_inqueue_mtx);
501 g_gate_release(sc);
502 ggio->gctl_length = bp->bio_length;
503 ggio->gctl_error = ENOMEM;
504 return (0);
505 }
506 bioq_remove(&sc->sc_inqueue, bp);
507 atomic_subtract_rel_32(&sc->sc_queue_count, 1);
508 mtx_unlock(&sc->sc_inqueue_mtx);
509 ggio->gctl_seq = (uintptr_t)bp->bio_driver1;
505 ggio->gctl_cmd = bp->bio_cmd;
506 ggio->gctl_offset = bp->bio_offset;
507 ggio->gctl_length = bp->bio_length;
508 switch (bp->bio_cmd) {
509 case BIO_READ:
510 break;
511 case BIO_DELETE:
512 case BIO_WRITE:
513 error = copyout(bp->bio_data, ggio->gctl_data,

--- 119 unchanged lines hidden ---
510 ggio->gctl_offset = bp->bio_offset;
511 ggio->gctl_length = bp->bio_length;
512 switch (bp->bio_cmd) {
513 case BIO_READ:
514 break;
515 case BIO_DELETE:
516 case BIO_WRITE:
517 error = copyout(bp->bio_data, ggio->gctl_data,

--- 119 unchanged lines hidden ---