qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Filip Navara" <xnavara@volny.cz>
To: qemu-devel@nongnu.org
Cc: Laurent Vivier <Laurent.Vivier@bull.net>,
	chenqing <chenqing@nsfocus.com>
Subject: Re: [Qemu-devel] [PATCH] Fix compilation of nbd on Windows
Date: Sat, 5 Jul 2008 13:58:08 +0200	[thread overview]
Message-ID: <5b31733c0807050458w41aebd89re70cc859602c3681@mail.gmail.com> (raw)
In-Reply-To: <alpine.DEB.1.00.0807042300550.9925@racer>

Closing sockets with "close" doesn't work on WinSock. Add "#define
close closesocket" to the top of file to fix it. Otherwise, good job!

Best regards,
Filip Navara

On Sat, Jul 5, 2008 at 12:02 AM, Johannes Schindelin
<Johannes.Schindelin@gmx.de> wrote:
>
> This still only supports the client side, and only the TCP version of
> it, since Windows does not have Unix sockets.
>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
>
>        This is only compile-tested, since I can only work in an emulated
>        environment.
>
>        Oh, and feel free to reorder nbd.h so that it has only one
>        #ifndef..#endif.
>
>        If I find some time next week, I might try to actually compile
>        qemu-nbd and get it to run on Windows.
>
>  Makefile    |    1 +
>  block-nbd.c |   11 ++++++++++-
>  nbd.c       |   36 +++++++++++++++++++++++++++++++++++-
>  nbd.h       |    6 ++++++
>  4 files changed, 52 insertions(+), 2 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index adb36c6..ef55952 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -70,6 +70,7 @@ endif
>
>  ifdef CONFIG_WIN32
>  OBJS+=tap-win32.o
> +LIBS+= -lws2_32
>  endif
>
>  AUDIO_OBJS = audio.o noaudio.o wavaudio.o mixeng.o
> diff --git a/block-nbd.c b/block-nbd.c
> index f350050..a2adbde 100644
> --- a/block-nbd.c
> +++ b/block-nbd.c
> @@ -31,11 +31,17 @@
>
>  #include <sys/types.h>
>  #include <unistd.h>
> +#ifdef _WIN32
> +#include <windows.h>
> +#include <winsock2.h>
> +#include <ws2tcpip.h>
> +#else
>  #include <sys/socket.h>
>  #include <sys/un.h>
>  #include <netinet/in.h>
>  #include <arpa/inet.h>
>  #include <pthread.h>
> +#endif
>
>  typedef struct BDRVNBDState {
>     int sock;
> @@ -61,11 +67,14 @@ static int nbd_open(BlockDriverState *bs, const char* filename, int flags)
>
>     if (strstart(host, "unix:", &unixpath)) {
>
> +#ifdef _WIN32
> +       return -EINVAL;
> +#else
>         if (unixpath[0] != '/')
>             return -EINVAL;
>
>         sock = unix_socket_outgoing(unixpath);
> -
> +#endif
>     } else {
>         uint16_t port;
>         char *p, *r;
> diff --git a/nbd.c b/nbd.c
> index e9308ee..d783cd0 100644
> --- a/nbd.c
> +++ b/nbd.c
> @@ -21,15 +21,45 @@
>
>  #include <errno.h>
>  #include <string.h>
> -#include <sys/ioctl.h>
>  #include <ctype.h>
>  #include <inttypes.h>
> +#ifdef _WIN32
> +#include <windows.h>
> +#include <winsock2.h>
> +#include <ws2tcpip.h>
> +
> +#define socket_error() WSAGetLastError()
> +#undef EAGAIN
> +#undef EINTR
> +#undef EINVAL
> +#define EAGAIN WSAEWOULDBLOCK
> +#define EINTR WSAEINTR
> +#define EINVAL WSAEINVAL
> +
> +static inline int inet_aton(const char *cp, struct in_addr *inp)
> +{
> +       unsigned long result = inet_addr(cp);
> +       if (result == INADDR_NONE)
> +               return 0;
> +       inp->s_addr = result;
> +       return 1;
> +}
> +
> +static inline int mingw_setsockopt(int s, int level, int optname,
> +               const void *optval, socklen_t optlen)
> +{
> +       return setsockopt(s, level, optname, (const char *)optval, optlen);
> +}
> +#define setsockopt mingw_setsockopt
> +#else
> +#include <sys/ioctl.h>
>  #include <sys/socket.h>
>  #include <sys/un.h>
>  #include <netinet/in.h>
>  #include <netinet/tcp.h>
>  #include <arpa/inet.h>
>  #include <netdb.h>
> +#endif
>
>  #if defined(QEMU_NBD)
>  extern int verbose;
> @@ -188,6 +218,7 @@ error:
>     return -1;
>  }
>
> +#ifndef _WIN32
>  int unix_socket_incoming(const char *path)
>  {
>     int s;
> @@ -245,6 +276,7 @@ error:
>     errno = serrno;
>     return -1;
>  }
> +#endif
>
>
>  /* Basic flow
> @@ -334,6 +366,7 @@ int nbd_receive_negotiate(int csock, off_t *size, size_t *blocksize)
>         return 0;
>  }
>
> +#ifndef _WIN32
>  int nbd_init(int fd, int csock, off_t size, size_t blocksize)
>  {
>        TRACE("Setting block size to %lu", (unsigned long)blocksize);
> @@ -407,6 +440,7 @@ int nbd_client(int fd, int csock)
>        errno = serrno;
>        return ret;
>  }
> +#endif
>
>  int nbd_send_request(int csock, struct nbd_request *request)
>  {
> diff --git a/nbd.h b/nbd.h
> index 55ba1ba..387246d 100644
> --- a/nbd.h
> +++ b/nbd.h
> @@ -47,17 +47,23 @@ enum {
>  size_t nbd_wr_sync(int fd, void *buffer, size_t size, bool do_read);
>  int tcp_socket_outgoing(const char *address, uint16_t port);
>  int tcp_socket_incoming(const char *address, uint16_t port);
> +#ifndef _WIN32
>  int unix_socket_outgoing(const char *path);
>  int unix_socket_incoming(const char *path);
> +#endif
>
>  int nbd_negotiate(BlockDriverState *bs, int csock, off_t size);
>  int nbd_receive_negotiate(int csock, off_t *size, size_t *blocksize);
> +#ifndef _WIN32
>  int nbd_init(int fd, int csock, off_t size, size_t blocksize);
> +#endif
>  int nbd_send_request(int csock, struct nbd_request *request);
>  int nbd_receive_reply(int csock, struct nbd_reply *reply);
>  int nbd_trip(BlockDriverState *bs, int csock, off_t size, uint64_t dev_offset,
>              off_t *offset, bool readonly, uint8_t *data, int data_size);
> +#ifndef _WIN32
>  int nbd_client(int fd, int csock);
>  int nbd_disconnect(int fd);
> +#endif
>
>  #endif
> --
> 1.5.6.1.376.g6b0fd
>
>
>
>
>

  reply	other threads:[~2008-07-05 17:07 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-03 13:41 [Qemu-devel] [4838] Allow QEMU to connect directly to an NBD server, by Laurent Vivier Thiemo Seufer
2008-07-04  1:33 ` chenqing
2008-07-04  2:34   ` Thiemo Seufer
2008-07-04  3:51     ` chenqing
2008-07-04  8:42       ` Laurent Vivier
2008-07-04 20:32         ` Thiemo Seufer
2008-07-04 20:52           ` Johannes Schindelin
2008-07-04 22:02             ` [Qemu-devel] [PATCH] Fix compilation of nbd on Windows Johannes Schindelin
2008-07-05 11:58               ` Filip Navara [this message]
2008-07-05 22:41                 ` Jamie Lokier
2008-07-06  1:51                   ` Johannes Schindelin
2008-07-06 16:49                     ` Jamie Lokier
2008-07-06 17:23                       ` Johannes Schindelin
2008-07-08 19:22               ` Anthony Liguori
2008-07-09  0:14                 ` Johannes Schindelin
2008-07-18 14:24                   ` [Qemu-devel] " Sebastian Herbszt
2008-07-18 15:26                     ` Johannes Schindelin
2008-08-02 19:21               ` [Qemu-devel] [PATCH v2] " Johannes Schindelin
2008-08-03 17:11                 ` Anthony Liguori
2008-08-03 17:32                   ` Johannes Schindelin
2008-08-03 20:42                     ` Anthony Liguori
2008-08-03 20:58                       ` Johannes Schindelin
2008-08-03 21:09                         ` Anthony Liguori
2008-08-03 21:30                           ` Johannes Schindelin
2008-08-04 13:29                       ` Jamie Lokier
2008-08-04 16:49                         ` Thiemo Seufer
2008-08-03 21:21                     ` Anthony Liguori
2008-08-03 21:37                       ` Johannes Schindelin
2008-08-04 13:23                         ` Jamie Lokier
2008-08-03 21:57                     ` Andreas Färber
2008-07-04  8:01     ` [Qemu-devel] [4838] Allow QEMU to connect directly to an NBD server, by Laurent Vivier Laurent Vivier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5b31733c0807050458w41aebd89re70cc859602c3681@mail.gmail.com \
    --to=xnavara@volny.cz \
    --cc=Laurent.Vivier@bull.net \
    --cc=chenqing@nsfocus.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).