diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c index 55032ae1df..c1241b8110 100644 --- a/src/bhyve/bhyve_command.c +++ b/src/bhyve/bhyve_command.c @@ -37,7 +37,6 @@ #include "virnetdev.h" #include "virnetdevbridge.h" #include "virnetdevtap.h" -#include "storage/storage_driver.h" #define VIR_FROM_THIS VIR_FROM_BHYVE @@ -199,7 +198,7 @@ bhyveBuildAHCIControllerArgStr(const virDomainDef *def, goto error; } - if (virStorageTranslateDiskSourcePool(conn, disk) < 0) + if (virDomainDiskTranslateSourcePool(conn, disk) < 0) goto error; disk_source = virDomainDiskGetSource(disk); @@ -295,7 +294,7 @@ bhyveBuildVirtIODiskArgStr(const virDomainDef *def ATTRIBUTE_UNUSED, { const char *disk_source; - if (virStorageTranslateDiskSourcePool(conn, disk) < 0) + if (virDomainDiskTranslateSourcePool(conn, disk) < 0) return -1; if (disk->device != VIR_DOMAIN_DISK_DEVICE_DISK) { @@ -676,7 +675,7 @@ static bool virBhyveUsableDisk(virConnectPtr conn, virDomainDiskDefPtr disk) { - if (virStorageTranslateDiskSourcePool(conn, disk) < 0) + if (virDomainDiskTranslateSourcePool(conn, disk) < 0) return false; if ((disk->device != VIR_DOMAIN_DISK_DEVICE_DISK) && diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1423cf2c55..fb732a0c2a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -28919,3 +28919,256 @@ virDomainNetResolveActualType(virDomainNetDefPtr iface) return netResolveActualType(iface); } + + +static int +virDomainDiskAddISCSIPoolSourceHost(virDomainDiskDefPtr def, + virStoragePoolDefPtr pooldef) +{ + int ret = -1; + char **tokens = NULL; + + /* Only support one host */ + if (pooldef->source.nhost != 1) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Expected exactly 1 host for the storage pool")); + goto cleanup; + } + + /* iscsi pool only supports one host */ + def->src->nhosts = 1; + + if (VIR_ALLOC_N(def->src->hosts, def->src->nhosts) < 0) + goto cleanup; + + if (VIR_STRDUP(def->src->hosts[0].name, pooldef->source.hosts[0].name) < 0) + goto cleanup; + + def->src->hosts[0].port = pooldef->source.hosts[0].port ? + pooldef->source.hosts[0].port : 3260; + + /* iscsi volume has name like "unit:0:0:1" */ + if (!(tokens = virStringSplit(def->src->srcpool->volume, ":", 0))) + goto cleanup; + + if (virStringListLength((const char * const *)tokens) != 4) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected iscsi volume name '%s'"), + def->src->srcpool->volume); + goto cleanup; + } + + /* iscsi pool has only one source device path */ + if (virAsprintf(&def->src->path, "%s/%s", + pooldef->source.devices[0].path, + tokens[3]) < 0) + goto cleanup; + + /* Storage pool have not supported these 2 attributes yet, + * use the defaults. + */ + def->src->hosts[0].transport = VIR_STORAGE_NET_HOST_TRANS_TCP; + def->src->hosts[0].socket = NULL; + + def->src->protocol = VIR_STORAGE_NET_PROTOCOL_ISCSI; + + ret = 0; + + cleanup: + virStringListFree(tokens); + return ret; +} + + +static int +virDomainDiskTranslateSourcePoolAuth(virDomainDiskDefPtr def, + virStoragePoolSourcePtr source) +{ + int ret = -1; + + /* Only necessary when authentication set */ + if (!source->auth) { + ret = 0; + goto cleanup; + } + def->src->auth = virStorageAuthDefCopy(source->auth); + if (!def->src->auth) + goto cleanup; + /* A doesn't use src->auth->authType = VIR_STORAGE_AUTH_TYPE_NONE; + ret = 0; + + cleanup: + return ret; +} + + +int +virDomainDiskTranslateSourcePool(virConnectPtr conn, + virDomainDiskDefPtr def) +{ + virStoragePoolDefPtr pooldef = NULL; + virStoragePoolPtr pool = NULL; + virStorageVolPtr vol = NULL; + char *poolxml = NULL; + virStorageVolInfo info; + int ret = -1; + + if (def->src->type != VIR_STORAGE_TYPE_VOLUME) + return 0; + + if (!def->src->srcpool) + return 0; + + if (!(pool = virStoragePoolLookupByName(conn, def->src->srcpool->pool))) + return -1; + + if (virStoragePoolIsActive(pool) != 1) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("storage pool '%s' containing volume '%s' " + "is not active"), + def->src->srcpool->pool, def->src->srcpool->volume); + goto cleanup; + } + + if (!(vol = virStorageVolLookupByName(pool, def->src->srcpool->volume))) + goto cleanup; + + if (virStorageVolGetInfo(vol, &info) < 0) + goto cleanup; + + if (!(poolxml = virStoragePoolGetXMLDesc(pool, 0))) + goto cleanup; + + if (!(pooldef = virStoragePoolDefParseString(poolxml))) + goto cleanup; + + def->src->srcpool->pooltype = pooldef->type; + def->src->srcpool->voltype = info.type; + + if (def->src->srcpool->mode && pooldef->type != VIR_STORAGE_POOL_ISCSI) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("disk source mode is only valid when " + "storage pool is of iscsi type")); + goto cleanup; + } + + VIR_FREE(def->src->path); + virStorageNetHostDefFree(def->src->nhosts, def->src->hosts); + def->src->nhosts = 0; + def->src->hosts = NULL; + virStorageAuthDefFree(def->src->auth); + def->src->auth = NULL; + + switch ((virStoragePoolType) pooldef->type) { + case VIR_STORAGE_POOL_DIR: + case VIR_STORAGE_POOL_FS: + case VIR_STORAGE_POOL_NETFS: + case VIR_STORAGE_POOL_LOGICAL: + case VIR_STORAGE_POOL_DISK: + case VIR_STORAGE_POOL_SCSI: + case VIR_STORAGE_POOL_ZFS: + case VIR_STORAGE_POOL_VSTORAGE: + if (!(def->src->path = virStorageVolGetPath(vol))) + goto cleanup; + + if (def->startupPolicy && info.type != VIR_STORAGE_VOL_FILE) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("'startupPolicy' is only valid for " + "'file' type volume")); + goto cleanup; + } + + + switch (info.type) { + case VIR_STORAGE_VOL_FILE: + def->src->srcpool->actualtype = VIR_STORAGE_TYPE_FILE; + break; + + case VIR_STORAGE_VOL_DIR: + def->src->srcpool->actualtype = VIR_STORAGE_TYPE_DIR; + break; + + case VIR_STORAGE_VOL_BLOCK: + def->src->srcpool->actualtype = VIR_STORAGE_TYPE_BLOCK; + break; + + case VIR_STORAGE_VOL_PLOOP: + def->src->srcpool->actualtype = VIR_STORAGE_TYPE_FILE; + break; + + case VIR_STORAGE_VOL_NETWORK: + case VIR_STORAGE_VOL_NETDIR: + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected storage volume type '%s' " + "for storage pool type '%s'"), + virStorageVolTypeToString(info.type), + virStoragePoolTypeToString(pooldef->type)); + goto cleanup; + } + + break; + + case VIR_STORAGE_POOL_ISCSI: + if (def->startupPolicy) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("'startupPolicy' is only valid for " + "'file' type volume")); + goto cleanup; + } + + switch (def->src->srcpool->mode) { + case VIR_STORAGE_SOURCE_POOL_MODE_DEFAULT: + case VIR_STORAGE_SOURCE_POOL_MODE_LAST: + def->src->srcpool->mode = VIR_STORAGE_SOURCE_POOL_MODE_HOST; + ATTRIBUTE_FALLTHROUGH; + case VIR_STORAGE_SOURCE_POOL_MODE_HOST: + def->src->srcpool->actualtype = VIR_STORAGE_TYPE_BLOCK; + if (!(def->src->path = virStorageVolGetPath(vol))) + goto cleanup; + break; + + case VIR_STORAGE_SOURCE_POOL_MODE_DIRECT: + def->src->srcpool->actualtype = VIR_STORAGE_TYPE_NETWORK; + def->src->protocol = VIR_STORAGE_NET_PROTOCOL_ISCSI; + + if (virDomainDiskTranslateSourcePoolAuth(def, + &pooldef->source) < 0) + goto cleanup; + + /* Source pool may not fill in the secrettype field, + * so we need to do so here + */ + if (def->src->auth && !def->src->auth->secrettype) { + const char *secrettype = + virSecretUsageTypeToString(VIR_SECRET_USAGE_TYPE_ISCSI); + if (VIR_STRDUP(def->src->auth->secrettype, secrettype) < 0) + goto cleanup; + } + + if (virDomainDiskAddISCSIPoolSourceHost(def, pooldef) < 0) + goto cleanup; + break; + } + break; + + case VIR_STORAGE_POOL_MPATH: + case VIR_STORAGE_POOL_RBD: + case VIR_STORAGE_POOL_SHEEPDOG: + case VIR_STORAGE_POOL_GLUSTER: + case VIR_STORAGE_POOL_LAST: + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("using '%s' pools for backing 'volume' disks " + "isn't yet supported"), + virStoragePoolTypeToString(pooldef->type)); + goto cleanup; + } + + ret = 0; + cleanup: + virObjectUnref(pool); + virObjectUnref(vol); + VIR_FREE(poolxml); + virStoragePoolDefFree(pooldef); + return ret; +} diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 8aba0b562f..6cd81ef2de 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3523,4 +3523,8 @@ virDomainNetResolveActualType(virDomainNetDefPtr iface) ATTRIBUTE_NONNULL(1); +int virDomainDiskTranslateSourcePool(virConnectPtr conn, + virDomainDiskDefPtr def); + + #endif /* __DOMAIN_CONF_H */ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index f2801a0d73..3b14d7d158 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -345,6 +345,7 @@ virDomainDiskSetDriver; virDomainDiskSetFormat; virDomainDiskSetSource; virDomainDiskSetType; +virDomainDiskTranslateSourcePool; virDomainFSDefFree; virDomainFSDefNew; virDomainFSDriverTypeToString; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 44b5655bdb..978ecd4e07 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -99,7 +99,6 @@ #include "virstring.h" #include "viraccessapicheck.h" #include "viraccessapicheckqemu.h" -#include "storage/storage_driver.h" #include "virhostdev.h" #include "domain_capabilities.h" #include "vircgroup.h" @@ -7882,7 +7881,7 @@ qemuDomainChangeDiskLive(virConnectPtr conn, virDomainDiskDefPtr orig_disk = NULL; int ret = -1; - if (virStorageTranslateDiskSourcePool(conn, disk) < 0) + if (virDomainDiskTranslateSourcePool(conn, disk) < 0) goto cleanup; if (qemuDomainDetermineDiskChain(driver, vm, disk, false, true) < 0) @@ -8009,7 +8008,7 @@ qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef, _("target %s already exists"), disk->dst); return -1; } - if (virStorageTranslateDiskSourcePool(conn, disk) < 0) + if (virDomainDiskTranslateSourcePool(conn, disk) < 0) return -1; if (qemuCheckDiskConfig(disk, NULL) < 0) return -1; @@ -14244,7 +14243,7 @@ qemuDomainSnapshotPrepareDiskExternal(virConnectPtr conn, return -1; if (!active) { - if (virStorageTranslateDiskSourcePool(conn, disk) < 0) + if (virDomainDiskTranslateSourcePool(conn, disk) < 0) return -1; if (qemuDomainSnapshotPrepareDiskExternalInactive(snapdisk, disk) < 0) @@ -14296,7 +14295,7 @@ qemuDomainSnapshotPrepareDiskInternal(virConnectPtr conn, if (active) return 0; - if (virStorageTranslateDiskSourcePool(conn, disk) < 0) + if (virDomainDiskTranslateSourcePool(conn, disk) < 0) return -1; actualType = virStorageSourceGetActualType(disk->src); diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 1a406b6d26..c7bf25eeef 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -56,7 +56,6 @@ #include "virstoragefile.h" #include "virstring.h" #include "virtime.h" -#include "storage/storage_driver.h" #define VIR_FROM_THIS VIR_FROM_QEMU @@ -714,7 +713,7 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn, goto cleanup; } - if (virStorageTranslateDiskSourcePool(conn, disk) < 0) + if (virDomainDiskTranslateSourcePool(conn, disk) < 0) goto cleanup; if (qemuAddSharedDevice(driver, dev, vm->def->name) < 0) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 7cfe581b3d..10211de871 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -72,7 +72,6 @@ #include "virstring.h" #include "virhostdev.h" #include "secret_util.h" -#include "storage/storage_driver.h" #include "configmake.h" #include "nwfilter_conf.h" #include "netdev_bandwidth_conf.h" @@ -5605,7 +5604,7 @@ qemuProcessPrepareDomainStorage(virConnectPtr conn, size_t idx = i - 1; virDomainDiskDefPtr disk = vm->def->disks[idx]; - if (virStorageTranslateDiskSourcePool(conn, disk) < 0) { + if (virDomainDiskTranslateSourcePool(conn, disk) < 0) { if (qemuDomainCheckDiskStartupPolicy(driver, vm, idx, cold_boot) < 0) return -1; @@ -7365,7 +7364,7 @@ qemuProcessReconnect(void *opaque) virDomainDiskDefPtr disk = obj->def->disks[i]; virDomainDeviceDef dev; - if (virStorageTranslateDiskSourcePool(conn, disk) < 0) + if (virDomainDiskTranslateSourcePool(conn, disk) < 0) goto error; /* backing chains need to be refreshed only if they could change */ diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index f2afb0b3f9..1b4bce4fc8 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -2752,257 +2752,6 @@ storageConnectStoragePoolEventDeregisterAny(virConnectPtr conn, } -static int -virStorageAddISCSIPoolSourceHost(virDomainDiskDefPtr def, - virStoragePoolDefPtr pooldef) -{ - int ret = -1; - char **tokens = NULL; - - /* Only support one host */ - if (pooldef->source.nhost != 1) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Expected exactly 1 host for the storage pool")); - goto cleanup; - } - - /* iscsi pool only supports one host */ - def->src->nhosts = 1; - - if (VIR_ALLOC_N(def->src->hosts, def->src->nhosts) < 0) - goto cleanup; - - if (VIR_STRDUP(def->src->hosts[0].name, pooldef->source.hosts[0].name) < 0) - goto cleanup; - - def->src->hosts[0].port = pooldef->source.hosts[0].port ? - pooldef->source.hosts[0].port : 3260; - - /* iscsi volume has name like "unit:0:0:1" */ - if (!(tokens = virStringSplit(def->src->srcpool->volume, ":", 0))) - goto cleanup; - - if (virStringListLength((const char * const *)tokens) != 4) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected iscsi volume name '%s'"), - def->src->srcpool->volume); - goto cleanup; - } - - /* iscsi pool has only one source device path */ - if (virAsprintf(&def->src->path, "%s/%s", - pooldef->source.devices[0].path, - tokens[3]) < 0) - goto cleanup; - - /* Storage pool have not supported these 2 attributes yet, - * use the defaults. - */ - def->src->hosts[0].transport = VIR_STORAGE_NET_HOST_TRANS_TCP; - def->src->hosts[0].socket = NULL; - - def->src->protocol = VIR_STORAGE_NET_PROTOCOL_ISCSI; - - ret = 0; - - cleanup: - virStringListFree(tokens); - return ret; -} - - -static int -virStorageTranslateDiskSourcePoolAuth(virDomainDiskDefPtr def, - virStoragePoolSourcePtr source) -{ - int ret = -1; - - /* Only necessary when authentication set */ - if (!source->auth) { - ret = 0; - goto cleanup; - } - def->src->auth = virStorageAuthDefCopy(source->auth); - if (!def->src->auth) - goto cleanup; - /* A doesn't use src->auth->authType = VIR_STORAGE_AUTH_TYPE_NONE; - ret = 0; - - cleanup: - return ret; -} - - -int -virStorageTranslateDiskSourcePool(virConnectPtr conn, - virDomainDiskDefPtr def) -{ - virStoragePoolDefPtr pooldef = NULL; - virStoragePoolPtr pool = NULL; - virStorageVolPtr vol = NULL; - char *poolxml = NULL; - virStorageVolInfo info; - int ret = -1; - - if (def->src->type != VIR_STORAGE_TYPE_VOLUME) - return 0; - - if (!def->src->srcpool) - return 0; - - if (!(pool = virStoragePoolLookupByName(conn, def->src->srcpool->pool))) - return -1; - - if (virStoragePoolIsActive(pool) != 1) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("storage pool '%s' containing volume '%s' " - "is not active"), - def->src->srcpool->pool, def->src->srcpool->volume); - goto cleanup; - } - - if (!(vol = virStorageVolLookupByName(pool, def->src->srcpool->volume))) - goto cleanup; - - if (virStorageVolGetInfo(vol, &info) < 0) - goto cleanup; - - if (!(poolxml = virStoragePoolGetXMLDesc(pool, 0))) - goto cleanup; - - if (!(pooldef = virStoragePoolDefParseString(poolxml))) - goto cleanup; - - def->src->srcpool->pooltype = pooldef->type; - def->src->srcpool->voltype = info.type; - - if (def->src->srcpool->mode && pooldef->type != VIR_STORAGE_POOL_ISCSI) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("disk source mode is only valid when " - "storage pool is of iscsi type")); - goto cleanup; - } - - VIR_FREE(def->src->path); - virStorageNetHostDefFree(def->src->nhosts, def->src->hosts); - def->src->nhosts = 0; - def->src->hosts = NULL; - virStorageAuthDefFree(def->src->auth); - def->src->auth = NULL; - - switch ((virStoragePoolType) pooldef->type) { - case VIR_STORAGE_POOL_DIR: - case VIR_STORAGE_POOL_FS: - case VIR_STORAGE_POOL_NETFS: - case VIR_STORAGE_POOL_LOGICAL: - case VIR_STORAGE_POOL_DISK: - case VIR_STORAGE_POOL_SCSI: - case VIR_STORAGE_POOL_ZFS: - case VIR_STORAGE_POOL_VSTORAGE: - if (!(def->src->path = virStorageVolGetPath(vol))) - goto cleanup; - - if (def->startupPolicy && info.type != VIR_STORAGE_VOL_FILE) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("'startupPolicy' is only valid for " - "'file' type volume")); - goto cleanup; - } - - - switch (info.type) { - case VIR_STORAGE_VOL_FILE: - def->src->srcpool->actualtype = VIR_STORAGE_TYPE_FILE; - break; - - case VIR_STORAGE_VOL_DIR: - def->src->srcpool->actualtype = VIR_STORAGE_TYPE_DIR; - break; - - case VIR_STORAGE_VOL_BLOCK: - def->src->srcpool->actualtype = VIR_STORAGE_TYPE_BLOCK; - break; - - case VIR_STORAGE_VOL_PLOOP: - def->src->srcpool->actualtype = VIR_STORAGE_TYPE_FILE; - break; - - case VIR_STORAGE_VOL_NETWORK: - case VIR_STORAGE_VOL_NETDIR: - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected storage volume type '%s' " - "for storage pool type '%s'"), - virStorageVolTypeToString(info.type), - virStoragePoolTypeToString(pooldef->type)); - goto cleanup; - } - - break; - - case VIR_STORAGE_POOL_ISCSI: - if (def->startupPolicy) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("'startupPolicy' is only valid for " - "'file' type volume")); - goto cleanup; - } - - switch (def->src->srcpool->mode) { - case VIR_STORAGE_SOURCE_POOL_MODE_DEFAULT: - case VIR_STORAGE_SOURCE_POOL_MODE_LAST: - def->src->srcpool->mode = VIR_STORAGE_SOURCE_POOL_MODE_HOST; - ATTRIBUTE_FALLTHROUGH; - case VIR_STORAGE_SOURCE_POOL_MODE_HOST: - def->src->srcpool->actualtype = VIR_STORAGE_TYPE_BLOCK; - if (!(def->src->path = virStorageVolGetPath(vol))) - goto cleanup; - break; - - case VIR_STORAGE_SOURCE_POOL_MODE_DIRECT: - def->src->srcpool->actualtype = VIR_STORAGE_TYPE_NETWORK; - def->src->protocol = VIR_STORAGE_NET_PROTOCOL_ISCSI; - - if (virStorageTranslateDiskSourcePoolAuth(def, - &pooldef->source) < 0) - goto cleanup; - - /* Source pool may not fill in the secrettype field, - * so we need to do so here - */ - if (def->src->auth && !def->src->auth->secrettype) { - const char *secrettype = - virSecretUsageTypeToString(VIR_SECRET_USAGE_TYPE_ISCSI); - if (VIR_STRDUP(def->src->auth->secrettype, secrettype) < 0) - goto cleanup; - } - - if (virStorageAddISCSIPoolSourceHost(def, pooldef) < 0) - goto cleanup; - break; - } - break; - - case VIR_STORAGE_POOL_MPATH: - case VIR_STORAGE_POOL_RBD: - case VIR_STORAGE_POOL_SHEEPDOG: - case VIR_STORAGE_POOL_GLUSTER: - case VIR_STORAGE_POOL_LAST: - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("using '%s' pools for backing 'volume' disks " - "isn't yet supported"), - virStoragePoolTypeToString(pooldef->type)); - goto cleanup; - } - - ret = 0; - cleanup: - virObjectUnref(pool); - virObjectUnref(vol); - VIR_FREE(poolxml); - virStoragePoolDefFree(pooldef); - return ret; -} /* diff --git a/src/storage/storage_driver.h b/src/storage/storage_driver.h index fd2fae1ba2..c284bf520f 100644 --- a/src/storage/storage_driver.h +++ b/src/storage/storage_driver.h @@ -29,9 +29,6 @@ # include "domain_conf.h" # include "virstorageobj.h" -int virStorageTranslateDiskSourcePool(virConnectPtr conn, - virDomainDiskDefPtr def); - virStoragePoolObjPtr virStoragePoolObjFindPoolByUUID(const unsigned char *uuid) ATTRIBUTE_NONNULL(1);