- Semaphores converted to mutexes

- pre_exec() callback added
 - *_DBG_SPECIAL() macroses added 



git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@153 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
Vladislav Bolkhovitin
2007-07-30 11:21:04 +00:00
parent 5814b4ba13
commit b28d1b9905
10 changed files with 218 additions and 131 deletions

View File

@@ -521,6 +521,22 @@ struct scst_tgt_template
*/
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

View File

@@ -220,6 +220,19 @@ do { \
} \
} 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 @@ do { \
} \
} 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 @@ do { \
#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) {}

View File

@@ -293,7 +293,7 @@ static int vcdrom_write_proc(char *buffer, char **start, off_t offset,
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 @@ static int vdisk_read_proc(struct seq_file *seq, struct scst_dev_type *dev_type)
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 @@ static int vdisk_read_proc(struct seq_file *seq, struct scst_dev_type *dev_type)
}
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 @@ static int vdisk_write_proc(char *buffer, char **start, off_t offset,
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 @@ static int vdisk_write_proc(char *buffer, char **start, off_t offset,
res = length;
out_up:
up(&scst_vdisk_mutex);
mutex_unlock(&scst_vdisk_mutex);
out:
TRACE_EXIT_RES(res);
@@ -2932,7 +2932,7 @@ static int vcdrom_read_proc(struct seq_file *seq, struct scst_dev_type *dev_type
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 @@ static int vcdrom_read_proc(struct seq_file *seq, struct scst_dev_type *dev_type
virt_dev->file_name);
}
up(&scst_vdisk_mutex);
mutex_unlock(&scst_vdisk_mutex);
out:
TRACE_EXIT_RES(res);
@@ -2965,7 +2965,7 @@ static int vcdrom_write_proc(char *buffer, char **start, off_t offset,
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 @@ static int vcdrom_write_proc(char *buffer, char **start, off_t offset,
res = length;
out_up:
up(&scst_vdisk_mutex);
mutex_unlock(&scst_vdisk_mutex);
out:
TRACE_EXIT_RES(res);
@@ -3122,7 +3122,7 @@ static void __exit exit_scst_vdisk(struct scst_dev_type *devtype,
{
TRACE_ENTRY();
down(&scst_vdisk_mutex);
mutex_lock(&scst_vdisk_mutex);
while (1) {
struct scst_vdisk_dev *virt_dev;
@@ -3141,7 +3141,7 @@ static void __exit exit_scst_vdisk(struct scst_dev_type *devtype,
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);

View File

@@ -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 @@ LIST_HEAD(scst_sess_mgmt_list);
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 scst_register_target_template(struct scst_tgt_template *vtt)
{
int res = 0;
struct scst_tgt_template *t;
static DECLARE_MUTEX(m);
static DEFINE_MUTEX(m);
TRACE_ENTRY();
@@ -185,20 +185,20 @@ int scst_register_target_template(struct scst_tgt_template *vtt)
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 @@ int scst_register_target_template(struct scst_tgt_template *vtt)
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 @@ void scst_unregister_target_template(struct scst_tgt_template *vtt)
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 @@ void scst_unregister_target_template(struct scst_tgt_template *vtt)
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 @@ restart:
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 @@ struct scst_tgt *scst_register(struct scst_tgt_template *vtt,
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 @@ struct scst_tgt *scst_register(struct scst_tgt_template *vtt,
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 @@ out_free_name:
kfree(tgt->default_group_name);
out_free_err:
up(&scst_mutex);
mutex_unlock(&scst_mutex);
scst_resume_activity();
kfree(tgt);
@@ -350,9 +350,9 @@ out_err:
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 @@ void scst_unregister(struct scst_tgt *tgt)
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 @@ void scst_unregister(struct scst_tgt *tgt)
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 @@ void scst_suspend_activity(void)
{
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 @@ void scst_suspend_activity(void)
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 @@ void scst_resume_activity(void)
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 @@ void scst_resume_activity(void)
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 @@ static int scst_register_device(struct scsi_device *scsidp)
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 @@ static int scst_register_device(struct scsi_device *scsidp)
}
out_up:
up(&scst_mutex);
mutex_unlock(&scst_mutex);
scst_resume_activity();
if (res == 0) {
@@ -550,7 +550,7 @@ static void scst_unregister_device(struct scsi_device *scsidp)
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 @@ static void scst_unregister_device(struct scsi_device *scsidp)
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 @@ int scst_register_virtual_device(struct scst_dev_type *dev_handler,
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 @@ int scst_register_virtual_device(struct scst_dev_type *dev_handler,
}
out_up:
up(&scst_mutex);
mutex_unlock(&scst_mutex);
out_resume:
scst_resume_activity();
@@ -694,7 +694,7 @@ void scst_unregister_virtual_device(int id)
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 @@ void scst_unregister_virtual_device(int id)
scst_free_device(dev);
out_unblock:
up(&scst_mutex);
mutex_unlock(&scst_mutex);
scst_resume_activity();
TRACE_EXIT();
@@ -756,7 +756,7 @@ int scst_register_dev_driver(struct scst_dev_type *dev_type)
#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 @@ int scst_register_dev_driver(struct scst_dev_type *dev_type)
scst_assign_dev_handler(dev, dev_type);
}
up(&scst_mutex);
mutex_unlock(&scst_mutex);
scst_resume_activity();
if (res == 0) {
@@ -800,7 +800,7 @@ out:
return res;
out_up:
up(&scst_mutex);
mutex_unlock(&scst_mutex);
out_err:
scst_resume_activity();
@@ -818,7 +818,7 @@ void scst_unregister_dev_driver(struct scst_dev_type *dev_type)
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 @@ void scst_unregister_dev_driver(struct scst_dev_type *dev_type)
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 @@ out:
return;
out_up:
up(&scst_mutex);
mutex_unlock(&scst_mutex);
scst_resume_activity();
goto out;
}
@@ -967,10 +967,10 @@ static int scst_create_dev_threads(struct scst_device *dev)
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 @@ static void scst_stop_dev_threads(struct scst_device *dev)
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 scst_cmd_threads_count(void)
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 @@ int scst_add_cmd_threads(int num)
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 @@ void scst_del_cmd_threads(int num)
{
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 @@ static void scst_stop_all_threads(void)
{
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 @@ static void scst_stop_all_threads(void)
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 @@ static int scst_start_all_threads(int num)
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 @@ static int scst_start_all_threads(int num)
}
out:
up(&scst_threads_info.cmd_threads_mutex);
mutex_unlock(&scst_threads_info.cmd_threads_mutex);
TRACE_EXIT_RES(res);
return res;
}

View File

@@ -1085,7 +1085,7 @@ void scst_free_session(struct scst_session *sess)
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 @@ void scst_free_session(struct scst_session *sess)
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 @@ void scst_dev_del_all_thr_data(struct scst_device *dev)
* 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;

View File

@@ -65,7 +65,7 @@ static int sgv_max_local_order, sgv_max_trans_order;
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 @@ int sgv_pool_init(struct sgv_pool *pool, const char *name, int clustered)
}
}
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 @@ void sgv_pool_deinit(struct sgv_pool *pool)
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();
}

View File

@@ -86,7 +86,7 @@ struct scst_sgv_pools
};
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,

View File

@@ -154,14 +154,14 @@ extern spinlock_t scst_main_lock;
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_cmd_thread_t {
};
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;

View File

@@ -163,7 +163,7 @@ static char *scst_proc_dev_handler_type[] =
"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 @@ static int strncasecmp(const char *s1, const char *s2, int n)
#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 @@ static ssize_t scst_proc_scsi_tgt_gen_write_log(struct file *file, const char __
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 @@ static ssize_t scst_proc_scsi_tgt_gen_write_log(struct file *file, const char __
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 @@ static ssize_t scst_proc_threads_write(struct file *file, const char __user *buf
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 @@ static ssize_t scst_proc_threads_write(struct file *file, const char __user *buf
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 @@ static ssize_t scst_proc_scsi_tgt_write(struct file *file, const char __user *bu
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 @@ static ssize_t scst_proc_scsi_dev_handler_write(struct file *file, const char __
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 @@ static ssize_t scst_proc_scsi_tgt_gen_write(struct file *file, const char __user
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 @@ static ssize_t scst_proc_scsi_tgt_gen_write(struct file *file, const char __user
res = rc;
out_up_free:
up(&scst_mutex);
mutex_unlock(&scst_mutex);
out_free_resume:
scst_resume_activity();
@@ -1366,7 +1366,7 @@ static ssize_t scst_proc_groups_devices_write(struct file *file, const char __us
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 @@ static ssize_t scst_proc_groups_devices_write(struct file *file, const char __us
}
out_free_up:
up(&scst_mutex);
mutex_unlock(&scst_mutex);
out_free_resume:
scst_resume_activity();
@@ -1569,7 +1569,7 @@ static ssize_t scst_proc_groups_names_write(struct file *file, const char __user
break;
}
if (down_interruptible(&scst_mutex) != 0) {
if (mutex_lock_interruptible(&scst_mutex) != 0) {
res = -EINTR;
goto out_free;
}
@@ -1591,7 +1591,7 @@ static ssize_t scst_proc_groups_names_write(struct file *file, const char __user
break;
}
up(&scst_mutex);
mutex_unlock(&scst_mutex);
out_free:
free_page((unsigned long)buffer);
@@ -1689,7 +1689,7 @@ static int scst_sessions_info_show(struct seq_file *seq, void *v)
TRACE_ENTRY();
if (down_interruptible(&scst_mutex) != 0) {
if (mutex_lock_interruptible(&scst_mutex) != 0) {
res = -EINTR;
goto out;
}
@@ -1707,7 +1707,7 @@ static int scst_sessions_info_show(struct seq_file *seq, void *v)
}
}
up(&scst_mutex);
mutex_unlock(&scst_mutex);
out:
TRACE_EXIT_RES(res);
@@ -1747,11 +1747,11 @@ static int scst_sgv_info_show(struct seq_file *seq, void *v)
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 @@ static int scst_groups_names_show(struct seq_file *seq, void *v)
TRACE_ENTRY();
if (down_interruptible(&scst_mutex) != 0) {
if (mutex_lock_interruptible(&scst_mutex) != 0) {
res = -EINTR;
goto out;
}
@@ -1781,7 +1781,7 @@ static int scst_groups_names_show(struct seq_file *seq, void *v)
seq_printf(seq, "%s\n", name->name);
}
up(&scst_mutex);
mutex_unlock(&scst_mutex);
out:
TRACE_EXIT_RES(res);
@@ -1801,7 +1801,7 @@ static int scst_groups_devices_show(struct seq_file *seq, void *v)
TRACE_ENTRY();
if (down_interruptible(&scst_mutex) != 0) {
if (mutex_lock_interruptible(&scst_mutex) != 0) {
res = -EINTR;
goto out;
}
@@ -1831,7 +1831,7 @@ static int scst_groups_devices_show(struct seq_file *seq, void *v)
acg_dev->rd_only_flag ? "RO" : "");
}
}
up(&scst_mutex);
mutex_unlock(&scst_mutex);
out:
TRACE_EXIT_RES(res);
@@ -1886,14 +1886,14 @@ static int log_info_show(struct seq_file *seq, void *v)
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 @@ static int scst_tgt_info_show(struct seq_file *seq, void *v)
TRACE_ENTRY();
if (down_interruptible(&scst_mutex) != 0) {
if (mutex_lock_interruptible(&scst_mutex) != 0) {
res = -EINTR;
goto out;
}
@@ -1937,7 +1937,7 @@ static int scst_tgt_info_show(struct seq_file *seq, void *v)
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 @@ static int scst_scsi_tgtinfo_show(struct seq_file *seq, void *v)
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 @@ static int scst_scsi_tgtinfo_show(struct seq_file *seq, void *v)
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 @@ static int scst_dev_handler_info_show(struct seq_file *seq, void *v)
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 @@ static int scst_dev_handler_info_show(struct seq_file *seq, void *v)
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);

View File

@@ -1001,6 +1001,43 @@ void scst_rx_data(struct scst_cmd *cmd, int status, int pref_context)
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 @@ static int scst_send_to_midlev(struct scst_cmd *cmd)
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 @@ static void scst_unblock_aborted_cmds(int scst_mutex_held)
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 @@ static void scst_unblock_aborted_cmds(int scst_mutex_held)
}
if (!scst_mutex_held)
up(&scst_mutex);
mutex_unlock(&scst_mutex);
TRACE_EXIT();
return;
@@ -3406,7 +3449,7 @@ static int scst_target_reset(struct scst_mgmt_cmd *mcmd)
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 @@ static int scst_target_reset(struct scst_mgmt_cmd *mcmd)
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 @@ static int scst_abort_all_nexus_loss_sess(struct scst_mgmt_cmd *mcmd,
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 @@ static int scst_abort_all_nexus_loss_sess(struct scst_mgmt_cmd *mcmd,
mcmd->status = rc;
}
}
up(&scst_mutex);
mutex_unlock(&scst_mutex);
res = scst_set_mcmd_next_state(mcmd);
@@ -3588,7 +3631,7 @@ static int scst_abort_all_nexus_loss_tgt(struct scst_mgmt_cmd *mcmd,
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 @@ static int scst_abort_all_nexus_loss_tgt(struct scst_mgmt_cmd *mcmd,
}
}
up(&scst_mutex);
mutex_unlock(&scst_mutex);
res = scst_set_mcmd_next_state(mcmd);
@@ -3728,11 +3771,11 @@ static void scst_mgmt_cmd_send_done(struct scst_mgmt_cmd *mcmd)
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 @@ static void scst_mgmt_cmd_send_done(struct scst_mgmt_cmd *mcmd)
{
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 @@ static void scst_mgmt_cmd_send_done(struct scst_mgmt_cmd *mcmd)
scst_unblock_dev(tgt_dev->dev);
}
}
up(&scst_mutex);
mutex_unlock(&scst_mutex);
break;
}
@@ -4116,7 +4159,7 @@ static int scst_init_session(struct scst_session *sess)
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 @@ static int scst_init_session(struct scst_session *sess)
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 @@ static void scst_unreg_work_fn(struct work_struct *work)
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 @@ static void scst_unreg_work_fn(struct work_struct *work)
}
}
}
up(&scst_mutex);
mutex_unlock(&scst_mutex);
scst_sess_put(sess);