From: Pavel Shilovsky <piastryyy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH 1/5] CIFS: Move buffer allocation to a separate function
Date: Fri, 24 Jun 2011 10:51:53 +0400 [thread overview]
Message-ID: <1308898317-7667-2-git-send-email-piastryyy@gmail.com> (raw)
In-Reply-To: <1308898317-7667-1-git-send-email-piastryyy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Signed-off-by: Pavel Shilovsky <piastryyy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
fs/cifs/connect.c | 84 +++++++++++++++++++++++++++++++---------------------
1 files changed, 50 insertions(+), 34 deletions(-)
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index 19fdbda..566080d 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -317,14 +317,50 @@ requeue_echo:
queue_delayed_work(system_nrt_wq, &server->echo, SMB_ECHO_INTERVAL);
}
+static bool
+allocate_buffers(char **pbigbuf, char **psmallbuf, unsigned int size,
+ bool isLargeBuf)
+{
+ char *bigbuf = *pbigbuf, *smallbuf = *psmallbuf;
+
+ if (bigbuf == NULL) {
+ bigbuf = (char *)cifs_buf_get();
+ if (!bigbuf) {
+ cERROR(1, "No memory for large SMB response");
+ msleep(3000);
+ /* retry will check if exiting */
+ return false;
+ }
+ } else if (isLargeBuf) {
+ /* we are reusing a dirty large buf, clear its start */
+ memset(bigbuf, 0, size);
+ }
+
+ if (smallbuf == NULL) {
+ smallbuf = (char *)cifs_small_buf_get();
+ if (!smallbuf) {
+ cERROR(1, "No memory for SMB response");
+ msleep(1000);
+ /* retry will check if exiting */
+ return false;
+ }
+ /* beginning of smb buffer is cleared in our buf_get */
+ } else /* if existing small buf clear beginning */
+ memset(smallbuf, 0, size);
+
+ *pbigbuf = bigbuf;
+ *psmallbuf = smallbuf;
+
+ return true;
+}
+
static int
cifs_demultiplex_thread(struct TCP_Server_Info *server)
{
int length;
unsigned int pdu_length, total_read;
+ char *buf = NULL, *bigbuf = NULL, *smallbuf = NULL;
struct smb_hdr *smb_buffer = NULL;
- struct smb_hdr *bigbuf = NULL;
- struct smb_hdr *smallbuf = NULL;
struct msghdr smb_msg;
struct kvec iov;
struct socket *csocket = server->ssocket;
@@ -348,34 +384,15 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
while (server->tcpStatus != CifsExiting) {
if (try_to_freeze())
continue;
- if (bigbuf == NULL) {
- bigbuf = cifs_buf_get();
- if (!bigbuf) {
- cERROR(1, "No memory for large SMB response");
- msleep(3000);
- /* retry will check if exiting */
- continue;
- }
- } else if (isLargeBuf) {
- /* we are reusing a dirty large buf, clear its start */
- memset(bigbuf, 0, sizeof(struct smb_hdr));
- }
- if (smallbuf == NULL) {
- smallbuf = cifs_small_buf_get();
- if (!smallbuf) {
- cERROR(1, "No memory for SMB response");
- msleep(1000);
- /* retry will check if exiting */
- continue;
- }
- /* beginning of smb buffer is cleared in our buf_get */
- } else /* if existing small buf clear beginning */
- memset(smallbuf, 0, sizeof(struct smb_hdr));
+ if (!allocate_buffers(&bigbuf, &smallbuf,
+ sizeof(struct smb_hdr), isLargeBuf))
+ continue;
isLargeBuf = false;
isMultiRsp = false;
- smb_buffer = smallbuf;
+ smb_buffer = (struct smb_hdr *)smallbuf;
+ buf = smallbuf;
iov.iov_base = smb_buffer;
iov.iov_len = 4;
smb_msg.msg_control = NULL;
@@ -414,8 +431,7 @@ incomplete_rcv:
allowing socket to clear and app threads to set
tcpStatus CifsNeedReconnect if server hung */
if (pdu_length < 4) {
- iov.iov_base = (4 - pdu_length) +
- (char *)smb_buffer;
+ iov.iov_base = (4 - pdu_length) + buf;
iov.iov_len = pdu_length;
smb_msg.msg_control = NULL;
smb_msg.msg_controllen = 0;
@@ -443,7 +459,7 @@ incomplete_rcv:
/* the first byte big endian of the length field,
is actually not part of the length but the type
with the most common, zero, as regular data */
- temp = *((char *) smb_buffer);
+ temp = *buf;
/* Note that FC 1001 length is big endian on the wire,
but we convert it here so it is always manipulated
@@ -477,8 +493,7 @@ incomplete_rcv:
continue;
} else if (temp != (char) 0) {
cERROR(1, "Unknown RFC 1002 frame");
- cifs_dump_mem(" Received Data: ", (char *)smb_buffer,
- length);
+ cifs_dump_mem(" Received Data: ", buf, length);
cifs_reconnect(server);
csocket = server->ssocket;
continue;
@@ -501,10 +516,11 @@ incomplete_rcv:
if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE - 4) {
isLargeBuf = true;
memcpy(bigbuf, smallbuf, 4);
- smb_buffer = bigbuf;
+ smb_buffer = (struct smb_hdr *)bigbuf;
+ buf = bigbuf;
}
length = 0;
- iov.iov_base = 4 + (char *)smb_buffer;
+ iov.iov_base = 4 + buf;
iov.iov_len = pdu_length;
for (total_read = 0; total_read < pdu_length;
total_read += length) {
@@ -645,7 +661,7 @@ multi_t2_fnd:
!isMultiRsp) {
cERROR(1, "No task to wake, unknown frame received! "
"NumMids %d", atomic_read(&midCount));
- cifs_dump_mem("Received Data is: ", (char *)smb_buffer,
+ cifs_dump_mem("Received Data is: ", buf,
sizeof(struct smb_hdr));
#ifdef CONFIG_CIFS_DEBUG2
cifs_dump_detail(smb_buffer);
--
1.7.1
next prev parent reply other threads:[~2011-06-24 6:51 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-24 6:51 [PATCH 0/5] Simplify demultiplex thread Pavel Shilovsky
[not found] ` <1308898317-7667-1-git-send-email-piastryyy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-06-24 6:51 ` Pavel Shilovsky [this message]
[not found] ` <1308898317-7667-2-git-send-email-piastryyy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-06-24 7:11 ` [PATCH 1/5] CIFS: Move buffer allocation to a separate function Christoph Hellwig
[not found] ` <20110624071159.GA11901-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2011-06-24 7:36 ` Pavel Shilovsky
2011-06-24 6:51 ` [PATCH 2/5] CIFS: Simplify socket reading in demultiplex thread Pavel Shilovsky
2011-06-24 6:51 ` [PATCH 3/5] CIFS: Move RFC1002 check to a separate function Pavel Shilovsky
2011-06-24 6:51 ` [PATCH 4/5] CIFS: Move mid search " Pavel Shilovsky
[not found] ` <1308898317-7667-5-git-send-email-piastryyy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-06-24 7:14 ` Christoph Hellwig
2011-06-24 6:51 ` [PATCH 5/5] CIFS: Cleanup demupltiplex thread exiting code Pavel Shilovsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1308898317-7667-2-git-send-email-piastryyy@gmail.com \
--to=piastryyy-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.