[PATCH 1/4] scsi: explicitly release bidi buffers

2014-05-01 Thread Christoph Hellwig
Instead of trying to guess when we have a BIDI buffer in scsi_release_buffers
add a function to explicitly free the BIDI ressoures in the one place that
handles them.  This avoids needing a special __scsi_release_buffers for the
case where we already have freed the request as well.

Signed-off-by: Christoph Hellwig h...@lst.de
Reviewed-by: Mike Christie micha...@cs.wisc.edu
---
 drivers/scsi/scsi_lib.c |   47 ---
 1 file changed, 20 insertions(+), 27 deletions(-)

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 9db097a..f416b59 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -512,8 +512,6 @@ void scsi_run_host_queues(struct Scsi_Host *shost)
scsi_run_queue(sdev-request_queue);
 }
 
-static void __scsi_release_buffers(struct scsi_cmnd *, int);
-
 /*
  * Function:scsi_end_request()
  *
@@ -569,7 +567,7 @@ static struct scsi_cmnd *scsi_end_request(struct scsi_cmnd 
*cmd, int error,
 * This will goose the queue request function at the end, so we don't
 * need to worry about launching another command.
 */
-   __scsi_release_buffers(cmd, 0);
+   scsi_release_buffers(cmd);
scsi_next_command(cmd);
return NULL;
 }
@@ -625,30 +623,10 @@ static void scsi_free_sgtable(struct scsi_data_buffer 
*sdb)
__sg_free_table(sdb-table, SCSI_MAX_SG_SEGMENTS, scsi_sg_free);
 }
 
-static void __scsi_release_buffers(struct scsi_cmnd *cmd, int do_bidi_check)
-{
-
-   if (cmd-sdb.table.nents)
-   scsi_free_sgtable(cmd-sdb);
-
-   memset(cmd-sdb, 0, sizeof(cmd-sdb));
-
-   if (do_bidi_check  scsi_bidi_cmnd(cmd)) {
-   struct scsi_data_buffer *bidi_sdb =
-   cmd-request-next_rq-special;
-   scsi_free_sgtable(bidi_sdb);
-   kmem_cache_free(scsi_sdb_cache, bidi_sdb);
-   cmd-request-next_rq-special = NULL;
-   }
-
-   if (scsi_prot_sg_count(cmd))
-   scsi_free_sgtable(cmd-prot_sdb);
-}
-
 /*
  * Function:scsi_release_buffers()
  *
- * Purpose: Completion processing for block device I/O requests.
+ * Purpose: Free resources allocate for a scsi_command.
  *
  * Arguments:   cmd- command that we are bailing.
  *
@@ -659,15 +637,29 @@ static void __scsi_release_buffers(struct scsi_cmnd *cmd, 
int do_bidi_check)
  * Notes:   In the event that an upper level driver rejects a
  * command, we must release resources allocated during
  * the __init_io() function.  Primarily this would involve
- * the scatter-gather table, and potentially any bounce
- * buffers.
+ * the scatter-gather table.
  */
 void scsi_release_buffers(struct scsi_cmnd *cmd)
 {
-   __scsi_release_buffers(cmd, 1);
+   if (cmd-sdb.table.nents)
+   scsi_free_sgtable(cmd-sdb);
+
+   memset(cmd-sdb, 0, sizeof(cmd-sdb));
+
+   if (scsi_prot_sg_count(cmd))
+   scsi_free_sgtable(cmd-prot_sdb);
 }
 EXPORT_SYMBOL(scsi_release_buffers);
 
+static void scsi_release_bidi_buffers(struct scsi_cmnd *cmd)
+{
+   struct scsi_data_buffer *bidi_sdb = cmd-request-next_rq-special;
+
+   scsi_free_sgtable(bidi_sdb);
+   kmem_cache_free(scsi_sdb_cache, bidi_sdb);
+   cmd-request-next_rq-special = NULL;
+}
+
 /**
  * __scsi_error_from_host_byte - translate SCSI error code into errno
  * @cmd:   SCSI command (unused)
@@ -801,6 +793,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int 
good_bytes)
req-next_rq-resid_len = scsi_in(cmd)-resid;
 
scsi_release_buffers(cmd);
+   scsi_release_bidi_buffers(cmd);
blk_end_request_all(req, 0);
 
scsi_next_command(cmd);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/4] scsi: explicitly release bidi buffers

2014-03-31 Thread Christoph Hellwig
On Mon, Mar 31, 2014 at 12:58:01AM -0500, Mike Christie wrote:
 
 Hey,
 
 I just wanted to double check that the only time we do bidi requests is
 when they come through as REQ_TYPE_BLOCK_PC requests. I saw some of the
 code comments on the init side that indicated that, but there was that
 scsi_end_request() - scsi_release_buffers() - __scsi_release_buffers()
  call which then did not make sense because we were passing in 1 for the
 bidi check argument.

We only support BIDI for REQ_TYPE_BLOCK_PC requests, and scsi_io_completion
enforces this:

if (req-cmd_type == REQ_TYPE_BLOCK_PC) { /* SG_IO ioctl from block 
level */
...

if (scsi_bidi_cmnd(cmd)) {
...
 end_io and return 
}
}

/* no bidi support for !REQ_TYPE_BLOCK_PC yet */
BUG_ON(blk_bidi_rq(req));

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/4] scsi: explicitly release bidi buffers

