Add HTTP protocol using curl
PATCH 1/1 Add HTTP protocol using curl
Currently Qemu can read from posix I/O and NBD. This patch adds a third protocol to the game: HTTP.
In certain situations it can be useful to access HTTP data directly, for example if you want to try out an http provided OS image, but don't know if you want to download it yet.
Using this patch you can now try it on on the fly. Just use it like:
qemu -cdrom http://host/path/my.iso
In order to not reinvent the wheel, this patch uses libcurl.
Warning:
With stock qemu I do get segmentation faults accessing http backed files, with kvm-userspace's IO threads I don't. I haven't tracked down why exactly that happens though.
--- Makefile | 6 ++ Makefile.target | 2 +- block-http.c | 140 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ block.c | 3 + block.h | 1 + configure | 26 ++++++++++- 6 files changed, 176 insertions(+), 2 deletions(-) create mode 100644 block-http.c
Makefile +6 -0
@@ -64,6 +64,10 @@ endif BLOCK_OBJS += block-raw-posix.o endif +ifdef CONFIG_CURL +BLOCK_OBJS += block-http.o +endif + ###################################################################### # libqemu_common.a: Target independent part of system emulation. The # long term path is to suppress *all* target specific code in case of
@@ -166,6 +170,8 @@ endif LIBS+=$(VDE_LIBS) +LIBS+=$(CURL_LIBS) + cocoa.o: cocoa.m keymaps.o: keymaps.c keymaps.h
Makefile.target +1 -1
@@ -726,7 +726,7 @@ endif vl.o: qemu-options.h -$(QEMU_PROG): LIBS += $(SDL_LIBS) $(COCOA_LIBS) $(CURSES_LIBS) $(BRLAPI_LIBS) $(VDE_LIBS) +$(QEMU_PROG): LIBS += $(SDL_LIBS) $(COCOA_LIBS) $(CURSES_LIBS) $(BRLAPI_LIBS) $(VDE_LIBS) $(CURL_LIBS) $(QEMU_PROG): $(OBJS) ../libqemu_common.a libqemu.a $(LINK)
block-http.c new file +140 -0
140 lines not on this page · raw message
block.c +3 -0
@@ -1539,6 +1539,9 @@ void bdrv_init(void)bdrv_register (&bdrv_qcow2);bdrv_register (&bdrv_parallels);bdrv_register (&bdrv_nbd); +#ifdef CONFIG_CURL +bdrv_register (&bdrv_http); +#endif } void aio_pool_init(AIOPool *pool, int aiocb_size,
block.h +1 -0
@@ -20,6 +20,7 @@ extern BlockDriver bdrv_vvfat;extern BlockDriver bdrv_qcow2;extern BlockDriver bdrv_parallels;extern BlockDriver bdrv_nbd; +extern BlockDriver bdrv_http; typedef struct BlockDriverInfo { /* in bytes, 0 if irrelevant */
configure +25 -0
@@ -180,6 +180,7 @@ bsd_user="no" build_docs="no" uname_release="" curses="yes" +curl="yes" aio="yes" nptl="yes" mixemu="no"
@@ -460,6 +461,8 @@ for opt do ;; --disable-curses) curses="no" ;; + --disable-curl) curl="no" + ;; --disable-nptl) nptl="no" ;; --enable-mixemu) mixemu="yes"
@@ -571,7 +574,8 @@ echo " --enable-mixemu enable mixer emulation" echo " --disable-brlapi disable BrlAPI" echo " --disable-vnc-tls disable TLS encryption for VNC server" echo " --disable-vnc-sasl disable SASL encryption for VNC server" echo " --disable-curses disable curses output" +echo " --disable-curl disable curl connectivity" echo " --disable-bluez disable bluez stack connectivity" echo " --disable-kvm disable KVM acceleration support" echo " --disable-nptl disable usermode NPTL support"
@@ -1010,6 +1013,21 @@ EOF fi # test "$curses" ########################################## +# curl probe + +if test "$curl" = "yes" ; then + curl=no + cat > $TMPC << EOF +#include <curl/curl.h> +int main(void) { return curl_easy_init(); } +EOF + curl_libs=`curl-config --libs` + if $cc $ARCH_CFLAGS $curl_libs -o $TMPE $TMPC > /dev/null 2> /dev/null ; then + curl=yes + fi +fi # test "$curl" + +########################################## # bluez support probe if test "$bluez" = "yes" ; then `pkg-config bluez` || bluez="no"
@@ -1193,6 +1211,7 @@ if test "$sdl" != "no" ; then echo "SDL static link $sdl_static" fi echo "curses support $curses" +echo "curl support $curl" echo "mingw32 support $mingw32" echo "Audio drivers $audio_drv_list" echo "Extra audio cards $audio_card_list"
@@ -1501,6 +1520,11 @@ if test "$curses" = "yes" ; then echo "CONFIG_CURSES=yes" >> $config_mak echo "CURSES_LIBS=-lcurses" >> $config_mak fi +if test "$curl" = "yes" ; then + echo "CONFIG_CURL=yes" >> $config_mak + echo "CURL_LIBS=$curl_libs" >> $config_mak + echo "#define CONFIG_CURL 1" >> $config_h +fi if test "$brlapi" = "yes" ; then echo "CONFIG_BRLAPI=yes" >> $config_mak echo "#define CONFIG_BRLAPI 1" >> $config_h
Signature · 1 line
1.6.0.2
Quoted 7 lines · Alexander Graf
Currently Qemu can read from posix I/O and NBD. This patch adds a third protocol to the game: HTTP.
In certain situations it can be useful to access HTTP data directly, for example if you want to try out an http provided OS image, but don't know if you want to download it yet.
Quoted 6 lines
Using this patch you can now try it on on the fly. Just use it like:
qemu -cdrom http://host/path/my.iso
In order to not reinvent the wheel, this patch uses libcurl.
I have one of these too that reinvents the wheel. The main reason was to enable bdrv_aio_* implementations.
I'm happy to merge a version that uses libcurl but I don't want to merge it unless it's implementing bdrv_aio_. As far as I'm concerned, backends implementing bdrv_read/bdrv_write is deprecated.
Regards,
Anthony Liguori
Quoted 10 lines · Anthony Liguori
Quoted 9 lines · Alexander Graf
Currently Qemu can read from posix I/O and NBD. This patch adds a third protocol to the game: HTTP.
In certain situations it can be useful to access HTTP data directly, for example if you want to try out an http provided OS image, but don't know if you want to download it yet.
Using this patch you can now try it on on the fly. Just use it like:
Quoted 8 lines
Quoted 4 lines
qemu -cdrom http://host/path/my.iso
In order to not reinvent the wheel, this patch uses libcurl.
I have one of these too that reinvents the wheel. The main reason was to enable bdrv_aio_* implementations.
I'm happy to merge a version that uses libcurl but I don't want to merge it unless it's implementing
bdrv_aio_. As far as I'm concerned, backends implementing bdrv_read/bdrv_write is deprecated.
I agree. Libcurl provides means to download asynchronously as well, so AIO is possible with it. I didn't implement it because I needed something quick before I leave for 3 weeks of vacation (today ;-)).
So in case you don't merge it, that's fine. I wanted to improve it next month anyways.
Alex
Quoted 13 lines · Alexander Graf
Currently Qemu can read from posix I/O and NBD. This patch adds a
third protocol to the game: HTTP.In certain situations it can be useful to access HTTP data directly, for example if you want to try out an http provided OS image, but don't know if you want to download it yet.
Using this patch you can now try it on on the fly. Just use it like:
qemu -cdrom http://host/path/my.iso
In order to not reinvent the wheel, this patch uses libcurl.
Quoted 7 lines
Warning:
With stock qemu I do get segmentation faults accessing http backed files, with kvm-userspace's IO threads I don't. I haven't tracked down why exactly that happens though.
Signed-off-by Alexander Graf <[email protected]>
The docs should be updated as well.
Quoted 1 line
+
sprintf(s->range, "%lld-%lld", start, end);
Please use snprintf.