qemu-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-commits] [qemu/qemu] c61964: osdep: fix socket_error() to work wit


From: GitHub
Subject: [Qemu-commits] [qemu/qemu] c61964: osdep: fix socket_error() to work with Mingw64
Date: Mon, 14 Mar 2016 07:00:09 -0700

  Branch: refs/heads/master
  Home:   https://github.com/qemu/qemu
  Commit: c619644067f98098dcdbc951e2dda79e97560afa
      
https://github.com/qemu/qemu/commit/c619644067f98098dcdbc951e2dda79e97560afa
  Author: Daniel P. Berrange <address@hidden>
  Date:   2016-03-10 (Thu, 10 Mar 2016)

  Changed paths:
    M include/qemu/sockets.h
    M include/sysemu/os-posix.h
    M include/sysemu/os-win32.h
    M util/oslib-win32.c

  Log Message:
  -----------
  osdep: fix socket_error() to work with Mingw64

Historically QEMU has had a socket_error() macro that was
defined to map to WSASocketError(). The os-win32.h header
file would define errno constants that mapped to the
WSA error constants. This worked fine with Mingw32 since
its header files never defined any errno values, nor did
it even provide an errno.h.  So callers of socket_error()
could match on traditional Exxxx constants and it would
all "just work".

With Mingw64 though, things work rather differently. First
there is an errno.h file which defines all the traditional
errno constants you'd expect from a UNIX platform. There
is then a winerror.h which defined the WSA error constants.
Crucially the WSAExxxx errno values in winerror.h do not
match the Exxxx errno values in error.h.

If QEMU had only imported winerror.h it would still work,
but the qemu/osdep.h file unconditionally imports errno.h.
So callers of socket_error() will get now WSAExxxx values
back and compare them to the Exxx constants. This will
always fail silently at runtime.

To solve this QEMU needs to stop assuming the WSAExxxx
constant values match the Exxx constant values. Thus the
socket_error() macro is turned into a small function that
re-maps WSAExxxx values into Exxx.

Reviewed-by: Paolo Bonzini <address@hidden>
Signed-off-by: Daniel P. Berrange <address@hidden>


  Commit: 0a27af918b9cfb7fc1605c66dfc70700be16fab5
      
https://github.com/qemu/qemu/commit/0a27af918b9cfb7fc1605c66dfc70700be16fab5
  Author: Daniel P. Berrange <address@hidden>
  Date:   2016-03-10 (Thu, 10 Mar 2016)

  Changed paths:
    M tests/test-io-channel-socket.c

  Log Message:
  -----------
  io: use bind() to check for IPv4/6 availability

Currently the test-io-channel-socket.c test uses getifaddrs
to see if an IPv4/6 address is present on any host NIC, as
a way to determine if IPv4/6 sockets can be used. This is
problematic because getifaddrs is not available on Win32.

Rather than testing indirectly via getifaddrs, just create
a socket and try to bind() to the loopback address instead.

Reviewed-by: Paolo Bonzini <address@hidden>
Signed-off-by: Daniel P. Berrange <address@hidden>


  Commit: 5838d66e73ac50c5547796afe1e86aa204b77fea
      
https://github.com/qemu/qemu/commit/5838d66e73ac50c5547796afe1e86aa204b77fea
  Author: Daniel P. Berrange <address@hidden>
  Date:   2016-03-10 (Thu, 10 Mar 2016)

  Changed paths:
    M tests/test-io-channel-socket.c

  Log Message:
  -----------
  io: initialize sockets in test program

The win32 sockets layer requires that socket_init() is called
otherwise nothing will work.

Reviewed-by: Paolo Bonzini <address@hidden>
Signed-off-by: Daniel P. Berrange <address@hidden>


  Commit: abc981bf292fb361f8a509c3611ddf2ba2c43360
      
