Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <jthumshirn@suse.de>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Johannes Thumshirn and committed by
Martin K. Petersen
bf0f2d38 ad7660cc

+7 -2
+5 -2
block/bsg-lib.c
··· 32 32 * bsg_destroy_job - routine to teardown/delete a bsg job 33 33 * @job: bsg_job that is to be torn down 34 34 */ 35 - static void bsg_destroy_job(struct bsg_job *job) 35 + static void bsg_destroy_job(struct kref *kref) 36 36 { 37 + struct bsg_job *job = container_of(kref, struct bsg_job, kref); 38 + 37 39 put_device(job->dev); /* release reference for the request */ 38 40 39 41 kfree(job->request_payload.sg_list); ··· 86 84 struct bsg_job *job = rq->special; 87 85 88 86 blk_end_request_all(rq, rq->errors); 89 - bsg_destroy_job(job); 87 + kref_put(&job->kref, bsg_destroy_job); 90 88 } 91 89 92 90 static int bsg_map_buffer(struct bsg_buffer *buf, struct request *req) ··· 144 142 job->dev = dev; 145 143 /* take a reference for the request */ 146 144 get_device(job->dev); 145 + kref_init(&job->kref); 147 146 return 0; 148 147 149 148 failjob_rls_rqst_payload:
+2
include/linux/bsg-lib.h
··· 40 40 struct device *dev; 41 41 struct request *req; 42 42 43 + struct kref kref; 44 + 43 45 /* Transport/driver specific request/reply structs */ 44 46 void *request; 45 47 void *reply;