All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johannes Thumshirn <jthumshirn@suse.de>
To: "Martin K . Petersen" <martin.petersen@oracle.com>
Cc: Christoph Hellwig <hch@infradead.org>,
	Hannes Reinecke <hare@suse.de>,
	Linux Kernel Mailinglist <linux-kernel@vger.kernel.org>,
	Linux SCSI Mailinglist <linux-scsi@vger.kernel.org>,
	Johannes Thumshirn <jthumshirn@suse.de>,
	Jens Axboe <axboe@kernel.dk>,
	linux-block@vger.kernel.org (open list:BLOCK LAYER)
Subject: [PATCH 35/44] block: add reference counting for struct bsg_job
Date: Tue, 11 Oct 2016 13:29:06 +0200	[thread overview]
Message-ID: <153309f7b4d7a182cfc4b15f0d8c307b878c95df.1476180827.git.jthumshirn@suse.de> (raw)
In-Reply-To: <cover.1476180827.git.jthumshirn@suse.de>
In-Reply-To: <cover.1476180827.git.jthumshirn@suse.de>

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>
---
 block/bsg-lib.c         | 7 +++++--
 include/linux/bsg-lib.h | 2 ++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/block/bsg-lib.c b/block/bsg-lib.c
index 650f427..632fb40 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:
diff --git a/include/linux/bsg-lib.h b/include/linux/bsg-lib.h
index a226652..58e0717 100644
--- a/include/linux/bsg-lib.h
+++ b/include/linux/bsg-lib.h
@@ -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;
-- 
1.8.5.6

WARNING: multiple messages have this Message-ID (diff)
From: Johannes Thumshirn <jthumshirn@suse.de>
To: "Martin K . Petersen" <martin.petersen@oracle.com>
Cc: Christoph Hellwig <hch@infradead.org>,
	Hannes Reinecke <hare@suse.de>,
	Linux Kernel Mailinglist <linux-kernel@vger.kernel.org>,
	Linux SCSI Mailinglist <linux-scsi@vger.kernel.org>,
	Johannes Thumshirn <jthumshirn@suse.de>,
	Jens Axboe <axboe@kernel.dk>,
	"open list:BLOCK LAYER" <linux-block@vger.kernel.org>
Subject: [PATCH 35/44] block: add reference counting for struct bsg_job
Date: Tue, 11 Oct 2016 13:29:06 +0200	[thread overview]
Message-ID: <153309f7b4d7a182cfc4b15f0d8c307b878c95df.1476180827.git.jthumshirn@suse.de> (raw)
In-Reply-To: <cover.1476180827.git.jthumshirn@suse.de>
In-Reply-To: <cover.1476180827.git.jthumshirn@suse.de>

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>
---
 block/bsg-lib.c         | 7 +++++--
 include/linux/bsg-lib.h | 2 ++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/block/bsg-lib.c b/block/bsg-lib.c
