From: VMware, Inc <> Date: Wed, 18 Sep 2013 03:20:14 +0000 (-0700) Subject: Internal branch sync. Included in this change: X-Git-Tag: 2013.09.16-1328054~86 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e996a35e60280a8dd73bb78f9a9ddde06fec7b77;p=thirdparty%2Fopen-vm-tools.git Internal branch sync. Included in this change: . dnd plugin: various cleanups . asyncsocket: Fix for race conditions with sync operations on a 2nd thread Signed-off-by: Dmitry Torokhov --- diff --git a/open-vm-tools/lib/asyncsocket/asyncsocket.c b/open-vm-tools/lib/asyncsocket/asyncsocket.c index 6fec4a1d0..9c55b34d9 100644 --- a/open-vm-tools/lib/asyncsocket/asyncsocket.c +++ b/open-vm-tools/lib/asyncsocket/asyncsocket.c @@ -3190,18 +3190,41 @@ AsyncSocket_WaitForConnection(AsyncSocket *s, // IN: Bool read; int error; VmTimeType now, done; + Bool removed = FALSE; ASSERT(s->asockType != ASYNCSOCKET_TYPE_NAMEDPIPE); + AsyncSocketLock(s); + if (s->state == AsyncSocketConnected) { - return ASOCKERR_SUCCESS; + error = ASOCKERR_SUCCESS; + goto outHaveLock; } if (s->state != AsyncSocketListening && s->state != AsyncSocketConnecting) { - return ASOCKERR_GENERIC; + error = ASOCKERR_GENERIC; + goto outHaveLock; } + /* + * A nuisance. ConnectCallback() is either registered as a device or + * rtime callback depending on the prior return value of connect(). + * So we try to remove it from both. + * + * XXX: For listening sockets, the callback is AsyncSocketAcceptCallback, + * which would need to be unregistered here and then be re-registered + * before returning. + */ + if (s->state == AsyncSocketConnecting) { + removed = AsyncSocketPollRemove(s, TRUE, POLL_FLAG_WRITE, + AsyncSocketConnectCallback) + || AsyncSocketPollRemove(s, FALSE, 0, AsyncSocketConnectCallback); + ASSERT(removed); + } + + AsyncSocketUnlock(s); + read = s->state == AsyncSocketListening; now = Hostinfo_SystemTimerUS() / 1000; @@ -3231,18 +3254,6 @@ AsyncSocket_WaitForConnection(AsyncSocket *s, // IN: goto outHaveLock; } } else { - /* - * A nuisance. ConnectCallback() is either registered as a device or - * rtime callback depending on the prior return value of connect(). - * So we try to remove it from both. - */ - - Bool removed = FALSE; - removed = AsyncSocketPollRemove(s, TRUE, POLL_FLAG_WRITE, - AsyncSocketConnectCallback) - || AsyncSocketPollRemove(s, FALSE, 0, AsyncSocketConnectCallback); - ASSERT(removed); - error = AsyncSocketConnectInternal(s); goto outHaveLock; } diff --git a/open-vm-tools/services/plugins/dndcp/dnd/dndLinux.c b/open-vm-tools/services/plugins/dndcp/dnd/dndLinux.c index e7fea758f..609a7fada 100644 --- a/open-vm-tools/services/plugins/dndcp/dnd/dndLinux.c +++ b/open-vm-tools/services/plugins/dndcp/dnd/dndLinux.c @@ -334,6 +334,8 @@ Bool DnD_AddBlockLegacy(int blockFd, // IN const char *blockPath) // IN { + LOG(1, ("%s: placing block on %s\n", __func__, blockPath)); + ASSERT(blockFd >= 0); if (VMBLOCK_CONTROL(blockFd, VMBLOCK_ADD_FILEBLOCK, blockPath) != 0) { @@ -367,6 +369,8 @@ Bool DnD_RemoveBlockLegacy(int blockFd, // IN const char *blockedPath) // IN { + LOG(1, ("%s: removing block on %s\n", __func__, blockedPath)); + if (blockFd >= 0) { if (VMBLOCK_CONTROL(blockFd, VMBLOCK_DEL_FILEBLOCK, blockedPath) != 0) { Log("%s: Cannot delete block on %s (%s)\n", @@ -429,6 +433,8 @@ Bool DnD_AddBlockFuse(int blockFd, // IN const char *blockPath) // IN { + LOG(1, ("%s: placing block on %s\n", __func__, blockPath)); + ASSERT(blockFd >= 0); if (VMBLOCK_CONTROL_FUSE(blockFd, VMBLOCK_FUSE_ADD_FILEBLOCK, @@ -463,6 +469,8 @@ Bool DnD_RemoveBlockFuse(int blockFd, // IN const char *blockedPath) // IN { + LOG(1, ("%s: removing block on %s\n", __func__, blockedPath)); + if (blockFd >= 0) { if (VMBLOCK_CONTROL_FUSE(blockFd, VMBLOCK_FUSE_DEL_FILEBLOCK, blockedPath) != 0) {