Skip to content
This repository has been archived by the owner on Nov 9, 2020. It is now read-only.

Commit

Permalink
Added errno generation in VMCI failures where errno was not set (#1049)
Browse files Browse the repository at this point in the history
We have some cases when protocol failed (e.g. EOF from client, or whatever).
THis is indicated with 0 lenght returned , but errno was no set because  it's considered success.
This makes it inconsistent with CGO (and maybe others) who rely on errno to form "err" part of the return value
  • Loading branch information
Mark Sterin authored Mar 21, 2017
1 parent 1445f96 commit dbd1804
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
7 changes: 7 additions & 0 deletions esx_service/vmci/connection_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
// First non privileged port
#define START_NON_PRIVILEGED_PORT 1024

/*
* Check and set errno helper
* Useful when send/recv gets us less than we wanted, and we want to set errno
* for the caller to know about the protocol Issue
*/
#define CHECK_ERRNO(_ret) {if (_ret >= 0 && errno == 0) { errno = EBADMSG; }}

/*
* This function acquires and returns address family for vSockets.
* On failure returns -1 an sets errno (if not set by VMCISock_GetAFValue ())
Expand Down
6 changes: 6 additions & 0 deletions esx_service/vmci/vmci_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,19 @@ vsock_get_reply(be_sock_id *s, be_request *r, be_answer* a)
b = MAGIC;
ret = send(s->sock_id, &b, sizeof b, 0);
if (ret == -1 || ret != sizeof b) {
CHECK_ERRNO(ret);
return CONN_FAILURE;
}

ret = send(s->sock_id, &r->mlen, sizeof r->mlen, 0);
if (ret == -1 || ret != sizeof r->mlen) {
CHECK_ERRNO(ret);
return CONN_FAILURE;
}

ret = send(s->sock_id, r->msg, r->mlen, 0);
if (ret == -1 || ret != r->mlen) {
CHECK_ERRNO(ret);
return CONN_FAILURE;
}

Expand All @@ -269,6 +272,7 @@ vsock_get_reply(be_sock_id *s, be_request *r, be_answer* a)
b = 0;
ret = recv(s->sock_id, &b, sizeof b, 0);
if (ret == -1 || ret != sizeof b ) {
CHECK_ERRNO(ret);
snprintf(a->errBuf, ERR_BUF_LEN, "Failed to receive magic data: received %d expected %d bytes\n",
ret, sizeof b);
return CONN_FAILURE;
Expand All @@ -282,6 +286,7 @@ vsock_get_reply(be_sock_id *s, be_request *r, be_answer* a)
// length
ret = recv(s->sock_id, &b, sizeof b, 0);
if (ret == -1 || ret != sizeof b) {
CHECK_ERRNO(ret);
snprintf(a->errBuf, ERR_BUF_LEN, "Failed to receive data len : ret %d (%s)\n",
ret, strerror(errno));
return CONN_FAILURE;
Expand All @@ -299,6 +304,7 @@ vsock_get_reply(be_sock_id *s, be_request *r, be_answer* a)
if (ret == -1 || ret != b) {
free(a->buf);
a->buf = NULL;
CHECK_ERRNO(ret);
snprintf(a->errBuf, ERR_BUF_LEN, "Failed to receive message data: received %d expected %d\n",
ret, b);
return CONN_FAILURE;
Expand Down
3 changes: 3 additions & 0 deletions esx_service/vmci/vmci_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ vmci_get_one_op(const int s, // socket to listen on
ret, strerror(errno), b, MAGIC);
close(client_socket);
errno = saved_errno;
CHECK_ERRNO(ret);
return CONN_FAILURE;
}

Expand Down Expand Up @@ -184,6 +185,7 @@ vmci_get_one_op(const int s, // socket to listen on
ret, strerror(errno), b);
close(client_socket);
errno = saved_errno;
CHECK_ERRNO(ret);
return CONN_FAILURE;
}
// do protocol sanity check
Expand Down Expand Up @@ -255,6 +257,7 @@ vmci_reply(const int client_socket, // socket to use
failed:
close(client_socket);
errno = saved_errno;
CHECK_ERRNO(ret);
return CONN_FAILURE;
}

Expand Down
4 changes: 2 additions & 2 deletions vmdk_plugin/utils/refcount/refcnt.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ func (r RefCountsMap) discoverAndSync(c *client.Client, d drivers.VolumeDriver)
for _, mount := range containerJSONInfo.Mounts {
if mount.Driver == driverName {
r.Incr(mount.Name)
log.Debugf(" name=%v (driver=%s source=%s)",
mount.Name, mount.Driver, mount.Source)
log.Debugf(" name=%v (driver=%s source=%s) (%v)",
mount.Name, mount.Driver, mount.Source, mount)
}
}
}
Expand Down

0 comments on commit dbd1804

Please sign in to comment.