BUG_ON(!bio);
BUG_ON(!bio->bi_vcnt);
- cursor->resid = length;
+ cursor->resid = min(length, data->bio_length);
cursor->bio = bio;
cursor->vector_index = 0;
cursor->vector_offset = 0;
BUG_ON(!data->pages);
BUG_ON(!data->length);
- BUG_ON(length > data->length); /* short reads are OK */
- cursor->resid = length;
+ cursor->resid = min(length, data->length);
page_count = calc_pages_for(data->alignment, (u64)data->length);
cursor->page_offset = data->alignment & ~PAGE_MASK;
cursor->page_index = 0;
pagelist = data->pagelist;
BUG_ON(!pagelist);
- BUG_ON(length > pagelist->length); /* short reads are OK */
if (!length)
return; /* pagelist can be assigned but empty */
BUG_ON(list_empty(&pagelist->head));
page = list_first_entry(&pagelist->head, struct page, lru);
- cursor->resid = length;
+ cursor->resid = min(length, pagelist->length);
cursor->page = page;
cursor->offset = 0;
cursor->last_piece = length <= PAGE_SIZE;
* be processed in that piece. It also tracks whether the current
* piece is the last one in the data item.
*/
-static void ceph_msg_data_cursor_init(struct ceph_msg *msg, size_t length)
+static void __ceph_msg_data_cursor_init(struct ceph_msg_data_cursor *cursor)
{
- struct ceph_msg_data_cursor *cursor = &msg->cursor;
- struct ceph_msg_data *data;
+ size_t length = cursor->total_resid;
- data = list_first_entry(&msg->data, struct ceph_msg_data, links);
- cursor->data = data;
switch (cursor->data->type) {
case CEPH_MSG_DATA_PAGELIST:
ceph_msg_data_pagelist_cursor_init(cursor, length);
cursor->need_crc = true;
}
+static void ceph_msg_data_cursor_init(struct ceph_msg *msg, size_t length)
+{
+ struct ceph_msg_data_cursor *cursor = &msg->cursor;
+ struct ceph_msg_data *data;
+
+ BUG_ON(!length);
+ BUG_ON(length > msg->data_length);
+ BUG_ON(list_empty(&msg->data));
+
+ data = list_first_entry(&msg->data, struct ceph_msg_data, links);
+
+ cursor->data_head = &msg->data;
+ cursor->total_resid = length;
+ data = list_first_entry(&msg->data, struct ceph_msg_data, links);
+ cursor->data = data;
+
+ __ceph_msg_data_cursor_init(cursor);
+}
+
/*
* Return the page containing the next piece to process for a given
* data item, and supply the page offset and length of that piece.
BUG();
break;
}
+ cursor->total_resid -= bytes;
cursor->need_crc = new_piece;
+ if (!cursor->resid && cursor->total_resid) {
+ WARN_ON(!cursor->last_piece);
+ BUG_ON(list_is_last(&cursor->data->links, cursor->data_head));
+ cursor->data = list_entry_next(cursor->data, links);
+ __ceph_msg_data_cursor_init(cursor);
+ }
+
return new_piece;
}
BUG_ON(!pages);
BUG_ON(!length);
- BUG_ON(msg->data_length);
- BUG_ON(!list_empty(&msg->data));
data = ceph_msg_data_create(CEPH_MSG_DATA_PAGES);
BUG_ON(!data);
BUG_ON(!pagelist);
BUG_ON(!pagelist->length);
- BUG_ON(msg->data_length);
- BUG_ON(!list_empty(&msg->data));
data = ceph_msg_data_create(CEPH_MSG_DATA_PAGELIST);
BUG_ON(!data);
struct ceph_msg_data *data;
BUG_ON(!bio);
- BUG_ON(msg->data_length);
- BUG_ON(!list_empty(&msg->data));
data = ceph_msg_data_create(CEPH_MSG_DATA_BIO);
BUG_ON(!data);