[libvirt] [PATCH 1/2] Format fs pool during pool build

David Allan dallan at redhat.com
Mon Jan 4 19:42:38 UTC 2010


---
 configure.in                     |    5 +++++
 src/storage/storage_backend_fs.c |   36 +++++++++++++++++++++++++++++++++---
 2 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/configure.in b/configure.in
index 3f2f8ff..59ceadd 100644
--- a/configure.in
+++ b/configure.in
@@ -1243,12 +1243,15 @@ AM_CONDITIONAL([WITH_STORAGE_DIR], [test "$with_storage_dir" = "yes"])
 if test "$with_storage_fs" = "yes" -o "$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([MKE2FS], [mke2fs], [], [$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 "$MKE2FS" ; then AC_MSG_ERROR([We need mke2fs 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 "$MKE2FS" ; then with_storage_fs=no ; fi

     if test "$with_storage_fs" = "check" ; then with_storage_fs=yes ; fi
   fi
@@ -1259,6 +1262,8 @@ if test "$with_storage_fs" = "yes" -o "$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([MKE2FS],["$MKE2FS"],
+        [Location or name of the mke2fs program])
   fi
 fi
 AM_CONDITIONAL([WITH_STORAGE_FS], [test "$with_storage_fs" = "yes"])
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index b7d4bd6..ca1f4cb 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -45,6 +45,7 @@
 #include "util.h"
 #include "memory.h"
 #include "xml.h"
+#include "logging.h"

 #define VIR_FROM_THIS VIR_FROM_STORAGE

@@ -505,15 +506,44 @@ virStorageBackendFileSystemBuild(virConnectPtr conn,
                                  virStoragePoolObjPtr pool,
                                  unsigned int flags ATTRIBUTE_UNUSED)
 {
-    int err;
+    const char *mke2fsargv[5], *device = NULL, *format = NULL;
+    int err, ret = -1;
+
     if ((err = virFileMakePath(pool->def->target.path)) < 0) {
         virReportSystemError(conn, err,
                              _("cannot create path '%s'"),
                              pool->def->target.path);
-        return -1;
+        goto out;
     }

-    return 0;
+    if (pool->def->source.ndevice != 1) {
+        virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
+                              "Exactly one source device "
+                              "may be specified for pool type '%s'",
+                              virStoragePoolFormatFileSystemTypeToString(pool->def->source.format));
+        goto out;
+    }
+
+    device = pool->def->source.devices[0].path;
+    format = virStoragePoolFormatFileSystemTypeToString(pool->def->source.format);
+
+    VIR_DEBUG("source device: '%s' format: '%s'", device, format);
+
+    mke2fsargv[0] = MKE2FS;
+    mke2fsargv[1] = "-t";
+    mke2fsargv[2] = format;
+    mke2fsargv[3] = device;
+    mke2fsargv[4] = NULL;
+
+    if (virRun(conn, mke2fsargv, NULL) < 0) {
+        VIR_ERROR("Failed to make '%s' filesystem on device '%s'", format, device);
+        goto out;
+    }
+
+    ret = 0;
+
+out:
+    return ret;
 }


-- 
1.6.5.5




More information about the libvir-list mailing list