Lines Matching defs:cursor
724 static void ceph_msg_data_bio_cursor_init(struct ceph_msg_data_cursor *cursor,
727 struct ceph_msg_data *data = cursor->data;
728 struct ceph_bio_iter *it = &cursor->bio_iter;
730 cursor->resid = min_t(size_t, length, data->bio_length);
732 if (cursor->resid < it->iter.bi_size)
733 it->iter.bi_size = cursor->resid;
735 BUG_ON(cursor->resid < bio_iter_len(it->bio, it->iter));
738 static struct page *ceph_msg_data_bio_next(struct ceph_msg_data_cursor *cursor,
742 struct bio_vec bv = bio_iter_iovec(cursor->bio_iter.bio,
743 cursor->bio_iter.iter);
750 static bool ceph_msg_data_bio_advance(struct ceph_msg_data_cursor *cursor,
753 struct ceph_bio_iter *it = &cursor->bio_iter;
756 BUG_ON(bytes > cursor->resid);
758 cursor->resid -= bytes;
761 if (!cursor->resid)
771 if (cursor->resid < it->iter.bi_size)
772 it->iter.bi_size = cursor->resid;
775 BUG_ON(cursor->resid < bio_iter_len(it->bio, it->iter));
780 static void ceph_msg_data_bvecs_cursor_init(struct ceph_msg_data_cursor *cursor,
783 struct ceph_msg_data *data = cursor->data;
786 cursor->resid = min_t(size_t, length, data->bvec_pos.iter.bi_size);
787 cursor->bvec_iter = data->bvec_pos.iter;
788 cursor->bvec_iter.bi_size = cursor->resid;
790 BUG_ON(cursor->resid < bvec_iter_len(bvecs, cursor->bvec_iter));
793 static struct page *ceph_msg_data_bvecs_next(struct ceph_msg_data_cursor *cursor,
797 struct bio_vec bv = bvec_iter_bvec(cursor->data->bvec_pos.bvecs,
798 cursor->bvec_iter);
805 static bool ceph_msg_data_bvecs_advance(struct ceph_msg_data_cursor *cursor,
808 struct bio_vec *bvecs = cursor->data->bvec_pos.bvecs;
809 struct page *page = bvec_iter_page(bvecs, cursor->bvec_iter);
811 BUG_ON(bytes > cursor->resid);
812 BUG_ON(bytes > bvec_iter_len(bvecs, cursor->bvec_iter));
813 cursor->resid -= bytes;
814 bvec_iter_advance(bvecs, &cursor->bvec_iter, bytes);
816 if (!cursor->resid)
819 if (!bytes || (cursor->bvec_iter.bi_bvec_done &&
820 page == bvec_iter_page(bvecs, cursor->bvec_iter)))
823 BUG_ON(cursor->resid < bvec_iter_len(bvecs, cursor->bvec_iter));
831 static void ceph_msg_data_pages_cursor_init(struct ceph_msg_data_cursor *cursor,
834 struct ceph_msg_data *data = cursor->data;
842 cursor->resid = min(length, data->length);
844 cursor->page_offset = data->alignment & ~PAGE_MASK;
845 cursor->page_index = 0;
847 cursor->page_count = (unsigned short)page_count;
848 BUG_ON(length > SIZE_MAX - cursor->page_offset);
852 ceph_msg_data_pages_next(struct ceph_msg_data_cursor *cursor,
855 struct ceph_msg_data *data = cursor->data;
859 BUG_ON(cursor->page_index >= cursor->page_count);
860 BUG_ON(cursor->page_offset >= PAGE_SIZE);
862 *page_offset = cursor->page_offset;
863 *length = min_t(size_t, cursor->resid, PAGE_SIZE - *page_offset);
864 return data->pages[cursor->page_index];
867 static bool ceph_msg_data_pages_advance(struct ceph_msg_data_cursor *cursor,
870 BUG_ON(cursor->data->type != CEPH_MSG_DATA_PAGES);
872 BUG_ON(cursor->page_offset + bytes > PAGE_SIZE);
874 /* Advance the cursor page offset */
876 cursor->resid -= bytes;
877 cursor->page_offset = (cursor->page_offset + bytes) & ~PAGE_MASK;
878 if (!bytes || cursor->page_offset)
881 if (!cursor->resid)
886 BUG_ON(cursor->page_index >= cursor->page_count);
887 cursor->page_index++;
896 ceph_msg_data_pagelist_cursor_init(struct ceph_msg_data_cursor *cursor,
899 struct ceph_msg_data *data = cursor->data;
914 cursor->resid = min(length, pagelist->length);
915 cursor->page = page;
916 cursor->offset = 0;
920 ceph_msg_data_pagelist_next(struct ceph_msg_data_cursor *cursor,
923 struct ceph_msg_data *data = cursor->data;
931 BUG_ON(!cursor->page);
932 BUG_ON(cursor->offset + cursor->resid != pagelist->length);
935 *page_offset = cursor->offset & ~PAGE_MASK;
936 *length = min_t(size_t, cursor->resid, PAGE_SIZE - *page_offset);
937 return cursor->page;
940 static bool ceph_msg_data_pagelist_advance(struct ceph_msg_data_cursor *cursor,
943 struct ceph_msg_data *data = cursor->data;
951 BUG_ON(cursor->offset + cursor->resid != pagelist->length);
952 BUG_ON((cursor->offset & ~PAGE_MASK) + bytes > PAGE_SIZE);
954 /* Advance the cursor offset */
956 cursor->resid -= bytes;
957 cursor->offset += bytes;
959 if (!bytes || cursor->offset & ~PAGE_MASK)
962 if (!cursor->resid)
967 BUG_ON(list_is_last(&cursor->page->lru, &pagelist->head));
968 cursor->page = list_next_entry(cursor->page, lru);
972 static void ceph_msg_data_iter_cursor_init(struct ceph_msg_data_cursor *cursor,
975 struct ceph_msg_data *data = cursor->data;
977 cursor->iov_iter = data->iter;
978 cursor->lastlen = 0;
979 iov_iter_truncate(&cursor->iov_iter, length);
980 cursor->resid = iov_iter_count(&cursor->iov_iter);
983 static struct page *ceph_msg_data_iter_next(struct ceph_msg_data_cursor *cursor,
989 if (cursor->lastlen)
990 iov_iter_revert(&cursor->iov_iter, cursor->lastlen);
992 len = iov_iter_get_pages2(&cursor->iov_iter, &page, PAGE_SIZE,
996 cursor->lastlen = len;
1008 *length = min_t(size_t, len, cursor->resid);
1012 static bool ceph_msg_data_iter_advance(struct ceph_msg_data_cursor *cursor,
1015 BUG_ON(bytes > cursor->resid);
1016 cursor->resid -= bytes;
1018 if (bytes < cursor->lastlen) {
1019 cursor->lastlen -= bytes;
1021 iov_iter_advance(&cursor->iov_iter, bytes - cursor->lastlen);
1022 cursor->lastlen = 0;
1025 return cursor->resid;
1031 * consume an entire piece at once. A data item's cursor keeps
1036 static void __ceph_msg_data_cursor_init(struct ceph_msg_data_cursor *cursor)
1038 size_t length = cursor->total_resid;
1040 switch (cursor->data->type) {
1042 ceph_msg_data_pagelist_cursor_init(cursor, length);
1045 ceph_msg_data_pages_cursor_init(cursor, length);
1049 ceph_msg_data_bio_cursor_init(cursor, length);
1053 ceph_msg_data_bvecs_cursor_init(cursor, length);
1056 ceph_msg_data_iter_cursor_init(cursor, length);
1063 cursor->need_crc = true;
1066 void ceph_msg_data_cursor_init(struct ceph_msg_data_cursor *cursor,
1073 cursor->total_resid = length;
1074 cursor->data = msg->data;
1075 cursor->sr_resid = 0;
1077 __ceph_msg_data_cursor_init(cursor);
1085 struct page *ceph_msg_data_next(struct ceph_msg_data_cursor *cursor,
1090 switch (cursor->data->type) {
1092 page = ceph_msg_data_pagelist_next(cursor, page_offset, length);
1095 page = ceph_msg_data_pages_next(cursor, page_offset, length);
1099 page = ceph_msg_data_bio_next(cursor, page_offset, length);
1103 page = ceph_msg_data_bvecs_next(cursor, page_offset, length);
1106 page = ceph_msg_data_iter_next(cursor, page_offset, length);
1117 BUG_ON(*length > cursor->resid);
1123 * Returns true if the result moves the cursor on to the next piece
1126 void ceph_msg_data_advance(struct ceph_msg_data_cursor *cursor, size_t bytes)
1130 BUG_ON(bytes > cursor->resid);
1131 switch (cursor->data->type) {
1133 new_piece = ceph_msg_data_pagelist_advance(cursor, bytes);
1136 new_piece = ceph_msg_data_pages_advance(cursor, bytes);
1140 new_piece = ceph_msg_data_bio_advance(cursor, bytes);
1144 new_piece = ceph_msg_data_bvecs_advance(cursor, bytes);
1147 new_piece = ceph_msg_data_iter_advance(cursor, bytes);
1154 cursor->total_resid -= bytes;
1156 if (!cursor->resid && cursor->total_resid) {
1157 cursor->data++;
1158 __ceph_msg_data_cursor_init(cursor);
1161 cursor->need_crc = new_piece;