diff mbox series

[12/28] bsg: provide bsg_remove_queue() helper

Message ID 20181025211039.11559-13-axboe@kernel.dk (mailing list archive)
State Superseded
Headers show
Series blk-mq driver conversions and legacy path removal | expand

Commit Message

Jens Axboe Oct. 25, 2018, 9:10 p.m. UTC
All drivers do unregister + cleanup, provide a helper for that.

Cc: Johannes Thumshirn <jthumshirn@suse.de>
Cc: Benjamin Block <bblock@linux.vnet.ibm.com>
Cc: linux-scsi@vger.kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 block/bsg-lib.c                     | 7 +++++++
 drivers/scsi/scsi_transport_fc.c    | 6 ++----
 drivers/scsi/scsi_transport_iscsi.c | 7 +++----
 drivers/scsi/scsi_transport_sas.c   | 6 ++----
 include/linux/bsg-lib.h             | 1 +
 5 files changed, 15 insertions(+), 12 deletions(-)

Comments

Christoph Hellwig Oct. 28, 2018, 3:53 p.m. UTC | #1
On Thu, Oct 25, 2018 at 03:10:23PM -0600, Jens Axboe wrote:
> All drivers do unregister + cleanup, provide a helper for that.

Nice cleanup,

Reviewed-by: Christoph Hellwig <hch@lst.de>
Hannes Reinecke Oct. 29, 2018, 6:55 a.m. UTC | #2
On 10/25/18 11:10 PM, Jens Axboe wrote:
> All drivers do unregister + cleanup, provide a helper for that.
> 
> Cc: Johannes Thumshirn <jthumshirn@suse.de>
> Cc: Benjamin Block <bblock@linux.vnet.ibm.com>
> Cc: linux-scsi@vger.kernel.org
> Signed-off-by: Jens Axboe <axboe@kernel.dk>
> ---
>   block/bsg-lib.c                     | 7 +++++++
>   drivers/scsi/scsi_transport_fc.c    | 6 ++----
>   drivers/scsi/scsi_transport_iscsi.c | 7 +++----
>   drivers/scsi/scsi_transport_sas.c   | 6 ++----
>   include/linux/bsg-lib.h             | 1 +
>   5 files changed, 15 insertions(+), 12 deletions(-)
> 
Reviewed-by: Hannes Reinecke <hare@suse.com>

Cheers,

