summaryrefslogtreecommitdiffstats
path: root/qemu-sockets.c
Commit message (Collapse)AuthorAgeFilesLines
* misc: move include files to include/qemu/Paolo Bonzini2012-12-191-2/+2
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* monitor: move include files to include/monitor/Paolo Bonzini2012-12-191-1/+1
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* use qemu_opts_create_nofailDong Xu Wang2012-12-111-8/+8
| | | | | | | | We will use qemu_opts_create_nofail function, it can make code more readable. Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* qemu-sockets: Fix parsing of the inet option 'to'.Anthony PERARD2012-11-211-2/+3
| | | | | | | | | Having a qemu command line argument like "-vnc 127.0.0.1:0,to=99" is broken. This have been break with commit 879e45c72da1569e07fbbc6a1aa2a708ea796044. Signed-off-by: Anthony PERARD <anthony.perard@citrix.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: malc <av1474@comtv.ru>
* build: replace weak symbols with a static libraryPaolo Bonzini2012-11-181-22/+0Star
| | | | | | | | | | | | | | | | | | | | | | Weak symbols were a nice idea, but they turned out not to be a good one. Toolchain support is just too sparse, in particular llvm-gcc is totally broken. This patch uses a surprisingly low-tech approach: a static library. Symbols in a static library are always overridden by symbols in an object file. Furthermore, if you place each function in a separate source file, object files for unused functions will not be taken in. This means that each function can use all the dependencies that it needs (especially QAPI stuff such as error_setg). Thus, all stubs are placed in separate object files and put together in a static library. The library then is linked to all programs. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Tested-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Tested-by: Stefan Weil <sw@weilnetz.de> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* compiler: support Darwin weak referencesPaolo Bonzini2012-11-021-18/+22
| | | | | | | | | | | Weakrefs only tell you if the symbol was defined elsewhere, so you need a further check at runtime to pick the default definition when needed. This could be automated by the compiler, but it does not do it. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* iohandler: add weak alias in qemu-sockets.c, for qemu-gaPaolo Bonzini2012-10-301-0/+11
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* sockets: use weak aliases instead of qemu-tool.cPaolo Bonzini2012-10-301-0/+7
| | | | | | | | qemu-tool.c has its own (largeish) set of dependencies. Weak aliases can be placed directly where people use them, and do not contribute to increasing the dependencies of generic utility files. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-sockets: add socket_listen, socket_connect, socket_parsePaolo Bonzini2012-10-231-0/+99
| | | | | | | | | These are QAPI-friendly versions of the qemu-sockets functions. They support IP sockets, Unix sockets, and named file descriptors, using a QAPI union to dispatch to the correct function. Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-sockets: return InetSocketAddress from inet_parsePaolo Bonzini2012-10-231-42/+79
| | | | | Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-sockets: add error propagation to Unix socket functionsPaolo Bonzini2012-10-231-8/+8
| | | | | | | | | | | | | | | | | Before: $ qemu-system-x86_64 -monitor unix:/vvv,server=off connect(unix:/vvv): No such file or directory chardev: opening backend "socket" failed After: $ x86_64-softmmu/qemu-system-x86_64 -monitor unix:/vvv,server=off qemu-system-x86_64: -monitor unix:/vvv,server=off: Failed to connect to socket: No such file or directory chardev: opening backend "socket" failed Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-sockets: add error propagation to inet_parsePaolo Bonzini2012-10-231-20/+21
| | | | | Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-sockets: add error propagation to inet_dgram_optsPaolo Bonzini2012-10-231-26/+8Star
| | | | | | | | | | | | | | | | | | Before: $ qemu-system-x86_64 -monitor udp:localhost:631@localhost:631 inet_dgram_opts: bind(ipv4,127.0.0.1,631): OK inet_dgram_opts failed chardev: opening backend "udp" failed After: $ x86_64-softmmu/qemu-system-x86_64 -monitor udp:localhost:631@localhost:631 qemu-system-x86_64: -monitor udp:localhost:631@localhost:631: Failed to bind socket: Address already in use chardev: opening backend "udp" failed Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-sockets: add error propagation to inet_connect_addrPaolo Bonzini2012-10-231-9/+6Star
| | | | | | | | | | | | | | | perror and fprintf can be removed because all clients can now consume Errors properly. However, we'll need to change the non-blocking connect handlers to take an Error, in order to improve error handling for migration with the TCP protocol. This is a minor degradation in error reporting for outgoing migration. However, until 1.2 this case just failed without even attempting to connect, so it is still an improvement as far as overall QoI is concerned. Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-sockets: include strerror or gai_strerror output in error messagesPaolo Bonzini2012-10-231-21/+9Star
| | | | | | | | | | | | | | | | | | | | Among others, before: $ qemu-system-x86_64 -chardev socket,port=12345,id=char inet_connect: host and/or port not specified chardev: opening backend "socket" failed After: $ x86_64-softmmu/qemu-system-x86_64 -chardev socket,port=12345,id=char qemu-system-x86_64: -chardev socket,port=12345,id=char: host and/or port not specified chardev: opening backend "socket" failed perror and fprintf can be removed because all clients can now consume Errors properly. Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-sockets: add nonblocking connect for Unix socketsPaolo Bonzini2012-10-231-13/+64
| | | | | | | | This patch mostly mimics what was done to TCP sockets, but simpler because there is only one address to try. It also includes a free EINTR bug fix. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-sockets: unix_listen and unix_connect are portablePaolo Bonzini2012-10-231-32/+17Star
| | | | | | | They are just wrappers and do not need a Win32-specific version. Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-sockets: add Error ** to all functionsPaolo Bonzini2012-10-231-11/+11
| | | | | | | | This lets me adjust the clients to do proper error propagation first, thus avoiding temporary regressions in the quality of the error messages. Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* cleanup useless return sentenceAmos Kong2012-10-051-1/+0Star
| | | | | | | | This patch cleans up return sentences in the end of void functions. Reported-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Amos Kong <akong@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
* qemu-sockets: Fix compiler warning (regression for MinGW)Stefan Weil2012-10-051-1/+1
| | | | | | | | | | | | | | | setsockopt needs a type cast for MinGW. That type cast is missing in a recent commit which results in a compiler warning. Like for other socket related functions which have the same problem, we add a 'qemu_setsockopt' macro which provides that type cast where needed and use the new macro to avoid the warning. A 'qemu_getsockopt' is also added and can be used for future modifications. Signed-off-by: Stefan Weil <sw@weilnetz.de> Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
* Fix address handling in inet_nonblocking_connectOrit Wasserman2012-09-261-24/+105
| | | | | | | | | | | | | | | | | getaddrinfo can give us a list of addresses, but we only try to connect to the first one. If that fails we never proceed to the next one. This is common on desktop setups that often have ipv6 configured but not actually working. To fix this make inet_connect_nonblocking retry connection with a different address. callers on inet_nonblocking_connect register a callback function that will be called when connect opertion completes, in case of failure the fd will have a negative value Signed-off-by: Orit Wasserman <owasserm@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* Separate inet_connect into inet_connect (blocking) and inet_nonblocking_connectOrit Wasserman2012-09-261-10/+48
| | | | | | | | No need to add non blocking parameters to the blocking inet_connect add block parameter for inet_connect_opts instead of using QemuOpt "block". Signed-off-by: Orit Wasserman <owasserm@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* Refactor inet_connect_opts functionMichael S. Tsirkin2012-09-261-63/+85
| | | | | | | | | | refactor address resolution code to fix nonblocking connect remove getnameinfo call Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Amos Kong <akong@redhat.com> Signed-off-by: Orit Wasserman <owasserm@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* qemu-sockets: Fix potential memory leakStefan Weil2012-09-231-1/+1
| | | | | | | The old code leaks variable 'peer'. Signed-off-by: Stefan Weil <sw@weilnetz.de> Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
* migration: don't rely on any QERR_SOCKET_*Luiz Capitulino2012-08-131-2/+0Star
| | | | | | | | | | | | | | | | | | | | | | | Use the in_progress argument for QERR_SOCKET_CONNECT_IN_PROGRESS. The other errors are handled the same by checking if the error is set and then calling migrate_fd_error() if it's. It's also necessary to change inet_connect_opts() not to set QERR_SOCKET_CONNECT_IN_PROGRESS. This error is only used by tcp_start_outgoing_migration() and not changing it along with the usage of in_progress would break migration. Furthermore this commit fixes a bug. Today, there's a spurious error report when migration succeeds: (qemu) migrate tcp:0:4444 migrate: Connection can not be completed immediately (qemu) After this commit no spurious error is reported anymore. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com>
* net: inet_connect(), inet_connect_opts(): add in_progress argumentLuiz Capitulino2012-08-131-3/+11
| | | | | | | | | | | | It's used to indicate the special case where a valid file-descriptor is returned (ie. success) but the connection can't be completed w/o blocking. This is needed because QERR_SOCKET_CONNECT_IN_PROGRESS is not treated like an error and a future commit will drop it. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com>
* socket: clean up redundant assignmentAmos Kong2012-08-031-1/+0Star
| | | | | Signed-off-by: Amos Kong <akong@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
* place qemu-sockets.c contributions since 2012-01-13 under GPLv2+Paolo Bonzini2012-07-291-0/+3
| | | | | | | | | Past contributions since 2012-01-13 were only made by Red Hat people, so they are already available under GPLv2+. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Stefan Weil <sw@weilnetz.de> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* qemu-option: qemu_opts_create(): use error_set()Luiz Capitulino2012-06-041-4/+4
| | | | | | | | | | | | | | | | | | | | | | | This commit converts qemu_opts_create() from qerror_report() to error_set(). Currently, most calls to qemu_opts_create() can't fail, so most callers don't need any changes. The two cases where code checks for qemu_opts_create() erros are: 1. Initialization code in vl.c. All of them print their own error messages directly to stderr, no need to pass the Error object 2. The functions opts_parse(), qemu_opts_from_qdict() and qemu_chr_parse_compat() make use of the error information and they can be called from HMP or QMP. In this case, to allow for incremental conversion, we propagate the error up using qerror_report_err(), which keeps the QError semantics Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Reviewed-By: Laszlo Ersek <lersek@redhat.com>
* sockets: use error class to pass listen errorAmos Kong2012-05-101-3/+14
| | | | | | | | | | | | Add a new argument in inet_listen()/inet_listen_opts() to pass back listen error. Change nbd, qemu-char, vnc to use new interface. Signed-off-by: Amos Kong <akong@redhat.com> Reviewed-by: Orit Wasserman <owasserm@redhat.com> Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* sockets: change inet_connect() to support nonblock socketAmos Kong2012-05-101-6/+37
| | | | | | | | | | | | | | | | | | | | | | Add a bool argument to inet_connect() to assign if set socket to block/nonblock, and delete original argument 'socktype' that is unused. Add a new argument to inet_connect()/inet_connect_opts(), to pass back connect error by error class. Retry to connect when -EINTR is got. Connect's successful for nonblock socket when following errors are got, user should wait for connecting by select(): -EINPROGRESS -EWOULDBLOCK (win32) -WSAEALREADY (win32) Change nbd, vnc to use new interface. Signed-off-by: Amos Kong <akong@redhat.com> Reviewed-by: Orit Wasserman <owasserm@redhat.com> Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* sockets: Clean up inet_listen_opts()'s convoluted bind() loopMarkus Armbruster2012-02-241-8/+6Star
| | | | | Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* sockets: Drop sockets_debug debug codeMarkus Armbruster2012-02-241-41/+2Star
| | | | | | | | | | | | | I'm trying to improve this code's error reporting, and the debug code is getting in my way: it clutters the code, it clobbers errno in inconvenient places, and it uses the same fprintf() both for error reporting and debug output in a few places. Get rid of it. Once decent error reporting is in place, adding back whatever debug code we need shouldn't be hard. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* qemu-sockets: Plug fd leak on unix_connect_opts() error pathMarkus Armbruster2011-11-111-0/+1
| | | | | | | Spotted by Coverity. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* Use glib memory allocation and free functionsAnthony Liguori2011-08-211-2/+2
| | | | | | qemu_malloc/qemu_free no longer exist after this commit. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* Set errno=ENOTSUP for attempts to use UNIX sockets on Windows platformsNick Thomas2011-04-071-0/+4
| | | | | Signed-off-by: Nick Thomas <nick@bytemark.co.uk> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* qemu-sockets: avoid strlen of NULL pointerJens Osterkamp2010-05-181-1/+2
| | | | | | | | | | If the user wants to create a chardev of type socket but forgets to give a host= option, qemu_opt_get returns NULL. This NULL pointer is then fed into strlen a few lines below without a check which results in a segfault. This fixes it. Signed-off-by: Jens Osterkamp <jens@linux.vnet.ibm.com> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
* move socket_init to qemu-sockets.cPaolo Bonzini2010-04-091-0/+24
| | | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
* fix inet_parse typoMarcelo Tosatti2010-02-101-4/+4
| | | | | | | qemu_opt_set wants on/off, not yes/no. Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* net: inet_strfamily(): Better unknown family reportLuiz Capitulino2010-01-201-1/+1
| | | | | | | Returning "????" is a bit meaningless, let's call it "unknown". Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* net: Make inet_strfamily() publicLuiz Capitulino2010-01-201-1/+1
| | | | | | | So that it can be used by other subsystems. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* Don't leak file descriptorsKevin Wolf2009-12-031-5/+5
| | | | | | | | We're leaking file descriptors to child processes. Set FD_CLOEXEC on file descriptors that don't need to be passed to children to stop this misbehaviour. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* Add 'static'Blue Swirl2009-09-121-1/+1
| | | | Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* Fix sys-queue.h conflict for goodBlue Swirl2009-09-121-1/+1
| | | | | | | | | | | | | | | Problem: Our file sys-queue.h is a copy of the BSD file, but there are some additions and it's not entirely compatible. Because of that, there have been conflicts with system headers on BSD systems. Some hacks have been introduced in the commits 15cc9235840a22c289edbe064a9b3c19c5f49896, f40d753718c72693c5f520f0d9899f6e50395e94, 96555a96d724016e13190b28cffa3bc929ac60dc and 3990d09adf4463eca200ad964cc55643c33feb50 but the fixes were fragile. Solution: Avoid the conflict entirely by renaming the functions and the file. Revert the previous hacks. Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* convert udp chardev to QemuOpts.Gerd Hoffmann2009-09-111-0/+114
| | | | | | | | | | | | While being at it: create a new inet_dgram_opts() function for udp setup, so udp can handle IPv6 now. new cmd line syntax: -chardev udp,id=name,host=remotehost,port=remoteport,\ localaddr=bindaddr,localport=bindport Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* sockets: add inet_listen_optsGerd Hoffmann2009-09-111-55/+48Star
| | | | | | | | | Add inet_listen_opts(). Does the same as inet_listen(), but uses QemuOpts. inet_listen() is a compatibility wrapper for inet_listen_opts() now and should go away some day. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* sockets: add inet_connect_optsGerd Hoffmann2009-09-111-33/+96
| | | | | | | | | Add inet_connect_opts(). Does the same as inet_connect(), but uses QemuOpts. inet_connect() is a compatibility wrapper for inet_connect_opts() now and should go away some day. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* sockets: add unix_*_opts for windows.Gerd Hoffmann2009-09-111-0/+12
| | | | | | | Add unix_*_opts function dummys for windows. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* sockets: add unix_listen_optsGerd Hoffmann2009-09-111-14/+33
| | | | | | | | | Add unix_listen_opts(). Does the same as unix_listen(), but uses QemuOpts. unix_listen() is a compatibility wrapper for unix_listen_opts() now and should go away some day. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* sockets: add unix_connect_optsGerd Hoffmann2009-09-111-1/+33
| | | | | | | | | Add unix_connect_opts(). Does the same as unix_connect(), but uses QemuOpts. unix_connect() is a compatibility wrapper for unix_connect_opts() now and should go away some day. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>