]> xenbits.xensource.com Git - libvirt.git/commitdiff
Move file format enum to libvirt_util
authorMark McLoughlin <markmc@redhat.com>
Fri, 25 Sep 2009 13:20:13 +0000 (14:20 +0100)
committerMark McLoughlin <markmc@redhat.com>
Wed, 30 Sep 2009 09:36:59 +0000 (10:36 +0100)
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
src/conf/storage_conf.c
src/conf/storage_conf.h
src/libvirt_private.syms
src/storage/storage_backend.c
src/storage/storage_backend_fs.c
src/util/storage_file.c [new file with mode: 0644]
src/util/storage_file.h [new file with mode: 0644]
src/vbox/vbox_tmpl.c

index b879056b50fbedc130896f9de53a1ab605a23a1b..de7765cd1c08fd28d2cf39215f9c0db2f700aaea 100644 (file)
@@ -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                            \
index cb063cc2589bcf5632f216668819438f75190077..788de15feed6fb1964f0b7697ec5f88ff552f963 100644 (file)
@@ -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,
index 421d305f6f87fc7ffd9895a790b9b3229c7ffeb1..9fedb12671a217d3516fe6e789ce8ffb2fa823fe 100644 (file)
@@ -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.
  *
index ad579d920a1bdccdd8c4079f9f7186dad06c68df..be85da91fbabb218e07590e6535da0a4ef3312cb 100644 (file)
@@ -380,8 +380,6 @@ virStorageVolDefParseNode;
 virStoragePoolFormatDiskTypeToString;
 virStoragePoolFormatFileSystemTypeToString;
 virStoragePoolFormatFileSystemNetTypeToString;
-virStorageVolFormatFileSystemTypeToString;
-virStorageVolFormatFileSystemTypeFromString;
 virStoragePoolTypeFromString;
 virStoragePartedFsTypeTypeToString;
 virStoragePoolObjLock;
@@ -394,6 +392,9 @@ virStorageEncryptionParseNode;
 virStorageEncryptionFormat;
 virStorageGenerateQcowPassphrase;
 
+# storage_file.h
+virStorageFileFormatTypeToString;
+virStorageFileFormatTypeFromString;
 
 # threads.h
 virMutexInit;
index b3c9b0ea7fb33da6f2919331b79eca52b80b5b2e..18a69be764585f7fc79774bc58d7853a8eaef345 100644 (file)
@@ -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,
index 01cb1715d26fa741e111c39b2567f9493a9e5540..e7a3ca9aed64007aef86997bd1a2f1808548d4d0 100644 (file)
@@ -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 (file)
index 0000000..e66ec8a
--- /dev/null
@@ -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 (file)
index 0000000..7bccbe4
--- /dev/null
@@ -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__ */
index 1980fabe2208aa7a8ddd34526f30f82cb3adf23d..154859a3e74c8cbe7fc0d576d0c02835ba847c0c 100644 (file)
@@ -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"
@@ -5985,14 +5986,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);
@@ -6307,13 +6308,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
                              */