From bf0f2d380f15f1fa05254b000ddeeb560dfb8638 Mon Sep 17 00:00:00 2001 From: Johannes Thumshirn Date: Thu, 17 Nov 2016 10:31:18 +0100 Subject: block: add reference counting for struct bsg_job Add reference counting to 'struct bsg_job' so we can implement a reuqest timeout handler for bsg_jobs, which is needed for Fibre Channel. Signed-off-by: Johannes Thumshirn Reviewed-by: Hannes Reinecke Signed-off-by: Martin K. Petersen --- block/bsg-lib.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'block/bsg-lib.c') diff --git a/block/bsg-lib.c b/block/bsg-lib.c index 650f427d915b..632fb4006c40 100644 --- a/block/bsg-lib.c +++ b/block/bsg-lib.c @@ -32,8 +32,10 @@ * bsg_destroy_job - routine to teardown/delete a bsg job * @job: bsg_job that is to be torn down */ -static void bsg_destroy_job(struct bsg_job *job) +static void bsg_destroy_job(struct kref *kref) { + struct bsg_job *job = container_of(kref, struct bsg_job, kref); + put_device(job->dev); /* release reference for the request */ kfree(job->request_payload.sg_list); @@ -84,7 +86,7 @@ static void bsg_softirq_done(struct request *rq) struct bsg_job *job = rq->special; blk_end_request_all(rq, rq->errors); - bsg_destroy_job(job); + kref_put(&job->kref, bsg_destroy_job); } static int bsg_map_buffer(struct bsg_buffer *buf, struct request *req) @@ -142,6 +144,7 @@ static int bsg_create_job(struct device *dev, struct request *req) job->dev = dev; /* take a reference for the request */ get_device(job->dev); + kref_init(&job->kref); return 0; failjob_rls_rqst_payload: -- cgit v1.2.1 From c00da4c90ffd066cdfe7f53ff3529c8ab4a35db0 Mon Sep 17 00:00:00 2001 From: Johannes Thumshirn Date: Thu, 17 Nov 2016 10:31:20 +0100 Subject: scsi: fc: Use bsg_destroy_job fc_destroy_bsgjob() and bsg_destroy_job() are now 1:1 copies, so use the latter. As bsg_destroy_job() comes from bsg-lib we need to select it in Kconfig once CONFOG_SCSI_FC_ATTRS is active. Signed-off-by: Johannes Thumshirn Reviewed-by: Hannes Reinecke Signed-off-by: Martin K. Petersen --- block/bsg-lib.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'block/bsg-lib.c') diff --git a/block/bsg-lib.c b/block/bsg-lib.c index 632fb4006c40..9f1e8fde924a 100644 --- a/block/bsg-lib.c +++ b/block/bsg-lib.c @@ -32,9 +32,12 @@ * bsg_destroy_job - routine to teardown/delete a bsg job * @job: bsg_job that is to be torn down */ -static void bsg_destroy_job(struct kref *kref) +void bsg_destroy_job(struct kref *kref) { struct bsg_job *job = container_of(kref, struct bsg_job, kref); + struct request *rq = job->req; + + blk_end_request_all(rq, rq->errors); put_device(job->dev); /* release reference for the request */ @@ -42,6 +45,7 @@ static void bsg_destroy_job(struct kref *kref) kfree(job->reply_payload.sg_list); kfree(job); } +EXPORT_SYMBOL_GPL(bsg_destroy_job); /** * bsg_job_done - completion routine for bsg requests @@ -85,7 +89,6 @@ static void bsg_softirq_done(struct request *rq) { struct bsg_job *job = rq->special; - blk_end_request_all(rq, rq->errors); kref_put(&job->kref, bsg_destroy_job); } -- cgit v1.2.1 From 6aa858cd335a94e2824ed542140ac9704c0a64e2 Mon Sep 17 00:00:00 2001 From: Johannes Thumshirn Date: Thu, 17 Nov 2016 10:31:21 +0100 Subject: scsi: fc: use bsg_softirq_done bsg_softirq_done() and fc_bsg_softirq_done() are copies of each other, so ditch the fc specific one. Signed-off-by: Johannes Thumshirn Reviewed-by: Hannes Reinecke Signed-off-by: Martin K. Petersen --- block/bsg-lib.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'block/bsg-lib.c') diff --git a/block/bsg-lib.c b/block/bsg-lib.c index 9f1e8fde924a..6661f823db4c 100644 --- a/block/bsg-lib.c +++ b/block/bsg-lib.c @@ -85,12 +85,13 @@ EXPORT_SYMBOL_GPL(bsg_job_done); * bsg_softirq_done - softirq done routine for destroying the bsg requests * @rq: BSG request that holds the job to be destroyed */ -static void bsg_softirq_done(struct request *rq) +void bsg_softirq_done(struct request *rq) { struct bsg_job *job = rq->special; kref_put(&job->kref, bsg_destroy_job); } +EXPORT_SYMBOL_GPL(bsg_softirq_done); static int bsg_map_buffer(struct bsg_buffer *buf, struct request *req) { -- cgit v1.2.1 From fb6f7c8d8a19e5543d5b4d44c58e2c4e5a82bb12 Mon Sep 17 00:00:00 2001 From: Johannes Thumshirn Date: Thu, 17 Nov 2016 10:31:23 +0100 Subject: block: add bsg_job_put() and bsg_job_get() Add bsg_job_put() and bsg_job_get() so don't need to export bsg_destroy_job() any more. Signed-off-by: Johannes Thumshirn Reviewed-by: Hannes Reinecke Signed-off-by: Martin K. Petersen --- block/bsg-lib.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'block/bsg-lib.c') diff --git a/block/bsg-lib.c b/block/bsg-lib.c index 6661f823db4c..803ec40ebd6d 100644 --- a/block/bsg-lib.c +++ b/block/bsg-lib.c @@ -32,7 +32,7 @@ * bsg_destroy_job - routine to teardown/delete a bsg job * @job: bsg_job that is to be torn down */ -void bsg_destroy_job(struct kref *kref) +static void bsg_destroy_job(struct kref *kref) { struct bsg_job *job = container_of(kref, struct bsg_job, kref); struct request *rq = job->req; @@ -45,7 +45,18 @@ void bsg_destroy_job(struct kref *kref) kfree(job->reply_payload.sg_list); kfree(job); } -EXPORT_SYMBOL_GPL(bsg_destroy_job); + +void bsg_job_put(struct bsg_job *job) +{ + kref_put(&job->kref, bsg_destroy_job); +} +EXPORT_SYMBOL_GPL(bsg_job_put); + +int bsg_job_get(struct bsg_job *job) +{ + return kref_get_unless_zero(&job->kref); +} +EXPORT_SYMBOL_GPL(bsg_job_get); /** * bsg_job_done - completion routine for bsg requests @@ -89,7 +100,7 @@ void bsg_softirq_done(struct request *rq) { struct bsg_job *job = rq->special; - kref_put(&job->kref, bsg_destroy_job); + bsg_job_put(job); } EXPORT_SYMBOL_GPL(bsg_softirq_done); -- cgit v1.2.1 From a0f4bd7f2a5be485747aa438cea38f69e3ae8962 Mon Sep 17 00:00:00 2001 From: Johannes Thumshirn Date: Thu, 17 Nov 2016 10:31:24 +0100 Subject: scsi: fc: move FC transport's bsg code to bsg-lib Now that all conversions are done, move the FibreChannel bsg code over to the bsg library. This patch is derived from work done by Mike Christie in 2011 [1] but only the iscsi parts got merged back then. [1] http://marc.info/?l=linux-scsi&m=131149780921009&w=2 Signed-off-by: Johannes Thumshirn Reviewed-by: Hannes Reinecke Signed-off-by: Martin K. Petersen --- block/bsg-lib.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'block/bsg-lib.c') diff --git a/block/bsg-lib.c b/block/bsg-lib.c index 803ec40ebd6d..2d1df5cc0507 100644 --- a/block/bsg-lib.c +++ b/block/bsg-lib.c @@ -96,13 +96,12 @@ EXPORT_SYMBOL_GPL(bsg_job_done); * bsg_softirq_done - softirq done routine for destroying the bsg requests * @rq: BSG request that holds the job to be destroyed */ -void bsg_softirq_done(struct request *rq) +static void bsg_softirq_done(struct request *rq) { struct bsg_job *job = rq->special; bsg_job_put(job); } -EXPORT_SYMBOL_GPL(bsg_softirq_done); static int bsg_map_buffer(struct bsg_buffer *buf, struct request *req) { -- cgit v1.2.1