#include "hgfs_kernel.h"
#include "requestInt.h"
-#include "channel.h"
/*
* Macros
ASSERT(container);
- /*
- * We may not have any channel currently. It so, try to
- * establish channel once again. Most likely we will fail
- * because user has probably disabled shared folders. This
- * check is useful when user enables shared folders and they
- * tries some operation. During that, we will come across this
- * code path and user will be magically able to access stuff
- * on host.
- *
- * Note that trying to establish new channel on send() path is
- * broken because every channel has specific allocator function.
- * Trying to allocate from one channel and then sending over
- * another channel is sure asking for trouble. Don't do that.
- */
- if (gHgfsChannel->status != HGFS_CHANNEL_CONNECTED) {
- if (!HgfsSetupNewChannel()) {
- return NULL;
- }
- }
-
req = os_zone_alloc(hgfsKReqZone, M_WAITOK);
if (!req) {
return NULL;
/* Global pointer that handles channel abstraction */
HgfsTransportChannel *gHgfsChannel = NULL;
-OS_MUTEX_T *gHgfsChannelLock = NULL;
/*
*----------------------------------------------------------------------
*/
-Bool
+static Bool
HgfsSetupNewChannel(void)
{
Bool ret;
- os_mutex_lock(gHgfsChannelLock);
-
- if (gHgfsChannel->status == HGFS_CHANNEL_CONNECTED) {
- ret = TRUE;
- goto exit;
- }
-
HgfsGetVmciChannel(gHgfsChannel);
if (gHgfsChannel->ops.open != NULL) {
if ((ret = gHgfsChannel->ops.open(gHgfsChannel))) {
exit:
if (ret) {
gHgfsChannel->status = HGFS_CHANNEL_CONNECTED;
- } else {
- gHgfsChannel->status = HGFS_CHANNEL_NOTCONNECTED;
}
-
- os_mutex_unlock(gHgfsChannelLock);
-
return ret;
}
-
/*
*-----------------------------------------------------------------------------
*
goto exit;
}
- gHgfsChannelLock = os_mutex_alloc_init(HGFS_FS_NAME "_channellck");
- if (!gHgfsChannelLock) {
- goto exit;
- }
-
ret = HgfsSetupNewChannel();
if (!ret) {
- DEBUG(VM_DEBUG_INFO, "VMware hgfs: %s: ohoh no channel yet.\n", __func__);
+ DEBUG(VM_DEBUG_INFO, "VMware hgfs: %s: ohoh no channel.\n", __func__);
+ goto exit;
}
for (;;) {
switch (req->state) {
case HGFS_REQ_SUBMITTED:
if (gHgfsChannel->status != HGFS_CHANNEL_CONNECTED) {
- req->state = HGFS_REQ_ERROR;
- os_cv_signal(&req->stateCv);
- os_mutex_unlock(req->stateLock);
- os_mutex_unlock(hgfsKReqWorkItemLock);
- goto done;
+ if (!HgfsSetupNewChannel()) {
+ 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:
* now. We do this because subsequent requests deserve a chance to
* reopen it.
*/
- os_mutex_lock(gHgfsChannelLock);
gHgfsChannel->ops.close(gHgfsChannel);
- os_mutex_unlock(gHgfsChannelLock);
}
done:
ws->running = FALSE;
- if (gHgfsChannel->status == HGFS_CHANNEL_CONNECTED) {
- gHgfsChannel->ops.close(gHgfsChannel);
- }
+ gHgfsChannel->ops.close(gHgfsChannel);
exit:
- if (gHgfsChannelLock) {
- os_mutex_free(gHgfsChannelLock);
- }
-
if (gHgfsChannel) {
os_free(gHgfsChannel, sizeof (*gHgfsChannel));
}