block: Add support for Secure Shell (ssh) block device.
PATCH v7 2/2 iotests: Add 'check -ssh' option to test Secure Shell block device.
In reply to Richard W.M. JonesFrom: "Richard W.M. Jones" <[email protected]>
Note in order to run these tests on ssh, you must be running a local ssh daemon, and that daemon must accept loopback connections, and ssh-agent has to be set up to allow logins on the local daemon. In other words, the following command should just work without demanding any passphrase:
ssh localhost
--- tests/qemu-iotests/common | 5 +++++ tests/qemu-iotests/common.rc | 3 +++ 2 files changed, 8 insertions(+)
tests/qemu-iotests/common +5 -0
@@ -137,6 +137,7 @@ check options -rbd test rbd -sheepdog test sheepdog -nbd test nbd + -ssh test ssh -xdiff graphical mode diff -nocache use O_DIRECT on backing file -misalign misalign memory allocations
@@ -206,6 +207,10 @@ testlist options IMGPROTO=nbd xpand=false ;; + -ssh) + IMGPROTO=ssh + xpand=false + ;; -nocache) QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --nocache" xpand=false
tests/qemu-iotests/common.rc +3 -0
@@ -52,6 +52,9 @@ if [ "$IMGPROTO" = "file" ]; then elif [ "$IMGPROTO" = "nbd" ]; then TEST_IMG_FILE=$TEST_DIR/t.$IMGFMT TEST_IMG="nbd:127.0.0.1:10810" +elif [ "$IMGPROTO" = "ssh" ]; then + TEST_IMG_FILE=$TEST_DIR/t.$IMGFMT + TEST_IMG="ssh://127.0.0.1$TEST_IMG_FILE" else TEST_IMG=$IMGPROTO:$TEST_DIR/t.$IMGFMT fi
Signature · 1 line
1.8.1.4
v7 cover block: Add support for Secure Shell (ssh) block device.
Since v6:
- This fixes a rather serious race condition in the previous versions, which only manifested itself when using 'snapshot=on'.
- Store the attributes (like filesize) in the state.
- Macros for LOCK/UNLOCK to make debugging simpler.
- Added an ssh driver to libguestfs and tested with that:
https://www.redhat.com/archives/libguestfs/2013-April/msg00022.html
Rich.
PATCH v7 1/2 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/...). You can also use an alternate syntax using properties (file.user, file.host, file.port, file.path).
Current limitations:
- Authentication must be done without passwords or passphrases, using ssh-agent. Other authentication methods are not supported.
- Uses a single connection, instead of concurrent AIO with multiple SSH connections.
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 | 880 ++++++++++++++++++++++++++++++++++++++++++++++++++++ configure | 48 +++ qemu-doc.texi | 40 +++ qemu-options.hx | 12 + 5 files changed, 981 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 +880 -0
880 lines not on this page · raw message
configure +48 -0
84 lines not on this page · raw message
qemu-doc.texi +40 -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,45 @@ 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 + +Alternative syntax using properties: + +@example +qemu-system-x86_64 -drive file.driver=ssh[,file.user=@var{user}],file.host=@var{server}[,file.port=@var{port}],file.path=@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. + +Currently authentication must be done using ssh-agent. Other +authentication methods may be supported in future. + +Note: The ssh driver does not obey disk flush requests (ie. to commit +data to the backing disk when the guest requests it). This is because +the underlying protocol (SFTP) does not support this. Thus there is a +risk of guest disk corruption if the remote server or network goes +down during writes. + @node pcsys_network @section Network emulation
qemu-options.hx +12 -0
@@ -2107,6 +2107,18 @@ Example for Unix Domain Sockets qemu-system-i386 --drive file=nbd:unix:/tmp/nbd-socket @end example +@item SSH +QEMU supports SSH (Secure Shell) access to remote disks. + +Examples: +@example +qemu-system-i386 -drive file=ssh://user@@host/path/to/disk.img +qemu-system-i386 -drive file.driver=ssh,file.user=user,file.host=host,file.port=22,file.path=/path/to/disk.img +@end example + +Currently authentication must be done using ssh-agent. Other +authentication methods may be supported in future. + @item Sheepdog Sheepdog is a distributed storage system for QEMU. QEMU supports using either local sheepdog devices or remote networked
Signature · 1 line
1.8.1.4
Quoted 10 lines · Richard W.M. Jones
block/ssh.c new file +10
-0+/* DEBUG_SSH=1 enables the DPRINTF (debugging printf) statements in +* this block driver code. +* +* TRACE_LIBSSH2=<bitmask> enables tracing in libssh2 itself. Note +* that this requires that libssh2 was specially compiled with the +* `./configure --enable-debug' option, so most likely you will have +* to compile it yourself. The meaning of <bitmask> is described +* here: http://www.libssh2.org/libssh2_trace.html +*/ +#define DEBUG_SSH 0
block/ssh.c line 56
Quoted 10 lines
block/ssh.c new file +10
-0+#define TRACE_LIBSSH2 0/* or try: LIBSSH2_TRACE_SFTP */ + +#if DEBUG_SSH +#define DPRINTF (fmt,...) \ + do { \ + fprintf(stderr, "ssh: %-15s " fmt "\n", __func__, ##__VA_ARGS__); \ + } while (0) +#else +#define DPRINTF (fmt,...)/* nothing */ +#endif
The following approach keeps syntax and format string error checking even when DEBUG_SSH if 0:
#define DPRINTF(fmt, ...) \
do { \
if (DEBUG_SSH) { \
fprintf(stderr, "ssh: %-15s " fmt "\n", \
__func__, ##__VA_ARGS__); \
} \
} while (0)It avoids DPRINTF() bitrot.
block/ssh.c line 87
Quoted 10 lines
block/ssh.c new file +10
-0+#define LOCK (s) do { \ + DPRINTF("acquiring the lock"); \ + qemu_co_mutex_lock(&s->lock); \ + DPRINTF("acquired the lock"); \ + } while (0) + +#define UNLOCK (s) do { \ + qemu_co_mutex_unlock(&s->lock); \ + DPRINTF("released the lock"); \ + } while (0)
See ./trace-events:
qemu_co_mutex_lock_entry(void *mutex, void *self) "mutex %p self %p" qemu_co_mutex_lock_return(void *mutex, void *self) "mutex %p self %p" qemu_co_mutex_unlock_entry(void *mutex, void *self) "mutex %p self %p" qemu_co_mutex_unlock_return(void *mutex, void *self) "mutex %p self %p"
This means you can get these printfs like this:
$ ./configure --enable-trace-backend=stderr $ echo qemu_co_mutex_lock_entry >my-events $ echo qemu_co_mutex_lock_return >>my-events $ echo qemu_co_mutex_unlock_entry >>my-events $ echo qemu_co_mutex_unlock_return >>my-events $ x86_64-softmmu/qemu-system-x86_64 -trace events=my-events ...
If you want you can keep the macros but really we already have these printfs.