index 650f427..632fb40 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:
diff --git a/include/linux/bsg-lib.h b/include/linux/bsg-lib.h
index a226652..58e0717 100644
--- a/include/linux/bsg-lib.h
+++ b/include/linux/bsg-lib.h
@@ -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;
-- 
1.8.5.6


  parent reply	other threads:[~2016-10-11 11:29 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-11 11:28 [PATCH 00/44] Convert FibreChannel bsg code to use bsg-lib Johannes Thumshirn
2016-10-11 11:28 ` [PATCH 01/44] scsi: Get rid of struct fc_bsg_buffer Johannes Thumshirn
2016-10-11 11:28 ` [PATCH 02/44] bfa: don't use fc_bsg_job::request and fc_bsg_job::reply directly Johannes Thumshirn
2016-10-11 11:28 ` [PATCH 03/44] zfcp: " Johannes Thumshirn
2016-10-11 11:28   ` Johannes Thumshirn
2016-10-11 11:28 ` [PATCH 04/44] ibmvfc: " Johannes Thumshirn
2016-10-11 11:28   ` Johannes Thumshirn
2016-10-11 11:28 ` [PATCH 05/44] lpfc: " Johannes Thumshirn
2016-10-11 11:28 ` [PATCH 06/44] qla2xxx: " Johannes Thumshirn
2016-10-11 11:28   ` Johannes Thumshirn
2016-10-11 11:28 ` [PATCH 07/44] libfc: " Johannes Thumshirn
2016-10-11 11:28   ` Johannes Thumshirn
2016-10-11 11:28 ` [PATCH 08/44] scsi: fc: " Johannes Thumshirn
2016-10-11 11:28 ` [PATCH 09/44] scsi: fc: Export fc_bsg_jobdone Johannes Thumshirn
2016-10-11 11:28 ` [PATCH 10/44] zfcp: Use fc_bsg_jobdone() Johannes Thumshirn
2016-10-11 11:28   ` Johannes Thumshirn
2016-10-11 11:28 ` [PATCH 11/44] bfa: " Johannes Thumshirn
2016-10-11 11:28 ` [PATCH 12/44] ibmvfc: " Johannes Thumshirn
2016-10-11 11:28   ` Johannes Thumshirn
2016-10-11 11:28 ` [PATCH 13/44] libfc: " Johannes Thumshirn
2016-10-11 11:28   ` Johannes Thumshirn
2016-10-11 11:28 ` [PATCH 14/44] lpfc: " Johannes Thumshirn
2016-10-11 11:28 ` [PATCH 15/44] qla2xxx: " Johannes Thumshirn
2016-10-11 11:28   ` Johannes Thumshirn
2016-10-11 11:28 ` [PATCH 16/44] scsi: fc: remove job_done method from struct fc_bsg_job Johannes Thumshirn
2016-10-11 11:28 ` [PATCH 17/44] scsi: Unify interfaces of fc_bsg_jobdone and bsg_job_done Johannes Thumshirn
2016-10-11 11:28   ` Johannes Thumshirn
2016-10-11 11:28 ` [PATCH 18/44] scsi: fc: provide fc_bsg_to_shost() helper Johannes Thumshirn
2016-10-11 11:28 ` [PATCH 19/44] scsi: fc: use fc_bsg_to_shost() to access a bsg_job's Scsi_Host Johannes Thumshirn
2016-10-11 11:28 ` [PATCH 20/44] bfa: " Johannes Thumshirn
2016-10-11 11:28 ` [PATCH 21/44] lpfc: " Johannes Thumshirn
2016-10-11 11:28 ` [PATCH 22/44] qla2xxx: " Johannes Thumshirn
2016-10-11 11:28   ` Johannes Thumshirn
2016-10-11 11:28 ` [PATCH 23/44] libfc: " Johannes Thumshirn
2016-10-11 11:28   ` Johannes Thumshirn
2016-10-11 11:28 ` [PATCH 24/44] ibmvfc: " Johannes Thumshirn
2016-10-11 11:28   ` Johannes Thumshirn
2016-10-11 11:28 ` [PATCH 25/44] zfcp: " Johannes Thumshirn
2016-10-11 11:28   ` Johannes Thumshirn
2016-10-11 11:28 ` [PATCH 26/44] scsi: fc: provide fc_bsg_to_rport() helper Johannes Thumshirn
2016-10-11 11:28 ` [PATCH 27/44] scsi: fc: use fc_bsg_to_rport() to access a bsg_job's rport Johannes Thumshirn
2016-10-11 11:28 ` [PATCH 28/44] zfcp: " Johannes Thumshirn
2016-10-11 11:28   ` Johannes Thumshirn
2016-10-11 11:29 ` [PATCH 29/44] qla2xxx: " Johannes Thumshirn
2016-10-11 11:29   ` Johannes Thumshirn
2016-10-11 11:29 ` [PATCH 30/44] lpfc: " Johannes Thumshirn
2016-10-11 11:29 ` [PATCH 31/44] libfc: " Johannes Thumshirn
2016-10-11 11:29   ` Johannes Thumshirn
2016-10-11 11:29 ` [PATCH 32/44] ibmvfc: " Johannes Thumshirn
2016-10-11 11:29   ` Johannes Thumshirn
2016-10-11 11:29 ` [PATCH 33/44] scsi: libfc: don't set FC_RQST_STATE_DONE before calling fc_bsg_jobdone() Johannes Thumshirn
2016-10-11 11:29   ` Johannes Thumshirn
2016-10-11 11:29 ` [PATCH 34/44] scsi: fc: implement kref backed reference counting Johannes Thumshirn
2016-10-11 11:29 ` Johannes Thumshirn [this message]
2016-10-11 11:29   ` [PATCH 35/44] block: add reference counting for struct bsg_job Johannes Thumshirn
2016-10-11 11:29 ` [PATCH 36/44] scsi: change FC drivers to use 'struct bsg_job' Johannes Thumshirn
2016-10-11 11:29   ` Johannes Thumshirn
2016-10-11 11:29 ` [PATCH 37/44] block: export bsg_destroy_job Johannes Thumshirn
2016-10-11 11:29   ` Johannes Thumshirn
2016-10-11 11:29 ` [PATCH 38/44] scsi: fc: Use bsg_destroy_job Johannes Thumshirn
2016-10-11 11:29 ` [PATCH 39/44] block: export bsg_softirq_done Johannes Thumshirn
2016-10-11 11:29   ` Johannes Thumshirn
2016-10-11 11:29 ` [PATCH 40/44] scsi: fc: use bsg_softirq_done Johannes Thumshirn
2016-10-11 11:29 ` [PATCH 41/44] scsi: fc: use bsg_job_done Johannes Thumshirn
2016-10-11 11:29   ` Johannes Thumshirn
2016-10-11 11:29 ` [PATCH 42/44] block: add bsg_job_put() and bsg_job_get() Johannes Thumshirn
2016-10-11 11:29   ` Johannes Thumshirn
2016-10-11 11:29 ` [PATCH 43/44] scsi: fc: move FC transport's bsg code to bsg-lib Johannes Thumshirn
2016-10-11 11:29 ` [PATCH 44/44] block: unexport bsg_softirq_done() again Johannes Thumshirn
2016-10-11 11:29   ` Johannes Thumshirn
2016-10-11 16:49 ` [PATCH 00/44] Convert FibreChannel bsg code to use bsg-lib Christoph Hellwig
2016-10-12  7:06   ` Johannes Thumshirn
2016-10-11 18:00 ` Hannes Reinecke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=153309f7b4d7a182cfc4b15f0d8c307b878c95df.1476180827.git.jthumshirn@suse.de \
    --to=jthumshirn@suse.de \
    --cc=axboe@kernel.dk \
    --cc=hare@suse.de \
    --cc=hch@infradead.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.