libceph: fix socket read error handling

If we get EAGAIN when trying to read from the socket, it is not an error.
Return 0 from the helper in this case to simplify the error handling cases
in the caller (indirectly, try_read).

Fix try_read to pass any error to it's caller (con_work) instead of almost
always returning 0. This let's us respond to things like socket
disconnects.

Signed-off-by: Sage Weil <sage@newdream.net>

Sage Weil 98bdb0aa d66bbd44

+19 -20
+19 -20
net/ceph/messenger.c
··· 252 { 253 struct kvec iov = {buf, len}; 254 struct msghdr msg = { .msg_flags = MSG_DONTWAIT | MSG_NOSIGNAL }; 255 256 - return kernel_recvmsg(sock, &msg, &iov, 1, len, msg.msg_flags); 257 } 258 259 /* ··· 1825 dout("try_read connecting\n"); 1826 ret = read_partial_banner(con); 1827 if (ret <= 0) 1828 - goto done; 1829 - if (process_banner(con) < 0) { 1830 - ret = -1; 1831 goto out; 1832 - } 1833 } 1834 ret = read_partial_connect(con); 1835 if (ret <= 0) 1836 - goto done; 1837 - if (process_connect(con) < 0) { 1838 - ret = -1; 1839 goto out; 1840 - } 1841 goto more; 1842 } 1843 ··· 1850 dout("skipping %d / %d bytes\n", skip, -con->in_base_pos); 1851 ret = ceph_tcp_recvmsg(con->sock, buf, skip); 1852 if (ret <= 0) 1853 - goto done; 1854 con->in_base_pos += ret; 1855 if (con->in_base_pos) 1856 goto more; ··· 1861 */ 1862 ret = ceph_tcp_recvmsg(con->sock, &con->in_tag, 1); 1863 if (ret <= 0) 1864 - goto done; 1865 dout("try_read got tag %d\n", (int)con->in_tag); 1866 switch (con->in_tag) { 1867 case CEPH_MSGR_TAG_MSG: ··· 1872 break; 1873 case CEPH_MSGR_TAG_CLOSE: 1874 set_bit(CLOSED, &con->state); /* fixme */ 1875 - goto done; 1876 default: 1877 goto bad_tag; 1878 } ··· 1884 case -EBADMSG: 1885 con->error_msg = "bad crc"; 1886 ret = -EIO; 1887 - goto out; 1888 case -EIO: 1889 con->error_msg = "io error"; 1890 - goto out; 1891 - default: 1892 - goto done; 1893 } 1894 } 1895 if (con->in_tag == CEPH_MSGR_TAG_READY) 1896 goto more; ··· 1899 if (con->in_tag == CEPH_MSGR_TAG_ACK) { 1900 ret = read_partial_ack(con); 1901 if (ret <= 0) 1902 - goto done; 1903 process_ack(con); 1904 goto more; 1905 } 1906 1907 - done: 1908 - ret = 0; 1909 out: 1910 - dout("try_read done on %p\n", con); 1911 return ret; 1912 1913 bad_tag:
··· 252 { 253 struct kvec iov = {buf, len}; 254 struct msghdr msg = { .msg_flags = MSG_DONTWAIT | MSG_NOSIGNAL }; 255 + int r; 256 257 + r = kernel_recvmsg(sock, &msg, &iov, 1, len, msg.msg_flags); 258 + if (r == -EAGAIN) 259 + r = 0; 260 + return r; 261 } 262 263 /* ··· 1821 dout("try_read connecting\n"); 1822 ret = read_partial_banner(con); 1823 if (ret <= 0) 1824 goto out; 1825 + ret = process_banner(con); 1826 + if (ret < 0) 1827 + goto out; 1828 } 1829 ret = read_partial_connect(con); 1830 if (ret <= 0) 1831 goto out; 1832 + ret = process_connect(con); 1833 + if (ret < 0) 1834 + goto out; 1835 goto more; 1836 } 1837 ··· 1848 dout("skipping %d / %d bytes\n", skip, -con->in_base_pos); 1849 ret = ceph_tcp_recvmsg(con->sock, buf, skip); 1850 if (ret <= 0) 1851 + goto out; 1852 con->in_base_pos += ret; 1853 if (con->in_base_pos) 1854 goto more; ··· 1859 */ 1860 ret = ceph_tcp_recvmsg(con->sock, &con->in_tag, 1); 1861 if (ret <= 0) 1862 + goto out; 1863 dout("try_read got tag %d\n", (int)con->in_tag); 1864 switch (con->in_tag) { 1865 case CEPH_MSGR_TAG_MSG: ··· 1870 break; 1871 case CEPH_MSGR_TAG_CLOSE: 1872 set_bit(CLOSED, &con->state); /* fixme */ 1873 + goto out; 1874 default: 1875 goto bad_tag; 1876 } ··· 1882 case -EBADMSG: 1883 con->error_msg = "bad crc"; 1884 ret = -EIO; 1885 + break; 1886 case -EIO: 1887 con->error_msg = "io error"; 1888 + break; 1889 } 1890 + goto out; 1891 } 1892 if (con->in_tag == CEPH_MSGR_TAG_READY) 1893 goto more; ··· 1898 if (con->in_tag == CEPH_MSGR_TAG_ACK) { 1899 ret = read_partial_ack(con); 1900 if (ret <= 0) 1901 + goto out; 1902 process_ack(con); 1903 goto more; 1904 } 1905 1906 out: 1907 + dout("try_read done on %p ret %d\n", con, ret); 1908 return ret; 1909 1910 bad_tag: