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:
John Ferlan 2016-05-25 09:35:09 -04:00
parent 1933b87855
commit a2a7f7ede8

View File

@ -1280,6 +1280,51 @@ virStorageBackendFileSystemVolDelete(virConnectPtr conn ATTRIBUTE_UNUSED,
} }
/* 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
virStorageBackendFileSystemLoadDefaultSecrets(virConnectPtr conn,
virStorageVolDefPtr vol)
{
virSecretPtr sec;
virStorageEncryptionSecretPtr encsec = NULL;
/* 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);
virObjectUnref(sec);
return -1;
}
vol->target.encryption->nsecrets = 1;
vol->target.encryption->secrets[0] = encsec;
encsec->type = VIR_STORAGE_ENCRYPTION_SECRET_TYPE_PASSPHRASE;
virSecretGetUUID(sec, encsec->uuid);
virObjectUnref(sec);
return 0;
}
/** /**
* Update info about a volume's capacity/allocation * Update info about a volume's capacity/allocation
*/ */
@ -1291,39 +1336,13 @@ virStorageBackendFileSystemVolRefresh(virConnectPtr conn,
int ret; int ret;
/* Refresh allocation / capacity / permissions info in case its changed */ /* Refresh allocation / capacity / permissions info in case its changed */
ret = virStorageBackendUpdateVolInfo(vol, false, if ((ret = virStorageBackendUpdateVolInfo(vol, false,
VIR_STORAGE_VOL_FS_OPEN_FLAGS, 0); VIR_STORAGE_VOL_FS_OPEN_FLAGS,
if (ret < 0) 0)) < 0)
return ret; return ret;
/* Load any secrets if possible */ /* Load any secrets if possible */
if (vol->target.encryption && return virStorageBackendFileSystemLoadDefaultSecrets(conn, vol);
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) {
if (VIR_ALLOC_N(vol->target.encryption->secrets, 1) < 0 ||
VIR_ALLOC(encsec) < 0) {
VIR_FREE(vol->target.encryption->secrets);
virObjectUnref(sec);
return -1;
}
vol->target.encryption->nsecrets = 1;
vol->target.encryption->secrets[0] = encsec;
encsec->type = VIR_STORAGE_ENCRYPTION_SECRET_TYPE_PASSPHRASE;
virSecretGetUUID(sec, encsec->uuid);
virObjectUnref(sec);
}
}
return 0;
} }
static int static int