diff options
Diffstat (limited to 'fs/cifs/transport.c')
-rw-r--r-- | fs/cifs/transport.c | 127 |
1 files changed, 38 insertions, 89 deletions
diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index 7ebe6599ed3a..0ad3e2d116a6 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c | |||
@@ -154,81 +154,8 @@ void DeleteTconOplockQEntries(struct cifsTconInfo *tcon) | |||
154 | spin_unlock(&GlobalMid_Lock); | 154 | spin_unlock(&GlobalMid_Lock); |
155 | } | 155 | } |
156 | 156 | ||
157 | int | ||
158 | smb_send(struct socket *ssocket, struct smb_hdr *smb_buffer, | ||
159 | unsigned int smb_buf_length, struct sockaddr *sin, bool noblocksnd) | ||
160 | { | ||
161 | int rc = 0; | ||
162 | int i = 0; | ||
163 | struct msghdr smb_msg; | ||
164 | struct kvec iov; | ||
165 | unsigned len = smb_buf_length + 4; | ||
166 | |||
167 | if (ssocket == NULL) | ||
168 | return -ENOTSOCK; /* BB eventually add reconnect code here */ | ||
169 | iov.iov_base = smb_buffer; | ||
170 | iov.iov_len = len; | ||
171 | |||
172 | smb_msg.msg_name = sin; | ||
173 | smb_msg.msg_namelen = sizeof(struct sockaddr); | ||
174 | smb_msg.msg_control = NULL; | ||
175 | smb_msg.msg_controllen = 0; | ||
176 | if (noblocksnd) | ||
177 | smb_msg.msg_flags = MSG_DONTWAIT + MSG_NOSIGNAL; | ||
178 | else | ||
179 | smb_msg.msg_flags = MSG_NOSIGNAL; | ||
180 | |||
181 | /* smb header is converted in header_assemble. bcc and rest of SMB word | ||
182 | area, and byte area if necessary, is converted to littleendian in | ||
183 | cifssmb.c and RFC1001 len is converted to bigendian in smb_send | ||
184 | Flags2 is converted in SendReceive */ | ||
185 | |||
186 | smb_buffer->smb_buf_length = cpu_to_be32(smb_buffer->smb_buf_length); | ||
187 | cFYI(1, ("Sending smb of length %d", smb_buf_length)); | ||
188 | dump_smb(smb_buffer, len); | ||
189 | |||
190 | while (len > 0) { | ||
191 | rc = kernel_sendmsg(ssocket, &smb_msg, &iov, 1, len); | ||
192 | if ((rc == -ENOSPC) || (rc == -EAGAIN)) { | ||
193 | i++; | ||
194 | /* smaller timeout here than send2 since smaller size */ | ||
195 | /* Although it may not be required, this also is smaller | ||
196 | oplock break time */ | ||
197 | if (i > 12) { | ||
198 | cERROR(1, | ||
199 | ("sends on sock %p stuck for 7 seconds", | ||
200 | ssocket)); | ||
201 | rc = -EAGAIN; | ||
202 | break; | ||
203 | } | ||
204 | msleep(1 << i); | ||
205 | continue; | ||
206 | } | ||
207 | if (rc < 0) | ||
208 | break; | ||
209 | else | ||
210 | i = 0; /* reset i after each successful send */ | ||
211 | iov.iov_base += rc; | ||
212 | iov.iov_len -= rc; | ||
213 | len -= rc; | ||
214 | } | ||
215 | |||
216 | if (rc < 0) { | ||
217 | cERROR(1, ("Error %d sending data on socket to server", rc)); | ||
218 | } else { | ||
219 | rc = 0; | ||
220 | } | ||
221 | |||
222 | /* Don't want to modify the buffer as a | ||
223 | side effect of this call. */ | ||
224 | smb_buffer->smb_buf_length = smb_buf_length; | ||
225 | |||
226 | return rc; | ||
227 | } | ||
228 | |||
229 | static int | 157 | static int |
230 | smb_send2(struct TCP_Server_Info *server, struct kvec *iov, int n_vec, | 158 | smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec) |
231 | struct sockaddr *sin, bool noblocksnd) | ||
232 | { | 159 | { |
233 | int rc = 0; | 160 | int rc = 0; |
234 | int i = 0; | 161 | int i = 0; |
@@ -243,11 +170,11 @@ smb_send2(struct TCP_Server_Info *server, struct kvec *iov, int n_vec, | |||
243 | if (ssocket == NULL) | 170 | if (ssocket == NULL) |
244 | return -ENOTSOCK; /* BB eventually add reconnect code here */ | 171 | return -ENOTSOCK; /* BB eventually add reconnect code here */ |
245 | 172 | ||
246 | smb_msg.msg_name = sin; | 173 | smb_msg.msg_name = (struct sockaddr *) &server->addr.sockAddr; |
247 | smb_msg.msg_namelen = sizeof(struct sockaddr); | 174 | smb_msg.msg_namelen = sizeof(struct sockaddr); |
248 | smb_msg.msg_control = NULL; | 175 | smb_msg.msg_control = NULL; |
249 | smb_msg.msg_controllen = 0; | 176 | smb_msg.msg_controllen = 0; |
250 | if (noblocksnd) | 177 | if (server->noblocksnd) |
251 | smb_msg.msg_flags = MSG_DONTWAIT + MSG_NOSIGNAL; | 178 | smb_msg.msg_flags = MSG_DONTWAIT + MSG_NOSIGNAL; |
252 | else | 179 | else |
253 | smb_msg.msg_flags = MSG_NOSIGNAL; | 180 | smb_msg.msg_flags = MSG_NOSIGNAL; |
@@ -272,7 +199,25 @@ smb_send2(struct TCP_Server_Info *server, struct kvec *iov, int n_vec, | |||
272 | n_vec - first_vec, total_len); | 199 | n_vec - first_vec, total_len); |
273 | if ((rc == -ENOSPC) || (rc == -EAGAIN)) { | 200 | if ((rc == -ENOSPC) || (rc == -EAGAIN)) { |
274 | i++; | 201 | i++; |
275 | if (i >= 14) { | 202 | /* if blocking send we try 3 times, since each can block |
203 | for 5 seconds. For nonblocking we have to try more | ||
204 | but wait increasing amounts of time allowing time for | ||
205 | socket to clear. The overall time we wait in either | ||
206 | case to send on the socket is about 15 seconds. | ||
207 | Similarly we wait for 15 seconds for | ||
208 | a response from the server in SendReceive[2] | ||
209 | for the server to send a response back for | ||
210 | most types of requests (except SMB Write | ||
211 | past end of file which can be slow, and | ||
212 | blocking lock operations). NFS waits slightly longer | ||
213 | than CIFS, but this can make it take longer for | ||
214 | nonresponsive servers to be detected and 15 seconds | ||
215 | is more than enough time for modern networks to | ||
216 | send a packet. In most cases if we fail to send | ||
217 | after the retries we will kill the socket and | ||
218 | reconnect which may clear the network problem. | ||
219 | */ | ||
220 | if ((i >= 14) || (!server->noblocksnd && (i > 2))) { | ||
276 | cERROR(1, | 221 | cERROR(1, |
277 | ("sends on sock %p stuck for 15 seconds", | 222 | ("sends on sock %p stuck for 15 seconds", |
278 | ssocket)); | 223 | ssocket)); |
@@ -339,6 +284,18 @@ smb_send2(struct TCP_Server_Info *server, struct kvec *iov, int n_vec, | |||
339 | return rc; | 284 | return rc; |
340 | } | 285 | } |
341 | 286 | ||
287 | int | ||
288 | smb_send(struct TCP_Server_Info *server, struct smb_hdr *smb_buffer, | ||
289 | unsigned int smb_buf_length) | ||
290 | { | ||
291 | struct kvec iov; | ||
292 | |||
293 | iov.iov_base = smb_buffer; | ||
294 | iov.iov_len = smb_buf_length + 4; | ||
295 | |||
296 | return smb_sendv(server, &iov, 1); | ||
297 | } | ||
298 | |||
342 | static int wait_for_free_request(struct cifsSesInfo *ses, const int long_op) | 299 | static int wait_for_free_request(struct cifsSesInfo *ses, const int long_op) |
343 | { | 300 | { |
344 | if (long_op == CIFS_ASYNC_OP) { | 301 | if (long_op == CIFS_ASYNC_OP) { |
@@ -540,9 +497,7 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses, | |||
540 | #ifdef CONFIG_CIFS_STATS2 | 497 | #ifdef CONFIG_CIFS_STATS2 |
541 | atomic_inc(&ses->server->inSend); | 498 | atomic_inc(&ses->server->inSend); |
542 | #endif | 499 | #endif |
543 | rc = smb_send2(ses->server, iov, n_vec, | 500 | rc = smb_sendv(ses->server, iov, n_vec); |
544 | (struct sockaddr *) &(ses->server->addr.sockAddr), | ||
545 | ses->server->noblocksnd); | ||
546 | #ifdef CONFIG_CIFS_STATS2 | 501 | #ifdef CONFIG_CIFS_STATS2 |
547 | atomic_dec(&ses->server->inSend); | 502 | atomic_dec(&ses->server->inSend); |
548 | midQ->when_sent = jiffies; | 503 | midQ->when_sent = jiffies; |
@@ -736,9 +691,7 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses, | |||
736 | #ifdef CONFIG_CIFS_STATS2 | 691 | #ifdef CONFIG_CIFS_STATS2 |
737 | atomic_inc(&ses->server->inSend); | 692 | atomic_inc(&ses->server->inSend); |
738 | #endif | 693 | #endif |
739 | rc = smb_send(ses->server->ssocket, in_buf, in_buf->smb_buf_length, | 694 | rc = smb_send(ses->server, in_buf, in_buf->smb_buf_length); |
740 | (struct sockaddr *) &(ses->server->addr.sockAddr), | ||
741 | ses->server->noblocksnd); | ||
742 | #ifdef CONFIG_CIFS_STATS2 | 695 | #ifdef CONFIG_CIFS_STATS2 |
743 | atomic_dec(&ses->server->inSend); | 696 | atomic_dec(&ses->server->inSend); |
744 | midQ->when_sent = jiffies; | 697 | midQ->when_sent = jiffies; |
@@ -879,9 +832,7 @@ send_nt_cancel(struct cifsTconInfo *tcon, struct smb_hdr *in_buf, | |||
879 | mutex_unlock(&ses->server->srv_mutex); | 832 | mutex_unlock(&ses->server->srv_mutex); |
880 | return rc; | 833 | return rc; |
881 | } | 834 | } |
882 | rc = smb_send(ses->server->ssocket, in_buf, in_buf->smb_buf_length, | 835 | rc = smb_send(ses->server, in_buf, in_buf->smb_buf_length); |
883 | (struct sockaddr *) &(ses->server->addr.sockAddr), | ||
884 | ses->server->noblocksnd); | ||
885 | mutex_unlock(&ses->server->srv_mutex); | 836 | mutex_unlock(&ses->server->srv_mutex); |
886 | return rc; | 837 | return rc; |
887 | } | 838 | } |
@@ -973,9 +924,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon, | |||
973 | #ifdef CONFIG_CIFS_STATS2 | 924 | #ifdef CONFIG_CIFS_STATS2 |
974 | atomic_inc(&ses->server->inSend); | 925 | atomic_inc(&ses->server->inSend); |
975 | #endif | 926 | #endif |
976 | rc = smb_send(ses->server->ssocket, in_buf, in_buf->smb_buf_length, | 927 | rc = smb_send(ses->server, in_buf, in_buf->smb_buf_length); |
977 | (struct sockaddr *) &(ses->server->addr.sockAddr), | ||
978 | ses->server->noblocksnd); | ||
979 | #ifdef CONFIG_CIFS_STATS2 | 928 | #ifdef CONFIG_CIFS_STATS2 |
980 | atomic_dec(&ses->server->inSend); | 929 | atomic_dec(&ses->server->inSend); |
981 | midQ->when_sent = jiffies; | 930 | midQ->when_sent = jiffies; |