diff --git a/scst/include/scsi_tgt.h b/scst/include/scsi_tgt.h index 4583a9111..ae0015250 100644 --- a/scst/include/scsi_tgt.h +++ b/scst/include/scsi_tgt.h @@ -1181,7 +1181,7 @@ struct scst_device /* Pointer to lists of commands with the lock */ struct scst_cmd_lists *p_cmd_lists; - /* Lists of commands with the lock, if dedicated threads are used */ + /* Lists of commands with lock, if dedicated threads are used */ struct scst_cmd_lists cmd_lists; /* How many cmds alive on this dev */ @@ -1257,8 +1257,11 @@ struct scst_device /* List of acg_dev's, one per acg, protected by scst_mutex */ struct list_head dev_acg_dev_list; - /* List of dedicated threads. Doesn't need any protection. */ + /* List of dedicated threads, protected by scst_mutex */ struct list_head threads_list; + + /* Device number */ + int dev_num; }; /* diff --git a/scst/src/scst.c b/scst/src/scst.c index d85a1bbf1..3c5f2660e 100644 --- a/scst/src/scst.c +++ b/scst/src/scst.c @@ -898,17 +898,17 @@ void scst_unregister_virtual_dev_driver(struct scst_dev_type *dev_type) int scst_add_dev_threads(struct scst_device *dev, int num) { int i, res = 0; - static atomic_t major = ATOMIC_INIT(0); - int N, n = 0; + int n = 0; + struct scst_cmd_thread_t *thr; char nm[12]; TRACE_ENTRY(); - N = atomic_inc_return(&major); + list_for_each_entry(thr, &dev->threads_list, thread_list_entry) { + n++; + } for (i = 0; i < num; i++) { - struct scst_cmd_thread_t *thr; - thr = kmalloc(sizeof(*thr), GFP_KERNEL); if (!thr) { res = -ENOMEM; @@ -918,7 +918,7 @@ int scst_add_dev_threads(struct scst_device *dev, int num) strncpy(nm, dev->handler->name, ARRAY_SIZE(nm)-1); nm[ARRAY_SIZE(nm)-1] = '\0'; thr->cmd_thread = kthread_run(scst_cmd_thread, - &dev->cmd_lists, "%sd%d_%d", nm, N, n++); + &dev->cmd_lists, "%sd%d_%d", nm, dev->dev_num, n++); if (IS_ERR(thr->cmd_thread)) { res = PTR_ERR(thr->cmd_thread); PRINT_ERROR_PR("kthread_create() failed: %d", res); diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index c2f0f062a..eb8646998 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -150,6 +150,7 @@ int scst_alloc_device(int gfp_mask, struct scst_device **out_dev) { struct scst_device *dev; int res = 0; + static int dev_num; /* protected by scst_mutex */ TRACE_ENTRY(); @@ -172,6 +173,7 @@ int scst_alloc_device(int gfp_mask, struct scst_device **out_dev) init_waitqueue_head(&dev->on_dev_waitQ); dev->dev_double_ua_possible = 1; dev->dev_serialized = 1; + dev->dev_num = dev_num++; *out_dev = dev;