r16950: remove the smb mid from the ntvfs layer and keep a list of pending
authorStefan Metzmacher <metze@samba.org>
Tue, 11 Jul 2006 18:15:42 +0000 (18:15 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:10:02 +0000 (14:10 -0500)
requests on the smbsrv_connection, to be able to match then on
ntcancel

metze

12 files changed:
source/ntvfs/cifs/vfs_cifs.c
source/ntvfs/ntvfs.h
source/ntvfs/ntvfs_util.c
source/ntvfs/posix/pvfs_wait.c
source/rpc_server/srvsvc/dcesrv_srvsvc.c
source/rpc_server/srvsvc/srvsvc_ntvfs.c
source/smb_server/smb/reply.c
source/smb_server/smb/request.c
source/smb_server/smb/service.c
source/smb_server/smb2/smb2_server.h
source/smb_server/smb2/tcon.c
source/smb_server/smb_server.h

index 47b89ff662cade996dd65424241bad7e3e7a0a41..41ea2a652d2bd7b4dbec6b25f80c8612b8eb8d44 100644 (file)
@@ -803,7 +803,7 @@ static NTSTATUS cvfs_cancel(struct ntvfs_module_context *ntvfs,
 
        /* find the matching request */
        for (a=private->pending;a;a=a->next) {
-               if (a->req->smbmid == req->smbmid) {
+               if (a->req == req) {
                        break;
                }
        }
index cf541de81e748e9672c841f4342824cfdb56eede..734df84ddeabc9dd0060fd56689b796c5d194e84 100644 (file)
@@ -253,9 +253,6 @@ struct ntvfs_request {
        /* the smb pid is needed for locking contexts */
        uint16_t smbpid;
 
-       /* the smb mid is needed for matching requests */
-       uint16_t smbmid;
-
        /* some statictics for the management tools */
        struct {
                /* the system time when the request arrived */
index d99d040378c5d782c06b37fc269031db77e9940e..5c73b53c1cdfb8157fe6256ce29bf099e9b86c60 100644 (file)
@@ -28,7 +28,7 @@
 
 _PUBLIC_ struct ntvfs_request *ntvfs_request_create(struct ntvfs_context *ctx, TALLOC_CTX *mem_ctx,
                                                    struct auth_session_info *session_info,
-                                                   uint16_t smbpid, uint16_t smbmid,
+                                                   uint16_t smbpid,
                                                    struct timeval request_time,
                                                    void *private_data,
                                                    void (*send_fn)(struct ntvfs_request *),
@@ -43,7 +43,6 @@ _PUBLIC_ struct ntvfs_request *ntvfs_request_create(struct ntvfs_context *ctx, T
        req->async_states               = NULL;
        req->session_info               = session_info;
        req->smbpid                     = smbpid;
-       req->smbmid                     = smbmid;
        req->statistics.request_time    = request_time;
 
        async = talloc(req, struct ntvfs_async_state);
index 90c9b60efe415e76c3d9a76619a95f3e5c7af9e2..d912125289a47a1a8c3d84348202ae4bf8a1c71e 100644 (file)
@@ -179,8 +179,7 @@ NTSTATUS pvfs_cancel(struct ntvfs_module_context *ntvfs, struct ntvfs_request *r
        struct pvfs_wait *pwait;
 
        for (pwait=pvfs->wait_list;pwait;pwait=pwait->next) {
-               if (req->smbmid == pwait->req->smbmid &&
-                   req->smbpid == pwait->req->smbpid) {
+               if (pwait->req == req) {
                        /* trigger a cancel on the request */
                        pwait->reason = PVFS_WAIT_CANCEL;
                        ntvfs_async_setup(pwait->req, pwait);
index c1854a6b207cec53a4f2e9c8178e874452421c80..44296655ac7c84b04eb2255972b3788354a77aeb 100644 (file)
@@ -1417,7 +1417,6 @@ static WERROR srvsvc_NetGetFileSecurity(struct dcesrv_call_state *dce_call, TALL
        ntvfs_req = ntvfs_request_create(ntvfs_ctx, mem_ctx,
                                         dce_call->conn->auth_state.session_info,
                                         0,
-                                        0,
                                         dce_call->time,
                                         NULL, NULL, 0);
        W_ERROR_HAVE_NO_MEMORY(ntvfs_req);
@@ -1459,7 +1458,6 @@ static WERROR srvsvc_NetSetFileSecurity(struct dcesrv_call_state *dce_call, TALL
        ntvfs_req = ntvfs_request_create(ntvfs_ctx, mem_ctx,
                                         dce_call->conn->auth_state.session_info,
                                         0,
-                                        0,
                                         dce_call->time,
                                         NULL, NULL, 0);
        W_ERROR_HAVE_NO_MEMORY(ntvfs_req);
index 9fafb8a3cdc5c798c75bd152cc51a78526df045c..8bd88e53e980d6751489aed8afbb7f06b0310b4a 100644 (file)
@@ -113,7 +113,6 @@ NTSTATUS srvsvc_create_ntvfs_context(struct dcesrv_call_state *dce_call,
        ntvfs_req = ntvfs_request_create(c->ntvfs, mem_ctx,
                                         dce_call->conn->auth_state.session_info,
                                         0, /* TODO: fill in PID */
-                                        0, /* TODO: fill in MID */
                                         dce_call->time,
                                         NULL, NULL, 0);
        NT_STATUS_HAVE_NO_MEMORY(ntvfs_req);
index 75830ae73ac45a40c0d127a02015b072e37c7f47..c79ad15ea8c1eb5a73a2c0c66f4acd4d69e0fddd 100644 (file)
@@ -633,7 +633,6 @@ void smbsrv_reply_readbraw(struct smbsrv_request *req)
        req->ntvfs = ntvfs_request_create(req->tcon->ntvfs, req,
                                          req->session->session_info,
                                          SVAL(req->in.hdr,HDR_PID),
-                                         SVAL(req->in.hdr,HDR_MID),
                                          req->request_time,
                                          req, NULL, 0);
        if (!req->ntvfs) {
@@ -2197,10 +2196,24 @@ void smbsrv_reply_ntcreate_and_X(struct smbsrv_request *req)
 ****************************************************************************/
 void smbsrv_reply_ntcancel(struct smbsrv_request *req)
 {
-       /* NOTE: this request does not generate a reply */
-       SMBSRV_SETUP_NTVFS_REQUEST(NULL,0);
-       ntvfs_cancel(req->ntvfs);
-       talloc_free(req);
+       struct smbsrv_request *r;
+       uint16_t mid = SVAL(req->in.hdr,HDR_MID);
+       uint16_t pid = SVAL(req->in.hdr,HDR_PID);
+
+       for (r = req->smb_conn->requests; r; r = r->next) {
+               if (mid != SVAL(r->in.hdr,HDR_MID)) continue;
+               /* do we really need to check the PID? */
+               if (pid != SVAL(r->in.hdr,HDR_PID)) continue;
+
+               SMBSRV_CHECK(ntvfs_cancel(r->ntvfs));
+
+               /* NOTE: this request does not generate a reply */
+               talloc_free(req);
+               return;
+       }
+
+       /* TODO: workout the correct error code */
+       smbsrv_send_error(req, NT_STATUS_FOOBAR);
 }
 
 /*
index a08ae46852a55778b13219fa8ce7d5c520695076..fc7d060ea89dd555b41874b13383461e9da8e5c1 100644 (file)
 /* we over allocate the data buffer to prevent too many realloc calls */
 #define REQ_OVER_ALLOCATION 0
 
+static int smbsrv_request_destructor(struct smbsrv_request *req)
+{
+       DLIST_REMOVE(req->smb_conn->requests, req);
+       return 0;
+}
+
 /****************************************************************************
 construct a basic request packet, mostly used to construct async packets
 such as change notify and oplock break requests
@@ -49,6 +55,8 @@ struct smbsrv_request *smbsrv_init_request(struct smbsrv_connection *smb_conn)
        /* setup the request context */
        req->smb_conn = smb_conn;
 
+       talloc_set_destructor(req, smbsrv_request_destructor);
+
        return req;
 }
 
index 676f417619e9b662dbb6072af1472c919099a72c..92967d858cd8886369600da68e07c4cc29db2938 100644 (file)
@@ -89,7 +89,6 @@ static NTSTATUS make_connection_snum(struct smbsrv_request *req,
        req->ntvfs = ntvfs_request_create(req->tcon->ntvfs, req,
                                          req->session->session_info,
                                          SVAL(req->in.hdr,HDR_PID),
-                                         SVAL(req->in.hdr,HDR_MID),
                                          req->request_time,
                                          req, NULL, 0);
        if (!req->ntvfs) {
index ce13756836da94b00f9116935704b984b2e2ba8e..838abdf4d621f307c17d1488b231707f5d754b00 100644 (file)
@@ -103,7 +103,6 @@ struct smbsrv_request;
        req->ntvfs = ntvfs_request_create(req->tcon->ntvfs, req, \
                                          req->session->session_info,\
                                          0, \
-                                         0, \
                                          req->request_time, \
                                          req, send_fn, state); \
        if (!req->ntvfs) { \
index cc0a9112241b256ee354360a214f8f2a16fa3ce5..338fb5ed22bece3740b64b49d3d377410b9ddb34 100644 (file)
@@ -242,7 +242,6 @@ static NTSTATUS smb2srv_tcon_backend(struct smb2srv_request *req, union smb_tcon
        req->ntvfs = ntvfs_request_create(req->tcon->ntvfs, req,
                                          req->session->session_info,
                                          0, /* TODO: fill in PID */
-                                         0, /* TODO: fill in MID */
                                          req->request_time,
                                          req, NULL, 0);
        if (!req->ntvfs) {
index 7ad1af2d27c92b00dd34a8d37807324e011f881f..c546de7e1c5a0f14e3be8d55c831081b5981d8d9 100644 (file)
@@ -24,6 +24,7 @@
 #include "libcli/raw/interfaces.h"
 #include "lib/events/events.h"
 #include "lib/socket/socket.h"
+#include "dlinklist.h"
 
 /*
   this header declares the core context structures associated with smb
@@ -320,15 +321,11 @@ struct smbsrv_connection {
        /* context associated with currently valid session setups */
        struct smbsrv_sessions_context sessions;
 
-       /* the server_context holds a linked list of pending requests,
-        * this is used for blocking locks and requests blocked due to oplock
-        * break requests */
-       struct _smbsrv_pending_request {
-               struct _smbsrv_pending_request *next, *prev;
-       
-               /* the request itself - needs to be freed */
-               struct smbsrv_request *request;
-       } *requests;
+       /*
+        * the server_context holds a linked list of pending requests,
+        * this is used for finding the request structures on ntcancel requests
+        */
+       struct smbsrv_request *requests;
 
        struct smb_signing_context signing;
 
@@ -387,7 +384,6 @@ struct smbsrv_connection {
        req->ntvfs = ntvfs_request_create(req->tcon->ntvfs, req, \
                                          req->session->session_info,\
                                          SVAL(req->in.hdr,HDR_PID), \
-                                         SVAL(req->in.hdr,HDR_MID), \
                                          req->request_time, \
                                          req, send_fn, state); \
        if (!req->ntvfs) { \
@@ -418,6 +414,15 @@ struct smbsrv_connection {
        } \
 } while (0)
 
+#define SMBSRV_CHECK(cmd) do {\
+       NTSTATUS _status; \
+       _status = cmd; \
+       if (!NT_STATUS_IS_OK(_status)) { \
+               smbsrv_send_error(req,  _status); \
+               return; \
+       } \
+} while (0)
+
 /* 
    check if the backend wants to handle the request asynchronously.
    if it wants it handled synchronously then call the send function
@@ -425,7 +430,9 @@ struct smbsrv_connection {
 */
 #define SMBSRV_CALL_NTVFS_BACKEND(cmd) do { \
        req->ntvfs->async_states->status = cmd; \
-       if (!(req->ntvfs->async_states->state & NTVFS_ASYNC_STATE_ASYNC)) { \
+       if (req->ntvfs->async_states->state & NTVFS_ASYNC_STATE_ASYNC) { \
+               DLIST_ADD_END(req->smb_conn->requests, req, struct smbsrv_request *); \
+       } else { \
                req->ntvfs->async_states->send_fn(req->ntvfs); \
        } \
 } while (0)