https://github.com/qemu/qemu/commit/abc981bf292fb361f8a509c3611ddf2ba2c43360
  Author: Daniel P. Berrange <address@hidden>
  Date:   2016-03-10 (Thu, 10 Mar 2016)

  Changed paths:
    M tests/test-io-channel-socket.c

  Log Message:
  -----------
  io: bind to socket before creating QIOChannelSocket

In the QIOChannelSocket test we create a socket file
descriptor and then try to create a QIOChannelSocket.
This works on Linux, but fails on Win32 because it is
not valid to call getsockname() on an unbound socket.

Reviewed-by: Paolo Bonzini <address@hidden>
Signed-off-by: Daniel P. Berrange <address@hidden>


  Commit: a9d5aed12d0cf067e87eda14e794cda022381e1b
      
https://github.com/qemu/qemu/commit/a9d5aed12d0cf067e87eda14e794cda022381e1b
  Author: Daniel P. Berrange <address@hidden>
  Date:   2016-03-10 (Thu, 10 Mar 2016)

  Changed paths:
    M tests/test-io-channel-socket.c

  Log Message:
  -----------
  io: wait for incoming client in socket test

Exercise the GSource code for server sockets by calling
qio_channel_wait() prior to accepting the incoming client.

Reviewed-by: Paolo Bonzini <address@hidden>
Signed-off-by: Daniel P. Berrange <address@hidden>


  Commit: 256920eb94f4de9430122b7618b9c2a16cb2df32
      
https://github.com/qemu/qemu/commit/256920eb94f4de9430122b7618b9c2a16cb2df32
  Author: Daniel P. Berrange <address@hidden>
  Date:   2016-03-10 (Thu, 10 Mar 2016)

  Changed paths:
    M tests/io-channel-helpers.c

  Log Message:
  -----------
  io: set correct error object in background reader test thread

The reader thread was accidentally setting the error pointer
intended for the writer thread. If both threads set errors
this would result in QEMU abort'ing due to the error already
being set.

Reviewed-by: Paolo Bonzini <address@hidden>
Signed-off-by: Daniel P. Berrange <address@hidden>


  Commit: 294bbbb4252ab5ff42d0e2c09f209c0bd7eb9748
      
https://github.com/qemu/qemu/commit/294bbbb4252ab5ff42d0e2c09f209c0bd7eb9748
  Author: Daniel P. Berrange <address@hidden>
  Date:   2016-03-10 (Thu, 10 Mar 2016)

  Changed paths:
    M tests/io-channel-helpers.c

  Log Message:
  -----------
  io: assert errors before asserting content in I/O test

When checking the results of an I/O operation test, assert that
the error objects are NULL before asserting on the content. This
is found to give more useful indication of the problem when
diagnosing test failures.

Reviewed-by: Paolo Bonzini <address@hidden>
Signed-off-by: Daniel P. Berrange <address@hidden>


  Commit: 5151d23e65e1ffc50c880d9fdcfd70bfa33255c5
      
https://github.com/qemu/qemu/commit/5151d23e65e1ffc50c880d9fdcfd70bfa33255c5
  Author: Daniel P. Berrange <address@hidden>
  Date:   2016-03-10 (Thu, 10 Mar 2016)

  Changed paths:
    M io/channel-socket.c

  Log Message:
  -----------
  io: fix copy+paste mistake in socket error message

s/write/read/ in the error message reported after
readmsg() fails

Reviewed-by: Paolo Bonzini <address@hidden>
Signed-off-by: Daniel P. Berrange <address@hidden>


  Commit: e560d141ab0504495142486c21769df1ec346479
      
https://github.com/qemu/qemu/commit/e560d141ab0504495142486c21769df1ec346479
  Author: Paolo Bonzini <address@hidden>
  Date:   2016-03-10 (Thu, 10 Mar 2016)

  Changed paths:
    M io/channel-watch.c

  Log Message:
  -----------
  io: pass HANDLE to g_source_add_poll on Win32

Reviewed-by: Daniel P. Berrange <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>


  Commit: b83b68a0132f43f3ebcb61c9237ec1090da58894
      
https://github.com/qemu/qemu/commit/b83b68a0132f43f3ebcb61c9237ec1090da58894
  Author: Paolo Bonzini <address@hidden>
  Date:   2016-03-10 (Thu, 10 Mar 2016)

  Changed paths:
    M include/io/channel-watch.h
    M io/channel-socket.c
    M io/channel-watch.c

  Log Message:
  -----------
  io: introduce qio_channel_create_socket_watch

Sockets are not in the same namespace as file descriptors on Windows.
As an initial step, introduce separate APIs for file descriptor and
socket watches.

Signed-off-by: Paolo Bonzini <address@hidden>


  Commit: de7971ffb9a1ac85cbcc12f5380f44d31ed182e6
      
https://github.com/qemu/qemu/commit/de7971ffb9a1ac85cbcc12f5380f44d31ed182e6
  Author: Daniel P. Berrange <address@hidden>
  Date:   2016-03-10 (Thu, 10 Mar 2016)

  Changed paths:
    M io/channel-socket.c

  Log Message:
  -----------
  io: use qemu_accept to ensure SOCK_CLOEXEC is set

The QIOChannelSocket code mistakenly uses the bare accept()
function which does not set SOCK_CLOEXEC.

Signed-off-by: Daniel P. Berrange <address@hidden>


  Commit: 30fd3e27907dfd1c0c66cc1339657af1a2ce1d4b
      
https://github.com/qemu/qemu/commit/30fd3e27907dfd1c0c66cc1339657af1a2ce1d4b
  Author: Daniel P. Berrange <address@hidden>
  Date:   2016-03-10 (Thu, 10 Mar 2016)

  Changed paths:
    M io/channel-command.c
    M io/channel-file.c
    M io/channel-socket.c

  Log Message:
  -----------
  io: remove checking of EWOULDBLOCK

Since we now canonicalize WSAEWOULDBLOCK into EAGAIN there is
no longer any need to explicitly check EWOULDBLOCK for Win32.

Signed-off-by: Daniel P. Berrange <address@hidden>


  Commit: a58972056776e2f2588aed5a2dc0db7cc28f80b1
      
https://github.com/qemu/qemu/commit/a58972056776e2f2588aed5a2dc0db7cc28f80b1
  Author: Paolo Bonzini <address@hidden>
  Date:   2016-03-10 (Thu, 10 Mar 2016)

  Changed paths:
    M include/io/channel.h
    M io/channel-socket.c
    M io/channel-watch.c
    M io/channel.c

  Log Message:
  -----------
  io: implement socket watch for win32 using WSAEventSelect+select

On Win32 we cannot directly poll on socket handles. Instead we
create a Win32 event object and associate the socket handle with
the event. When the event signals readyness we then have to
use select to determine which events are ready. Creating Win32
events is moderately heavyweight, so we don't want todo it
every time we create a GSource, so this associates a single
event with a QIOChannel.

Signed-off-by: Paolo Bonzini <address@hidden>
Signed-off-by: Daniel P. Berrange <address@hidden>


  Commit: f50dfe457f128632efa0a49e2b2a472e357e00f9
      
https://github.com/qemu/qemu/commit/f50dfe457f128632efa0a49e2b2a472e357e00f9
  Author: Daniel P. Berrange <address@hidden>
  Date:   2016-03-10 (Thu, 10 Mar 2016)

  Changed paths:
    M qemu-char.c

  Log Message:
  -----------
  char: remove qemu_chr_finish_socket_connection method

The qemu_chr_finish_socket_connection method is multiplexing two
different actions into one method. Each caller of it though, only
wants one specific action. The code is shorter & clearer if we
thus remove the method and just inline the specific actions
where needed.

Signed-off-by: Daniel P. Berrange <address@hidden>


  Commit: 317856cac87b2aa15d03982262a436f1d3d0a2b3
      
https://github.com/qemu/qemu/commit/317856cac87b2aa15d03982262a436f1d3d0a2b3
  Author: Daniel P. Berrange <address@hidden>
  Date:   2016-03-10 (Thu, 10 Mar 2016)

  Changed paths:
    M qemu-char.c

  Log Message:
  -----------
  char: remove socket_try_connect method

The qemu_chr_open_socket_fd() method multiplexes three different
actions into one method. The socket_try_connect() method is one
of its callers, but it only ever want one specific action
performed. By inlining that action into socket_try_connect()
we see that there is not in fact any failure scenario, so there
is not even any reason for socket_try_connect to exist. Just
inline the asynchronous connection attempts directly at the
places that need them. This shortens & clarifies the code.

Reviewed-by: Paolo Bonzini <address@hidden>
Signed-off-by: Daniel P. Berrange <address@hidden>


  Commit: 08b758b4820ca65791894a268f7bcd2964f66c31
      
https://github.com/qemu/qemu/commit/08b758b4820ca65791894a268f7bcd2964f66c31
  Author: Daniel P. Berrange <address@hidden>
  Date:   2016-03-10 (Thu, 10 Mar 2016)

  Changed paths:
    M qemu-char.c

  Log Message:
  -----------
  char: remove qemu_chr_open_socket_fd method

The qemu_chr_open_socket_fd method takes care of either doing a
synchronous socket connect, or creating a listener socket. Part
of the work when creating the listener socket is to register a
watch for incoming clients. The caller of qemu_chr_open_socket_fd
may not want this watch created, as it might be doing a synchronous
wait for the first client. Rather than passing yet more parameters
into qemu_chr_open_socket_fd to let it handle this, just remove
the qemu_chr_open_socket_fd method an inline its functionality
into the caller. This allows for a clearer control flow and shorter
code.

Signed-off-by: Daniel P. Berrange <address@hidden>


  Commit: a2d96af4bb267bd1844f71f593d07273c7fc134c
      
https://github.com/qemu/qemu/commit/a2d96af4bb267bd1844f71f593d07273c7fc134c
  Author: Daniel P. Berrange <address@hidden>
  Date:   2016-03-10 (Thu, 10 Mar 2016)

  Changed paths:
    M Makefile
    M include/qemu/sockets.h
    M include/sysemu/os-posix.h
    M include/sysemu/os-win32.h
    M linux-user/flatload.c
    M slirp/slirp.h
    M util/oslib-win32.c

  Log Message:
  -----------
  osdep: add wrappers for socket functions

The windows socket functions look identical to the normal POSIX
sockets functions, but instead of setting errno, the caller needs
to call WSAGetLastError(). QEMU has tried to deal with this
incompatibility by defining a socket_error() method that callers
must use that abstracts the difference between WSAGetLastError()
and errno.

This approach is somewhat error prone though - many callers of
the sockets functions are just using errno directly because it
is easy to forget the need use a QEMU specific wrapper. It is
not always immediately obvious that a particular function will
in fact call into Windows sockets functions, so the dev may not
even realize they need to use socket_error().

This introduces an alternative approach to portability inspired
by the way GNULIB fixes portability problems. We use a macro to
redefine the original socket function names to refer to a QEMU
wrapper function. The wrapper function calls the original Win32
sockets method and then sets errno from the WSAGetLastError()
value.

Thus all code can simply call the normal POSIX sockets APIs are
have standard errno reporting on error, even on Windows. This
makes the socket_error() method obsolete.

We also bring closesocket & ioctlsocket into this approach. Even
though they are non-standard Win32 names, we can't wrap the normal
close/ioctl methods since there's no reliable way to distinguish
between a file descriptor and HANDLE in Win32.

