Lines Matching full:sdp
196 static Sg_fd *sg_add_sfp(Sg_device * sdp);
209 #define sg_printk(prefix, sdp, fmt, a...) \ argument
210 sdev_prefix_printk(prefix, (sdp)->device, (sdp)->name, fmt, ##a)
246 open_wait(Sg_device *sdp, int flags) in open_wait() argument
251 while (sdp->open_cnt > 0) { in open_wait()
252 mutex_unlock(&sdp->open_rel_lock); in open_wait()
253 retval = wait_event_interruptible(sdp->open_wait, in open_wait()
254 (atomic_read(&sdp->detaching) || in open_wait()
255 !sdp->open_cnt)); in open_wait()
256 mutex_lock(&sdp->open_rel_lock); in open_wait()
260 if (atomic_read(&sdp->detaching)) in open_wait()
264 while (sdp->exclude) { in open_wait()
265 mutex_unlock(&sdp->open_rel_lock); in open_wait()
266 retval = wait_event_interruptible(sdp->open_wait, in open_wait()
267 (atomic_read(&sdp->detaching) || in open_wait()
268 !sdp->exclude)); in open_wait()
269 mutex_lock(&sdp->open_rel_lock); in open_wait()
273 if (atomic_read(&sdp->detaching)) in open_wait()
289 Sg_device *sdp; in sg_open() local
296 sdp = sg_get_dev(dev); in sg_open()
297 if (IS_ERR(sdp)) in sg_open()
298 return PTR_ERR(sdp); in sg_open()
300 SCSI_LOG_TIMEOUT(3, sg_printk(KERN_INFO, sdp, in sg_open()
305 device = sdp->device; in sg_open()
320 mutex_lock(&sdp->open_rel_lock); in sg_open()
323 if (sdp->open_cnt > 0) { in sg_open()
328 if (sdp->exclude) { in sg_open()
334 retval = open_wait(sdp, flags); in sg_open()
341 sdp->exclude = true; in sg_open()
343 if (sdp->open_cnt < 1) { /* no existing opens */ in sg_open()
344 sdp->sgdebug = 0; in sg_open()
346 sdp->sg_tablesize = queue_max_segments(q); in sg_open()
348 sfp = sg_add_sfp(sdp); in sg_open()
355 sdp->open_cnt++; in sg_open()
356 mutex_unlock(&sdp->open_rel_lock); in sg_open()
360 kref_put(&sdp->d_ref, sg_device_destroy); in sg_open()
365 sdp->exclude = false; /* undo if error */ in sg_open()
366 wake_up_interruptible(&sdp->open_wait); in sg_open()
369 mutex_unlock(&sdp->open_rel_lock); in sg_open()
371 kref_put(&sdp->d_ref, sg_device_destroy); in sg_open()
381 Sg_device *sdp; in sg_release() local
384 if ((!(sfp = (Sg_fd *) filp->private_data)) || (!(sdp = sfp->parentdp))) in sg_release()
386 SCSI_LOG_TIMEOUT(3, sg_printk(KERN_INFO, sdp, "sg_release\n")); in sg_release()
388 mutex_lock(&sdp->open_rel_lock); in sg_release()
389 sdp->open_cnt--; in sg_release()
393 if (sdp->exclude) { in sg_release()
394 sdp->exclude = false; in sg_release()
395 wake_up_interruptible_all(&sdp->open_wait); in sg_release()
396 } else if (0 == sdp->open_cnt) { in sg_release()
397 wake_up_interruptible(&sdp->open_wait); in sg_release()
399 mutex_unlock(&sdp->open_rel_lock); in sg_release()
439 Sg_device *sdp; in sg_read() local
456 if ((!(sfp = (Sg_fd *) filp->private_data)) || (!(sdp = sfp->parentdp))) in sg_read()
458 SCSI_LOG_TIMEOUT(3, sg_printk(KERN_INFO, sdp, in sg_read()
472 (!busy && atomic_read(&sdp->detaching)))); in sg_read()
600 Sg_device *sdp; in sg_write() local
612 if ((!(sfp = (Sg_fd *) filp->private_data)) || (!(sdp = sfp->parentdp))) in sg_write()
614 SCSI_LOG_TIMEOUT(3, sg_printk(KERN_INFO, sdp, in sg_write()
616 if (atomic_read(&sdp->detaching)) in sg_write()
619 scsi_block_when_processing_errors(sdp->device))) in sg_write()
638 SCSI_LOG_TIMEOUT(1, sg_printk(KERN_INFO, sdp, in sg_write()
652 SCSI_LOG_TIMEOUT(4, sg_printk(KERN_INFO, sdp, in sg_write()
779 Sg_device *sdp = sfp->parentdp; in sg_common_write() local
807 if (atomic_read(&sdp->detaching)) { in sg_common_write()
913 sg_ioctl_common(struct file *filp, Sg_device *sdp, Sg_fd *sfp, in sg_ioctl_common() argument
921 SCSI_LOG_TIMEOUT(3, sg_printk(KERN_INFO, sdp, in sg_ioctl_common()
927 if (atomic_read(&sdp->detaching)) in sg_ioctl_common()
929 if (!scsi_block_when_processing_errors(sdp->device)) in sg_ioctl_common()
976 if (atomic_read(&sdp->detaching)) in sg_ioctl_common()
979 v.host_no = sdp->device->host->host_no; in sg_ioctl_common()
980 v.channel = sdp->device->channel; in sg_ioctl_common()
981 v.scsi_id = sdp->device->id; in sg_ioctl_common()
982 v.lun = sdp->device->lun; in sg_ioctl_common()
983 v.scsi_type = sdp->device->type; in sg_ioctl_common()
984 v.h_cmd_per_lun = sdp->device->host->cmd_per_lun; in sg_ioctl_common()
985 v.d_queue_depth = sdp->device->queue_depth; in sg_ioctl_common()
1017 return put_user(sdp->sg_tablesize, ip); in sg_ioctl_common()
1025 max_sectors_bytes(sdp->device->request_queue)); in sg_ioctl_common()
1041 max_sectors_bytes(sdp->device->request_queue)); in sg_ioctl_common()
1071 val = (sdp->device ? 1 : 0); in sg_ioctl_common()
1096 if (atomic_read(&sdp->detaching)) in sg_ioctl_common()
1098 return put_user(sdp->device->host->hostt->emulated, ip); in sg_ioctl_common()
1100 if (atomic_read(&sdp->detaching)) in sg_ioctl_common()
1102 return scsi_ioctl(sdp->device, filp->f_mode & FMODE_WRITE, in sg_ioctl_common()
1108 sdp->sgdebug = (char) val; in sg_ioctl_common()
1111 return put_user(max_sectors_bytes(sdp->device->request_queue), in sg_ioctl_common()
1114 return blk_trace_setup(sdp->device->request_queue, sdp->name, in sg_ioctl_common()
1115 MKDEV(SCSI_GENERIC_MAJOR, sdp->index), in sg_ioctl_common()
1118 return blk_trace_startstop(sdp->device->request_queue, 1); in sg_ioctl_common()
1120 return blk_trace_startstop(sdp->device->request_queue, 0); in sg_ioctl_common()
1122 return blk_trace_remove(sdp->device->request_queue); in sg_ioctl_common()
1128 if (atomic_read(&sdp->detaching)) in sg_ioctl_common()
1137 result = scsi_ioctl_block_when_processing_errors(sdp->device, in sg_ioctl_common()
1149 Sg_device *sdp; in sg_ioctl() local
1153 if ((!(sfp = (Sg_fd *) filp->private_data)) || (!(sdp = sfp->parentdp))) in sg_ioctl()
1156 ret = sg_ioctl_common(filp, sdp, sfp, cmd_in, p); in sg_ioctl()
1159 return scsi_ioctl(sdp->device, filp->f_mode & FMODE_WRITE, cmd_in, p); in sg_ioctl()
1166 Sg_device *sdp; in sg_poll() local
1175 sdp = sfp->parentdp; in sg_poll()
1176 if (!sdp) in sg_poll()
1188 if (atomic_read(&sdp->detaching)) in sg_poll()
1195 SCSI_LOG_TIMEOUT(3, sg_printk(KERN_INFO, sdp, in sg_poll()
1203 Sg_device *sdp; in sg_fasync() local
1206 if ((!(sfp = (Sg_fd *) filp->private_data)) || (!(sdp = sfp->parentdp))) in sg_fasync()
1208 SCSI_LOG_TIMEOUT(3, sg_printk(KERN_INFO, sdp, in sg_fasync()
1316 Sg_device *sdp; in sg_rq_end_io() local
1330 sdp = sfp->parentdp; in sg_rq_end_io()
1331 if (unlikely(atomic_read(&sdp->detaching))) in sg_rq_end_io()
1338 SCSI_LOG_TIMEOUT(4, sg_printk(KERN_INFO, sdp, in sg_rq_end_io()
1353 if ((sdp->sgdebug > 0) && in sg_rq_end_io()
1356 __scsi_print_sense(sdp->device, __func__, sense, in sg_rq_end_io()
1364 && sdp->device->removable) { in sg_rq_end_io()
1367 sdp->device->changed = 1; in sg_rq_end_io()
1431 Sg_device *sdp; in sg_alloc() local
1436 sdp = kzalloc(sizeof(Sg_device), GFP_KERNEL); in sg_alloc()
1437 if (!sdp) { in sg_alloc()
1446 error = idr_alloc(&sg_index_idr, sdp, 0, SG_MAX_DEVS, GFP_NOWAIT); in sg_alloc()
1464 sprintf(sdp->name, "sg%d", k); in sg_alloc()
1465 sdp->device = scsidp; in sg_alloc()
1466 mutex_init(&sdp->open_rel_lock); in sg_alloc()
1467 INIT_LIST_HEAD(&sdp->sfds); in sg_alloc()
1468 init_waitqueue_head(&sdp->open_wait); in sg_alloc()
1469 atomic_set(&sdp->detaching, 0); in sg_alloc()
1470 rwlock_init(&sdp->sfd_lock); in sg_alloc()
1471 sdp->sg_tablesize = queue_max_segments(q); in sg_alloc()
1472 sdp->index = k; in sg_alloc()
1473 kref_init(&sdp->d_ref); in sg_alloc()
1481 kfree(sdp); in sg_alloc()
1484 return sdp; in sg_alloc()
1491 Sg_device *sdp = NULL; in sg_add_device() local
1510 sdp = sg_alloc(scsidp); in sg_add_device()
1511 if (IS_ERR(sdp)) { in sg_add_device()
1513 error = PTR_ERR(sdp); in sg_add_device()
1517 error = cdev_add(cdev, MKDEV(SCSI_GENERIC_MAJOR, sdp->index), 1); in sg_add_device()
1521 sdp->cdev = cdev; in sg_add_device()
1527 sdp->index), in sg_add_device()
1528 sdp, "%s", sdp->name); in sg_add_device()
1538 "to sg%d\n", __func__, sdp->index); in sg_add_device()
1543 "type %d\n", sdp->index, scsidp->type); in sg_add_device()
1545 dev_set_drvdata(cl_dev, sdp); in sg_add_device()
1551 idr_remove(&sg_index_idr, sdp->index); in sg_add_device()
1553 kfree(sdp); in sg_add_device()
1565 struct sg_device *sdp = container_of(kref, struct sg_device, d_ref); in sg_device_destroy() local
1566 struct request_queue *q = sdp->device->request_queue; in sg_device_destroy()
1578 idr_remove(&sg_index_idr, sdp->index); in sg_device_destroy()
1582 sg_printk(KERN_INFO, sdp, "sg_device_destroy\n")); in sg_device_destroy()
1584 kfree(sdp); in sg_device_destroy()
1591 Sg_device *sdp = dev_get_drvdata(cl_dev); in sg_remove_device() local
1596 if (!sdp) in sg_remove_device()
1598 /* want sdp->detaching non-zero as soon as possible */ in sg_remove_device()
1599 val = atomic_inc_return(&sdp->detaching); in sg_remove_device()
1603 SCSI_LOG_TIMEOUT(3, sg_printk(KERN_INFO, sdp, in sg_remove_device()
1606 read_lock_irqsave(&sdp->sfd_lock, iflags); in sg_remove_device()
1607 list_for_each_entry(sfp, &sdp->sfds, sfd_siblings) { in sg_remove_device()
1611 wake_up_interruptible_all(&sdp->open_wait); in sg_remove_device()
1612 read_unlock_irqrestore(&sdp->sfd_lock, iflags); in sg_remove_device()
1615 device_destroy(sg_sysfs_class, MKDEV(SCSI_GENERIC_MAJOR, sdp->index)); in sg_remove_device()
1616 cdev_del(sdp->cdev); in sg_remove_device()
1617 sdp->cdev = NULL; in sg_remove_device()
1619 kref_put(&sdp->d_ref, sg_device_destroy); in sg_remove_device()
2155 sg_add_sfp(Sg_device * sdp) in sg_add_sfp() argument
2175 sfp->parentdp = sdp; in sg_add_sfp()
2176 write_lock_irqsave(&sdp->sfd_lock, iflags); in sg_add_sfp()
2177 if (atomic_read(&sdp->detaching)) { in sg_add_sfp()
2178 write_unlock_irqrestore(&sdp->sfd_lock, iflags); in sg_add_sfp()
2182 list_add_tail(&sfp->sfd_siblings, &sdp->sfds); in sg_add_sfp()
2183 write_unlock_irqrestore(&sdp->sfd_lock, iflags); in sg_add_sfp()
2184 SCSI_LOG_TIMEOUT(3, sg_printk(KERN_INFO, sdp, in sg_add_sfp()
2190 max_sectors_bytes(sdp->device->request_queue)); in sg_add_sfp()
2192 SCSI_LOG_TIMEOUT(3, sg_printk(KERN_INFO, sdp, in sg_add_sfp()
2197 kref_get(&sdp->d_ref); in sg_add_sfp()
2206 struct sg_device *sdp = sfp->parentdp; in sg_remove_sfp_usercontext() local
2207 struct scsi_device *device = sdp->device; in sg_remove_sfp_usercontext()
2222 SCSI_LOG_TIMEOUT(6, sg_printk(KERN_INFO, sdp, in sg_remove_sfp_usercontext()
2229 SCSI_LOG_TIMEOUT(6, sg_printk(KERN_INFO, sdp, in sg_remove_sfp_usercontext()
2233 kref_put(&sdp->d_ref, sg_device_destroy); in sg_remove_sfp_usercontext()
2242 struct sg_device *sdp = sfp->parentdp; in sg_remove_sfp() local
2245 write_lock_irqsave(&sdp->sfd_lock, iflags); in sg_remove_sfp()
2247 write_unlock_irqrestore(&sdp->sfd_lock, iflags); in sg_remove_sfp()
2287 struct sg_device *sdp; in sg_get_dev() local
2291 sdp = sg_lookup_dev(dev); in sg_get_dev()
2292 if (!sdp) in sg_get_dev()
2293 sdp = ERR_PTR(-ENXIO); in sg_get_dev()
2294 else if (atomic_read(&sdp->detaching)) { in sg_get_dev()
2295 /* If sdp->detaching, then the refcount may already be 0, in in sg_get_dev()
2298 sdp = ERR_PTR(-ENODEV); in sg_get_dev()
2300 kref_get(&sdp->d_ref); in sg_get_dev()
2303 return sdp; in sg_get_dev()
2481 Sg_device *sdp; in sg_proc_seq_show_dev() local
2486 sdp = it ? sg_lookup_dev(it->index) : NULL; in sg_proc_seq_show_dev()
2487 if ((NULL == sdp) || (NULL == sdp->device) || in sg_proc_seq_show_dev()
2488 (atomic_read(&sdp->detaching))) in sg_proc_seq_show_dev()
2491 scsidp = sdp->device; in sg_proc_seq_show_dev()
2507 Sg_device *sdp; in sg_proc_seq_show_devstrs() local
2512 sdp = it ? sg_lookup_dev(it->index) : NULL; in sg_proc_seq_show_devstrs()
2513 scsidp = sdp ? sdp->device : NULL; in sg_proc_seq_show_devstrs()
2514 if (sdp && scsidp && (!atomic_read(&sdp->detaching))) in sg_proc_seq_show_devstrs()
2524 static void sg_proc_debug_helper(struct seq_file *s, Sg_device * sdp) in sg_proc_debug_helper() argument
2534 list_for_each_entry(fp, &sdp->sfds, sfd_siblings) { in sg_proc_debug_helper()
2589 Sg_device *sdp; in sg_proc_seq_show_debug() local
2597 sdp = it ? sg_lookup_dev(it->index) : NULL; in sg_proc_seq_show_debug()
2598 if (NULL == sdp) in sg_proc_seq_show_debug()
2600 read_lock(&sdp->sfd_lock); in sg_proc_seq_show_debug()
2601 if (!list_empty(&sdp->sfds)) { in sg_proc_seq_show_debug()
2602 seq_printf(s, " >>> device=%s ", sdp->name); in sg_proc_seq_show_debug()
2603 if (atomic_read(&sdp->detaching)) in sg_proc_seq_show_debug()
2605 else if (sdp->device) { in sg_proc_seq_show_debug()
2606 struct scsi_device *scsidp = sdp->device; in sg_proc_seq_show_debug()
2615 sdp->sg_tablesize, sdp->exclude, sdp->open_cnt); in sg_proc_seq_show_debug()
2616 sg_proc_debug_helper(s, sdp); in sg_proc_seq_show_debug()
2618 read_unlock(&sdp->sfd_lock); in sg_proc_seq_show_debug()