From: VMware, Inc <> Date: Tue, 24 Aug 2010 18:44:49 +0000 (-0700) Subject: Channel abstraction for Mac OS. X-Git-Tag: 2010.08.24-292196~14 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fbf114b040763febcb512b63801bce52a0f19a02;p=thirdparty%2Fopen-vm-tools.git Channel abstraction for Mac OS. 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 --- diff --git a/open-vm-tools/modules/freebsd/vmhgfs/request.c b/open-vm-tools/modules/freebsd/vmhgfs/request.c index 5d3eea68e..6e5accfd4 100644 --- a/open-vm-tools/modules/freebsd/vmhgfs/request.c +++ b/open-vm-tools/modules/freebsd/vmhgfs/request.c @@ -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; } diff --git a/open-vm-tools/modules/freebsd/vmhgfs/worker.c b/open-vm-tools/modules/freebsd/vmhgfs/worker.c index 48b26231e..750b49bd0 100644 --- a/open-vm-tools/modules/freebsd/vmhgfs/worker.c +++ b/open-vm-tools/modules/freebsd/vmhgfs/worker.c @@ -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); }