[libvirt] [PATCH v3 0/2] bhyve: add volumes support

Changes from v1: - Add volume support for the bhyveload command as well to allow booting from a volume Changes from v2: - Move disk source pool translation to storage/storage_driver.c instead of conf/domain_conf.c, because having that in conf/domain_conf.c requires pulling storage driver that is not needed for many drivers Roman Bogorodskiy (2): conf: make disk source pool translation generic bhyve: add volumes support src/bhyve/bhyve_command.c | 17 ++- src/bhyve/bhyve_command.h | 7 +- src/bhyve/bhyve_driver.c | 4 +- src/bhyve/bhyve_process.c | 4 +- src/qemu/qemu_conf.c | 243 ------------------------------------------ src/qemu/qemu_conf.h | 3 - src/qemu/qemu_driver.c | 6 +- src/qemu/qemu_hotplug.c | 3 +- src/qemu/qemu_process.c | 5 +- src/storage/storage_driver.c | 245 +++++++++++++++++++++++++++++++++++++++++++ src/storage/storage_driver.h | 4 + tests/Makefile.am | 3 + tests/bhyvexml2argvtest.c | 5 +- tests/qemuxml2argvtest.c | 3 +- 14 files changed, 287 insertions(+), 265 deletions(-) -- 1.9.0

