* [PATCH 1/2] target/rd: reduce code duplication in rd_execute_rw()
@ 2015-04-04 12:24 Akinobu Mita
2015-04-04 12:24 ` [PATCH 2/2] target/rd: Don't pass imcomplete scatterlist entries to sbc_dif_verify_* Akinobu Mita
2015-04-05 10:01 ` [PATCH 1/2] target/rd: reduce code duplication in rd_execute_rw() Sagi Grimberg
0 siblings, 2 replies; 6+ messages in thread
From: Akinobu Mita @ 2015-04-04 12:24 UTC (permalink / raw)
To: target-devel
Cc: Akinobu Mita, Nicholas Bellinger, Asias He, Martin K. Petersen,
Christoph Hellwig, James E.J. Bottomley, linux-scsi
Factor out code duplication in rd_execute_rw() into a helper function
rd_do_prot_rw(). This change is required to minimize the forthcoming
fix in rd_do_prot_rw().
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Nicholas Bellinger <nab@linux-iscsi.org>
Cc: Asias He <asias@redhat.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: target-devel@vger.kernel.org
Cc: linux-scsi@vger.kernel.org
---
drivers/target/target_core_rd.c | 66 ++++++++++++++++++++---------------------
1 file changed, 32 insertions(+), 34 deletions(-)
diff --git a/drivers/target/target_core_rd.c b/drivers/target/target_core_rd.c
index 98e83ac..4d614c9 100644
--- a/drivers/target/target_core_rd.c
+++ b/drivers/target/target_core_rd.c
@@ -382,6 +382,36 @@ static struct rd_dev_sg_table *rd_get_prot_table(struct rd_dev *rd_dev, u32 page
return NULL;
}
+static sense_reason_t rd_do_prot_rw(struct se_cmd *cmd, bool is_write)
+{
+ struct se_device *se_dev = cmd->se_dev;
+ struct rd_dev *dev = RD_DEV(se_dev);
+ struct rd_dev_sg_table *prot_table;
+ struct scatterlist *prot_sg;
+ u32 sectors = cmd->data_length / se_dev->dev_attrib.block_size;
+ u32 prot_offset, prot_page;
+ u64 tmp;
+ sense_reason_t rc;
+ sense_reason_t (*dif_verify)(struct se_cmd *, sector_t, unsigned int,
+ unsigned int, struct scatterlist *, int) =
+ is_write ? sbc_dif_verify_write : sbc_dif_verify_read;
+
+ tmp = cmd->t_task_lba * se_dev->prot_length;
+ prot_offset = do_div(tmp, PAGE_SIZE);
+ prot_page = tmp;
+
+ prot_table = rd_get_prot_table(dev, prot_page);
+ if (!prot_table)
+ return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
+
+ prot_sg = &prot_table->sg_table[prot_page -
+ prot_table->page_start_offset];
+
+ rc = dif_verify(cmd, cmd->t_task_lba, sectors, 0, prot_sg, prot_offset);
+
+ return rc;
+}
+
static sense_reason_t
rd_execute_rw(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
enum dma_data_direction data_direction)
@@ -420,23 +450,7 @@ rd_execute_rw(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
cmd->t_task_lba, rd_size, rd_page, rd_offset);
if (cmd->prot_type && data_direction == DMA_TO_DEVICE) {
- struct rd_dev_sg_table *prot_table;
- struct scatterlist *prot_sg;
- u32 sectors = cmd->data_length / se_dev->dev_attrib.block_size;
- u32 prot_offset, prot_page;
-
- tmp = cmd->t_task_lba * se_dev->prot_length;
- prot_offset = do_div(tmp, PAGE_SIZE);
- prot_page = tmp;
-
- prot_table = rd_get_prot_table(dev, prot_page);
- if (!prot_table)
- return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
-
- prot_sg = &prot_table->sg_table[prot_page - prot_table->page_start_offset];
-
- rc = sbc_dif_verify_write(cmd, cmd->t_task_lba, sectors, 0,
- prot_sg, prot_offset);
+ rc = rd_do_prot_rw(cmd, true);
if (rc)
return rc;
}
@@ -503,23 +517,7 @@ rd_execute_rw(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
sg_miter_stop(&m);
if (cmd->prot_type && data_direction == DMA_FROM_DEVICE) {
- struct rd_dev_sg_table *prot_table;
- struct scatterlist *prot_sg;
- u32 sectors = cmd->data_length / se_dev->dev_attrib.block_size;
- u32 prot_offset, prot_page;
-
- tmp = cmd->t_task_lba * se_dev->prot_length;
- prot_offset = do_div(tmp, PAGE_SIZE);
- prot_page = tmp;
-
- prot_table = rd_get_prot_table(dev, prot_page);
- if (!prot_table)
- return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
-
- prot_sg = &prot_table->sg_table[prot_page - prot_table->page_start_offset];
-
- rc = sbc_dif_verify_read(cmd, cmd->t_task_lba, sectors, 0,
- prot_sg, prot_offset);
+ rc = rd_do_prot_rw(cmd, false);
if (rc)
return rc;
}
--
1.9.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] target/rd: Don't pass imcomplete scatterlist entries to sbc_dif_verify_*
2015-04-04 12:24 [PATCH 1/2] target/rd: reduce code duplication in rd_execute_rw() Akinobu Mita
@ 2015-04-04 12:24 ` Akinobu Mita
2015-04-05 10:10 ` Sagi Grimberg
2015-04-05 10:01 ` [PATCH 1/2] target/rd: reduce code duplication in rd_execute_rw() Sagi Grimberg
1 sibling, 1 reply; 6+ messages in thread
From: Akinobu Mita @ 2015-04-04 12:24 UTC (permalink / raw)
To: target-devel
Cc: Akinobu Mita, Nicholas Bellinger, Asias He, Martin K. Petersen,
Christoph Hellwig, James E.J. Bottomley, linux-scsi
The scatterlist for protection information which is passed to
sbc_dif_verify_read() or sbc_dif_verify_write() requires that
neighboring scatterlist entries are contiguous or chained so that they
can be iterated by sg_next().
However, the protection information for RD-MCP backends could be located
in the multiple scatterlist arrays when the ramdisk space is too large.
So if the read/write request straddles this boundary, sbc_dif_verify_read()
or sbc_dif_verify_write() can't iterate all scatterlist entries.
This fixes it by allocating temporary scatterlist if it is needed.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Nicholas Bellinger <nab@linux-iscsi.org>
Cc: Asias He <asias@redhat.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: target-devel@vger.kernel.org
Cc: linux-scsi@vger.kernel.org
---
drivers/target/target_core_rd.c | 39 +++++++++++++++++++++++++++++++++++----
1 file changed, 35 insertions(+), 4 deletions(-)
diff --git a/drivers/target/target_core_rd.c b/drivers/target/target_core_rd.c
index 4d614c9..19c893d 100644
--- a/drivers/target/target_core_rd.c
+++ b/drivers/target/target_core_rd.c
@@ -387,11 +387,12 @@ static sense_reason_t rd_do_prot_rw(struct se_cmd *cmd, bool is_write)
struct se_device *se_dev = cmd->se_dev;
struct rd_dev *dev = RD_DEV(se_dev);
struct rd_dev_sg_table *prot_table;
+ bool need_to_release = false;
struct scatterlist *prot_sg;
u32 sectors = cmd->data_length / se_dev->dev_attrib.block_size;
- u32 prot_offset, prot_page;
+ u32 prot_offset, prot_page, prot_npages;
u64 tmp;
- sense_reason_t rc;
+ sense_reason_t rc = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
sense_reason_t (*dif_verify)(struct se_cmd *, sector_t, unsigned int,
unsigned int, struct scatterlist *, int) =
is_write ? sbc_dif_verify_write : sbc_dif_verify_read;
@@ -404,10 +405,40 @@ static sense_reason_t rd_do_prot_rw(struct se_cmd *cmd, bool is_write)
if (!prot_table)
return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
- prot_sg = &prot_table->sg_table[prot_page -
- prot_table->page_start_offset];
+ prot_npages = DIV_ROUND_UP(prot_offset + sectors * se_dev->prot_length,
+ PAGE_SIZE);
+
+ /* prot pages straddles multiple scatterlist tables */
+ if (prot_table->page_end_offset < prot_page + prot_npages - 1) {
+ int i;
+
+ prot_sg = kcalloc(prot_npages, sizeof(*prot_sg), GFP_KERNEL);
+ if (!prot_sg)
+ return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
+
+ need_to_release = true;
+ sg_init_table(prot_sg, prot_npages);
+
+ for (i = 0; i < prot_npages; i++) {
+ if (prot_page + i > prot_table->page_end_offset) {
+ prot_table = rd_get_prot_table(dev,
+ prot_page + i);
+ if (!prot_table)
+ goto out;
+ sg_unmark_end(&prot_sg[i - 1]);
+ }
+ prot_sg[i] = prot_table->sg_table[prot_page + i -
+ prot_table->page_start_offset];
+ }
+ } else {
+ prot_sg = &prot_table->sg_table[prot_page -
+ prot_table->page_start_offset];
+ }
rc = dif_verify(cmd, cmd->t_task_lba, sectors, 0, prot_sg, prot_offset);
+out:
+ if (need_to_release)
+ kfree(prot_sg);
return rc;
}
--
1.9.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] target/rd: reduce code duplication in rd_execute_rw()
2015-04-04 12:24 [PATCH 1/2] target/rd: reduce code duplication in rd_execute_rw() Akinobu Mita
2015-04-04 12:24 ` [PATCH 2/2] target/rd: Don't pass imcomplete scatterlist entries to sbc_dif_verify_* Akinobu Mita
@ 2015-04-05 10:01 ` Sagi Grimberg
2015-04-05 12:40 ` Akinobu Mita
1 sibling, 1 reply; 6+ messages in thread
From: Sagi Grimberg @ 2015-04-05 10:01 UTC (permalink / raw)
To: Akinobu Mita, target-devel
Cc: Nicholas Bellinger, Asias He, Martin K. Petersen,
Christoph Hellwig, James E.J. Bottomley, linux-scsi
On 4/4/2015 3:24 PM, Akinobu Mita wrote:
> Factor out code duplication in rd_execute_rw() into a helper function
> rd_do_prot_rw(). This change is required to minimize the forthcoming
> fix in rd_do_prot_rw().
>
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
> Cc: Nicholas Bellinger <nab@linux-iscsi.org>
> Cc: Asias He <asias@redhat.com>
> Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
> Cc: target-devel@vger.kernel.org
> Cc: linux-scsi@vger.kernel.org
> ---
> drivers/target/target_core_rd.c | 66 ++++++++++++++++++++---------------------
> 1 file changed, 32 insertions(+), 34 deletions(-)
>
> diff --git a/drivers/target/target_core_rd.c b/drivers/target/target_core_rd.c
> index 98e83ac..4d614c9 100644
> --- a/drivers/target/target_core_rd.c
> +++ b/drivers/target/target_core_rd.c
> @@ -382,6 +382,36 @@ static struct rd_dev_sg_table *rd_get_prot_table(struct rd_dev *rd_dev, u32 page
> return NULL;
> }
>
> +static sense_reason_t rd_do_prot_rw(struct se_cmd *cmd, bool is_write)
> +{
> + struct se_device *se_dev = cmd->se_dev;
> + struct rd_dev *dev = RD_DEV(se_dev);
> + struct rd_dev_sg_table *prot_table;
> + struct scatterlist *prot_sg;
> + u32 sectors = cmd->data_length / se_dev->dev_attrib.block_size;
> + u32 prot_offset, prot_page;
> + u64 tmp;
> + sense_reason_t rc;
> + sense_reason_t (*dif_verify)(struct se_cmd *, sector_t, unsigned int,
> + unsigned int, struct scatterlist *, int) =
> + is_write ? sbc_dif_verify_write : sbc_dif_verify_read;
Hi Akinobu,
I think it would make more sense to pass the dif_verify() function
pointer instead of is_write (only used for that anyway).
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] target/rd: Don't pass imcomplete scatterlist entries to sbc_dif_verify_*
2015-04-04 12:24 ` [PATCH 2/2] target/rd: Don't pass imcomplete scatterlist entries to sbc_dif_verify_* Akinobu Mita
@ 2015-04-05 10:10 ` Sagi Grimberg
2015-04-05 12:42 ` Akinobu Mita
0 siblings, 1 reply; 6+ messages in thread
From: Sagi Grimberg @ 2015-04-05 10:10 UTC (permalink / raw)
To: Akinobu Mita, target-devel
Cc: Nicholas Bellinger, Asias He, Martin K. Petersen,
Christoph Hellwig, James E.J. Bottomley, linux-scsi
On 4/4/2015 3:24 PM, Akinobu Mita wrote:
> The scatterlist for protection information which is passed to
> sbc_dif_verify_read() or sbc_dif_verify_write() requires that
> neighboring scatterlist entries are contiguous or chained so that they
> can be iterated by sg_next().
>
> However, the protection information for RD-MCP backends could be located
> in the multiple scatterlist arrays when the ramdisk space is too large.
> So if the read/write request straddles this boundary, sbc_dif_verify_read()
> or sbc_dif_verify_write() can't iterate all scatterlist entries.
>
> This fixes it by allocating temporary scatterlist if it is needed.
>
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
> Cc: Nicholas Bellinger <nab@linux-iscsi.org>
> Cc: Asias He <asias@redhat.com>
> Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
> Cc: target-devel@vger.kernel.org
> Cc: linux-scsi@vger.kernel.org
> ---
> drivers/target/target_core_rd.c | 39 +++++++++++++++++++++++++++++++++++----
> 1 file changed, 35 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/target/target_core_rd.c b/drivers/target/target_core_rd.c
> index 4d614c9..19c893d 100644
> --- a/drivers/target/target_core_rd.c
> +++ b/drivers/target/target_core_rd.c
> @@ -387,11 +387,12 @@ static sense_reason_t rd_do_prot_rw(struct se_cmd *cmd, bool is_write)
> struct se_device *se_dev = cmd->se_dev;
> struct rd_dev *dev = RD_DEV(se_dev);
> struct rd_dev_sg_table *prot_table;
> + bool need_to_release = false;
> struct scatterlist *prot_sg;
> u32 sectors = cmd->data_length / se_dev->dev_attrib.block_size;
> - u32 prot_offset, prot_page;
> + u32 prot_offset, prot_page, prot_npages;
> u64 tmp;
> - sense_reason_t rc;
> + sense_reason_t rc = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
> sense_reason_t (*dif_verify)(struct se_cmd *, sector_t, unsigned int,
> unsigned int, struct scatterlist *, int) =
> is_write ? sbc_dif_verify_write : sbc_dif_verify_read;
> @@ -404,10 +405,40 @@ static sense_reason_t rd_do_prot_rw(struct se_cmd *cmd, bool is_write)
> if (!prot_table)
> return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
>
> - prot_sg = &prot_table->sg_table[prot_page -
> - prot_table->page_start_offset];
> + prot_npages = DIV_ROUND_UP(prot_offset + sectors * se_dev->prot_length,
> + PAGE_SIZE);
> +
> + /* prot pages straddles multiple scatterlist tables */
> + if (prot_table->page_end_offset < prot_page + prot_npages - 1) {
> + int i;
> +
> + prot_sg = kcalloc(prot_npages, sizeof(*prot_sg), GFP_KERNEL);
> + if (!prot_sg)
> + return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
> +
> + need_to_release = true;
> + sg_init_table(prot_sg, prot_npages);
> +
> + for (i = 0; i < prot_npages; i++) {
> + if (prot_page + i > prot_table->page_end_offset) {
> + prot_table = rd_get_prot_table(dev,
> + prot_page + i);
> + if (!prot_table)
> + goto out;
> + sg_unmark_end(&prot_sg[i - 1]);
> + }
> + prot_sg[i] = prot_table->sg_table[prot_page + i -
> + prot_table->page_start_offset];
> + }
> + } else {
> + prot_sg = &prot_table->sg_table[prot_page -
> + prot_table->page_start_offset];
> + }
>
> rc = dif_verify(cmd, cmd->t_task_lba, sectors, 0, prot_sg, prot_offset);
> +out:
> + if (need_to_release)
> + kfree(prot_sg);
I think it is safe to free prot_sg if you just make sure to initialize
it to NULL at declaration time, no need for 'need_to_release'.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] target/rd: reduce code duplication in rd_execute_rw()
2015-04-05 10:01 ` [PATCH 1/2] target/rd: reduce code duplication in rd_execute_rw() Sagi Grimberg
@ 2015-04-05 12:40 ` Akinobu Mita
0 siblings, 0 replies; 6+ messages in thread
From: Akinobu Mita @ 2015-04-05 12:40 UTC (permalink / raw)
To: Sagi Grimberg
Cc: target-devel, Nicholas Bellinger, Asias He, Martin K. Petersen,
Christoph Hellwig, James E.J. Bottomley,
linux-scsi@vger.kernel.org
2015-04-05 19:01 GMT+09:00 Sagi Grimberg <sagig@dev.mellanox.co.il>:
> On 4/4/2015 3:24 PM, Akinobu Mita wrote:
>>
>> Factor out code duplication in rd_execute_rw() into a helper function
>> rd_do_prot_rw(). This change is required to minimize the forthcoming
>> fix in rd_do_prot_rw().
>>
>> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
>> Cc: Nicholas Bellinger <nab@linux-iscsi.org>
>> Cc: Asias He <asias@redhat.com>
>> Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
>> Cc: Christoph Hellwig <hch@lst.de>
>> Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
>> Cc: target-devel@vger.kernel.org
>> Cc: linux-scsi@vger.kernel.org
>> ---
>> drivers/target/target_core_rd.c | 66
>> ++++++++++++++++++++---------------------
>> 1 file changed, 32 insertions(+), 34 deletions(-)
>>
>> diff --git a/drivers/target/target_core_rd.c
>> b/drivers/target/target_core_rd.c
>> index 98e83ac..4d614c9 100644
>> --- a/drivers/target/target_core_rd.c
>> +++ b/drivers/target/target_core_rd.c
>> @@ -382,6 +382,36 @@ static struct rd_dev_sg_table
>> *rd_get_prot_table(struct rd_dev *rd_dev, u32 page
>> return NULL;
>> }
>>
>> +static sense_reason_t rd_do_prot_rw(struct se_cmd *cmd, bool is_write)
>> +{
>> + struct se_device *se_dev = cmd->se_dev;
>> + struct rd_dev *dev = RD_DEV(se_dev);
>> + struct rd_dev_sg_table *prot_table;
>> + struct scatterlist *prot_sg;
>> + u32 sectors = cmd->data_length / se_dev->dev_attrib.block_size;
>> + u32 prot_offset, prot_page;
>> + u64 tmp;
>> + sense_reason_t rc;
>> + sense_reason_t (*dif_verify)(struct se_cmd *, sector_t, unsigned
>> int,
>> + unsigned int, struct scatterlist *, int) =
>> + is_write ? sbc_dif_verify_write : sbc_dif_verify_read;
>
>
> Hi Akinobu,
>
> I think it would make more sense to pass the dif_verify() function
> pointer instead of is_write (only used for that anyway).
Make sense. I'll update this series with that change.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] target/rd: Don't pass imcomplete scatterlist entries to sbc_dif_verify_*
2015-04-05 10:10 ` Sagi Grimberg
@ 2015-04-05 12:42 ` Akinobu Mita
0 siblings, 0 replies; 6+ messages in thread
From: Akinobu Mita @ 2015-04-05 12:42 UTC (permalink / raw)
To: Sagi Grimberg
Cc: target-devel, Nicholas Bellinger, Asias He, Martin K. Petersen,
Christoph Hellwig, James E.J. Bottomley,
linux-scsi@vger.kernel.org
2015-04-05 19:10 GMT+09:00 Sagi Grimberg <sagig@dev.mellanox.co.il>:
> On 4/4/2015 3:24 PM, Akinobu Mita wrote:
>>
>> The scatterlist for protection information which is passed to
>> sbc_dif_verify_read() or sbc_dif_verify_write() requires that
>> neighboring scatterlist entries are contiguous or chained so that they
>> can be iterated by sg_next().
>>
>> However, the protection information for RD-MCP backends could be located
>> in the multiple scatterlist arrays when the ramdisk space is too large.
>> So if the read/write request straddles this boundary,
>> sbc_dif_verify_read()
>> or sbc_dif_verify_write() can't iterate all scatterlist entries.
>>
>> This fixes it by allocating temporary scatterlist if it is needed.
>>
>> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
>> Cc: Nicholas Bellinger <nab@linux-iscsi.org>
>> Cc: Asias He <asias@redhat.com>
>> Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
>> Cc: Christoph Hellwig <hch@lst.de>
>> Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
>> Cc: target-devel@vger.kernel.org
>> Cc: linux-scsi@vger.kernel.org
>> ---
>> drivers/target/target_core_rd.c | 39
>> +++++++++++++++++++++++++++++++++++----
>> 1 file changed, 35 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/target/target_core_rd.c
>> b/drivers/target/target_core_rd.c
>> index 4d614c9..19c893d 100644
>> --- a/drivers/target/target_core_rd.c
>> +++ b/drivers/target/target_core_rd.c
>> @@ -387,11 +387,12 @@ static sense_reason_t rd_do_prot_rw(struct se_cmd
>> *cmd, bool is_write)
>> struct se_device *se_dev = cmd->se_dev;
>> struct rd_dev *dev = RD_DEV(se_dev);
>> struct rd_dev_sg_table *prot_table;
>> + bool need_to_release = false;
>> struct scatterlist *prot_sg;
>> u32 sectors = cmd->data_length / se_dev->dev_attrib.block_size;
>> - u32 prot_offset, prot_page;
>> + u32 prot_offset, prot_page, prot_npages;
>> u64 tmp;
>> - sense_reason_t rc;
>> + sense_reason_t rc = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
>> sense_reason_t (*dif_verify)(struct se_cmd *, sector_t, unsigned
>> int,
>> unsigned int, struct scatterlist *, int) =
>> is_write ? sbc_dif_verify_write : sbc_dif_verify_read;
>> @@ -404,10 +405,40 @@ static sense_reason_t rd_do_prot_rw(struct se_cmd
>> *cmd, bool is_write)
>> if (!prot_table)
>> return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
>>
>> - prot_sg = &prot_table->sg_table[prot_page -
>> - prot_table->page_start_offset];
>> + prot_npages = DIV_ROUND_UP(prot_offset + sectors *
>> se_dev->prot_length,
>> + PAGE_SIZE);
>> +
>> + /* prot pages straddles multiple scatterlist tables */
>> + if (prot_table->page_end_offset < prot_page + prot_npages - 1) {
>> + int i;
>> +
>> + prot_sg = kcalloc(prot_npages, sizeof(*prot_sg),
>> GFP_KERNEL);
>> + if (!prot_sg)
>> + return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
>> +
>> + need_to_release = true;
>> + sg_init_table(prot_sg, prot_npages);
>> +
>> + for (i = 0; i < prot_npages; i++) {
>> + if (prot_page + i > prot_table->page_end_offset) {
>> + prot_table = rd_get_prot_table(dev,
>> + prot_page
>> + i);
>> + if (!prot_table)
>> + goto out;
>> + sg_unmark_end(&prot_sg[i - 1]);
>> + }
>> + prot_sg[i] = prot_table->sg_table[prot_page + i -
>> +
>> prot_table->page_start_offset];
>> + }
>> + } else {
>> + prot_sg = &prot_table->sg_table[prot_page -
>> +
>> prot_table->page_start_offset];
>> + }
>>
>> rc = dif_verify(cmd, cmd->t_task_lba, sectors, 0, prot_sg,
>> prot_offset);
>> +out:
>> + if (need_to_release)
>> + kfree(prot_sg);
>
>
> I think it is safe to free prot_sg if you just make sure to initialize
> it to NULL at declaration time, no need for 'need_to_release'.
'need_to_release' is required to avoid kfree when 'prot_sg' is
initialized to a pointer in the real prot space (i.e. "else" case above).
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-04-05 12:42 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-04 12:24 [PATCH 1/2] target/rd: reduce code duplication in rd_execute_rw() Akinobu Mita
2015-04-04 12:24 ` [PATCH 2/2] target/rd: Don't pass imcomplete scatterlist entries to sbc_dif_verify_* Akinobu Mita
2015-04-05 10:10 ` Sagi Grimberg
2015-04-05 12:42 ` Akinobu Mita
2015-04-05 10:01 ` [PATCH 1/2] target/rd: reduce code duplication in rd_execute_rw() Sagi Grimberg
2015-04-05 12:40 ` Akinobu Mita
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox