Deleted Added
full compact
scsi_enc.c (242173) scsi_enc.c (244014)
1/*-
2 * Copyright (c) 2000 Matthew Jacob
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

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

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
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2000 Matthew Jacob
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

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

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
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/cam/scsi/scsi_enc.c 242173 2012-10-27 08:52:33Z mav $");
28__FBSDID("$FreeBSD: head/sys/cam/scsi/scsi_enc.c 244014 2012-12-08 04:03:04Z ken $");
29
30#include <sys/param.h>
31
32#include <sys/conf.h>
33#include <sys/errno.h>
34#include <sys/fcntl.h>
35#include <sys/kernel.h>
36#include <sys/kthread.h>

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

106 printf("enc: Failed to attach master async callback "
107 "due to status 0x%x!\n", status);
108 }
109}
110
111static void
112enc_devgonecb(void *arg)
113{
29
30#include <sys/param.h>
31
32#include <sys/conf.h>
33#include <sys/errno.h>
34#include <sys/fcntl.h>
35#include <sys/kernel.h>
36#include <sys/kthread.h>

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

106 printf("enc: Failed to attach master async callback "
107 "due to status 0x%x!\n", status);
108 }
109}
110
111static void
112enc_devgonecb(void *arg)
113{
114 struct cam_sim *sim;
114 struct cam_periph *periph;
115 struct cam_periph *periph;
116 struct enc_softc *enc;
117 int i;
115
116 periph = (struct cam_periph *)arg;
118
119 periph = (struct cam_periph *)arg;
120 sim = periph->sim;
121 enc = (struct enc_softc *)periph->softc;
117
122
118 cam_periph_release(periph);
123 mtx_lock(sim->mtx);
124
125 /*
126 * When we get this callback, we will get no more close calls from
127 * devfs. So if we have any dangling opens, we need to release the
128 * reference held for that particular context.
129 */
130 for (i = 0; i < enc->open_count; i++)
131 cam_periph_release_locked(periph);
132
133 enc->open_count = 0;
134
135 /*
136 * Release the reference held for the device node, it is gone now.
137 */
138 cam_periph_release_locked(periph);
139
140 /*
141 * We reference the SIM lock directly here, instead of using
142 * cam_periph_unlock(). The reason is that the final call to
143 * cam_periph_release_locked() above could result in the periph
144 * getting freed. If that is the case, dereferencing the periph
145 * with a cam_periph_unlock() call would cause a page fault.
146 */
147 mtx_unlock(sim->mtx);
119}
120
121static void
122enc_oninvalidate(struct cam_periph *periph)
123{
124 struct enc_softc *enc;
125
126 enc = periph->softc;

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

257 }
258 if (softc->enc_flags & ENC_FLAG_INVALID) {
259 error = ENXIO;
260 goto out;
261 }
262out:
263 if (error != 0)
264 cam_periph_release_locked(periph);
148}
149
150static void
151enc_oninvalidate(struct cam_periph *periph)
152{
153 struct enc_softc *enc;
154
155 enc = periph->softc;

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

286 }
287 if (softc->enc_flags & ENC_FLAG_INVALID) {
288 error = ENXIO;
289 goto out;
290 }
291out:
292 if (error != 0)
293 cam_periph_release_locked(periph);
294 else
295 softc->open_count++;
265
266 cam_periph_unlock(periph);
267
268 return (error);
269}
270
271static int
272enc_close(struct cdev *dev, int flag, int fmt, struct thread *td)
273{
296
297 cam_periph_unlock(periph);
298
299 return (error);
300}
301
302static int
303enc_close(struct cdev *dev, int flag, int fmt, struct thread *td)
304{
305 struct cam_sim *sim;
274 struct cam_periph *periph;
306 struct cam_periph *periph;
307 struct enc_softc *enc;
275
276 periph = (struct cam_periph *)dev->si_drv1;
277 if (periph == NULL)
278 return (ENXIO);
279
308
309 periph = (struct cam_periph *)dev->si_drv1;
310 if (periph == NULL)
311 return (ENXIO);
312
280 cam_periph_release(periph);
313 sim = periph->sim;
314 enc = periph->softc;
281
315
316 mtx_lock(sim->mtx);
317
318 enc->open_count--;
319
320 cam_periph_release_locked(periph);
321
322 /*
323 * We reference the SIM lock directly here, instead of using
324 * cam_periph_unlock(). The reason is that the call to
325 * cam_periph_release_locked() above could result in the periph
326 * getting freed. If that is the case, dereferencing the periph
327 * with a cam_periph_unlock() call would cause a page fault.
328 *
329 * cam_periph_release() avoids this problem using the same method,
330 * but we're manually acquiring and dropping the lock here to
331 * protect the open count and avoid another lock acquisition and
332 * release.
333 */
334 mtx_unlock(sim->mtx);
335
282 return (0);
283}
284
285static void
286enc_start(struct cam_periph *p, union ccb *sccb)
287{
288 struct enc_softc *enc;
289

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

941 err = enc_kproc_init(enc);
942 if (err) {
943 xpt_print(periph->path,
944 "error %d starting enc_daemon\n", err);
945 goto out;
946 }
947 }
948
336 return (0);
337}
338
339static void
340enc_start(struct cam_periph *p, union ccb *sccb)
341{
342 struct enc_softc *enc;
343

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

995 err = enc_kproc_init(enc);
996 if (err) {
997 xpt_print(periph->path,
998 "error %d starting enc_daemon\n", err);
999 goto out;
1000 }
1001 }
1002
1003 /*
1004 * Acquire a reference to the periph before we create the devfs
1005 * instance for it. We'll release this reference once the devfs
1006 * instance has been freed.
1007 */
949 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
950 xpt_print(periph->path, "%s: lost periph during "
951 "registration!\n", __func__);
952 cam_periph_lock(periph);
953
954 return (CAM_REQ_CMP_ERR);
955 }
956

--- 48 unchanged lines hidden ---
1008 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
1009 xpt_print(periph->path, "%s: lost periph during "
1010 "registration!\n", __func__);
1011 cam_periph_lock(periph);
1012
1013 return (CAM_REQ_CMP_ERR);
1014 }
1015

--- 48 unchanged lines hidden ---