diff options
author | Xiubo Li <lixiubo@cmss.chinamobile.com> | 2017-11-28 13:40:36 -0500 |
---|---|---|
committer | Nicholas Bellinger <nab@linux-iscsi.org> | 2018-01-12 18:07:16 -0500 |
commit | 3e60913579b2fefa74eeb3269426e864f4afa7e7 (patch) | |
tree | 6b6f6b5ce54e2a90a45d36fd70bc7fc103f869f3 /drivers/target | |
parent | 3c0f26ff9d040c6193b33689bbc03103854dba4d (diff) |
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>
Diffstat (limited to 'drivers/target')
-rw-r--r-- | drivers/target/target_core_user.c | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c index 5d1daea51079..8d0dc471fce8 100644 --- a/drivers/target/target_core_user.c +++ b/drivers/target/target_core_user.c | |||
@@ -492,8 +492,7 @@ static inline size_t head_to_end(size_t head, size_t size) | |||
492 | return size - head; | 492 | return size - head; |
493 | } | 493 | } |
494 | 494 | ||
495 | static inline void new_iov(struct iovec **iov, int *iov_cnt, | 495 | static inline void new_iov(struct iovec **iov, int *iov_cnt) |
496 | struct tcmu_dev *udev) | ||
497 | { | 496 | { |
498 | struct iovec *iovec; | 497 | struct iovec *iovec; |
499 | 498 | ||
@@ -546,19 +545,38 @@ static void scatter_data_area(struct tcmu_dev *udev, | |||
546 | to = kmap_atomic(page); | 545 | to = kmap_atomic(page); |
547 | } | 546 | } |
548 | 547 | ||
549 | copy_bytes = min_t(size_t, sg_remaining, | 548 | /* |
550 | block_remaining); | 549 | * Covert to virtual offset of the ring data area. |
550 | */ | ||
551 | to_offset = get_block_offset_user(udev, dbi, | 551 | to_offset = get_block_offset_user(udev, dbi, |
552 | block_remaining); | 552 | block_remaining); |
553 | 553 | ||
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); | ||
554 | if (*iov_cnt != 0 && | 561 | if (*iov_cnt != 0 && |
555 | to_offset == iov_tail(*iov)) { | 562 | 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 | */ | ||
556 | (*iov)->iov_len += copy_bytes; | 568 | (*iov)->iov_len += copy_bytes; |
557 | } else { | 569 | } 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); | ||
559 | (*iov)->iov_base = (void __user *)to_offset; | 576 | (*iov)->iov_base = (void __user *)to_offset; |
560 | (*iov)->iov_len = copy_bytes; | 577 | (*iov)->iov_len = copy_bytes; |
561 | } | 578 | } |
579 | |||
562 | if (copy_data) { | 580 | if (copy_data) { |
563 | offset = DATA_BLOCK_SIZE - block_remaining; | 581 | offset = DATA_BLOCK_SIZE - block_remaining; |
564 | memcpy(to + offset, | 582 | memcpy(to + offset, |
@@ -566,11 +584,13 @@ static void scatter_data_area(struct tcmu_dev *udev, | |||
566 | copy_bytes); | 584 | copy_bytes); |
567 | tcmu_flush_dcache_range(to, copy_bytes); | 585 | tcmu_flush_dcache_range(to, copy_bytes); |
568 | } | 586 | } |
587 | |||
569 | sg_remaining -= copy_bytes; | 588 | sg_remaining -= copy_bytes; |
570 | block_remaining -= copy_bytes; | 589 | block_remaining -= copy_bytes; |
571 | } | 590 | } |
572 | kunmap_atomic(from - sg->offset); | 591 | kunmap_atomic(from - sg->offset); |
573 | } | 592 | } |
593 | |||
574 | if (to) | 594 | if (to) |
575 | kunmap_atomic(to); | 595 | kunmap_atomic(to); |
576 | } | 596 | } |