Skip to content

Commit 4fcf812

Browse files
djbwJames Bottomley
authored andcommitted
[SCSI] libsas: export sas_alloc_task()
Now that isci has added a 3rd open coded user of this functionality just share the libsas version. Acked-by: Jack Wang <[email protected]> Signed-off-by: Dan Williams <[email protected]> Signed-off-by: James Bottomley <[email protected]>
1 parent 7ca3c80 commit 4fcf812

File tree

5 files changed

+41
-111
lines changed

5 files changed

+41
-111
lines changed

drivers/scsi/isci/task.c

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,29 +1345,6 @@ static void isci_smp_task_done(struct sas_task *task)
13451345
complete(&task->completion);
13461346
}
13471347

1348-
static struct sas_task *isci_alloc_task(void)
1349-
{
1350-
struct sas_task *task = kzalloc(sizeof(*task), GFP_KERNEL);
1351-
1352-
if (task) {
1353-
INIT_LIST_HEAD(&task->list);
1354-
spin_lock_init(&task->task_state_lock);
1355-
task->task_state_flags = SAS_TASK_STATE_PENDING;
1356-
init_timer(&task->timer);
1357-
init_completion(&task->completion);
1358-
}
1359-
1360-
return task;
1361-
}
1362-
1363-
static void isci_free_task(struct isci_host *ihost, struct sas_task *task)
1364-
{
1365-
if (task) {
1366-
BUG_ON(!list_empty(&task->list));
1367-
kfree(task);
1368-
}
1369-
}
1370-
13711348
static int isci_smp_execute_task(struct isci_host *ihost,
13721349
struct domain_device *dev, void *req,
13731350
int req_size, void *resp, int resp_size)
@@ -1376,7 +1353,7 @@ static int isci_smp_execute_task(struct isci_host *ihost,
13761353
struct sas_task *task = NULL;
13771354

13781355
for (retry = 0; retry < 3; retry++) {
1379-
task = isci_alloc_task();
1356+
task = sas_alloc_task(GFP_KERNEL);
13801357
if (!task)
13811358
return -ENOMEM;
13821359

@@ -1439,13 +1416,13 @@ static int isci_smp_execute_task(struct isci_host *ihost,
14391416
SAS_ADDR(dev->sas_addr),
14401417
task->task_status.resp,
14411418
task->task_status.stat);
1442-
isci_free_task(ihost, task);
1419+
sas_free_task(task);
14431420
task = NULL;
14441421
}
14451422
}
14461423
ex_err:
14471424
BUG_ON(retry == 3 && task != NULL);
1448-
isci_free_task(ihost, task);
1425+
sas_free_task(task);
14491426
return res;
14501427
}
14511428

drivers/scsi/libsas/sas_init.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,32 @@
3737

3838
#include "../scsi_sas_internal.h"
3939

40-
struct kmem_cache *sas_task_cache;
40+
static struct kmem_cache *sas_task_cache;
41+
42+
struct sas_task *sas_alloc_task(gfp_t flags)
43+
{
44+
struct sas_task *task = kmem_cache_zalloc(sas_task_cache, flags);
45+
46+
if (task) {
47+
INIT_LIST_HEAD(&task->list);
48+
spin_lock_init(&task->task_state_lock);
49+
task->task_state_flags = SAS_TASK_STATE_PENDING;
50+
init_timer(&task->timer);
51+
init_completion(&task->completion);
52+
}
53+
54+
return task;
55+
}
56+
EXPORT_SYMBOL_GPL(sas_alloc_task);
57+
58+
void sas_free_task(struct sas_task *task)
59+
{
60+
if (task) {
61+
BUG_ON(!list_empty(&task->list));
62+
kmem_cache_free(sas_task_cache, task);
63+
}
64+
}
65+
EXPORT_SYMBOL_GPL(sas_free_task);
4166

4267
/*------------ SAS addr hash -----------*/
4368
void sas_hash_addr(u8 *hashed, const u8 *sas_addr)
@@ -293,8 +318,7 @@ EXPORT_SYMBOL_GPL(sas_domain_release_transport);
293318

294319
static int __init sas_class_init(void)
295320
{
296-
sas_task_cache = kmem_cache_create("sas_task", sizeof(struct sas_task),
297-
0, SLAB_HWCACHE_ALIGN, NULL);
321+
sas_task_cache = KMEM_CACHE(sas_task, SLAB_HWCACHE_ALIGN);
298322
if (!sas_task_cache)
299323
return -ENOMEM;
300324

drivers/scsi/mvsas/mv_sas.c

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,28 +1387,6 @@ void mvs_dev_gone(struct domain_device *dev)
13871387
mvs_dev_gone_notify(dev);
13881388
}
13891389

1390-
static struct sas_task *mvs_alloc_task(void)
1391-
{
1392-
struct sas_task *task = kzalloc(sizeof(struct sas_task), GFP_KERNEL);
1393-
1394-
if (task) {
1395-
INIT_LIST_HEAD(&task->list);
1396-
spin_lock_init(&task->task_state_lock);
1397-
task->task_state_flags = SAS_TASK_STATE_PENDING;
1398-
init_timer(&task->timer);
1399-
init_completion(&task->completion);
1400-
}
1401-
return task;
1402-
}
1403-
1404-
static void mvs_free_task(struct sas_task *task)
1405-
{
1406-
if (task) {
1407-
BUG_ON(!list_empty(&task->list));
1408-
kfree(task);
1409-
}
1410-
}
1411-
14121390
static void mvs_task_done(struct sas_task *task)
14131391
{
14141392
if (!del_timer(&task->timer))
@@ -1432,7 +1410,7 @@ static int mvs_exec_internal_tmf_task(struct domain_device *dev,
14321410
struct sas_task *task = NULL;
14331411

14341412
for (retry = 0; retry < 3; retry++) {
1435-
task = mvs_alloc_task();
1413+
task = sas_alloc_task(GFP_KERNEL);
14361414
if (!task)
14371415
return -ENOMEM;
14381416

@@ -1490,15 +1468,14 @@ static int mvs_exec_internal_tmf_task(struct domain_device *dev,
14901468
SAS_ADDR(dev->sas_addr),
14911469
task->task_status.resp,
14921470
task->task_status.stat);
1493-
mvs_free_task(task);
1471+
sas_free_task(task);
14941472
task = NULL;
14951473

14961474
}
14971475
}
14981476
ex_err:
14991477
BUG_ON(retry == 3 && task != NULL);
1500-
if (task != NULL)
1501-
mvs_free_task(task);
1478+
sas_free_task(task);
15021479
return res;
15031480
}
15041481

