Skip to contentSkip to conversation

Add HTTP protocol using curl v2

PATCH In review [email protected] 7 participants 35 messages May 6, 2009 – May 8, 2009 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add HTTP protocol using curl v2

From: Alexander Graf <[email protected]>

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.

v2 changes:

- fix the segfault (yay!)
- implement AIO

I am still missing caching completely, so if you're accessing a WAN server it'll be rather slow. Also, a lot of small partial accesses will clutter the server's logs which is not ideal.

I'm open to suggestions on how to implement caching. I was thinking of a model similar to -snapshot, but invoked from within the http backend, with the option to write the file to a real file too, so you can use qemu as download application while already using the image.

I haven't thought out resuming downloads for that one yet though :-/. Maybe scanning the download file for sparse spots and force download those chunks?

Again, I'm open to suggestions :-). The patch as is is rather useful already though as long as you stay in a LAN (or have a really fast internet connection).

Also please give me ideas on how and where to put this feature in the docs.

---
 Makefile        |    6 +
 Makefile.target |    2 +-
 block-http.c    |  381 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 block.c         |    3 +
 block.h         |    1 +
 configure       |   25 ++++
 6 files changed, 417 insertions(+), 1 deletions(-)
 create mode 100644 block-http.c
Makefile +6 -0
index 3c70068..fbfbc6e 100644
@@ -77,6 +77,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
@@ -185,6 +189,8 @@ endif
 
 LIBS+=$(VDE_LIBS)
 
+LIBS+=$(CURL_LIBS)
+
 cocoa.o: cocoa.m
 
 keymaps.o: keymaps.c keymaps.h
Makefile.target +1 -1
index f735105..3a9226c 100644
@@ -735,7 +735,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 +381 -0

381 lines not on this page · raw message

block.c +3 -0
index 3d1223d..76a8d86 100644
@@ -1504,6 +1504,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
index 5aef076..ebff06d 100644
@@ -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
index 82fb60a..49b5b84 100755
@@ -181,6 +181,7 @@ bsd_user="no"
 build_docs="no"
 uname_release=""
 curses="yes"
+curl="yes"
 pthread="yes"
 aio="yes"
 io_thread="no"
@@ -477,6 +478,8 @@ for opt do
   ;;
   --disable-curses) curses="no"
   ;;
+  --disable-curl) curl="no"
+  ;;
   --disable-nptl) nptl="no"
   ;;
   --enable-mixemu) mixemu="yes"
