提交 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,
}
/* 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)
static int
virStorageBackendCreateQemuImgSetInfo(virStoragePoolObjPtr pool,
virStorageVolDefPtr vol,
virStorageVolDefPtr inputvol,
struct _virStorageBackendQemuImgInfo *info)
{
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 */
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)
info.format = VIR_STORAGE_FILE_RAW;
if (info->format == VIR_STORAGE_FILE_ISO)
info->format = VIR_STORAGE_FILE_RAW;
if (!(info.type = virStorageFileFormatTypeToString(info.format))) {
if (!(info->type = virStorageFileFormatTypeToString(info->format))) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unknown storage vol type %d"),
info.format);
return NULL;
info->format);
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",
_("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",
_("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",
_("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) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("cannot use inputvol with encrypted raw volume"));
return NULL;
return -1;
}
if (vol->target.encryption->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) {
info.type = "luks";
info->type = "luks";
} else {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Only luks encryption is supported for raw files"));
return NULL;
return -1;
}
}
if (inputvol &&
storageBackendCreateQemuImgSetInput(inputvol, &info) < 0)
return NULL;
storageBackendCreateQemuImgSetInput(inputvol, info) < 0)
return -1;
if (virStorageSourceHasBacking(&vol->target) &&
storageBackendCreateQemuImgSetBacking(pool, vol, inputvol, &info) < 0)
return NULL;
storageBackendCreateQemuImgSetBacking(pool, vol, inputvol, info) < 0)
return -1;
if (info.encryption &&
storageBackendCreateQemuImgCheckEncryption(info.format, info.type, vol) < 0)
return NULL;
if (info->encryption &&
storageBackendCreateQemuImgCheckEncryption(info->format, info->type,
vol) < 0)
return -1;
/* 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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册