2014-03-30 Thread Mike Christie
On 03/27/2014 11:14 AM, Christoph Hellwig wrote:
 +static void scsi_release_bidi_buffers(struct scsi_cmnd *cmd)
 +{
 + struct scsi_data_buffer *bidi_sdb = cmd-request-next_rq-special;
 +
 + scsi_free_sgtable(bidi_sdb);
 + kmem_cache_free(scsi_sdb_cache, bidi_sdb);
 + cmd-request-next_rq-special = NULL;
 +}
 +
  /**
   * __scsi_error_from_host_byte - translate SCSI error code into errno
   * @cmd: SCSI command (unused)
 @@ -800,6 +792,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned 
 int good_bytes)
   req-next_rq-resid_len = scsi_in(cmd)-resid;
  
   scsi_release_buffers(cmd);
 + scsi_release_bidi_buffers(cmd);
   blk_end_request_all(req, 0);
  
   scsi_next_command(cmd);
 

Hey,

I just wanted to double check that the only time we do bidi requests is
when they come through as REQ_TYPE_BLOCK_PC requests. I saw some of the
code comments on the init side that indicated that, but there was that
scsi_end_request() - scsi_release_buffers() - __scsi_release_buffers()
 call which then did not make sense because we were passing in 1 for the
bidi check argument.
--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/4] scsi: explicitly release bidi buffers

2014-03-27 Thread Christoph Hellwig
Instead of trying to guess when we have a BIDI buffer in scsi_release_buffers
add a function to explicitly free the BIDI ressoures in the one place that
handles them.  This avoids needing a special __scsi_release_buffers for the
case where we already have freed the request as well.

Signed-off-by: Christoph Hellwig h...@lst.de
---
 drivers/scsi/scsi_lib.c |   47 ---
 1 file changed, 20 insertions(+), 27 deletions(-)

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 5681c05..5454d7d 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -511,8 +511,6 @@ void scsi_run_host_queues(struct Scsi_Host *shost)
scsi_run_queue(sdev-request_queue);
 }
 
-static void __scsi_release_buffers(struct scsi_cmnd *, int);
-
 /*
  * Function:scsi_end_request()
  *
@@ -568,7 +566,7 @@ static struct scsi_cmnd *scsi_end_request(struct scsi_cmnd 
*cmd, int error,
 * This will goose the queue request function at the end, so we don't
 * need to worry about launching another command.
 */
-   __scsi_release_buffers(cmd, 0);
+   scsi_release_buffers(cmd);
scsi_next_command(cmd);
return NULL;
 }
@@ -624,30 +622,10 @@ static void scsi_free_sgtable(struct scsi_data_buffer 
*sdb)
__sg_free_table(sdb-table, SCSI_MAX_SG_SEGMENTS, scsi_sg_free);
 }
 
-static void __scsi_release_buffers(struct scsi_cmnd *cmd, int do_bidi_check)
-{
-
-   if (cmd-sdb.table.nents)
-   scsi_free_sgtable(cmd-sdb);
-
-   memset(cmd-sdb, 0, sizeof(cmd-sdb));
-
-   if (do_bidi_check  scsi_bidi_cmnd(cmd)) {
-   struct scsi_data_buffer *bidi_sdb =
-   cmd-request-next_rq-special;
-   scsi_free_sgtable(bidi_sdb);
-   kmem_cache_free(scsi_sdb_cache, bidi_sdb);
-   cmd-request-next_rq-special = NULL;
-   }
-
-   if (scsi_prot_sg_count(cmd))
-   scsi_free_sgtable(cmd-prot_sdb);
-}
-
 /*
  * Function:scsi_release_buffers()
  *
- * Purpose: Completion processing for block device I/O requests.
+ * Purpose: Free resources allocate for a scsi_command.
  *
  * Arguments:   cmd- command that we are bailing.
  *
@@ -658,15 +636,29 @@ static void __scsi_release_buffers(struct scsi_cmnd *cmd, 
int do_bidi_check)
  * Notes:   In the event that an upper level driver rejects a
  * command, we must release resources allocated during
  * the __init_io() function.  Primarily this would involve
- * the scatter-gather table, and potentially any bounce
- * buffers.
+ * the scatter-gather table.
  */
 void scsi_release_buffers(struct scsi_cmnd *cmd)
 {
-   __scsi_release_buffers(cmd, 1);
+   if (cmd-sdb.table.nents)
+   scsi_free_sgtable(cmd-sdb);
+
+   memset(cmd-sdb, 0, sizeof(cmd-sdb));
+
+   if (scsi_prot_sg_count(cmd))
+   scsi_free_sgtable(cmd-prot_sdb);
 }
 EXPORT_SYMBOL(scsi_release_buffers);
 
+static void scsi_release_bidi_buffers(struct scsi_cmnd *cmd)
+{
+   struct scsi_data_buffer *bidi_sdb = cmd-request-next_rq-special;
+
+   scsi_free_sgtable(bidi_sdb);
+   kmem_cache_free(scsi_sdb_cache, bidi_sdb);
+   cmd-request-next_rq-special = NULL;
+}
+
 /**
  * __scsi_error_from_host_byte - translate SCSI error code into errno
  * @cmd:   SCSI command (unused)
@@ -800,6 +792,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int 
good_bytes)
req-next_rq-resid_len = scsi_in(cmd)-resid;
 
scsi_release_buffers(cmd);
+   scsi_release_bidi_buffers(cmd);
blk_end_request_all(req, 0);
 
scsi_next_command(cmd);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html