drivers/scsi/pm8001/pm8001_sas.c

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -669,30 +669,6 @@ int pm8001_dev_found(struct domain_device *dev)
669669
return pm8001_dev_found_notify(dev);
670670
}
671671

672-
/**
673-
* pm8001_alloc_task - allocate a task structure for TMF
674-
*/
675-
static struct sas_task *pm8001_alloc_task(void)
676-
{
677-
struct sas_task *task = kzalloc(sizeof(*task), GFP_KERNEL);
678-
if (task) {
679-
INIT_LIST_HEAD(&task->list);
680-
spin_lock_init(&task->task_state_lock);
681-
task->task_state_flags = SAS_TASK_STATE_PENDING;
682-
init_timer(&task->timer);
683-
init_completion(&task->completion);
684-
}
685-
return task;
686-
}
687-
688-
static void pm8001_free_task(struct sas_task *task)
689-
{
690-
if (task) {
691-
BUG_ON(!list_empty(&task->list));
692-
kfree(task);
693-
}
694-
}
695-
696672
static void pm8001_task_done(struct sas_task *task)
697673
{
698674
if (!del_timer(&task->timer))
@@ -728,7 +704,7 @@ static int pm8001_exec_internal_tmf_task(struct domain_device *dev,
728704
struct pm8001_hba_info *pm8001_ha = pm8001_find_ha_by_dev(dev);
729705

730706
for (retry = 0; retry < 3; retry++) {
731-
task = pm8001_alloc_task();
707+
task = sas_alloc_task(GFP_KERNEL);
732708
if (!task)
733709
return -ENOMEM;
734710

@@ -789,14 +765,13 @@ static int pm8001_exec_internal_tmf_task(struct domain_device *dev,
789765
SAS_ADDR(dev->sas_addr),
790766
task->task_status.resp,
791767
task->task_status.stat));
792-
pm8001_free_task(task);
768+
sas_free_task(task);
793769
task = NULL;
794770
}
795771
}
796772
ex_err:
797773
BUG_ON(retry == 3 && task != NULL);
798-
if (task != NULL)
799-
pm8001_free_task(task);
774+
sas_free_task(task);
800775
return res;
801776
}
802777

@@ -811,7 +786,7 @@ pm8001_exec_internal_task_abort(struct pm8001_hba_info *pm8001_ha,
811786
struct sas_task *task = NULL;
812787

813788
for (retry = 0; retry < 3; retry++) {
814-
task = pm8001_alloc_task();
789+
task = sas_alloc_task(GFP_KERNEL);
815790
if (!task)
816791
return -ENOMEM;
817792

@@ -864,14 +839,13 @@ pm8001_exec_internal_task_abort(struct pm8001_hba_info *pm8001_ha,
864839
SAS_ADDR(dev->sas_addr),
865840
task->task_status.resp,
866841
task->task_status.stat));
867-
pm8001_free_task(task);
842+
sas_free_task(task);
868843
task = NULL;
869844
}
870845
}
871846
ex_err:
872847
BUG_ON(retry == 3 && task != NULL);
873-
if (task != NULL)
874-
pm8001_free_task(task);
848+
sas_free_task(task);
875849
return res;
876850
}
877851

include/scsi/libsas.h

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -555,36 +555,14 @@ struct sas_task {
555555
struct work_struct abort_work;
556556
};
557557

558-
extern struct kmem_cache *sas_task_cache;
559-
560558
#define SAS_TASK_STATE_PENDING 1
561559
#define SAS_TASK_STATE_DONE 2
562560
#define SAS_TASK_STATE_ABORTED 4
563561
#define SAS_TASK_NEED_DEV_RESET 8
564562
#define SAS_TASK_AT_INITIATOR 16
565563

566-
static inline struct sas_task *sas_alloc_task(gfp_t flags)
567-
{
568-
struct sas_task *task = kmem_cache_zalloc(sas_task_cache, flags);
569-
570-
if (task) {
571-
INIT_LIST_HEAD(&task->list);
572-
spin_lock_init(&task->task_state_lock);
573-
task->task_state_flags = SAS_TASK_STATE_PENDING;
574-
init_timer(&task->timer);
575-
init_completion(&task->completion);
576-
}
577-
578-
return task;
579-
}
580-
581-
static inline void sas_free_task(struct sas_task *task)
582-
{
583-
if (task) {
584-
BUG_ON(!list_empty(&task->list));
585-
kmem_cache_free(sas_task_cache, task);
586-
}
587-
}
564+
extern struct sas_task *sas_alloc_task(gfp_t flags);
565+
extern void sas_free_task(struct sas_task *task);
588566

589567
struct sas_domain_function_template {
590568
/* The class calls these to notify the LLDD of an event. */

0 commit comments

Comments
 (0)