Skip to content

Commit 36153ec

Browse files
Alex ElderSage Weil
authored andcommitted
libceph: move cursor into message
A message will only be processing a single data item at a time, so there's no need for each data item to have its own cursor. Move the cursor embedded in the message data structure into the message itself. To minimize the impact, keep the data->cursor field, but make it be a pointer to the cursor in the message. Move the definition of ceph_msg_data above ceph_msg_data_cursor so the cursor can point to the data without a forward definition rather than vice-versa. This and the upcoming patches are part of: http://tracker.ceph.com/issues/3761 Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
1 parent c851c49 commit 36153ec

2 files changed

Lines changed: 41 additions & 37 deletions

File tree

‎include/linux/ceph/messenger.h‎

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,25 @@ static __inline__ bool ceph_msg_data_type_valid(enum ceph_msg_data_type type)
8888
}
8989
}
9090

91+
struct ceph_msg_data {
92+
enum ceph_msg_data_type type;
93+
union {
94+
#ifdef CONFIG_BLOCK
95+
struct {
96+
struct bio *bio;
97+
size_t bio_length;
98+
};
99+
#endif /* CONFIG_BLOCK */
100+
struct {
101+
struct page **pages; /* NOT OWNER. */
102+
size_t length; /* total # bytes */
103+
unsigned int alignment; /* first page */
104+
};
105+
struct ceph_pagelist *pagelist;
106+
};
107+
struct ceph_msg_data_cursor *cursor;
108+
};
109+
91110
struct ceph_msg_data_cursor {
92111
size_t resid; /* bytes not yet consumed */
93112
bool last_piece; /* now at last piece of data item */
@@ -112,25 +131,6 @@ struct ceph_msg_data_cursor {
112131
};
113132
};
114133

115-
struct ceph_msg_data {
116-
enum ceph_msg_data_type type;
117-
union {
118-
#ifdef CONFIG_BLOCK
119-
struct {
120-
struct bio *bio;
121-
size_t bio_length;
122-
};
123-
#endif /* CONFIG_BLOCK */
124-
struct {
125-
struct page **pages; /* NOT OWNER. */
126-
size_t length; /* total # bytes */
127-
unsigned int alignment; /* first page */
128-
};
129-
struct ceph_pagelist *pagelist;
130-
};
131-
struct ceph_msg_data_cursor cursor; /* pagelist only */
132-
};
133-
134134
/*
135135
* a single message. it contains a header (src, dest, message type, etc.),
136136
* footer (crc values, mainly), a "front" message body, and possibly a
@@ -142,8 +142,9 @@ struct ceph_msg {
142142
struct kvec front; /* unaligned blobs of message */
143143
struct ceph_buffer *middle;
144144

145-
size_t data_length;
146-
struct ceph_msg_data *data; /* data payload */
145+
size_t data_length;
146+
struct ceph_msg_data *data;
147+
struct ceph_msg_data_cursor cursor;
147148

148149
struct ceph_connection *con;
149150
struct list_head list_head; /* links for connection lists */

‎net/ceph/messenger.c‎

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ static void con_out_kvec_add(struct ceph_connection *con,
725725
static void ceph_msg_data_bio_cursor_init(struct ceph_msg_data *data,
726726
size_t length)
727727
{
728-
struct ceph_msg_data_cursor *cursor = &data->cursor;
728+
struct ceph_msg_data_cursor *cursor = data->cursor;
729729
struct bio *bio;
730730

731731
BUG_ON(data->type != CEPH_MSG_DATA_BIO);
@@ -745,7 +745,7 @@ static struct page *ceph_msg_data_bio_next(struct ceph_msg_data *data,
745745
size_t *page_offset,
746746
size_t *length)
747747
{
748-
struct ceph_msg_data_cursor *cursor = &data->cursor;
748+
struct ceph_msg_data_cursor *cursor = data->cursor;
749749
struct bio *bio;
750750
struct bio_vec *bio_vec;
751751
unsigned int index;
@@ -774,7 +774,7 @@ static struct page *ceph_msg_data_bio_next(struct ceph_msg_data *data,
774774

775775
static bool ceph_msg_data_bio_advance(struct ceph_msg_data *data, size_t bytes)
776776
{
777-
struct ceph_msg_data_cursor *cursor = &data->cursor;
777+
struct ceph_msg_data_cursor *cursor = data->cursor;
778778
struct bio *bio;
779779
struct bio_vec *bio_vec;
780780
unsigned int index;
@@ -826,7 +826,7 @@ static bool ceph_msg_data_bio_advance(struct ceph_msg_data *data, size_t bytes)
826826
static void ceph_msg_data_pages_cursor_init(struct ceph_msg_data *data,
827827
size_t length)
828828
{
829-
struct ceph_msg_data_cursor *cursor = &data->cursor;
829+
struct ceph_msg_data_cursor *cursor = data->cursor;
830830
int page_count;
831831

832832
BUG_ON(data->type != CEPH_MSG_DATA_PAGES);
@@ -849,7 +849,7 @@ static struct page *ceph_msg_data_pages_next(struct ceph_msg_data *data,
849849
size_t *page_offset,
850850
size_t *length)
851851
{
852-
struct ceph_msg_data_cursor *cursor = &data->cursor;
852+
struct ceph_msg_data_cursor *cursor = data->cursor;
853853

854854
BUG_ON(data->type != CEPH_MSG_DATA_PAGES);
855855

@@ -868,7 +868,7 @@ static struct page *ceph_msg_data_pages_next(struct ceph_msg_data *data,
868868
static bool ceph_msg_data_pages_advance(struct ceph_msg_data *data,
869869
size_t bytes)
870870
{
871-
struct ceph_msg_data_cursor *cursor = &data->cursor;
871+
struct ceph_msg_data_cursor *cursor = data->cursor;
872872

873873
BUG_ON(data->type != CEPH_MSG_DATA_PAGES);
874874

@@ -897,7 +897,7 @@ static bool ceph_msg_data_pages_advance(struct ceph_msg_data *data,
897897
static void ceph_msg_data_pagelist_cursor_init(struct ceph_msg_data *data,
898898
size_t length)
899899
{
900-
struct ceph_msg_data_cursor *cursor = &data->cursor;
900+
struct ceph_msg_data_cursor *cursor = data->cursor;
901901
struct ceph_pagelist *pagelist;
902902
struct page *page;
903903

@@ -923,7 +923,7 @@ static struct page *ceph_msg_data_pagelist_next(struct ceph_msg_data *data,
923923
size_t *page_offset,
924924
size_t *length)
925925
{
926-
struct ceph_msg_data_cursor *cursor = &data->cursor;
926+
struct ceph_msg_data_cursor *cursor = data->cursor;
927927
struct ceph_pagelist *pagelist;
928928

929929
BUG_ON(data->type != CEPH_MSG_DATA_PAGELIST);
@@ -941,13 +941,13 @@ static struct page *ceph_msg_data_pagelist_next(struct ceph_msg_data *data,
941941
else
942942
*length = PAGE_SIZE - *page_offset;
943943

944-
return data->cursor.page;
944+
return data->cursor->page;
945945
}
946946

947947
static bool ceph_msg_data_pagelist_advance(struct ceph_msg_data *data,
948948
size_t bytes)
949949
{
950-
struct ceph_msg_data_cursor *cursor = &data->cursor;
950+
struct ceph_msg_data_cursor *cursor = data->cursor;
951951
struct ceph_pagelist *pagelist;
952952

953953
BUG_ON(data->type != CEPH_MSG_DATA_PAGELIST);
@@ -1003,7 +1003,7 @@ static void ceph_msg_data_cursor_init(struct ceph_msg_data *data,
10031003
/* BUG(); */
10041004
break;
10051005
}
1006-
data->cursor.need_crc = true;
1006+
data->cursor->need_crc = true;
10071007
}
10081008

10091009
/*
@@ -1039,7 +1039,7 @@ static struct page *ceph_msg_data_next(struct ceph_msg_data *data,
10391039
BUG_ON(*page_offset + *length > PAGE_SIZE);
10401040
BUG_ON(!*length);
10411041
if (last_piece)
1042-
*last_piece = data->cursor.last_piece;
1042+
*last_piece = data->cursor->last_piece;
10431043

10441044
return page;
10451045
}
@@ -1050,7 +1050,7 @@ static struct page *ceph_msg_data_next(struct ceph_msg_data *data,
10501050
*/
10511051
static bool ceph_msg_data_advance(struct ceph_msg_data *data, size_t bytes)
10521052
{
1053-
struct ceph_msg_data_cursor *cursor = &data->cursor;
1053+
struct ceph_msg_data_cursor *cursor = data->cursor;
10541054
bool new_piece;
10551055

10561056
BUG_ON(bytes > cursor->resid);
@@ -1071,7 +1071,7 @@ static bool ceph_msg_data_advance(struct ceph_msg_data *data, size_t bytes)
10711071
BUG();
10721072
break;
10731073
}
1074-
data->cursor.need_crc = new_piece;
1074+
data->cursor->need_crc = new_piece;
10751075

10761076
return new_piece;
10771077
}
@@ -1404,7 +1404,7 @@ static u32 ceph_crc32c_page(u32 crc, struct page *page,
14041404
static int write_partial_message_data(struct ceph_connection *con)
14051405
{
14061406
struct ceph_msg *msg = con->out_msg;
1407-
struct ceph_msg_data_cursor *cursor = &msg->data->cursor;
1407+
struct ceph_msg_data_cursor *cursor = msg->data->cursor;
14081408
bool do_datacrc = !con->msgr->nocrc;
14091409
u32 crc;
14101410

@@ -2102,7 +2102,7 @@ static int read_partial_message_section(struct ceph_connection *con,
21022102
static int read_partial_msg_data(struct ceph_connection *con)
21032103
{
21042104
struct ceph_msg *msg = con->in_msg;
2105-
struct ceph_msg_data_cursor *cursor = &msg->data->cursor;
2105+
struct ceph_msg_data_cursor *cursor = msg->data->cursor;
21062106
const bool do_datacrc = !con->msgr->nocrc;
21072107
struct page *page;
21082108
size_t page_offset;
@@ -2991,6 +2991,7 @@ void ceph_msg_data_set_pages(struct ceph_msg *msg, struct page **pages,
29912991

29922992
data = ceph_msg_data_create(CEPH_MSG_DATA_PAGES);
29932993
BUG_ON(!data);
2994+
data->cursor = &msg->cursor;
29942995
data->pages = pages;
29952996
data->length = length;
29962997
data->alignment = alignment & ~PAGE_MASK;
@@ -3012,6 +3013,7 @@ void ceph_msg_data_set_pagelist(struct ceph_msg *msg,
30123013

30133014
data = ceph_msg_data_create(CEPH_MSG_DATA_PAGELIST);
30143015
BUG_ON(!data);
3016+
data->cursor = &msg->cursor;
30153017
data->pagelist = pagelist;
30163018

30173019
msg->data = data;
@@ -3031,6 +3033,7 @@ void ceph_msg_data_set_bio(struct ceph_msg *msg, struct bio *bio,
30313033

30323034
data = ceph_msg_data_create(CEPH_MSG_DATA_BIO);
30333035
BUG_ON(!data);
3036+
data->cursor = &msg->cursor;
30343037
data->bio = bio;
30353038
data->bio_length = length;
30363039

0 commit comments

Comments
 (0)