[libvirt] [PATCH 0/3 v4] Add filesystem pool formatting

The following patches add the ability to format filesystem pools when the appropriate flags are passed to pool build. This patch set introduces two new flags: VIR_STORAGE_POOL_BUILD_NO_OVERWRITE causes the build to probe for an existing pool of the requested type. The build operation formats the filesystem if it does not find an existing filesystem of that type. VIR_STORAGE_POOL_BUILD_OVERWRITE causes the build to format unconditionally. This patch set is mainly based on v3 by Dave Allan. http://www.redhat.com/archives/libvir-list/2010-June/msg00042.html [PATCH 1/3] storage: Add mkfs and libblkid to build system [PATCH 2/3] storage: Add fs pool formatting [PATCH 3/3] storage: Add virsh support for fs pool formating Regards, Osier

--- configure.ac | 26 ++++++++++++++++++++++++++ libvirt.spec.in | 4 ++++ 2 files changed, 30 insertions(+), 0 deletions(-) diff --git a/configure.ac b/configure.ac index 3c08a19..5e3539f 100644 --- a/configure.ac +++ b/configure.ac @@ -73,6 +73,7 @@ OPENWSMAN_REQUIRED="2.2.3" LIBPCAP_REQUIRED="1.0.0" LIBNL_REQUIRED="1.1" LIBSSH2_REQUIRED="1.0" +LIBBLKID_REQUIRED="2.17" dnl Checks for C compiler. AC_PROG_CC @@ -1643,12 +1644,15 @@ fi if test "$with_storage_fs" = "yes" || test "$with_storage_fs" = "check"; then AC_PATH_PROG([MOUNT], [mount], [], [$PATH:/sbin:/usr/sbin]) AC_PATH_PROG([UMOUNT], [umount], [], [$PATH:/sbin:/usr/sbin]) + AC_PATH_PROG([MKFS], [mkfs], [], [$PATH:/sbin:/usr/sbin]) if test "$with_storage_fs" = "yes" ; then if test -z "$MOUNT" ; then AC_MSG_ERROR([We need mount for FS storage driver]) ; fi if test -z "$UMOUNT" ; then AC_MSG_ERROR([We need umount for FS storage driver]) ; fi + if test -z "$MKFS" ; then AC_MSG_ERROR([We need mkfs for FS storage driver]) ; fi else if test -z "$MOUNT" ; then with_storage_fs=no ; fi if test -z "$UMOUNT" ; then with_storage_fs=no ; fi + if test -z "$MKFS" ; then with_storage_fs=no ; fi if test "$with_storage_fs" = "check" ; then with_storage_fs=yes ; fi fi @@ -1659,6 +1663,8 @@ if test "$with_storage_fs" = "yes" || test "$with_storage_fs" = "check"; then [Location or name of the mount program]) AC_DEFINE_UNQUOTED([UMOUNT],["$UMOUNT"], [Location or name of the mount program]) + AC_DEFINE_UNQUOTED([MKFS],["$MKFS"], + [Location or name of the mkfs program]) fi fi AM_CONDITIONAL([WITH_STORAGE_FS], [test "$with_storage_fs" = "yes"]) @@ -2304,6 +2310,26 @@ if test "$with_nwfilter" = "yes" ; then fi AM_CONDITIONAL([WITH_NWFILTER], [test "$with_nwfilter" = "yes"]) +dnl libblkid is used by several storage drivers; therefore we probe +dnl for it unconditionally. +AC_ARG_WITH([libblkid], + [AS_HELP_STRING([--with-libblkid], + [use libblkid to scan for filesystems and partitions @<:@default=check@:>@])], + [], + [with_libblkid=check]) + +if test "x$with_libblkid" = "xyes" || test "x$with_libblkid" = "xcheck"; then + PKG_CHECK_MODULES([BLKID], + [blkid >= $LIBBLKID_REQUIRED], + [with_libblkid="yes"], + [with_libblkid="no"]) +fi + +if test "x$with_libblkid" = "xyes"; then + AC_DEFINE([HAVE_LIBBLKID], [1], [libblkid is present]) +fi +AM_CONDITIONAL([HAVE_LIBBLKID], [test "x$with_libblkid" = "xyes"]) + AC_ARG_WITH([qemu-user], AC_HELP_STRING([--with-qemu-user], [username to run QEMU system instance as @<:@default=root@:>@]), [QEMU_USER=${withval}], diff --git a/libvirt.spec.in b/libvirt.spec.in index f4da969..a7bcfd7 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -281,6 +281,10 @@ Requires: PolicyKit >= 0.6 %endif %if %{with_storage_fs} Requires: nfs-utils +# For mkfs +Requires: util-linux-ng +# For pool-build probing for existing pools +BuildRequires: libblkid-devel >= 2.17 # For glusterfs %if 0%{?fedora} >= 11 Requires: glusterfs-client >= 2.0.1 -- 1.7.6

On Wed, Aug 31, 2011 at 10:34:46PM +0800, Osier Yang wrote:
--- configure.ac | 26 ++++++++++++++++++++++++++ libvirt.spec.in | 4 ++++ 2 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/configure.ac b/configure.ac index 3c08a19..5e3539f 100644 --- a/configure.ac +++ b/configure.ac @@ -73,6 +73,7 @@ OPENWSMAN_REQUIRED="2.2.3" LIBPCAP_REQUIRED="1.0.0" LIBNL_REQUIRED="1.1" LIBSSH2_REQUIRED="1.0" +LIBBLKID_REQUIRED="2.17"
dnl Checks for C compiler. AC_PROG_CC @@ -1643,12 +1644,15 @@ fi if test "$with_storage_fs" = "yes" || test "$with_storage_fs" = "check"; then AC_PATH_PROG([MOUNT], [mount], [], [$PATH:/sbin:/usr/sbin]) AC_PATH_PROG([UMOUNT], [umount], [], [$PATH:/sbin:/usr/sbin]) + AC_PATH_PROG([MKFS], [mkfs], [], [$PATH:/sbin:/usr/sbin]) if test "$with_storage_fs" = "yes" ; then if test -z "$MOUNT" ; then AC_MSG_ERROR([We need mount for FS storage driver]) ; fi if test -z "$UMOUNT" ; then AC_MSG_ERROR([We need umount for FS storage driver]) ; fi + if test -z "$MKFS" ; then AC_MSG_ERROR([We need mkfs for FS storage driver]) ; fi else if test -z "$MOUNT" ; then with_storage_fs=no ; fi if test -z "$UMOUNT" ; then with_storage_fs=no ; fi + if test -z "$MKFS" ; then with_storage_fs=no ; fi
if test "$with_storage_fs" = "check" ; then with_storage_fs=yes ; fi fi @@ -1659,6 +1663,8 @@ if test "$with_storage_fs" = "yes" || test "$with_storage_fs" = "check"; then [Location or name of the mount program]) AC_DEFINE_UNQUOTED([UMOUNT],["$UMOUNT"], [Location or name of the mount program]) + AC_DEFINE_UNQUOTED([MKFS],["$MKFS"], + [Location or name of the mkfs program]) fi fi AM_CONDITIONAL([WITH_STORAGE_FS], [test "$with_storage_fs" = "yes"]) @@ -2304,6 +2310,26 @@ if test "$with_nwfilter" = "yes" ; then fi AM_CONDITIONAL([WITH_NWFILTER], [test "$with_nwfilter" = "yes"])
+dnl libblkid is used by several storage drivers; therefore we probe +dnl for it unconditionally. +AC_ARG_WITH([libblkid], + [AS_HELP_STRING([--with-libblkid], + [use libblkid to scan for filesystems and partitions @<:@default=check@:>@])], + [], + [with_libblkid=check]) + +if test "x$with_libblkid" = "xyes" || test "x$with_libblkid" = "xcheck"; then + PKG_CHECK_MODULES([BLKID], + [blkid >= $LIBBLKID_REQUIRED], + [with_libblkid="yes"], + [with_libblkid="no"]) +fi + +if test "x$with_libblkid" = "xyes"; then + AC_DEFINE([HAVE_LIBBLKID], [1], [libblkid is present]) +fi +AM_CONDITIONAL([HAVE_LIBBLKID], [test "x$with_libblkid" = "xyes"]) + AC_ARG_WITH([qemu-user], AC_HELP_STRING([--with-qemu-user], [username to run QEMU system instance as @<:@default=root@:>@]), [QEMU_USER=${withval}], diff --git a/libvirt.spec.in b/libvirt.spec.in index f4da969..a7bcfd7 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -281,6 +281,10 @@ Requires: PolicyKit >= 0.6 %endif %if %{with_storage_fs} Requires: nfs-utils +# For mkfs +Requires: util-linux-ng +# For pool-build probing for existing pools +BuildRequires: libblkid-devel >= 2.17
We may have to tweak this if it's not available for example on RHEL5 but okay for now
# For glusterfs %if 0%{?fedora} >= 11 Requires: glusterfs-client >= 2.0.1
ACK, but should be commited without the other 2 patches Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

于 2011年09月02日 19:11, Daniel Veillard 写道:
On Wed, Aug 31, 2011 at 10:34:46PM +0800, Osier Yang wrote:
--- configure.ac | 26 ++++++++++++++++++++++++++ libvirt.spec.in | 4 ++++ 2 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/configure.ac b/configure.ac index 3c08a19..5e3539f 100644 --- a/configure.ac +++ b/configure.ac @@ -73,6 +73,7 @@ OPENWSMAN_REQUIRED="2.2.3" LIBPCAP_REQUIRED="1.0.0" LIBNL_REQUIRED="1.1" LIBSSH2_REQUIRED="1.0" +LIBBLKID_REQUIRED="2.17"
dnl Checks for C compiler. AC_PROG_CC @@ -1643,12 +1644,15 @@ fi if test "$with_storage_fs" = "yes" || test "$with_storage_fs" = "check"; then AC_PATH_PROG([MOUNT], [mount], [], [$PATH:/sbin:/usr/sbin]) AC_PATH_PROG([UMOUNT], [umount], [], [$PATH:/sbin:/usr/sbin]) + AC_PATH_PROG([MKFS], [mkfs], [], [$PATH:/sbin:/usr/sbin]) if test "$with_storage_fs" = "yes" ; then if test -z "$MOUNT" ; then AC_MSG_ERROR([We need mount for FS storage driver]) ; fi if test -z "$UMOUNT" ; then AC_MSG_ERROR([We need umount for FS storage driver]) ; fi + if test -z "$MKFS" ; then AC_MSG_ERROR([We need mkfs for FS storage driver]) ; fi else if test -z "$MOUNT" ; then with_storage_fs=no ; fi if test -z "$UMOUNT" ; then with_storage_fs=no ; fi + if test -z "$MKFS" ; then with_storage_fs=no ; fi
if test "$with_storage_fs" = "check" ; then with_storage_fs=yes ; fi fi @@ -1659,6 +1663,8 @@ if test "$with_storage_fs" = "yes" || test "$with_storage_fs" = "check"; then [Location or name of the mount program]) AC_DEFINE_UNQUOTED([UMOUNT],["$UMOUNT"], [Location or name of the mount program]) + AC_DEFINE_UNQUOTED([MKFS],["$MKFS"], + [Location or name of the mkfs program]) fi fi AM_CONDITIONAL([WITH_STORAGE_FS], [test "$with_storage_fs" = "yes"]) @@ -2304,6 +2310,26 @@ if test "$with_nwfilter" = "yes" ; then fi AM_CONDITIONAL([WITH_NWFILTER], [test "$with_nwfilter" = "yes"])
+dnl libblkid is used by several storage drivers; therefore we probe +dnl for it unconditionally. +AC_ARG_WITH([libblkid], + [AS_HELP_STRING([--with-libblkid], + [use libblkid to scan for filesystems and partitions @<:@default=check@:>@])], + [], + [with_libblkid=check]) + +if test "x$with_libblkid" = "xyes" || test "x$with_libblkid" = "xcheck"; then + PKG_CHECK_MODULES([BLKID], + [blkid>= $LIBBLKID_REQUIRED], + [with_libblkid="yes"], + [with_libblkid="no"]) +fi + +if test "x$with_libblkid" = "xyes"; then + AC_DEFINE([HAVE_LIBBLKID], [1], [libblkid is present]) +fi +AM_CONDITIONAL([HAVE_LIBBLKID], [test "x$with_libblkid" = "xyes"]) + AC_ARG_WITH([qemu-user], AC_HELP_STRING([--with-qemu-user], [username to run QEMU system instance as @<:@default=root@:>@]), [QEMU_USER=${withval}], diff --git a/libvirt.spec.in b/libvirt.spec.in index f4da969..a7bcfd7 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -281,6 +281,10 @@ Requires: PolicyKit>= 0.6 %endif %if %{with_storage_fs} Requires: nfs-utils +# For mkfs +Requires: util-linux-ng +# For pool-build probing for existing pools +BuildRequires: libblkid-devel>= 2.17 We may have to tweak this if it's not available for example on RHEL5 but okay for now
# For glusterfs %if 0%{?fedora}>= 11 Requires: glusterfs-client>= 2.0.1 ACK, but should be commited without the other 2 patches
Aren't the other 2 patches also ACKed? :-) Osier

On Fri, Sep 02, 2011 at 07:19:46PM +0800, Osier Yang wrote:
于 2011年09月02日 19:11, Daniel Veillard 写道:
On Wed, Aug 31, 2011 at 10:34:46PM +0800, Osier Yang wrote:
--- configure.ac | 26 ++++++++++++++++++++++++++ libvirt.spec.in | 4 ++++ 2 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/configure.ac b/configure.ac index 3c08a19..5e3539f 100644 --- a/configure.ac +++ b/configure.ac @@ -73,6 +73,7 @@ OPENWSMAN_REQUIRED="2.2.3" LIBPCAP_REQUIRED="1.0.0" LIBNL_REQUIRED="1.1" LIBSSH2_REQUIRED="1.0" +LIBBLKID_REQUIRED="2.17"
dnl Checks for C compiler. AC_PROG_CC @@ -1643,12 +1644,15 @@ fi if test "$with_storage_fs" = "yes" || test "$with_storage_fs" = "check"; then AC_PATH_PROG([MOUNT], [mount], [], [$PATH:/sbin:/usr/sbin]) AC_PATH_PROG([UMOUNT], [umount], [], [$PATH:/sbin:/usr/sbin]) + AC_PATH_PROG([MKFS], [mkfs], [], [$PATH:/sbin:/usr/sbin]) if test "$with_storage_fs" = "yes" ; then if test -z "$MOUNT" ; then AC_MSG_ERROR([We need mount for FS storage driver]) ; fi if test -z "$UMOUNT" ; then AC_MSG_ERROR([We need umount for FS storage driver]) ; fi + if test -z "$MKFS" ; then AC_MSG_ERROR([We need mkfs for FS storage driver]) ; fi else if test -z "$MOUNT" ; then with_storage_fs=no ; fi if test -z "$UMOUNT" ; then with_storage_fs=no ; fi + if test -z "$MKFS" ; then with_storage_fs=no ; fi
if test "$with_storage_fs" = "check" ; then with_storage_fs=yes ; fi fi @@ -1659,6 +1663,8 @@ if test "$with_storage_fs" = "yes" || test "$with_storage_fs" = "check"; then [Location or name of the mount program]) AC_DEFINE_UNQUOTED([UMOUNT],["$UMOUNT"], [Location or name of the mount program]) + AC_DEFINE_UNQUOTED([MKFS],["$MKFS"], + [Location or name of the mkfs program]) fi fi AM_CONDITIONAL([WITH_STORAGE_FS], [test "$with_storage_fs" = "yes"]) @@ -2304,6 +2310,26 @@ if test "$with_nwfilter" = "yes" ; then fi AM_CONDITIONAL([WITH_NWFILTER], [test "$with_nwfilter" = "yes"])
+dnl libblkid is used by several storage drivers; therefore we probe +dnl for it unconditionally. +AC_ARG_WITH([libblkid], + [AS_HELP_STRING([--with-libblkid], + [use libblkid to scan for filesystems and partitions @<:@default=check@:>@])], + [], + [with_libblkid=check]) + +if test "x$with_libblkid" = "xyes" || test "x$with_libblkid" = "xcheck"; then + PKG_CHECK_MODULES([BLKID], + [blkid>= $LIBBLKID_REQUIRED], + [with_libblkid="yes"], + [with_libblkid="no"]) +fi + +if test "x$with_libblkid" = "xyes"; then + AC_DEFINE([HAVE_LIBBLKID], [1], [libblkid is present]) +fi +AM_CONDITIONAL([HAVE_LIBBLKID], [test "x$with_libblkid" = "xyes"]) + AC_ARG_WITH([qemu-user], AC_HELP_STRING([--with-qemu-user], [username to run QEMU system instance as @<:@default=root@:>@]), [QEMU_USER=${withval}], diff --git a/libvirt.spec.in b/libvirt.spec.in index f4da969..a7bcfd7 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -281,6 +281,10 @@ Requires: PolicyKit>= 0.6 %endif %if %{with_storage_fs} Requires: nfs-utils +# For mkfs +Requires: util-linux-ng +# For pool-build probing for existing pools +BuildRequires: libblkid-devel>= 2.17 We may have to tweak this if it's not available for example on RHEL5 but okay for now
# For glusterfs %if 0%{?fedora}>= 11 Requires: glusterfs-client>= 2.0.1 ACK, but should be commited without the other 2 patches
Aren't the other 2 patches also ACKed? :-)
Now yes but at the time I didn't know :-) Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

于 2011年09月02日 19:34, Daniel Veillard 写道:
On Fri, Sep 02, 2011 at 07:19:46PM +0800, Osier Yang wrote:
于 2011年09月02日 19:11, Daniel Veillard 写道:
On Wed, Aug 31, 2011 at 10:34:46PM +0800, Osier Yang wrote:
--- configure.ac | 26 ++++++++++++++++++++++++++ libvirt.spec.in | 4 ++++ 2 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/configure.ac b/configure.ac index 3c08a19..5e3539f 100644 --- a/configure.ac +++ b/configure.ac @@ -73,6 +73,7 @@ OPENWSMAN_REQUIRED="2.2.3" LIBPCAP_REQUIRED="1.0.0" LIBNL_REQUIRED="1.1" LIBSSH2_REQUIRED="1.0" +LIBBLKID_REQUIRED="2.17"
dnl Checks for C compiler. AC_PROG_CC @@ -1643,12 +1644,15 @@ fi if test "$with_storage_fs" = "yes" || test "$with_storage_fs" = "check"; then AC_PATH_PROG([MOUNT], [mount], [], [$PATH:/sbin:/usr/sbin]) AC_PATH_PROG([UMOUNT], [umount], [], [$PATH:/sbin:/usr/sbin]) + AC_PATH_PROG([MKFS], [mkfs], [], [$PATH:/sbin:/usr/sbin]) if test "$with_storage_fs" = "yes" ; then if test -z "$MOUNT" ; then AC_MSG_ERROR([We need mount for FS storage driver]) ; fi if test -z "$UMOUNT" ; then AC_MSG_ERROR([We need umount for FS storage driver]) ; fi + if test -z "$MKFS" ; then AC_MSG_ERROR([We need mkfs for FS storage driver]) ; fi else if test -z "$MOUNT" ; then with_storage_fs=no ; fi if test -z "$UMOUNT" ; then with_storage_fs=no ; fi + if test -z "$MKFS" ; then with_storage_fs=no ; fi
if test "$with_storage_fs" = "check" ; then with_storage_fs=yes ; fi fi @@ -1659,6 +1663,8 @@ if test "$with_storage_fs" = "yes" || test "$with_storage_fs" = "check"; then [Location or name of the mount program]) AC_DEFINE_UNQUOTED([UMOUNT],["$UMOUNT"], [Location or name of the mount program]) + AC_DEFINE_UNQUOTED([MKFS],["$MKFS"], + [Location or name of the mkfs program]) fi fi AM_CONDITIONAL([WITH_STORAGE_FS], [test "$with_storage_fs" = "yes"]) @@ -2304,6 +2310,26 @@ if test "$with_nwfilter" = "yes" ; then fi AM_CONDITIONAL([WITH_NWFILTER], [test "$with_nwfilter" = "yes"])
+dnl libblkid is used by several storage drivers; therefore we probe +dnl for it unconditionally. +AC_ARG_WITH([libblkid], + [AS_HELP_STRING([--with-libblkid], + [use libblkid to scan for filesystems and partitions @<:@default=check@:>@])], + [], + [with_libblkid=check]) + +if test "x$with_libblkid" = "xyes" || test "x$with_libblkid" = "xcheck"; then + PKG_CHECK_MODULES([BLKID], + [blkid>= $LIBBLKID_REQUIRED], + [with_libblkid="yes"], + [with_libblkid="no"]) +fi + +if test "x$with_libblkid" = "xyes"; then + AC_DEFINE([HAVE_LIBBLKID], [1], [libblkid is present]) +fi +AM_CONDITIONAL([HAVE_LIBBLKID], [test "x$with_libblkid" = "xyes"]) + AC_ARG_WITH([qemu-user], AC_HELP_STRING([--with-qemu-user], [username to run QEMU system instance as @<:@default=root@:>@]), [QEMU_USER=${withval}], diff --git a/libvirt.spec.in b/libvirt.spec.in index f4da969..a7bcfd7 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -281,6 +281,10 @@ Requires: PolicyKit>= 0.6 %endif %if %{with_storage_fs} Requires: nfs-utils +# For mkfs +Requires: util-linux-ng +# For pool-build probing for existing pools +BuildRequires: libblkid-devel>= 2.17 We may have to tweak this if it's not available for example on RHEL5 but okay for now
# For glusterfs %if 0%{?fedora}>= 11 Requires: glusterfs-client>= 2.0.1 ACK, but should be commited without the other 2 patches Aren't the other 2 patches also ACKed? :-) Now yes but at the time I didn't know :-)
Daniel
I pushed these patchset as-is, will add test case and improve spec file in a following patch later. Thanks for the reviewing. Osier

This patch adds the ability to make the filesystem for a filesystem pool during a pool build. The patch adds two new flags, no overwrite and overwrite, to control when mkfs gets executed. By default, the patch preserves the current behavior, i.e., if no flags are specified, pool build on a filesystem pool only makes the directory on which the filesystem will be mounted. If the no overwrite flag is specified, the target device is checked to determine if a filesystem of the type specified in the pool is present. If a filesystem of that type is already present, mkfs is not executed and the build call returns an error. Otherwise, mkfs is executed and any data present on the device is overwritten. If the overwrite flag is specified, mkfs is always executed, and any existing data on the target device is overwritten unconditionally. --- include/libvirt/libvirt.h.in | 6 +- include/libvirt/virterror.h | 2 + src/Makefile.am | 4 + src/libvirt.c | 4 + src/storage/storage_backend_fs.c | 188 +++++++++++++++++++++++++++++++++++++- src/storage/storage_backend_fs.h | 5 + src/util/virterror.c | 12 +++ 7 files changed, 215 insertions(+), 6 deletions(-) diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index c51a5b9..92e1d62 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -1666,8 +1666,10 @@ typedef enum { typedef enum { VIR_STORAGE_POOL_BUILD_NEW = 0, /* Regular build from scratch */ - VIR_STORAGE_POOL_BUILD_REPAIR = 1, /* Repair / reinitialize */ - VIR_STORAGE_POOL_BUILD_RESIZE = 2 /* Extend existing pool */ + VIR_STORAGE_POOL_BUILD_REPAIR = (1 << 0), /* Repair / reinitialize */ + VIR_STORAGE_POOL_BUILD_RESIZE = (1 << 1), /* Extend existing pool */ + VIR_STORAGE_POOL_BUILD_NO_OVERWRITE = (1 << 2), /* Do not overwrite existing pool */ + VIR_STORAGE_POOL_BUILD_OVERWRITE = (1 << 3), /* Overwrite data */ } virStoragePoolBuildFlags; typedef enum { diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h index c270b54..0aae622 100644 --- a/include/libvirt/virterror.h +++ b/include/libvirt/virterror.h @@ -235,6 +235,8 @@ typedef enum { VIR_ERR_INVALID_STREAM = 73, /* stream pointer not valid */ VIR_ERR_ARGUMENT_UNSUPPORTED = 74, /* valid API use but unsupported by the given driver */ + VIR_ERR_STORAGE_PROBE_FAILED = 75, /* storage pool proble failed */ + VIR_ERR_STORAGE_POOL_BUILT = 76, /* storage pool already built */ } virErrorNumber; /** diff --git a/src/Makefile.am b/src/Makefile.am index 322c900..14f09e4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -954,6 +954,10 @@ endif if WITH_SECDRIVER_APPARMOR libvirt_driver_storage_la_LIBADD += $(APPARMOR_LIBS) endif +if HAVE_LIBBLKID +libvirt_driver_storage_la_CFLAGS += $(BLKID_CFLAGS) +libvirt_driver_storage_la_LIBADD += $(BLKID_LIBS) +endif if WITH_STORAGE_DIR if WITH_DRIVER_MODULES mod_LTLIBRARIES += libvirt_driver_storage.la diff --git a/src/libvirt.c b/src/libvirt.c index e4a21b6..b876b1c 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -10466,6 +10466,10 @@ error: * virStoragePoolBuild: * @pool: pointer to storage pool * @flags: future flags, use 0 for now + * @flags: flags to control pool build behaviour + * + * Currently only filesystem pool accepts flags VIR_STORAGE_POOL_BUILD_OVERWRITE + * and VIR_STORAGE_POOL_BUILD_NO_OVERWRITE. * * Build the underlying storage pool * diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index 4f53d3f..36f1c60 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -37,6 +37,10 @@ #include <libxml/tree.h> #include <libxml/xpath.h> +#if HAVE_LIBBLKID +# include <blkid/blkid.h> +#endif + #include "virterror_internal.h" #include "storage_backend_fs.h" #include "storage_conf.h" @@ -45,6 +49,7 @@ #include "memory.h" #include "xml.h" #include "virfile.h" +#include "logging.h" #define VIR_FROM_THIS VIR_FROM_STORAGE @@ -534,13 +539,172 @@ virStorageBackendFileSystemStart(virConnectPtr conn ATTRIBUTE_UNUSED, } #endif /* WITH_STORAGE_FS */ +#if HAVE_LIBBLKID +static virStoragePoolProbeResult +virStorageBackendFileSystemProbe(const char *device, + const char *format) { + + virStoragePoolProbeResult ret = FILESYSTEM_PROBE_ERROR; + blkid_probe probe = NULL; + const char *fstype = NULL; + char *names[2], *libblkid_format = NULL; + + VIR_DEBUG("Probing for existing filesystem of type %s on device %s", + format, device); + + if (blkid_known_fstype(format) == 0) { + virStorageReportError(VIR_ERR_STORAGE_PROBE_FAILED, + _("Not capable of probing for " + "filesystem of type %s"), + format); + goto error; + } + + probe = blkid_new_probe_from_filename(device); + if (probe == NULL) { + virStorageReportError(VIR_ERR_STORAGE_PROBE_FAILED, + _("Failed to create filesystem probe " + "for device %s"), + device); + goto error; + } + + if ((libblkid_format = strdup(format)) == NULL) { + virReportOOMError(); + goto error; + } + + names[0] = libblkid_format; + names[1] = NULL; + + blkid_probe_filter_superblocks_type(probe, + BLKID_FLTR_ONLYIN, + names); + + if (blkid_do_probe(probe) != 0) { + VIR_INFO("No filesystem of type '%s' found on device '%s'", + format, device); + ret = FILESYSTEM_PROBE_NOT_FOUND; + } else if (blkid_probe_lookup_value(probe, "TYPE", &fstype, NULL) == 0) { + virStorageReportError(VIR_ERR_STORAGE_POOL_BUILT, + _("Existing filesystem of type '%s' found on " + "device '%s'"), + fstype, device); + ret = FILESYSTEM_PROBE_FOUND; + } + + if (blkid_do_probe(probe) != 1) { + virStorageReportError(VIR_ERR_STORAGE_PROBE_FAILED, + _("Found additional probes to run, " + "filesystem probing may be incorrect")); + ret = FILESYSTEM_PROBE_ERROR; + } + +error: + VIR_FREE(libblkid_format); + + if (probe != NULL) { + blkid_free_probe(probe); + } + + return ret; +} + +#else /* #if HAVE_LIBBLKID */ + +static virStoragePoolProbeResult +virStorageBackendFileSystemProbe(const char *device ATTRIBUTE_UNUSED, + const char *format ATTRIBUTE_UNUSED) +{ + virStorageReportError(VIR_ERR_OPERATION_INVALID, + _("probing for filesystems is unsupported " + "by this build")); + + return FILESYSTEM_PROBE_ERROR; +} + +#endif /* #if HAVE_LIBBLKID */ + +static int +virStorageBackendExecuteMKFS(const char *device, + const char *format) +{ + int ret = 0; + virCommandPtr cmd = NULL; + + cmd = virCommandNewArgList(MKFS, + "-t", + format, + device, + NULL); + + if (virCommandRun(cmd, NULL) < 0) { + virReportSystemError(errno, + _("Failed to make filesystem of " + "type '%s' on device '%s'"), + format, device); + ret = -1; + } + return ret; +} + +static int +virStorageBackendMakeFileSystem(virStoragePoolObjPtr pool, + unsigned int flags) +{ + const char *device = NULL, *format = NULL; + bool ok_to_mkfs = false; + int ret = -1; + + if (pool->def->source.devices == NULL) { + virStorageReportError(VIR_ERR_OPERATION_INVALID, + _("No source device specified when formatting pool '%s'"), + pool->def->name); + goto error; + } + + device = pool->def->source.devices[0].path; + format = virStoragePoolFormatFileSystemTypeToString(pool->def->source.format); + VIR_DEBUG("source device: '%s' format: '%s'", device, format); + + if (!virFileExists(device)) { + virStorageReportError(VIR_ERR_OPERATION_INVALID, + _("Source device does not exist when formatting pool '%s'"), + pool->def->name); + goto error; + } + + if (flags & VIR_STORAGE_POOL_BUILD_OVERWRITE) { + ok_to_mkfs = true; + } else if (flags & VIR_STORAGE_POOL_BUILD_NO_OVERWRITE && + virStorageBackendFileSystemProbe(device, format) == + FILESYSTEM_PROBE_NOT_FOUND) { + ok_to_mkfs = true; + } + + if (ok_to_mkfs) { + ret = virStorageBackendExecuteMKFS(device, format); + } + +error: + return ret; +} + /** * @conn connection to report errors against * @pool storage pool to build + * @flags controls the pool formating behaviour * * Build a directory or FS based storage pool. * + * If no flag is set, it only makes the directory; If + * VIR_STORAGE_POOL_BUILD_NO_OVERWRITE set, it probes to determine if + * filesystem already exists on the target device, renurning an error + * if exists, or using mkfs to format the target device if not; If + * VIR_STORAGE_POOL_BUILD_OVERWRITE is set, mkfs is always executed, + * any existed data on the target device is overwritten unconditionally. + * * - If it is a FS based pool, mounts the unlying source device on the pool * * Returns 0 on success, -1 on error @@ -551,10 +715,20 @@ virStorageBackendFileSystemBuild(virConnectPtr conn ATTRIBUTE_UNUSED, unsigned int flags) { int err, ret = -1; - char *parent; - char *p; + char *parent = NULL; + char *p = NULL; - virCheckFlags(0, -1); + virCheckFlags(VIR_STORAGE_POOL_BUILD_OVERWRITE | + VIR_STORAGE_POOL_BUILD_NO_OVERWRITE, ret); + + if (flags == (VIR_STORAGE_POOL_BUILD_OVERWRITE | + VIR_STORAGE_POOL_BUILD_NO_OVERWRITE)) { + + virStorageReportError(VIR_ERR_OPERATION_INVALID, + _("Overwrite and no overwrite flags" + " are mutually exclusive")); + goto error; + } if ((parent = strdup(pool->def->target.path)) == NULL) { virReportOOMError(); @@ -604,7 +778,13 @@ virStorageBackendFileSystemBuild(virConnectPtr conn ATTRIBUTE_UNUSED, goto error; } } - ret = 0; + + if (flags != 0) { + ret = virStorageBackendMakeFileSystem(pool, flags); + } else { + ret = 0; + } + error: VIR_FREE(parent); return ret; diff --git a/src/storage/storage_backend_fs.h b/src/storage/storage_backend_fs.h index 7def53e..54c6739 100644 --- a/src/storage/storage_backend_fs.h +++ b/src/storage/storage_backend_fs.h @@ -29,6 +29,11 @@ # if WITH_STORAGE_FS extern virStorageBackend virStorageBackendFileSystem; extern virStorageBackend virStorageBackendNetFileSystem; +typedef enum { + FILESYSTEM_PROBE_FOUND, + FILESYSTEM_PROBE_NOT_FOUND, + FILESYSTEM_PROBE_ERROR, +} virStoragePoolProbeResult; # endif extern virStorageBackend virStorageBackendDirectory; diff --git a/src/util/virterror.c b/src/util/virterror.c index b50fbfd..26c4981 100644 --- a/src/util/virterror.c +++ b/src/util/virterror.c @@ -1030,6 +1030,18 @@ virErrorMsg(virErrorNumber error, const char *info) else errmsg = _("Storage volume not found: %s"); break; + case VIR_ERR_STORAGE_PROBE_FAILED: + if (info == NULL) + errmsg = _("Storage pool probe failed"); + else + errmsg = _("Storage pool probe failed: %s"); + break; + case VIR_ERR_STORAGE_POOL_BUILT: + if (info == NULL) + errmsg = _("Storage pool already built"); + else + errmsg = _("Storage pool already built: %s"); + break; case VIR_ERR_INVALID_STORAGE_POOL: if (info == NULL) errmsg = _("invalid storage pool pointer in"); -- 1.7.6

On Wed, Aug 31, 2011 at 10:34:47PM +0800, Osier Yang wrote:
This patch adds the ability to make the filesystem for a filesystem pool during a pool build.
The patch adds two new flags, no overwrite and overwrite, to control when mkfs gets executed. By default, the patch preserves the current behavior, i.e., if no flags are specified, pool build on a filesystem pool only makes the directory on which the filesystem will be mounted.
If the no overwrite flag is specified, the target device is checked to determine if a filesystem of the type specified in the pool is present. If a filesystem of that type is already present, mkfs is not executed and the build call returns an error. Otherwise, mkfs is executed and any data present on the device is overwritten.
If the overwrite flag is specified, mkfs is always executed, and any existing data on the target device is overwritten unconditionally. --- include/libvirt/libvirt.h.in | 6 +- include/libvirt/virterror.h | 2 + src/Makefile.am | 4 + src/libvirt.c | 4 + src/storage/storage_backend_fs.c | 188 +++++++++++++++++++++++++++++++++++++- src/storage/storage_backend_fs.h | 5 + src/util/virterror.c | 12 +++ 7 files changed, 215 insertions(+), 6 deletions(-)
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index c51a5b9..92e1d62 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -1666,8 +1666,10 @@ typedef enum {
typedef enum { VIR_STORAGE_POOL_BUILD_NEW = 0, /* Regular build from scratch */ - VIR_STORAGE_POOL_BUILD_REPAIR = 1, /* Repair / reinitialize */ - VIR_STORAGE_POOL_BUILD_RESIZE = 2 /* Extend existing pool */ + VIR_STORAGE_POOL_BUILD_REPAIR = (1 << 0), /* Repair / reinitialize */ + VIR_STORAGE_POOL_BUILD_RESIZE = (1 << 1), /* Extend existing pool */ + VIR_STORAGE_POOL_BUILD_NO_OVERWRITE = (1 << 2), /* Do not overwrite existing pool */ + VIR_STORAGE_POOL_BUILD_OVERWRITE = (1 << 3), /* Overwrite data */ } virStoragePoolBuildFlags;
typedef enum { diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h index c270b54..0aae622 100644 --- a/include/libvirt/virterror.h +++ b/include/libvirt/virterror.h @@ -235,6 +235,8 @@ typedef enum { VIR_ERR_INVALID_STREAM = 73, /* stream pointer not valid */ VIR_ERR_ARGUMENT_UNSUPPORTED = 74, /* valid API use but unsupported by the given driver */ + VIR_ERR_STORAGE_PROBE_FAILED = 75, /* storage pool proble failed */ + VIR_ERR_STORAGE_POOL_BUILT = 76, /* storage pool already built */ } virErrorNumber;
/** diff --git a/src/Makefile.am b/src/Makefile.am index 322c900..14f09e4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -954,6 +954,10 @@ endif if WITH_SECDRIVER_APPARMOR libvirt_driver_storage_la_LIBADD += $(APPARMOR_LIBS) endif +if HAVE_LIBBLKID +libvirt_driver_storage_la_CFLAGS += $(BLKID_CFLAGS) +libvirt_driver_storage_la_LIBADD += $(BLKID_LIBS) +endif if WITH_STORAGE_DIR if WITH_DRIVER_MODULES mod_LTLIBRARIES += libvirt_driver_storage.la diff --git a/src/libvirt.c b/src/libvirt.c index e4a21b6..b876b1c 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -10466,6 +10466,10 @@ error: * virStoragePoolBuild: * @pool: pointer to storage pool * @flags: future flags, use 0 for now + * @flags: flags to control pool build behaviour + * + * Currently only filesystem pool accepts flags VIR_STORAGE_POOL_BUILD_OVERWRITE + * and VIR_STORAGE_POOL_BUILD_NO_OVERWRITE. * * Build the underlying storage pool * diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index 4f53d3f..36f1c60 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -37,6 +37,10 @@ #include <libxml/tree.h> #include <libxml/xpath.h>
+#if HAVE_LIBBLKID +# include <blkid/blkid.h> +#endif + #include "virterror_internal.h" #include "storage_backend_fs.h" #include "storage_conf.h" @@ -45,6 +49,7 @@ #include "memory.h" #include "xml.h" #include "virfile.h" +#include "logging.h"
#define VIR_FROM_THIS VIR_FROM_STORAGE
@@ -534,13 +539,172 @@ virStorageBackendFileSystemStart(virConnectPtr conn ATTRIBUTE_UNUSED, } #endif /* WITH_STORAGE_FS */
+#if HAVE_LIBBLKID +static virStoragePoolProbeResult +virStorageBackendFileSystemProbe(const char *device, + const char *format) { + + virStoragePoolProbeResult ret = FILESYSTEM_PROBE_ERROR; + blkid_probe probe = NULL; + const char *fstype = NULL; + char *names[2], *libblkid_format = NULL; + + VIR_DEBUG("Probing for existing filesystem of type %s on device %s", + format, device); + + if (blkid_known_fstype(format) == 0) { + virStorageReportError(VIR_ERR_STORAGE_PROBE_FAILED, + _("Not capable of probing for " + "filesystem of type %s"), + format); + goto error; + } + + probe = blkid_new_probe_from_filename(device); + if (probe == NULL) { + virStorageReportError(VIR_ERR_STORAGE_PROBE_FAILED, + _("Failed to create filesystem probe " + "for device %s"), + device); + goto error; + } + + if ((libblkid_format = strdup(format)) == NULL) { + virReportOOMError(); + goto error; + } + + names[0] = libblkid_format; + names[1] = NULL; + + blkid_probe_filter_superblocks_type(probe, + BLKID_FLTR_ONLYIN, + names); + + if (blkid_do_probe(probe) != 0) { + VIR_INFO("No filesystem of type '%s' found on device '%s'", + format, device); + ret = FILESYSTEM_PROBE_NOT_FOUND; + } else if (blkid_probe_lookup_value(probe, "TYPE", &fstype, NULL) == 0) { + virStorageReportError(VIR_ERR_STORAGE_POOL_BUILT, + _("Existing filesystem of type '%s' found on " + "device '%s'"), + fstype, device); + ret = FILESYSTEM_PROBE_FOUND; + } + + if (blkid_do_probe(probe) != 1) { + virStorageReportError(VIR_ERR_STORAGE_PROBE_FAILED, + _("Found additional probes to run, " + "filesystem probing may be incorrect")); + ret = FILESYSTEM_PROBE_ERROR; + } + +error: + VIR_FREE(libblkid_format); + + if (probe != NULL) { + blkid_free_probe(probe); + } + + return ret; +} + +#else /* #if HAVE_LIBBLKID */ + +static virStoragePoolProbeResult +virStorageBackendFileSystemProbe(const char *device ATTRIBUTE_UNUSED, + const char *format ATTRIBUTE_UNUSED) +{ + virStorageReportError(VIR_ERR_OPERATION_INVALID, + _("probing for filesystems is unsupported " + "by this build")); + + return FILESYSTEM_PROBE_ERROR; +} + +#endif /* #if HAVE_LIBBLKID */ + +static int +virStorageBackendExecuteMKFS(const char *device, + const char *format) +{ + int ret = 0; + virCommandPtr cmd = NULL; + + cmd = virCommandNewArgList(MKFS, + "-t", + format, + device, + NULL); + + if (virCommandRun(cmd, NULL) < 0) { + virReportSystemError(errno, + _("Failed to make filesystem of " + "type '%s' on device '%s'"), + format, device); + ret = -1; + } + return ret; +} + +static int +virStorageBackendMakeFileSystem(virStoragePoolObjPtr pool, + unsigned int flags) +{ + const char *device = NULL, *format = NULL; + bool ok_to_mkfs = false; + int ret = -1; + + if (pool->def->source.devices == NULL) { + virStorageReportError(VIR_ERR_OPERATION_INVALID, + _("No source device specified when formatting pool '%s'"), + pool->def->name); + goto error; + } + + device = pool->def->source.devices[0].path; + format = virStoragePoolFormatFileSystemTypeToString(pool->def->source.format); + VIR_DEBUG("source device: '%s' format: '%s'", device, format); + + if (!virFileExists(device)) { + virStorageReportError(VIR_ERR_OPERATION_INVALID, + _("Source device does not exist when formatting pool '%s'"), + pool->def->name); + goto error; + } + + if (flags & VIR_STORAGE_POOL_BUILD_OVERWRITE) { + ok_to_mkfs = true; + } else if (flags & VIR_STORAGE_POOL_BUILD_NO_OVERWRITE && + virStorageBackendFileSystemProbe(device, format) == + FILESYSTEM_PROBE_NOT_FOUND) { + ok_to_mkfs = true; + } + + if (ok_to_mkfs) { + ret = virStorageBackendExecuteMKFS(device, format); + } + +error: + return ret; +} +
/** * @conn connection to report errors against * @pool storage pool to build + * @flags controls the pool formating behaviour * * Build a directory or FS based storage pool. * + * If no flag is set, it only makes the directory; If + * VIR_STORAGE_POOL_BUILD_NO_OVERWRITE set, it probes to determine if + * filesystem already exists on the target device, renurning an error + * if exists, or using mkfs to format the target device if not; If + * VIR_STORAGE_POOL_BUILD_OVERWRITE is set, mkfs is always executed, + * any existed data on the target device is overwritten unconditionally. + * * - If it is a FS based pool, mounts the unlying source device on the pool * * Returns 0 on success, -1 on error @@ -551,10 +715,20 @@ virStorageBackendFileSystemBuild(virConnectPtr conn ATTRIBUTE_UNUSED, unsigned int flags) { int err, ret = -1; - char *parent; - char *p; + char *parent = NULL; + char *p = NULL;
- virCheckFlags(0, -1); + virCheckFlags(VIR_STORAGE_POOL_BUILD_OVERWRITE | + VIR_STORAGE_POOL_BUILD_NO_OVERWRITE, ret); + + if (flags == (VIR_STORAGE_POOL_BUILD_OVERWRITE | + VIR_STORAGE_POOL_BUILD_NO_OVERWRITE)) { + + virStorageReportError(VIR_ERR_OPERATION_INVALID, + _("Overwrite and no overwrite flags" + " are mutually exclusive")); + goto error; + }
if ((parent = strdup(pool->def->target.path)) == NULL) { virReportOOMError(); @@ -604,7 +778,13 @@ virStorageBackendFileSystemBuild(virConnectPtr conn ATTRIBUTE_UNUSED, goto error; } } - ret = 0; + + if (flags != 0) { + ret = virStorageBackendMakeFileSystem(pool, flags); + } else { + ret = 0; + } + error: VIR_FREE(parent); return ret; diff --git a/src/storage/storage_backend_fs.h b/src/storage/storage_backend_fs.h index 7def53e..54c6739 100644 --- a/src/storage/storage_backend_fs.h +++ b/src/storage/storage_backend_fs.h @@ -29,6 +29,11 @@ # if WITH_STORAGE_FS extern virStorageBackend virStorageBackendFileSystem; extern virStorageBackend virStorageBackendNetFileSystem; +typedef enum { + FILESYSTEM_PROBE_FOUND, + FILESYSTEM_PROBE_NOT_FOUND, + FILESYSTEM_PROBE_ERROR, +} virStoragePoolProbeResult; # endif extern virStorageBackend virStorageBackendDirectory;
diff --git a/src/util/virterror.c b/src/util/virterror.c index b50fbfd..26c4981 100644 --- a/src/util/virterror.c +++ b/src/util/virterror.c @@ -1030,6 +1030,18 @@ virErrorMsg(virErrorNumber error, const char *info) else errmsg = _("Storage volume not found: %s"); break; + case VIR_ERR_STORAGE_PROBE_FAILED: + if (info == NULL) + errmsg = _("Storage pool probe failed"); + else + errmsg = _("Storage pool probe failed: %s"); + break; + case VIR_ERR_STORAGE_POOL_BUILT: + if (info == NULL) + errmsg = _("Storage pool already built"); + else + errmsg = _("Storage pool already built: %s"); + break; case VIR_ERR_INVALID_STORAGE_POOL: if (info == NULL) errmsg = _("invalid storage pool pointer in");
ACK the logic looks right. I would love to see some ways to test the various behaviours though, Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

--- tools/virsh.c | 14 ++++++++++++-- tools/virsh.pod | 11 ++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index 49034ae..cd87107 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -7134,6 +7134,8 @@ static const vshCmdInfo info_pool_build[] = { static const vshCmdOptDef opts_pool_build[] = { {"pool", VSH_OT_DATA, VSH_OFLAG_REQ, N_("pool name or uuid")}, + {"no-overwrite", VSH_OT_BOOL, 0, N_("do not overwrite an existing pool of this type")}, + {"overwrite", VSH_OT_BOOL, 0, N_("overwrite any existing data")}, {NULL, 0, 0, NULL} }; @@ -7143,6 +7145,7 @@ cmdPoolBuild(vshControl *ctl, const vshCmd *cmd) virStoragePoolPtr pool; bool ret = true; const char *name; + unsigned int flags = 0; if (!vshConnectionUsability(ctl, ctl->conn)) return false; @@ -7150,7 +7153,15 @@ cmdPoolBuild(vshControl *ctl, const vshCmd *cmd) if (!(pool = vshCommandOptPool(ctl, cmd, "pool", &name))) return false; - if (virStoragePoolBuild(pool, 0) == 0) { + if (vshCommandOptBool (cmd, "no-overwrite")) { + flags |= VIR_STORAGE_POOL_BUILD_NO_OVERWRITE; + } + + if (vshCommandOptBool (cmd, "overwrite")) { + flags |= VIR_STORAGE_POOL_BUILD_OVERWRITE; + } + + if (virStoragePoolBuild(pool, flags) == 0) { vshPrint(ctl, _("Pool %s built\n"), name); } else { vshError(ctl, _("Failed to build pool %s"), name); @@ -7162,7 +7173,6 @@ cmdPoolBuild(vshControl *ctl, const vshCmd *cmd) return ret; } - /* * "pool-destroy" command */ diff --git a/tools/virsh.pod b/tools/virsh.pod index 2cd0f73..27e6f05 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1274,10 +1274,19 @@ where the query is performed. Configure whether I<pool> should automatically start at boot. -=item B<pool-build> I<pool-or-uuid> +=item B<pool-build> I<pool-or-uuid> [I<--overwrite>] [I<--no-overwrite>] Build a given pool. +Options I<--overwrite> and I<--no-overwrite> can only be used for +B<pool-build> a filesystem pool. If neither of them is specified, +B<pool-build> on a filesystem pool only makes the directory; If +I<--no-overwrite> is specified, it probes to determine if a +filesystem already exists on the target device, returning an error +if exists, or using mkfs to format the target device if not; If +I<--overwrite> is specified, mkfs is always executed, any existed +data on the target device is overwritten unconditionally. + =item B<pool-create> I<file> Create and start a pool object from the XML I<file>. -- 1.7.6

On Wed, Aug 31, 2011 at 10:34:48PM +0800, Osier Yang wrote:
--- tools/virsh.c | 14 ++++++++++++-- tools/virsh.pod | 11 ++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/tools/virsh.c b/tools/virsh.c index 49034ae..cd87107 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -7134,6 +7134,8 @@ static const vshCmdInfo info_pool_build[] = {
static const vshCmdOptDef opts_pool_build[] = { {"pool", VSH_OT_DATA, VSH_OFLAG_REQ, N_("pool name or uuid")}, + {"no-overwrite", VSH_OT_BOOL, 0, N_("do not overwrite an existing pool of this type")}, + {"overwrite", VSH_OT_BOOL, 0, N_("overwrite any existing data")}, {NULL, 0, 0, NULL} };
@@ -7143,6 +7145,7 @@ cmdPoolBuild(vshControl *ctl, const vshCmd *cmd) virStoragePoolPtr pool; bool ret = true; const char *name; + unsigned int flags = 0;
if (!vshConnectionUsability(ctl, ctl->conn)) return false; @@ -7150,7 +7153,15 @@ cmdPoolBuild(vshControl *ctl, const vshCmd *cmd) if (!(pool = vshCommandOptPool(ctl, cmd, "pool", &name))) return false;
- if (virStoragePoolBuild(pool, 0) == 0) { + if (vshCommandOptBool (cmd, "no-overwrite")) { + flags |= VIR_STORAGE_POOL_BUILD_NO_OVERWRITE; + } + + if (vshCommandOptBool (cmd, "overwrite")) { + flags |= VIR_STORAGE_POOL_BUILD_OVERWRITE; + } + + if (virStoragePoolBuild(pool, flags) == 0) { vshPrint(ctl, _("Pool %s built\n"), name); } else { vshError(ctl, _("Failed to build pool %s"), name); @@ -7162,7 +7173,6 @@ cmdPoolBuild(vshControl *ctl, const vshCmd *cmd) return ret; }
- /* * "pool-destroy" command */ diff --git a/tools/virsh.pod b/tools/virsh.pod index 2cd0f73..27e6f05 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1274,10 +1274,19 @@ where the query is performed.
Configure whether I<pool> should automatically start at boot.
-=item B<pool-build> I<pool-or-uuid> +=item B<pool-build> I<pool-or-uuid> [I<--overwrite>] [I<--no-overwrite>]
Build a given pool.
+Options I<--overwrite> and I<--no-overwrite> can only be used for +B<pool-build> a filesystem pool. If neither of them is specified, +B<pool-build> on a filesystem pool only makes the directory; If +I<--no-overwrite> is specified, it probes to determine if a +filesystem already exists on the target device, returning an error +if exists, or using mkfs to format the target device if not; If +I<--overwrite> is specified, mkfs is always executed, any existed +data on the target device is overwritten unconditionally. + =item B<pool-create> I<file>
Create and start a pool object from the XML I<file>.
ACK, Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/
participants (2)
-
Daniel Veillard
-
Osier Yang