Commit 03ff3ca30f29f422ebfd10d2bee1393efb4d4f7a
1 parent
d9cf1578
Use common objects for qemu-img and qemu-nbd
Right now, we sprinkle #if defined(QEMU_IMG) && defined(QEMU_NBD) all over the code. It's ugly and causes us to have to build multiple object files for linking against qemu and the tools. This patch introduces a new file, qemu-tool.c which contains enough for qemu-img, qemu-nbd, and QEMU to all share the same objects. This also required getting qemu-nbd to be a bit more Windows friendly. I also changed the Windows block-raw to use normal IO instead of overlapping IO since we don't actually do AIO yet on Windows. I changed the various #if 0's to #if WIN32_AIO to make it easier for someone to eventually fix AIO on Windows. After this patch, there are no longer any #ifdef's related to qemu-img and qemu-nbd. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5226 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
11 changed files
with
212 additions
and
177 deletions
Makefile
@@ -28,6 +28,10 @@ ifdef CONFIG_SOLARIS | @@ -28,6 +28,10 @@ ifdef CONFIG_SOLARIS | ||
28 | LIBS+=-lsocket -lnsl -lresolv | 28 | LIBS+=-lsocket -lnsl -lresolv |
29 | endif | 29 | endif |
30 | 30 | ||
31 | +ifdef CONFIG_WIN32 | ||
32 | +LIBS+=-lwinmm -lws2_32 -liphlpapi | ||
33 | +endif | ||
34 | + | ||
31 | all: $(TOOLS) $(DOCS) recurse-all | 35 | all: $(TOOLS) $(DOCS) recurse-all |
32 | 36 | ||
33 | SUBDIR_RULES=$(patsubst %,subdir-%, $(TARGET_DIRS)) | 37 | SUBDIR_RULES=$(patsubst %,subdir-%, $(TARGET_DIRS)) |
@@ -46,9 +50,17 @@ recurse-all: $(SUBDIR_RULES) | @@ -46,9 +50,17 @@ recurse-all: $(SUBDIR_RULES) | ||
46 | BLOCK_OBJS=cutils.o qemu-malloc.o | 50 | BLOCK_OBJS=cutils.o qemu-malloc.o |
47 | BLOCK_OBJS+=block-cow.o block-qcow.o aes.o block-vmdk.o block-cloop.o | 51 | BLOCK_OBJS+=block-cow.o block-qcow.o aes.o block-vmdk.o block-cloop.o |
48 | BLOCK_OBJS+=block-dmg.o block-bochs.o block-vpc.o block-vvfat.o | 52 | BLOCK_OBJS+=block-dmg.o block-bochs.o block-vpc.o block-vvfat.o |
49 | -BLOCK_OBJS+=block-qcow2.o block-parallels.o | ||
50 | -ifndef CONFIG_WIN32 | ||
51 | -BLOCK_OBJS+=block-nbd.o | 53 | +BLOCK_OBJS+=block-qcow2.o block-parallels.o block-nbd.o |
54 | +BLOCK_OBJS+=nbd.o block.o | ||
55 | + | ||
56 | +ifdef CONFIG_WIN32 | ||
57 | +BLOCK_OBJS += block-raw-win32.o | ||
58 | +else | ||
59 | +BLOCK_OBJS += block-raw-posix.o | ||
60 | +endif | ||
61 | + | ||
62 | +ifdef CONFIG_AIO | ||
63 | +BLOCK_OBJS += compatfd.o | ||
52 | endif | 64 | endif |
53 | 65 | ||
54 | ###################################################################### | 66 | ###################################################################### |
@@ -59,11 +71,6 @@ endif | @@ -59,11 +71,6 @@ endif | ||
59 | 71 | ||
60 | OBJS=$(BLOCK_OBJS) | 72 | OBJS=$(BLOCK_OBJS) |
61 | OBJS+=readline.o console.o | 73 | OBJS+=readline.o console.o |
62 | -OBJS+=block.o | ||
63 | - | ||
64 | -ifndef CONFIG_WIN32 | ||
65 | -OBJS+=nbd.o | ||
66 | -endif | ||
67 | 74 | ||
68 | OBJS+=irq.o | 75 | OBJS+=irq.o |
69 | OBJS+=i2c.o smbus.o smbus_eeprom.o max7310.o max111x.o wm8750.o | 76 | OBJS+=i2c.o smbus.o smbus_eeprom.o max7310.o max111x.o wm8750.o |
@@ -173,33 +180,15 @@ libqemu_user.a: $(USER_OBJS) | @@ -173,33 +180,15 @@ libqemu_user.a: $(USER_OBJS) | ||
173 | rm -f $@ | 180 | rm -f $@ |
174 | $(AR) rcs $@ $(USER_OBJS) | 181 | $(AR) rcs $@ $(USER_OBJS) |
175 | 182 | ||
176 | -QEMU_IMG_BLOCK_OBJS = $(BLOCK_OBJS) | ||
177 | -ifdef CONFIG_WIN32 | ||
178 | -QEMU_IMG_BLOCK_OBJS += qemu-img-block-raw-win32.o | ||
179 | -else | ||
180 | -QEMU_IMG_BLOCK_OBJS += nbd.o qemu-img-block-raw-posix.o | ||
181 | -endif | ||
182 | - | ||
183 | -ifdef CONFIG_AIO | ||
184 | -QEMU_IMG_BLOCK_OBJS += compatfd.o | ||
185 | -endif | ||
186 | - | ||
187 | ###################################################################### | 183 | ###################################################################### |
188 | 184 | ||
189 | -qemu-img$(EXESUF): qemu-img.o qemu-img-block.o $(QEMU_IMG_BLOCK_OBJS) | 185 | +qemu-img$(EXESUF): qemu-img.o qemu-tool.o osdep.o $(BLOCK_OBJS) |
190 | $(CC) $(LDFLAGS) -o $@ $^ -lz $(LIBS) | 186 | $(CC) $(LDFLAGS) -o $@ $^ -lz $(LIBS) |
191 | 187 | ||
192 | -qemu-img-%.o: %.c | ||
193 | - $(CC) $(CFLAGS) $(CPPFLAGS) -DQEMU_IMG -c -o $@ $< | ||
194 | - | ||
195 | %.o: %.c | 188 | %.o: %.c |
196 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< | 189 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< |
197 | 190 | ||
198 | -qemu-nbd-%.o: %.c | ||
199 | - $(CC) $(CFLAGS) $(CPPFLAGS) -DQEMU_NBD -c -o $@ $< | ||
200 | - | ||
201 | -qemu-nbd$(EXESUF): qemu-nbd.o qemu-nbd-nbd.o qemu-img-block.o \ | ||
202 | - osdep.o qemu-nbd-block-raw-posix.o compatfd.o $(BLOCK_OBJS) | 191 | +qemu-nbd$(EXESUF): qemu-nbd.o qemu-tool.o osdep.o $(BLOCK_OBJS) |
203 | $(CC) $(LDFLAGS) -o $@ $^ -lz $(LIBS) | 192 | $(CC) $(LDFLAGS) -o $@ $^ -lz $(LIBS) |
204 | 193 | ||
205 | # dyngen host tool | 194 | # dyngen host tool |
block-raw-posix.c
@@ -22,11 +22,8 @@ | @@ -22,11 +22,8 @@ | ||
22 | * THE SOFTWARE. | 22 | * THE SOFTWARE. |
23 | */ | 23 | */ |
24 | #include "qemu-common.h" | 24 | #include "qemu-common.h" |
25 | -#if !defined(QEMU_IMG) && !defined(QEMU_NBD) | ||
26 | #include "qemu-timer.h" | 25 | #include "qemu-timer.h" |
27 | -#include "exec-all.h" | ||
28 | #include "qemu-char.h" | 26 | #include "qemu-char.h" |
29 | -#endif | ||
30 | #include "block_int.h" | 27 | #include "block_int.h" |
31 | #include "compatfd.h" | 28 | #include "compatfd.h" |
32 | #include <assert.h> | 29 | #include <assert.h> |
@@ -70,7 +67,7 @@ | @@ -70,7 +67,7 @@ | ||
70 | //#define DEBUG_FLOPPY | 67 | //#define DEBUG_FLOPPY |
71 | 68 | ||
72 | //#define DEBUG_BLOCK | 69 | //#define DEBUG_BLOCK |
73 | -#if defined(DEBUG_BLOCK) && !defined(QEMU_IMG) && !defined(QEMU_NBD) | 70 | +#if defined(DEBUG_BLOCK) |
74 | #define DEBUG_BLOCK_PRINT(formatCstr, args...) do { if (loglevel != 0) \ | 71 | #define DEBUG_BLOCK_PRINT(formatCstr, args...) do { if (loglevel != 0) \ |
75 | { fprintf(logfile, formatCstr, ##args); fflush(logfile); } } while (0) | 72 | { fprintf(logfile, formatCstr, ##args); fflush(logfile); } } while (0) |
76 | #else | 73 | #else |
@@ -99,7 +96,7 @@ typedef struct BDRVRawState { | @@ -99,7 +96,7 @@ typedef struct BDRVRawState { | ||
99 | int fd_got_error; | 96 | int fd_got_error; |
100 | int fd_media_changed; | 97 | int fd_media_changed; |
101 | #endif | 98 | #endif |
102 | -#if defined(O_DIRECT) && !defined(QEMU_IMG) | 99 | +#if defined(O_DIRECT) |
103 | uint8_t* aligned_buf; | 100 | uint8_t* aligned_buf; |
104 | #endif | 101 | #endif |
105 | } BDRVRawState; | 102 | } BDRVRawState; |
@@ -137,7 +134,7 @@ static int raw_open(BlockDriverState *bs, const char *filename, int flags) | @@ -137,7 +134,7 @@ static int raw_open(BlockDriverState *bs, const char *filename, int flags) | ||
137 | return ret; | 134 | return ret; |
138 | } | 135 | } |
139 | s->fd = fd; | 136 | s->fd = fd; |
140 | -#if defined(O_DIRECT) && !defined(QEMU_IMG) | 137 | +#if defined(O_DIRECT) |
141 | s->aligned_buf = NULL; | 138 | s->aligned_buf = NULL; |
142 | if (flags & BDRV_O_DIRECT) { | 139 | if (flags & BDRV_O_DIRECT) { |
143 | s->aligned_buf = qemu_memalign(512, ALIGNED_BUFFER_SIZE); | 140 | s->aligned_buf = qemu_memalign(512, ALIGNED_BUFFER_SIZE); |
@@ -272,7 +269,7 @@ label__raw_write__success: | @@ -272,7 +269,7 @@ label__raw_write__success: | ||
272 | } | 269 | } |
273 | 270 | ||
274 | 271 | ||
275 | -#if defined(O_DIRECT) && !defined(QEMU_IMG) | 272 | +#if defined(O_DIRECT) |
276 | /* | 273 | /* |
277 | * offset and count are in bytes and possibly not aligned. For files opened | 274 | * offset and count are in bytes and possibly not aligned. For files opened |
278 | * with O_DIRECT, necessary alignments are ensured before calling | 275 | * with O_DIRECT, necessary alignments are ensured before calling |
@@ -525,9 +522,7 @@ void qemu_aio_init(void) | @@ -525,9 +522,7 @@ void qemu_aio_init(void) | ||
525 | 522 | ||
526 | fcntl(aio_sig_fd, F_SETFL, O_NONBLOCK); | 523 | fcntl(aio_sig_fd, F_SETFL, O_NONBLOCK); |
527 | 524 | ||
528 | -#if !defined(QEMU_IMG) && !defined(QEMU_NBD) | ||
529 | qemu_set_fd_handler2(aio_sig_fd, NULL, qemu_aio_poll, NULL, NULL); | 525 | qemu_set_fd_handler2(aio_sig_fd, NULL, qemu_aio_poll, NULL, NULL); |
530 | -#endif | ||
531 | 526 | ||
532 | #if defined(__GLIBC__) && defined(__linux__) | 527 | #if defined(__GLIBC__) && defined(__linux__) |
533 | { | 528 | { |
@@ -556,10 +551,8 @@ void qemu_aio_wait(void) | @@ -556,10 +551,8 @@ void qemu_aio_wait(void) | ||
556 | { | 551 | { |
557 | int ret; | 552 | int ret; |
558 | 553 | ||
559 | -#if !defined(QEMU_IMG) && !defined(QEMU_NBD) | ||
560 | if (qemu_bh_poll()) | 554 | if (qemu_bh_poll()) |
561 | return; | 555 | return; |
562 | -#endif | ||
563 | 556 | ||
564 | if (!first_aio) | 557 | if (!first_aio) |
565 | return; | 558 | return; |
@@ -605,14 +598,12 @@ static RawAIOCB *raw_aio_setup(BlockDriverState *bs, | @@ -605,14 +598,12 @@ static RawAIOCB *raw_aio_setup(BlockDriverState *bs, | ||
605 | return acb; | 598 | return acb; |
606 | } | 599 | } |
607 | 600 | ||
608 | -#if !defined(QEMU_IMG) && !defined(QEMU_NBD) | ||
609 | static void raw_aio_em_cb(void* opaque) | 601 | static void raw_aio_em_cb(void* opaque) |
610 | { | 602 | { |
611 | RawAIOCB *acb = opaque; | 603 | RawAIOCB *acb = opaque; |
612 | acb->common.cb(acb->common.opaque, acb->ret); | 604 | acb->common.cb(acb->common.opaque, acb->ret); |
613 | qemu_aio_release(acb); | 605 | qemu_aio_release(acb); |
614 | } | 606 | } |
615 | -#endif | ||
616 | 607 | ||
617 | static BlockDriverAIOCB *raw_aio_read(BlockDriverState *bs, | 608 | static BlockDriverAIOCB *raw_aio_read(BlockDriverState *bs, |
618 | int64_t sector_num, uint8_t *buf, int nb_sectors, | 609 | int64_t sector_num, uint8_t *buf, int nb_sectors, |
@@ -624,7 +615,7 @@ static BlockDriverAIOCB *raw_aio_read(BlockDriverState *bs, | @@ -624,7 +615,7 @@ static BlockDriverAIOCB *raw_aio_read(BlockDriverState *bs, | ||
624 | * If O_DIRECT is used and the buffer is not aligned fall back | 615 | * If O_DIRECT is used and the buffer is not aligned fall back |
625 | * to synchronous IO. | 616 | * to synchronous IO. |
626 | */ | 617 | */ |
627 | -#if defined(O_DIRECT) && !defined(QEMU_IMG) && !defined(QEMU_NBD) | 618 | +#if defined(O_DIRECT) |
628 | BDRVRawState *s = bs->opaque; | 619 | BDRVRawState *s = bs->opaque; |
629 | 620 | ||
630 | if (unlikely(s->aligned_buf != NULL && ((uintptr_t) buf % 512))) { | 621 | if (unlikely(s->aligned_buf != NULL && ((uintptr_t) buf % 512))) { |
@@ -657,7 +648,7 @@ static BlockDriverAIOCB *raw_aio_write(BlockDriverState *bs, | @@ -657,7 +648,7 @@ static BlockDriverAIOCB *raw_aio_write(BlockDriverState *bs, | ||
657 | * If O_DIRECT is used and the buffer is not aligned fall back | 648 | * If O_DIRECT is used and the buffer is not aligned fall back |
658 | * to synchronous IO. | 649 | * to synchronous IO. |
659 | */ | 650 | */ |
660 | -#if defined(O_DIRECT) && !defined(QEMU_IMG) && !defined(QEMU_NBD) | 651 | +#if defined(O_DIRECT) |
661 | BDRVRawState *s = bs->opaque; | 652 | BDRVRawState *s = bs->opaque; |
662 | 653 | ||
663 | if (unlikely(s->aligned_buf != NULL && ((uintptr_t) buf % 512))) { | 654 | if (unlikely(s->aligned_buf != NULL && ((uintptr_t) buf % 512))) { |
@@ -719,9 +710,7 @@ void qemu_aio_flush(void) | @@ -719,9 +710,7 @@ void qemu_aio_flush(void) | ||
719 | 710 | ||
720 | void qemu_aio_wait(void) | 711 | void qemu_aio_wait(void) |
721 | { | 712 | { |
722 | -#if !defined(QEMU_IMG) && !defined(QEMU_NBD) | ||
723 | qemu_bh_poll(); | 713 | qemu_bh_poll(); |
724 | -#endif | ||
725 | } | 714 | } |
726 | 715 | ||
727 | #endif /* CONFIG_AIO */ | 716 | #endif /* CONFIG_AIO */ |
@@ -732,7 +721,7 @@ static void raw_close(BlockDriverState *bs) | @@ -732,7 +721,7 @@ static void raw_close(BlockDriverState *bs) | ||
732 | if (s->fd >= 0) { | 721 | if (s->fd >= 0) { |
733 | close(s->fd); | 722 | close(s->fd); |
734 | s->fd = -1; | 723 | s->fd = -1; |
735 | -#if defined(O_DIRECT) && !defined(QEMU_IMG) | 724 | +#if defined(O_DIRECT) |
736 | if (s->aligned_buf != NULL) | 725 | if (s->aligned_buf != NULL) |
737 | qemu_free(s->aligned_buf); | 726 | qemu_free(s->aligned_buf); |
738 | #endif | 727 | #endif |
@@ -1002,7 +991,7 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags) | @@ -1002,7 +991,7 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags) | ||
1002 | return 0; | 991 | return 0; |
1003 | } | 992 | } |
1004 | 993 | ||
1005 | -#if defined(__linux__) && !defined(QEMU_IMG) && !defined(QEMU_NBD) | 994 | +#if defined(__linux__) |
1006 | 995 | ||
1007 | /* Note: we do not have a reliable method to detect if the floppy is | 996 | /* Note: we do not have a reliable method to detect if the floppy is |
1008 | present. The current method is to try to open the floppy at every | 997 | present. The current method is to try to open the floppy at every |
@@ -1052,14 +1041,6 @@ static int fd_open(BlockDriverState *bs) | @@ -1052,14 +1041,6 @@ static int fd_open(BlockDriverState *bs) | ||
1052 | s->fd_got_error = 0; | 1041 | s->fd_got_error = 0; |
1053 | return 0; | 1042 | return 0; |
1054 | } | 1043 | } |
1055 | -#else | ||
1056 | -static int fd_open(BlockDriverState *bs) | ||
1057 | -{ | ||
1058 | - return 0; | ||
1059 | -} | ||
1060 | -#endif | ||
1061 | - | ||
1062 | -#if defined(__linux__) | ||
1063 | 1044 | ||
1064 | static int raw_is_inserted(BlockDriverState *bs) | 1045 | static int raw_is_inserted(BlockDriverState *bs) |
1065 | { | 1046 | { |
block-raw-win32.c
@@ -22,14 +22,13 @@ | @@ -22,14 +22,13 @@ | ||
22 | * THE SOFTWARE. | 22 | * THE SOFTWARE. |
23 | */ | 23 | */ |
24 | #include "qemu-common.h" | 24 | #include "qemu-common.h" |
25 | -#ifndef QEMU_IMG | ||
26 | #include "qemu-timer.h" | 25 | #include "qemu-timer.h" |
27 | -#include "exec-all.h" | ||
28 | -#endif | ||
29 | #include "block_int.h" | 26 | #include "block_int.h" |
30 | #include <assert.h> | 27 | #include <assert.h> |
31 | #include <winioctl.h> | 28 | #include <winioctl.h> |
32 | 29 | ||
30 | +//#define WIN32_AIO | ||
31 | + | ||
33 | #define FTYPE_FILE 0 | 32 | #define FTYPE_FILE 0 |
34 | #define FTYPE_CD 1 | 33 | #define FTYPE_CD 1 |
35 | #define FTYPE_HARDDISK 2 | 34 | #define FTYPE_HARDDISK 2 |
@@ -100,10 +99,10 @@ static int raw_open(BlockDriverState *bs, const char *filename, int flags) | @@ -100,10 +99,10 @@ static int raw_open(BlockDriverState *bs, const char *filename, int flags) | ||
100 | } else { | 99 | } else { |
101 | create_flags = OPEN_EXISTING; | 100 | create_flags = OPEN_EXISTING; |
102 | } | 101 | } |
103 | -#ifdef QEMU_IMG | ||
104 | - overlapped = FILE_ATTRIBUTE_NORMAL; | ||
105 | -#else | 102 | +#ifdef WIN32_AIO |
106 | overlapped = FILE_FLAG_OVERLAPPED; | 103 | overlapped = FILE_FLAG_OVERLAPPED; |
104 | +#else | ||
105 | + overlapped = FILE_ATTRIBUTE_NORMAL; | ||
107 | #endif | 106 | #endif |
108 | if (flags & BDRV_O_DIRECT) | 107 | if (flags & BDRV_O_DIRECT) |
109 | overlapped |= FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH; | 108 | overlapped |= FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH; |
@@ -133,10 +132,12 @@ static int raw_pread(BlockDriverState *bs, int64_t offset, | @@ -133,10 +132,12 @@ static int raw_pread(BlockDriverState *bs, int64_t offset, | ||
133 | ov.OffsetHigh = offset >> 32; | 132 | ov.OffsetHigh = offset >> 32; |
134 | ret = ReadFile(s->hfile, buf, count, &ret_count, &ov); | 133 | ret = ReadFile(s->hfile, buf, count, &ret_count, &ov); |
135 | if (!ret) { | 134 | if (!ret) { |
135 | +#ifdef WIN32_AIO | ||
136 | ret = GetOverlappedResult(s->hfile, &ov, &ret_count, TRUE); | 136 | ret = GetOverlappedResult(s->hfile, &ov, &ret_count, TRUE); |
137 | if (!ret) | 137 | if (!ret) |
138 | return -EIO; | 138 | return -EIO; |
139 | else | 139 | else |
140 | +#endif | ||
140 | return ret_count; | 141 | return ret_count; |
141 | } | 142 | } |
142 | return ret_count; | 143 | return ret_count; |
@@ -155,17 +156,18 @@ static int raw_pwrite(BlockDriverState *bs, int64_t offset, | @@ -155,17 +156,18 @@ static int raw_pwrite(BlockDriverState *bs, int64_t offset, | ||
155 | ov.OffsetHigh = offset >> 32; | 156 | ov.OffsetHigh = offset >> 32; |
156 | ret = WriteFile(s->hfile, buf, count, &ret_count, &ov); | 157 | ret = WriteFile(s->hfile, buf, count, &ret_count, &ov); |
157 | if (!ret) { | 158 | if (!ret) { |
159 | +#ifdef WIN32_AIO | ||
158 | ret = GetOverlappedResult(s->hfile, &ov, &ret_count, TRUE); | 160 | ret = GetOverlappedResult(s->hfile, &ov, &ret_count, TRUE); |
159 | if (!ret) | 161 | if (!ret) |
160 | return -EIO; | 162 | return -EIO; |
161 | else | 163 | else |
164 | +#endif | ||
162 | return ret_count; | 165 | return ret_count; |
163 | } | 166 | } |
164 | return ret_count; | 167 | return ret_count; |
165 | } | 168 | } |
166 | 169 | ||
167 | -#if 0 | ||
168 | -#ifndef QEMU_IMG | 170 | +#ifdef WIN32_AIO |
169 | static void raw_aio_cb(void *opaque) | 171 | static void raw_aio_cb(void *opaque) |
170 | { | 172 | { |
171 | RawAIOCB *acb = opaque; | 173 | RawAIOCB *acb = opaque; |
@@ -181,7 +183,6 @@ static void raw_aio_cb(void *opaque) | @@ -181,7 +183,6 @@ static void raw_aio_cb(void *opaque) | ||
181 | acb->common.cb(acb->common.opaque, 0); | 183 | acb->common.cb(acb->common.opaque, 0); |
182 | } | 184 | } |
183 | } | 185 | } |
184 | -#endif | ||
185 | 186 | ||
186 | static RawAIOCB *raw_aio_setup(BlockDriverState *bs, | 187 | static RawAIOCB *raw_aio_setup(BlockDriverState *bs, |
187 | int64_t sector_num, uint8_t *buf, int nb_sectors, | 188 | int64_t sector_num, uint8_t *buf, int nb_sectors, |
@@ -204,9 +205,7 @@ static RawAIOCB *raw_aio_setup(BlockDriverState *bs, | @@ -204,9 +205,7 @@ static RawAIOCB *raw_aio_setup(BlockDriverState *bs, | ||
204 | acb->ov.OffsetHigh = offset >> 32; | 205 | acb->ov.OffsetHigh = offset >> 32; |
205 | acb->ov.hEvent = acb->hEvent; | 206 | acb->ov.hEvent = acb->hEvent; |
206 | acb->count = nb_sectors * 512; | 207 | acb->count = nb_sectors * 512; |
207 | -#ifndef QEMU_IMG | ||
208 | qemu_add_wait_object(acb->ov.hEvent, raw_aio_cb, acb); | 208 | qemu_add_wait_object(acb->ov.hEvent, raw_aio_cb, acb); |
209 | -#endif | ||
210 | return acb; | 209 | return acb; |
211 | } | 210 | } |
212 | 211 | ||
@@ -226,9 +225,7 @@ static BlockDriverAIOCB *raw_aio_read(BlockDriverState *bs, | @@ -226,9 +225,7 @@ static BlockDriverAIOCB *raw_aio_read(BlockDriverState *bs, | ||
226 | qemu_aio_release(acb); | 225 | qemu_aio_release(acb); |
227 | return NULL; | 226 | return NULL; |
228 | } | 227 | } |
229 | -#ifdef QEMU_IMG | ||
230 | qemu_aio_release(acb); | 228 | qemu_aio_release(acb); |
231 | -#endif | ||
232 | return (BlockDriverAIOCB *)acb; | 229 | return (BlockDriverAIOCB *)acb; |
233 | } | 230 | } |
234 | 231 | ||
@@ -248,15 +245,12 @@ static BlockDriverAIOCB *raw_aio_write(BlockDriverState *bs, | @@ -248,15 +245,12 @@ static BlockDriverAIOCB *raw_aio_write(BlockDriverState *bs, | ||
248 | qemu_aio_release(acb); | 245 | qemu_aio_release(acb); |
249 | return NULL; | 246 | return NULL; |
250 | } | 247 | } |
251 | -#ifdef QEMU_IMG | ||
252 | qemu_aio_release(acb); | 248 | qemu_aio_release(acb); |
253 | -#endif | ||
254 | return (BlockDriverAIOCB *)acb; | 249 | return (BlockDriverAIOCB *)acb; |
255 | } | 250 | } |
256 | 251 | ||
257 | static void raw_aio_cancel(BlockDriverAIOCB *blockacb) | 252 | static void raw_aio_cancel(BlockDriverAIOCB *blockacb) |
258 | { | 253 | { |
259 | -#ifndef QEMU_IMG | ||
260 | RawAIOCB *acb = (RawAIOCB *)blockacb; | 254 | RawAIOCB *acb = (RawAIOCB *)blockacb; |
261 | BlockDriverState *bs = acb->common.bs; | 255 | BlockDriverState *bs = acb->common.bs; |
262 | BDRVRawState *s = bs->opaque; | 256 | BDRVRawState *s = bs->opaque; |
@@ -265,9 +259,8 @@ static void raw_aio_cancel(BlockDriverAIOCB *blockacb) | @@ -265,9 +259,8 @@ static void raw_aio_cancel(BlockDriverAIOCB *blockacb) | ||
265 | /* XXX: if more than one async I/O it is not correct */ | 259 | /* XXX: if more than one async I/O it is not correct */ |
266 | CancelIo(s->hfile); | 260 | CancelIo(s->hfile); |
267 | qemu_aio_release(acb); | 261 | qemu_aio_release(acb); |
268 | -#endif | ||
269 | } | 262 | } |
270 | -#endif /* #if 0 */ | 263 | +#endif /* #if WIN32_AIO */ |
271 | 264 | ||
272 | static void raw_flush(BlockDriverState *bs) | 265 | static void raw_flush(BlockDriverState *bs) |
273 | { | 266 | { |
@@ -356,9 +349,7 @@ void qemu_aio_flush(void) | @@ -356,9 +349,7 @@ void qemu_aio_flush(void) | ||
356 | 349 | ||
357 | void qemu_aio_wait(void) | 350 | void qemu_aio_wait(void) |
358 | { | 351 | { |
359 | -#ifndef QEMU_IMG | ||
360 | qemu_bh_poll(); | 352 | qemu_bh_poll(); |
361 | -#endif | ||
362 | } | 353 | } |
363 | 354 | ||
364 | BlockDriver bdrv_raw = { | 355 | BlockDriver bdrv_raw = { |
@@ -372,7 +363,7 @@ BlockDriver bdrv_raw = { | @@ -372,7 +363,7 @@ BlockDriver bdrv_raw = { | ||
372 | raw_create, | 363 | raw_create, |
373 | raw_flush, | 364 | raw_flush, |
374 | 365 | ||
375 | -#if 0 | 366 | +#ifdef WIN32_AIO |
376 | .bdrv_aio_read = raw_aio_read, | 367 | .bdrv_aio_read = raw_aio_read, |
377 | .bdrv_aio_write = raw_aio_write, | 368 | .bdrv_aio_write = raw_aio_write, |
378 | .bdrv_aio_cancel = raw_aio_cancel, | 369 | .bdrv_aio_cancel = raw_aio_cancel, |
@@ -458,10 +449,10 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags) | @@ -458,10 +449,10 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags) | ||
458 | } | 449 | } |
459 | create_flags = OPEN_EXISTING; | 450 | create_flags = OPEN_EXISTING; |
460 | 451 | ||
461 | -#ifdef QEMU_IMG | ||
462 | - overlapped = FILE_ATTRIBUTE_NORMAL; | ||
463 | -#else | 452 | +#ifdef WIN32_AIO |
464 | overlapped = FILE_FLAG_OVERLAPPED; | 453 | overlapped = FILE_FLAG_OVERLAPPED; |
454 | +#else | ||
455 | + overlapped = FILE_ATTRIBUTE_NORMAL; | ||
465 | #endif | 456 | #endif |
466 | if (flags & BDRV_O_DIRECT) | 457 | if (flags & BDRV_O_DIRECT) |
467 | overlapped |= FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH; | 458 | overlapped |= FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH; |
@@ -524,7 +515,7 @@ BlockDriver bdrv_host_device = { | @@ -524,7 +515,7 @@ BlockDriver bdrv_host_device = { | ||
524 | NULL, | 515 | NULL, |
525 | raw_flush, | 516 | raw_flush, |
526 | 517 | ||
527 | -#if 0 | 518 | +#ifdef WIN32_AIO |
528 | .bdrv_aio_read = raw_aio_read, | 519 | .bdrv_aio_read = raw_aio_read, |
529 | .bdrv_aio_write = raw_aio_write, | 520 | .bdrv_aio_write = raw_aio_write, |
530 | .bdrv_aio_cancel = raw_aio_cancel, | 521 | .bdrv_aio_cancel = raw_aio_cancel, |
block.c
@@ -22,9 +22,7 @@ | @@ -22,9 +22,7 @@ | ||
22 | * THE SOFTWARE. | 22 | * THE SOFTWARE. |
23 | */ | 23 | */ |
24 | #include "qemu-common.h" | 24 | #include "qemu-common.h" |
25 | -#ifndef QEMU_IMG | ||
26 | #include "console.h" | 25 | #include "console.h" |
27 | -#endif | ||
28 | #include "block_int.h" | 26 | #include "block_int.h" |
29 | 27 | ||
30 | #ifdef _BSD | 28 | #ifdef _BSD |
@@ -922,7 +920,6 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, | @@ -922,7 +920,6 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, | ||
922 | return bs->drv->bdrv_is_allocated(bs, sector_num, nb_sectors, pnum); | 920 | return bs->drv->bdrv_is_allocated(bs, sector_num, nb_sectors, pnum); |
923 | } | 921 | } |
924 | 922 | ||
925 | -#ifndef QEMU_IMG | ||
926 | void bdrv_info(void) | 923 | void bdrv_info(void) |
927 | { | 924 | { |
928 | BlockDriverState *bs; | 925 | BlockDriverState *bs; |
@@ -980,7 +977,6 @@ void bdrv_info_stats (void) | @@ -980,7 +977,6 @@ void bdrv_info_stats (void) | ||
980 | bs->rd_ops, bs->wr_ops); | 977 | bs->rd_ops, bs->wr_ops); |
981 | } | 978 | } |
982 | } | 979 | } |
983 | -#endif | ||
984 | 980 | ||
985 | void bdrv_get_backing_filename(BlockDriverState *bs, | 981 | void bdrv_get_backing_filename(BlockDriverState *bs, |
986 | char *filename, int filename_size) | 982 | char *filename, int filename_size) |
@@ -1203,31 +1199,6 @@ void bdrv_aio_cancel(BlockDriverAIOCB *acb) | @@ -1203,31 +1199,6 @@ void bdrv_aio_cancel(BlockDriverAIOCB *acb) | ||
1203 | /**************************************************************/ | 1199 | /**************************************************************/ |
1204 | /* async block device emulation */ | 1200 | /* async block device emulation */ |
1205 | 1201 | ||
1206 | -#ifdef QEMU_IMG | ||
1207 | -static BlockDriverAIOCB *bdrv_aio_read_em(BlockDriverState *bs, | ||
1208 | - int64_t sector_num, uint8_t *buf, int nb_sectors, | ||
1209 | - BlockDriverCompletionFunc *cb, void *opaque) | ||
1210 | -{ | ||
1211 | - int ret; | ||
1212 | - ret = bdrv_read(bs, sector_num, buf, nb_sectors); | ||
1213 | - cb(opaque, ret); | ||
1214 | - return NULL; | ||
1215 | -} | ||
1216 | - | ||
1217 | -static BlockDriverAIOCB *bdrv_aio_write_em(BlockDriverState *bs, | ||
1218 | - int64_t sector_num, const uint8_t *buf, int nb_sectors, | ||
1219 | - BlockDriverCompletionFunc *cb, void *opaque) | ||
1220 | -{ | ||
1221 | - int ret; | ||
1222 | - ret = bdrv_write(bs, sector_num, buf, nb_sectors); | ||
1223 | - cb(opaque, ret); | ||
1224 | - return NULL; | ||
1225 | -} | ||
1226 | - | ||
1227 | -static void bdrv_aio_cancel_em(BlockDriverAIOCB *acb) | ||
1228 | -{ | ||
1229 | -} | ||
1230 | -#else | ||
1231 | static void bdrv_aio_bh_cb(void *opaque) | 1202 | static void bdrv_aio_bh_cb(void *opaque) |
1232 | { | 1203 | { |
1233 | BlockDriverAIOCBSync *acb = opaque; | 1204 | BlockDriverAIOCBSync *acb = opaque; |
@@ -1273,7 +1244,6 @@ static void bdrv_aio_cancel_em(BlockDriverAIOCB *blockacb) | @@ -1273,7 +1244,6 @@ static void bdrv_aio_cancel_em(BlockDriverAIOCB *blockacb) | ||
1273 | qemu_bh_cancel(acb->bh); | 1244 | qemu_bh_cancel(acb->bh); |
1274 | qemu_aio_release(acb); | 1245 | qemu_aio_release(acb); |
1275 | } | 1246 | } |
1276 | -#endif /* !QEMU_IMG */ | ||
1277 | 1247 | ||
1278 | /**************************************************************/ | 1248 | /**************************************************************/ |
1279 | /* sync block device emulation */ | 1249 | /* sync block device emulation */ |
@@ -1337,9 +1307,7 @@ void bdrv_init(void) | @@ -1337,9 +1307,7 @@ void bdrv_init(void) | ||
1337 | bdrv_register(&bdrv_vvfat); | 1307 | bdrv_register(&bdrv_vvfat); |
1338 | bdrv_register(&bdrv_qcow2); | 1308 | bdrv_register(&bdrv_qcow2); |
1339 | bdrv_register(&bdrv_parallels); | 1309 | bdrv_register(&bdrv_parallels); |
1340 | -#ifndef _WIN32 | ||
1341 | bdrv_register(&bdrv_nbd); | 1310 | bdrv_register(&bdrv_nbd); |
1342 | -#endif | ||
1343 | 1311 | ||
1344 | qemu_aio_init(); | 1312 | qemu_aio_init(); |
1345 | } | 1313 | } |
block.h
@@ -47,10 +47,8 @@ typedef struct QEMUSnapshotInfo { | @@ -47,10 +47,8 @@ typedef struct QEMUSnapshotInfo { | ||
47 | bdrv_file_open()) */ | 47 | bdrv_file_open()) */ |
48 | #define BDRV_O_DIRECT 0x0020 | 48 | #define BDRV_O_DIRECT 0x0020 |
49 | 49 | ||
50 | -#ifndef QEMU_IMG | ||
51 | void bdrv_info(void); | 50 | void bdrv_info(void); |
52 | void bdrv_info_stats(void); | 51 | void bdrv_info_stats(void); |
53 | -#endif | ||
54 | 52 | ||
55 | void bdrv_init(void); | 53 | void bdrv_init(void); |
56 | BlockDriver *bdrv_find_format(const char *format_name); | 54 | BlockDriver *bdrv_find_format(const char *format_name); |
nbd.c
@@ -21,28 +21,27 @@ | @@ -21,28 +21,27 @@ | ||
21 | 21 | ||
22 | #include <errno.h> | 22 | #include <errno.h> |
23 | #include <string.h> | 23 | #include <string.h> |
24 | +#ifndef _WIN32 | ||
24 | #include <sys/ioctl.h> | 25 | #include <sys/ioctl.h> |
26 | +#endif | ||
25 | #ifdef __sun__ | 27 | #ifdef __sun__ |
26 | #include <sys/ioccom.h> | 28 | #include <sys/ioccom.h> |
27 | #endif | 29 | #endif |
28 | #include <ctype.h> | 30 | #include <ctype.h> |
29 | #include <inttypes.h> | 31 | #include <inttypes.h> |
30 | -#include <sys/socket.h> | ||
31 | -#include <sys/un.h> | ||
32 | -#include <netinet/in.h> | ||
33 | -#include <netinet/tcp.h> | ||
34 | -#include <arpa/inet.h> | ||
35 | -#include <netdb.h> | ||
36 | - | ||
37 | -#if defined(QEMU_NBD) | ||
38 | -extern int verbose; | ||
39 | -#else | ||
40 | -static int verbose = 0; | ||
41 | -#endif | ||
42 | 32 | ||
33 | +#include "qemu_socket.h" | ||
34 | + | ||
35 | +//#define DEBUG_NBD | ||
36 | + | ||
37 | +#ifdef DEBUG_NBD | ||
43 | #define TRACE(msg, ...) do { \ | 38 | #define TRACE(msg, ...) do { \ |
44 | - if (verbose) LOG(msg, ## __VA_ARGS__); \ | 39 | + LOG(msg, ## __VA_ARGS__); \ |
45 | } while(0) | 40 | } while(0) |
41 | +#else | ||
42 | +#define TRACE(msg, ...) \ | ||
43 | + do { } while (0) | ||
44 | +#endif | ||
46 | 45 | ||
47 | #define LOG(msg, ...) do { \ | 46 | #define LOG(msg, ...) do { \ |
48 | fprintf(stderr, "%s:%s():L%d: " msg "\n", \ | 47 | fprintf(stderr, "%s:%s():L%d: " msg "\n", \ |
@@ -77,11 +76,14 @@ size_t nbd_wr_sync(int fd, void *buffer, size_t size, bool do_read) | @@ -77,11 +76,14 @@ size_t nbd_wr_sync(int fd, void *buffer, size_t size, bool do_read) | ||
77 | ssize_t len; | 76 | ssize_t len; |
78 | 77 | ||
79 | if (do_read) { | 78 | if (do_read) { |
80 | - len = read(fd, buffer + offset, size - offset); | 79 | + len = recv(fd, buffer + offset, size - offset, 0); |
81 | } else { | 80 | } else { |
82 | - len = write(fd, buffer + offset, size - offset); | 81 | + len = send(fd, buffer + offset, size - offset, 0); |
83 | } | 82 | } |
84 | 83 | ||
84 | + if (len == -1) | ||
85 | + errno = socket_error(); | ||
86 | + | ||
85 | /* recoverable error */ | 87 | /* recoverable error */ |
86 | if (len == -1 && (errno == EAGAIN || errno == EINTR)) { | 88 | if (len == -1 && (errno == EAGAIN || errno == EINTR)) { |
87 | continue; | 89 | continue; |
@@ -108,7 +110,6 @@ int tcp_socket_outgoing(const char *address, uint16_t port) | @@ -108,7 +110,6 @@ int tcp_socket_outgoing(const char *address, uint16_t port) | ||
108 | int s; | 110 | int s; |
109 | struct in_addr in; | 111 | struct in_addr in; |
110 | struct sockaddr_in addr; | 112 | struct sockaddr_in addr; |
111 | - int serrno; | ||
112 | 113 | ||
113 | s = socket(PF_INET, SOCK_STREAM, 0); | 114 | s = socket(PF_INET, SOCK_STREAM, 0); |
114 | if (s == -1) { | 115 | if (s == -1) { |
@@ -136,9 +137,7 @@ int tcp_socket_outgoing(const char *address, uint16_t port) | @@ -136,9 +137,7 @@ int tcp_socket_outgoing(const char *address, uint16_t port) | ||
136 | 137 | ||
137 | return s; | 138 | return s; |
138 | error: | 139 | error: |
139 | - serrno = errno; | ||
140 | - close(s); | ||
141 | - errno = serrno; | 140 | + closesocket(s); |
142 | return -1; | 141 | return -1; |
143 | } | 142 | } |
144 | 143 | ||
@@ -147,7 +146,6 @@ int tcp_socket_incoming(const char *address, uint16_t port) | @@ -147,7 +146,6 @@ int tcp_socket_incoming(const char *address, uint16_t port) | ||
147 | int s; | 146 | int s; |
148 | struct in_addr in; | 147 | struct in_addr in; |
149 | struct sockaddr_in addr; | 148 | struct sockaddr_in addr; |
150 | - int serrno; | ||
151 | int opt; | 149 | int opt; |
152 | 150 | ||
153 | s = socket(PF_INET, SOCK_STREAM, 0); | 151 | s = socket(PF_INET, SOCK_STREAM, 0); |
@@ -185,17 +183,15 @@ int tcp_socket_incoming(const char *address, uint16_t port) | @@ -185,17 +183,15 @@ int tcp_socket_incoming(const char *address, uint16_t port) | ||
185 | 183 | ||
186 | return s; | 184 | return s; |
187 | error: | 185 | error: |
188 | - serrno = errno; | ||
189 | - close(s); | ||
190 | - errno = serrno; | 186 | + closesocket(s); |
191 | return -1; | 187 | return -1; |
192 | } | 188 | } |
193 | 189 | ||
190 | +#ifndef _WIN32 | ||
194 | int unix_socket_incoming(const char *path) | 191 | int unix_socket_incoming(const char *path) |
195 | { | 192 | { |
196 | int s; | 193 | int s; |
197 | struct sockaddr_un addr; | 194 | struct sockaddr_un addr; |
198 | - int serrno; | ||
199 | 195 | ||
200 | s = socket(PF_UNIX, SOCK_STREAM, 0); | 196 | s = socket(PF_UNIX, SOCK_STREAM, 0); |
201 | if (s == -1) { | 197 | if (s == -1) { |
@@ -216,9 +212,7 @@ int unix_socket_incoming(const char *path) | @@ -216,9 +212,7 @@ int unix_socket_incoming(const char *path) | ||
216 | 212 | ||
217 | return s; | 213 | return s; |
218 | error: | 214 | error: |
219 | - serrno = errno; | ||
220 | - close(s); | ||
221 | - errno = serrno; | 215 | + closesocket(s); |
222 | return -1; | 216 | return -1; |
223 | } | 217 | } |
224 | 218 | ||
@@ -226,7 +220,6 @@ int unix_socket_outgoing(const char *path) | @@ -226,7 +220,6 @@ int unix_socket_outgoing(const char *path) | ||
226 | { | 220 | { |
227 | int s; | 221 | int s; |
228 | struct sockaddr_un addr; | 222 | struct sockaddr_un addr; |
229 | - int serrno; | ||
230 | 223 | ||
231 | s = socket(PF_UNIX, SOCK_STREAM, 0); | 224 | s = socket(PF_UNIX, SOCK_STREAM, 0); |
232 | if (s == -1) { | 225 | if (s == -1) { |
@@ -243,12 +236,23 @@ int unix_socket_outgoing(const char *path) | @@ -243,12 +236,23 @@ int unix_socket_outgoing(const char *path) | ||
243 | 236 | ||
244 | return s; | 237 | return s; |
245 | error: | 238 | error: |
246 | - serrno = errno; | ||
247 | - close(s); | ||
248 | - errno = serrno; | 239 | + closesocket(s); |
240 | + return -1; | ||
241 | +} | ||
242 | +#else | ||
243 | +int unix_socket_incoming(const char *path) | ||
244 | +{ | ||
245 | + errno = ENOTSUP; | ||
249 | return -1; | 246 | return -1; |
250 | } | 247 | } |
251 | 248 | ||
249 | +int unix_socket_outgoing(const char *path) | ||
250 | +{ | ||
251 | + errno = ENOTSUP; | ||
252 | + return -1; | ||
253 | +} | ||
254 | +#endif | ||
255 | + | ||
252 | 256 | ||
253 | /* Basic flow | 257 | /* Basic flow |
254 | 258 | ||
@@ -337,6 +341,7 @@ int nbd_receive_negotiate(int csock, off_t *size, size_t *blocksize) | @@ -337,6 +341,7 @@ int nbd_receive_negotiate(int csock, off_t *size, size_t *blocksize) | ||
337 | return 0; | 341 | return 0; |
338 | } | 342 | } |
339 | 343 | ||
344 | +#ifndef _WIN32 | ||
340 | int nbd_init(int fd, int csock, off_t size, size_t blocksize) | 345 | int nbd_init(int fd, int csock, off_t size, size_t blocksize) |
341 | { | 346 | { |
342 | TRACE("Setting block size to %lu", (unsigned long)blocksize); | 347 | TRACE("Setting block size to %lu", (unsigned long)blocksize); |
@@ -410,6 +415,25 @@ int nbd_client(int fd, int csock) | @@ -410,6 +415,25 @@ int nbd_client(int fd, int csock) | ||
410 | errno = serrno; | 415 | errno = serrno; |
411 | return ret; | 416 | return ret; |
412 | } | 417 | } |
418 | +#else | ||
419 | +int nbd_init(int fd, int csock, off_t size, size_t blocksize) | ||
420 | +{ | ||
421 | + errno = ENOTSUP; | ||
422 | + return -1; | ||
423 | +} | ||
424 | + | ||
425 | +int nbd_disconnect(int fd) | ||
426 | +{ | ||
427 | + errno = ENOTSUP; | ||
428 | + return -1; | ||
429 | +} | ||
430 | + | ||
431 | +int nbd_client(int fd, int csock) | ||
432 | +{ | ||
433 | + errno = ENOTSUP; | ||
434 | + return -1; | ||
435 | +} | ||
436 | +#endif | ||
413 | 437 | ||
414 | int nbd_send_request(int csock, struct nbd_request *request) | 438 | int nbd_send_request(int csock, struct nbd_request *request) |
415 | { | 439 | { |
osdep.c
@@ -45,6 +45,8 @@ | @@ -45,6 +45,8 @@ | ||
45 | #include <malloc.h> | 45 | #include <malloc.h> |
46 | #endif | 46 | #endif |
47 | 47 | ||
48 | +#include "qemu_socket.h" | ||
49 | + | ||
48 | #if defined(_WIN32) | 50 | #if defined(_WIN32) |
49 | void *qemu_memalign(size_t alignment, size_t size) | 51 | void *qemu_memalign(size_t alignment, size_t size) |
50 | { | 52 | { |
@@ -283,3 +285,28 @@ int qemu_gettimeofday(qemu_timeval *tp) | @@ -283,3 +285,28 @@ int qemu_gettimeofday(qemu_timeval *tp) | ||
283 | return 0; | 285 | return 0; |
284 | } | 286 | } |
285 | #endif /* _WIN32 */ | 287 | #endif /* _WIN32 */ |
288 | + | ||
289 | + | ||
290 | +#ifdef _WIN32 | ||
291 | +void socket_set_nonblock(int fd) | ||
292 | +{ | ||
293 | + unsigned long opt = 1; | ||
294 | + ioctlsocket(fd, FIONBIO, &opt); | ||
295 | +} | ||
296 | + | ||
297 | +int inet_aton(const char *cp, struct in_addr *ia) | ||
298 | +{ | ||
299 | + uint32_t addr = inet_addr(cp); | ||
300 | + if (addr == 0xffffffff) | ||
301 | + return 0; | ||
302 | + ia->s_addr = addr; | ||
303 | + return 1; | ||
304 | +} | ||
305 | +#else | ||
306 | +void socket_set_nonblock(int fd) | ||
307 | +{ | ||
308 | + int f; | ||
309 | + f = fcntl(fd, F_GETFL); | ||
310 | + fcntl(fd, F_SETFL, f | O_NONBLOCK); | ||
311 | +} | ||
312 | +#endif |
qemu-tool.c
0 โ 100644
1 | +/* | ||
2 | + * Compatibility for qemu-img/qemu-nbd | ||
3 | + * | ||
4 | + * Copyright IBM, Corp. 2008 | ||
5 | + * | ||
6 | + * Authors: | ||
7 | + * Anthony Liguori <aliguori@us.ibm.com> | ||
8 | + * | ||
9 | + * This work is licensed under the terms of the GNU GPL, version 2. See | ||
10 | + * the COPYING file in the top-level directory. | ||
11 | + * | ||
12 | + */ | ||
13 | + | ||
14 | +#include "qemu-common.h" | ||
15 | +#include "console.h" | ||
16 | +#include "sysemu.h" | ||
17 | +#include "qemu-timer.h" | ||
18 | + | ||
19 | +#include <sys/time.h> | ||
20 | + | ||
21 | +QEMUClock *rt_clock; | ||
22 | + | ||
23 | +struct QEMUBH | ||
24 | +{ | ||
25 | + QEMUBHFunc *cb; | ||
26 | + void *opaque; | ||
27 | +}; | ||
28 | + | ||
29 | +void term_printf(const char *fmt, ...) | ||
30 | +{ | ||
31 | +} | ||
32 | + | ||
33 | +void term_print_filename(const char *filename) | ||
34 | +{ | ||
35 | +} | ||
36 | + | ||
37 | +QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque) | ||
38 | +{ | ||
39 | + QEMUBH *bh; | ||
40 | + | ||
41 | + bh = qemu_malloc(sizeof(*bh)); | ||
42 | + if (bh) { | ||
43 | + bh->cb = cb; | ||
44 | + bh->opaque = opaque; | ||
45 | + } | ||
46 | + | ||
47 | + return bh; | ||
48 | +} | ||
49 | + | ||
50 | +int qemu_bh_poll(void) | ||
51 | +{ | ||
52 | + return 0; | ||
53 | +} | ||
54 | + | ||
55 | +void qemu_bh_schedule(QEMUBH *bh) | ||
56 | +{ | ||
57 | + bh->cb(bh->opaque); | ||
58 | +} | ||
59 | + | ||
60 | +void qemu_bh_cancel(QEMUBH *bh) | ||
61 | +{ | ||
62 | +} | ||
63 | + | ||
64 | +void qemu_bh_delete(QEMUBH *bh) | ||
65 | +{ | ||
66 | + qemu_free(bh); | ||
67 | +} | ||
68 | + | ||
69 | +int qemu_set_fd_handler2(int fd, | ||
70 | + IOCanRWHandler *fd_read_poll, | ||
71 | + IOHandler *fd_read, | ||
72 | + IOHandler *fd_write, | ||
73 | + void *opaque) | ||
74 | +{ | ||
75 | + return 0; | ||
76 | +} | ||
77 | + | ||
78 | +int64_t qemu_get_clock(QEMUClock *clock) | ||
79 | +{ | ||
80 | + struct timeval tv; | ||
81 | + gettimeofday(&tv, NULL); | ||
82 | + return (tv.tv_sec * 1000000000LL + (tv.tv_usec * 1000)) / 1000000; | ||
83 | +} |
qemu_socket.h
@@ -14,11 +14,15 @@ | @@ -14,11 +14,15 @@ | ||
14 | #define EINTR WSAEINTR | 14 | #define EINTR WSAEINTR |
15 | #define EINPROGRESS WSAEINPROGRESS | 15 | #define EINPROGRESS WSAEINPROGRESS |
16 | 16 | ||
17 | +int inet_aton(const char *cp, struct in_addr *ia); | ||
18 | + | ||
17 | #else | 19 | #else |
18 | 20 | ||
19 | #include <sys/socket.h> | 21 | #include <sys/socket.h> |
20 | #include <netinet/in.h> | 22 | #include <netinet/in.h> |
21 | #include <netinet/tcp.h> | 23 | #include <netinet/tcp.h> |
24 | +#include <arpa/inet.h> | ||
25 | +#include <netdb.h> | ||
22 | #include <sys/un.h> | 26 | #include <sys/un.h> |
23 | 27 | ||
24 | #define socket_error() errno | 28 | #define socket_error() errno |
slirp/misc.c
@@ -66,20 +66,6 @@ redir_x(inaddr, start_port, display, screen) | @@ -66,20 +66,6 @@ redir_x(inaddr, start_port, display, screen) | ||
66 | } | 66 | } |
67 | #endif | 67 | #endif |
68 | 68 | ||
69 | -#ifndef HAVE_INET_ATON | ||
70 | -int | ||
71 | -inet_aton(cp, ia) | ||
72 | - const char *cp; | ||
73 | - struct in_addr *ia; | ||
74 | -{ | ||
75 | - u_int32_t addr = inet_addr(cp); | ||
76 | - if (addr == 0xffffffff) | ||
77 | - return 0; | ||
78 | - ia->s_addr = addr; | ||
79 | - return 1; | ||
80 | -} | ||
81 | -#endif | ||
82 | - | ||
83 | /* | 69 | /* |
84 | * Get our IP address and put it in our_addr | 70 | * Get our IP address and put it in our_addr |
85 | */ | 71 | */ |
vl.c
@@ -100,11 +100,10 @@ | @@ -100,11 +100,10 @@ | ||
100 | #include <stropts.h> | 100 | #include <stropts.h> |
101 | #endif | 101 | #endif |
102 | #endif | 102 | #endif |
103 | -#else | ||
104 | -#include <winsock2.h> | ||
105 | -int inet_aton(const char *cp, struct in_addr *ia); | ||
106 | #endif | 103 | #endif |
107 | 104 | ||
105 | +#include "qemu_socket.h" | ||
106 | + | ||
108 | #if defined(CONFIG_SLIRP) | 107 | #if defined(CONFIG_SLIRP) |
109 | #include "libslirp.h" | 108 | #include "libslirp.h" |
110 | #endif | 109 | #endif |
@@ -125,8 +124,6 @@ int inet_aton(const char *cp, struct in_addr *ia); | @@ -125,8 +124,6 @@ int inet_aton(const char *cp, struct in_addr *ia); | ||
125 | #define memalign(align, size) malloc(size) | 124 | #define memalign(align, size) malloc(size) |
126 | #endif | 125 | #endif |
127 | 126 | ||
128 | -#include "qemu_socket.h" | ||
129 | - | ||
130 | #ifdef CONFIG_SDL | 127 | #ifdef CONFIG_SDL |
131 | #ifdef __APPLE__ | 128 | #ifdef __APPLE__ |
132 | #include <SDL/SDL.h> | 129 | #include <SDL/SDL.h> |
@@ -2133,12 +2130,6 @@ static int send_all(int fd, const uint8_t *buf, int len1) | @@ -2133,12 +2130,6 @@ static int send_all(int fd, const uint8_t *buf, int len1) | ||
2133 | return len1 - len; | 2130 | return len1 - len; |
2134 | } | 2131 | } |
2135 | 2132 | ||
2136 | -void socket_set_nonblock(int fd) | ||
2137 | -{ | ||
2138 | - unsigned long opt = 1; | ||
2139 | - ioctlsocket(fd, FIONBIO, &opt); | ||
2140 | -} | ||
2141 | - | ||
2142 | #else | 2133 | #else |
2143 | 2134 | ||
2144 | static int unix_write(int fd, const uint8_t *buf, int len1) | 2135 | static int unix_write(int fd, const uint8_t *buf, int len1) |
@@ -2165,13 +2156,6 @@ static inline int send_all(int fd, const uint8_t *buf, int len1) | @@ -2165,13 +2156,6 @@ static inline int send_all(int fd, const uint8_t *buf, int len1) | ||
2165 | { | 2156 | { |
2166 | return unix_write(fd, buf, len1); | 2157 | return unix_write(fd, buf, len1); |
2167 | } | 2158 | } |
2168 | - | ||
2169 | -void socket_set_nonblock(int fd) | ||
2170 | -{ | ||
2171 | - int f; | ||
2172 | - f = fcntl(fd, F_GETFL); | ||
2173 | - fcntl(fd, F_SETFL, f | O_NONBLOCK); | ||
2174 | -} | ||
2175 | #endif /* !_WIN32 */ | 2159 | #endif /* !_WIN32 */ |
2176 | 2160 | ||
2177 | #ifndef _WIN32 | 2161 | #ifndef _WIN32 |