]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: Refactor storage file initialization to use virStorageSourcePtr
authorPeter Krempa <pkrempa@redhat.com>
Tue, 8 Apr 2014 06:42:57 +0000 (08:42 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 9 Apr 2014 12:31:12 +0000 (14:31 +0200)
Now that storage source metadata is stored in a single struct we don't
need two initialization functions for different structs.

src/qemu/qemu_driver.c
src/storage/storage_backend.c
src/storage/storage_driver.c
src/storage/storage_driver.h

index 5b0e48499822fb56d8a9b87b11cd957588151974..d824e2452c4f8c2bd191bab0afa2d0fe6d1b0c10 100644 (file)
@@ -12489,7 +12489,7 @@ qemuDomainSnapshotPrepareDiskExternal(virConnectPtr conn,
             return -1;
     }
 
-    if (!(snapfile = virStorageFileInitFromSnapshotDef(snapdisk)))
+    if (!(snapfile = virStorageFileInit(&snapdisk->src)))
         return -1;
 
     if (virStorageFileStat(snapfile, &st) < 0) {
@@ -12757,7 +12757,7 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
     virStorageFileFreeMetadata(disk->backingChain);
     disk->backingChain = NULL;
 
-    if (!(snapfile = virStorageFileInitFromSnapshotDef(snap)))
+    if (!(snapfile = virStorageFileInit(&snap->src)))
         goto cleanup;
 
     if (qemuDomainSnapshotDiskGetSourceString(snap, &source) < 0)
@@ -12914,7 +12914,7 @@ qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver,
     virStorageFilePtr diskfile = NULL;
     struct stat st;
 
-    diskfile = virStorageFileInitFromDiskDef(disk);
+    diskfile = virStorageFileInit(&disk->src);
 
     if (VIR_STRDUP(source, origdisk->src.path) < 0 ||
         (persistDisk && VIR_STRDUP(persistSource, source) < 0))
index b56fefe34b4a808c2ddcc1c7d24b3c9c108d1430..8f9df786034f2c4cdeea506172ec474b70151231 100644 (file)
@@ -55,6 +55,7 @@
 #include "virfile.h"
 #include "stat-time.h"
 #include "virstring.h"
+#include "virxml.h"
 
 #if WITH_STORAGE_LVM
 # include "storage_backend_logical.h"
index d58d98655eb5156bc4b6cc80a2a527fdd8070e84..ed347319a14108c48caa5c8ccbcb938bc9888685 100644 (file)
@@ -2770,26 +2770,22 @@ virStorageFileFree(virStorageFilePtr file)
 }
 
 
-static virStorageFilePtr
-virStorageFileInitInternal(int type,
-                           const char *path,
-                           int protocol,
-                           size_t nhosts,
-                           virStorageNetHostDefPtr hosts)
+virStorageFilePtr
+virStorageFileInit(virStorageSourcePtr src)
 {
     virStorageFilePtr file = NULL;
 
     if (VIR_ALLOC(file) < 0)
         return NULL;
 
-    file->type = type;
-    file->protocol = protocol;
-    file->nhosts = nhosts;
+    file->type = virStorageSourceGetActualType(src);
+    file->protocol = src->protocol;
+    file->nhosts = src->nhosts;
 
-    if (VIR_STRDUP(file->path, path) < 0)
+    if (VIR_STRDUP(file->path, src->path) < 0)
         goto error;
 
-    if (!(file->hosts = virStorageNetHostDefCopy(nhosts, hosts)))
+    if (!(file->hosts = virStorageNetHostDefCopy(src->nhosts, src->hosts)))
         goto error;
 
     if (!(file->backend = virStorageFileBackendForType(file->type,
@@ -2810,29 +2806,6 @@ virStorageFileInitInternal(int type,
 }
 
 
-virStorageFilePtr
-virStorageFileInitFromDiskDef(virDomainDiskDefPtr disk)
-{
-    return virStorageFileInitInternal(virStorageSourceGetActualType(&disk->src),
-                                      disk->src.path,
-                                      disk->src.protocol,
-                                      disk->src.nhosts,
-                                      disk->src.hosts);
-}
-
-
-virStorageFilePtr
-virStorageFileInitFromSnapshotDef(virDomainSnapshotDiskDefPtr disk)
-{
-    return virStorageFileInitInternal(virStorageSourceGetActualType(&disk->src),
-                                      disk->src.path,
-                                      disk->src.protocol,
-                                      disk->src.nhosts,
-                                      disk->src.hosts);
-}
-
-
-
 /**
  * virStorageFileCreate: Creates an empty storage file via storage driver
  *
index 886a4d50373aac690f9e018855f753eee2f0280c..9771207a1febc8bff4cc44b5abae771c434caee5 100644 (file)
 #ifndef __VIR_STORAGE_DRIVER_H__
 # define __VIR_STORAGE_DRIVER_H__
 
+# include <sys/stat.h>
+
 # include "storage_conf.h"
-# include "conf/domain_conf.h"
-# include "conf/snapshot_conf.h"
+# include "virstoragefile.h"
 
 typedef struct _virStorageFileBackend virStorageFileBackend;
 typedef virStorageFileBackend *virStorageFileBackendPtr;
@@ -46,9 +47,7 @@ struct _virStorageFile {
 };
 
 virStorageFilePtr
-virStorageFileInitFromDiskDef(virDomainDiskDefPtr disk);
-virStorageFilePtr
-virStorageFileInitFromSnapshotDef(virDomainSnapshotDiskDefPtr disk);
+virStorageFileInit(virStorageSourcePtr src);
 void virStorageFileFree(virStorageFilePtr file);
 
 int virStorageFileCreate(virStorageFilePtr file);