[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 1/6] Move file format enum to libvirt_util



Rename virStorageVolFormatFileSystem to virStorageFileFormat and
move to src/util/storage_file.[ch]

* src/Makefile.am: add src/util/storage_file.[ch]

* src/conf/storage_conf.[ch]: move enum from here ...

* src/util/storage_file.[ch]: .. to here

* src/libvirt_private.syms: update To/FromString exports

* src/storage/storage_backend.c, src/storage/storage_backend_fs.c,
  src/vbox/vbox_tmpl.c: update for above changes
---
 src/Makefile.am                  |    1 +
 src/conf/storage_conf.c          |   25 ++++++++------------
 src/conf/storage_conf.h          |   17 --------------
 src/libvirt_private.syms         |    5 ++-
 src/storage/storage_backend.c    |   17 +++++++------
 src/storage/storage_backend_fs.c |   33 ++++++++++++++-------------
 src/util/storage_file.c          |   31 +++++++++++++++++++++++++
 src/util/storage_file.h          |   46 ++++++++++++++++++++++++++++++++++++++
 src/vbox/vbox_tmpl.c             |   15 ++++++-----
 9 files changed, 125 insertions(+), 65 deletions(-)
 create mode 100644 src/util/storage_file.c
 create mode 100644 src/util/storage_file.h

diff --git a/src/Makefile.am b/src/Makefile.am
index 9cbec47..47bc39b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -49,6 +49,7 @@ UTIL_SOURCES =							\
 		util/hostusb.c util/hostusb.h			\
 		util/qparams.c util/qparams.h			\
 		util/stats_linux.c util/stats_linux.h		\
+		util/storage_file.c util/storage_file.h		\
 		util/threads.c util/threads.h			\
 		util/threads-pthread.h				\
 		util/threads-win32.h				\
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index cb063cc..788de15 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -36,6 +36,7 @@
 #include "virterror_internal.h"
 #include "datatypes.h"
 #include "storage_conf.h"
+#include "storage_file.h"
 
 #include "xml.h"
 #include "uuid.h"
@@ -82,12 +83,6 @@ VIR_ENUM_IMPL(virStorageVolFormatDisk,
               "linux-lvm", "linux-raid",
               "extended")
 
