mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 15:27:47 +00:00
storage: Refactor storage file initialization to use virStorageSourcePtr
Now that storage source metadata is stored in a single struct we don't need two initialization functions for different structs.
This commit is contained in:
parent
93c1f2cd70
commit
9689dfaad3
@ -12489,7 +12489,7 @@ qemuDomainSnapshotPrepareDiskExternal(virConnectPtr conn,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(snapfile = virStorageFileInitFromSnapshotDef(snapdisk)))
|
if (!(snapfile = virStorageFileInit(&snapdisk->src)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (virStorageFileStat(snapfile, &st) < 0) {
|
if (virStorageFileStat(snapfile, &st) < 0) {
|
||||||
@ -12757,7 +12757,7 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
|
|||||||
virStorageFileFreeMetadata(disk->backingChain);
|
virStorageFileFreeMetadata(disk->backingChain);
|
||||||
disk->backingChain = NULL;
|
disk->backingChain = NULL;
|
||||||
|
|
||||||
if (!(snapfile = virStorageFileInitFromSnapshotDef(snap)))
|
if (!(snapfile = virStorageFileInit(&snap->src)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (qemuDomainSnapshotDiskGetSourceString(snap, &source) < 0)
|
if (qemuDomainSnapshotDiskGetSourceString(snap, &source) < 0)
|
||||||
@ -12914,7 +12914,7 @@ qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver,
|
|||||||
virStorageFilePtr diskfile = NULL;
|
virStorageFilePtr diskfile = NULL;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
diskfile = virStorageFileInitFromDiskDef(disk);
|
diskfile = virStorageFileInit(&disk->src);
|
||||||
|
|
||||||
if (VIR_STRDUP(source, origdisk->src.path) < 0 ||
|
if (VIR_STRDUP(source, origdisk->src.path) < 0 ||
|
||||||
(persistDisk && VIR_STRDUP(persistSource, source) < 0))
|
(persistDisk && VIR_STRDUP(persistSource, source) < 0))
|
||||||
|
@ -55,6 +55,7 @@
|
|||||||
#include "virfile.h"
|
#include "virfile.h"
|
||||||
#include "stat-time.h"
|
#include "stat-time.h"
|
||||||
#include "virstring.h"
|
#include "virstring.h"
|
||||||
|
#include "virxml.h"
|
||||||
|
|
||||||
#if WITH_STORAGE_LVM
|
#if WITH_STORAGE_LVM
|
||||||
# include "storage_backend_logical.h"
|
# include "storage_backend_logical.h"
|
||||||
|
@ -2770,26 +2770,22 @@ virStorageFileFree(virStorageFilePtr file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static virStorageFilePtr
|
virStorageFilePtr
|
||||||
virStorageFileInitInternal(int type,
|
virStorageFileInit(virStorageSourcePtr src)
|
||||||
const char *path,
|
|
||||||
int protocol,
|
|
||||||
size_t nhosts,
|
|
||||||
virStorageNetHostDefPtr hosts)
|
|
||||||
{
|
{
|
||||||
virStorageFilePtr file = NULL;
|
virStorageFilePtr file = NULL;
|
||||||
|
|
||||||
if (VIR_ALLOC(file) < 0)
|
if (VIR_ALLOC(file) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
file->type = type;
|
file->type = virStorageSourceGetActualType(src);
|
||||||
file->protocol = protocol;
|
file->protocol = src->protocol;
|
||||||
file->nhosts = nhosts;
|
file->nhosts = src->nhosts;
|
||||||
|
|
||||||
if (VIR_STRDUP(file->path, path) < 0)
|
if (VIR_STRDUP(file->path, src->path) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (!(file->hosts = virStorageNetHostDefCopy(nhosts, hosts)))
|
if (!(file->hosts = virStorageNetHostDefCopy(src->nhosts, src->hosts)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (!(file->backend = virStorageFileBackendForType(file->type,
|
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
|
* virStorageFileCreate: Creates an empty storage file via storage driver
|
||||||
*
|
*
|
||||||
|
@ -24,9 +24,10 @@
|
|||||||
#ifndef __VIR_STORAGE_DRIVER_H__
|
#ifndef __VIR_STORAGE_DRIVER_H__
|
||||||
# define __VIR_STORAGE_DRIVER_H__
|
# define __VIR_STORAGE_DRIVER_H__
|
||||||
|
|
||||||
|
# include <sys/stat.h>
|
||||||
|
|
||||||
# include "storage_conf.h"
|
# include "storage_conf.h"
|
||||||
# include "conf/domain_conf.h"
|
# include "virstoragefile.h"
|
||||||
# include "conf/snapshot_conf.h"
|
|
||||||
|
|
||||||
typedef struct _virStorageFileBackend virStorageFileBackend;
|
typedef struct _virStorageFileBackend virStorageFileBackend;
|
||||||
typedef virStorageFileBackend *virStorageFileBackendPtr;
|
typedef virStorageFileBackend *virStorageFileBackendPtr;
|
||||||
@ -46,9 +47,7 @@ struct _virStorageFile {
|
|||||||
};
|
};
|
||||||
|
|
||||||
virStorageFilePtr
|
virStorageFilePtr
|
||||||
virStorageFileInitFromDiskDef(virDomainDiskDefPtr disk);
|
virStorageFileInit(virStorageSourcePtr src);
|
||||||
virStorageFilePtr
|
|
||||||
virStorageFileInitFromSnapshotDef(virDomainSnapshotDiskDefPtr disk);
|
|
||||||
void virStorageFileFree(virStorageFilePtr file);
|
void virStorageFileFree(virStorageFilePtr file);
|
||||||
|
|
||||||
int virStorageFileCreate(virStorageFilePtr file);
|
int virStorageFileCreate(virStorageFilePtr file);
|
||||||
|
Loading…
Reference in New Issue
Block a user