Lines Matching refs:cursor
715 static void ceph_msg_data_bio_cursor_init(struct ceph_msg_data_cursor *cursor, in ceph_msg_data_bio_cursor_init() argument
718 struct ceph_msg_data *data = cursor->data; in ceph_msg_data_bio_cursor_init()
719 struct ceph_bio_iter *it = &cursor->bio_iter; in ceph_msg_data_bio_cursor_init()
721 cursor->resid = min_t(size_t, length, data->bio_length); in ceph_msg_data_bio_cursor_init()
723 if (cursor->resid < it->iter.bi_size) in ceph_msg_data_bio_cursor_init()
724 it->iter.bi_size = cursor->resid; in ceph_msg_data_bio_cursor_init()
726 BUG_ON(cursor->resid < bio_iter_len(it->bio, it->iter)); in ceph_msg_data_bio_cursor_init()
727 cursor->last_piece = cursor->resid == bio_iter_len(it->bio, it->iter); in ceph_msg_data_bio_cursor_init()
730 static struct page *ceph_msg_data_bio_next(struct ceph_msg_data_cursor *cursor, in ceph_msg_data_bio_next() argument
734 struct bio_vec bv = bio_iter_iovec(cursor->bio_iter.bio, in ceph_msg_data_bio_next()
735 cursor->bio_iter.iter); in ceph_msg_data_bio_next()
742 static bool ceph_msg_data_bio_advance(struct ceph_msg_data_cursor *cursor, in ceph_msg_data_bio_advance() argument
745 struct ceph_bio_iter *it = &cursor->bio_iter; in ceph_msg_data_bio_advance()
748 BUG_ON(bytes > cursor->resid); in ceph_msg_data_bio_advance()
750 cursor->resid -= bytes; in ceph_msg_data_bio_advance()
753 if (!cursor->resid) { in ceph_msg_data_bio_advance()
754 BUG_ON(!cursor->last_piece); in ceph_msg_data_bio_advance()
765 if (cursor->resid < it->iter.bi_size) in ceph_msg_data_bio_advance()
766 it->iter.bi_size = cursor->resid; in ceph_msg_data_bio_advance()
769 BUG_ON(cursor->last_piece); in ceph_msg_data_bio_advance()
770 BUG_ON(cursor->resid < bio_iter_len(it->bio, it->iter)); in ceph_msg_data_bio_advance()
771 cursor->last_piece = cursor->resid == bio_iter_len(it->bio, it->iter); in ceph_msg_data_bio_advance()
776 static void ceph_msg_data_bvecs_cursor_init(struct ceph_msg_data_cursor *cursor, in ceph_msg_data_bvecs_cursor_init() argument
779 struct ceph_msg_data *data = cursor->data; in ceph_msg_data_bvecs_cursor_init()
782 cursor->resid = min_t(size_t, length, data->bvec_pos.iter.bi_size); in ceph_msg_data_bvecs_cursor_init()
783 cursor->bvec_iter = data->bvec_pos.iter; in ceph_msg_data_bvecs_cursor_init()
784 cursor->bvec_iter.bi_size = cursor->resid; in ceph_msg_data_bvecs_cursor_init()
786 BUG_ON(cursor->resid < bvec_iter_len(bvecs, cursor->bvec_iter)); in ceph_msg_data_bvecs_cursor_init()
787 cursor->last_piece = in ceph_msg_data_bvecs_cursor_init()
788 cursor->resid == bvec_iter_len(bvecs, cursor->bvec_iter); in ceph_msg_data_bvecs_cursor_init()
791 static struct page *ceph_msg_data_bvecs_next(struct ceph_msg_data_cursor *cursor, in ceph_msg_data_bvecs_next() argument
795 struct bio_vec bv = bvec_iter_bvec(cursor->data->bvec_pos.bvecs, in ceph_msg_data_bvecs_next()
796 cursor->bvec_iter); in ceph_msg_data_bvecs_next()
803 static bool ceph_msg_data_bvecs_advance(struct ceph_msg_data_cursor *cursor, in ceph_msg_data_bvecs_advance() argument
806 struct bio_vec *bvecs = cursor->data->bvec_pos.bvecs; in ceph_msg_data_bvecs_advance()
807 struct page *page = bvec_iter_page(bvecs, cursor->bvec_iter); in ceph_msg_data_bvecs_advance()
809 BUG_ON(bytes > cursor->resid); in ceph_msg_data_bvecs_advance()
810 BUG_ON(bytes > bvec_iter_len(bvecs, cursor->bvec_iter)); in ceph_msg_data_bvecs_advance()
811 cursor->resid -= bytes; in ceph_msg_data_bvecs_advance()
812 bvec_iter_advance(bvecs, &cursor->bvec_iter, bytes); in ceph_msg_data_bvecs_advance()
814 if (!cursor->resid) { in ceph_msg_data_bvecs_advance()
815 BUG_ON(!cursor->last_piece); in ceph_msg_data_bvecs_advance()
819 if (!bytes || (cursor->bvec_iter.bi_bvec_done && in ceph_msg_data_bvecs_advance()
820 page == bvec_iter_page(bvecs, cursor->bvec_iter))) in ceph_msg_data_bvecs_advance()
823 BUG_ON(cursor->last_piece); in ceph_msg_data_bvecs_advance()
824 BUG_ON(cursor->resid < bvec_iter_len(bvecs, cursor->bvec_iter)); in ceph_msg_data_bvecs_advance()
825 cursor->last_piece = in ceph_msg_data_bvecs_advance()
826 cursor->resid == bvec_iter_len(bvecs, cursor->bvec_iter); in ceph_msg_data_bvecs_advance()
834 static void ceph_msg_data_pages_cursor_init(struct ceph_msg_data_cursor *cursor, in ceph_msg_data_pages_cursor_init() argument
837 struct ceph_msg_data *data = cursor->data; in ceph_msg_data_pages_cursor_init()
845 cursor->resid = min(length, data->length); in ceph_msg_data_pages_cursor_init()
847 cursor->page_offset = data->alignment & ~PAGE_MASK; in ceph_msg_data_pages_cursor_init()
848 cursor->page_index = 0; in ceph_msg_data_pages_cursor_init()
850 cursor->page_count = (unsigned short)page_count; in ceph_msg_data_pages_cursor_init()
851 BUG_ON(length > SIZE_MAX - cursor->page_offset); in ceph_msg_data_pages_cursor_init()
852 cursor->last_piece = cursor->page_offset + cursor->resid <= PAGE_SIZE; in ceph_msg_data_pages_cursor_init()
856 ceph_msg_data_pages_next(struct ceph_msg_data_cursor *cursor, in ceph_msg_data_pages_next() argument
859 struct ceph_msg_data *data = cursor->data; in ceph_msg_data_pages_next()
863 BUG_ON(cursor->page_index >= cursor->page_count); in ceph_msg_data_pages_next()
864 BUG_ON(cursor->page_offset >= PAGE_SIZE); in ceph_msg_data_pages_next()
866 *page_offset = cursor->page_offset; in ceph_msg_data_pages_next()
867 if (cursor->last_piece) in ceph_msg_data_pages_next()
868 *length = cursor->resid; in ceph_msg_data_pages_next()
872 return data->pages[cursor->page_index]; in ceph_msg_data_pages_next()
875 static bool ceph_msg_data_pages_advance(struct ceph_msg_data_cursor *cursor, in ceph_msg_data_pages_advance() argument
878 BUG_ON(cursor->data->type != CEPH_MSG_DATA_PAGES); in ceph_msg_data_pages_advance()
880 BUG_ON(cursor->page_offset + bytes > PAGE_SIZE); in ceph_msg_data_pages_advance()
884 cursor->resid -= bytes; in ceph_msg_data_pages_advance()
885 cursor->page_offset = (cursor->page_offset + bytes) & ~PAGE_MASK; in ceph_msg_data_pages_advance()
886 if (!bytes || cursor->page_offset) in ceph_msg_data_pages_advance()
889 if (!cursor->resid) in ceph_msg_data_pages_advance()
894 BUG_ON(cursor->page_index >= cursor->page_count); in ceph_msg_data_pages_advance()
895 cursor->page_index++; in ceph_msg_data_pages_advance()
896 cursor->last_piece = cursor->resid <= PAGE_SIZE; in ceph_msg_data_pages_advance()
906 ceph_msg_data_pagelist_cursor_init(struct ceph_msg_data_cursor *cursor, in ceph_msg_data_pagelist_cursor_init() argument
909 struct ceph_msg_data *data = cursor->data; in ceph_msg_data_pagelist_cursor_init()
924 cursor->resid = min(length, pagelist->length); in ceph_msg_data_pagelist_cursor_init()
925 cursor->page = page; in ceph_msg_data_pagelist_cursor_init()
926 cursor->offset = 0; in ceph_msg_data_pagelist_cursor_init()
927 cursor->last_piece = cursor->resid <= PAGE_SIZE; in ceph_msg_data_pagelist_cursor_init()
931 ceph_msg_data_pagelist_next(struct ceph_msg_data_cursor *cursor, in ceph_msg_data_pagelist_next() argument
934 struct ceph_msg_data *data = cursor->data; in ceph_msg_data_pagelist_next()
942 BUG_ON(!cursor->page); in ceph_msg_data_pagelist_next()
943 BUG_ON(cursor->offset + cursor->resid != pagelist->length); in ceph_msg_data_pagelist_next()
946 *page_offset = cursor->offset & ~PAGE_MASK; in ceph_msg_data_pagelist_next()
947 if (cursor->last_piece) in ceph_msg_data_pagelist_next()
948 *length = cursor->resid; in ceph_msg_data_pagelist_next()
952 return cursor->page; in ceph_msg_data_pagelist_next()
955 static bool ceph_msg_data_pagelist_advance(struct ceph_msg_data_cursor *cursor, in ceph_msg_data_pagelist_advance() argument
958 struct ceph_msg_data *data = cursor->data; in ceph_msg_data_pagelist_advance()
966 BUG_ON(cursor->offset + cursor->resid != pagelist->length); in ceph_msg_data_pagelist_advance()
967 BUG_ON((cursor->offset & ~PAGE_MASK) + bytes > PAGE_SIZE); in ceph_msg_data_pagelist_advance()
971 cursor->resid -= bytes; in ceph_msg_data_pagelist_advance()
972 cursor->offset += bytes; in ceph_msg_data_pagelist_advance()
974 if (!bytes || cursor->offset & ~PAGE_MASK) in ceph_msg_data_pagelist_advance()
977 if (!cursor->resid) in ceph_msg_data_pagelist_advance()
982 BUG_ON(list_is_last(&cursor->page->lru, &pagelist->head)); in ceph_msg_data_pagelist_advance()
983 cursor->page = list_next_entry(cursor->page, lru); in ceph_msg_data_pagelist_advance()
984 cursor->last_piece = cursor->resid <= PAGE_SIZE; in ceph_msg_data_pagelist_advance()
997 static void __ceph_msg_data_cursor_init(struct ceph_msg_data_cursor *cursor) in __ceph_msg_data_cursor_init() argument
999 size_t length = cursor->total_resid; in __ceph_msg_data_cursor_init()
1001 switch (cursor->data->type) { in __ceph_msg_data_cursor_init()
1003 ceph_msg_data_pagelist_cursor_init(cursor, length); in __ceph_msg_data_cursor_init()
1006 ceph_msg_data_pages_cursor_init(cursor, length); in __ceph_msg_data_cursor_init()
1010 ceph_msg_data_bio_cursor_init(cursor, length); in __ceph_msg_data_cursor_init()
1014 ceph_msg_data_bvecs_cursor_init(cursor, length); in __ceph_msg_data_cursor_init()
1021 cursor->need_crc = true; in __ceph_msg_data_cursor_init()
1024 void ceph_msg_data_cursor_init(struct ceph_msg_data_cursor *cursor, in ceph_msg_data_cursor_init() argument
1031 cursor->total_resid = length; in ceph_msg_data_cursor_init()
1032 cursor->data = msg->data; in ceph_msg_data_cursor_init()
1034 __ceph_msg_data_cursor_init(cursor); in ceph_msg_data_cursor_init()
1042 struct page *ceph_msg_data_next(struct ceph_msg_data_cursor *cursor, in ceph_msg_data_next() argument
1048 switch (cursor->data->type) { in ceph_msg_data_next()
1050 page = ceph_msg_data_pagelist_next(cursor, page_offset, length); in ceph_msg_data_next()
1053 page = ceph_msg_data_pages_next(cursor, page_offset, length); in ceph_msg_data_next()
1057 page = ceph_msg_data_bio_next(cursor, page_offset, length); in ceph_msg_data_next()
1061 page = ceph_msg_data_bvecs_next(cursor, page_offset, length); in ceph_msg_data_next()
1072 BUG_ON(*length > cursor->resid); in ceph_msg_data_next()
1074 *last_piece = cursor->last_piece; in ceph_msg_data_next()
1083 void ceph_msg_data_advance(struct ceph_msg_data_cursor *cursor, size_t bytes) in ceph_msg_data_advance() argument
1087 BUG_ON(bytes > cursor->resid); in ceph_msg_data_advance()
1088 switch (cursor->data->type) { in ceph_msg_data_advance()
1090 new_piece = ceph_msg_data_pagelist_advance(cursor, bytes); in ceph_msg_data_advance()
1093 new_piece = ceph_msg_data_pages_advance(cursor, bytes); in ceph_msg_data_advance()
1097 new_piece = ceph_msg_data_bio_advance(cursor, bytes); in ceph_msg_data_advance()
1101 new_piece = ceph_msg_data_bvecs_advance(cursor, bytes); in ceph_msg_data_advance()
1108 cursor->total_resid -= bytes; in ceph_msg_data_advance()
1110 if (!cursor->resid && cursor->total_resid) { in ceph_msg_data_advance()
1111 WARN_ON(!cursor->last_piece); in ceph_msg_data_advance()
1112 cursor->data++; in ceph_msg_data_advance()
1113 __ceph_msg_data_cursor_init(cursor); in ceph_msg_data_advance()
1116 cursor->need_crc = new_piece; in ceph_msg_data_advance()