2 * Copyright (c) 2003 Silicon Graphics International Corp.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions, and the following disclaimer,
10 * without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 * substantially similar to the "NO WARRANTY" disclaimer below
13 * ("Disclaimer") and any redistribution must be conditioned upon
14 * including a substantially similar Disclaimer requirement for further
15 * binary redistribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGES.
30 * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_backend.c#3 $
33 * CTL backend driver registration routines
35 * Author: Ken Merry <ken@FreeBSD.org>
38 #include <sys/cdefs.h>
39 __FBSDID("$FreeBSD$");
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/kernel.h>
44 #include <sys/types.h>
45 #include <sys/malloc.h>
47 #include <sys/mutex.h>
48 #include <sys/condvar.h>
49 #include <sys/queue.h>
50 #include <sys/sysctl.h>
52 #include <cam/scsi/scsi_all.h>
53 #include <cam/scsi/scsi_da.h>
54 #include <cam/ctl/ctl_io.h>
55 #include <cam/ctl/ctl.h>
56 #include <cam/ctl/ctl_frontend.h>
57 #include <cam/ctl/ctl_backend.h>
58 #include <cam/ctl/ctl_frontend_internal.h>
59 #include <cam/ctl/ctl_ioctl.h>
60 #include <cam/ctl/ctl_ha.h>
61 #include <cam/ctl/ctl_private.h>
62 #include <cam/ctl/ctl_debug.h>
64 extern struct ctl_softc *control_softc;
67 ctl_backend_register(struct ctl_backend_driver *be)
69 struct ctl_softc *softc;
70 struct ctl_backend_driver *be_tmp;
72 softc = control_softc;
74 mtx_lock(&softc->ctl_lock);
76 * Sanity check, make sure this isn't a duplicate registration.
78 STAILQ_FOREACH(be_tmp, &softc->be_list, links) {
79 if (strcmp(be_tmp->name, be->name) == 0) {
80 mtx_unlock(&softc->ctl_lock);
84 mtx_unlock(&softc->ctl_lock);
87 * Call the backend's initialization routine.
91 mtx_lock(&softc->ctl_lock);
93 STAILQ_INSERT_TAIL(&softc->be_list, be, links);
95 softc->num_backends++;
98 * Don't want to increment the usage count for internal consumers,
99 * we won't be able to unload otherwise.
101 /* XXX KDM find a substitute for this? */
103 if ((be->flags & CTL_BE_FLAG_INTERNAL) == 0)
107 #ifdef CS_BE_CONFIG_MOVE_DONE_IS_NOT_USED
108 be->config_move_done = ctl_config_move_done;
110 /* XXX KDM fix this! */
113 atomic_set(&be->num_luns, 0);
116 mtx_unlock(&softc->ctl_lock);
122 ctl_backend_deregister(struct ctl_backend_driver *be)
124 struct ctl_softc *softc;
126 softc = control_softc;
128 mtx_lock(&softc->ctl_lock);
131 if (atomic_read(&be->num_luns) != 0) {
133 /* XXX KDM fix this! */
134 if (be->num_luns != 0) {
135 mtx_unlock(&softc->ctl_lock);
139 STAILQ_REMOVE(&softc->be_list, be, ctl_backend_driver, links);
141 softc->num_backends--;
143 /* XXX KDM find a substitute for this? */
145 if ((be->flags & CTL_BE_FLAG_INTERNAL) == 0)
149 mtx_unlock(&softc->ctl_lock);
154 struct ctl_backend_driver *
155 ctl_backend_find(char *backend_name)
157 struct ctl_softc *softc;
158 struct ctl_backend_driver *be_tmp;
160 softc = control_softc;
162 mtx_lock(&softc->ctl_lock);
164 STAILQ_FOREACH(be_tmp, &softc->be_list, links) {
165 if (strcmp(be_tmp->name, backend_name) == 0) {
166 mtx_unlock(&softc->ctl_lock);
171 mtx_unlock(&softc->ctl_lock);
177 ctl_init_opts(ctl_options_t *opts, int num_args, struct ctl_be_arg *args)
179 struct ctl_option *opt;
183 for (i = 0; i < num_args; i++) {
184 if ((args[i].flags & CTL_BEARG_RD) == 0)
186 if ((args[i].flags & CTL_BEARG_ASCII) == 0)
188 opt = malloc(sizeof(*opt), M_CTL, M_WAITOK);
189 opt->name = malloc(strlen(args[i].kname) + 1, M_CTL, M_WAITOK);
190 strcpy(opt->name, args[i].kname);
191 opt->value = malloc(strlen(args[i].kvalue) + 1, M_CTL, M_WAITOK);
192 strcpy(opt->value, args[i].kvalue);
193 STAILQ_INSERT_TAIL(opts, opt, links);
198 ctl_free_opts(ctl_options_t *opts)
200 struct ctl_option *opt;
202 while ((opt = STAILQ_FIRST(opts)) != NULL) {
203 STAILQ_REMOVE_HEAD(opts, links);
204 free(opt->name, M_CTL);
205 free(opt->value, M_CTL);
211 ctl_get_opt(ctl_options_t *opts, const char *name)
213 struct ctl_option *opt;
215 STAILQ_FOREACH(opt, opts, links) {
216 if (strcmp(opt->name, name) == 0) {