[SCM] Samba Shared Repository - branch v4-0-test updated
Karolin Seeger
kseeger at samba.org
Tue Dec 10 07:07:05 MST 2013
The branch, v4-0-test has been updated
via 717edc2 smbd: Fix a panic when a smb2 brlock times out
via e533a99 selftest: Remove samba3.smb2.lock.*.rw-exclusive from flapping file
via 5b0b88d selftest: Run smb2.lock tests also against AIO share
via 009d5aa selftest: Introduce share for testing AIO
via 5c99489 s3: Return correct error code from SMB2 AIO read failure
via c36bda8 s3-aio: Use correct locking context for SMB2
via 9c622f0 s3:smb2_server: avoid calling set_current_user_info() for each request
via 83f3344 s3:smb2_server: generate a header blob for the sendfile path
via 3efa732 s3:smb2_server: allocate smbd_smb2_request on talloc_tos()
via 6d4df0f s3:smb2_server: use tevent_req_notify_callback() in smbd_smb2_request_pending_queue()
via e2169a7 s3:smb2_server: for performance reasons we use tevent_fd and readv/writev directly
via 8b72512 s3:smb2_server: fix drain_socket error handling
via fe04555 smbd: Always use UCF_PREP_CREATEFILE for filename_convert calls to resolve a path for open.
via b1fb353 smbd: change flag name from UCF_CREATING_FILE to UCF_PREP_CREATEFILE
via 790a3b2 smbd: Fix regression for the dropbox case.
from db8b33d VERSION: Bump version up to 4.0.14
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v4-0-test
- Log -----------------------------------------------------------------
commit 717edc25b21ed03acf07b704aae9d6c2a81bc73e
Author: Volker Lendecke <vl at samba.org>
Date: Thu Dec 5 15:50:58 2013 +0100
smbd: Fix a panic when a smb2 brlock times out
Found by Peter Somogyi.
Signed-off-by: Volker Lendecke <vl at samba.org>
Reviewed-by: Jeremy Allison <jra at samba.org>
Autobuild-User(master): Jeremy Allison <jra at samba.org>
Autobuild-Date(master): Thu Dec 5 21:21:35 CET 2013 on sn-devel-104
Fix bug #10311 - SMB2 server can panic when a smb2 brlock times out.
Autobuild-User(v4-0-test): Karolin Seeger <kseeger at samba.org>
Autobuild-Date(v4-0-test): Tue Dec 10 15:06:45 CET 2013 on sn-devel-104
commit e533a998539d449f085b38e8c621b2db377d3e06
Author: Christof Schmitt <cs at samba.org>
Date: Thu Dec 5 15:53:47 2013 -0700
selftest: Remove samba3.smb2.lock.*.rw-exclusive from flapping file
This test demonstrates a problem with byte range locks and AIO.
Signed-off-by: Christof Schmitt <cs at samba.org>
Reviewed-by: Jeremy Allison <jra at samba.org>
Autobuild-User(master): Jeremy Allison <jra at samba.org>
Autobuild-Date(master): Fri Dec 6 05:19:37 CET 2013 on sn-devel-104
(cherry picked from commit 8c3bf7b84950fbb0305bcccd49ecfc202e08901a)
The last 5 patches address bug #10310 - Fix AIO with SMB2 and locks.
commit 5b0b88ddaff7d6d3e276fce4285d146aac17ca42
Author: Christof Schmitt <cs at samba.org>
Date: Thu Dec 5 15:22:13 2013 -0700
selftest: Run smb2.lock tests also against AIO share
Signed-off-by: Christof Schmitt <cs at samba.org>
Reviewed-by: Jeremy Allison <jra at samba.org>
(cherry picked from commit d551d5256f9b1ca57b8018d816ea665c9b847ced)
commit 009d5aa44e2c95dbe27addf32b683cd8e8952fcf
Author: Christof Schmitt <cs at samba.org>
Date: Thu Dec 5 15:20:06 2013 -0700
selftest: Introduce share for testing AIO
Signed-off-by: Christof Schmitt <cs at samba.org>
Reviewed-by: Jeremy Allison <jra at samba.org>
(cherry picked from commit 63727c15450e1db2be49ade758c369aa4599657a)
commit 5c994896d2fa4010297b6cde53a158c797a44bd1
Author: Christof Schmitt <cs at samba.org>
Date: Thu Dec 5 16:20:26 2013 -0700
s3: Return correct error code from SMB2 AIO read failure
This is similar to commit 27e20d5d60ea8aa526bcb7c2dfc18dd2de0bb97b which
fixed the same case for SMB2 writes: When sending the AIO read fails,
return the real error instead of mapping it to NT_STATUS_FILE_CLOSED.
Signed-off-by: Christof Schmitt <cs at samba.org>
Reviewed-by: Jeremy Allison <jra at samba.org>
(cherry picked from commit eadb2a54d1733a482999eb770182156dad1e184d)
commit c36bda8872b9a62b64de6f2f5c7486895dc5634c
Author: Christof Schmitt <cs at samba.org>
Date: Thu Dec 5 15:57:54 2013 -0700
s3-aio: Use correct locking context for SMB2
The synchronous SMB2 reads and writes use open_persistent_id. The AIO
codepathes have to use the same, otherwise a write will conflict with a
lock on the same open file.
Signed-off-by: Christof Schmitt <cs at samba.org>
Reviewed-by: Jeremy Allison <jra at samba.org>
(cherry picked from commit dfef0701c398982226dde8a8e15ff97bba0fef53)
commit 9c622f082bb983179666263f77b3ecfb08d24915
Author: Stefan Metzmacher <metze at samba.org>
Date: Tue Nov 19 05:21:05 2013 +0100
s3:smb2_server: avoid calling set_current_user_info() for each request
Signed-off-by: Stefan Metzmacher <metze at samba.org>
Reviewed-by: David Disseldorp <ddiss at samba.org>
Autobuild-User(master): Stefan Metzmacher <metze at samba.org>
Autobuild-Date(master): Wed Nov 27 16:31:44 CET 2013 on sn-devel-104
(cherry picked from commit 3cc0651d9feda00b6a04f84b76744b2acc3a0446)
The last 6 patches address bug #10298 - smb2_server processing overhead.
commit 83f33440bb635bb0f3f82997108cd8183664af19
Author: Stefan Metzmacher <metze at samba.org>
Date: Mon Oct 14 14:18:26 2013 +0200
s3:smb2_server: generate a header blob for the sendfile path
We need to pass the NBT header, SMB2 header and SMB2 Read header
as header blob to SMB_VFS_SENDFILE(). This allows the usage
of MSG_SEND or other tricks to avoid multiple TCP packets
on the wire.
Signed-off-by: Stefan Metzmacher <metze at samba.org>
Reviewed-by: David Disseldorp <ddiss at samba.org>
(cherry picked from commit 36efaac2597d2d36826c02f23be15e7323b09784)
commit 3efa732ab65ad1ffa19e7235c754e693a562c3a9
Author: Stefan Metzmacher <metze at samba.org>
Date: Wed Oct 16 09:15:12 2013 +0200
s3:smb2_server: allocate smbd_smb2_request on talloc_tos()
This matches the behavior for smb1 requests
and avoids an additional malloc() per request.
Signed-off-by: Stefan Metzmacher <metze at samba.org>
Reviewed-by: David Disseldorp <ddiss at samba.org>
(cherry picked from commit 9d33a3f3e814e2924a423496ccc133c6c73fcd12)
commit 6d4df0f796fdb36f31a7176b8ed6a198e82d9c0c
Author: Stefan Metzmacher <metze at samba.org>
Date: Sat Oct 12 02:40:12 2013 +0200
s3:smb2_server: use tevent_req_notify_callback() in smbd_smb2_request_pending_queue()
If the request is already done we can avoid one iteration
of tevent_loop_once(), which means we avoids one
talloc_stackframe_pool/talloc_free pair.
Signed-off-by: Stefan Metzmacher <metze at samba.org>
Reviewed-by: David Disseldorp <ddiss at samba.org>
(cherry picked from commit acfd4b068a5b99ac1d3fe716afff34cb7d2a0147)
commit e2169a754869b27a5939595588c9991627d2262e
Author: Stefan Metzmacher <metze at samba.org>
Date: Mon Oct 14 10:33:57 2013 +0200
s3:smb2_server: for performance reasons we use tevent_fd and readv/writev directly
Going via tevent_req_create/talloc_free at multiple layer costs
too much cpu cycles per request.
I tested downloading a 16GB (sparse) file with smbclient -b1 -mNT1,
and -mSMB2_02. Using smb2 max read = 64512, which means smb1 and smb2
will use the same read size.
I build with -O3 -g and compared the results with valgrind --tool=callgrind.
With -mNT1 the server uses about 2.000.000.000 cpu cycles.
This patch reduces the userspace cpu cycles for -mSMB2_02
from about ~ 8.000.000.000 down to ~ 4.000.000.000.
Signed-off-by: Stefan Metzmacher <metze at samba.org>
Reviewed-by: David Disseldorp <ddiss at samba.org>
(cherry picked from commit 4244a2686cddcdc754c284df884ae497afa4053a)
commit 8b7251201edd04081aa737373f74d9b14e7fe649
Author: Stefan Metzmacher <metze at samba.org>
Date: Mon Oct 14 16:42:55 2013 +0200
s3:smb2_server: fix drain_socket error handling
smbd_smb2_request_error_ex() should return NTSTATUS and the caller
will terminate the connection.
Signed-off-by: Stefan Metzmacher <metze at samba.org>
Reviewed-by: David Disseldorp <ddiss at samba.org>
(cherry picked from commit 9393e28df59954414313bfae70ffb796d3e332fe)
commit fe04555152e382554356b3f4f754e37bdf83a83c
Author: Jeremy Allison <jra at samba.org>
Date: Tue Dec 3 10:21:16 2013 -0800
smbd: Always use UCF_PREP_CREATEFILE for filename_convert calls to resolve a path for open.
BUG: https://bugzilla.samba.org/show_bug.cgi?id=10297
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Volker Lendecke <vl at samba.org>
Autobuild-User(master): Jeremy Allison <jra at samba.org>
Autobuild-Date(master): Mon Dec 9 21:02:21 CET 2013 on sn-devel-104
(cherry picked from commit f98d10af2a05f0261611f4cabdfe274cd9fe91c0)
commit b1fb353db8a95a7140c79984bf9b3f1178945b5f
Author: Jeremy Allison <jra at samba.org>
Date: Tue Dec 3 10:19:09 2013 -0800
smbd: change flag name from UCF_CREATING_FILE to UCF_PREP_CREATEFILE
In preparation to using it for all open calls.
BUG: https://bugzilla.samba.org/show_bug.cgi?id=10297
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Volker Lendecke <vl at samba.org>
(cherry picked from commit 874318a97868e08837a1febb1be8e8a167b5ae0f)
commit 790a3b29190931603f68d65ea9b7046f6b3e802a
Author: Volker Lendecke <vl at samba.org>
Date: Tue Dec 3 13:20:17 2013 +0100
smbd: Fix regression for the dropbox case.
We need to allow to save a file to a directory with perm -wx.
BUG: https://bugzilla.samba.org/show_bug.cgi?id=10297
Signed-off-by: Volker Lendecke <vl at samba.org>
Reviewed-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Andreas Schneider <asn at samba.org>
(cherry picked from commit 5b49fe24c906cbae12beff7a1b45de6809258cab)
-----------------------------------------------------------------------
Summary of changes:
selftest/flapping | 1 -
selftest/target/Samba3.pm | 4 +
source3/selftest/tests.py | 4 +
source3/smbd/aio.c | 4 +-
source3/smbd/filename.c | 10 +-
source3/smbd/globals.h | 31 ++-
source3/smbd/nttrans.c | 6 +-
source3/smbd/process.c | 5 +-
source3/smbd/reply.c | 12 +-
source3/smbd/smb2_create.c | 3 +-
source3/smbd/smb2_lock.c | 2 +-
source3/smbd/smb2_read.c | 12 +-
source3/smbd/smb2_server.c | 886 ++++++++++++++++++++++----------------------
source3/smbd/smbd.h | 2 +-
14 files changed, 504 insertions(+), 478 deletions(-)
Changeset truncated at 500 lines:
diff --git a/selftest/flapping b/selftest/flapping
index afeae65..fd2e0c3 100644
--- a/selftest/flapping
+++ b/selftest/flapping
@@ -16,7 +16,6 @@
^samba3.rap.printing # fails sometimes on sn-devel
^samba3.rpc.spoolss.printer.*addprinter.print_test # fails on some hosts due to timing issues ?
^samba3.rpc.lsa.privileges.lsa.Privileges\(s3dc\) # fails sometimes on sn-devel
-^samba3.smb2.lock.*.rw-exclusive # another intermittent failure
^samba4.blackbox.gentest # is flakey due to timing
^samba3.smb2.acls.INHERITANCE\(plugin_s4_dc\) # Seems to flap - succeeds on sn-devel, fails on Fedora 16
^samba3.smb2.acls.DYNAMIC\(plugin_s4_dc\) # Seems to flap - succeeds on sn-devel, fails on Fedora 16
diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
index 2061d97..792bbca 100755
--- a/selftest/target/Samba3.pm
+++ b/selftest/target/Samba3.pm
@@ -1004,6 +1004,10 @@ sub provision($$$$$$)
directory mask = 0777
force directory mode = 0
vfs objects = $vfs_modulesdir_abs/xattr_tdb.so
+[aio]
+ copy = tmp
+ aio read size = 1
+ aio write size = 1
[print\$]
copy = tmp
diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py
index c293e6d..a968665 100755
--- a/source3/selftest/tests.py
+++ b/source3/selftest/tests.py
@@ -336,6 +336,10 @@ for t in tests:
plansmbtorture4testsuite(t, "s3dc", '//$SERVER_IP/valid-users-tmp -U$USERNAME%$PASSWORD')
plansmbtorture4testsuite(t, "s3dc", '//$SERVER_IP/write-list-tmp -U$USERNAME%$PASSWORD')
plansmbtorture4testsuite(t, "plugin_s4_dc", '//$SERVER/tmp -U$USERNAME%$PASSWORD')
+ elif t == "smb2.lock":
+ plansmbtorture4testsuite(t, "s3dc", '//$SERVER_IP/aio -U$USERNAME%$PASSWORD', 'aio')
+ plansmbtorture4testsuite(t, "s3dc", '//$SERVER_IP/tmp -U$USERNAME%$PASSWORD')
+ plansmbtorture4testsuite(t, "plugin_s4_dc", '//$SERVER/tmp -U$USERNAME%$PASSWORD')
else:
plansmbtorture4testsuite(t, "s3dc", '//$SERVER_IP/tmp -U$USERNAME%$PASSWORD')
plansmbtorture4testsuite(t, "plugin_s4_dc", '//$SERVER/tmp -U$USERNAME%$PASSWORD')
diff --git a/source3/smbd/aio.c b/source3/smbd/aio.c
index e8be408..3d43b2c 100644
--- a/source3/smbd/aio.c
+++ b/source3/smbd/aio.c
@@ -720,7 +720,7 @@ NTSTATUS schedule_smb2_aio_read(connection_struct *conn,
return NT_STATUS_NO_MEMORY;
}
- init_strict_lock_struct(fsp, (uint64_t)smbreq->smbpid,
+ init_strict_lock_struct(fsp, fsp->op->global->open_persistent_id,
(uint64_t)startpos, (uint64_t)smb_maxcnt, READ_LOCK,
&aio_ex->lock);
@@ -872,7 +872,7 @@ NTSTATUS schedule_aio_smb2_write(connection_struct *conn,
aio_ex->write_through = write_through;
- init_strict_lock_struct(fsp, (uint64_t)smbreq->smbpid,
+ init_strict_lock_struct(fsp, fsp->op->global->open_persistent_id,
in_offset, (uint64_t)in_data.length, WRITE_LOCK,
&aio_ex->lock);
diff --git a/source3/smbd/filename.c b/source3/smbd/filename.c
index fc96550..ba41986 100644
--- a/source3/smbd/filename.c
+++ b/source3/smbd/filename.c
@@ -722,7 +722,10 @@ NTSTATUS unix_convert(TALLOC_CTX *ctx,
*/
if (errno == EACCES) {
- if (ucf_flags & UCF_CREATING_FILE) {
+ if ((ucf_flags & UCF_PREP_CREATEFILE) == 0) {
+ status = NT_STATUS_ACCESS_DENIED;
+ goto fail;
+ } else {
/*
* This is the dropbox
* behaviour. A dropbox is a
@@ -734,11 +737,8 @@ NTSTATUS unix_convert(TALLOC_CTX *ctx,
* nevertheless want to allow
* users creating a file.
*/
- status = NT_STATUS_OBJECT_PATH_NOT_FOUND;
- } else {
- status = NT_STATUS_ACCESS_DENIED;
+ errno = 0;
}
- goto fail;
}
if ((errno != 0) && (errno != ENOENT)) {
diff --git a/source3/smbd/globals.h b/source3/smbd/globals.h
index c7badbc..b5b7d8d 100644
--- a/source3/smbd/globals.h
+++ b/source3/smbd/globals.h
@@ -366,6 +366,7 @@ struct smbXsrv_connection {
* this session_table is used for SMB1 and SMB2,
*/
struct smbXsrv_session_table *session_table;
+ uint64_t last_session_id;
/*
* this tcon_table is only used for SMB1.
*/
@@ -466,12 +467,23 @@ NTSTATUS smbXsrv_open_global_traverse(
NTSTATUS smbXsrv_open_cleanup(uint64_t persistent_id);
+struct smbd_smb2_send_queue {
+ struct smbd_smb2_send_queue *prev, *next;
+
+ DATA_BLOB *sendfile_header;
+ struct iovec *vector;
+ int count;
+
+ TALLOC_CTX *mem_ctx;
+};
struct smbd_smb2_request {
struct smbd_smb2_request *prev, *next;
struct smbd_server_connection *sconn;
+ struct smbd_smb2_send_queue queue_entry;
+
/* the session the request operates on, maybe NULL */
struct smbXsrv_session *session;
uint64_t last_session_id;
@@ -719,7 +731,6 @@ struct smbd_server_connection {
* Set by us for CORE protocol.
*/
int max_send;
- uint64_t last_session_tag;
} sessions;
struct smb_signing_state *signing_state;
@@ -739,9 +750,21 @@ struct smbd_server_connection {
} locks;
} smb1;
struct {
- struct tevent_queue *recv_queue;
- struct tevent_queue *send_queue;
- struct tstream_context *stream;
+ struct smbd_smb2_request_read_state {
+ struct smbd_smb2_request *req;
+ struct {
+ uint8_t nbt[NBT_HDR_SIZE];
+ bool done;
+ } hdr;
+ struct iovec vector;
+ bool doing_receivefile;
+ size_t min_recv_size;
+ size_t pktlen;
+ uint8_t *pktbuf;
+ } request_read_state;
+ struct smbd_smb2_send_queue *send_queue;
+ size_t send_queue_len;
+ struct tevent_fd *fde;
bool negprot_2ff;
struct {
/* The event that makes us process our blocking lock queue */
diff --git a/source3/smbd/nttrans.c b/source3/smbd/nttrans.c
index b7dfa8c..0d3cd07 100644
--- a/source3/smbd/nttrans.c
+++ b/source3/smbd/nttrans.c
@@ -538,8 +538,7 @@ void reply_ntcreate_and_X(struct smb_request *req)
conn,
req->flags2 & FLAGS2_DFS_PATHNAMES,
fname,
- (create_disposition == FILE_CREATE)
- ? UCF_CREATING_FILE : 0,
+ UCF_PREP_CREATEFILE,
NULL,
&smb_fname);
@@ -1118,8 +1117,7 @@ static void call_nt_transact_create(connection_struct *conn,
conn,
req->flags2 & FLAGS2_DFS_PATHNAMES,
fname,
- (create_disposition == FILE_CREATE)
- ? UCF_CREATING_FILE : 0,
+ UCF_PREP_CREATEFILE,
NULL,
&smb_fname);
diff --git a/source3/smbd/process.c b/source3/smbd/process.c
index 8add79d..3bf10de 100644
--- a/source3/smbd/process.c
+++ b/source3/smbd/process.c
@@ -1434,10 +1434,10 @@ static connection_struct *switch_message(uint8 type, struct smb_request *req)
}
}
- if (session_tag != sconn->smb1.sessions.last_session_tag) {
+ if (session_tag != sconn->conn->last_session_id) {
struct user_struct *vuser = NULL;
- sconn->smb1.sessions.last_session_tag = session_tag;
+ sconn->conn->last_session_id = session_tag;
if (session) {
vuser = session->compat;
}
@@ -3593,7 +3593,6 @@ void smbd_process(struct tevent_context *ev_ctx,
sconn->smb1.sessions.done_sesssetup = false;
sconn->smb1.sessions.max_send = BUFFER_SIZE;
- sconn->smb1.sessions.last_session_tag = UID_FIELD_INVALID;
if (!init_dptrs(sconn)) {
exit_server("init_dptrs() failed");
diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index 2d729ec..f293b69 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -1917,8 +1917,7 @@ void reply_open(struct smb_request *req)
conn,
req->flags2 & FLAGS2_DFS_PATHNAMES,
fname,
- (create_disposition == FILE_CREATE)
- ? UCF_CREATING_FILE : 0,
+ UCF_PREP_CREATEFILE,
NULL,
&smb_fname);
if (!NT_STATUS_IS_OK(status)) {
@@ -2095,8 +2094,7 @@ void reply_open_and_X(struct smb_request *req)
conn,
req->flags2 & FLAGS2_DFS_PATHNAMES,
fname,
- (create_disposition == FILE_CREATE)
- ? UCF_CREATING_FILE : 0,
+ UCF_PREP_CREATEFILE,
NULL,
&smb_fname);
if (!NT_STATUS_IS_OK(status)) {
@@ -2329,7 +2327,7 @@ void reply_mknew(struct smb_request *req)
conn,
req->flags2 & FLAGS2_DFS_PATHNAMES,
fname,
- UCF_CREATING_FILE,
+ UCF_PREP_CREATEFILE,
NULL,
&smb_fname);
if (!NT_STATUS_IS_OK(status)) {
@@ -2470,7 +2468,7 @@ void reply_ctemp(struct smb_request *req)
status = filename_convert(ctx, conn,
req->flags2 & FLAGS2_DFS_PATHNAMES,
fname,
- UCF_CREATING_FILE,
+ UCF_PREP_CREATEFILE,
NULL,
&smb_fname);
if (!NT_STATUS_IS_OK(status)) {
@@ -5829,7 +5827,7 @@ void reply_mkdir(struct smb_request *req)
status = filename_convert(ctx, conn,
req->flags2 & FLAGS2_DFS_PATHNAMES,
directory,
- UCF_CREATING_FILE,
+ UCF_PREP_CREATEFILE,
NULL,
&smb_dname);
if (!NT_STATUS_IS_OK(status)) {
diff --git a/source3/smbd/smb2_create.c b/source3/smbd/smb2_create.c
index c4d4991..6730ad6 100644
--- a/source3/smbd/smb2_create.c
+++ b/source3/smbd/smb2_create.c
@@ -871,8 +871,7 @@ static struct tevent_req *smbd_smb2_create_send(TALLOC_CTX *mem_ctx,
smb1req->conn,
smb1req->flags2 & FLAGS2_DFS_PATHNAMES,
fname,
- (in_create_disposition == FILE_CREATE) ?
- UCF_CREATING_FILE : 0,
+ UCF_PREP_CREATEFILE,
NULL, /* ppath_contains_wcards */
&smb_fname);
if (!NT_STATUS_IS_OK(status)) {
diff --git a/source3/smbd/smb2_lock.c b/source3/smbd/smb2_lock.c
index e2ea251..671cd6f 100644
--- a/source3/smbd/smb2_lock.c
+++ b/source3/smbd/smb2_lock.c
@@ -511,7 +511,7 @@ static bool recalc_smb2_brl_timeout(struct smbd_server_connection *sconn)
NULL,
next_timeout,
brl_timeout_fn,
- NULL);
+ sconn);
if (!sconn->smb2.locks.brl_timeout) {
return false;
}
diff --git a/source3/smbd/smb2_read.c b/source3/smbd/smb2_read.c
index 41adb03..6478326 100644
--- a/source3/smbd/smb2_read.c
+++ b/source3/smbd/smb2_read.c
@@ -166,6 +166,7 @@ struct smbd_smb2_read_state {
uint32_t in_length;
uint64_t in_offset;
uint32_t in_minimum;
+ DATA_BLOB out_headers;
DATA_BLOB out_data;
uint32_t out_remaining;
};
@@ -180,10 +181,10 @@ static int smb2_sendfile_send_data(struct smbd_smb2_read_state *state)
ssize_t nread;
nread = SMB_VFS_SENDFILE(fsp->conn->sconn->sock,
- fsp,
- NULL,
- in_offset,
- in_length);
+ fsp,
+ state->smb2req->queue_entry.sendfile_header,
+ in_offset,
+ in_length);
DEBUG(10,("smb2_sendfile_send_data: SMB_VFS_SENDFILE returned %d on file %s\n",
(int)nread,
fsp_str_dbg(fsp) ));
@@ -301,6 +302,7 @@ static NTSTATUS schedule_smb2_sendfile_read(struct smbd_smb2_request *smb2req,
}
*state_copy = *state;
talloc_set_destructor(state_copy, smb2_sendfile_send_data);
+ state->smb2req->queue_entry.sendfile_header = &state_copy->out_headers;
return NT_STATUS_OK;
}
@@ -462,7 +464,7 @@ static struct tevent_req *smbd_smb2_read_send(TALLOC_CTX *mem_ctx,
if (!NT_STATUS_EQUAL(status, NT_STATUS_RETRY)) {
/* Real error in setting up aio. Fail. */
- tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
+ tevent_req_nterror(req, status);
return tevent_req_post(req, ev);
}
diff --git a/source3/smbd/smb2_server.c b/source3/smbd/smb2_server.c
index 525b81b..b4c291e 100644
--- a/source3/smbd/smb2_server.c
+++ b/source3/smbd/smb2_server.c
@@ -30,6 +30,13 @@
#include "../librpc/gen_ndr/krb5pac.h"
#include "auth.h"
+static void smbd_smb2_connection_handler(struct tevent_context *ev,
+ struct tevent_fd *fde,
+ uint16_t flags,
+ void *private_data);
+static NTSTATUS smbd_smb2_io_handler(struct smbd_server_connection *sconn,
+ uint16_t fde_flags);
+
#define OUTVEC_ALLOC_SIZE (SMB2_HDR_BODY + 9)
static const struct smbd_smb2_dispatch_table {
@@ -196,20 +203,9 @@ bool smbd_is_smb2_header(const uint8_t *inbuf, size_t size)
static NTSTATUS smbd_initialize_smb2(struct smbd_server_connection *sconn)
{
- NTSTATUS status;
- int ret;
-
TALLOC_FREE(sconn->smb1.fde);
- sconn->smb2.recv_queue = tevent_queue_create(sconn, "smb2 recv queue");
- if (sconn->smb2.recv_queue == NULL) {
- return NT_STATUS_NO_MEMORY;
- }
-
- sconn->smb2.send_queue = tevent_queue_create(sconn, "smb2 send queue");
- if (sconn->smb2.send_queue == NULL) {
- return NT_STATUS_NO_MEMORY;
- }
+ sconn->smb2.send_queue = NULL;
sconn->smb2.seqnum_low = 0;
sconn->smb2.seqnum_range = 1;
@@ -221,11 +217,14 @@ static NTSTATUS smbd_initialize_smb2(struct smbd_server_connection *sconn)
return NT_STATUS_NO_MEMORY;
}
- ret = tstream_bsd_existing_socket(sconn, sconn->sock,
- &sconn->smb2.stream);
- if (ret == -1) {
- status = map_nt_error_from_unix(errno);
- return status;
+ sconn->smb2.fde = tevent_add_fd(sconn->ev_ctx,
+ sconn,
+ sconn->sock,
+ TEVENT_FD_READ,
+ smbd_smb2_connection_handler,
+ sconn);
+ if (sconn->smb2.fde == NULL) {
+ return NT_STATUS_NO_MEMORY;
}
/* Ensure child is set to non-blocking mode */
@@ -270,7 +269,7 @@ static struct smbd_smb2_request *smbd_smb2_request_allocate(TALLOC_CTX *mem_ctx)
/* Enable this to find subtle valgrind errors. */
mem_pool = talloc_init("smbd_smb2_request_allocate");
#else
- mem_pool = talloc_pool(mem_ctx, 8192);
+ mem_pool = talloc_tos();
#endif
if (mem_pool == NULL) {
return NULL;
@@ -282,7 +281,9 @@ static struct smbd_smb2_request *smbd_smb2_request_allocate(TALLOC_CTX *mem_ctx)
return NULL;
}
talloc_reparent(mem_pool, mem_ctx, req);
+#if 0
TALLOC_FREE(mem_pool);
+#endif
req->last_session_id = UINT64_MAX;
req->last_tid = UINT32_MAX;
@@ -1151,10 +1152,9 @@ static struct smbd_smb2_request *dup_smb2_req(const struct smbd_smb2_request *re
return newreq;
}
-static void smbd_smb2_request_writev_done(struct tevent_req *subreq);
-
static NTSTATUS smb2_send_async_interim_response(const struct smbd_smb2_request *req)
{
+ struct smbd_server_connection *sconn = req->sconn;
struct smbXsrv_connection *conn = req->sconn->conn;
int first_idx = 1;
struct iovec *firsttf = NULL;
@@ -1218,50 +1218,27 @@ static NTSTATUS smb2_send_async_interim_response(const struct smbd_smb2_request
}
}
- nreq->subreq = tstream_writev_queue_send(nreq,
- nreq->sconn->ev_ctx,
- nreq->sconn->smb2.stream,
- nreq->sconn->smb2.send_queue,
- nreq->out.vector,
- nreq->out.vector_count);
+ nreq->queue_entry.mem_ctx = nreq;
+ nreq->queue_entry.vector = nreq->out.vector;
+ nreq->queue_entry.count = nreq->out.vector_count;
+ DLIST_ADD_END(nreq->sconn->smb2.send_queue, &nreq->queue_entry, NULL);
+ nreq->sconn->smb2.send_queue_len++;
- if (nreq->subreq == NULL) {
- return NT_STATUS_NO_MEMORY;
+ status = smbd_smb2_io_handler(sconn, TEVENT_FD_WRITE);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
}
- tevent_req_set_callback(nreq->subreq,
- smbd_smb2_request_writev_done,
- nreq);
-
return NT_STATUS_OK;
}
struct smbd_smb2_request_pending_state {
struct smbd_server_connection *sconn;
+ struct smbd_smb2_send_queue queue_entry;
uint8_t buf[NBT_HDR_SIZE + SMB2_TF_HDR_SIZE + SMB2_HDR_BODY + 0x08 + 1];
struct iovec vector[1 + SMBD_SMB2_NUM_IOV_PER_REQ];
};
-static void smbd_smb2_request_pending_writev_done(struct tevent_req *subreq)
-{
- struct smbd_smb2_request_pending_state *state =
- tevent_req_callback_data(subreq,
- struct smbd_smb2_request_pending_state);
- struct smbd_server_connection *sconn = state->sconn;
- int ret;
- int sys_errno;
-
- ret = tstream_writev_queue_recv(subreq, &sys_errno);
- TALLOC_FREE(subreq);
- if (ret == -1) {
- NTSTATUS status = map_nt_error_from_unix(sys_errno);
- smbd_server_connection_terminate(sconn, nt_errstr(status));
- return;
- }
-
- TALLOC_FREE(state);
-}
-
static void smbd_smb2_request_pending_timer(struct tevent_context *ev,
struct tevent_timer *te,
struct timeval current_time,
@@ -1277,6 +1254,13 @@ NTSTATUS smbd_smb2_request_pending_queue(struct smbd_smb2_request *req,
uint32_t flags;
if (!tevent_req_is_in_progress(subreq)) {
+ /*
+ * This is a performance optimization,
+ * it avoids one tevent_loop iteration,
+ * which means we avoid one
+ * talloc_stackframe_pool/talloc_free pair.
+ */
+ tevent_req_notify_callback(subreq);
return NT_STATUS_OK;
}
@@ -1393,6 +1377,7 @@ static void smbd_smb2_request_pending_timer(struct tevent_context *ev,
struct smbd_smb2_request *req =
--
Samba Shared Repository
More information about the samba-cvs
mailing list