From: <vl...@us...> - 2007-07-30 11:23:08
|
Revision: 153 http://scst.svn.sourceforge.net/scst/?rev=153&view=rev Author: vlnb Date: 2007-07-30 04:21:04 -0700 (Mon, 30 Jul 2007) Log Message: ----------- - Semaphores converted to mutexes - pre_exec() callback added - *_DBG_SPECIAL() macroses added Modified Paths: -------------- trunk/scst/include/scsi_tgt.h trunk/scst/include/scst_debug.h trunk/scst/src/dev_handlers/scst_vdisk.c trunk/scst/src/scst.c trunk/scst/src/scst_lib.c trunk/scst/src/scst_mem.c trunk/scst/src/scst_mem.h trunk/scst/src/scst_priv.h trunk/scst/src/scst_proc.c trunk/scst/src/scst_targ.c Modified: trunk/scst/include/scsi_tgt.h =================================================================== --- trunk/scst/include/scsi_tgt.h 2007-07-23 11:51:05 UTC (rev 152) +++ trunk/scst/include/scsi_tgt.h 2007-07-30 11:21:04 UTC (rev 153) @@ -522,6 +522,22 @@ void (*preprocessing_done) (struct scst_cmd *cmd); /* + * This function informs the driver that the said command is about + * to be executed. + * + * Returns one of the SCST_PREPROCESS_* constants. + * + * This command is expected to be NON-BLOCKING. + * + * Pay attention to "atomic" attribute of the cmd, which can be get + * by scst_cmd_atomic(): it is true if the function called in the + * atomic (non-sleeping) context. + * + * OPTIONAL + */ + int (*pre_exec) (struct scst_cmd *cmd); + + /* * This function informs the driver that a * received task management function has been completed. This * function is necessary because low-level protocols have some Modified: trunk/scst/include/scst_debug.h =================================================================== --- trunk/scst/include/scst_debug.h 2007-07-23 11:51:05 UTC (rev 152) +++ trunk/scst/include/scst_debug.h 2007-07-30 11:21:04 UTC (rev 153) @@ -220,6 +220,19 @@ } \ } while(0) +#define TRACE_DBG_SPECIAL(format, args...) \ +do { \ + if (trace_flag & (TRACE_DEBUG|TRACE_SPECIAL)) \ + { \ + char *__tflag = LOG_FLAG; \ + if (debug_print_prefix(trace_flag, __FUNCTION__, __LINE__) > 0) \ + { \ + __tflag = NO_FLAG; \ + } \ + PRINT(NO_FLAG, "%s" format, __tflag, args); \ + } \ +} while(0) + #define TRACE_MGMT_DBG(format, args...) \ do { \ if (trace_flag & TRACE_MGMT_DEBUG) \ @@ -233,6 +246,19 @@ } \ } while(0) +#define TRACE_MGMT_DBG_SPECIAL(format, args...) \ +do { \ + if (trace_flag & (TRACE_MGMT_DEBUG|TRACE_SPECIAL)) \ + { \ + char *__tflag = LOG_FLAG; \ + if (debug_print_prefix(trace_flag, __FUNCTION__, __LINE__) > 0) \ + { \ + __tflag = NO_FLAG; \ + } \ + PRINT(NO_FLAG, "%s" format, __tflag, args); \ + } \ +} while(0) + #define PRINT_ERROR_PR(format, args...) \ do { \ if (ERROR_FLAG != LOG_FLAG) \ @@ -341,7 +367,9 @@ #define TRACE_MEM(format, args...) {} #define TRACE_DBG(format, args...) {} +#define TRACE_DBG_SPECIAL(format, args...) {} #define TRACE_MGMT_DBG(format, args...) {} +#define TRACE_MGMT_DBG_SPECIAL(format, args...) {} #define TRACE_ENTRY() {} #define TRACE_EXIT() {} #define TRACE_EXIT_RES(res) {} Modified: trunk/scst/src/dev_handlers/scst_vdisk.c =================================================================== --- trunk/scst/src/dev_handlers/scst_vdisk.c 2007-07-23 11:51:05 UTC (rev 152) +++ trunk/scst/src/dev_handlers/scst_vdisk.c 2007-07-30 11:21:04 UTC (rev 153) @@ -293,7 +293,7 @@ write_proc: vcdrom_write_proc, \ } -static DECLARE_MUTEX(scst_vdisk_mutex); +static DEFINE_MUTEX(scst_vdisk_mutex); static LIST_HEAD(vdisk_dev_list); static LIST_HEAD(vcdrom_dev_list); @@ -2356,7 +2356,7 @@ TRACE_ENTRY(); - if (down_interruptible(&scst_vdisk_mutex) != 0) { + if (mutex_lock_interruptible(&scst_vdisk_mutex) != 0) { res = -EINTR; goto out; } @@ -2400,7 +2400,7 @@ } seq_printf(seq, "%s\n", virt_dev->file_name); } - up(&scst_vdisk_mutex); + mutex_unlock(&scst_vdisk_mutex); out: TRACE_EXIT_RES(res); return res; @@ -2426,7 +2426,7 @@ if (buffer[0] == '\0') goto out; - if (down_interruptible(&scst_vdisk_mutex) != 0) { + if (mutex_lock_interruptible(&scst_vdisk_mutex) != 0) { res = -EINTR; goto out; } @@ -2632,7 +2632,7 @@ res = length; out_up: - up(&scst_vdisk_mutex); + mutex_unlock(&scst_vdisk_mutex); out: TRACE_EXIT_RES(res); @@ -2932,7 +2932,7 @@ TRACE_ENTRY(); - if (down_interruptible(&scst_vdisk_mutex) != 0) { + if (mutex_lock_interruptible(&scst_vdisk_mutex) != 0) { res = -EINTR; goto out; } @@ -2946,7 +2946,7 @@ virt_dev->file_name); } - up(&scst_vdisk_mutex); + mutex_unlock(&scst_vdisk_mutex); out: TRACE_EXIT_RES(res); @@ -2965,7 +2965,7 @@ TRACE_ENTRY(); - if (down_interruptible(&scst_vdisk_mutex) != 0) { + if (mutex_lock_interruptible(&scst_vdisk_mutex) != 0) { res = -EINTR; goto out; } @@ -3022,7 +3022,7 @@ res = length; out_up: - up(&scst_vdisk_mutex); + mutex_unlock(&scst_vdisk_mutex); out: TRACE_EXIT_RES(res); @@ -3122,7 +3122,7 @@ { TRACE_ENTRY(); - down(&scst_vdisk_mutex); + mutex_lock(&scst_vdisk_mutex); while (1) { struct scst_vdisk_dev *virt_dev; @@ -3141,7 +3141,7 @@ kfree(virt_dev->file_name); kfree(virt_dev); } - up(&scst_vdisk_mutex); + mutex_unlock(&scst_vdisk_mutex); if (!devtype->no_proc) { vdisk_proc_help_destroy(devtype); Modified: trunk/scst/src/scst.c =================================================================== --- trunk/scst/src/scst.c 2007-07-23 11:51:05 UTC (rev 152) +++ trunk/scst/src/scst.c 2007-07-30 11:21:04 UTC (rev 153) @@ -53,7 +53,7 @@ #endif /* All targets, devices and dev_types management is done under this mutex */ -DECLARE_MUTEX(scst_mutex); +DEFINE_MUTEX(scst_mutex); LIST_HEAD(scst_template_list); LIST_HEAD(scst_dev_list); @@ -113,7 +113,7 @@ DECLARE_WAIT_QUEUE_HEAD(scst_dev_cmd_waitQ); -DECLARE_MUTEX(scst_suspend_mutex); +DEFINE_MUTEX(scst_suspend_mutex); LIST_HEAD(scst_cmd_lists_list); /* protected by scst_suspend_mutex */ static int scst_threads; @@ -141,7 +141,7 @@ { int res = 0; struct scst_tgt_template *t; - static DECLARE_MUTEX(m); + static DEFINE_MUTEX(m); TRACE_ENTRY(); @@ -185,20 +185,20 @@ if (vtt->preprocessing_done == NULL) vtt->preprocessing_done_atomic = 1; - if (down_interruptible(&m) != 0) + if (mutex_lock_interruptible(&m) != 0) goto out_err; - if (down_interruptible(&scst_mutex) != 0) + if (mutex_lock_interruptible(&scst_mutex) != 0) goto out_m_up; list_for_each_entry(t, &scst_template_list, scst_template_list_entry) { if (strcmp(t->name, vtt->name) == 0) { PRINT_ERROR_PR("Target driver %s already registered", vtt->name); - up(&scst_mutex); + mutex_unlock(&scst_mutex); goto out_cleanup; } } - up(&scst_mutex); + mutex_unlock(&scst_mutex); TRACE_DBG("%s", "Calling target driver's detect()"); res = vtt->detect(vtt); @@ -209,22 +209,22 @@ goto out_cleanup; } - down(&scst_mutex); + mutex_lock(&scst_mutex); list_add_tail(&vtt->scst_template_list_entry, &scst_template_list); - up(&scst_mutex); + mutex_unlock(&scst_mutex); res = 0; PRINT_INFO_PR("Target template %s registered successfully", vtt->name); - up(&m); + mutex_unlock(&m); out: TRACE_EXIT_RES(res); return res; out_m_up: - up(&m); + mutex_unlock(&m); out_cleanup: scst_cleanup_proc_target_dir_entries(vtt); @@ -242,7 +242,7 @@ TRACE_ENTRY(); - down(&scst_mutex); + mutex_lock(&scst_mutex); list_for_each_entry(t, &scst_template_list, scst_template_list_entry) { if (strcmp(t->name, vtt->name) == 0) { @@ -257,9 +257,9 @@ restart: list_for_each_entry(tgt, &vtt->tgt_list, tgt_list_entry) { - up(&scst_mutex); + mutex_unlock(&scst_mutex); scst_unregister(tgt); - down(&scst_mutex); + mutex_lock(&scst_mutex); goto restart; } list_del(&vtt->scst_template_list_entry); @@ -267,7 +267,7 @@ PRINT_INFO_PR("Target template %s unregistered successfully", vtt->name); out_up: - up(&scst_mutex); + mutex_unlock(&scst_mutex); scst_cleanup_proc_target_dir_entries(vtt); @@ -300,7 +300,7 @@ tgt->retry_timer.function = scst_tgt_retry_timer_fn; scst_suspend_activity(); - down(&scst_mutex); + mutex_lock(&scst_mutex); if (target_name != NULL) { int len = strlen(target_name) + 1 + @@ -321,7 +321,7 @@ else list_add_tail(&tgt->tgt_list_entry, &vtt->tgt_list); - up(&scst_mutex); + mutex_unlock(&scst_mutex); scst_resume_activity(); PRINT_INFO_PR("Target %s for template %s registered successfully", @@ -336,7 +336,7 @@ kfree(tgt->default_group_name); out_free_err: - up(&scst_mutex); + mutex_unlock(&scst_mutex); scst_resume_activity(); kfree(tgt); @@ -350,9 +350,9 @@ static inline int test_sess_list(struct scst_tgt *tgt) { int res; - down(&scst_mutex); + mutex_lock(&scst_mutex); res = list_empty(&tgt->sess_list); - up(&scst_mutex); + mutex_unlock(&scst_mutex); return res; } @@ -367,18 +367,18 @@ tgt->tgtt->release(tgt); TRACE_DBG("%s", "Target driver's release() returned"); - down(&scst_mutex); + mutex_lock(&scst_mutex); list_for_each_entry(sess, &tgt->sess_list, sess_list_entry) { sBUG_ON(!sess->shutting_down); } - up(&scst_mutex); + mutex_unlock(&scst_mutex); TRACE_DBG("%s", "Waiting for sessions shutdown"); wait_event(tgt->unreg_waitQ, test_sess_list(tgt)); TRACE_DBG("%s", "wait_event() returned"); scst_suspend_activity(); - down(&scst_mutex); + mutex_lock(&scst_mutex); list_del(&tgt->tgt_list_entry); @@ -387,7 +387,7 @@ if (tgt->default_group_name) kfree(tgt->default_group_name); - up(&scst_mutex); + mutex_unlock(&scst_mutex); scst_resume_activity(); del_timer_sync(&tgt->retry_timer); @@ -405,7 +405,7 @@ { TRACE_ENTRY(); - down(&scst_suspend_mutex); + mutex_lock(&scst_suspend_mutex); TRACE_MGMT_DBG("suspend_count %d", suspend_count); suspend_count++; @@ -430,7 +430,7 @@ TRACE_MGMT_DBG("%s", "wait_event() returned"); out_up: - up(&scst_suspend_mutex); + mutex_unlock(&scst_suspend_mutex); TRACE_EXIT(); return; @@ -442,7 +442,7 @@ TRACE_ENTRY(); - down(&scst_suspend_mutex); + mutex_lock(&scst_suspend_mutex); TRACE_MGMT_DBG("suspend_count %d", suspend_count); suspend_count--; @@ -470,7 +470,7 @@ wake_up_all(&scst_mgmt_cmd_list_waitQ); out_up: - up(&scst_suspend_mutex); + mutex_unlock(&scst_suspend_mutex); TRACE_EXIT(); return; @@ -485,7 +485,7 @@ TRACE_ENTRY(); scst_suspend_activity(); - down(&scst_mutex); + mutex_lock(&scst_mutex); res = scst_alloc_device(GFP_KERNEL, &dev); if (res != 0) @@ -514,7 +514,7 @@ } out_up: - up(&scst_mutex); + mutex_unlock(&scst_mutex); scst_resume_activity(); if (res == 0) { @@ -550,7 +550,7 @@ TRACE_ENTRY(); scst_suspend_activity(); - down(&scst_mutex); + mutex_lock(&scst_mutex); list_for_each_entry(d, &scst_dev_list, dev_list_entry) { if (d->scsi_dev == scsidp) { @@ -582,7 +582,7 @@ scsidp->channel, scsidp->id, scsidp->lun, scsidp->type); out_unblock: - up(&scst_mutex); + mutex_unlock(&scst_mutex); scst_resume_activity(); TRACE_EXIT(); @@ -637,7 +637,7 @@ goto out; scst_suspend_activity(); - if (down_interruptible(&scst_mutex) != 0) { + if (mutex_lock_interruptible(&scst_mutex) != 0) { res = -EINTR; goto out_resume; } @@ -662,7 +662,7 @@ } out_up: - up(&scst_mutex); + mutex_unlock(&scst_mutex); out_resume: scst_resume_activity(); @@ -694,7 +694,7 @@ TRACE_ENTRY(); scst_suspend_activity(); - down(&scst_mutex); + mutex_lock(&scst_mutex); list_for_each_entry(d, &scst_dev_list, dev_list_entry) { if (d->virt_id == id) { @@ -724,7 +724,7 @@ scst_free_device(dev); out_unblock: - up(&scst_mutex); + mutex_unlock(&scst_mutex); scst_resume_activity(); TRACE_EXIT(); @@ -756,7 +756,7 @@ #endif scst_suspend_activity(); - if (down_interruptible(&scst_mutex) != 0) { + if (mutex_lock_interruptible(&scst_mutex) != 0) { res = -EINTR; goto out_err; } @@ -787,7 +787,7 @@ scst_assign_dev_handler(dev, dev_type); } - up(&scst_mutex); + mutex_unlock(&scst_mutex); scst_resume_activity(); if (res == 0) { @@ -800,7 +800,7 @@ return res; out_up: - up(&scst_mutex); + mutex_unlock(&scst_mutex); out_err: scst_resume_activity(); @@ -818,7 +818,7 @@ TRACE_ENTRY(); scst_suspend_activity(); - down(&scst_mutex); + mutex_lock(&scst_mutex); list_for_each_entry(dt, &scst_dev_type_list, dev_type_list_entry) { if (strcmp(dt->name, dev_type->name) == 0) { @@ -841,7 +841,7 @@ list_del(&dev_type->dev_type_list_entry); - up(&scst_mutex); + mutex_unlock(&scst_mutex); scst_resume_activity(); scst_cleanup_proc_dev_handler_dir_entries(dev_type); @@ -854,7 +854,7 @@ return; out_up: - up(&scst_mutex); + mutex_unlock(&scst_mutex); scst_resume_activity(); goto out; } @@ -967,10 +967,10 @@ if (res != 0) goto out; - down(&scst_suspend_mutex); + mutex_lock(&scst_suspend_mutex); list_add_tail(&dev->cmd_lists.lists_list_entry, &scst_cmd_lists_list); - up(&scst_suspend_mutex); + mutex_unlock(&scst_suspend_mutex); dev->p_cmd_lists = &dev->cmd_lists; @@ -1014,9 +1014,9 @@ scst_del_dev_threads(dev, -1); if (dev->p_cmd_lists == &dev->cmd_lists) { - down(&scst_suspend_mutex); + mutex_lock(&scst_suspend_mutex); list_del(&dev->cmd_lists.lists_list_entry); - up(&scst_suspend_mutex); + mutex_unlock(&scst_suspend_mutex); } out: @@ -1127,16 +1127,16 @@ int i; /* Just to lower the race window, when user can get just changed value */ - down(&scst_threads_info.cmd_threads_mutex); + mutex_lock(&scst_threads_info.cmd_threads_mutex); i = scst_threads_info.nr_cmd_threads; - up(&scst_threads_info.cmd_threads_mutex); + mutex_unlock(&scst_threads_info.cmd_threads_mutex); return i; } static void scst_threads_info_init(void) { memset(&scst_threads_info, 0, sizeof(scst_threads_info)); - init_MUTEX(&scst_threads_info.cmd_threads_mutex); + mutex_init(&scst_threads_info.cmd_threads_mutex); INIT_LIST_HEAD(&scst_threads_info.cmd_threads_list); } @@ -1222,9 +1222,9 @@ TRACE_ENTRY(); - down(&scst_threads_info.cmd_threads_mutex); + mutex_lock(&scst_threads_info.cmd_threads_mutex); res = __scst_add_cmd_threads(num); - up(&scst_threads_info.cmd_threads_mutex); + mutex_unlock(&scst_threads_info.cmd_threads_mutex); TRACE_EXIT_RES(res); return res; @@ -1234,9 +1234,9 @@ { TRACE_ENTRY(); - down(&scst_threads_info.cmd_threads_mutex); + mutex_lock(&scst_threads_info.cmd_threads_mutex); __scst_del_cmd_threads(num); - up(&scst_threads_info.cmd_threads_mutex); + mutex_unlock(&scst_threads_info.cmd_threads_mutex); TRACE_EXIT(); return; @@ -1246,7 +1246,7 @@ { TRACE_ENTRY(); - down(&scst_threads_info.cmd_threads_mutex); + mutex_lock(&scst_threads_info.cmd_threads_mutex); __scst_del_cmd_threads(scst_threads_info.nr_cmd_threads); if (scst_threads_info.mgmt_cmd_thread) kthread_stop(scst_threads_info.mgmt_cmd_thread); @@ -1254,7 +1254,7 @@ kthread_stop(scst_threads_info.mgmt_thread); if (scst_threads_info.init_cmd_thread) kthread_stop(scst_threads_info.init_cmd_thread); - up(&scst_threads_info.cmd_threads_mutex); + mutex_unlock(&scst_threads_info.cmd_threads_mutex); TRACE_EXIT(); return; @@ -1266,7 +1266,7 @@ TRACE_ENTRY(); - down(&scst_threads_info.cmd_threads_mutex); + mutex_lock(&scst_threads_info.cmd_threads_mutex); res = __scst_add_cmd_threads(num); if (res < 0) goto out; @@ -1299,7 +1299,7 @@ } out: - up(&scst_threads_info.cmd_threads_mutex); + mutex_unlock(&scst_threads_info.cmd_threads_mutex); TRACE_EXIT_RES(res); return res; } Modified: trunk/scst/src/scst_lib.c =================================================================== --- trunk/scst/src/scst_lib.c 2007-07-23 11:51:05 UTC (rev 152) +++ trunk/scst/src/scst_lib.c 2007-07-30 11:21:04 UTC (rev 153) @@ -1085,7 +1085,7 @@ TRACE_ENTRY(); scst_suspend_activity(); - down(&scst_mutex); + mutex_lock(&scst_mutex); TRACE_DBG("Removing sess %p from the list", sess); list_del(&sess->sess_list_entry); @@ -1096,7 +1096,7 @@ wake_up_all(&sess->tgt->unreg_waitQ); - up(&scst_mutex); + mutex_unlock(&scst_mutex); scst_resume_activity(); kfree(sess->initiator_name); @@ -2599,14 +2599,14 @@ * suspending the activity isn't necessary. */ - down(&scst_mutex); + mutex_lock(&scst_mutex); list_for_each_entry(tgt_dev, &dev->dev_tgt_dev_list, dev_tgt_dev_list_entry) { scst_del_all_thr_data(tgt_dev); } - up(&scst_mutex); + mutex_unlock(&scst_mutex); TRACE_EXIT(); return; Modified: trunk/scst/src/scst_mem.c =================================================================== --- trunk/scst/src/scst_mem.c 2007-07-23 11:51:05 UTC (rev 152) +++ trunk/scst/src/scst_mem.c 2007-07-30 11:21:04 UTC (rev 153) @@ -65,7 +65,7 @@ atomic_t sgv_other_total_alloc; -DECLARE_MUTEX(scst_sgv_pool_mutex); +DEFINE_MUTEX(scst_sgv_pool_mutex); LIST_HEAD(scst_sgv_pool_list); static int scst_check_clustering(struct scatterlist *sg, int cur, int hint) @@ -643,9 +643,9 @@ } } - down(&scst_sgv_pool_mutex); + mutex_lock(&scst_sgv_pool_mutex); list_add_tail(&pool->sgv_pool_list_entry, &scst_sgv_pool_list); - up(&scst_sgv_pool_mutex); + mutex_unlock(&scst_sgv_pool_mutex); res = 0; @@ -676,9 +676,9 @@ pool->caches[i] = NULL; } - down(&scst_sgv_pool_mutex); + mutex_lock(&scst_sgv_pool_mutex); list_del(&pool->sgv_pool_list_entry); - up(&scst_sgv_pool_mutex); + mutex_unlock(&scst_sgv_pool_mutex); TRACE_EXIT(); } Modified: trunk/scst/src/scst_mem.h =================================================================== --- trunk/scst/src/scst_mem.h 2007-07-23 11:51:05 UTC (rev 152) +++ trunk/scst/src/scst_mem.h 2007-07-30 11:21:04 UTC (rev 153) @@ -86,7 +86,7 @@ }; extern atomic_t sgv_other_total_alloc; -extern struct semaphore scst_sgv_pool_mutex; +extern struct mutex scst_sgv_pool_mutex; extern struct list_head scst_sgv_pool_list; int sgv_pool_init(struct sgv_pool *pool, const char *name, Modified: trunk/scst/src/scst_priv.h =================================================================== --- trunk/scst/src/scst_priv.h 2007-07-23 11:51:05 UTC (rev 152) +++ trunk/scst/src/scst_priv.h 2007-07-30 11:21:04 UTC (rev 153) @@ -154,14 +154,14 @@ extern struct scst_sgv_pools scst_sgv; extern unsigned long scst_flags; -extern struct semaphore scst_mutex; +extern struct mutex scst_mutex; extern atomic_t scst_cmd_count; extern struct list_head scst_template_list; /* protected by scst_mutex */ extern struct list_head scst_dev_list; /* protected by scst_mutex */ extern struct list_head scst_dev_type_list; /* protected by scst_mutex */ extern wait_queue_head_t scst_dev_cmd_waitQ; -extern struct semaphore scst_suspend_mutex; +extern struct mutex scst_suspend_mutex; extern struct list_head scst_cmd_lists_list; /* protected by scst_suspend_mutex */ extern struct list_head scst_acg_list; @@ -206,7 +206,7 @@ }; struct scst_threads_info_t { - struct semaphore cmd_threads_mutex; + struct mutex cmd_threads_mutex; u32 nr_cmd_threads; struct list_head cmd_threads_list; struct task_struct *init_cmd_thread; Modified: trunk/scst/src/scst_proc.c =================================================================== --- trunk/scst/src/scst_proc.c 2007-07-23 11:51:05 UTC (rev 152) +++ trunk/scst/src/scst_proc.c 2007-07-30 11:21:04 UTC (rev 153) @@ -163,7 +163,7 @@ "Optical card reader/writer device" }; -static DECLARE_MUTEX(scst_proc_mutex); +static DEFINE_MUTEX(scst_proc_mutex); #include <linux/ctype.h> @@ -195,7 +195,7 @@ #if defined(DEBUG) || defined(TRACING) -static DECLARE_MUTEX(scst_log_mutex); +static DEFINE_MUTEX(scst_log_mutex); int scst_proc_log_entry_write(struct file *file, const char *buf, unsigned long length, unsigned long *log_level, @@ -358,7 +358,7 @@ TRACE_ENTRY(); - if (down_interruptible(&scst_log_mutex) != 0) { + if (mutex_lock_interruptible(&scst_log_mutex) != 0) { res = -EINTR; goto out; } @@ -366,7 +366,7 @@ res = scst_proc_log_entry_write(file, buf, length, &trace_flag, SCST_DEFAULT_LOG_FLAGS, scst_proc_local_trace_tbl); - up(&scst_log_mutex); + mutex_unlock(&scst_log_mutex); out: TRACE_EXIT_RES(res); @@ -769,12 +769,12 @@ goto out_free; } - if (down_interruptible(&scst_proc_mutex) != 0) { + if (mutex_lock_interruptible(&scst_proc_mutex) != 0) { res = -EINTR; goto out_free; } - down(&scst_threads_info.cmd_threads_mutex); + mutex_lock(&scst_threads_info.cmd_threads_mutex); oldtn = scst_threads_info.nr_cmd_threads; newtn = simple_strtoul(buffer, NULL, 0); @@ -792,9 +792,9 @@ PRINT_INFO_PR("Changed cmd threads num: old %d, new %d", oldtn, newtn); out_up_thr_free: - up(&scst_threads_info.cmd_threads_mutex); + mutex_unlock(&scst_threads_info.cmd_threads_mutex); - up(&scst_proc_mutex); + mutex_unlock(&scst_proc_mutex); out_free: free_page((unsigned long)buffer); @@ -925,14 +925,14 @@ TRACE_BUFFER("Buffer", buffer, length); - if (down_interruptible(&scst_proc_mutex) != 0) { + if (mutex_lock_interruptible(&scst_proc_mutex) != 0) { res = -EINTR; goto out_free; } res = vtt->tgtt->write_proc(buffer, &start, 0, length, &eof, vtt); - up(&scst_proc_mutex); + mutex_unlock(&scst_proc_mutex); out_free: free_page((unsigned long)buffer); @@ -1066,14 +1066,14 @@ TRACE_BUFFER("Buffer", buffer, length); - if (down_interruptible(&scst_proc_mutex) != 0) { + if (mutex_lock_interruptible(&scst_proc_mutex) != 0) { res = -EINTR; goto out_free; } res = dev_type->write_proc(buffer, &start, 0, length, &eof, dev_type); - up(&scst_proc_mutex); + mutex_unlock(&scst_proc_mutex); out_free: free_page((unsigned long)buffer); @@ -1142,7 +1142,7 @@ scst_suspend_activity(); - if (down_interruptible(&scst_mutex) != 0) { + if (mutex_lock_interruptible(&scst_mutex) != 0) { res = -EINTR; goto out_free_resume; } @@ -1192,7 +1192,7 @@ res = rc; out_up_free: - up(&scst_mutex); + mutex_unlock(&scst_mutex); out_free_resume: scst_resume_activity(); @@ -1366,7 +1366,7 @@ scst_suspend_activity(); - if (down_interruptible(&scst_mutex) != 0) { + if (mutex_lock_interruptible(&scst_mutex) != 0) { res = -EINTR; goto out_free_resume; } @@ -1486,7 +1486,7 @@ } out_free_up: - up(&scst_mutex); + mutex_unlock(&scst_mutex); out_free_resume: scst_resume_activity(); @@ -1569,7 +1569,7 @@ break; } - if (down_interruptible(&scst_mutex) != 0) { + if (mutex_lock_interruptible(&scst_mutex) != 0) { res = -EINTR; goto out_free; } @@ -1591,7 +1591,7 @@ break; } - up(&scst_mutex); + mutex_unlock(&scst_mutex); out_free: free_page((unsigned long)buffer); @@ -1689,7 +1689,7 @@ TRACE_ENTRY(); - if (down_interruptible(&scst_mutex) != 0) { + if (mutex_lock_interruptible(&scst_mutex) != 0) { res = -EINTR; goto out; } @@ -1707,7 +1707,7 @@ } } - up(&scst_mutex); + mutex_unlock(&scst_mutex); out: TRACE_EXIT_RES(res); @@ -1747,11 +1747,11 @@ seq_printf(seq, "%-30s %-11s %-11s", "Name", "Hit", "Total"); - down(&scst_sgv_pool_mutex); + mutex_lock(&scst_sgv_pool_mutex); list_for_each_entry(pool, &scst_sgv_pool_list, sgv_pool_list_entry) { scst_do_sgv_read(seq, pool); } - up(&scst_sgv_pool_mutex); + mutex_unlock(&scst_sgv_pool_mutex); seq_printf(seq, "\n%-42s %-11d\n", "other", atomic_read(&sgv_other_total_alloc)); @@ -1772,7 +1772,7 @@ TRACE_ENTRY(); - if (down_interruptible(&scst_mutex) != 0) { + if (mutex_lock_interruptible(&scst_mutex) != 0) { res = -EINTR; goto out; } @@ -1781,7 +1781,7 @@ seq_printf(seq, "%s\n", name->name); } - up(&scst_mutex); + mutex_unlock(&scst_mutex); out: TRACE_EXIT_RES(res); @@ -1801,7 +1801,7 @@ TRACE_ENTRY(); - if (down_interruptible(&scst_mutex) != 0) { + if (mutex_lock_interruptible(&scst_mutex) != 0) { res = -EINTR; goto out; } @@ -1831,7 +1831,7 @@ acg_dev->rd_only_flag ? "RO" : ""); } } - up(&scst_mutex); + mutex_unlock(&scst_mutex); out: TRACE_EXIT_RES(res); @@ -1886,14 +1886,14 @@ TRACE_ENTRY(); - if (down_interruptible(&scst_log_mutex) != 0) { + if (mutex_lock_interruptible(&scst_log_mutex) != 0) { res = -EINTR; goto out; } res = scst_proc_log_entry_read(seq, trace_flag, scst_proc_local_trace_tbl); - up(&scst_log_mutex); + mutex_unlock(&scst_log_mutex); out: TRACE_EXIT_RES(res); @@ -1915,7 +1915,7 @@ TRACE_ENTRY(); - if (down_interruptible(&scst_mutex) != 0) { + if (mutex_lock_interruptible(&scst_mutex) != 0) { res = -EINTR; goto out; } @@ -1937,7 +1937,7 @@ seq_printf(seq, "%-60s%s\n", dev->virt_name, dev->handler->name); } - up(&scst_mutex); + mutex_unlock(&scst_mutex); out: TRACE_EXIT_RES(res); @@ -1971,7 +1971,7 @@ TRACE_ENTRY(); - if (down_interruptible(&scst_proc_mutex) != 0) { + if (mutex_lock_interruptible(&scst_proc_mutex) != 0) { res = -EINTR; goto out; } @@ -1979,7 +1979,7 @@ if (vtt->tgtt->read_proc) res = vtt->tgtt->read_proc(seq, vtt); - up(&scst_proc_mutex); + mutex_unlock(&scst_proc_mutex); out: TRACE_EXIT_RES(res); return res; @@ -1997,7 +1997,7 @@ TRACE_ENTRY(); - if (down_interruptible(&scst_proc_mutex) != 0) { + if (mutex_lock_interruptible(&scst_proc_mutex) != 0) { res = -EINTR; goto out; } @@ -2005,7 +2005,7 @@ if (dev_type->read_proc) res = dev_type->read_proc(seq, dev_type); - up(&scst_proc_mutex); + mutex_unlock(&scst_proc_mutex); out: TRACE_EXIT_RES(res); Modified: trunk/scst/src/scst_targ.c =================================================================== --- trunk/scst/src/scst_targ.c 2007-07-23 11:51:05 UTC (rev 152) +++ trunk/scst/src/scst_targ.c 2007-07-30 11:21:04 UTC (rev 153) @@ -1001,6 +1001,43 @@ return; } +static int scst_tgt_pre_exec(struct scst_cmd *cmd, int *action) +{ + int res = 0, rc; + + TRACE_ENTRY(); + + TRACE_DBG("Calling pre_exec(%p)", cmd); + rc = cmd->tgtt->pre_exec(cmd); + TRACE_DBG("pre_exec() returned %d", rc); + + if (unlikely(rc != SCST_PREPROCESS_STATUS_SUCCESS)) { + switch(rc) { + case SCST_PREPROCESS_STATUS_ERROR_SENSE_SET: + cmd->state = SCST_CMD_STATE_DEV_DONE; + *action = SCST_CMD_STATE_RES_CONT_SAME; + res = -1; + break; + case SCST_PREPROCESS_STATUS_ERROR_FATAL: + set_bit(SCST_CMD_NO_RESP, &cmd->cmd_flags); + /* go through */ + case SCST_PREPROCESS_STATUS_ERROR: + scst_set_cmd_error(cmd, + SCST_LOAD_SENSE(scst_sense_hardw_error)); + cmd->state = SCST_CMD_STATE_DEV_DONE; + *action = SCST_CMD_STATE_RES_CONT_SAME; + res = -1; + break; + default: + sBUG(); + break; + } + } + + TRACE_EXIT_RES(res); + return res; +} + static void scst_inc_check_expected_sn(struct scst_cmd *cmd) { struct scst_cmd *c; @@ -1812,6 +1849,12 @@ res = SCST_CMD_STATE_RES_CONT_NEXT; + if (cmd->tgtt->pre_exec != NULL) { + rc = scst_tgt_pre_exec(cmd, &res); + if (unlikely(rc != 0)) + goto out; + } + if (unlikely(scst_inc_on_dev_cmd(cmd) != 0)) goto out; @@ -3229,7 +3272,7 @@ TRACE_ENTRY(); if (!scst_mutex_held) - down(&scst_mutex); + mutex_lock(&scst_mutex); list_for_each_entry(dev, &scst_dev_list, dev_list_entry) { struct scst_cmd *cmd, *tcmd; @@ -3264,7 +3307,7 @@ } if (!scst_mutex_held) - up(&scst_mutex); + mutex_unlock(&scst_mutex); TRACE_EXIT(); return; @@ -3406,7 +3449,7 @@ TRACE(TRACE_MGMT, "Target reset (mcmd %p, cmd count %d)", mcmd, atomic_read(&mcmd->sess->sess_cmd_count)); - down(&scst_mutex); + mutex_lock(&scst_mutex); list_for_each_entry(dev, &scst_dev_list, dev_list_entry) { int found = 0; @@ -3472,7 +3515,7 @@ dev->scsi_dev->was_reset = 0; } - up(&scst_mutex); + mutex_unlock(&scst_mutex); tm_dbg_task_mgmt("TARGET RESET", 0); res = scst_set_mcmd_next_state(mcmd); @@ -3537,7 +3580,7 @@ mcmd); } - down(&scst_mutex); + mutex_lock(&scst_mutex); for(i = 0; i < TGT_DEV_HASH_SIZE; i++) { struct list_head *sess_tgt_dev_list_head = &sess->sess_tgt_dev_list_hash[i]; @@ -3559,7 +3602,7 @@ mcmd->status = rc; } } - up(&scst_mutex); + mutex_unlock(&scst_mutex); res = scst_set_mcmd_next_state(mcmd); @@ -3588,7 +3631,7 @@ mcmd); } - down(&scst_mutex); + mutex_lock(&scst_mutex); list_for_each_entry(dev, &scst_dev_list, dev_list_entry) { spin_lock_bh(&dev->dev_lock); @@ -3616,7 +3659,7 @@ } } - up(&scst_mutex); + mutex_unlock(&scst_mutex); res = scst_set_mcmd_next_state(mcmd); @@ -3728,11 +3771,11 @@ case SCST_TARGET_RESET: case SCST_ABORT_ALL_TASKS: case SCST_NEXUS_LOSS: - down(&scst_mutex); + mutex_lock(&scst_mutex); list_for_each_entry(dev, &scst_dev_list, dev_list_entry) { scst_unblock_dev(dev); } - up(&scst_mutex); + mutex_unlock(&scst_mutex); break; case SCST_NEXUS_LOSS_SESS: @@ -3740,7 +3783,7 @@ { int i; - down(&scst_mutex); + mutex_lock(&scst_mutex); for(i = 0; i < TGT_DEV_HASH_SIZE; i++) { struct list_head *sess_tgt_dev_list_head = &mcmd->sess->sess_tgt_dev_list_hash[i]; @@ -3749,7 +3792,7 @@ scst_unblock_dev(tgt_dev->dev); } } - up(&scst_mutex); + mutex_unlock(&scst_mutex); break; } @@ -4116,7 +4159,7 @@ TRACE_ENTRY(); scst_suspend_activity(); - down(&scst_mutex); + mutex_lock(&scst_mutex); if (sess->initiator_name) acg = scst_find_acg(sess->initiator_name); @@ -4137,7 +4180,7 @@ res = scst_sess_alloc_tgt_devs(sess); - up(&scst_mutex); + mutex_unlock(&scst_mutex); scst_resume_activity(); if (sess->init_result_fn) { @@ -4259,7 +4302,7 @@ TRACE_ENTRY(); - down(&scst_mutex); + mutex_lock(&scst_mutex); for(i = 0; i < TGT_DEV_HASH_SIZE; i++) { struct list_head *sess_tgt_dev_list_head = &sess->sess_tgt_dev_list_hash[i]; @@ -4275,7 +4318,7 @@ } } } - up(&scst_mutex); + mutex_unlock(&scst_mutex); scst_sess_put(sess); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |