From: <vl...@us...> - 2007-01-12 15:42:50
|
Revision: 77 http://svn.sourceforge.net/scst/?rev=77&view=rev Author: vlnb Date: 2007-01-12 07:42:31 -0800 (Fri, 12 Jan 2007) Log Message: ----------- Some cleanup Modified Paths: -------------- trunk/scst/src/dev_handlers/scst_fileio.c trunk/scst/src/scst.c trunk/scst/src/scst_proc.c Modified: trunk/scst/src/dev_handlers/scst_fileio.c =================================================================== --- trunk/scst/src/dev_handlers/scst_fileio.c 2007-01-11 12:46:22 UTC (rev 76) +++ trunk/scst/src/dev_handlers/scst_fileio.c 2007-01-12 15:42:31 UTC (rev 77) @@ -178,7 +178,7 @@ write_proc: cdrom_fileio_write_proc,\ } -DECLARE_MUTEX(scst_fileio_mutex); +static DECLARE_MUTEX(scst_fileio_mutex); static LIST_HEAD(disk_fileio_dev_list); static LIST_HEAD(cdrom_fileio_dev_list); Modified: trunk/scst/src/scst.c =================================================================== --- trunk/scst/src/scst.c 2007-01-11 12:46:22 UTC (rev 76) +++ trunk/scst/src/scst.c 2007-01-12 15:42:31 UTC (rev 77) @@ -125,32 +125,31 @@ PRINT_ERROR_PR("Target driver %s doesn't have a " "detect() method.", vtt->name); res = -EINVAL; - goto out; + goto out_err; } if (!vtt->release) { PRINT_ERROR_PR("Target driver %s doesn't have a " "release() method.", vtt->name); res = -EINVAL; - goto out; + goto out_err; } if (!vtt->xmit_response) { PRINT_ERROR_PR("Target driver %s doesn't have a " "xmit_response() method.", vtt->name); res = -EINVAL; - goto out; + goto out_err; } if (!vtt->no_proc_entry) { res = scst_build_proc_target_dir_entries(vtt); - if (res < 0) { - goto out; - } + if (res < 0) + goto out_err; } if (down_interruptible(&m) != 0) - goto out; + goto out_err; if (down_interruptible(&scst_mutex) != 0) goto out_m_up; @@ -179,32 +178,58 @@ res = 0; -out_m_up: + PRINT_INFO_PR("Target template %s registered successfully", vtt->name); + up(&m); out: TRACE_EXIT_RES(res); return res; +out_m_up: + up(&m); + out_cleanup: scst_cleanup_proc_target_dir_entries(vtt); + +out_err: + PRINT_ERROR_PR("Failed to register target template %s", vtt->name); goto out; } void scst_unregister_target_template(struct scst_tgt_template *vtt) { struct scst_tgt *tgt; + struct scst_tgt_template *t; + int found = 0; TRACE_ENTRY(); + down(&scst_mutex); + + list_for_each_entry(t, &scst_template_list, scst_template_list_entry) { + if (strcmp(t->name, vtt->name) == 0) { + found = 1; + break; + } + } + if (!found) { + PRINT_ERROR_PR("Target driver %s isn't registered", vtt->name); + goto out_up; + } + restart: - down(&scst_mutex); list_for_each_entry(tgt, &vtt->tgt_list, tgt_list_entry) { up(&scst_mutex); scst_unregister(tgt); + down(&scst_mutex); goto restart; } list_del(&vtt->scst_template_list_entry); + + PRINT_INFO_PR("Target template %s unregistered successfully", vtt->name); + +out_up: up(&scst_mutex); scst_cleanup_proc_target_dir_entries(vtt); @@ -222,7 +247,7 @@ tgt = kzalloc(sizeof(*tgt), GFP_KERNEL); if (tgt == NULL) { TRACE(TRACE_OUT_OF_MEM, "%s", "kzalloc() failed"); - goto out; + goto out_err; } INIT_LIST_HEAD(&tgt->sess_list); @@ -241,14 +266,25 @@ if (scst_build_proc_target_entries(tgt) < 0) { kfree(tgt); tgt = NULL; + goto out_up; } else list_add_tail(&tgt->tgt_list_entry, &vtt->tgt_list); up(&scst_mutex); + PRINT_INFO_PR("Target for template %s registered successfully", + vtt->name); + out: TRACE_EXIT(); return tgt; + +out_up: + up(&scst_mutex); + +out_err: + PRINT_ERROR_PR("Failed to register target for template %s", vtt->name); + goto out; } static inline int test_sess_list(struct scst_tgt *tgt) @@ -263,6 +299,7 @@ void scst_unregister(struct scst_tgt *tgt) { struct scst_session *sess; + struct scst_tgt_template *vtt = tgt->tgtt; TRACE_ENTRY(); @@ -290,6 +327,9 @@ kfree(tgt); + PRINT_INFO_PR("Target for template %s unregistered successfully", + vtt->name); + TRACE_EXIT(); return; } @@ -377,8 +417,7 @@ dev->rq_disk = alloc_disk(1); if (dev->rq_disk == NULL) { res = -ENOMEM; - scst_free_device(dev); - goto out; + goto out_free_dev; } dev->rq_disk->major = SCST_MAJOR; @@ -413,10 +452,11 @@ return res; out_free: + list_del(&dev->dev_list_entry); put_disk(dev->rq_disk); - list_del(&dev->dev_list_entry); - scst_assign_dev_handler(dev, NULL); +out_free_dev: + scst_free_device(dev); goto out; } @@ -437,7 +477,6 @@ break; } } - if (dev == NULL) { PRINT_ERROR_PR("%s", "Target device not found"); goto out_unblock; @@ -456,13 +495,13 @@ put_disk(dev->rq_disk); scst_free_device(dev); + PRINT_INFO_PR("Detached SCSI target mid-level from scsi%d, channel %d, " + "id %d, lun %d, type %d", scsidp->host->host_no, + scsidp->channel, scsidp->id, scsidp->lun, scsidp->type); + out_unblock: __scst_resume_activity(); - PRINT_INFO_PR("Detached SCSI target mid-level from scsi%d, channel %d, " - "id %d, lun %d, type %d", scsidp->host->host_no, scsidp->channel, - scsidp->id, scsidp->lun, scsidp->type); - TRACE_EXIT(); return; } @@ -545,8 +584,7 @@ TRACE_ENTRY(); - if (down_interruptible(&scst_mutex) != 0) - goto out; + down(&scst_mutex); __scst_suspend_activity(); @@ -557,7 +595,6 @@ break; } } - if (dev == NULL) { PRINT_ERROR_PR("%s", "Target device not found"); goto out_unblock; @@ -583,7 +620,6 @@ up(&scst_mutex); -out: TRACE_EXIT(); return; } @@ -601,7 +637,7 @@ PRINT_ERROR_PR("scst dev_type driver %s doesn't have a " "parse() method.", dev_type->name); res = -EINVAL; - goto out; + goto out_err; } #ifdef FILEIO_ONLY @@ -610,25 +646,24 @@ "supported. Recompile SCST with undefined FILEIO_ONLY", dev_type->name); res = -EINVAL; - goto out; + goto out_err; } #endif if (down_interruptible(&scst_mutex) != 0) { res = -EINTR; - goto out; + goto out_err; } exist = 0; list_for_each_entry(dt, &scst_dev_type_list, dev_type_list_entry) { - if (dt->type == dev_type->type) { - TRACE_DBG("Device type handler for type %d " - "already exist", dt->type); + if (strcmp(dt->name, dev_type->name) == 0) { + PRINT_ERROR_PR("Device type handler %s already exist", + dt->name); exist = 1; break; } } - if (exist) goto out_up; @@ -636,39 +671,60 @@ if (res < 0) { goto out_up; } - + list_add_tail(&dev_type->dev_type_list_entry, &scst_dev_type_list); __scst_suspend_activity(); list_for_each_entry(dev, &scst_dev_list, dev_list_entry) { - if (dev->scsi_dev == NULL) + if ((dev->scsi_dev == NULL) || (dev->handler != NULL)) continue; if (dev->scsi_dev->type == dev_type->type) scst_assign_dev_handler(dev, dev_type); } __scst_resume_activity(); -out_up: up(&scst_mutex); if (res == 0) { - PRINT_INFO_PR("Device handler %s for type %d loaded " + PRINT_INFO_PR("Device handler %s for type %d registered " "successfully", dev_type->name, dev_type->type); } out: TRACE_EXIT_RES(res); return res; + +out_up: + up(&scst_mutex); + +out_err: + PRINT_ERROR_PR("Failed to register device handler %s for type %d", + dev_type->name, dev_type->type); + goto out; } void scst_unregister_dev_driver(struct scst_dev_type *dev_type) { struct scst_device *dev; + struct scst_dev_type *dt; + int found = 0; TRACE_ENTRY(); down(&scst_mutex); + list_for_each_entry(dt, &scst_dev_type_list, dev_type_list_entry) { + if (strcmp(dt->name, dev_type->name) == 0) { + found = 1; + break; + } + } + if (!found) { + PRINT_ERROR_PR("Dev handler %s isn't registered", + dev_type->name); + goto out_up; + } + __scst_suspend_activity(); list_for_each_entry(dev, &scst_dev_list, dev_list_entry) { if (dev->handler == dev_type) { @@ -687,8 +743,13 @@ PRINT_INFO_PR("Device handler %s for type %d unloaded", dev_type->name, dev_type->type); +out: TRACE_EXIT(); return; + +out_up: + up(&scst_mutex); + goto out; } int scst_register_virtual_dev_driver(struct scst_dev_type *dev_type) @@ -701,20 +762,24 @@ PRINT_ERROR_PR("scst dev_type driver %s doesn't have a " "parse() method.", dev_type->name); res = -EINVAL; - goto out; + goto out_err; } res = scst_build_proc_dev_handler_dir_entries(dev_type); - if (res < 0) { - goto out; - } + if (res < 0) + goto out_err; - PRINT_INFO_PR("Device handler %s for type %d loaded " + PRINT_INFO_PR("Virtuel device handler %s for type %d registered " "successfully", dev_type->name, dev_type->type); out: TRACE_EXIT_RES(res); return res; + +out_err: + PRINT_ERROR_PR("Failed to register virtual device handler %s for " + "type %d", dev_type->name, dev_type->type); + goto out; } void scst_unregister_virtual_dev_driver(struct scst_dev_type *dev_type) Modified: trunk/scst/src/scst_proc.c =================================================================== --- trunk/scst/src/scst_proc.c 2007-01-11 12:46:22 UTC (rev 76) +++ trunk/scst/src/scst_proc.c 2007-01-12 15:42:31 UTC (rev 77) @@ -834,6 +834,7 @@ return; } +/* Called under scst_mutex */ int scst_build_proc_target_entries(struct scst_tgt *vtt) { int res = 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |