diff options
author | Alex Elder <elder@inktank.com> | 2013-03-12 00:34:23 -0400 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2013-05-02 00:17:29 -0400 |
commit | 686be20875db63c6103573565c63db20153ee6e1 (patch) | |
tree | 1bf80f78424ce402a56a3782572652f42253e214 /net/ceph/messenger.c | |
parent | 61fcdc97c06bce7b6d16dd2a6b478f24cd121d96 (diff) |
libceph: get rid of read helpers
Now that read_partial_message_pages() and read_partial_message_bio()
are literally identical functions we can factor them out. They're
pretty simple as well, so just move their relevant content into
read_partial_msg_data().
This is and previous patches together resolve:
http://tracker.ceph.com/issues/4428
Signed-off-by: Alex Elder <elder@inktank.com>
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
Diffstat (limited to 'net/ceph/messenger.c')
-rw-r--r-- | net/ceph/messenger.c | 80 |
1 files changed, 18 insertions, 62 deletions
diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c index 598d21830417..a19ba00ce777 100644 --- a/net/ceph/messenger.c +++ b/net/ceph/messenger.c | |||
@@ -2185,66 +2185,15 @@ static int read_partial_message_section(struct ceph_connection *con, | |||
2185 | return 1; | 2185 | return 1; |
2186 | } | 2186 | } |
2187 | 2187 | ||
2188 | static int ceph_con_in_msg_alloc(struct ceph_connection *con, int *skip); | ||
2189 | |||
2190 | static int read_partial_message_pages(struct ceph_connection *con, | ||
2191 | unsigned int data_len, bool do_datacrc) | ||
2192 | { | ||
2193 | struct ceph_msg *msg = con->in_msg; | ||
2194 | struct page *page; | ||
2195 | size_t page_offset; | ||
2196 | size_t length; | ||
2197 | int ret; | ||
2198 | |||
2199 | page = ceph_msg_data_next(&msg->p, &page_offset, &length, NULL); | ||
2200 | |||
2201 | ret = ceph_tcp_recvpage(con->sock, page, page_offset, length); | ||
2202 | if (ret <= 0) | ||
2203 | return ret; | ||
2204 | |||
2205 | if (do_datacrc) | ||
2206 | con->in_data_crc = ceph_crc32c_page(con->in_data_crc, page, | ||
2207 | page_offset, ret); | ||
2208 | |||
2209 | in_msg_pos_next(con, length, ret); | ||
2210 | |||
2211 | return ret; | ||
2212 | } | ||
2213 | |||
2214 | #ifdef CONFIG_BLOCK | ||
2215 | static int read_partial_message_bio(struct ceph_connection *con, | ||
2216 | unsigned int data_len, bool do_datacrc) | ||
2217 | { | ||
2218 | struct ceph_msg *msg = con->in_msg; | ||
2219 | struct page *page; | ||
2220 | size_t page_offset; | ||
2221 | size_t length; | ||
2222 | int ret; | ||
2223 | |||
2224 | BUG_ON(!msg); | ||
2225 | |||
2226 | page = ceph_msg_data_next(&msg->b, &page_offset, &length, NULL); | ||
2227 | |||
2228 | ret = ceph_tcp_recvpage(con->sock, page, page_offset, length); | ||
2229 | if (ret <= 0) | ||
2230 | return ret; | ||
2231 | |||
2232 | if (do_datacrc) | ||
2233 | con->in_data_crc = ceph_crc32c_page(con->in_data_crc, page, | ||
2234 | page_offset, ret); | ||
2235 | |||
2236 | in_msg_pos_next(con, length, ret); | ||
2237 | |||
2238 | return ret; | ||
2239 | } | ||
2240 | #endif | ||
2241 | |||
2242 | static int read_partial_msg_data(struct ceph_connection *con) | 2188 | static int read_partial_msg_data(struct ceph_connection *con) |
2243 | { | 2189 | { |
2244 | struct ceph_msg *msg = con->in_msg; | 2190 | struct ceph_msg *msg = con->in_msg; |
2245 | struct ceph_msg_pos *msg_pos = &con->in_msg_pos; | 2191 | struct ceph_msg_pos *msg_pos = &con->in_msg_pos; |
2246 | const bool do_datacrc = !con->msgr->nocrc; | 2192 | const bool do_datacrc = !con->msgr->nocrc; |
2247 | unsigned int data_len; | 2193 | unsigned int data_len; |
2194 | struct page *page; | ||
2195 | size_t page_offset; | ||
2196 | size_t length; | ||
2248 | int ret; | 2197 | int ret; |
2249 | 2198 | ||
2250 | BUG_ON(!msg); | 2199 | BUG_ON(!msg); |
@@ -2252,20 +2201,25 @@ static int read_partial_msg_data(struct ceph_connection *con) | |||
2252 | data_len = le32_to_cpu(con->in_hdr.data_len); | 2201 | data_len = le32_to_cpu(con->in_hdr.data_len); |
2253 | while (msg_pos->data_pos < data_len) { | 2202 | while (msg_pos->data_pos < data_len) { |
2254 | if (ceph_msg_has_pages(msg)) { | 2203 | if (ceph_msg_has_pages(msg)) { |
2255 | ret = read_partial_message_pages(con, data_len, | 2204 | page = ceph_msg_data_next(&msg->p, &page_offset, |
2256 | do_datacrc); | 2205 | &length, NULL); |
2257 | if (ret <= 0) | ||
2258 | return ret; | ||
2259 | #ifdef CONFIG_BLOCK | 2206 | #ifdef CONFIG_BLOCK |
2260 | } else if (ceph_msg_has_bio(msg)) { | 2207 | } else if (ceph_msg_has_bio(msg)) { |
2261 | ret = read_partial_message_bio(con, | 2208 | page = ceph_msg_data_next(&msg->b, &page_offset, |
2262 | data_len, do_datacrc); | 2209 | &length, NULL); |
2263 | if (ret <= 0) | ||
2264 | return ret; | ||
2265 | #endif | 2210 | #endif |
2266 | } else { | 2211 | } else { |
2267 | BUG_ON(1); | 2212 | BUG_ON(1); |
2268 | } | 2213 | } |
2214 | ret = ceph_tcp_recvpage(con->sock, page, page_offset, length); | ||
2215 | if (ret <= 0) | ||
2216 | return ret; | ||
2217 | |||
2218 | if (do_datacrc) | ||
2219 | con->in_data_crc = ceph_crc32c_page(con->in_data_crc, | ||
2220 | page, page_offset, ret); | ||
2221 | |||
2222 | in_msg_pos_next(con, length, ret); | ||
2269 | } | 2223 | } |
2270 | 2224 | ||
2271 | return 1; /* must return > 0 to indicate success */ | 2225 | return 1; /* must return > 0 to indicate success */ |
@@ -2274,6 +2228,8 @@ static int read_partial_msg_data(struct ceph_connection *con) | |||
2274 | /* | 2228 | /* |
2275 | * read (part of) a message. | 2229 | * read (part of) a message. |
2276 | */ | 2230 | */ |
2231 | static int ceph_con_in_msg_alloc(struct ceph_connection *con, int *skip); | ||
2232 | |||
2277 | static int read_partial_message(struct ceph_connection *con) | 2233 | static int read_partial_message(struct ceph_connection *con) |
2278 | { | 2234 | { |
2279 | struct ceph_msg *m = con->in_msg; | 2235 | struct ceph_msg *m = con->in_msg; |