[Libguestfs] Provide NBD via Browser over Websockets

Daniel P. Berrangé berrange at redhat.com
Fri May 29 13:50:42 UTC 2020


On Fri, May 29, 2020 at 07:50:14AM -0500, Eric Blake wrote:
> [adding qemu list]
> 
> On 5/29/20 4:37 AM, Richard W.M. Jones wrote:
> > Going back to the original email from 2018:
> > 
> > > It might be neat to attach ISOs to KVM guests via websockets.  Basically
> > > the  browser would be the NBD "server" and an NBD client would run on the
> > > hypervisor, then use `virsh change-media vm1 hdc --insert /dev/nbd0` could
> > > use an ISO from my desk to boot from.
> > > 
> > > Here's an HTML5 open file example:
> > > https://stackoverflow.com/questions/3582671/how-to-open-a-local-disk-file-with-javascript
> > > 
> > > and the NBD protocol looks simple enough to implement in javascript:
> > > https://stackoverflow.com/questions/17295140/where-is-the-network-block-device-format-describled
> > 
> > So I think what you mean here is that in a browser you'd open a local
> > (eg) ISO, and then that ISO could be shared with a remote VM.  The
> > browser runs a Javascript NBD server.  The remote VM is qemu.  Between
> > the two is a WebSocket.
> > 
> > I've seen this being done with an HP blade server of some kind and
> > IIRC the client side used a Java applet.  No idea what the protocol
> > was but likely something proprietary.  It was nevertheless a useful
> > feature, eg to boot the server from an install CD that you have
> > locally.
> > 
> > I guess the problem is two-fold:
> > 
> > (1) You need to write an NBD server in Javascript.  Not especially
> > difficult, particularly if you avoid any complicated features, and I
> > guess you only need read support.
> 
> Or use an existing NBD server over a Unix socket paired to a WebSocket proxy
> that forwards all traffic from the Unix socket over a WebSocket. That may be
> easier than writing the NBD server itself in Javascript.
> 
> > 
> > (2) You need to persuade qemu's NBD client to read from a WebSocket.
> > I didn't really know anything about WebSockets until today but it
> > seems as if they are a full-duplex protocol layered on top of HTTP [a].
> > Is there a WebSocket proxy that turns WS into plain TCP (a bit like
> > stunnel)?  Google suggests [b].
> > 
> > [a] https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake
> > [b] https://github.com/novnc/websockify
> 
> qemu already knows how to connect as a client to websockets; Dan Berrange
> knows more about that setup.  I suspect it would not be too difficult to
> teach the qemu NBD client code to use a WebSocket instead of a Unix or TCP
> socket as its data source.

Actually the inverse. The QIOChannelWebsocket impl is only the server
side of the problem, as used by QEMU's VNC server. We've never implemented
the client side. There is nothing especially stopping us doing that - just
needs someone motivated with time to work on it.

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|




More information about the Libguestfs mailing list