+        if (!DeviceIoControl(sock->handle, OVS_IOCTL_READ,
+                             NULL, 0, tail, sizeof tail, &bytes, NULL))
...
+                memcpy(ofpbuf_data(buf), tail, retval);
+                ofpbuf_set_size(buf, retval);

We probably want to send down the "struct iovec iov" (rather than the tail)  
parameter so we can use the original and avoid the data copy.
This will require to map the user mode virtual address into the kernel (since 
the kernel executed in the context of the use mode thread we don't have to pin 
this memory).
Eitan

-----Original Message-----
From: dev [mailto:dev-boun...@openvswitch.org] On Behalf Of Nithin Raju
Sent: Wednesday, August 27, 2014 8:36 AM
To: dev@openvswitch.org; aserd...@cloudbasesolutions.com
Subject: [ovs-dev] [PATCH] netlink-socket.c: 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 <nit...@vmware.com>
---
 lib/netlink-socket.c |   46 ++++++++++++++++++++++++++--------------------
 1 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/lib/netlink-socket.c b/lib/netlink-socket.c index 4d9832f..a6be186 
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);
--
1.7.4.1

_______________________________________________
dev mailing list
dev@openvswitch.org
https://urldefense.proofpoint.com/v1/url?u=http://openvswitch.org/mailman/listinfo/dev&k=oIvRg1%2BdGAgOoM1BIlLLqw%3D%3D%0A&r=yTvML8OxA42Jb6ViHe7fUXbvPVOYDPVq87w43doxtlY%3D%0A&m=pobbphoswUVAlYlGyDNMKifynvHgFWdpDrVvUMLFReg%3D%0A&s=83541ef0d336bd56a4c781e92871129c4339a90888183dd5fc13efa1646b0a37
_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to