mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 14:15:28 +00:00
storage: Split out setting default secret for encryption
Split the qcow setting of encryption secrets into a helper Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
1933b87855
commit
a2a7f7ede8
@ -1280,33 +1280,33 @@ virStorageBackendFileSystemVolDelete(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update info about a volume's capacity/allocation
|
||||
/* virStorageBackendFileSystemLoadDefaultSecrets:
|
||||
* @conn: Connection pointer to fetch secret
|
||||
* @vol: volume being refreshed
|
||||
*
|
||||
* If the volume had a QCOW secret generated, we need to regenerate the
|
||||
* secret
|
||||
*
|
||||
* Returns 0 if no secret or secret setup was successful,
|
||||
* -1 on failures w/ error message set
|
||||
*/
|
||||
static int
|
||||
virStorageBackendFileSystemVolRefresh(virConnectPtr conn,
|
||||
virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
|
||||
virStorageBackendFileSystemLoadDefaultSecrets(virConnectPtr conn,
|
||||
virStorageVolDefPtr vol)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Refresh allocation / capacity / permissions info in case its changed */
|
||||
ret = virStorageBackendUpdateVolInfo(vol, false,
|
||||
VIR_STORAGE_VOL_FS_OPEN_FLAGS, 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
/* Load any secrets if possible */
|
||||
if (vol->target.encryption &&
|
||||
vol->target.encryption->format == VIR_STORAGE_ENCRYPTION_FORMAT_QCOW &&
|
||||
vol->target.encryption->nsecrets == 0) {
|
||||
virSecretPtr sec;
|
||||
virStorageEncryptionSecretPtr encsec = NULL;
|
||||
|
||||
sec = virSecretLookupByUsage(conn,
|
||||
VIR_SECRET_USAGE_TYPE_VOLUME,
|
||||
vol->target.path);
|
||||
if (sec) {
|
||||
/* Only necessary for qcow format */
|
||||
if (!vol->target.encryption ||
|
||||
vol->target.encryption->format != VIR_STORAGE_ENCRYPTION_FORMAT_QCOW ||
|
||||
vol->target.encryption->nsecrets != 0)
|
||||
return 0;
|
||||
|
||||
if (!(sec = virSecretLookupByUsage(conn, VIR_SECRET_USAGE_TYPE_VOLUME,
|
||||
vol->target.path)))
|
||||
return 0;
|
||||
|
||||
if (VIR_ALLOC_N(vol->target.encryption->secrets, 1) < 0 ||
|
||||
VIR_ALLOC(encsec) < 0) {
|
||||
VIR_FREE(vol->target.encryption->secrets);
|
||||
@ -1320,12 +1320,31 @@ virStorageBackendFileSystemVolRefresh(virConnectPtr conn,
|
||||
encsec->type = VIR_STORAGE_ENCRYPTION_SECRET_TYPE_PASSPHRASE;
|
||||
virSecretGetUUID(sec, encsec->uuid);
|
||||
virObjectUnref(sec);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update info about a volume's capacity/allocation
|
||||
*/
|
||||
static int
|
||||
virStorageBackendFileSystemVolRefresh(virConnectPtr conn,
|
||||
virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
|
||||
virStorageVolDefPtr vol)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Refresh allocation / capacity / permissions info in case its changed */
|
||||
if ((ret = virStorageBackendUpdateVolInfo(vol, false,
|
||||
VIR_STORAGE_VOL_FS_OPEN_FLAGS,
|
||||
0)) < 0)
|
||||
return ret;
|
||||
|
||||
/* Load any secrets if possible */
|
||||
return virStorageBackendFileSystemLoadDefaultSecrets(conn, vol);
|
||||
}
|
||||
|
||||
static int
|
||||
virStorageBackendFilesystemResizeQemuImg(const char *path,
|
||||
unsigned long long capacity)
|
||||
|
Loading…
Reference in New Issue
Block a user