提交 e1e1fcf7 编写于 作者: J John Ferlan

storage_util: Introduce storageBackendCreateQemuImgSetInput

Split up virStorageBackendCreateQemuImgCmdFromVol into two parts.
It's too long anyway and virStorageBackendCreateQemuImgCmdFromVol
should just handle the command line processing.

NB: Requires changing info.* into info->* references.
Signed-off-by: NJohn Ferlan <jferlan@redhat.com>
上级 4b9055c9
...@@ -1116,91 +1116,105 @@ storageBackendResizeQemuImgImageOpts(virCommandPtr cmd, ...@@ -1116,91 +1116,105 @@ storageBackendResizeQemuImgImageOpts(virCommandPtr cmd,
} }
/* Create a qemu-img virCommand from the supplied arguments */ static int
virCommandPtr virStorageBackendCreateQemuImgSetInfo(virStoragePoolObjPtr pool,
virStorageBackendCreateQemuImgCmdFromVol(virStoragePoolObjPtr pool, virStorageVolDefPtr vol,
virStorageVolDefPtr vol, virStorageVolDefPtr inputvol,
virStorageVolDefPtr inputvol, struct _virStorageBackendQemuImgInfo *info)
unsigned int flags,
const char *create_tool,
const char *secretPath)
{ {
virCommandPtr cmd = NULL;
struct _virStorageBackendQemuImgInfo info = {
.format = vol->target.format,
.type = NULL,
.path = vol->target.path,
.allocation = vol->target.allocation,
.encryption = !!vol->target.encryption,
.preallocate = !!(flags & VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA),
.compat = vol->target.compat,
.features = vol->target.features,
.nocow = vol->target.nocow,
.secretPath = secretPath,
.secretAlias = NULL,
};
virStorageEncryptionInfoDefPtr enc = NULL;
virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA, NULL);
/* Treat output block devices as 'raw' format */ /* Treat output block devices as 'raw' format */
if (vol->type == VIR_STORAGE_VOL_BLOCK) if (vol->type == VIR_STORAGE_VOL_BLOCK)
info.format = VIR_STORAGE_FILE_RAW; info->format = VIR_STORAGE_FILE_RAW;
if (info.format == VIR_STORAGE_FILE_ISO) if (info->format == VIR_STORAGE_FILE_ISO)
info.format = VIR_STORAGE_FILE_RAW; info->format = VIR_STORAGE_FILE_RAW;
if (!(info.type = virStorageFileFormatTypeToString(info.format))) { if (!(info->type = virStorageFileFormatTypeToString(info->format))) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("unknown storage vol type %d"), _("unknown storage vol type %d"),
info.format); info->format);
return NULL; return -1;
} }
if (info.preallocate && info.format != VIR_STORAGE_FILE_QCOW2) { if (info->preallocate && info->format != VIR_STORAGE_FILE_QCOW2) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("metadata preallocation only available with qcow2")); _("metadata preallocation only available with qcow2"));
return NULL; return -1;
} }
if (info.compat && info.format != VIR_STORAGE_FILE_QCOW2) { if (info->compat && info->format != VIR_STORAGE_FILE_QCOW2) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("compatibility option only available with qcow2")); _("compatibility option only available with qcow2"));
return NULL; return -1;
} }
if (info.features && info.format != VIR_STORAGE_FILE_QCOW2) { if (info->features && info->format != VIR_STORAGE_FILE_QCOW2) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("format features only available with qcow2")); _("format features only available with qcow2"));
return NULL; return -1;
} }
if (info.format == VIR_STORAGE_FILE_RAW && vol->target.encryption) { if (info->format == VIR_STORAGE_FILE_RAW && vol->target.encryption) {
if (inputvol) { if (inputvol) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("cannot use inputvol with encrypted raw volume")); _("cannot use inputvol with encrypted raw volume"));
return NULL; return -1;
} }
if (vol->target.encryption->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) { if (vol->target.encryption->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) {
info.type = "luks"; info->type = "luks";
} else { } else {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Only luks encryption is supported for raw files")); _("Only luks encryption is supported for raw files"));
return NULL; return -1;
} }
} }
if (inputvol && if (inputvol &&
storageBackendCreateQemuImgSetInput(inputvol, &info) < 0) storageBackendCreateQemuImgSetInput(inputvol, info) < 0)
return NULL; return -1;
if (virStorageSourceHasBacking(&vol->target) && if (virStorageSourceHasBacking(&vol->target) &&
storageBackendCreateQemuImgSetBacking(pool, vol, inputvol, &info) < 0) storageBackendCreateQemuImgSetBacking(pool, vol, inputvol, info) < 0)
return NULL; return -1;
if (info.encryption && if (info->encryption &&
storageBackendCreateQemuImgCheckEncryption(info.format, info.type, vol) < 0) storageBackendCreateQemuImgCheckEncryption(info->format, info->type,
return NULL; vol) < 0)
return -1;
/* Size in KB */ /* Size in KB */
info.size_arg = VIR_DIV_UP(vol->target.capacity, 1024); info->size_arg = VIR_DIV_UP(vol->target.capacity, 1024);
return 0;
}
/* Create a qemu-img virCommand from the supplied arguments */
virCommandPtr
virStorageBackendCreateQemuImgCmdFromVol(virStoragePoolObjPtr pool,
virStorageVolDefPtr vol,
virStorageVolDefPtr inputvol,
unsigned int flags,
const char *create_tool,
const char *secretPath)
{
virCommandPtr cmd = NULL;
struct _virStorageBackendQemuImgInfo info = {
.format = vol->target.format,
.type = NULL,
.path = vol->target.path,
.allocation = vol->target.allocation,
.encryption = !!vol->target.encryption,
.preallocate = !!(flags & VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA),
.compat = vol->target.compat,
.features = vol->target.features,
.nocow = vol->target.nocow,
.secretPath = secretPath,
.secretAlias = NULL,
};
virStorageEncryptionInfoDefPtr enc = NULL;
virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA, NULL);
if (virStorageBackendCreateQemuImgSetInfo(pool, vol, inputvol, &info) < 0)
goto error;
cmd = virCommandNew(create_tool); cmd = virCommandNew(create_tool);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册