Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

libceph: drop last_piece flag from ceph_msg_data_cursor

ceph_msg_data_next is always passed a NULL pointer for this field. Some
of the "next" operations look at it in order to determine the length,
but we can just take the min of the data on the page or cursor->resid.

Signed-off-by: Jeff Layton <jlayton@kernel.org>
Reviewed-by: Xiubo Li <xiubli@redhat.com>
Reviewed-by: Ilya Dryomov <idryomov@gmail.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>

authored by

Jeff Layton and committed by
Ilya Dryomov
da4ab869 4fe89d07

+10 -42
+1 -3
include/linux/ceph/messenger.h
··· 207 207 208 208 struct ceph_msg_data *data; /* current data item */ 209 209 size_t resid; /* bytes not yet consumed */ 210 - bool last_piece; /* current is last piece */ 211 210 bool need_crc; /* crc update needed */ 212 211 union { 213 212 #ifdef CONFIG_BLOCK ··· 497 498 void ceph_msg_data_cursor_init(struct ceph_msg_data_cursor *cursor, 498 499 struct ceph_msg *msg, size_t length); 499 500 struct page *ceph_msg_data_next(struct ceph_msg_data_cursor *cursor, 500 - size_t *page_offset, size_t *length, 501 - bool *last_piece); 501 + size_t *page_offset, size_t *length); 502 502 void ceph_msg_data_advance(struct ceph_msg_data_cursor *cursor, size_t bytes); 503 503 504 504 u32 ceph_crc32c_page(u32 crc, struct page *page, unsigned int page_offset,
+5 -35
net/ceph/messenger.c
··· 728 728 it->iter.bi_size = cursor->resid; 729 729 730 730 BUG_ON(cursor->resid < bio_iter_len(it->bio, it->iter)); 731 - cursor->last_piece = cursor->resid == bio_iter_len(it->bio, it->iter); 732 731 } 733 732 734 733 static struct page *ceph_msg_data_bio_next(struct ceph_msg_data_cursor *cursor, ··· 753 754 cursor->resid -= bytes; 754 755 bio_advance_iter(it->bio, &it->iter, bytes); 755 756 756 - if (!cursor->resid) { 757 - BUG_ON(!cursor->last_piece); 757 + if (!cursor->resid) 758 758 return false; /* no more data */ 759 - } 760 759 761 760 if (!bytes || (it->iter.bi_size && it->iter.bi_bvec_done && 762 761 page == bio_iter_page(it->bio, it->iter))) ··· 767 770 it->iter.bi_size = cursor->resid; 768 771 } 769 772 770 - BUG_ON(cursor->last_piece); 771 773 BUG_ON(cursor->resid < bio_iter_len(it->bio, it->iter)); 772 - cursor->last_piece = cursor->resid == bio_iter_len(it->bio, it->iter); 773 774 return true; 774 775 } 775 776 #endif /* CONFIG_BLOCK */ ··· 783 788 cursor->bvec_iter.bi_size = cursor->resid; 784 789 785 790 BUG_ON(cursor->resid < bvec_iter_len(bvecs, cursor->bvec_iter)); 786 - cursor->last_piece = 787 - cursor->resid == bvec_iter_len(bvecs, cursor->bvec_iter); 788 791 } 789 792 790 793 static struct page *ceph_msg_data_bvecs_next(struct ceph_msg_data_cursor *cursor, ··· 808 815 cursor->resid -= bytes; 809 816 bvec_iter_advance(bvecs, &cursor->bvec_iter, bytes); 810 817 811 - if (!cursor->resid) { 812 - BUG_ON(!cursor->last_piece); 818 + if (!cursor->resid) 813 819 return false; /* no more data */ 814 - } 815 820 816 821 if (!bytes || (cursor->bvec_iter.bi_bvec_done && 817 822 page == bvec_iter_page(bvecs, cursor->bvec_iter))) 818 823 return false; /* more bytes to process in this segment */ 819 824 820 - BUG_ON(cursor->last_piece); 821 825 BUG_ON(cursor->resid < bvec_iter_len(bvecs, cursor->bvec_iter)); 822 - cursor->last_piece = 823 - cursor->resid == bvec_iter_len(bvecs, cursor->bvec_iter); 824 826 return true; 825 827 } 826 828 ··· 841 853 BUG_ON(page_count > (int)USHRT_MAX); 842 854 cursor->page_count = (unsigned short)page_count; 843 855 BUG_ON(length > SIZE_MAX - cursor->page_offset); 844 - cursor->last_piece = cursor->page_offset + cursor->resid <= PAGE_SIZE; 845 856 } 846 857 847 858 static struct page * ··· 855 868 BUG_ON(cursor->page_offset >= PAGE_SIZE); 856 869 857 870 *page_offset = cursor->page_offset; 858 - if (cursor->last_piece) 859 - *length = cursor->resid; 860 - else 861 - *length = PAGE_SIZE - *page_offset; 862 - 871 + *length = min_t(size_t, cursor->resid, PAGE_SIZE - *page_offset); 863 872 return data->pages[cursor->page_index]; 864 873 } 865 874 ··· 880 897 881 898 BUG_ON(cursor->page_index >= cursor->page_count); 882 899 cursor->page_index++; 883 - cursor->last_piece = cursor->resid <= PAGE_SIZE; 884 - 885 900 return true; 886 901 } 887 902 ··· 909 928 cursor->resid = min(length, pagelist->length); 910 929 cursor->page = page; 911 930 cursor->offset = 0; 912 - cursor->last_piece = cursor->resid <= PAGE_SIZE; 913 931 } 914 932 915 933 static struct page * ··· 928 948 929 949 /* offset of first page in pagelist is always 0 */ 930 950 *page_offset = cursor->offset & ~PAGE_MASK; 931 - if (cursor->last_piece) 932 - *length = cursor->resid; 933 - else 934 - *length = PAGE_SIZE - *page_offset; 935 - 951 + *length = min_t(size_t, cursor->resid, PAGE_SIZE - *page_offset); 936 952 return cursor->page; 937 953 } 938 954 ··· 961 985 962 986 BUG_ON(list_is_last(&cursor->page->lru, &pagelist->head)); 963 987 cursor->page = list_next_entry(cursor->page, lru); 964 - cursor->last_piece = cursor->resid <= PAGE_SIZE; 965 - 966 988 return true; 967 989 } 968 990 ··· 1018 1044 * Indicate whether this is the last piece in this data item. 1019 1045 */ 1020 1046 struct page *ceph_msg_data_next(struct ceph_msg_data_cursor *cursor, 1021 - size_t *page_offset, size_t *length, 1022 - bool *last_piece) 1047 + size_t *page_offset, size_t *length) 1023 1048 { 1024 1049 struct page *page; 1025 1050 ··· 1047 1074 BUG_ON(*page_offset + *length > PAGE_SIZE); 1048 1075 BUG_ON(!*length); 1049 1076 BUG_ON(*length > cursor->resid); 1050 - if (last_piece) 1051 - *last_piece = cursor->last_piece; 1052 1077 1053 1078 return page; 1054 1079 } ··· 1083 1112 cursor->total_resid -= bytes; 1084 1113 1085 1114 if (!cursor->resid && cursor->total_resid) { 1086 - WARN_ON(!cursor->last_piece); 1087 1115 cursor->data++; 1088 1116 __ceph_msg_data_cursor_init(cursor); 1089 1117 new_piece = true;
+3 -3
net/ceph/messenger_v1.c
··· 495 495 continue; 496 496 } 497 497 498 - page = ceph_msg_data_next(cursor, &page_offset, &length, NULL); 498 + page = ceph_msg_data_next(cursor, &page_offset, &length); 499 499 if (length == cursor->total_resid) 500 500 more = MSG_MORE; 501 501 ret = ceph_tcp_sendpage(con->sock, page, page_offset, length, ··· 1008 1008 continue; 1009 1009 } 1010 1010 1011 - page = ceph_msg_data_next(cursor, &page_offset, &length, NULL); 1011 + page = ceph_msg_data_next(cursor, &page_offset, &length); 1012 1012 ret = ceph_tcp_recvpage(con->sock, page, page_offset, length); 1013 1013 if (ret <= 0) { 1014 1014 if (do_datacrc) ··· 1050 1050 continue; 1051 1051 } 1052 1052 1053 - page = ceph_msg_data_next(cursor, &off, &len, NULL); 1053 + page = ceph_msg_data_next(cursor, &off, &len); 1054 1054 ret = ceph_tcp_recvpage(con->sock, con->bounce_page, 0, len); 1055 1055 if (ret <= 0) { 1056 1056 con->in_data_crc = crc;
+1 -1
net/ceph/messenger_v2.c
··· 862 862 ceph_msg_data_advance(cursor, 0); 863 863 864 864 /* get a piece of data, cursor isn't advanced */ 865 - page = ceph_msg_data_next(cursor, &off, &len, NULL); 865 + page = ceph_msg_data_next(cursor, &off, &len); 866 866 867 867 bv->bv_page = page; 868 868 bv->bv_offset = off;