1/*-
2 * Copyright (c) 2003 Silicon Graphics International Corp.
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
--- 22 unchanged lines hidden (view full) ---
31 */
32/*
33 * CTL backend driver registration routines
34 *
35 * Author: Ken Merry <ken@FreeBSD.org>
36 */
37
38#include <sys/cdefs.h>
39__FBSDID("$FreeBSD: head/sys/cam/ctl/ctl_backend.c 268288 2014-07-05 14:32:42Z mav $");
40
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>
46#include <sys/lock.h>
47#include <sys/mutex.h>
--- 13 unchanged lines hidden (view full) ---
61#include <cam/ctl/ctl_private.h>
62#include <cam/ctl/ctl_debug.h>
63
64extern struct ctl_softc *control_softc;
65
66int
67ctl_backend_register(struct ctl_backend_driver *be)
68{
69 struct ctl_softc *ctl_softc;
70 struct ctl_backend_driver *be_tmp;
71
72 ctl_softc = control_softc;
73
74 mtx_lock(&ctl_softc->ctl_lock);
75 /*
76 * Sanity check, make sure this isn't a duplicate registration.
77 */
78 STAILQ_FOREACH(be_tmp, &ctl_softc->be_list, links) {
79 if (strcmp(be_tmp->name, be->name) == 0) {
80 mtx_unlock(&ctl_softc->ctl_lock);
81 return (-1);
82 }
83 }
84 mtx_unlock(&ctl_softc->ctl_lock);
85
86 /*
87 * Call the backend's initialization routine.
88 */
89 be->init();
90
91 mtx_lock(&ctl_softc->ctl_lock);
92
93 STAILQ_INSERT_TAIL(&ctl_softc->be_list, be, links);
94
95 ctl_softc->num_backends++;
96
97 /*
98 * Don't want to increment the usage count for internal consumers,
99 * we won't be able to unload otherwise.
100 */
101 /* XXX KDM find a substitute for this? */
102#if 0
103 if ((be->flags & CTL_BE_FLAG_INTERNAL) == 0)
--- 4 unchanged lines hidden (view full) ---
108 be->config_move_done = ctl_config_move_done;
109#endif
110 /* XXX KDM fix this! */
111 be->num_luns = 0;
112#if 0
113 atomic_set(&be->num_luns, 0);
114#endif
115
116 mtx_unlock(&ctl_softc->ctl_lock);
117
118 return (0);
119}
120
121int
122ctl_backend_deregister(struct ctl_backend_driver *be)
123{
124 struct ctl_softc *ctl_softc;
125
126 ctl_softc = control_softc;
127
128 mtx_lock(&ctl_softc->ctl_lock);
129
130#if 0
131 if (atomic_read(&be->num_luns) != 0) {
132#endif
133 /* XXX KDM fix this! */
134 if (be->num_luns != 0) {
135 mtx_unlock(&ctl_softc->ctl_lock);
136 return (-1);
137 }
138
139 STAILQ_REMOVE(&ctl_softc->be_list, be, ctl_backend_driver, links);
140
141 ctl_softc->num_backends--;
142
143 /* XXX KDM find a substitute for this? */
144#if 0
145 if ((be->flags & CTL_BE_FLAG_INTERNAL) == 0)
146 MOD_DEC_USE_COUNT;
147#endif
148
149 mtx_unlock(&ctl_softc->ctl_lock);
150
151 return (0);
152}
153
154struct ctl_backend_driver *
155ctl_backend_find(char *backend_name)
156{
157 struct ctl_softc *ctl_softc;
158 struct ctl_backend_driver *be_tmp;
159
160 ctl_softc = control_softc;
161
162 mtx_lock(&ctl_softc->ctl_lock);
163
164 STAILQ_FOREACH(be_tmp, &ctl_softc->be_list, links) {
165 if (strcmp(be_tmp->name, backend_name) == 0) {
166 mtx_unlock(&ctl_softc->ctl_lock);
167 return (be_tmp);
168 }
169 }
170
171 mtx_unlock(&ctl_softc->ctl_lock);
172
173 return (NULL);
174}
175
176void
177ctl_init_opts(ctl_options_t *opts, int num_args, struct ctl_be_arg *args)
178{
179 struct ctl_option *opt;
--- 42 unchanged lines hidden ---
2 * Copyright (c) 2003 Silicon Graphics International Corp.
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
--- 22 unchanged lines hidden (view full) ---
31 */
32/*
33 * CTL backend driver registration routines
34 *
35 * Author: Ken Merry <ken@FreeBSD.org>
36 */
37
38#include <sys/cdefs.h>
39__FBSDID("$FreeBSD: head/sys/cam/ctl/ctl_backend.c 268288 2014-07-05 14:32:42Z mav $");
40
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>
46#include <sys/lock.h>
47#include <sys/mutex.h>
--- 13 unchanged lines hidden (view full) ---
61#include <cam/ctl/ctl_private.h>
62#include <cam/ctl/ctl_debug.h>
63
64extern struct ctl_softc *control_softc;
65
66int
67ctl_backend_register(struct ctl_backend_driver *be)
68{
69 struct ctl_softc *ctl_softc;
70 struct ctl_backend_driver *be_tmp;
71
72 ctl_softc = control_softc;
73
74 mtx_lock(&ctl_softc->ctl_lock);
75 /*
76 * Sanity check, make sure this isn't a duplicate registration.
77 */
78 STAILQ_FOREACH(be_tmp, &ctl_softc->be_list, links) {
79 if (strcmp(be_tmp->name, be->name) == 0) {
80 mtx_unlock(&ctl_softc->ctl_lock);
81 return (-1);
82 }
83 }
84 mtx_unlock(&ctl_softc->ctl_lock);
85
86 /*
87 * Call the backend's initialization routine.
88 */
89 be->init();
90
91 mtx_lock(&ctl_softc->ctl_lock);
92
93 STAILQ_INSERT_TAIL(&ctl_softc->be_list, be, links);
94
95 ctl_softc->num_backends++;
96
97 /*
98 * Don't want to increment the usage count for internal consumers,
99 * we won't be able to unload otherwise.
100 */
101 /* XXX KDM find a substitute for this? */
102#if 0
103 if ((be->flags & CTL_BE_FLAG_INTERNAL) == 0)
--- 4 unchanged lines hidden (view full) ---
108 be->config_move_done = ctl_config_move_done;
109#endif
110 /* XXX KDM fix this! */
111 be->num_luns = 0;
112#if 0
113 atomic_set(&be->num_luns, 0);
114#endif
115
116 mtx_unlock(&ctl_softc->ctl_lock);
117
118 return (0);
119}
120
121int
122ctl_backend_deregister(struct ctl_backend_driver *be)
123{
124 struct ctl_softc *ctl_softc;
125
126 ctl_softc = control_softc;
127
128 mtx_lock(&ctl_softc->ctl_lock);
129
130#if 0
131 if (atomic_read(&be->num_luns) != 0) {
132#endif
133 /* XXX KDM fix this! */
134 if (be->num_luns != 0) {
135 mtx_unlock(&ctl_softc->ctl_lock);
136 return (-1);
137 }
138
139 STAILQ_REMOVE(&ctl_softc->be_list, be, ctl_backend_driver, links);
140
141 ctl_softc->num_backends--;
142
143 /* XXX KDM find a substitute for this? */
144#if 0
145 if ((be->flags & CTL_BE_FLAG_INTERNAL) == 0)
146 MOD_DEC_USE_COUNT;
147#endif
148
149 mtx_unlock(&ctl_softc->ctl_lock);
150
151 return (0);
152}
153
154struct ctl_backend_driver *
155ctl_backend_find(char *backend_name)
156{
157 struct ctl_softc *ctl_softc;
158 struct ctl_backend_driver *be_tmp;
159
160 ctl_softc = control_softc;
161
162 mtx_lock(&ctl_softc->ctl_lock);
163
164 STAILQ_FOREACH(be_tmp, &ctl_softc->be_list, links) {
165 if (strcmp(be_tmp->name, backend_name) == 0) {
166 mtx_unlock(&ctl_softc->ctl_lock);
167 return (be_tmp);
168 }
169 }
170
171 mtx_unlock(&ctl_softc->ctl_lock);
172
173 return (NULL);
174}
175
176void
177ctl_init_opts(ctl_options_t *opts, int num_args, struct ctl_be_arg *args)
178{
179 struct ctl_option *opt;
--- 42 unchanged lines hidden ---