[PATCH 01/10] storage: encryption: Add deep copy function for storage encryption

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 src/util/virstorageencryption.c | 40 ++++++++++++++++++++++++++++++++++++++++
 src/util/virstorageencryption.h |  3 +++
 2 files changed, 43 insertions(+)

diff --git a/src/util/virstorageencryption.c b/src/util/virstorageencryption.c
index 1306490..5a401b7 100644
--- a/src/util/virstorageencryption.c
+++ b/src/util/virstorageencryption.c
@@ -67,6 +67,46 @@ virStorageEncryptionFree(virStorageEncryptionPtr 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)
 {
diff --git a/src/util/virstorageencryption.h b/src/util/virstorageencryption.h
index f63c9ee..04641b1 100644
--- a/src/util/virstorageencryption.h
+++ b/src/util/virstorageencryption.h
@@ -61,6 +61,9 @@ struct _virStorageEncryption {
     virStorageEncryptionSecretPtr *secrets;
 };

+virStorageEncryptionPtr virStorageEncryptionCopy(const virStorageEncryption *src)
+    ATTRIBUTE_NONNULL(1);
+
 void virStorageEncryptionFree(virStorageEncryptionPtr enc);

 virStorageEncryptionPtr virStorageEncryptionParseNode(xmlDocPtr xml,
-- 
1.9.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]