]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Channel abstraction for Mac OS.
authorVMware, Inc <>
Tue, 24 Aug 2010 18:44:49 +0000 (11:44 -0700)
committerMarcelo Vanzin <mvanzin@vmware.com>
Tue, 24 Aug 2010 18:44:49 +0000 (11:44 -0700)
In preparation for Hgfs over vmci, let's abstract
the channel for Mac OS i.e remove all the assumptions
of backdoor so that it can transparently over both backdoor
and vmci.

Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/modules/freebsd/vmhgfs/request.c
open-vm-tools/modules/freebsd/vmhgfs/worker.c

index 5d3eea68efbaecc591399ca017e3941c951f97f9..6e5accfd448fcb6d0c54460ed9300810b4c40b94 100644 (file)
@@ -62,10 +62,10 @@ OS_CV_T hgfsKReqWorkItemCv;
  * Local functions (prototypes)
  */
 
-   static int   HgfsKReqZCtor(void *mem, int size, void *arg, int flags);
-   static void  HgfsKReqZDtor(void *mem, int size, void *arg);
-   static int   HgfsKReqZInit(void *mem, int size, int flags);
-   static void  HgfsKReqZFini(void *mem, int size);
+static int   HgfsKReqZCtor(void *mem, int size, void *arg, int flags);
+static void  HgfsKReqZDtor(void *mem, int size, void *arg);
+static int   HgfsKReqZInit(void *mem, int size, int flags);
+static void  HgfsKReqZFini(void *mem, int size);
 
 /*
  * Global functions (definitions)
@@ -719,10 +719,7 @@ HgfsKReqZInit(void *mem,     // IN: Pointer to the allocated object
    HgfsKReqObject *req = (HgfsKReqObject *)mem;
    ASSERT(size == sizeof *req);
 
-   /*
-    * Zero out the object.  (Do NOT pass UMA_ZEROINIT to uma_zcreate, as
-    * that will override this routine and zero everything -after- us.)
-    */
+   /* Zero out the object. */
    bzero(req, sizeof *req);
 
    /*
@@ -746,8 +743,6 @@ HgfsKReqZInit(void *mem,     // IN: Pointer to the allocated object
 
    /* Clear packet of request before allocating to clients. */
    bzero(&req->__rpc_packet, sizeof req->__rpc_packet);
-   bcopy(HGFS_SYNC_REQREP_CLIENT_CMD, req->__rpc_packet._command,
-         HGFS_SYNC_REQREP_CLIENT_CMD_LEN);
 
    return 0;
 }
@@ -817,9 +812,6 @@ HgfsKReqZCtor(void *mem,     // IN: Pointer to memory allocated to user
    /* Initialize state & reference count. */
    req->state = HGFS_REQ_ALLOCATED;
    req->refcnt = 1;
-
-   ASSERT(!strncmp(req->__rpc_packet._command, HGFS_SYNC_REQREP_CLIENT_CMD, HGFS_SYNC_REQREP_CLIENT_CMD_LEN));
-
    return 0;
 }
 
index 48b26231e930e85c8acde9acf89bd896180bbf88..750b49bd0f45331eef0206d406833a51821842cd 100644 (file)
@@ -30,8 +30,7 @@
 #include "request.h"
 #include "requestInt.h"
 #include "os.h"
-
-#include "hgfsBd.h"
+#include "channel.h"
 
 
 /*
@@ -47,6 +46,7 @@ OS_THREAD_T hgfsKReqWorkerThread;
  * See requestInt.h.
  */
 HgfsKReqWState hgfsKReqWorkerState;
+HgfsTransportChannel *gHgfsChannel;
 
 
 /*
@@ -77,12 +77,12 @@ HgfsKReqWorker(void *arg)
    DblLnkLst_Links *currNode, *nextNode;
    HgfsKReqWState *ws = (HgfsKReqWState *)arg;
    HgfsKReqObject *req;
-   RpcOut *hgfsRpcOut = NULL;
-   char const *replyPacket;
    int ret = 0;
 
    ws->running = TRUE;
 
+   gHgfsChannel = HgfsGetBdChannel();
+
    for (;;) {
       /*
        * This loop spends most of its time sleeping until signalled by another
@@ -93,7 +93,7 @@ HgfsKReqWorker(void *arg)
       os_mutex_lock(hgfsKReqWorkItemLock);
 
       while (!ws->exit && !DblLnkLst_IsLinked(&hgfsKReqWorkItemList)) {
-        os_cv_wait(&hgfsKReqWorkItemCv, hgfsKReqWorkItemLock);
+         os_cv_wait(&hgfsKReqWorkItemCv, hgfsKReqWorkItemLock);
       }
 
       if (ws->exit) {
@@ -126,12 +126,14 @@ HgfsKReqWorker(void *arg)
       os_mutex_lock(req->stateLock);
       switch (req->state) {
       case HGFS_REQ_SUBMITTED:
-         if (!HgfsBd_OpenBackdoor(&hgfsRpcOut)) {
-            req->state = HGFS_REQ_ERROR;
-            os_cv_signal(&req->stateCv);
-            os_mutex_unlock(req->stateLock);
-           os_mutex_unlock(hgfsKReqWorkItemLock);
-            goto done;
+         if (gHgfsChannel->status != HGFS_CHANNEL_CONNECTED) {
+            if (!gHgfsChannel->ops.open(gHgfsChannel)) {
+               req->state = HGFS_REQ_ERROR;
+               os_cv_signal(&req->stateCv);
+               os_mutex_unlock(req->stateLock);
+               os_mutex_unlock(hgfsKReqWorkItemLock);
+               goto done;
+            }
          }
          break;
       case HGFS_REQ_ABANDONED:
@@ -150,25 +152,7 @@ HgfsKReqWorker(void *arg)
        */
       os_mutex_unlock(hgfsKReqWorkItemLock);
 
-      ret = HgfsBd_Dispatch(hgfsRpcOut, req->payload, &req->payloadSize,
-                            &replyPacket);
-
-      /*
-       * We have a response.  (Maybe.)  Re-lock the request, update its state,
-       * etc.
-       */
-
-      os_mutex_lock(req->stateLock);
-
-      if ((ret == 0) && (req->state == HGFS_REQ_SUBMITTED)) {
-         bcopy(replyPacket, req->payload, req->payloadSize);
-         req->state = HGFS_REQ_COMPLETED;
-      } else {
-         req->state = HGFS_REQ_ERROR;
-      }
-
-      os_cv_signal(&req->stateCv);
-      os_mutex_unlock(req->stateLock);
+      ret = gHgfsChannel->ops.send(gHgfsChannel, req);
 
       if (ret != 0) {
          /*
@@ -176,7 +160,7 @@ HgfsKReqWorker(void *arg)
           * now. We do this because subsequent requests deserve a chance to
           * reopen it.
           */
-         HgfsBd_CloseBackdoor(&hgfsRpcOut);
+         gHgfsChannel->ops.close(gHgfsChannel);
       }
 
 done:
@@ -213,9 +197,6 @@ done:
 
    ws->running = FALSE;
 
-   if (hgfsRpcOut != NULL ) {
-      HgfsBd_CloseBackdoor(&hgfsRpcOut);
-   }
-
+   gHgfsChannel->ops.close(gHgfsChannel);
    os_thread_exit(0);
 }