Lines Matching refs:cursor

725 static void ceph_msg_data_bio_cursor_init(struct ceph_msg_data_cursor *cursor,
728 struct ceph_msg_data *data = cursor->data;
729 struct ceph_bio_iter *it = &cursor->bio_iter;
731 cursor->resid = min_t(size_t, length, data->bio_length);
733 if (cursor->resid < it->iter.bi_size)
734 it->iter.bi_size = cursor->resid;
736 BUG_ON(cursor->resid < bio_iter_len(it->bio, it->iter));
739 static struct page *ceph_msg_data_bio_next(struct ceph_msg_data_cursor *cursor,
743 struct bio_vec bv = bio_iter_iovec(cursor->bio_iter.bio,
744 cursor->bio_iter.iter);
751 static bool ceph_msg_data_bio_advance(struct ceph_msg_data_cursor *cursor,
754 struct ceph_bio_iter *it = &cursor->bio_iter;
757 BUG_ON(bytes > cursor->resid);
759 cursor->resid -= bytes;
762 if (!cursor->resid)
772 if (cursor->resid < it->iter.bi_size)
773 it->iter.bi_size = cursor->resid;
776 BUG_ON(cursor->resid < bio_iter_len(it->bio, it->iter));
781 static void ceph_msg_data_bvecs_cursor_init(struct ceph_msg_data_cursor *cursor,
784 struct ceph_msg_data *data = cursor->data;
787 cursor->resid = min_t(size_t, length, data->bvec_pos.iter.bi_size);
788 cursor->bvec_iter = data->bvec_pos.iter;
789 cursor->bvec_iter.bi_size = cursor->resid;
791 BUG_ON(cursor->resid < bvec_iter_len(bvecs, cursor->bvec_iter));
794 static struct page *ceph_msg_data_bvecs_next(struct ceph_msg_data_cursor *cursor,
798 struct bio_vec bv = bvec_iter_bvec(cursor->data->bvec_pos.bvecs,
799 cursor->bvec_iter);
806 static bool ceph_msg_data_bvecs_advance(struct ceph_msg_data_cursor *cursor,
809 struct bio_vec *bvecs = cursor->data->bvec_pos.bvecs;
810 struct page *page = bvec_iter_page(bvecs, cursor->bvec_iter);
812 BUG_ON(bytes > cursor->resid);
813 BUG_ON(bytes > bvec_iter_len(bvecs, cursor->bvec_iter));
814 cursor->resid -= bytes;
815 bvec_iter_advance(bvecs, &cursor->bvec_iter, bytes);
817 if (!cursor->resid)
820 if (!bytes || (cursor->bvec_iter.bi_bvec_done &&
821 page == bvec_iter_page(bvecs, cursor->bvec_iter)))
824 BUG_ON(cursor->resid < bvec_iter_len(bvecs, cursor->bvec_iter));
832 static void ceph_msg_data_pages_cursor_init(struct ceph_msg_data_cursor *cursor,
835 struct ceph_msg_data *data = cursor->data;
843 cursor->resid = min(length, data->length);
845 cursor->page_offset = data->alignment & ~PAGE_MASK;
846 cursor->page_index = 0;
848 cursor->page_count = (unsigned short)page_count;
849 BUG_ON(length > SIZE_MAX - cursor->page_offset);
853 ceph_msg_data_pages_next(struct ceph_msg_data_cursor *cursor,
856 struct ceph_msg_data *data = cursor->data;
860 BUG_ON(cursor->page_index >= cursor->page_count);
861 BUG_ON(cursor->page_offset >= PAGE_SIZE);
863 *page_offset = cursor->page_offset;
864 *length = min_t(size_t, cursor->resid, PAGE_SIZE - *page_offset);
865 return data->pages[cursor->page_index];
868 static bool ceph_msg_data_pages_advance(struct ceph_msg_data_cursor *cursor,
871 BUG_ON(cursor->data->type != CEPH_MSG_DATA_PAGES);
873 BUG_ON(cursor->page_offset + bytes > PAGE_SIZE);
875 /* Advance the cursor page offset */
877 cursor->resid -= bytes;
878 cursor->page_offset = (cursor->page_offset + bytes) & ~PAGE_MASK;
879 if (!bytes || cursor->page_offset)
882 if (!cursor->resid)
887 BUG_ON(cursor->page_index >= cursor->page_count);
888 cursor->page_index++;
897 ceph_msg_data_pagelist_cursor_init(struct ceph_msg_data_cursor *cursor,
900 struct ceph_msg_data *data = cursor->data;
915 cursor->resid = min(length, pagelist->length);
916 cursor->page = page;
917 cursor->offset = 0;
921 ceph_msg_data_pagelist_next(struct ceph_msg_data_cursor *cursor,
924 struct ceph_msg_data *data = cursor->data;
932 BUG_ON(!cursor->page);
933 BUG_ON(cursor->offset + cursor->resid != pagelist->length);
936 *page_offset = cursor->offset & ~PAGE_MASK;
937 *length = min_t(size_t, cursor->resid, PAGE_SIZE - *page_offset);
938 return cursor->page;
941 static bool ceph_msg_data_pagelist_advance(struct ceph_msg_data_cursor *cursor,
944 struct ceph_msg_data *data = cursor->data;
952 BUG_ON(cursor->offset + cursor->resid != pagelist->length);
953 BUG_ON((cursor->offset & ~PAGE_MASK) + bytes > PAGE_SIZE);
955 /* Advance the cursor offset */
957 cursor->resid -= bytes;
958 cursor->offset += bytes;
960 if (!bytes || cursor->offset & ~PAGE_MASK)
963 if (!cursor->resid)
968 BUG_ON(list_is_last(&cursor->page->lru, &pagelist->head));
969 cursor->page = list_next_entry(cursor->page, lru);
973 static void ceph_msg_data_iter_cursor_init(struct ceph_msg_data_cursor *cursor,
976 struct ceph_msg_data *data = cursor->data;
978 cursor->iov_iter = data->iter;
979 cursor->lastlen = 0;
980 iov_iter_truncate(&cursor->iov_iter, length);
981 cursor->resid = iov_iter_count(&cursor->iov_iter);
984 static struct page *ceph_msg_data_iter_next(struct ceph_msg_data_cursor *cursor,
990 if (cursor->lastlen)
991 iov_iter_revert(&cursor->iov_iter, cursor->lastlen);
993 len = iov_iter_get_pages2(&cursor->iov_iter, &page, PAGE_SIZE,
997 cursor->lastlen = len;
1009 *length = min_t(size_t, len, cursor->resid);
1013 static bool ceph_msg_data_iter_advance(struct ceph_msg_data_cursor *cursor,
1016 BUG_ON(bytes > cursor->resid);
1017 cursor->resid -= bytes;
1019 if (bytes < cursor->lastlen) {
1020 cursor->lastlen -= bytes;
1022 iov_iter_advance(&cursor->iov_iter, bytes - cursor->lastlen);
1023 cursor->lastlen = 0;
1026 return cursor->resid;
1032 * consume an entire piece at once. A data item's cursor keeps
1037 static void __ceph_msg_data_cursor_init(struct ceph_msg_data_cursor *cursor)
1039 size_t length = cursor->total_resid;
1041 switch (cursor->data->type) {
1043 ceph_msg_data_pagelist_cursor_init(cursor, length);
1046 ceph_msg_data_pages_cursor_init(cursor, length);
1050 ceph_msg_data_bio_cursor_init(cursor, length);
1054 ceph_msg_data_bvecs_cursor_init(cursor, length);
1057 ceph_msg_data_iter_cursor_init(cursor, length);
1064 cursor->need_crc = true;
1067 void ceph_msg_data_cursor_init(struct ceph_msg_data_cursor *cursor,
1074 cursor->total_resid = length;
1075 cursor->data = msg->data;
1076 cursor->sr_resid = 0;
1078 __ceph_msg_data_cursor_init(cursor);
1086 struct page *ceph_msg_data_next(struct ceph_msg_data_cursor *cursor,
1091 switch (cursor->data->type) {
1093 page = ceph_msg_data_pagelist_next(cursor, page_offset, length);
1096 page = ceph_msg_data_pages_next(cursor, page_offset, length);
1100 page = ceph_msg_data_bio_next(cursor, page_offset, length);
1104 page = ceph_msg_data_bvecs_next(cursor, page_offset, length);
1107 page = ceph_msg_data_iter_next(cursor, page_offset, length);
1118 BUG_ON(*length > cursor->resid);
1124 * Returns true if the result moves the cursor on to the next piece
1127 void ceph_msg_data_advance(struct ceph_msg_data_cursor *cursor, size_t bytes)
1131 BUG_ON(bytes > cursor->resid);
1132 switch (cursor->data->type) {
1134 new_piece = ceph_msg_data_pagelist_advance(cursor, bytes);
1137 new_piece = ceph_msg_data_pages_advance(cursor, bytes);
1141 new_piece = ceph_msg_data_bio_advance(cursor, bytes);
1145 new_piece = ceph_msg_data_bvecs_advance(cursor, bytes);
1148 new_piece = ceph_msg_data_iter_advance(cursor, bytes);
1155 cursor->total_resid -= bytes;
1157 if (!cursor->resid && cursor->total_resid) {
1158 cursor->data++;
1159 __ceph_msg_data_cursor_init(cursor);
1162 cursor->need_crc = new_piece;