Signed-off-by: Daniel P. Berrange <address@hidden>


  Commit: b16a44e13e89ee397a3d9a9e3cfa1605c3c1dc68
      
https://github.com/qemu/qemu/commit/b16a44e13e89ee397a3d9a9e3cfa1605c3c1dc68
  Author: Daniel P. Berrange <address@hidden>
  Date:   2016-03-10 (Thu, 10 Mar 2016)

  Changed paths:
    M block/sheepdog.c
    M include/sysemu/os-posix.h
    M include/sysemu/os-win32.h
    M io/channel-socket.c
    M migration/qemu-file-unix.c
    M migration/tcp.c
    M net/socket.c
    M slirp/tcp_input.c
    M util/oslib-win32.c
    M util/qemu-coroutine-io.c
    M util/qemu-sockets.c

  Log Message:
  -----------
  osdep: remove use of socket_error() from all code

Now that QEMU wraps the Win32 sockets methods to automatically
set errno upon failure, there is no reason for callers to use
the socket_error() method. They can rely on accessing errno
even on Win32. Remove all use of socket_error() from general
code, leaving it as a static method in oslib-win32.c only.

Signed-off-by: Daniel P. Berrange <address@hidden>


  Commit: 8326ec2c834f7debbba0ed80a433c3ae0cf48289
      
https://github.com/qemu/qemu/commit/8326ec2c834f7debbba0ed80a433c3ae0cf48289
  Author: Peter Maydell <address@hidden>
  Date:   2016-03-14 (Mon, 14 Mar 2016)

  Changed paths:
    M Makefile
    M block/sheepdog.c
    M include/io/channel-watch.h
    M include/io/channel.h
    M include/qemu/sockets.h
    M include/sysemu/os-posix.h
    M include/sysemu/os-win32.h
    M io/channel-command.c
    M io/channel-file.c
    M io/channel-socket.c
    M io/channel-watch.c
    M io/channel.c
    M linux-user/flatload.c
    M migration/qemu-file-unix.c
    M migration/tcp.c
    M net/socket.c
    M qemu-char.c
    M slirp/slirp.h
    M slirp/tcp_input.c
    M tests/io-channel-helpers.c
    M tests/test-io-channel-socket.c
    M util/oslib-win32.c
    M util/qemu-coroutine-io.c
    M util/qemu-sockets.c

  Log Message:
  -----------
  Merge remote-tracking branch 
'remotes/berrange/tags/pull-io-win32-2016-03-11-1' into staging

Merge I/O fixes for win32

# gpg: Signature made Fri 11 Mar 2016 10:03:20 GMT using RSA key ID 15104FDF
# gpg: Good signature from "Daniel P. Berrange <address@hidden>"
# gpg:                 aka "Daniel P. Berrange <address@hidden>"

* remotes/berrange/tags/pull-io-win32-2016-03-11-1:
  osdep: remove use of socket_error() from all code
  osdep: add wrappers for socket functions
  char: remove qemu_chr_open_socket_fd method
  char: remove socket_try_connect method
  char: remove qemu_chr_finish_socket_connection method
  io: implement socket watch for win32 using WSAEventSelect+select
  io: remove checking of EWOULDBLOCK
  io: use qemu_accept to ensure SOCK_CLOEXEC is set
  io: introduce qio_channel_create_socket_watch
  io: pass HANDLE to g_source_add_poll on Win32
  io: fix copy+paste mistake in socket error message
  io: assert errors before asserting content in I/O test
  io: set correct error object in background reader test thread
  io: wait for incoming client in socket test
  io: bind to socket before creating QIOChannelSocket
  io: initialize sockets in test program
  io: use bind() to check for IPv4/6 availability
  osdep: fix socket_error() to work with Mingw64

Signed-off-by: Peter Maydell <address@hidden>


Compare: https://github.com/qemu/qemu/compare/d1ab9681ac54...8326ec2c834f

reply via email to

[Prev in Thread] Current Thread [Next in Thread]