storage: encryption: Add deep copy function for storage encryption

This commit is contained in:
Peter Krempa 2014-06-12 15:26:18 +02:00
parent 2624dfde37
commit 756b46ddd2
2 changed files with 43 additions and 0 deletions

View File

@ -66,6 +66,46 @@ virStorageEncryptionFree(virStorageEncryptionPtr enc)
VIR_FREE(enc);
}
static virStorageEncryptionSecretPtr
virStorageEncryptionSecretCopy(const virStorageEncryptionSecret *src)
{
virStorageEncryptionSecretPtr ret;
if (VIR_ALLOC(ret) < 0)
return NULL;
memcpy(ret, src, sizeof(*src));
return ret;
}
virStorageEncryptionPtr
virStorageEncryptionCopy(const virStorageEncryption *src)
{
virStorageEncryptionPtr ret;
size_t i;
if (VIR_ALLOC(ret) < 0)
return NULL;
if (VIR_ALLOC_N(ret->secrets, src->nsecrets) < 0)
goto error;
ret->nsecrets = src->nsecrets;
ret->format = src->format;
for (i = 0; i < src->nsecrets; i++) {
if (!(ret->secrets[i] = virStorageEncryptionSecretCopy(src->secrets[i])))
goto error;
}
return ret;
error:
virStorageEncryptionFree(ret);
return NULL;
}
static virStorageEncryptionSecretPtr
virStorageEncryptionSecretParse(xmlXPathContextPtr ctxt,
xmlNodePtr node)

View File

@ -61,6 +61,9 @@ struct _virStorageEncryption {
virStorageEncryptionSecretPtr *secrets;
};
virStorageEncryptionPtr virStorageEncryptionCopy(const virStorageEncryption *src)
ATTRIBUTE_NONNULL(1);
void virStorageEncryptionFree(virStorageEncryptionPtr enc);
virStorageEncryptionPtr virStorageEncryptionParseNode(xmlDocPtr xml,