[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2] Fix compilation of nbd on Windows
From: |
Johannes Schindelin |
Subject: |
[Qemu-devel] [PATCH v2] Fix compilation of nbd on Windows |
Date: |
Sat, 2 Aug 2008 21:21:24 +0200 (CEST) |
User-agent: |
Alpine 1.00 (DEB 882 2007-12-20) |
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 <address@hidden>
---
This is still untested; that is the job of Windows users.
At least it compiles.
Makefile | 1 +
block-nbd.c | 10 +++++++---
nbd.c | 31 +++++++++++++++++++------------
nbd.h | 6 ++++++
qemu_socket.h | 18 ++++++++++++++++++
5 files changed, 51 insertions(+), 15 deletions(-)
diff --git a/Makefile b/Makefile
index 0472e16..cf5501f 100644
--- a/Makefile
+++ b/Makefile
@@ -75,6 +75,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 88b6199..7cdbb7c 100644
--- a/block-nbd.c
+++ b/block-nbd.c
@@ -31,11 +31,12 @@
#include <sys/types.h>
#include <unistd.h>
-#include <sys/socket.h>
+#include "qemu_socket.h"
+#ifndef WIN32
#include <sys/un.h>
-#include <netinet/in.h>
#include <arpa/inet.h>
#include <pthread.h>
+#endif
typedef struct BDRVNBDState {
int sock;
@@ -61,11 +62,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 9bebe4a..b334f15 100644
--- a/nbd.c
+++ b/nbd.c
@@ -21,18 +21,18 @@
#include <errno.h>
#include <string.h>
+#include <ctype.h>
+#include <inttypes.h>
+#include "qemu_socket.h"
+#ifndef _WIN32
#include <sys/ioctl.h>
#ifdef __sun__
#include <sys/ioccom.h>
#endif
-#include <ctype.h>
-#include <inttypes.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;
@@ -83,7 +83,8 @@ size_t nbd_wr_sync(int fd, void *buffer, size_t size, bool
do_read)
}
/* recoverable error */
- if (len == -1 && (errno == EAGAIN || errno == EINTR)) {
+ if (len == -1 && (socket_error() == EAGAIN ||
+ socket_error() == EINTR)) {
continue;
}
@@ -112,6 +113,7 @@ int tcp_socket_outgoing(const char *address, uint16_t port)
s = socket(PF_INET, SOCK_STREAM, 0);
if (s == -1) {
+ errno = socket_error();
return -1;
}
@@ -136,8 +138,8 @@ int tcp_socket_outgoing(const char *address, uint16_t port)
return s;
error:
- serrno = errno;
- close(s);
+ serrno = socket_error();
+ closesocket(s);
errno = serrno;
return -1;
}
@@ -152,6 +154,7 @@ int tcp_socket_incoming(const char *address, uint16_t port)
s = socket(PF_INET, SOCK_STREAM, 0);
if (s == -1) {
+ errno = socket_error();
return -1;
}
@@ -185,12 +188,13 @@ int tcp_socket_incoming(const char *address, uint16_t
port)
return s;
error:
- serrno = errno;
- close(s);
+ serrno = socket_error();
+ closesocket(s);
errno = serrno;
return -1;
}
+#ifndef _WIN32
int unix_socket_incoming(const char *path)
{
int s;
@@ -217,7 +221,7 @@ int unix_socket_incoming(const char *path)
return s;
error:
serrno = errno;
- close(s);
+ closesocket(s);
errno = serrno;
return -1;
}
@@ -244,10 +248,11 @@ int unix_socket_outgoing(const char *path)
return s;
error:
serrno = errno;
- close(s);
+ closesocket(s);
errno = serrno;
return -1;
}
+#endif
/* Basic flow
@@ -337,6 +342,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);
@@ -410,6 +416,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
diff --git a/qemu_socket.h b/qemu_socket.h
index 5229c24..73e05d8 100644
--- a/qemu_socket.h
+++ b/qemu_socket.h
@@ -10,9 +10,27 @@
#define socket_error() WSAGetLastError()
#undef EINTR
+#undef EINVAL
#define EWOULDBLOCK WSAEWOULDBLOCK
#define EINTR WSAEINTR
#define EINPROGRESS WSAEINPROGRESS
+#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
--
1.6.0.rc1.70.g91e1d