Skip to content

Commit 3e60913

Browse files
Xiubo LiNicholas Bellinger
authored andcommitted
tcmu: clean up the scatter helper
Add some comments to make the scatter code to be more readable, and drop unused arg to new_iov. Signed-off-by: Xiubo Li <lixiubo@cmss.chinamobile.com> Signed-off-by: Mike Christie <mchristi@redhat.com> Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
1 parent 3c0f26f commit 3e60913

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

drivers/target/target_core_user.c

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,7 @@ static inline size_t head_to_end(size_t head, size_t size)
492492
return size - head;
493493
}
494494

495-
static inline void new_iov(struct iovec **iov, int *iov_cnt,
496-
struct tcmu_dev *udev)
495+
static inline void new_iov(struct iovec **iov, int *iov_cnt)
497496
{
498497
struct iovec *iovec;
499498

@@ -546,31 +545,52 @@ static void scatter_data_area(struct tcmu_dev *udev,
546545
to = kmap_atomic(page);
547546
}
548547

549-
copy_bytes = min_t(size_t, sg_remaining,
550-
block_remaining);
548+
/*
549+
* Covert to virtual offset of the ring data area.
550+
*/
551551
to_offset = get_block_offset_user(udev, dbi,
552552
block_remaining);
553553

554+
/*
555+
* The following code will gather and map the blocks
556+
* to the same iovec when the blocks are all next to
557+
* each other.
558+
*/
559+
copy_bytes = min_t(size_t, sg_remaining,
560+
block_remaining);
554561
if (*iov_cnt != 0 &&
555562
to_offset == iov_tail(*iov)) {
563+
/*
564+
* Will append to the current iovec, because
565+
* the current block page is next to the
566+
* previous one.
567+
*/
556568
(*iov)->iov_len += copy_bytes;
557569
} else {
558-
new_iov(iov, iov_cnt, udev);
570+
/*
571+
* Will allocate a new iovec because we are
572+
* first time here or the current block page
573+
* is not next to the previous one.
574+
*/
575+
new_iov(iov, iov_cnt);
559576
(*iov)->iov_base = (void __user *)to_offset;
560577
(*iov)->iov_len = copy_bytes;
561578
}
579+
562580
if (copy_data) {
563581
offset = DATA_BLOCK_SIZE - block_remaining;
564582
memcpy(to + offset,
565583
from + sg->length - sg_remaining,
566584
copy_bytes);
567585
tcmu_flush_dcache_range(to, copy_bytes);
568586
}
587+
569588
sg_remaining -= copy_bytes;
570589
block_remaining -= copy_bytes;
571590
}
572591
kunmap_atomic(from - sg->offset);
573592
}
593+
574594
if (to)
575595
kunmap_atomic(to);
576596
}

0 commit comments

Comments
 (0)