mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-23 21:15:20 +00:00
virDomainDiskTranslateSourcePool: split code to setup one storage source
Extract all the code setting up one storage source from the rest which sets up the whole disk. This will allow us to prepare the whole backing chain. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
bc42d88ffd
commit
63469116cc
@ -31426,37 +31426,28 @@ virDomainDiskTranslateISCSIDirect(virStorageSourcePtr src,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
static int
|
||||||
virDomainDiskTranslateSourcePool(virDomainDiskDefPtr def)
|
virDomainStorageSourceTranslateSourcePool(virStorageSourcePtr src,
|
||||||
|
virConnectPtr conn)
|
||||||
{
|
{
|
||||||
virStorageVolInfo info;
|
virStorageVolInfo info;
|
||||||
g_autoptr(virStoragePoolDef) pooldef = NULL;
|
g_autoptr(virStoragePoolDef) pooldef = NULL;
|
||||||
g_autofree char *poolxml = NULL;
|
g_autofree char *poolxml = NULL;
|
||||||
g_autoptr(virConnect) conn = NULL;
|
|
||||||
g_autoptr(virStoragePool) pool = NULL;
|
g_autoptr(virStoragePool) pool = NULL;
|
||||||
g_autoptr(virStorageVol) vol = NULL;
|
g_autoptr(virStorageVol) vol = NULL;
|
||||||
|
|
||||||
if (def->src->type != VIR_STORAGE_TYPE_VOLUME)
|
if (!(pool = virStoragePoolLookupByName(conn, src->srcpool->pool)))
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (!def->src->srcpool)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (!(conn = virGetConnectStorage()))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (!(pool = virStoragePoolLookupByName(conn, def->src->srcpool->pool)))
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (virStoragePoolIsActive(pool) != 1) {
|
if (virStoragePoolIsActive(pool) != 1) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
_("storage pool '%s' containing volume '%s' "
|
_("storage pool '%s' containing volume '%s' "
|
||||||
"is not active"),
|
"is not active"),
|
||||||
def->src->srcpool->pool, def->src->srcpool->volume);
|
src->srcpool->pool, src->srcpool->volume);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(vol = virStorageVolLookupByName(pool, def->src->srcpool->volume)))
|
if (!(vol = virStorageVolLookupByName(pool, src->srcpool->volume)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (virStorageVolGetInfo(vol, &info) < 0)
|
if (virStorageVolGetInfo(vol, &info) < 0)
|
||||||
@ -31468,22 +31459,22 @@ virDomainDiskTranslateSourcePool(virDomainDiskDefPtr def)
|
|||||||
if (!(pooldef = virStoragePoolDefParseString(poolxml)))
|
if (!(pooldef = virStoragePoolDefParseString(poolxml)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
def->src->srcpool->pooltype = pooldef->type;
|
src->srcpool->pooltype = pooldef->type;
|
||||||
def->src->srcpool->voltype = info.type;
|
src->srcpool->voltype = info.type;
|
||||||
|
|
||||||
if (def->src->srcpool->mode && pooldef->type != VIR_STORAGE_POOL_ISCSI) {
|
if (src->srcpool->mode && pooldef->type != VIR_STORAGE_POOL_ISCSI) {
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
_("disk source mode is only valid when "
|
_("disk source mode is only valid when "
|
||||||
"storage pool is of iscsi type"));
|
"storage pool is of iscsi type"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_FREE(def->src->path);
|
VIR_FREE(src->path);
|
||||||
virStorageNetHostDefFree(def->src->nhosts, def->src->hosts);
|
virStorageNetHostDefFree(src->nhosts, src->hosts);
|
||||||
def->src->nhosts = 0;
|
src->nhosts = 0;
|
||||||
def->src->hosts = NULL;
|
src->hosts = NULL;
|
||||||
virStorageAuthDefFree(def->src->auth);
|
virStorageAuthDefFree(src->auth);
|
||||||
def->src->auth = NULL;
|
src->auth = NULL;
|
||||||
|
|
||||||
switch ((virStoragePoolType) pooldef->type) {
|
switch ((virStoragePoolType) pooldef->type) {
|
||||||
case VIR_STORAGE_POOL_DIR:
|
case VIR_STORAGE_POOL_DIR:
|
||||||
@ -31494,32 +31485,24 @@ virDomainDiskTranslateSourcePool(virDomainDiskDefPtr def)
|
|||||||
case VIR_STORAGE_POOL_SCSI:
|
case VIR_STORAGE_POOL_SCSI:
|
||||||
case VIR_STORAGE_POOL_ZFS:
|
case VIR_STORAGE_POOL_ZFS:
|
||||||
case VIR_STORAGE_POOL_VSTORAGE:
|
case VIR_STORAGE_POOL_VSTORAGE:
|
||||||
if (!(def->src->path = virStorageVolGetPath(vol)))
|
if (!(src->path = virStorageVolGetPath(vol)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (def->startupPolicy && info.type != VIR_STORAGE_VOL_FILE) {
|
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
||||||
_("'startupPolicy' is only valid for "
|
|
||||||
"'file' type volume"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
switch (info.type) {
|
switch (info.type) {
|
||||||
case VIR_STORAGE_VOL_FILE:
|
case VIR_STORAGE_VOL_FILE:
|
||||||
def->src->srcpool->actualtype = VIR_STORAGE_TYPE_FILE;
|
src->srcpool->actualtype = VIR_STORAGE_TYPE_FILE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_STORAGE_VOL_DIR:
|
case VIR_STORAGE_VOL_DIR:
|
||||||
def->src->srcpool->actualtype = VIR_STORAGE_TYPE_DIR;
|
src->srcpool->actualtype = VIR_STORAGE_TYPE_DIR;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_STORAGE_VOL_BLOCK:
|
case VIR_STORAGE_VOL_BLOCK:
|
||||||
def->src->srcpool->actualtype = VIR_STORAGE_TYPE_BLOCK;
|
src->srcpool->actualtype = VIR_STORAGE_TYPE_BLOCK;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_STORAGE_VOL_PLOOP:
|
case VIR_STORAGE_VOL_PLOOP:
|
||||||
def->src->srcpool->actualtype = VIR_STORAGE_TYPE_FILE;
|
src->srcpool->actualtype = VIR_STORAGE_TYPE_FILE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_STORAGE_VOL_NETWORK:
|
case VIR_STORAGE_VOL_NETWORK:
|
||||||
@ -31535,39 +31518,25 @@ virDomainDiskTranslateSourcePool(virDomainDiskDefPtr def)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_STORAGE_POOL_ISCSI_DIRECT:
|
case VIR_STORAGE_POOL_ISCSI_DIRECT:
|
||||||
if (def->startupPolicy) {
|
if (virDomainDiskTranslateISCSIDirect(src, pooldef) < 0)
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
||||||
_("'startupPolicy' is only valid for "
|
|
||||||
"'file' type volume"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (virDomainDiskTranslateISCSIDirect(def->src, pooldef) < 0)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_STORAGE_POOL_ISCSI:
|
case VIR_STORAGE_POOL_ISCSI:
|
||||||
if (def->startupPolicy) {
|
switch (src->srcpool->mode) {
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
||||||
_("'startupPolicy' is only valid for "
|
|
||||||
"'file' type volume"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (def->src->srcpool->mode) {
|
|
||||||
case VIR_STORAGE_SOURCE_POOL_MODE_DEFAULT:
|
case VIR_STORAGE_SOURCE_POOL_MODE_DEFAULT:
|
||||||
case VIR_STORAGE_SOURCE_POOL_MODE_LAST:
|
case VIR_STORAGE_SOURCE_POOL_MODE_LAST:
|
||||||
def->src->srcpool->mode = VIR_STORAGE_SOURCE_POOL_MODE_HOST;
|
src->srcpool->mode = VIR_STORAGE_SOURCE_POOL_MODE_HOST;
|
||||||
G_GNUC_FALLTHROUGH;
|
G_GNUC_FALLTHROUGH;
|
||||||
case VIR_STORAGE_SOURCE_POOL_MODE_HOST:
|
case VIR_STORAGE_SOURCE_POOL_MODE_HOST:
|
||||||
def->src->srcpool->actualtype = VIR_STORAGE_TYPE_BLOCK;
|
src->srcpool->actualtype = VIR_STORAGE_TYPE_BLOCK;
|
||||||
if (!(def->src->path = virStorageVolGetPath(vol)))
|
if (!(src->path = virStorageVolGetPath(vol)))
|
||||||
return -1;
|
return -1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_STORAGE_SOURCE_POOL_MODE_DIRECT:
|
case VIR_STORAGE_SOURCE_POOL_MODE_DIRECT:
|
||||||
if (virDomainDiskTranslateISCSIDirect(def->src, pooldef) < 0)
|
if (virDomainDiskTranslateISCSIDirect(src, pooldef) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -31589,6 +31558,35 @@ virDomainDiskTranslateSourcePool(virDomainDiskDefPtr def)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
virDomainDiskTranslateSourcePool(virDomainDiskDefPtr def)
|
||||||
|
{
|
||||||
|
g_autoptr(virConnect) conn = NULL;
|
||||||
|
|
||||||
|
if (def->src->type != VIR_STORAGE_TYPE_VOLUME)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!def->src->srcpool)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!(conn = virGetConnectStorage()))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (virDomainStorageSourceTranslateSourcePool(def->src, conn) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (def->startupPolicy != 0 &&
|
||||||
|
virStorageSourceGetActualType(def->src) != VIR_STORAGE_VOL_FILE) {
|
||||||
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
|
_("'startupPolicy' is only valid for "
|
||||||
|
"'file' type volume"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virDomainDiskGetDetectZeroesMode:
|
* virDomainDiskGetDetectZeroesMode:
|
||||||
* @discard: disk/image sector discard setting
|
* @discard: disk/image sector discard setting
|
||||||
|
Loading…
x
Reference in New Issue
Block a user