mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-08 12:41:29 +00:00
util: move virQEMUBuildQemuImgKeySecretOpts into storage
Function virQEMUBuildQemuImgKeySecretOpts is not used anywhere else so there is no need to have it in util. Signed-off-by: Pavel Hrdina <phrdina@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
ba9b419910
commit
fd90641d96
@ -2954,7 +2954,6 @@ virQEMUBuildCommandLineJSONArrayNumbered;
|
|||||||
virQEMUBuildDriveCommandlineFromJSON;
|
virQEMUBuildDriveCommandlineFromJSON;
|
||||||
virQEMUBuildNetdevCommandlineFromJSON;
|
virQEMUBuildNetdevCommandlineFromJSON;
|
||||||
virQEMUBuildObjectCommandlineFromJSON;
|
virQEMUBuildObjectCommandlineFromJSON;
|
||||||
virQEMUBuildQemuImgKeySecretOpts;
|
|
||||||
|
|
||||||
|
|
||||||
# util/virrandom.h
|
# util/virrandom.h
|
||||||
|
@ -679,6 +679,74 @@ struct _virStorageBackendQemuImgInfo {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* storageBackendBuildQemuImgEncriptionOpts:
|
||||||
|
* @buf: buffer to build the string into
|
||||||
|
* @encinfo: pointer to encryption info
|
||||||
|
* @alias: alias to use
|
||||||
|
*
|
||||||
|
* Generate the string for id=$alias and any encryption options for
|
||||||
|
* into the buffer.
|
||||||
|
*
|
||||||
|
* Important note, a trailing comma (",") is built into the return since
|
||||||
|
* it's expected other arguments are appended after the id=$alias string.
|
||||||
|
* So either turn something like:
|
||||||
|
*
|
||||||
|
* "key-secret=$alias,"
|
||||||
|
*
|
||||||
|
* or
|
||||||
|
* "key-secret=$alias,cipher-alg=twofish-256,cipher-mode=cbc,
|
||||||
|
* hash-alg=sha256,ivgen-alg=plain64,igven-hash-alg=sha256,"
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
storageBackendBuildQemuImgEncriptionOpts(virBufferPtr buf,
|
||||||
|
int format,
|
||||||
|
virStorageEncryptionInfoDefPtr encinfo,
|
||||||
|
const char *alias)
|
||||||
|
{
|
||||||
|
const char *encprefix;
|
||||||
|
|
||||||
|
if (format == VIR_STORAGE_FILE_QCOW2) {
|
||||||
|
virBufferAddLit(buf, "encrypt.format=luks,");
|
||||||
|
encprefix = "encrypt.";
|
||||||
|
} else {
|
||||||
|
encprefix = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
virBufferAsprintf(buf, "%skey-secret=%s,", encprefix, alias);
|
||||||
|
|
||||||
|
if (!encinfo->cipher_name)
|
||||||
|
return;
|
||||||
|
|
||||||
|
virBufferAsprintf(buf, "%scipher-alg=", encprefix);
|
||||||
|
virQEMUBuildBufferEscapeComma(buf, encinfo->cipher_name);
|
||||||
|
virBufferAsprintf(buf, "-%u,", encinfo->cipher_size);
|
||||||
|
if (encinfo->cipher_mode) {
|
||||||
|
virBufferAsprintf(buf, "%scipher-mode=", encprefix);
|
||||||
|
virQEMUBuildBufferEscapeComma(buf, encinfo->cipher_mode);
|
||||||
|
virBufferAddLit(buf, ",");
|
||||||
|
}
|
||||||
|
if (encinfo->cipher_hash) {
|
||||||
|
virBufferAsprintf(buf, "%shash-alg=", encprefix);
|
||||||
|
virQEMUBuildBufferEscapeComma(buf, encinfo->cipher_hash);
|
||||||
|
virBufferAddLit(buf, ",");
|
||||||
|
}
|
||||||
|
if (!encinfo->ivgen_name)
|
||||||
|
return;
|
||||||
|
|
||||||
|
virBufferAsprintf(buf, "%sivgen-alg=", encprefix);
|
||||||
|
virQEMUBuildBufferEscapeComma(buf, encinfo->ivgen_name);
|
||||||
|
virBufferAddLit(buf, ",");
|
||||||
|
|
||||||
|
if (encinfo->ivgen_hash) {
|
||||||
|
virBufferAsprintf(buf, "%sivgen-hash-alg=", encprefix);
|
||||||
|
virQEMUBuildBufferEscapeComma(buf, encinfo->ivgen_hash);
|
||||||
|
virBufferAddLit(buf, ",");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
storageBackendCreateQemuImgOpts(virStorageEncryptionInfoDefPtr encinfo,
|
storageBackendCreateQemuImgOpts(virStorageEncryptionInfoDefPtr encinfo,
|
||||||
char **opts,
|
char **opts,
|
||||||
@ -690,8 +758,10 @@ storageBackendCreateQemuImgOpts(virStorageEncryptionInfoDefPtr encinfo,
|
|||||||
virBufferAsprintf(&buf, "backing_fmt=%s,",
|
virBufferAsprintf(&buf, "backing_fmt=%s,",
|
||||||
virStorageFileFormatTypeToString(info->backingFormat));
|
virStorageFileFormatTypeToString(info->backingFormat));
|
||||||
|
|
||||||
if (encinfo)
|
if (encinfo) {
|
||||||
virQEMUBuildQemuImgKeySecretOpts(&buf, info->format, encinfo, info->secretAlias);
|
storageBackendBuildQemuImgEncriptionOpts(&buf, info->format, encinfo,
|
||||||
|
info->secretAlias);
|
||||||
|
}
|
||||||
|
|
||||||
if (info->preallocate) {
|
if (info->preallocate) {
|
||||||
if (info->size_arg > info->allocation)
|
if (info->size_arg > info->allocation)
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
#include "virqemu.h"
|
#include "virqemu.h"
|
||||||
#include "virstring.h"
|
#include "virstring.h"
|
||||||
#include "viralloc.h"
|
#include "viralloc.h"
|
||||||
#include "virstoragefile.h"
|
|
||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_NONE
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
||||||
|
|
||||||
@ -384,71 +383,3 @@ virQEMUBuildBufferEscapeComma(virBufferPtr buf, const char *str)
|
|||||||
{
|
{
|
||||||
virBufferEscape(buf, ',', ",", "%s", str);
|
virBufferEscape(buf, ',', ",", "%s", str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* virQEMUBuildQemuImgKeySecretOpts:
|
|
||||||
* @buf: buffer to build the string into
|
|
||||||
* @encinfo: pointer to encryption info
|
|
||||||
* @alias: alias to use
|
|
||||||
*
|
|
||||||
* Generate the string for id=$alias and any encryption options for
|
|
||||||
* into the buffer.
|
|
||||||
*
|
|
||||||
* Important note, a trailing comma (",") is built into the return since
|
|
||||||
* it's expected other arguments are appended after the id=$alias string.
|
|
||||||
* So either turn something like:
|
|
||||||
*
|
|
||||||
* "key-secret=$alias,"
|
|
||||||
*
|
|
||||||
* or
|
|
||||||
* "key-secret=$alias,cipher-alg=twofish-256,cipher-mode=cbc,
|
|
||||||
* hash-alg=sha256,ivgen-alg=plain64,igven-hash-alg=sha256,"
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
virQEMUBuildQemuImgKeySecretOpts(virBufferPtr buf,
|
|
||||||
int format,
|
|
||||||
virStorageEncryptionInfoDefPtr encinfo,
|
|
||||||
const char *alias)
|
|
||||||
{
|
|
||||||
const char *encprefix;
|
|
||||||
|
|
||||||
if (format == VIR_STORAGE_FILE_QCOW2) {
|
|
||||||
virBufferAddLit(buf, "encrypt.format=luks,");
|
|
||||||
encprefix = "encrypt.";
|
|
||||||
} else {
|
|
||||||
encprefix = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
virBufferAsprintf(buf, "%skey-secret=%s,", encprefix, alias);
|
|
||||||
|
|
||||||
if (!encinfo->cipher_name)
|
|
||||||
return;
|
|
||||||
|
|
||||||
virBufferAsprintf(buf, "%scipher-alg=", encprefix);
|
|
||||||
virQEMUBuildBufferEscapeComma(buf, encinfo->cipher_name);
|
|
||||||
virBufferAsprintf(buf, "-%u,", encinfo->cipher_size);
|
|
||||||
if (encinfo->cipher_mode) {
|
|
||||||
virBufferAsprintf(buf, "%scipher-mode=", encprefix);
|
|
||||||
virQEMUBuildBufferEscapeComma(buf, encinfo->cipher_mode);
|
|
||||||
virBufferAddLit(buf, ",");
|
|
||||||
}
|
|
||||||
if (encinfo->cipher_hash) {
|
|
||||||
virBufferAsprintf(buf, "%shash-alg=", encprefix);
|
|
||||||
virQEMUBuildBufferEscapeComma(buf, encinfo->cipher_hash);
|
|
||||||
virBufferAddLit(buf, ",");
|
|
||||||
}
|
|
||||||
if (!encinfo->ivgen_name)
|
|
||||||
return;
|
|
||||||
|
|
||||||
virBufferAsprintf(buf, "%sivgen-alg=", encprefix);
|
|
||||||
virQEMUBuildBufferEscapeComma(buf, encinfo->ivgen_name);
|
|
||||||
virBufferAddLit(buf, ",");
|
|
||||||
|
|
||||||
if (encinfo->ivgen_hash) {
|
|
||||||
virBufferAsprintf(buf, "%sivgen-hash-alg=", encprefix);
|
|
||||||
virQEMUBuildBufferEscapeComma(buf, encinfo->ivgen_hash);
|
|
||||||
virBufferAddLit(buf, ",");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "virbuffer.h"
|
#include "virbuffer.h"
|
||||||
#include "virjson.h"
|
#include "virjson.h"
|
||||||
#include "virstorageencryption.h"
|
|
||||||
|
|
||||||
typedef int (*virQEMUBuildCommandLineJSONArrayFormatFunc)(const char *key,
|
typedef int (*virQEMUBuildCommandLineJSONArrayFormatFunc)(const char *key,
|
||||||
virJSONValuePtr array,
|
virJSONValuePtr array,
|
||||||
@ -59,8 +58,3 @@ int virQEMUBuildObjectCommandlineFromJSON(virBufferPtr buf,
|
|||||||
char *virQEMUBuildDriveCommandlineFromJSON(virJSONValuePtr src);
|
char *virQEMUBuildDriveCommandlineFromJSON(virJSONValuePtr src);
|
||||||
|
|
||||||
void virQEMUBuildBufferEscapeComma(virBufferPtr buf, const char *str);
|
void virQEMUBuildBufferEscapeComma(virBufferPtr buf, const char *str);
|
||||||
void virQEMUBuildQemuImgKeySecretOpts(virBufferPtr buf,
|
|
||||||
int format,
|
|
||||||
virStorageEncryptionInfoDefPtr enc,
|
|
||||||
const char *alias)
|
|
||||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user