* [PATCH] tcmu: Skip Data-Out blocks before gathering Data-In buffer for BIDI case
@ 2017-03-31 2:35 lixiubo
2017-03-31 20:46 ` Ilias Tsitsimpis
2017-04-02 23:20 ` Nicholas A. Bellinger
0 siblings, 2 replies; 3+ messages in thread
From: lixiubo @ 2017-03-31 2:35 UTC (permalink / raw)
To: nab
Cc: mchristi, agrover, iliastsi, namei.unix, sheng, linux-scsi,
target-devel, linux-kernel, Xiubo Li
From: Xiubo Li <lixiubo@cmss.chinamobile.com>
For the bidirectional case, the Data-Out buffer blocks will always at
the head of the tcmu_cmd's bitmap, and before gathering the Data-In
buffer, first of all it should skip the Data-Out ones, or the device
supporting BIDI commands won't work.
Fixed: 26418649eead ("target/user: Introduce data_bitmap, replace
data_length/data_head/data_tail")
Reported-by: Ilias Tsitsimpis <iliastsi@arrikto.com>
Signed-off-by: Xiubo Li <lixiubo@cmss.chinamobile.com>
---
drivers/target/target_core_user.c | 48 +++++++++++++++++++++++++++------------
1 file changed, 33 insertions(+), 15 deletions(-)
diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c
index ede815c..63e3a1b 100644
--- a/drivers/target/target_core_user.c
+++ b/drivers/target/target_core_user.c
@@ -311,24 +311,50 @@ static void free_data_area(struct tcmu_dev *udev, struct tcmu_cmd *cmd)
DATA_BLOCK_BITS);
}
-static void gather_data_area(struct tcmu_dev *udev, unsigned long *cmd_bitmap,
- struct scatterlist *data_sg, unsigned int data_nents)
+static void gather_data_area(struct tcmu_dev *udev, struct tcmu_cmd *cmd,
+ bool bidi)
{
+ struct se_cmd *se_cmd = cmd->se_cmd;
int i, block;
int block_remaining = 0;
void *from, *to;
size_t copy_bytes, from_offset;
- struct scatterlist *sg;
+ struct scatterlist *sg, *data_sg;
+ unsigned int data_nents;
+ DECLARE_BITMAP(bitmap, DATA_BLOCK_BITS);
+
+ bitmap_copy(bitmap, cmd->data_bitmap, DATA_BLOCK_BITS);
+
+ if (!bidi) {
+ data_sg = se_cmd->t_data_sg;
+ data_nents = se_cmd->t_data_nents;
+ } else {
+ uint32_t count;
+
+ /*
+ * For bidi case, the first count blocks are for Data-Out
+ * buffer blocks, and before gathering the Data-In buffer
+ * the Data-Out buffer blocks should be discarded.
+ */
+ count = DIV_ROUND_UP(se_cmd->data_length, DATA_BLOCK_SIZE);
+ while (count--) {
+ block = find_first_bit(bitmap, DATA_BLOCK_BITS);
+ clear_bit(block, bitmap);
+ }
+
+ data_sg = se_cmd->t_bidi_data_sg;
+ data_nents = se_cmd->t_bidi_data_nents;
+ }
for_each_sg(data_sg, sg, data_nents, i) {
int sg_remaining = sg->length;
to = kmap_atomic(sg_page(sg)) + sg->offset;
while (sg_remaining > 0) {
if (block_remaining == 0) {
- block = find_first_bit(cmd_bitmap,
+ block = find_first_bit(bitmap,
DATA_BLOCK_BITS);
block_remaining = DATA_BLOCK_SIZE;
- clear_bit(block, cmd_bitmap);
+ clear_bit(block, bitmap);
}
copy_bytes = min_t(size_t, sg_remaining,
block_remaining);
@@ -610,19 +636,11 @@ static void tcmu_handle_completion(struct tcmu_cmd *cmd, struct tcmu_cmd_entry *
se_cmd->scsi_sense_length);
free_data_area(udev, cmd);
} else if (se_cmd->se_cmd_flags & SCF_BIDI) {
- DECLARE_BITMAP(bitmap, DATA_BLOCK_BITS);
-
/* Get Data-In buffer before clean up */
- bitmap_copy(bitmap, cmd->data_bitmap, DATA_BLOCK_BITS);
- gather_data_area(udev, bitmap,
- se_cmd->t_bidi_data_sg, se_cmd->t_bidi_data_nents);
+ gather_data_area(udev, cmd, true);
free_data_area(udev, cmd);
} else if (se_cmd->data_direction == DMA_FROM_DEVICE) {
- DECLARE_BITMAP(bitmap, DATA_BLOCK_BITS);
-
- bitmap_copy(bitmap, cmd->data_bitmap, DATA_BLOCK_BITS);
- gather_data_area(udev, bitmap,
- se_cmd->t_data_sg, se_cmd->t_data_nents);
+ gather_data_area(udev, cmd, false);
free_data_area(udev, cmd);
} else if (se_cmd->data_direction == DMA_TO_DEVICE) {
free_data_area(udev, cmd);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] tcmu: Skip Data-Out blocks before gathering Data-In buffer for BIDI case
2017-03-31 2:35 [PATCH] tcmu: Skip Data-Out blocks before gathering Data-In buffer for BIDI case lixiubo
@ 2017-03-31 20:46 ` Ilias Tsitsimpis
2017-04-02 23:20 ` Nicholas A. Bellinger
1 sibling, 0 replies; 3+ messages in thread
From: Ilias Tsitsimpis @ 2017-03-31 20:46 UTC (permalink / raw)
To: lixiubo
Cc: nab, mchristi, agrover, namei.unix, sheng, linux-scsi,
target-devel, linux-kernel
Hi Xiubo,
On Fri, Mar 31, 2017 at 10:35AM, lixiubo@cmss.chinamobile.com wrote:
> From: Xiubo Li <lixiubo@cmss.chinamobile.com>
>
> For the bidirectional case, the Data-Out buffer blocks will always at
> the head of the tcmu_cmd's bitmap, and before gathering the Data-In
> buffer, first of all it should skip the Data-Out ones, or the device
> supporting BIDI commands won't work.
>
> Fixed: 26418649eead ("target/user: Introduce data_bitmap, replace
> data_length/data_head/data_tail")
> Reported-by: Ilias Tsitsimpis <iliastsi@arrikto.com>
> Signed-off-by: Xiubo Li <lixiubo@cmss.chinamobile.com>
Thanks for taking care of this.
Tested-by: Ilias Tsitsimpis <iliastsi@arrikto.com>
Best,
--
Ilias
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] tcmu: Skip Data-Out blocks before gathering Data-In buffer for BIDI case
2017-03-31 2:35 [PATCH] tcmu: Skip Data-Out blocks before gathering Data-In buffer for BIDI case lixiubo
2017-03-31 20:46 ` Ilias Tsitsimpis
@ 2017-04-02 23:20 ` Nicholas A. Bellinger
1 sibling, 0 replies; 3+ messages in thread
From: Nicholas A. Bellinger @ 2017-04-02 23:20 UTC (permalink / raw)
To: lixiubo
Cc: mchristi, agrover, iliastsi, namei.unix, sheng, linux-scsi,
target-devel, linux-kernel
On Fri, 2017-03-31 at 10:35 +0800, lixiubo@cmss.chinamobile.com wrote:
> From: Xiubo Li <lixiubo@cmss.chinamobile.com>
>
> For the bidirectional case, the Data-Out buffer blocks will always at
> the head of the tcmu_cmd's bitmap, and before gathering the Data-In
> buffer, first of all it should skip the Data-Out ones, or the device
> supporting BIDI commands won't work.
>
> Fixed: 26418649eead ("target/user: Introduce data_bitmap, replace
> data_length/data_head/data_tail")
> Reported-by: Ilias Tsitsimpis <iliastsi@arrikto.com>
> Signed-off-by: Xiubo Li <lixiubo@cmss.chinamobile.com>
> ---
> drivers/target/target_core_user.c | 48 +++++++++++++++++++++++++++------------
> 1 file changed, 33 insertions(+), 15 deletions(-)
Applied to target-pending/master, with a CC' to linux-4.6.y stable.
Thanks Xiubo + Ilias.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-04-02 23:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-31 2:35 [PATCH] tcmu: Skip Data-Out blocks before gathering Data-In buffer for BIDI case lixiubo
2017-03-31 20:46 ` Ilias Tsitsimpis
2017-04-02 23:20 ` Nicholas A. Bellinger
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.