1*3af888c1Sjakllsch /* $NetBSD: dmover_session.c,v 1.6 2011/05/14 18:24:47 jakllsch Exp $ */
25d06c0e8Sthorpej
35d06c0e8Sthorpej /*
45d06c0e8Sthorpej * Copyright (c) 2002 Wasabi Systems, Inc.
55d06c0e8Sthorpej * All rights reserved.
65d06c0e8Sthorpej *
75d06c0e8Sthorpej * Written by Jason R. Thorpe for Wasabi Systems, Inc.
85d06c0e8Sthorpej *
95d06c0e8Sthorpej * Redistribution and use in source and binary forms, with or without
105d06c0e8Sthorpej * modification, are permitted provided that the following conditions
115d06c0e8Sthorpej * are met:
125d06c0e8Sthorpej * 1. Redistributions of source code must retain the above copyright
135d06c0e8Sthorpej * notice, this list of conditions and the following disclaimer.
145d06c0e8Sthorpej * 2. Redistributions in binary form must reproduce the above copyright
155d06c0e8Sthorpej * notice, this list of conditions and the following disclaimer in the
165d06c0e8Sthorpej * documentation and/or other materials provided with the distribution.
175d06c0e8Sthorpej * 3. All advertising materials mentioning features or use of this software
185d06c0e8Sthorpej * must display the following acknowledgement:
195d06c0e8Sthorpej * This product includes software developed for the NetBSD Project by
205d06c0e8Sthorpej * Wasabi Systems, Inc.
215d06c0e8Sthorpej * 4. The name of Wasabi Systems, Inc. may not be used to endorse
225d06c0e8Sthorpej * or promote products derived from this software without specific prior
235d06c0e8Sthorpej * written permission.
245d06c0e8Sthorpej *
255d06c0e8Sthorpej * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
265d06c0e8Sthorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
275d06c0e8Sthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
285d06c0e8Sthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
295d06c0e8Sthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
305d06c0e8Sthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
315d06c0e8Sthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
325d06c0e8Sthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
335d06c0e8Sthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
345d06c0e8Sthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
355d06c0e8Sthorpej * POSSIBILITY OF SUCH DAMAGE.
365d06c0e8Sthorpej */
375d06c0e8Sthorpej
385d06c0e8Sthorpej /*
395d06c0e8Sthorpej * dmover_session.c: Session management functions for dmover-api.
405d06c0e8Sthorpej */
415d06c0e8Sthorpej
425d06c0e8Sthorpej #include <sys/cdefs.h>
43*3af888c1Sjakllsch __KERNEL_RCSID(0, "$NetBSD: dmover_session.c,v 1.6 2011/05/14 18:24:47 jakllsch Exp $");
445d06c0e8Sthorpej
455d06c0e8Sthorpej #include <sys/param.h>
465d06c0e8Sthorpej #include <sys/pool.h>
475d06c0e8Sthorpej #include <sys/systm.h>
485d06c0e8Sthorpej #include <sys/malloc.h>
495d06c0e8Sthorpej
505d06c0e8Sthorpej #include <dev/dmover/dmovervar.h>
515d06c0e8Sthorpej
525d06c0e8Sthorpej struct pool dmover_session_pool;
535d06c0e8Sthorpej
54*3af888c1Sjakllsch static bool initialized;
555d06c0e8Sthorpej
565d06c0e8Sthorpej void
dmover_session_initialize(void)575d06c0e8Sthorpej dmover_session_initialize(void)
585d06c0e8Sthorpej {
595d06c0e8Sthorpej
60*3af888c1Sjakllsch KASSERT(initialized == false);
61*3af888c1Sjakllsch
625d06c0e8Sthorpej pool_init(&dmover_session_pool, sizeof(struct dmover_session),
633bf25423Sad 0, 0, 0, "dmses", &pool_allocator_nointr, IPL_NONE);
64*3af888c1Sjakllsch initialized = true;
655d06c0e8Sthorpej }
665d06c0e8Sthorpej
675d06c0e8Sthorpej /*
685d06c0e8Sthorpej * dmover_session_create: [client interface function]
695d06c0e8Sthorpej *
705d06c0e8Sthorpej * Create a dmover session.
715d06c0e8Sthorpej */
725d06c0e8Sthorpej int
dmover_session_create(const char * type,struct dmover_session ** dsesp)735d06c0e8Sthorpej dmover_session_create(const char *type, struct dmover_session **dsesp)
745d06c0e8Sthorpej {
755d06c0e8Sthorpej struct dmover_session *dses;
765d06c0e8Sthorpej int error;
775d06c0e8Sthorpej
78*3af888c1Sjakllsch if (__predict_false(initialized == false)) {
79*3af888c1Sjakllsch error = initialized ? false : ENXIO;
805d06c0e8Sthorpej
815d06c0e8Sthorpej if (error)
825d06c0e8Sthorpej return (error);
835d06c0e8Sthorpej }
845d06c0e8Sthorpej
855d06c0e8Sthorpej dses = pool_get(&dmover_session_pool, PR_NOWAIT);
865d06c0e8Sthorpej if (__predict_false(dses == NULL))
875d06c0e8Sthorpej return (ENOMEM);
885d06c0e8Sthorpej
895d06c0e8Sthorpej /* Allocate a back-end to the session. */
905d06c0e8Sthorpej error = dmover_backend_alloc(dses, type);
915d06c0e8Sthorpej if (__predict_false(error)) {
925d06c0e8Sthorpej pool_put(&dmover_session_pool, dses);
935d06c0e8Sthorpej return (error);
945d06c0e8Sthorpej }
955d06c0e8Sthorpej
965d06c0e8Sthorpej TAILQ_INIT(&dses->__dses_pendreqs);
975d06c0e8Sthorpej dses->__dses_npendreqs = 0;
985d06c0e8Sthorpej
995d06c0e8Sthorpej *dsesp = dses;
1005d06c0e8Sthorpej return (0);
1015d06c0e8Sthorpej }
1025d06c0e8Sthorpej
1035d06c0e8Sthorpej /*
1045d06c0e8Sthorpej * dmover_session_destroy: [client interface function]
1055d06c0e8Sthorpej *
1065d06c0e8Sthorpej * Tear down a dmover session.
1075d06c0e8Sthorpej */
1085d06c0e8Sthorpej void
dmover_session_destroy(struct dmover_session * dses)1095d06c0e8Sthorpej dmover_session_destroy(struct dmover_session *dses)
1105d06c0e8Sthorpej {
1115d06c0e8Sthorpej
112*3af888c1Sjakllsch KASSERT(initialized == true);
1135d06c0e8Sthorpej
1145d06c0e8Sthorpej /* XXX */
1155d06c0e8Sthorpej if (dses->__dses_npendreqs)
1165d06c0e8Sthorpej panic("dmover_session_destroy");
1175d06c0e8Sthorpej
1185d06c0e8Sthorpej dmover_backend_release(dses);
1195d06c0e8Sthorpej pool_put(&dmover_session_pool, dses);
1205d06c0e8Sthorpej }
121