s3:smb2_server: optimize smbd_smb2_request_setup_out()
authorStefan Metzmacher <metze@samba.org>
Wed, 20 Nov 2013 08:56:19 +0000 (09:56 +0100)
committerJeremy Allison <jra@samba.org>
Wed, 5 Mar 2014 21:59:20 +0000 (13:59 -0800)
We can use a preallocated buffer for the possible error
response of the first response in the compound chain.

This avoids a talloc_array_zero() call for the common case.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/globals.h
source3/smbd/smb2_server.c

index 2b7fc7ec51cd30541f0dfebac8235d3ee9b8dce7..781379c986ab418190e4cd76dd1777b904774f5b 100644 (file)
@@ -611,6 +611,8 @@ struct smbd_smb2_request {
                 */
                struct iovec *vector;
                int vector_count;
+#define OUTVEC_ALLOC_SIZE (SMB2_HDR_BODY + 9)
+               uint8_t _hdr[OUTVEC_ALLOC_SIZE];
        } out;
 };
 
index 192e99c81473174411d46781a8edb809e3c29ca7..c98766247da526ab6a96477c95d4c8af93d4d33e 100644 (file)
@@ -37,8 +37,6 @@ static void smbd_smb2_connection_handler(struct tevent_context *ev,
 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 {
        uint16_t opcode;
        const char *name;
@@ -948,10 +946,14 @@ static NTSTATUS smbd_smb2_request_setup_out(struct smbd_smb2_request *req)
                        next_command_ofs = SMB2_HDR_BODY + 9;
                }
 
-               outhdr = talloc_zero_array(vector, uint8_t,
-                                     OUTVEC_ALLOC_SIZE);
-               if (outhdr == NULL) {
-                       return NT_STATUS_NO_MEMORY;
+               if (idx == 1) {
+                       outhdr = req->out._hdr;
+               } else {
+                       outhdr = talloc_zero_array(vector, uint8_t,
+                                                  OUTVEC_ALLOC_SIZE);
+                       if (outhdr == NULL) {
+                               return NT_STATUS_NO_MEMORY;
+                       }
                }
 
                outbody = outhdr + SMB2_HDR_BODY;