提交 57d6df39 编写于 作者: J John Ferlan

storage: Add capability to use LUKS encryption for disk backend

https://bugzilla.redhat.com/show_bug.cgi?id=1560946

Similar to the the Logical backend, use qemu-img on the created
disk partition device to set up for LUKS encryption. Secret mgmt
for the device can be complicated by a reboot possibly changing
the path to the device if the infrastructure changes.
Signed-off-by: NJohn Ferlan <jferlan@redhat.com>
ACKed-by: NPeter Krempa <pkrempa@redhat.com>
上级 b8b42ca0
...@@ -879,16 +879,17 @@ virStorageBackendDiskCreateVol(virStoragePoolObjPtr pool, ...@@ -879,16 +879,17 @@ virStorageBackendDiskCreateVol(virStoragePoolObjPtr pool,
char *partFormat = NULL; char *partFormat = NULL;
unsigned long long startOffset = 0, endOffset = 0; unsigned long long startOffset = 0, endOffset = 0;
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
virErrorPtr save_err;
virCommandPtr cmd = virCommandNewArgList(PARTED, virCommandPtr cmd = virCommandNewArgList(PARTED,
def->source.devices[0].path, def->source.devices[0].path,
"mkpart", "mkpart",
"--script", "--script",
NULL); NULL);
if (vol->target.encryption != NULL) { if (vol->target.encryption &&
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, vol->target.encryption->format != VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) {
"%s", _("storage pool does not support encrypted " virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
"volumes")); _("storage pool only supports LUKS encrypted volumes"));
goto cleanup; goto cleanup;
} }
...@@ -896,11 +897,14 @@ virStorageBackendDiskCreateVol(virStoragePoolObjPtr pool, ...@@ -896,11 +897,14 @@ virStorageBackendDiskCreateVol(virStoragePoolObjPtr pool,
goto cleanup; goto cleanup;
virCommandAddArg(cmd, partFormat); virCommandAddArg(cmd, partFormat);
if (virStorageBackendDiskPartBoundaries(pool, &startOffset, /* If we're going to encrypt using LUKS, then we could need up to
&endOffset, * an extra 2MB for the LUKS header - so account for that now */
vol->target.capacity) != 0) { if (vol->target.encryption)
vol->target.capacity += 2 * 1024 * 1024;
if (virStorageBackendDiskPartBoundaries(pool, &startOffset, &endOffset,
vol->target.capacity) < 0)
goto cleanup; goto cleanup;
}
virCommandAddArgFormat(cmd, "%lluB", startOffset); virCommandAddArgFormat(cmd, "%lluB", startOffset);
virCommandAddArgFormat(cmd, "%lluB", endOffset); virCommandAddArgFormat(cmd, "%lluB", endOffset);
...@@ -919,15 +923,15 @@ virStorageBackendDiskCreateVol(virStoragePoolObjPtr pool, ...@@ -919,15 +923,15 @@ virStorageBackendDiskCreateVol(virStoragePoolObjPtr pool,
VIR_FREE(vol->target.path); VIR_FREE(vol->target.path);
/* Fetch actual extent info, generate key */ /* Fetch actual extent info, generate key */
if (virStorageBackendDiskReadPartitions(pool, vol) < 0) { if (virStorageBackendDiskReadPartitions(pool, vol) < 0)
/* Best effort to remove the partition. Ignore any errors goto error;
* since we could be calling this with vol->target.path == NULL
*/ if (vol->target.encryption) {
virErrorPtr save_err = virSaveLastError(); /* Adjust the sizes to account for the LUKS header */
ignore_value(virStorageBackendDiskDeleteVol(pool, vol, 0)); vol->target.capacity -= 2 * 1024 * 1024;
virSetError(save_err); vol->target.allocation -= 2 * 1024 * 1024;
virFreeError(save_err); if (virStorageBackendCreateVolUsingQemuImg(pool, vol, NULL, 0) < 0)
goto cleanup; goto error;
} }
res = 0; res = 0;
...@@ -936,8 +940,19 @@ virStorageBackendDiskCreateVol(virStoragePoolObjPtr pool, ...@@ -936,8 +940,19 @@ virStorageBackendDiskCreateVol(virStoragePoolObjPtr pool,
VIR_FREE(partFormat); VIR_FREE(partFormat);
virCommandFree(cmd); virCommandFree(cmd);
return res; return res;
error:
/* Best effort to remove the partition. Ignore any errors
* since we could be calling this with vol->target.path == NULL
*/
save_err = virSaveLastError();
ignore_value(virStorageBackendDiskDeleteVol(pool, vol, 0));
virSetError(save_err);
virFreeError(save_err);
goto cleanup;
} }
static int static int
virStorageBackendDiskBuildVolFrom(virStoragePoolObjPtr pool, virStorageBackendDiskBuildVolFrom(virStoragePoolObjPtr pool,
virStorageVolDefPtr vol, virStorageVolDefPtr vol,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册