Hannes
Johannes Thumshirn Oct. 29, 2018, 10:16 a.m. UTC | #3
On 25/10/18 23:10, Jens Axboe wrote:
> All drivers do unregister + cleanup, provide a helper for that.
> 
> Cc: Johannes Thumshirn <jthumshirn@suse.de>
> Cc: Benjamin Block <bblock@linux.vnet.ibm.com>
> Cc: linux-scsi@vger.kernel.org
> Signed-off-by: Jens Axboe <axboe@kernel.dk>
> ---
>  block/bsg-lib.c                     | 7 +++++++
>  drivers/scsi/scsi_transport_fc.c    | 6 ++----
>  drivers/scsi/scsi_transport_iscsi.c | 7 +++----
>  drivers/scsi/scsi_transport_sas.c   | 6 ++----
>  include/linux/bsg-lib.h             | 1 +
>  5 files changed, 15 insertions(+), 12 deletions(-)
> 
> diff --git a/block/bsg-lib.c b/block/bsg-lib.c
> index 1da011ec04e6..267f965af77a 100644
> --- a/block/bsg-lib.c
> +++ b/block/bsg-lib.c
> @@ -296,6 +296,13 @@ static void bsg_exit_rq(struct request_queue *q, struct request *req)
>  	kfree(job->reply);
>  }
>  
> +void bsg_remove_queue(struct request_queue *q)
> +{
> +	bsg_unregister_queue(q);
> +	blk_cleanup_queue(q);
> +}
> +EXPORT_SYMBOL_GPL(bsg_remove_queue);
> +
>  /**
>   * bsg_setup_queue - Create and add the bsg hooks so we can receive requests
>   * @dev: device to attach bsg device to
> diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
> index 98aaffb4c715..4d64956bb5d3 100644
> --- a/drivers/scsi/scsi_transport_fc.c
> +++ b/drivers/scsi/scsi_transport_fc.c
> @@ -3851,10 +3851,8 @@ fc_bsg_rportadd(struct Scsi_Host *shost, struct fc_rport *rport)
>  static void
>  fc_bsg_remove(struct request_queue *q)
>  {
> -	if (q) {
> -		bsg_unregister_queue(q);
> -		blk_cleanup_queue(q);
> -	}
> +	if (q)
> +		bsg_remove_queue(q);
>  }

Not sure if I'm too late to the game, but as all callers do a
"if  (q)" check, can't we just move it into bsg_remove_queue()?

Otherwise:
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Jens Axboe Oct. 29, 2018, 2:15 p.m. UTC | #4
On 10/29/18 4:16 AM, Johannes Thumshirn wrote:
> On 25/10/18 23:10, Jens Axboe wrote:
>> All drivers do unregister + cleanup, provide a helper for that.
>>
>> Cc: Johannes Thumshirn <jthumshirn@suse.de>
>> Cc: Benjamin Block <bblock@linux.vnet.ibm.com>
>> Cc: linux-scsi@vger.kernel.org
>> Signed-off-by: Jens Axboe <axboe@kernel.dk>
>> ---
>>  block/bsg-lib.c                     | 7 +++++++
>>  drivers/scsi/scsi_transport_fc.c    | 6 ++----
>>  drivers/scsi/scsi_transport_iscsi.c | 7 +++----
>>  drivers/scsi/scsi_transport_sas.c   | 6 ++----
>>  include/linux/bsg-lib.h             | 1 +
>>  5 files changed, 15 insertions(+), 12 deletions(-)
>>
>> diff --git a/block/bsg-lib.c b/block/bsg-lib.c
>> index 1da011ec04e6..267f965af77a 100644
>> --- a/block/bsg-lib.c
>> +++ b/block/bsg-lib.c
>> @@ -296,6 +296,13 @@ static void bsg_exit_rq(struct request_queue *q, struct request *req)
>>  	kfree(job->reply);
>>  }
>>  
>> +void bsg_remove_queue(struct request_queue *q)
>> +{
>> +	bsg_unregister_queue(q);
>> +	blk_cleanup_queue(q);
>> +}
>> +EXPORT_SYMBOL_GPL(bsg_remove_queue);
>> +
>>  /**
>>   * bsg_setup_queue - Create and add the bsg hooks so we can receive requests
>>   * @dev: device to attach bsg device to
>> diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
>> index 98aaffb4c715..4d64956bb5d3 100644
>> --- a/drivers/scsi/scsi_transport_fc.c
>> +++ b/drivers/scsi/scsi_transport_fc.c
>> @@ -3851,10 +3851,8 @@ fc_bsg_rportadd(struct Scsi_Host *shost, struct fc_rport *rport)
>>  static void
>>  fc_bsg_remove(struct request_queue *q)
>>  {
>> -	if (q) {
>> -		bsg_unregister_queue(q);
>> -		blk_cleanup_queue(q);
>> -	}
>> +	if (q)
>> +		bsg_remove_queue(q);
>>  }
> 
> Not sure if I'm too late to the game, but as all callers do a
> "if  (q)" check, can't we just move it into bsg_remove_queue()?

Not too late, I'll make that change.
diff mbox series

Patch

diff --git a/block/bsg-lib.c b/block/bsg-lib.c
index 1da011ec04e6..267f965af77a 100644
--- a/block/bsg-lib.c
+++ b/block/bsg-lib.c
@@ -296,6 +296,13 @@  static void bsg_exit_rq(struct request_queue *q, struct request *req)
 	kfree(job->reply);
 }
 
+void bsg_remove_queue(struct request_queue *q)
+{
+	bsg_unregister_queue(q);
+	blk_cleanup_queue(q);
+}
+EXPORT_SYMBOL_GPL(bsg_remove_queue);
+
 /**
  * bsg_setup_queue - Create and add the bsg hooks so we can receive requests
  * @dev: device to attach bsg device to
diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 98aaffb4c715..4d64956bb5d3 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -3851,10 +3851,8 @@  fc_bsg_rportadd(struct Scsi_Host *shost, struct fc_rport *rport)
 static void
 fc_bsg_remove(struct request_queue *q)
 {
-	if (q) {
-		bsg_unregister_queue(q);
-		blk_cleanup_queue(q);
-	}
+	if (q)
+		bsg_remove_queue(q);
 }
 
 
diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
index 26b11a775be9..3ead0dba5d8d 100644
--- a/drivers/scsi/scsi_transport_iscsi.c
+++ b/drivers/scsi/scsi_transport_iscsi.c
@@ -1576,10 +1576,9 @@  static int iscsi_remove_host(struct transport_container *tc,
 	struct Scsi_Host *shost = dev_to_shost(dev);
 	struct iscsi_cls_host *ihost = shost->shost_data;
 
-	if (ihost->bsg_q) {
-		bsg_unregister_queue(ihost->bsg_q);
-		blk_cleanup_queue(ihost->bsg_q);
-	}
+	if (ihost->bsg_q)
+		bsg_remove_queue(ihost->bsg_q);
+
 	return 0;
 }
 
diff --git a/drivers/scsi/scsi_transport_sas.c b/drivers/scsi/scsi_transport_sas.c
index cf6d47891d77..c46d642dc133 100644
--- a/drivers/scsi/scsi_transport_sas.c
+++ b/drivers/scsi/scsi_transport_sas.c
@@ -246,10 +246,8 @@  static int sas_host_remove(struct transport_container *tc, struct device *dev,
 	struct Scsi_Host *shost = dev_to_shost(dev);
 	struct request_queue *q = to_sas_host_attrs(shost)->q;
 
-	if (q) {
-		bsg_unregister_queue(q);
-		blk_cleanup_queue(q);
-	}
+	if (q)
+		bsg_remove_queue(q);
 
 	return 0;
 }
diff --git a/include/linux/bsg-lib.h b/include/linux/bsg-lib.h
index b13ae143e7ef..9c9b134b1fa5 100644
--- a/include/linux/bsg-lib.h
+++ b/include/linux/bsg-lib.h
@@ -73,6 +73,7 @@  void bsg_job_done(struct bsg_job *job, int result,
 		  unsigned int reply_payload_rcv_len);
 struct request_queue *bsg_setup_queue(struct device *dev, const char *name,
 		bsg_job_fn *job_fn, rq_timed_out_fn *timeout, int dd_job_size);
+void bsg_remove_queue(struct request_queue *q);
 void bsg_job_put(struct bsg_job *job);
 int __must_check bsg_job_get(struct bsg_job *job);