Currently, qemu driver uses qemuTranslateDiskSourcePool() to translate disk volume information. This function is general enough and could be used for other drivers as well, so move it to conf/domain_conf.c along with its helpers. - qemuTranslateDiskSourcePool: move to storage/storage_driver.c and rename to virStorageTranslateDiskSourcePool, - qemuAddISCSIPoolSourceHost: move to storage/storage_driver.c and rename to virStorageAddISCSIPoolSourceHost, - qemuTranslateDiskSourcePoolAuth: move to storage/storage_driver.c and rename to virStorageTranslateDiskSourcePoolAuth, - Update users of qemuTranslateDiskSourcePool to use a new name. --- src/qemu/qemu_conf.c | 243 ------------------------------------------ src/qemu/qemu_conf.h | 3 - src/qemu/qemu_driver.c | 6 +- src/qemu/qemu_hotplug.c | 3 +- src/qemu/qemu_process.c | 5 +- src/storage/storage_driver.c | 245 +++++++++++++++++++++++++++++++++++++++++++ src/storage/storage_driver.h | 4 + tests/qemuxml2argvtest.c | 3 +- 8 files changed, 259 insertions(+), 253 deletions(-) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 238d2b1..eef5be1 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1225,249 +1225,6 @@ int qemuDriverAllocateID(virQEMUDriverPtr driver) return virAtomicIntInc(&driver->nextvmid); } -static int -qemuAddISCSIPoolSourceHost(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; - - if (virAsprintf(&def->src->hosts[0].port, "%d", - pooldef->source.hosts[0].port ? - pooldef->source.hosts[0].port : - 3260) < 0) - goto cleanup; - - /* iscsi volume has name like "unit:0:0:1" */ - if (!(tokens = virStringSplit(def->src->srcpool->volume, ":", 0))) - goto cleanup; - - if (virStringListLength(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: - virStringFreeList(tokens); - return ret; -} - -static int -qemuTranslateDiskSourcePoolAuth(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; - ret = 0; - - cleanup: - return ret; -} - - -int -qemuTranslateDiskSourcePool(virConnectPtr conn, - virDomainDiskDefPtr def) -{ - virStoragePoolDefPtr pooldef = NULL; - virStoragePoolPtr pool = NULL; - virStorageVolPtr vol = NULL; - char *poolxml = NULL; - virStorageVolInfo info; - int ret = -1; - virErrorPtr savedError = NULL; - - 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); - virStorageAuthDefFree(def->src->auth); - - 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: - 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_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; - /* 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 (qemuTranslateDiskSourcePoolAuth(def, &pooldef->source) < 0) - goto cleanup; - - if (qemuAddISCSIPoolSourceHost(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: - if (ret < 0) - savedError = virSaveLastError(); - if (pool) - virStoragePoolFree(pool); - if (vol) - virStorageVolFree(vol); - if (savedError) { - virSetError(savedError); - virFreeError(savedError); - } - - VIR_FREE(poolxml); - virStoragePoolDefFree(pooldef); - return ret; -} - int qemuTranslateSnapshotDiskSourcePool(virConnectPtr conn ATTRIBUTE_UNUSED, diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 90aebef..3276412 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -307,9 +307,6 @@ int qemuSetUnprivSGIO(virDomainDeviceDefPtr dev); int qemuDriverAllocateID(virQEMUDriverPtr driver); virDomainXMLOptionPtr virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver); -int qemuTranslateDiskSourcePool(virConnectPtr conn, - virDomainDiskDefPtr def); - int qemuTranslateSnapshotDiskSourcePool(virConnectPtr conn, virDomainSnapshotDiskDefPtr def); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ac0717c..133354b 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6635,7 +6635,7 @@ qemuDomainChangeDiskMediaLive(virConnectPtr conn, virCapsPtr caps = NULL; int ret = -1; - if (qemuTranslateDiskSourcePool(conn, disk) < 0) + if (virStorageTranslateDiskSourcePool(conn, disk) < 0) goto end; if (qemuDomainDetermineDiskChain(driver, vm, disk, false) < 0) @@ -12581,7 +12581,7 @@ qemuDomainSnapshotPrepareDiskExternal(virConnectPtr conn, return -1; if (!active) { - if (qemuTranslateDiskSourcePool(conn, disk) < 0) + if (virStorageTranslateDiskSourcePool(conn, disk) < 0) return -1; if (qemuDomainSnapshotPrepareDiskExternalBackingInactive(disk) < 0) @@ -12639,7 +12639,7 @@ qemuDomainSnapshotPrepareDiskInternal(virConnectPtr conn, if (active) return 0; - if (qemuTranslateDiskSourcePool(conn, disk) < 0) + if (virStorageTranslateDiskSourcePool(conn, disk) < 0) return -1; actualType = virStorageSourceGetActualType(disk->src); diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index f7e223a..d8f66ac 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -49,6 +49,7 @@ #include "virstoragefile.h" #include "virstring.h" #include "virtime.h" +#include "storage/storage_driver.h" #define VIR_FROM_THIS VIR_FROM_QEMU @@ -722,7 +723,7 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn, goto end; } - if (qemuTranslateDiskSourcePool(conn, disk) < 0) + if (virStorageTranslateDiskSourcePool(conn, disk) < 0) goto end; if (qemuAddSharedDevice(driver, dev, vm->def->name) < 0) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 13c396f..1f55f5db 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -66,6 +66,7 @@ #include "virnuma.h" #include "virstring.h" #include "virhostdev.h" +#include "storage/storage_driver.h" #define VIR_FROM_THIS VIR_FROM_QEMU @@ -3321,7 +3322,7 @@ qemuProcessReconnect(void *opaque) for (i = 0; i < obj->def->ndisks; i++) { virDomainDeviceDef dev; - if (qemuTranslateDiskSourcePool(conn, obj->def->disks[i]) < 0) + if (virStorageTranslateDiskSourcePool(conn, obj->def->disks[i]) < 0) goto error; /* XXX we should be able to restore all data from XML in the future */ @@ -4000,7 +4001,7 @@ int qemuProcessStart(virConnectPtr conn, * cgroup and security setting. */ for (i = 0; i < vm->def->ndisks; i++) { - if (qemuTranslateDiskSourcePool(conn, vm->def->disks[i]) < 0) + if (virStorageTranslateDiskSourcePool(conn, vm->def->disks[i]) < 0) goto cleanup; } diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index d2fe2cc..3604613 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -2908,3 +2908,248 @@ virStorageFileGetMetadata(virStorageSourcePtr src, virHashFree(cycle); return ret; } + + +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; + + if (virAsprintf(&def->src->hosts[0].port, "%d", + pooldef->source.hosts[0].port ? + pooldef->source.hosts[0].port : + 3260) < 0) + goto cleanup; + + /* iscsi volume has name like "unit:0:0:1" */ + if (!(tokens = virStringSplit(def->src->srcpool->volume, ":", 0))) + goto cleanup; + + if (virStringListLength(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: + virStringFreeList(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; + 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; + virErrorPtr savedError = NULL; + + 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); + virStorageAuthDefFree(def->src->auth); + + 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: + 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_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; + /* 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; + + 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: + if (ret < 0) + savedError = virSaveLastError(); + if (pool) + virStoragePoolFree(pool); + if (vol) + virStorageVolFree(vol); + if (savedError) { + virSetError(savedError); + virFreeError(savedError); + } + + VIR_FREE(poolxml); + virStoragePoolDefFree(pooldef); + return ret; +} diff --git a/src/storage/storage_driver.h b/src/storage/storage_driver.h index 9592dd8..e773928 100644 --- a/src/storage/storage_driver.h +++ b/src/storage/storage_driver.h @@ -26,6 +26,7 @@ # include <sys/stat.h> +# include "domain_conf.h" # include "storage_conf.h" # include "virstoragefile.h" @@ -52,6 +53,9 @@ int virStorageFileGetMetadata(virStorageSourcePtr src, bool allow_probe) ATTRIBUTE_NONNULL(1); +int virStorageTranslateDiskSourcePool(virConnectPtr conn, + virDomainDiskDefPtr def); + int storageRegister(void); #endif /* __VIR_STORAGE_DRIVER_H__ */ diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 62b969c..65dc9c7 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -21,6 +21,7 @@ # include "conf/storage_conf.h" # include "cpu/cpu_map.h" # include "virstring.h" +# include "storage/storage_driver.h" # include "testutilsqemu.h" @@ -351,7 +352,7 @@ static int testCompareXMLToArgvFiles(const char *xml, } for (i = 0; i < vmdef->ndisks; i++) { - if (qemuTranslateDiskSourcePool(conn, vmdef->disks[i]) < 0) + if (virStorageTranslateDiskSourcePool(conn, vmdef->disks[i]) < 0) goto out; } -- 1.9.0

Update bhyveBuildDiskArgStr to support volumes: - Make virBhyveProcessBuildBhyveCmd and virBhyveProcessBuildLoadCmd take virConnectPtr as the first argument instead of bhyveConnPtr as virConnectPtr is needed for virStorageTranslateDiskSourcePool, - Add virStorageTranslateDiskSourcePool call to virBhyveProcessBuildBhyveCmd and virBhyveProcessBuildLoadCmd, - Allow disks of type VIR_STORAGE_TYPE_VOLUME --- src/bhyve/bhyve_command.c | 17 +++++++++++++---- src/bhyve/bhyve_command.h | 7 ++++--- src/bhyve/bhyve_driver.c | 4 ++-- src/bhyve/bhyve_process.c | 4 ++-- tests/Makefile.am | 3 +++ tests/bhyvexml2argvtest.c | 5 ++++- 6 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c index e2940e8..94829e7 100644 --- a/src/bhyve/bhyve_command.c +++ b/src/bhyve/bhyve_command.c @@ -33,6 +33,7 @@ #include "virnetdev.h" #include "virnetdevbridge.h" #include "virnetdevtap.h" +#include "storage/storage_driver.h" #define VIR_FROM_THIS VIR_FROM_BHYVE @@ -184,7 +185,8 @@ bhyveBuildDiskArgStr(const virDomainDef *def ATTRIBUTE_UNUSED, return -1; } - if (virDomainDiskGetType(disk) != VIR_STORAGE_TYPE_FILE) { + if ((virDomainDiskGetType(disk) != VIR_STORAGE_TYPE_FILE) && + (virDomainDiskGetType(disk) != VIR_STORAGE_TYPE_VOLUME)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("unsupported disk type")); return -1; @@ -209,7 +211,7 @@ bhyveBuildDiskArgStr(const virDomainDef *def ATTRIBUTE_UNUSED, } virCommandPtr -virBhyveProcessBuildBhyveCmd(bhyveConnPtr driver ATTRIBUTE_UNUSED, +virBhyveProcessBuildBhyveCmd(virConnectPtr conn, virDomainDefPtr def, bool dryRun) { /* @@ -263,6 +265,9 @@ virBhyveProcessBuildBhyveCmd(bhyveConnPtr driver ATTRIBUTE_UNUSED, for (i = 0; i < def->ndisks; i++) { virDomainDiskDefPtr disk = def->disks[i]; + if (virStorageTranslateDiskSourcePool(conn, disk) < 0) + goto error; + if (bhyveBuildDiskArgStr(def, disk, cmd) < 0) goto error; } @@ -290,7 +295,7 @@ virBhyveProcessBuildDestroyCmd(bhyveConnPtr driver ATTRIBUTE_UNUSED, } virCommandPtr -virBhyveProcessBuildLoadCmd(bhyveConnPtr driver ATTRIBUTE_UNUSED, +virBhyveProcessBuildLoadCmd(virConnectPtr conn, virDomainDefPtr def) { virCommandPtr cmd; @@ -304,6 +309,9 @@ virBhyveProcessBuildLoadCmd(bhyveConnPtr driver ATTRIBUTE_UNUSED, disk = def->disks[0]; + if (virStorageTranslateDiskSourcePool(conn, disk) < 0) + return NULL; + if ((disk->device != VIR_DOMAIN_DISK_DEVICE_DISK) && (disk->device != VIR_DOMAIN_DISK_DEVICE_CDROM)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", @@ -311,7 +319,8 @@ virBhyveProcessBuildLoadCmd(bhyveConnPtr driver ATTRIBUTE_UNUSED, return NULL; } - if (virDomainDiskGetType(disk) != VIR_STORAGE_TYPE_FILE) { + if ((virDomainDiskGetType(disk) != VIR_STORAGE_TYPE_FILE) && + (virDomainDiskGetType(disk) != VIR_STORAGE_TYPE_VOLUME)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("unsupported disk type")); return NULL; diff --git a/src/bhyve/bhyve_command.h b/src/bhyve/bhyve_command.h index 31de97a..5b323bf 100644 --- a/src/bhyve/bhyve_command.h +++ b/src/bhyve/bhyve_command.h @@ -29,15 +29,16 @@ # define BHYVE_CONFIG_FORMAT_ARGV "bhyve-argv" -virCommandPtr virBhyveProcessBuildBhyveCmd(bhyveConnPtr, - virDomainDefPtr def, bool dryRun); +virCommandPtr virBhyveProcessBuildBhyveCmd(virConnectPtr conn, + virDomainDefPtr def, + bool dryRun); virCommandPtr virBhyveProcessBuildDestroyCmd(bhyveConnPtr driver, virDomainDefPtr def); virCommandPtr -virBhyveProcessBuildLoadCmd(bhyveConnPtr driver, +virBhyveProcessBuildLoadCmd(virConnectPtr conn, virDomainDefPtr def); #endif /* __BHYVE_COMMAND_H__ */ diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index eb8f9af..d2f9c73 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -689,10 +689,10 @@ bhyveConnectDomainXMLToNative(virConnectPtr conn, if (bhyveDomainAssignAddresses(def, NULL) < 0) goto cleanup; - if (!(loadcmd = virBhyveProcessBuildLoadCmd(privconn, def))) + if (!(loadcmd = virBhyveProcessBuildLoadCmd(conn, def))) goto cleanup; - if (!(cmd = virBhyveProcessBuildBhyveCmd(privconn, def, true))) + if (!(cmd = virBhyveProcessBuildBhyveCmd(conn, def, true))) goto cleanup; virBufferAdd(&buf, virCommandToString(loadcmd), -1); diff --git a/src/bhyve/bhyve_process.c b/src/bhyve/bhyve_process.c index 168202e..6b5403d 100644 --- a/src/bhyve/bhyve_process.c +++ b/src/bhyve/bhyve_process.c @@ -137,7 +137,7 @@ virBhyveProcessStart(virConnectPtr conn, goto cleanup; /* Call bhyve to start the VM */ - if (!(cmd = virBhyveProcessBuildBhyveCmd(driver, + if (!(cmd = virBhyveProcessBuildBhyveCmd(conn, vm->def, false))) goto cleanup; @@ -151,7 +151,7 @@ virBhyveProcessStart(virConnectPtr conn, /* Now bhyve command is constructed, meaning the * domain is ready to be started, so we can build * and execute bhyveload command */ - if (!(load_cmd = virBhyveProcessBuildLoadCmd(driver, vm->def))) + if (!(load_cmd = virBhyveProcessBuildLoadCmd(conn, vm->def))) goto cleanup; virCommandSetOutputFD(load_cmd, &logfd); virCommandSetErrorFD(load_cmd, &logfd); diff --git a/tests/Makefile.am b/tests/Makefile.am index 3e71069..d6c3cfb 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -674,6 +674,9 @@ bhyvexml2argvmock_la_LDFLAGS = -module -avoid-version \ -rpath /evil/libtool/hack/to/force/shared/lib/creation bhyve_LDADDS = ../src/libvirt_driver_bhyve_impl.la +if WITH_STORAGE +bhyve_LDADDS += ../src/libvirt_driver_storage_impl.la +endif WITH_STORAGE bhyve_LDADDS += $(LDADDS) bhyvexml2argvtest_SOURCES = \ bhyvexml2argvtest.c \ diff --git a/tests/bhyvexml2argvtest.c b/tests/bhyvexml2argvtest.c index 408c73a..b9be378 100644 --- a/tests/bhyvexml2argvtest.c +++ b/tests/bhyvexml2argvtest.c @@ -23,8 +23,11 @@ static int testCompareXMLToArgvFiles(const char *xml, virDomainDefPtr vmdef = NULL; virDomainObj vm; virCommandPtr cmd = NULL; + virConnectPtr conn; int ret = -1; + if (!(conn = virGetConnect())) + goto out; if (!(vmdef = virDomainDefParseFile(xml, driver.caps, driver.xmlopt, 1 << VIR_DOMAIN_VIRT_BHYVE, @@ -33,7 +36,7 @@ static int testCompareXMLToArgvFiles(const char *xml, vm.def = vmdef; - if (!(cmd = virBhyveProcessBuildBhyveCmd(&driver, vmdef, false))) + if (!(cmd = virBhyveProcessBuildBhyveCmd(conn, vmdef, false))) goto out; if (!(actualargv = virCommandToString(cmd))) -- 1.9.0

On 15.08.2014 17:58, Roman Bogorodskiy wrote:
Changes from v1:
- Add volume support for the bhyveload command as well to allow booting from a volume
Changes from v2:
- Move disk source pool translation to storage/storage_driver.c instead of conf/domain_conf.c, because having that in conf/domain_conf.c requires pulling storage driver that is not needed for many drivers
Roman Bogorodskiy (2): conf: make disk source pool translation generic bhyve: add volumes support
src/bhyve/bhyve_command.c | 17 ++- src/bhyve/bhyve_command.h | 7 +- src/bhyve/bhyve_driver.c | 4 +- src/bhyve/bhyve_process.c | 4 +- src/qemu/qemu_conf.c | 243 ------------------------------------------ src/qemu/qemu_conf.h | 3 - src/qemu/qemu_driver.c | 6 +- src/qemu/qemu_hotplug.c | 3 +- src/qemu/qemu_process.c | 5 +- src/storage/storage_driver.c | 245 +++++++++++++++++++++++++++++++++++++++++++ src/storage/storage_driver.h | 4 + tests/Makefile.am | 3 + tests/bhyvexml2argvtest.c | 5 +- tests/qemuxml2argvtest.c | 3 +- 14 files changed, 287 insertions(+), 265 deletions(-)
ACK series Michal

Michal Privoznik wrote:
On 15.08.2014 17:58, Roman Bogorodskiy wrote:
Changes from v1:
- Add volume support for the bhyveload command as well to allow booting from a volume
Changes from v2:
- Move disk source pool translation to storage/storage_driver.c instead of conf/domain_conf.c, because having that in conf/domain_conf.c requires pulling storage driver that is not needed for many drivers
Roman Bogorodskiy (2): conf: make disk source pool translation generic bhyve: add volumes support
src/bhyve/bhyve_command.c | 17 ++- src/bhyve/bhyve_command.h | 7 +- src/bhyve/bhyve_driver.c | 4 +- src/bhyve/bhyve_process.c | 4 +- src/qemu/qemu_conf.c | 243 ------------------------------------------ src/qemu/qemu_conf.h | 3 - src/qemu/qemu_driver.c | 6 +- src/qemu/qemu_hotplug.c | 3 +- src/qemu/qemu_process.c | 5 +- src/storage/storage_driver.c | 245 +++++++++++++++++++++++++++++++++++++++++++ src/storage/storage_driver.h | 4 + tests/Makefile.am | 3 + tests/bhyvexml2argvtest.c | 5 +- tests/qemuxml2argvtest.c | 3 +- 14 files changed, 287 insertions(+), 265 deletions(-)
ACK series
Pushed, thanks! I replaced 'conf:' with 'storage:' in the first commit's title along the way because the functions ended up in the storage driver. Roman Bogorodskiy
participants (2)
-
Michal Privoznik
-
Roman Bogorodskiy