From 0257d06ba41af075386eb43987f95d445ee895d4 Mon Sep 17 00:00:00 2001
From: Roman Bogorodskiy
Date: Mon, 21 Jul 2014 18:38:42 +0400
Subject: [PATCH] storage: ZFS support
Implement ZFS storage backend driver. Currently supported
only on FreeBSD because of ZFS limitations on Linux.
Features supported:
- pool-start, pool-stop
- pool-info
- vol-list
- vol-create / vol-delete
Pool definition looks like that:
myzfspool
The 'actualpoolname' value is a name of the pool on the system,
such as shown by 'zpool list' command. Target makes no sense
here because volumes path is always /dev/zvol/$poolname/$volname.
User has to create a pool on his own, this driver doesn't
support pool creation currently.
A volume could be used with Qemu by adding an entry like this:
---
configure.ac | 43 ++++
docs/schemas/storagepool.rng | 20 ++
docs/storage.html.in | 34 +++
include/libvirt/libvirt.h.in | 1 +
po/POTFILES.in | 1 +
src/Makefile.am | 8 +
src/conf/storage_conf.c | 15 +-
src/conf/storage_conf.h | 4 +-
src/qemu/qemu_conf.c | 1 +
src/storage/storage_backend.c | 6 +
src/storage/storage_backend_zfs.c | 329 ++++++++++++++++++++++++++++++
src/storage/storage_backend_zfs.h | 29 +++
src/storage/storage_driver.c | 1 +
tools/virsh-pool.c | 3 +
14 files changed, 492 insertions(+), 3 deletions(-)
create mode 100644 src/storage/storage_backend_zfs.c
create mode 100644 src/storage/storage_backend_zfs.h
diff --git a/configure.ac b/configure.ac
index 9dd07d27ef..081f2981cf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1734,6 +1734,10 @@ AC_ARG_WITH([storage-gluster],
[AS_HELP_STRING([--with-storage-gluster],
[with Gluster backend for the storage driver @<:@default=check@:>@])],
[],[with_storage_gluster=check])
+AC_ARG_WITH([storage-zfs],
+ [AS_HELP_STRING([--with-storage-zfs],
+ [with ZFS backend for the storage driver @<:@default=check@:>@])],
+ [],[with_storage_zfs=check])
if test "$with_libvirtd" = "no"; then
with_storage_dir=no
@@ -1746,6 +1750,7 @@ if test "$with_libvirtd" = "no"; then
with_storage_rbd=no
with_storage_sheepdog=no
with_storage_gluster=no
+ with_storage_zfs=no
fi
if test "$with_storage_dir" = "yes" ; then
AC_DEFINE_UNQUOTED([WITH_STORAGE_DIR], 1, [whether directory backend for storage driver is enabled])
@@ -1963,6 +1968,43 @@ if test "$with_storage_gluster" = "yes"; then
fi
AM_CONDITIONAL([WITH_STORAGE_GLUSTER], [test "$with_storage_gluster" = "yes"])
+if test "$with_storage_zfs" = "check"; then
+ with_storage_zfs=$with_freebsd
+fi
+
+if test "$with_storage_zfs" = "yes" && test "$with_freebsd" = "no"; then
+ AC_MSG_ERROR([The ZFS storage driver can be enabled on FreeBSD only.])
+fi
+
+if test "$with_storage_zfs" = "yes" ||
+ test "$with_storage_zfs" = "check"; then
+ AC_PATH_PROG([ZFS], [zfs], [], [$PATH:/sbin:/usr/sbin])
+ AC_PATH_PROG([ZPOOL], [zpool], [], [$PATH:/sbin:/usr/sbin])
+
+ if test "$with_storage_zfs" = "yes"; then
+ if test -z "$ZFS" || test -z "$ZPOOL"; then
+ AC_MSG_ERROR([We need zfs and zpool for ZFS storage driver])
+ fi
+ else
+ if test -z "$ZFS" || test -z "$ZPOOL"; then
+ with_storage_zfs=no
+ fi
+
+ if test "$with_storage_zfs" = "check"; then
+ with_storage_zfs=yes
+ fi
+ fi
+
+ if test "$with_storage_zfs" = "yes"; then
+ AC_DEFINE_UNQUOTED([WITH_STORAGE_ZFS], 1,
+ [whether ZFS backend for storage driver is enabled])
+ AC_DEFINE_UNQUOTED([ZFS], ["$ZFS"], [Location of zfs program])
+ AC_DEFINE_UNQUOTED([ZPOOL], ["$ZPOOL"], [Location of zpool program])
+ fi
+fi
+AM_CONDITIONAL([WITH_STORAGE_ZFS],
+ [test "$with_storage_zfs" = "yes"])
+
if test "$with_storage_fs" = "yes" ||
test "$with_storage_gluster" = "yes"; then
AC_PATH_PROG([GLUSTER_CLI], [gluster], [], [$PATH:/sbin:/usr/sbin])
@@ -2806,6 +2848,7 @@ AC_MSG_NOTICE([ Disk: $with_storage_disk])
AC_MSG_NOTICE([ RBD: $with_storage_rbd])
AC_MSG_NOTICE([Sheepdog: $with_storage_sheepdog])
AC_MSG_NOTICE([ Gluster: $with_storage_gluster])
+AC_MSG_NOTICE([ ZFS: $with_storage_zfs])
AC_MSG_NOTICE([])
AC_MSG_NOTICE([Security Drivers])
AC_MSG_NOTICE([])
diff --git a/docs/schemas/storagepool.rng b/docs/schemas/storagepool.rng
index b2d1473309..908cc1129d 100644
--- a/docs/schemas/storagepool.rng
+++ b/docs/schemas/storagepool.rng
@@ -22,6 +22,7 @@
+
@@ -157,6 +158,17 @@
+
+
+ zfs
+
+
+
+
+
+
+
+
@@ -370,6 +382,14 @@
+
+
+
+
+
+
+
+
diff --git a/docs/storage.html.in b/docs/storage.html.in
index eb38b16abf..5db79c7ae4 100644
--- a/docs/storage.html.in
+++ b/docs/storage.html.in
@@ -117,6 +117,9 @@
+ This provides a pool based on the ZFS filesystem. It is currently
+ supported on FreeBSD only.
+
+ A pool has to be created before libvirt could start using it. That
+ could be done using zpool create command. Please refer to
+ the ZFS documentation for details on a pool creation.
+
+ Since 1.2.8
+