From fd972eb87a888242fb1a8ec2394fa7b3030fbd7d Mon Sep 17 00:00:00 2001 From: Nithin Raju Date: Wed, 27 Aug 2014 08:36:19 -0700 Subject: [PATCH] netlink-socket: Use read/write ioctl instead of ReadFile/WriteFile. The Windows datapath supports a READ/WRITE ioctl instead of ReadFile/WriteFile. In this change, we update the following: - WriteFile() in nl_sock_send__() to use DeviceIoControl(OVS_IOCTL_WRITE) - ReadFile() in nl_sock_recv__() to use DeviceIoControl(OVS_IOCTL_READ) The WriteFile() call in nl_sock_transact_multiple__() has not been touched since it is not needed yet. Main motive for this change is to be able to unblock the DP Dump workflow. Signed-off-by: Nithin Raju Signed-off-by: Ben Pfaff Acked-by: Eitan Eliahu Acked-by: Alin Gabriel Serdean --- lib/netlink-socket.c | 46 +++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/lib/netlink-socket.c b/lib/netlink-socket.c index 4d9832f48..a6be1861e 100644 --- a/lib/netlink-socket.c +++ b/lib/netlink-socket.c @@ -426,17 +426,20 @@ nl_sock_send__(struct nl_sock *sock, const struct ofpbuf *msg, do { int retval; #ifdef _WIN32 - bool result; - DWORD last_error = 0; - result = WriteFile(sock->handle, ofpbuf_data(msg), ofpbuf_size(msg), - &retval, NULL); - last_error = GetLastError(); - if (last_error != ERROR_SUCCESS && !result) { + DWORD bytes; + + if (!DeviceIoControl(sock->handle, OVS_IOCTL_WRITE, + ofpbuf_data(msg), ofpbuf_size(msg), NULL, 0, + &bytes, NULL)) { retval = -1; - errno = EAGAIN; + /* XXX: Map to a more appropriate error based on GetLastError(). */ + errno = EINVAL; + } else { + retval = ofpbuf_size(msg); } #else - retval = send(sock->fd, ofpbuf_data(msg), ofpbuf_size(msg), wait ? 0 : MSG_DONTWAIT); + retval = send(sock->fd, ofpbuf_data(msg), ofpbuf_size(msg), + wait ? 0 : MSG_DONTWAIT); #endif error = retval < 0 ? errno : 0; } while (error == EINTR); @@ -488,12 +491,7 @@ nl_sock_recv__(struct nl_sock *sock, struct ofpbuf *buf, bool wait) * 'tail' to allow Netlink messages to be up to 64 kB long (a reasonable * figure since that's the maximum length of a Netlink attribute). */ struct nlmsghdr *nlmsghdr; -#ifdef _WIN32 -#define MAX_STACK_LENGTH 81920 - uint8_t tail[MAX_STACK_LENGTH]; -#else uint8_t tail[65536]; -#endif struct iovec iov[2]; struct msghdr msg; ssize_t retval; @@ -522,15 +520,23 @@ nl_sock_recv__(struct nl_sock *sock, struct ofpbuf *buf, bool wait) do { nlmsghdr->nlmsg_len = UINT32_MAX; #ifdef _WIN32 - boolean result = false; - DWORD last_error = 0; - result = ReadFile(sock->handle, tail, MAX_STACK_LENGTH, &retval, NULL); - last_error = GetLastError(); - if (last_error != ERROR_SUCCESS && !result) { + DWORD bytes; + if (!DeviceIoControl(sock->handle, OVS_IOCTL_READ, + NULL, 0, tail, sizeof tail, &bytes, NULL)) { retval = -1; - errno = EAGAIN; + errno = EINVAL; } else { - ofpbuf_put(buf, tail, retval); + retval = bytes; + if (retval == 0) { + retval = -1; + errno = EAGAIN; + } else { + if (retval >= buf->allocated) { + ofpbuf_reinit(buf, retval); + } + memcpy(ofpbuf_data(buf), tail, retval); + ofpbuf_set_size(buf, retval); + } } #else retval = recvmsg(sock->fd, &msg, wait ? 0 : MSG_DONTWAIT); -- 2.20.1