diff options
author | Alex Elder <elder@inktank.com> | 2013-03-08 21:58:59 -0500 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2013-05-02 00:16:50 -0400 |
commit | 34d2d2006cc82fd21f716e10568b8c8b4ef61c0e (patch) | |
tree | 5b3cf676932c10274c6a1beb36d292a7a5251e23 /net | |
parent | e387d525b0ceeecf07b074781eab77414dc9697e (diff) |
libceph: encapsulate reading message data
Pull the code that reads the data portion into a message into
a separate function read_partial_msg_data().
Rename write_partial_msg_pages() to be write_partial_message_data()
to match its read counterpart, and to reflect its more generic
purpose.
Signed-off-by: Alex Elder <elder@inktank.com>
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
Diffstat (limited to 'net')
-rw-r--r-- | net/ceph/messenger.c | 63 |
1 files changed, 41 insertions, 22 deletions
diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c index 813c29924d56..6e0bd36d676a 100644 --- a/net/ceph/messenger.c +++ b/net/ceph/messenger.c | |||
@@ -1076,7 +1076,7 @@ static void in_msg_pos_next(struct ceph_connection *con, size_t len, | |||
1076 | * 0 -> socket full, but more to do | 1076 | * 0 -> socket full, but more to do |
1077 | * <0 -> error | 1077 | * <0 -> error |
1078 | */ | 1078 | */ |
1079 | static int write_partial_msg_pages(struct ceph_connection *con) | 1079 | static int write_partial_message_data(struct ceph_connection *con) |
1080 | { | 1080 | { |
1081 | struct ceph_msg *msg = con->out_msg; | 1081 | struct ceph_msg *msg = con->out_msg; |
1082 | struct ceph_msg_pos *msg_pos = &con->out_msg_pos; | 1082 | struct ceph_msg_pos *msg_pos = &con->out_msg_pos; |
@@ -1088,7 +1088,7 @@ static int write_partial_msg_pages(struct ceph_connection *con) | |||
1088 | const size_t trail_len = (msg->trail ? msg->trail->length : 0); | 1088 | const size_t trail_len = (msg->trail ? msg->trail->length : 0); |
1089 | const size_t trail_off = data_len - trail_len; | 1089 | const size_t trail_off = data_len - trail_len; |
1090 | 1090 | ||
1091 | dout("write_partial_msg_pages %p msg %p page %d offset %d\n", | 1091 | dout("%s %p msg %p page %d offset %d\n", __func__, |
1092 | con, msg, msg_pos->page, msg_pos->page_pos); | 1092 | con, msg, msg_pos->page, msg_pos->page_pos); |
1093 | 1093 | ||
1094 | /* | 1094 | /* |
@@ -1157,7 +1157,7 @@ static int write_partial_msg_pages(struct ceph_connection *con) | |||
1157 | out_msg_pos_next(con, page, length, (size_t) ret, in_trail); | 1157 | out_msg_pos_next(con, page, length, (size_t) ret, in_trail); |
1158 | } | 1158 | } |
1159 | 1159 | ||
1160 | dout("write_partial_msg_pages %p msg %p done\n", con, msg); | 1160 | dout("%s %p msg %p done\n", __func__, con, msg); |
1161 | 1161 | ||
1162 | /* prepare and queue up footer, too */ | 1162 | /* prepare and queue up footer, too */ |
1163 | if (!do_datacrc) | 1163 | if (!do_datacrc) |
@@ -1869,13 +1869,44 @@ static int read_partial_message_bio(struct ceph_connection *con, | |||
1869 | } | 1869 | } |
1870 | #endif | 1870 | #endif |
1871 | 1871 | ||
1872 | static int read_partial_msg_data(struct ceph_connection *con) | ||
1873 | { | ||
1874 | struct ceph_msg *msg = con->in_msg; | ||
1875 | struct ceph_msg_pos *msg_pos = &con->in_msg_pos; | ||
1876 | const bool do_datacrc = !con->msgr->nocrc; | ||
1877 | unsigned int data_len; | ||
1878 | int ret; | ||
1879 | |||
1880 | BUG_ON(!msg); | ||
1881 | |||
1882 | data_len = le32_to_cpu(con->in_hdr.data_len); | ||
1883 | while (msg_pos->data_pos < data_len) { | ||
1884 | if (msg->pages) { | ||
1885 | ret = read_partial_message_pages(con, msg->pages, | ||
1886 | data_len, do_datacrc); | ||
1887 | if (ret <= 0) | ||
1888 | return ret; | ||
1889 | #ifdef CONFIG_BLOCK | ||
1890 | } else if (msg->bio) { | ||
1891 | ret = read_partial_message_bio(con, | ||
1892 | data_len, do_datacrc); | ||
1893 | if (ret <= 0) | ||
1894 | return ret; | ||
1895 | #endif | ||
1896 | } else { | ||
1897 | BUG_ON(1); | ||
1898 | } | ||
1899 | } | ||
1900 | |||
1901 | return 1; /* must return > 0 to indicate success */ | ||
1902 | } | ||
1903 | |||
1872 | /* | 1904 | /* |
1873 | * read (part of) a message. | 1905 | * read (part of) a message. |
1874 | */ | 1906 | */ |
1875 | static int read_partial_message(struct ceph_connection *con) | 1907 | static int read_partial_message(struct ceph_connection *con) |
1876 | { | 1908 | { |
1877 | struct ceph_msg *m = con->in_msg; | 1909 | struct ceph_msg *m = con->in_msg; |
1878 | struct ceph_msg_pos *msg_pos = &con->in_msg_pos; | ||
1879 | int size; | 1910 | int size; |
1880 | int end; | 1911 | int end; |
1881 | int ret; | 1912 | int ret; |
@@ -1978,22 +2009,10 @@ static int read_partial_message(struct ceph_connection *con) | |||
1978 | } | 2009 | } |
1979 | 2010 | ||
1980 | /* (page) data */ | 2011 | /* (page) data */ |
1981 | while (msg_pos->data_pos < data_len) { | 2012 | if (data_len) { |
1982 | if (m->pages) { | 2013 | ret = read_partial_msg_data(con); |
1983 | ret = read_partial_message_pages(con, m->pages, | 2014 | if (ret <= 0) |
1984 | data_len, do_datacrc); | 2015 | return ret; |
1985 | if (ret <= 0) | ||
1986 | return ret; | ||
1987 | #ifdef CONFIG_BLOCK | ||
1988 | } else if (m->bio) { | ||
1989 | ret = read_partial_message_bio(con, | ||
1990 | data_len, do_datacrc); | ||
1991 | if (ret <= 0) | ||
1992 | return ret; | ||
1993 | #endif | ||
1994 | } else { | ||
1995 | BUG_ON(1); | ||
1996 | } | ||
1997 | } | 2016 | } |
1998 | 2017 | ||
1999 | /* footer */ | 2018 | /* footer */ |
@@ -2119,13 +2138,13 @@ more_kvec: | |||
2119 | goto do_next; | 2138 | goto do_next; |
2120 | } | 2139 | } |
2121 | 2140 | ||
2122 | ret = write_partial_msg_pages(con); | 2141 | ret = write_partial_message_data(con); |
2123 | if (ret == 1) | 2142 | if (ret == 1) |
2124 | goto more_kvec; /* we need to send the footer, too! */ | 2143 | goto more_kvec; /* we need to send the footer, too! */ |
2125 | if (ret == 0) | 2144 | if (ret == 0) |
2126 | goto out; | 2145 | goto out; |
2127 | if (ret < 0) { | 2146 | if (ret < 0) { |
2128 | dout("try_write write_partial_msg_pages err %d\n", | 2147 | dout("try_write write_partial_message_data err %d\n", |
2129 | ret); | 2148 | ret); |
2130 | goto out; | 2149 | goto out; |
2131 | } | 2150 | } |