block: Add support for Secure Shell (ssh) block device.
PATCH v2 1/1 block: Add support for Secure Shell (ssh) block device.
** For discussion / early review only, still not complete **
This is the second version of the ssh block device patch, previously posted and discussed here:
http://www.mail-archive.com/[email protected]/msg161996.html
There are multiple changes since last time, but the main one is that this ought to be properly using coroutines so it will not block during reads and writes.
Rich.
PATCH v2 1/1 block: Add support for Secure Shell (ssh) block device.
From: "Richard W.M. Jones" <[email protected]>
qemu-system-x86_64 -drive file=ssh://hostname/some/image
QEMU will ssh into 'hostname' and open '/some/image' which is made available as a standard block device.
You can specify a username (ssh://user@host/...) and/or a port number (ssh://host:port/...).
Current limitations:
- Authentication must be done without passwords or passphrases, using ssh-agent. Other authentication methods are not supported. (*)
- Does not check host key. (*)
- New remote files cannot be created. (*)
- Uses a single connection, instead of concurrent AIO with multiple SSH connections.
- Blocks during connection and authentication.
(*) = potentially easy fix
This is implemented using libssh2 on the client side. The server just requires a regular ssh daemon with sftp-server support. Most ssh daemons on Unix/Linux systems will work out of the box.
--- block/Makefile.objs | 1 + block/ssh.c | 656 ++++++++++++++++++++++++++++++++++++++++++++++++++++ configure | 47 ++++ qemu-doc.texi | 28 +++ 4 files changed, 732 insertions(+) create mode 100644 block/ssh.c
block/Makefile.objs +1 -0
@@ -13,6 +13,7 @@ block-obj-$(CONFIG_LIBISCSI) += iscsi.o block-obj-$(CONFIG_CURL) += curl.o block-obj-$(CONFIG_RBD) += rbd.o block-obj-$(CONFIG_GLUSTERFS) += gluster.o +block-obj-$(CONFIG_LIBSSH2) += ssh.o endif common-obj-y += stream.o
block/ssh.c new file +656 -0
656 lines not on this page · raw message
configure +47 -0
83 lines not on this page · raw message
qemu-doc.texi +28 -0
@@ -423,6 +423,7 @@ snapshots. * disk_images_sheepdog:: Sheepdog disk images * disk_images_iscsi:: iSCSI LUNs * disk_images_gluster:: GlusterFS disk images +* disk_images_ssh:: Secure Shell (ssh) disk images @end menu @node disk_images_quickstart
@@ -1038,6 +1039,33 @@ qemu-system-x86_64 -drive file=gluster+unix:///testvol/dir/a.img?socket=/tmp/glu qemu-system-x86_64 -drive file=gluster+rdma://1.2.3.4:24007/testvol/a.img @end example +@node disk_images_ssh +@subsection Secure Shell (ssh) disk images + +You can access disk images located on a remote ssh server +by using the ssh protocol: +@example +qemu-system-x86_64 -drive file=ssh://[@var{user}@@]@var{server}[:@var{port}]/@var{path} +@end example + +@var{ssh} is the protocol. + +@var{user} is the remote user. If not specified, then the local +username is tried. + +@var{server} specifies the remote ssh server. Any ssh server can be +used, but it must implement the sftp-server protocol. Most Unix/Linux +systems should work without requiring any extra configuration. + +@var{port} is the port number on which sshd is listening. By default +the standard ssh port (22) is used. + +@var{path} is the path to the disk image. + +Authentication must currently be done without requiring a password or +passphrase. Set up ssh-agent with authorized keys, or Kerberos or +similar. + @node pcsys_network @section Network emulation
Signature · 1 line
1.8.1.4
Quoted 15 lines · Richard W.M. Jones
From: "Richard W.M. Jones" <[email protected]>
qemu-system-x86_64 -drive file=ssh://hostname/some/image
QEMU will ssh into 'hostname' and open '/some/image' which is made available as a standard block device.
You can specify a username (ssh://user@host/...) and/or a port number (ssh://host:port/...).
Current limitations:
- Authentication must be done without passwords or passphrases, using ssh-agent. Other authentication methods are not supported. (*)
Quoted 8 lines
- Does not check host key. (*)
- New remote files cannot be created. (*)
- Uses a single connection, instead of concurrent AIO with multiple SSH connections.
- Blocks during connection and authentication.
This isn't ideal but .bdrv_open() is a blocking function anyway. If you open a raw image on an NFS export the open(2) call can block too.
Blocking in .bdrv_open() is fine during startup. It's bad when hotplugging drives since the running VM will experience downtime.
block/ssh.c line 325
Quoted 10 lines
block/ssh.c new file +10
-0+/* Start SFTP. */ + s->sftp =libssh2_sftp_init (s->session); +if (!s->sftp) { +session_error_report (s,"failed to initialize sftp handle" ); + ret = -EINVAL ; + goto err; + } + + s->sftp_handle = libssh2_sftp_open(s->sftp, path, + LIBSSH2_FXF_READ|LIBSSH2_FXF_WRITE,
Probably worth handling -drive ...,readonly=on. !(flags & BDRV_O_RDWR)
block/ssh.c line 444
Quoted 5 lines
block/ssh.c new file +5
-0+static coroutine_fn void set_fd_handler(BDRVSSHState *s) +{ +int r; +void (*rd_handler)(void *); +void (*wr_handler)(void *);
There's a typedef for this: IOHandler.
Quoted 17 lines
block/ssh.c new file +17
-0+Coroutine *co =qemu_coroutine_self (); + + rd_handler = wr_handler =NULL ; + + r =libssh2_session_block_directions (s->session); + +if (r &LIBSSH2_SESSION_BLOCK_INBOUND ) { + rd_handler = restart_coroutine; + } +if (r &LIBSSH2_SESSION_BLOCK_OUTBOUND ) { + wr_handler = restart_coroutine; + } + +DPRINTF ("s->sock=%d rd_handler=%p wr_handler=%p" , s->sock, + rd_handler, wr_handler); + +qemu_aio_set_fd_handler (s->sock, rd_handler, wr_handler, return_true, co);
block/ssh.c line 471
Quoted 10 lines
block/ssh.c new file +10
-0+} + +/* A non-blocking call returned EAGAIN, so yield, ensuring the +* handlers are set up so that we'll be rescheduled when there is an +* interesting event on the socket. +*/ +static coroutine_fn void co_yield(BDRVSSHState *s) +{ +set_fd_handler (s); +qemu_coroutine_yield ();
Should we clear the fd handler here? That way the caller doesn't have to worry about fd handler state.
Thanks -- I've included all feedback up to this point in version 3, which I'll post in a moment.
Rich.
Signature · 3 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming blog: http://rwmj.wordpress.com Fedora now supports 80 OCaml packages (the OPEN alternative to F#)