@@ -600,6 +603,7 @@ 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"
@@ -1062,6 +1066,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 2> /dev/null` || bluez="no"
@@ -1311,6 +1330,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"
@@ -1637,6 +1657,11 @@ fi
 if test "$inotify" = "yes" ; then
   echo "#define CONFIG_INOTIFY 1" >> $config_h
 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
#1 lore raw
Quoted 5 lines · On Wed, May 06, 2009 at 03:00:50AM +0200, [email protected] wrote:

From: Alexander Graf <[email protected]>

Currently Qemu can read from posix I/O and NBD. This patch adds a third protocol to the game: HTTP.

Quoted 7 lines

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

I rather think there should be an explicit flag to allow use of http://
URLs in filenames at runtime, not just 'configure' time. There are many apps out there using QEMU which will be assuming QEMU treats all disk paths as local files, and thus not got explicit code to check whether a URI is passed. I could well see that some will consider it a security issue to allow QEMU to download off the net, but if they updated to a new QEMU with this patch, downloading would be allowed by default.

Perhaps only enable these remote URIs with the -drive parameter, when an explicit fmt=http option is set. But can this be layered into the other protocols, eg could the remote URI be in qcow, vmdk, etc formats, or are you assuming the remote uri is raw file ?

Daniel

Signature · 4 lines
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
#2 lore raw
Quoted 14 lines · Daniel P. Berrange
Quoted 5 lines · On Wed, May 06, 2009 at 03:00:50AM +0200, [email protected] wrote:

From: Alexander Graf <[email protected]>

Currently Qemu can read from posix I/O and NBD. This patch adds a third protocol to the game: HTTP.

Quoted 7 lines

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

Quoted 7 lines

I rather think there should be an explicit flag to allow use of http://
URLs in filenames at runtime, not just 'configure' time. There are many apps out there using QEMU which will be assuming QEMU treats all disk paths as local files, and thus not got explicit code to check whether a URI is passed. I could well see that some will consider it a security issue to allow QEMU to download off the net, but if they updated to a new QEMU with this patch, downloading would be allowed by default.

If apps want to be sure that they are accessing a local file, they must ensure not to have a colon in the file name. Otherwise this specifies a protocol for the qemu block layer.

Btw, we could use a way to escape colons in a file name. Using such files isn't possible currently.

Quoted 4 lines

Perhaps only enable these remote URIs with the -drive parameter, when an explicit fmt=http option is set. But can this be layered into the other protocols, eg could the remote URI be in qcow, vmdk, etc formats, or are you assuming the remote uri is raw file ?

It should work with all formats. This is why fmt=http is wrong. It's not a format, but a protocol.

Kevin

#3 lore raw
Quoted 23 lines · Kevin Wolf
Quoted 14 lines · Daniel P. Berrange
Quoted 5 lines · On Wed, May 06, 2009 at 03:00:50AM +0200, [email protected] wrote:

From: Alexander Graf <[email protected]>

Currently Qemu can read from posix I/O and NBD. This patch adds a third protocol to the game: HTTP.

Quoted 7 lines

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

Quoted 7 lines

I rather think there should be an explicit flag to allow use of http://
URLs in filenames at runtime, not just 'configure' time. There are many apps out there using QEMU which will be assuming QEMU treats all disk paths as local files, and thus not got explicit code to check whether a URI is passed. I could well see that some will consider it a security issue to allow QEMU to download off the net, but if they updated to a new QEMU with this patch, downloading would be allowed by default.

Quoted 3 lines

If apps want to be sure that they are accessing a local file, they must ensure not to have a colon in the file name. Otherwise this specifies a protocol for the qemu block layer.

Using paths with a colon in the file name is pretty critical if you wish to configure VMs with block devices using a stable path like those under /dev/disk/by-path/ - they pretty much all contain colons, and are the only good stable path for iSCSI or FibreChannel block devices.

Quoted 10 lines

Btw, we could use a way to escape colons in a file name. Using such files isn't possible currently.

Quoted 4 lines

Perhaps only enable these remote URIs with the -drive parameter, when an explicit fmt=http option is set. But can this be layered into the other protocols, eg could the remote URI be in qcow, vmdk, etc formats, or are you assuming the remote uri is raw file ?

It should work with all formats. This is why fmt=http is wrong. It's not a format, but a protocol.

Then I'd prefer we add a protocol=XXX option for magic protocols. This would be easier to use & clearer than requiring escaping of magic characters, eg

-drive file=/some/path:with:colons,protocol=file -drive file=http://some/path,protocol=uri

For compatability, we could make it such that if protocol=XXX was left out, it could try and "guess" it, in same way QEMU does if format=XXX is left out for content format.

Daniel

Signature · 4 lines
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
#4 lore raw
Quoted 14 lines · Daniel P. Berrange
Quoted 8 lines · Kevin Wolf
Quoted 4 lines · Daniel P. Berrange

Perhaps only enable these remote URIs with the -drive parameter, when an explicit fmt=http option is set. But can this be layered into the other protocols, eg could the remote URI be in qcow, vmdk, etc formats, or are you assuming the remote uri is raw file ?

It should work with all formats. This is why fmt=http is wrong. It's not a format, but a protocol.

Then I'd prefer we add a protocol=XXX option for magic protocols. This would be easier to use & clearer than requiring escaping of magic characters, eg

Quoted 6 lines

-drive file=/some/path:with:colons,protocol=file -drive file=http://some/path,protocol=uri

For compatability, we could make it such that if protocol=XXX was left out, it could try and "guess" it, in same way QEMU does if format=XXX is left out for content format.

I like that idea, yes.

Unfortunately it is out of scope of this patch. The problem you're describing with qemu taking on remote connections exists today already with NBD support. Right now there are 2 protocols implemented in qemu that I'm aware of:

- file (local)
- nbd (remote)

and I just add another remote one:
- http (remote)

So your concerns do apply today already. Maybe you want to come up with a patch to implement a protocol= parameter to -drive?

Alex

#5 lore raw
In reply to Daniel P. Berrange
Quoted 9 lines · Daniel P. Berrange

Then I'd prefer we add a protocol=XXX option for magic protocols. This would be easier to use & clearer than requiring escaping of magic characters, eg

-drive file=/some/path:with:colons,protocol=file -drive file=http://some/path,protocol=uri

For compatability, we could make it such that if protocol=XXX was left out, it could try and "guess" it, in same way QEMU does if format=XXX is left out for content format.

How about

-drive file=file:///some/path:with:colons?

Libvirt would use this unconditionally, command-line users can choose.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#6 lore raw
Quoted 13 lines · Avi Kivity
Quoted 11 lines · Daniel P. Berrange

Then I'd prefer we add a protocol=XXX option for magic protocols. This would be easier to use & clearer than requiring escaping of magic characters, eg

-drive file=/some/path:with:colons,protocol=file -drive file=http://some/path,protocol=uri

For compatability, we could make it such that if protocol=XXX was left out, it could try and "guess" it, in same way QEMU does if format=XXX is left out for content format.

Quoted 5 lines

How about

-drive file=file:///some/path:with:colons?

Libvirt would use this unconditionally, command-line users can choose.

+1

The patch to achieve this would be pretty easy. You just need to assign the file protocol to bdrv_raw and have it strip the file: prefix in its open function.

Kevin

#7 lore raw
In reply to Avi Kivity
Quoted 14 lines · Avi Kivity
Quoted 4 lines · Daniel P. Berrange

Then I'd prefer we add a protocol=XXX option for magic protocols. This would be easier to use & clearer than requiring escaping of magic characters, eg

Quoted 8 lines

-drive file=/some/path:with:colons,protocol=file -drive file=http://some/path,protocol=uri

For compatability, we could make it such that if protocol=XXX was left out, it could try and "guess" it, in same way QEMU does if format=XXX is left out
for content format.

Quoted 5 lines

How about

-drive file=file:///some/path:with:colons?

Libvirt would use this unconditionally, command-line users can choose.

Sure, that achieves the same end result, so fine by me.

Daniel

Signature · 4 lines
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
#8 lore raw
Quoted 15 lines · Daniel P. Berrange
Quoted 14 lines · Avi Kivity
Quoted 12 lines · Daniel P. Berrange

Then I'd prefer we add a protocol=XXX option for magic protocols. This would be easier to use & clearer than requiring escaping of magic characters, eg

-drive file=/some/path:with:colons,protocol=file -drive file=http://some/path,protocol=uri

For compatability, we could make it such that if protocol=XXX was left out, it could try and "guess" it, in same way QEMU does if format=XXX is left out
for content format.

Quoted 7 lines
Quoted 5 lines

How about

-drive file=file:///some/path:with:colons?

Libvirt would use this unconditionally, command-line users can choose.

Sure, that achieves the same end result, so fine by me.

Oh and if you want to be really nice, you could say that any filename with a leading '/' is implicitly file:///, since I can't imagine any protocol name starting with a '/'. And this would ensure any existing usage with absolute filenames 'just works' without tripping up on colons.

Daniel

Signature · 4 lines
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
#9 lore raw
Quoted 6 lines · Daniel P. Berrange

Oh and if you want to be really nice, you could say that any filename with a leading '/' is implicitly file:///, since I can't imagine any protocol name starting with a '/'. And this would ensure any existing usage with absolute filenames 'just works' without tripping up on colons.

A protocol should match ^[a-zA-Z][a-zA-Z0-9_-]*://, anything else is a file.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#10 lore raw
In reply to Daniel P. Berrange
Quoted 22 lines · Daniel P. Berrange
Quoted 21 lines · Daniel P. Berrange
Quoted 19 lines · Avi Kivity
Quoted 4 lines · Daniel P. Berrange

Then I'd prefer we add a protocol=XXX option for magic protocols. This would be easier to use & clearer than requiring escaping of magic characters, eg

Quoted 8 lines

-drive file=/some/path:with:colons,protocol=file
-drive file=http://some/path,protocol=uri

For compatability, we could make it such that if protocol=XXX was left out, it could try and "guess" it, in same way QEMU does if format=XXX is left out
for content format.

How about

-drive file=file:///some/path:with:colons?

Libvirt would use this unconditionally, command-line users can choose.

Quoted 7 lines
Quoted 1 line

Sure, that achieves the same end result, so fine by me.

Oh and if you want to be really nice, you could say that any filename with a leading '/' is implicitly file:///, since I can't imagine any protocol name starting with a '/'. And this would ensure any existing usage with absolute filenames 'just works' without tripping up on colons.

No, "the right way" would be to always assume file:// for filenames that don't have a protocol ("://") specified.

Alex

#11 lore raw
Quoted 27 lines · Alexander Graf
Quoted 24 lines · Daniel P. Berrange
Quoted 22 lines · Daniel P. Berrange
Quoted 14 lines · Avi Kivity
Quoted 4 lines · Daniel P. Berrange

Then I'd prefer we add a protocol=XXX option for magic protocols. This would be easier to use & clearer than requiring escaping of magic characters, eg

Quoted 8 lines

-drive file=/some/path:with:colons,protocol=file
-drive file=http://some/path,protocol=uri

For compatability, we could make it such that if protocol=XXX was left out, it could try and "guess" it, in same way QEMU does if format=XXX is left out
for content format.

Quoted 5 lines

How about

-drive file=file:///some/path:with:colons?

Libvirt would use this unconditionally, command-line users can choose.

Sure, that achieves the same end result, so fine by me.

Quoted 7 lines
Quoted 5 lines

Oh and if you want to be really nice, you could say that any filename with a leading '/' is implicitly file:///, since I can't imagine any protocol name starting with a '/'. And this would ensure any existing usage with absolute filenames 'just works' without tripping up on colons.

No, "the right way" would be to always assume file:// for filenames that don't have a protocol ("://") specified.

nbd doesn't use '://'. It's prohibitively hard to express a unix domain socket and parameters with a standard URI.

Regards,

Anthony Liguori

Quoted 4 lines

Alex

#12 lore raw
In reply to Daniel P. Berrange
Quoted 5 lines · Daniel P. Berrange

Oh and if you want to be really nice, you could say that any filename with a leading '/' is implicitly file:///, since I can't imagine any protocol name starting with a '/'. And this would ensure any existing usage with absolute filenames 'just works' without tripping up on colons.

Existing usage would mean to get an error message. I don't see any reason why we should change this behaviour if we have a real solution. Adding more exceptions to the guessing doesn't really make it more harmless.

Kevin

#13 lore raw
Quoted 10 lines · Kevin Wolf
Quoted 5 lines · Daniel P. Berrange

Oh and if you want to be really nice, you could say that any filename with a leading '/' is implicitly file:///, since I can't imagine any protocol name starting with a '/'. And this would ensure any existing usage with absolute filenames 'just works' without tripping up on colons.

Existing usage would mean to get an error message. I don't see any reason why we should change this behaviour if we have a real solution. Adding more exceptions to the guessing doesn't really make it more harmless.

No, please don't break something as essential as this without a good reason. If you don't specify a protocol, chances are 99.999% the user wants a file, so let's behave that way!

Alex

#14 lore raw
In reply to Kevin Wolf
Quoted 10 lines · Kevin Wolf
Quoted 5 lines · Daniel P. Berrange

Oh and if you want to be really nice, you could say that any filename with a leading '/' is implicitly file:///, since I can't imagine any protocol name starting with a '/'. And this would ensure any existing usage with absolute filenames 'just works' without tripping up on colons.

Existing usage would mean to get an error message. I don't see any reason why we should change this behaviour if we have a real solution. Adding more exceptions to the guessing doesn't really make it more harmless.

By existing usage, I meant the practice of supplying an absolute filename to QEMU, which works all the time, except if you're unlucky to have a colon in the filename, in which case it breaks, even though it could trivially work. Getting an error for an absolute path with a colon is a bug IMHO, rather than useful behaviour.

Daniel

Signature · 4 lines
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
#15 lore raw
In reply to Avi Kivity
Quoted 11 lines · Avi Kivity
Quoted 9 lines · Daniel P. Berrange

Then I'd prefer we add a protocol=XXX option for magic protocols. This would be easier to use & clearer than requiring escaping of magic characters, eg

-drive file=/some/path:with:colons,protocol=file -drive file=http://some/path,protocol=uri

For compatability, we could make it such that if protocol=XXX was left out, it could try and "guess" it, in same way QEMU does if format=XXX is left out for content format.

Quoted 5 lines

How about

-drive file=file:///some/path:with:colons?

Libvirt would use this unconditionally, command-line users can choose.

It's about the same as having a protocol= parameter, but more compatible and easier. I'm sold :-).

Alex

#16 lore raw
In reply to Avi Kivity
Quoted 6 lines · Avi Kivity
Quoted 5 lines · Daniel P. Berrange

Then I'd prefer we add a protocol=XXX option for magic protocols. This would be easier to use & clearer than requiring escaping of magic characters, eg

-drive file=/some/path:with:colons,protocol=file -drive file=http://some/path,protocol=uri

Quoted 8 lines
Quoted 4 lines

For compatability, we could make it such that if protocol=XXX was left out, it could try and "guess" it, in same way QEMU does if format=XXX is left out for content format.

How about

-drive file=file:///some/path:with:colons?

No '///' please.

Regards,

Anthony Liguori

Quoted 2 lines

Libvirt would use this unconditionally, command-line users can choose.

#17 lore raw
Quoted 5 lines · Anthony Liguori
Quoted 2 lines

-drive file=file:///some/path:with:colons?

No '///' please.

Why not?

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#18 lore raw
Quoted 8 lines · Avi Kivity
Quoted 5 lines · Anthony Liguori
Quoted 2 lines

-drive file=file:///some/path:with:colons?

No '///' please.

Why not?

For better or worse, this aren't URIs. The main reason, is that a URI requires a hostname as the first component (which is empty in your URI). But unix domain sockets don't match up with URIs because they aren't hostnames.

Regards,

Anthony Liguori

#19 lore raw
Quoted 8 lines
Quoted 7 lines · Avi Kivity
Quoted 5 lines · Anthony Liguori
Quoted 2 lines

-drive file=file:///some/path:with:colons?

No '///' please.

Quoted 7 lines
Quoted 1 line

Why not?

For better or worse, this aren't URIs. The main reason, is that a URI
requires a hostname as the first component (which is empty in your URI). But unix domain sockets don't match up with URIs because they aren't hostnames.

Not for file:, which is why there are 3 /, though it's actually * possible* to specify a hostname for file:, it's *not* required, and useless anyway.

François.

#20 lore raw
In reply to Avi Kivity
Quoted 11 lines · Avi Kivity
Quoted 9 lines · Daniel P. Berrange

Then I'd prefer we add a protocol=XXX option for magic protocols. This would be easier to use & clearer than requiring escaping of magic characters, eg

-drive file=/some/path:with:colons,protocol=file -drive file=http://some/path,protocol=uri

For compatability, we could make it such that if protocol=XXX was left out, it could try and "guess" it, in same way QEMU does if format=XXX is left out for content format.

Quoted 5 lines

How about

-drive file=file:///some/path:with:colons?

Libvirt would use this unconditionally, command-line users can choose.

Why does libvirt care? That confuses me.

Regards,

Anthony Liguori

#21 lore raw
Quoted 16 lines · Anthony Liguori
Quoted 15 lines · Avi Kivity
Quoted 13 lines · Daniel P. Berrange

Then I'd prefer we add a protocol=XXX option for magic protocols. This would be easier to use & clearer than requiring escaping of magic characters, eg

-drive file=/some/path:with:colons,protocol=file -drive file=http://some/path,protocol=uri

For compatability, we could make it such that if protocol=XXX was left out,
it could try and "guess" it, in same way QEMU does if format=XXX is left out
for content format.

Quoted 7 lines
Quoted 5 lines

How about

-drive file=file:///some/path:with:colons?

Libvirt would use this unconditionally, command-line users can choose.

Why does libvirt care? That confuses me.

I don't have any problem with QEMU supporting http, nbd, or other clever file access schemes. I'll let others debate its merits vs using FUSE http filesystems :-)

All I care about from libvirt POV, is that there is a way to give QEMU an absolute file path for a disk, and guarentee that QEMU will treat this as a local file path, and not try any access protocols, other than 'open(2)'. Various options from this thread....

- Treat any path starting with / as local file
- Allow file: as a prefix
- Allow file:/// as a prefix, real URI style
- Add a protocol=file flag to -drive

Pick one, pick several, suggest more. Any of these options would work as far as I'm concerned, and we could easily support several. I think the first is desirable because that's the natural thing users will try when launching QEMU directly. I see the merit in also having file: or file:/// as an explicit protocol too. I think the 4th protocol=file is redundant really, given that we have precedent of using XXX: prefixes in nbd driver

Regards,
Daniel

Signature · 4 lines
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
#22 lore raw
Quoted 28 lines · Daniel P. Berrange
Quoted 14 lines · Anthony Liguori
Quoted 12 lines · Avi Kivity
Quoted 10 lines · Daniel P. Berrange

Then I'd prefer we add a protocol=XXX option for magic protocols. This would be easier to use & clearer than requiring escaping of magic characters, eg

-drive file=/some/path:with:colons,protocol=file -drive file=http://some/path,protocol=uri

For compatability, we could make it such that if protocol=XXX was left out, it could try and "guess" it, in same way QEMU does if format=XXX is left out for content format.

Quoted 8 lines
Quoted 6 lines

How about

-drive file=file:///some/path:with:colons?

Libvirt would use this unconditionally, command-line users can choose.

Why does libvirt care? That confuses me.

I don't have any problem with QEMU supporting http, nbd, or other clever file access schemes. I'll let others debate its merits vs using FUSE http filesystems :-)

Quoted 9 lines

All I care about from libvirt POV, is that there is a way to give QEMU an absolute file path for a disk, and guarentee that QEMU will treat this as a local file path, and not try any access protocols, other than 'open(2)'.
Various options from this thread....

- Treat any path starting with / as local file
- Allow file: as a prefix
- Allow file:/// as a prefix, real URI style
- Add a protocol=file flag to -drive

The only viable solution is for libvirt to escape it's file names.

For instance, you're in all sorts of trouble if a user creates a filename that looks like 'My disk image,format=raw.img'

Regards,

Anthony Liguori

#23 lore raw
In reply to Daniel P. Berrange
Quoted 10 lines · Daniel P. Berrange

All I care about from libvirt POV, is that there is a way to give QEMU an absolute file path for a disk, and guarentee that QEMU will treat this as a local file path, and not try any access protocols, other than 'open(2)'. Various options from this thread....

- Treat any path starting with / as local file
- Allow file: as a prefix
- Allow file:/// as a prefix, real URI style
- Add a protocol=file flag to -drive

Quoted 4 lines

Pick one, pick several, suggest more. Any of these options would work as far as I'm concerned, and we could easily support several. I think the first is desirable because that's the natural thing users will try when launching QEMU directly.

I think we all agree that file: is a reasonable option for libvirt which covers all cases of colons (even relative paths starting with http:), so let's take this one. If you want to magically do the right thing for users invoking qemu manually, I think we should rather go for:

5) Treat anything as local file which has a protocol prefix that doesn't match a known protocol

This would mean that vvfat:xyz uses the vvfat protocol, but foo:bar is a local file because the protocol foo doesn't exist. I think this variant is less confusing magic than checking for a completely unrelated character like /.

Kevin

#24 lore raw
Quoted 16 lines · Kevin Wolf
Quoted 4 lines · Daniel P. Berrange

All I care about from libvirt POV, is that there is a way to give QEMU an absolute file path for a disk, and guarentee that QEMU will treat this as a local file path, and not try any access protocols, other than 'open(2)'.
Various options from this thread....

Quoted 9 lines

- Treat any path starting with / as local file
- Allow file: as a prefix
- Allow file:/// as a prefix, real URI style
- Add a protocol=file flag to -drive

Pick one, pick several, suggest more. Any of these options would work as far as I'm concerned, and we could easily support several. I think the first is desirable because that's the natural thing users will try when
launching QEMU directly.

Quoted 5 lines

I think we all agree that file: is a reasonable option for libvirt which covers all cases of colons (even relative paths starting with http:), so let's take this one. If you want to magically do the right thing for users invoking qemu manually, I think we should rather go for:

I've changed my mind. I think file: makes the situation worse because it gives a false sense of security. If you just pass file:<user-inputed-filename> you are broken. You still have to escape commas. If you're escaping commas, you might as well escape colons too.

I think escaping is the only complete solution.

Regards,

Anthony Liguori

#25 lore raw
Quoted 6 lines · Anthony Liguori

I've changed my mind. I think file: makes the situation worse because it gives a false sense of security. If you just pass file:<user-inputed-filename> you are broken. You still have to escape commas. If you're escaping commas, you might as well escape colons too.

I think escaping is the only complete solution.

You're completely right if we don't limit the discussion to colons. I'm not sure if breaking colons really makes tools aware that they need to take care of commas, but "it's broken anyway" is a reasonable answer if we can have a generic fix (and we can have it here).

So what should the generic escaping look like?

And I still think we should do something about colons, they are much more common in paths than commas. Even more so on Windows, I guess. Should we still implement the strategy "anything that isn't a valid protocol must be a local file"?

Kevin

#26 lore raw
Quoted 4 lines · Kevin Wolf
Quoted 2 lines · Anthony Liguori

I've changed my mind. I think file: makes the situation worse because it gives a false sense of security. If you just pass file:<user-inputed-filename> you are broken. You still have to escape commas. If you're escaping commas, you might as well escape colons too.

Quoted 8 lines
Quoted 2 lines

I think escaping is the only complete solution.

You're completely right if we don't limit the discussion to colons. I'm not sure if breaking colons really makes tools aware that they need to take care of commas, but "it's broken anyway" is a reasonable answer if we can have a generic fix (and we can have it here).

If we have escaping, I'm happy to consider file: if people still think it's useful. But adding file: without escaping is IMHO dangerous.

Quoted 2 lines

So what should the generic escaping look like?

-drive file=my-silly\:filename\,with\ strange\ characters

I see no reason to do anything overly complicated. Of course, if you're in a shell, you'll have to double escape unless you've got single quotes around it. That's a good argument for file: in addition to escaping.

Regards,

Anthony Liguori

#27 lore raw
Quoted 14 lines · Anthony Liguori
Quoted 4 lines · Kevin Wolf
Quoted 2 lines · Anthony Liguori

I've changed my mind. I think file: makes the situation worse because it gives a false sense of security. If you just pass file:<user-inputed-filename> you are broken. You still have to escape commas. If you're escaping commas, you might as well escape colons too.

Quoted 8 lines
Quoted 2 lines

I think escaping is the only complete solution.

You're completely right if we don't limit the discussion to colons. I'm not sure if breaking colons really makes tools aware that they need to take care of commas, but "it's broken anyway" is a reasonable answer if we can have a generic fix (and we can have it here).

Quoted 6 lines

If we have escaping, I'm happy to consider file: if people still think it's useful. But adding file: without escaping is IMHO dangerous.

Quoted 2 lines

So what should the generic escaping look like?

-drive file=my-silly\:filename\,with\ strange\ characters

I liked the idea of URI escaping, like "%20" being byte 32 -> space. There are enough libraries out there that can easily generate such an escaping, so people don't have to stick with a dozen of different ways of escaping, depending on which option they're using.

Alex

#28 lore raw
In reply to Anthony Liguori
Quoted 7 lines · Anthony Liguori
Quoted 2 lines

So what should the generic escaping look like?

-drive file=my-silly\:filename\,with\ strange\ characters

I see no reason to do anything overly complicated. Of course, if you're in a shell, you'll have to double escape unless you've got single quotes around it. That's a good argument for file: in addition to escaping.

With backslash escaping, I never know how many backslashes I end up with. They're also the path separators in one OS.

I'd go with URL separating:

-drive file=file:my-silly%3afilename%2cwith%20strange%20characters

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#29 lore raw
Quoted 6 lines · Avi Kivity
Quoted 5 lines · Anthony Liguori
Quoted 2 lines

So what should the generic escaping look like?

-drive file=my-silly\:filename\,with\ strange\ characters

Quoted 8 lines
Quoted 2 lines

I see no reason to do anything overly complicated. Of course, if you're in a shell, you'll have to double escape unless you've got single quotes around it. That's a good argument for file: in addition to escaping.

With backslash escaping, I never know how many backslashes I end up with. They're also the path separators in one OS.

I'd go with URL separating:

-drive file=file:my-silly%3afilename%2cwith%20strange%20characters

URI escaping has some pretty strange rules because there set of characters allowed in a URI is << what is representable in a shell without requiring escaping.

But honestly, I don't care that much. I'll leave the decision up to whoever writes up the patch.

Regards,

Anthony Liguori

#30 lore raw
Quoted 16 lines · Anthony Liguori
Quoted 15 lines · Avi Kivity
Quoted 10 lines · Anthony Liguori
Quoted 2 lines

So what should the generic escaping look like?

-drive file=my-silly\:filename\,with\ strange\ characters

I see no reason to do anything overly complicated. Of course, if you're in a shell, you'll have to double escape unless you've got single quotes around it. That's a good argument for file: in addition to escaping.

With backslash escaping, I never know how many backslashes I end up with. They're also the path separators in one OS.

Quoted 7 lines
Quoted 3 lines

I'd go with URL separating:

-drive file=file:my-silly%3afilename%2cwith%20strange%20characters

URI escaping has some pretty strange rules because there set of characters allowed in a URI is << what is representable in a shell without requiring escaping.

There's no harm in accepting characters which aren't normally allowed in a URI. When _escaped_, any octet sequence can be encoded in a URI so there's no problem there.

Backslash quoting in shell is easiest to type like this, using single quotes around it:

-drive 'file=my-silly\:filename\,with\ strange\ characters'

Backslash quoting is easier to do in shell scripts which are driving QEMU, or driving QEMU's monitor. I.e. using sed or printf %q in Bash:

qpath=printf %q "$path"
qemu -drive file="$qpath"

(I don't know why, but conveniently Bash's %q quotes commas).

-- Jamie

#31 lore raw
In reply to Anthony Liguori
Quoted 5 lines · Anthony Liguori

-drive file=my-silly\:filename\,with\ strange\ characters

I see no reason to do anything overly complicated. Of course, if you're in a shell, you'll have to double escape unless you've got single quotes around it. That's a good argument for file: in addition to escaping.

Double escaping is why I thought that it might be ugly. But as long as it's meant for tools and users still have something like file: I'm fine with it.

Fortunately cmd.exe doesn't do escaping. Not having to use it, I must admit that I would kind of like things like -hda c\\:\\\\foo.img though. ;-)

Kevin

#32 lore raw
In reply to Daniel P. Berrange
Quoted 47 lines · Daniel P. Berrange
Quoted 24 lines · Kevin Wolf
Quoted 13 lines · Daniel P. Berrange
Quoted 11 lines · On Wed, May 06, 2009 at 03:00:50AM +0200, [email protected] wrote:

From: Alexander Graf <[email protected]>

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 9 lines
Quoted 2 lines

qemu -cdrom http://host/path/my.iso

I rather think there should be an explicit flag to allow use of http://
URLs in filenames at runtime, not just 'configure' time. There are many
apps out there using QEMU which will be assuming QEMU treats all disk
paths as local files, and thus not got explicit code to check whether a URI is passed. I could well see that some will consider it a security issue to allow QEMU to download off the net, but if they updated to
a new QEMU with this patch, downloading would be allowed by default.

Quoted 4 lines

If apps want to be sure that they are accessing a local file, they must ensure not to have a colon in the file name. Otherwise this specifies a protocol for the qemu block layer.

Using paths with a colon in the file name is pretty critical if you wish to configure VMs with block devices using a stable path like those under /dev/disk/by-path/ - they pretty much all contain colons, and are the only good stable path for iSCSI or FibreChannel block devices.

Quoted 9 lines

Btw, we could use a way to escape colons in a file name. Using such files isn't possible currently.

Quoted 5 lines

Perhaps only enable these remote URIs with the -drive parameter, when an explicit fmt=http option is set. But can this be layered into the other protocols, eg could the remote URI be in qcow, vmdk, etc formats, or are you assuming the remote uri is raw file ?

Quoted 6 lines
Quoted 3 lines

It should work with all formats. This is why fmt=http is wrong. It's not a format, but a protocol.

Then I'd prefer we add a protocol=XXX option for magic protocols. This would be easier to use & clearer than requiring escaping of magic characters, eg

It just exacerbates the problem. The comma is also a special character so now to avoid problems with ':' as a special character, you're relying on another special character.

We absolutely need escaping. I have no doubt about that.

From a human readable perspective though, I think we could introduce a "file:" protocol which ensured that we used a local file protocol. For instance,

-drive file=file:/some/path

Regards,

Anthony Liguori

#33 lore raw
In reply to Kevin Wolf
Quoted 6 lines · Kevin Wolf

If apps want to be sure that they are accessing a local file, they must ensure not to have a colon in the file name. Otherwise this specifies a protocol for the qemu block layer.

Btw, we could use a way to escape colons in a file name. Using such files isn't possible currently.

Escaping:

Because I'm not sure how QEMU parses colons, spaces, commas, quotes and who knows what other special characters in these options, and because the monitor might use different parsing when reading a disk image name, my management scripts always create symlinks to the disks, and pass the names of the symlinks instead to the command line and the monitor.

It's quite awkward for qcow2 delta files, because they contain the name of their backing file, it can be relative, cannot be overriden, and is resolved relative to the management script's symlinks, and they can be stacked more than one deep... But most of the time it is solvable by making a set of symlinks in a little directory hierarchy.

I'd be quite happy with file:///path/to/file%20containing%20spaces.vhd working, on the command line and in the monitor, in the the way file URIs are meant to work.

-- Jamie

#34 lore raw
In reply to Daniel P. Berrange
Quoted 16 lines · Daniel P. Berrange
Quoted 5 lines · On Wed, May 06, 2009 at 03:00:50AM +0200, [email protected] wrote:

From: Alexander Graf <[email protected]>

Currently Qemu can read from posix I/O and NBD. This patch adds a third protocol to the game: HTTP.

Quoted 8 lines

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

Quoted 7 lines

I rather think there should be an explicit flag to allow use of http://
URLs in filenames at runtime, not just 'configure' time. There are many
apps out there using QEMU which will be assuming QEMU treats all disk
paths as local files, and thus not got explicit code to check whether a URI is passed. I could well see that some will consider it a security issue to allow QEMU to download off the net, but if they updated to
a new QEMU with this patch, downloading would be allowed by default.

QEMU already supports protocol URLs (like nbd://). If a management app has some reason to restrict what QEMU has access to, they should be using SELinux or already scrubbing device names. I don't understand why accessing a URL would be a security issue though. I expect that management apps should be running QEMU as a non-privileged user and that from a security perspective, that user is restricted as much as the guest would be restricted.

Regards,

Anthony Liguori