-VIR_ENUM_IMPL(virStorageVolFormatFileSystem,
-              VIR_STORAGE_VOL_FILE_LAST,
-              "raw", "dir", "bochs",
-              "cloop", "cow", "dmg", "iso",
-              "qcow", "qcow2", "vmdk", "vpc")
-
 VIR_ENUM_IMPL(virStoragePartedFsType,
               VIR_STORAGE_PARTED_FS_TYPE_LAST,
               "ext2", "ext2", "fat16",
@@ -150,9 +145,9 @@ static virStoragePoolTypeInfo poolTypeInfo[] = {
     },
     { .poolType = VIR_STORAGE_POOL_DIR,
       .volOptions = {
-            .defaultFormat = VIR_STORAGE_VOL_FILE_RAW,
-            .formatFromString = virStorageVolFormatFileSystemTypeFromString,
-            .formatToString = virStorageVolFormatFileSystemTypeToString,
+            .defaultFormat = VIR_STORAGE_FILE_RAW,
+            .formatFromString = virStorageFileFormatTypeFromString,
+            .formatToString = virStorageFileFormatTypeToString,
         },
     },
     { .poolType = VIR_STORAGE_POOL_FS,
@@ -162,9 +157,9 @@ static virStoragePoolTypeInfo poolTypeInfo[] = {
             .formatToString = virStoragePoolFormatFileSystemTypeToString,
         },
       .volOptions = {
-            .defaultFormat = VIR_STORAGE_VOL_FILE_RAW,
-            .formatFromString = virStorageVolFormatFileSystemTypeFromString,
-            .formatToString = virStorageVolFormatFileSystemTypeToString,
+            .defaultFormat = VIR_STORAGE_FILE_RAW,
+            .formatFromString = virStorageFileFormatTypeFromString,
+            .formatToString = virStorageFileFormatTypeToString,
         },
     },
     { .poolType = VIR_STORAGE_POOL_NETFS,
@@ -176,9 +171,9 @@ static virStoragePoolTypeInfo poolTypeInfo[] = {
             .formatToString = virStoragePoolFormatFileSystemNetTypeToString,
         },
       .volOptions = {
-            .defaultFormat = VIR_STORAGE_VOL_FILE_RAW,
-            .formatFromString = virStorageVolFormatFileSystemTypeFromString,
-            .formatToString = virStorageVolFormatFileSystemTypeToString,
+            .defaultFormat = VIR_STORAGE_FILE_RAW,
+            .formatFromString = virStorageFileFormatTypeFromString,
+            .formatToString = virStorageFileFormatTypeToString,
         },
     },
     { .poolType = VIR_STORAGE_POOL_ISCSI,
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index 421d305..9fedb12 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -429,23 +429,6 @@ enum virStoragePoolFormatLogical {
 };
 VIR_ENUM_DECL(virStoragePoolFormatLogical)
 
-
-enum virStorageVolFormatFileSystem {
-    VIR_STORAGE_VOL_FILE_RAW = 0,
-    VIR_STORAGE_VOL_FILE_DIR,
-    VIR_STORAGE_VOL_FILE_BOCHS,
-    VIR_STORAGE_VOL_FILE_CLOOP,
-    VIR_STORAGE_VOL_FILE_COW,
-    VIR_STORAGE_VOL_FILE_DMG,
-    VIR_STORAGE_VOL_FILE_ISO,
-    VIR_STORAGE_VOL_FILE_QCOW,
-    VIR_STORAGE_VOL_FILE_QCOW2,
-    VIR_STORAGE_VOL_FILE_VMDK,
-    VIR_STORAGE_VOL_FILE_VPC,
-    VIR_STORAGE_VOL_FILE_LAST,
-};
-VIR_ENUM_DECL(virStorageVolFormatFileSystem)
-
 /*
  * XXX these are basically partition types.
  *
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index a6668f3..ddab21d 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -378,8 +378,6 @@ virStorageVolDefParseNode;
 virStoragePoolFormatDiskTypeToString;
 virStoragePoolFormatFileSystemTypeToString;
 virStoragePoolFormatFileSystemNetTypeToString;
-virStorageVolFormatFileSystemTypeToString;
-virStorageVolFormatFileSystemTypeFromString;
 virStoragePoolTypeFromString;
 virStoragePartedFsTypeTypeToString;
 virStoragePoolObjLock;
@@ -392,6 +390,9 @@ virStorageEncryptionParseNode;
 virStorageEncryptionFormat;
 virStorageGenerateQcowPassphrase;
 
+# storage_file.h
+virStorageFileFormatTypeToString;
+virStorageFileFormatTypeFromString;
 
 # threads.h
 virMutexInit;
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index b3c9b0e..18a69be 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -50,6 +50,7 @@
 #include "internal.h"
 #include "secret_conf.h"
 #include "uuid.h"
+#include "storage_file.h"
 #include "storage_backend.h"
 #include "logging.h"
 
@@ -461,16 +462,16 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
     char *create_tool;
     short use_kvmimg;
 
-    const char *type = virStorageVolFormatFileSystemTypeToString(vol->target.format);
+    const char *type = virStorageFileFormatTypeToString(vol->target.format);
     const char *backingType = vol->backingStore.path ?
-        virStorageVolFormatFileSystemTypeToString(vol->backingStore.format) : NULL;
+        virStorageFileFormatTypeToString(vol->backingStore.format) : NULL;
 
     const char *inputBackingPath = (inputvol ? inputvol->backingStore.path
                                              : NULL);
     const char *inputPath = inputvol ? inputvol->target.path : NULL;
     /* Treat input block devices as 'raw' format */
     const char *inputType = inputPath ?
-                            virStorageVolFormatFileSystemTypeToString(inputvol->type == VIR_STORAGE_VOL_BLOCK ? VIR_STORAGE_VOL_FILE_RAW : inputvol->target.format) :
+                            virStorageFileFormatTypeToString(inputvol->type == VIR_STORAGE_VOL_BLOCK ? VIR_STORAGE_FILE_RAW : inputvol->target.format) :
                             NULL;
 
     const char **imgargv;
@@ -551,8 +552,8 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
     if (vol->target.encryption != NULL) {
         virStorageEncryptionPtr enc;
 
-        if (vol->target.format != VIR_STORAGE_VOL_FILE_QCOW &&
-            vol->target.format != VIR_STORAGE_VOL_FILE_QCOW2) {
+        if (vol->target.format != VIR_STORAGE_FILE_QCOW &&
+            vol->target.format != VIR_STORAGE_FILE_QCOW2) {
             virStorageReportError(conn, VIR_ERR_NO_SUPPORT,
                                   _("qcow volume encryption unsupported with "
                                     "volume format %s"), type);
@@ -643,7 +644,7 @@ virStorageBackendCreateQcowCreate(virConnectPtr conn,
         return -1;
     }
 
-    if (vol->target.format != VIR_STORAGE_VOL_FILE_QCOW2) {
+    if (vol->target.format != VIR_STORAGE_FILE_QCOW2) {
         virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
                               _("unsupported storage vol type %d"),
                               vol->target.format);
@@ -734,9 +735,9 @@ virStorageBackendGetBuildVolFromFunction(virConnectPtr conn,
      * tool for converting
      */
     if ((vol->type == VIR_STORAGE_VOL_FILE &&
-         vol->target.format != VIR_STORAGE_VOL_FILE_RAW) ||
+         vol->target.format != VIR_STORAGE_FILE_RAW) ||
         (inputvol->type == VIR_STORAGE_VOL_FILE &&
-         inputvol->target.format != VIR_STORAGE_VOL_FILE_RAW)) {
+         inputvol->target.format != VIR_STORAGE_FILE_RAW)) {
 
         if ((tool_type = virStorageBackendFindFSImageTool(NULL)) < 0) {
             virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index 01cb171..e7a3ca9 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -41,6 +41,7 @@
 #include "virterror_internal.h"
 #include "storage_backend_fs.h"
 #include "storage_conf.h"
+#include "storage_file.h"
 #include "util.h"
 #include "memory.h"
 #include "xml.h"
@@ -91,7 +92,7 @@ struct FileTypeInfo {
 struct FileTypeInfo const fileTypeInfo[] = {
     /* Bochs */
     /* XXX Untested
-    { VIR_STORAGE_VOL_FILE_BOCHS, "Bochs Virtual HD Image", NULL,
+    { VIR_STORAGE_FILE_BOCHS, "Bochs Virtual HD Image", NULL,
       LV_LITTLE_ENDIAN, 64, 0x20000,
       32+16+16+4+4+4+4+4, 8, 1, -1, NULL },*/
     /* CLoop */
@@ -100,45 +101,45 @@ struct FileTypeInfo const fileTypeInfo[] = {
       LV_LITTLE_ENDIAN, -1, 0,
       -1, 0, 0, -1, NULL }, */
     /* Cow */
-    { VIR_STORAGE_VOL_FILE_COW, "OOOM", NULL,
+    { VIR_STORAGE_FILE_COW, "OOOM", NULL,
       LV_BIG_ENDIAN, 4, 2,
       4+4+1024+4, 8, 1, -1, cowGetBackingStore },
     /* DMG */
     /* XXX QEMU says there's no magic for dmg, but we should check... */
-    { VIR_STORAGE_VOL_FILE_DMG, NULL, ".dmg",
+    { VIR_STORAGE_FILE_DMG, NULL, ".dmg",
       0, -1, 0,
       -1, 0, 0, -1, NULL },
     /* XXX there's probably some magic for iso we can validate too... */
-    { VIR_STORAGE_VOL_FILE_ISO, NULL, ".iso",
+    { VIR_STORAGE_FILE_ISO, NULL, ".iso",
       0, -1, 0,
       -1, 0, 0, -1, NULL },
     /* Parallels */
     /* XXX Untested
-    { VIR_STORAGE_VOL_FILE_PARALLELS, "WithoutFreeSpace", NULL,
+    { VIR_STORAGE_FILE_PARALLELS, "WithoutFreeSpace", NULL,
       LV_LITTLE_ENDIAN, 16, 2,
       16+4+4+4+4, 4, 512, -1, NULL },
     */
     /* QCow */
-    { VIR_STORAGE_VOL_FILE_QCOW, "QFI", NULL,
+    { VIR_STORAGE_FILE_QCOW, "QFI", NULL,
       LV_BIG_ENDIAN, 4, 1,
       4+4+8+4+4, 8, 1, 4+4+8+4+4+8+1+1+2, qcowXGetBackingStore },
     /* QCow 2 */
-    { VIR_STORAGE_VOL_FILE_QCOW2, "QFI", NULL,
+    { VIR_STORAGE_FILE_QCOW2, "QFI", NULL,
       LV_BIG_ENDIAN, 4, 2,
       4+4+8+4+4, 8, 1, 4+4+8+4+4+8, qcowXGetBackingStore },
     /* VMDK 3 */
     /* XXX Untested
-    { VIR_STORAGE_VOL_FILE_VMDK, "COWD", NULL,
+    { VIR_STORAGE_FILE_VMDK, "COWD", NULL,
       LV_LITTLE_ENDIAN, 4, 1,
       4+4+4, 4, 512, -1, NULL },
     */
     /* VMDK 4 */
-    { VIR_STORAGE_VOL_FILE_VMDK, "KDMV", NULL,
+    { VIR_STORAGE_FILE_VMDK, "KDMV", NULL,
       LV_LITTLE_ENDIAN, 4, 1,
       4+4+4, 8, 512, -1, vmdk4GetBackingStore },
     /* Connectix / VirtualPC */
     /* XXX Untested
-    { VIR_STORAGE_VOL_FILE_VPC, "conectix", NULL,
+    { VIR_STORAGE_FILE_VPC, "conectix", NULL,
       LV_BIG_ENDIAN, -1, 0,
       -1, 0, 0, -1, NULL},
     */
@@ -452,7 +453,7 @@ static int virStorageBackendProbeTarget(virConnectPtr conn,
     }
 
     /* All fails, so call it a raw file */
-    target->format = VIR_STORAGE_VOL_FILE_RAW;
+    target->format = VIR_STORAGE_FILE_RAW;
     return 0;
 }
 
@@ -891,7 +892,7 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn,
             goto no_memory;
 
         vol->type = VIR_STORAGE_VOL_FILE;
-        vol->target.format = VIR_STORAGE_VOL_FILE_RAW; /* Real value is filled in during probe */
+        vol->target.format = VIR_STORAGE_FILE_RAW; /* Real value is filled in during probe */
         if (virAsprintf(&vol->target.path, "%s/%s",
                         pool->def->target.path,
                         vol->name) == -1)
@@ -918,7 +919,7 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn,
         }
 
         if (backingStore != NULL) {
-            if (vol->target.format == VIR_STORAGE_VOL_FILE_QCOW2 &&
+            if (vol->target.format == VIR_STORAGE_FILE_QCOW2 &&
                 STRPREFIX("fmt:", backingStore)) {
                 char *fmtstr = backingStore + 4;
                 char *path = strchr(fmtstr, ':');
@@ -927,7 +928,7 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn,
                 } else {
                     *path = '\0';
                     if ((vol->backingStore.format =
-                         virStorageVolFormatFileSystemTypeFromString(fmtstr)) < 0) {
+                         virStorageFileFormatTypeFromString(fmtstr)) < 0) {
                         VIR_FREE(backingStore);
                     } else {
                         memmove(backingStore, path, strlen(path) + 1);
@@ -1121,9 +1122,9 @@ _virStorageBackendFileSystemVolBuild(virConnectPtr conn,
                                                                inputvol);
         if (!create_func)
             return -1;
-    } else if (vol->target.format == VIR_STORAGE_VOL_FILE_RAW) {
+    } else if (vol->target.format == VIR_STORAGE_FILE_RAW) {
         create_func = virStorageBackendCreateRaw;
-    } else if (vol->target.format == VIR_STORAGE_VOL_FILE_DIR) {
+    } else if (vol->target.format == VIR_STORAGE_FILE_DIR) {
         create_func = createFileDir;
     } else if ((tool_type = virStorageBackendFindFSImageTool(NULL)) != -1) {
         create_func = virStorageBackendFSImageToolTypeToFunc(conn, tool_type);
diff --git a/src/util/storage_file.c b/src/util/storage_file.c
new file mode 100644
index 0000000..e66ec8a
--- /dev/null
+++ b/src/util/storage_file.c
@@ -0,0 +1,31 @@
+/*
+ * storage_file.c: file utility functions for FS storage backend
+ *
+ * Copyright (C) 2007-2009 Red Hat, Inc.
+ * Copyright (C) 2007-2008 Daniel P. Berrange
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ *
+ * Author: Daniel P. Berrange <berrange redhat com>
+ */
+
+#include <config.h>
+#include "storage_file.h"
+
+VIR_ENUM_IMPL(virStorageFileFormat,
+              VIR_STORAGE_FILE_LAST,
+              "raw", "dir", "bochs",
+              "cloop", "cow", "dmg", "iso",
+              "qcow", "qcow2", "vmdk", "vpc")
diff --git a/src/util/storage_file.h b/src/util/storage_file.h
new file mode 100644
index 0000000..7bccbe4
--- /dev/null
+++ b/src/util/storage_file.h
@@ -0,0 +1,46 @@
+/*
+ * storage_file.c: file utility functions for FS storage backend
+ *
+ * Copyright (C) 2007-2009 Red Hat, Inc.
+ * Copyright (C) 2007-2008 Daniel P. Berrange
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ *
+ * Author: Daniel P. Berrange <berrange redhat com>
+ */
+
+#ifndef __VIR_STORAGE_FILE_H__
+#define __VIR_STORAGE_FILE_H__
+
+#include "util.h"
+
+enum virStorageFileFormat {
+    VIR_STORAGE_FILE_RAW = 0,
+    VIR_STORAGE_FILE_DIR,
+    VIR_STORAGE_FILE_BOCHS,
+    VIR_STORAGE_FILE_CLOOP,
+    VIR_STORAGE_FILE_COW,
+    VIR_STORAGE_FILE_DMG,
+    VIR_STORAGE_FILE_ISO,
+    VIR_STORAGE_FILE_QCOW,
+    VIR_STORAGE_FILE_QCOW2,
+    VIR_STORAGE_FILE_VMDK,
+    VIR_STORAGE_FILE_VPC,
+    VIR_STORAGE_FILE_LAST,
+};
+
+VIR_ENUM_DECL(virStorageFileFormat);
+
+#endif /* __VIR_STORAGE_FILE_H__ */
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index c02b18c..ecad2a1 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -45,6 +45,7 @@
 #include "virterror_internal.h"
 #include "domain_event.h"
 #include "storage_conf.h"
+#include "storage_file.h"
 #include "uuid.h"
 #include "event.h"
 #include "memory.h"
@@ -5980,14 +5981,14 @@ static virStorageVolPtr vboxStorageVolCreateXML(virStoragePoolPtr pool,
 
         /* TODO: for now only the vmdk, vpc and vdi type harddisk
          * variants can be created, also since there is no vdi
-         * type in enum virStorageVolFormatFileSystem {} the default
+         * type in enum virStorageFileFormat {} the default
          * will be to create vdi if nothing is specified in
          * def->target.format
          */
 
-        if (def->target.format == VIR_STORAGE_VOL_FILE_VMDK) {
+        if (def->target.format == VIR_STORAGE_FILE_VMDK) {
             data->pFuncs->pfnUtf8ToUtf16("VMDK", &hddFormatUtf16);
-        } else if (def->target.format == VIR_STORAGE_VOL_FILE_VPC) {
+        } else if (def->target.format == VIR_STORAGE_FILE_VPC) {
             data->pFuncs->pfnUtf8ToUtf16("VHD", &hddFormatUtf16);
         } else {
             data->pFuncs->pfnUtf8ToUtf16("VDI", &hddFormatUtf16);
@@ -6302,13 +6303,13 @@ static char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags A
                             DEBUG("Storage Volume Format: %s", hddFormatUtf8);
 
                             if (STRCASEEQ("vmdk", hddFormatUtf8))
-                                def.target.format = VIR_STORAGE_VOL_FILE_VMDK;
+                                def.target.format = VIR_STORAGE_FILE_VMDK;
                             else if (STRCASEEQ("vhd", hddFormatUtf8))
-                                def.target.format = VIR_STORAGE_VOL_FILE_VPC;
+                                def.target.format = VIR_STORAGE_FILE_VPC;
                             else
-                                def.target.format = VIR_STORAGE_VOL_FILE_RAW;
+                                def.target.format = VIR_STORAGE_FILE_RAW;
 
-                            /* TODO: need to add vdi to enum virStorageVolFormatFileSystem {}
+                            /* TODO: need to add vdi to enum virStorageFileFormat {}
                              * and then add it here
                              */
 
-- 
1.6.2.5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]