]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
block: add reference counting for struct bsg_job
authorJohannes Thumshirn <jthumshirn@suse.de>
Thu, 17 Nov 2016 09:31:18 +0000 (10:31 +0100)
committerMartin K. Petersen <martin.petersen@oracle.com>
Fri, 18 Nov 2016 01:15:25 +0000 (20:15 -0500)
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 <jthumshirn@suse.de>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
block/bsg-lib.c
include/linux/bsg-lib.h

index 650f427d915be22bd1a6bc88f21083de8c924a15..632fb4006c406423a7748ff1261af8c295a46427 100644 (file)
  * 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:
index a226652a5a6c7afc5f8d86146e526f9f5057904e..58e0717fda6e4e80d9f2fa693f73712825b5fc4f 100644 (file)
@@ -40,6 +40,8 @@ struct bsg_job {
        struct device *dev;
        struct request *req;
 
+       struct kref kref;
+
        /* Transport/driver specific request/reply structs */
        void *request;
        void *reply;