Lines Matching refs:cursor

807 static void ceph_msg_data_bio_cursor_init(struct ceph_msg_data_cursor *cursor,
810 struct ceph_msg_data *data = cursor->data;
811 struct ceph_bio_iter *it = &cursor->bio_iter;
813 cursor->resid = min_t(size_t, length, data->bio_length);
815 if (cursor->resid < it->iter.bi_size)
816 it->iter.bi_size = cursor->resid;
818 BUG_ON(cursor->resid < bio_iter_len(it->bio, it->iter));
819 cursor->last_piece = cursor->resid == bio_iter_len(it->bio, it->iter);
822 static struct page *ceph_msg_data_bio_next(struct ceph_msg_data_cursor *cursor,
826 struct bio_vec bv = bio_iter_iovec(cursor->bio_iter.bio,
827 cursor->bio_iter.iter);
834 static bool ceph_msg_data_bio_advance(struct ceph_msg_data_cursor *cursor,
837 struct ceph_bio_iter *it = &cursor->bio_iter;
840 BUG_ON(bytes > cursor->resid);
842 cursor->resid -= bytes;
845 if (!cursor->resid) {
846 BUG_ON(!cursor->last_piece);
857 if (cursor->resid < it->iter.bi_size)
858 it->iter.bi_size = cursor->resid;
861 BUG_ON(cursor->last_piece);
862 BUG_ON(cursor->resid < bio_iter_len(it->bio, it->iter));
863 cursor->last_piece = cursor->resid == bio_iter_len(it->bio, it->iter);
868 static void ceph_msg_data_bvecs_cursor_init(struct ceph_msg_data_cursor *cursor,
871 struct ceph_msg_data *data = cursor->data;
874 cursor->resid = min_t(size_t, length, data->bvec_pos.iter.bi_size);
875 cursor->bvec_iter = data->bvec_pos.iter;
876 cursor->bvec_iter.bi_size = cursor->resid;
878 BUG_ON(cursor->resid < bvec_iter_len(bvecs, cursor->bvec_iter));
879 cursor->last_piece =
880 cursor->resid == bvec_iter_len(bvecs, cursor->bvec_iter);
883 static struct page *ceph_msg_data_bvecs_next(struct ceph_msg_data_cursor *cursor,
887 struct bio_vec bv = bvec_iter_bvec(cursor->data->bvec_pos.bvecs,
888 cursor->bvec_iter);
895 static bool ceph_msg_data_bvecs_advance(struct ceph_msg_data_cursor *cursor,
898 struct bio_vec *bvecs = cursor->data->bvec_pos.bvecs;
899 struct page *page = bvec_iter_page(bvecs, cursor->bvec_iter);
901 BUG_ON(bytes > cursor->resid);
902 BUG_ON(bytes > bvec_iter_len(bvecs, cursor->bvec_iter));
903 cursor->resid -= bytes;
904 bvec_iter_advance(bvecs, &cursor->bvec_iter, bytes);
906 if (!cursor->resid) {
907 BUG_ON(!cursor->last_piece);
911 if (!bytes || (cursor->bvec_iter.bi_bvec_done &&
912 page == bvec_iter_page(bvecs, cursor->bvec_iter)))
915 BUG_ON(cursor->last_piece);
916 BUG_ON(cursor->resid < bvec_iter_len(bvecs, cursor->bvec_iter));
917 cursor->last_piece =
918 cursor->resid == bvec_iter_len(bvecs, cursor->bvec_iter);
926 static void ceph_msg_data_pages_cursor_init(struct ceph_msg_data_cursor *cursor,
929 struct ceph_msg_data *data = cursor->data;
937 cursor->resid = min(length, data->length);
939 cursor->page_offset = data->alignment & ~PAGE_MASK;
940 cursor->page_index = 0;
942 cursor->page_count = (unsigned short)page_count;
943 BUG_ON(length > SIZE_MAX - cursor->page_offset);
944 cursor->last_piece = cursor->page_offset + cursor->resid <= PAGE_SIZE;
948 ceph_msg_data_pages_next(struct ceph_msg_data_cursor *cursor,
951 struct ceph_msg_data *data = cursor->data;
955 BUG_ON(cursor->page_index >= cursor->page_count);
956 BUG_ON(cursor->page_offset >= PAGE_SIZE);
958 *page_offset = cursor->page_offset;
959 if (cursor->last_piece)
960 *length = cursor->resid;
964 return data->pages[cursor->page_index];
967 static bool ceph_msg_data_pages_advance(struct ceph_msg_data_cursor *cursor,
970 BUG_ON(cursor->data->type != CEPH_MSG_DATA_PAGES);
972 BUG_ON(cursor->page_offset + bytes > PAGE_SIZE);
974 /* Advance the cursor page offset */
976 cursor->resid -= bytes;
977 cursor->page_offset = (cursor->page_offset + bytes) & ~PAGE_MASK;
978 if (!bytes || cursor->page_offset)
981 if (!cursor->resid)
986 BUG_ON(cursor->page_index >= cursor->page_count);
987 cursor->page_index++;
988 cursor->last_piece = cursor->resid <= PAGE_SIZE;
998 ceph_msg_data_pagelist_cursor_init(struct ceph_msg_data_cursor *cursor,
1001 struct ceph_msg_data *data = cursor->data;
1016 cursor->resid = min(length, pagelist->length);
1017 cursor->page = page;
1018 cursor->offset = 0;
1019 cursor->last_piece = cursor->resid <= PAGE_SIZE;
1023 ceph_msg_data_pagelist_next(struct ceph_msg_data_cursor *cursor,
1026 struct ceph_msg_data *data = cursor->data;
1034 BUG_ON(!cursor->page);
1035 BUG_ON(cursor->offset + cursor->resid != pagelist->length);
1038 *page_offset = cursor->offset & ~PAGE_MASK;
1039 if (cursor->last_piece)
1040 *length = cursor->resid;
1044 return cursor->page;
1047 static bool ceph_msg_data_pagelist_advance(struct ceph_msg_data_cursor *cursor,
1050 struct ceph_msg_data *data = cursor->data;
1058 BUG_ON(cursor->offset + cursor->resid != pagelist->length);
1059 BUG_ON((cursor->offset & ~PAGE_MASK) + bytes > PAGE_SIZE);
1061 /* Advance the cursor offset */
1063 cursor->resid -= bytes;
1064 cursor->offset += bytes;
1066 if (!bytes || cursor->offset & ~PAGE_MASK)
1069 if (!cursor->resid)
1074 BUG_ON(list_is_last(&cursor->page->lru, &pagelist->head));
1075 cursor->page = list_next_entry(cursor->page, lru);
1076 cursor->last_piece = cursor->resid <= PAGE_SIZE;
1084 * consume an entire piece at once. A data item's cursor keeps
1089 static void __ceph_msg_data_cursor_init(struct ceph_msg_data_cursor *cursor)
1091 size_t length = cursor->total_resid;
1093 switch (cursor->data->type) {
1095 ceph_msg_data_pagelist_cursor_init(cursor, length);
1098 ceph_msg_data_pages_cursor_init(cursor, length);
1102 ceph_msg_data_bio_cursor_init(cursor, length);
1106 ceph_msg_data_bvecs_cursor_init(cursor, length);
1113 cursor->need_crc = true;
1118 struct ceph_msg_data_cursor *cursor = &msg->cursor;
1124 cursor->total_resid = length;
1125 cursor->data = msg->data;
1127 __ceph_msg_data_cursor_init(cursor);
1135 static struct page *ceph_msg_data_next(struct ceph_msg_data_cursor *cursor,
1141 switch (cursor->data->type) {
1143 page = ceph_msg_data_pagelist_next(cursor, page_offset, length);
1146 page = ceph_msg_data_pages_next(cursor, page_offset, length);
1150 page = ceph_msg_data_bio_next(cursor, page_offset, length);
1154 page = ceph_msg_data_bvecs_next(cursor, page_offset, length);
1165 BUG_ON(*length > cursor->resid);
1167 *last_piece = cursor->last_piece;
1173 * Returns true if the result moves the cursor on to the next piece
1176 static void ceph_msg_data_advance(struct ceph_msg_data_cursor *cursor,
1181 BUG_ON(bytes > cursor->resid);
1182 switch (cursor->data->type) {
1184 new_piece = ceph_msg_data_pagelist_advance(cursor, bytes);
1187 new_piece = ceph_msg_data_pages_advance(cursor, bytes);
1191 new_piece = ceph_msg_data_bio_advance(cursor, bytes);
1195 new_piece = ceph_msg_data_bvecs_advance(cursor, bytes);
1202 cursor->total_resid -= bytes;
1204 if (!cursor->resid && cursor->total_resid) {
1205 WARN_ON(!cursor->last_piece);
1206 cursor->data++;
1207 __ceph_msg_data_cursor_init(cursor);
1210 cursor->need_crc = new_piece;
1222 /* Initialize data cursor */
1555 struct ceph_msg_data_cursor *cursor = &msg->cursor;
1574 while (cursor->total_resid) {
1580 if (!cursor->resid) {
1581 ceph_msg_data_advance(cursor, 0);
1585 page = ceph_msg_data_next(cursor, &page_offset, &length, NULL);
1586 if (length == cursor->total_resid)
1596 if (do_datacrc && cursor->need_crc)
1598 ceph_msg_data_advance(cursor, (size_t)ret);
2313 struct ceph_msg_data_cursor *cursor = &msg->cursor;
2326 while (cursor->total_resid) {
2327 if (!cursor->resid) {
2328 ceph_msg_data_advance(cursor, 0);
2332 page = ceph_msg_data_next(cursor, &page_offset, &length, NULL);
2343 ceph_msg_data_advance(cursor, (size_t)ret);
3158 con->out_skip += msg->cursor.total_resid;