]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: move virStorageEncryption code into conf
authorPavel Hrdina <phrdina@redhat.com>
Tue, 8 Dec 2020 15:54:30 +0000 (16:54 +0100)
committerPavel Hrdina <phrdina@redhat.com>
Fri, 22 Jan 2021 10:10:27 +0000 (11:10 +0100)
The code handles XML bits and internal definition and should be
in conf directory.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
po/POTFILES.in
src/conf/domain_conf.h
src/conf/meson.build
src/conf/storage_conf.h
src/conf/storage_encryption_conf.c [new file with mode: 0644]
src/conf/storage_encryption_conf.h [new file with mode: 0644]
src/conf/storage_source_conf.h
src/libvirt_private.syms
src/util/meson.build
src/util/virstorageencryption.c [deleted file]
src/util/virstorageencryption.h [deleted file]

index 2a3c848d058138a2daa4ec68c2bb3a0b0d13448a..a2c46dd2390b1a9654ae68b38fdafa644caad7d1 100644 (file)
@@ -43,6 +43,7 @@
 @SRCDIR@src/conf/snapshot_conf.c
 @SRCDIR@src/conf/storage_adapter_conf.c
 @SRCDIR@src/conf/storage_conf.c
+@SRCDIR@src/conf/storage_encryption_conf.c
 @SRCDIR@src/conf/storage_source_conf.c
 @SRCDIR@src/conf/virchrdev.c
 @SRCDIR@src/conf/virdomainmomentobjlist.c
 @SRCDIR@src/util/virscsivhost.c
 @SRCDIR@src/util/virsecret.c
 @SRCDIR@src/util/virsocketaddr.c
-@SRCDIR@src/util/virstorageencryption.c
 @SRCDIR@src/util/virstoragefile.c
 @SRCDIR@src/util/virstring.c
 @SRCDIR@src/util/virsysinfo.c
index f5d346ddf00fb6a4f9dd802eca51743a0f8c9f52..95ad052891bc9bca1f0d3d1abaf4cf0250c36725 100644 (file)
@@ -29,7 +29,7 @@
 #include "internal.h"
 #include "virconftypes.h"
 #include "capabilities.h"
-#include "virstorageencryption.h"
+#include "storage_encryption_conf.h"
 #include "cpu_conf.h"
 #include "virthread.h"
 #include "virhash.h"
index 9d4831b81598cd7e65a97aa4cb784d5078000728..bd35d87e0a70a03bfd60945c27c2ac9e39c6b0e2 100644 (file)
@@ -54,6 +54,7 @@ storage_conf_sources = [
   'storage_adapter_conf.c',
   'storage_capabilities.c',
   'storage_conf.c',
+  'storage_encryption_conf.c',
   'storage_source_conf.c',
   'virstorageobj.c',
 ]
index aeda2891d403fcfe277227cf3274647555fd2a00..647eb847bf9cd778dc111a44e5e457938708f0c6 100644 (file)
@@ -22,7 +22,7 @@
 #pragma once
 
 #include "internal.h"
-#include "virstorageencryption.h"
+#include "storage_encryption_conf.h"
 #include "storage_source_conf.h"
 #include "virbitmap.h"
 #include "virthread.h"
diff --git a/src/conf/storage_encryption_conf.c b/src/conf/storage_encryption_conf.c
new file mode 100644 (file)
index 0000000..34ad5df
--- /dev/null
@@ -0,0 +1,366 @@
+/*
+ * storage_encryption_conf.c: volume encryption information
+ *
+ * Copyright (C) 2009-2014 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "internal.h"
+
+#include "virbuffer.h"
+#include "viralloc.h"
+#include "storage_encryption_conf.h"
+#include "virxml.h"
+#include "virerror.h"
+#include "viruuid.h"
+#include "virfile.h"
+#include "virsecret.h"
+#include "virstring.h"
+
+#define VIR_FROM_THIS VIR_FROM_STORAGE
+
+VIR_ENUM_IMPL(virStorageEncryptionSecret,
+              VIR_STORAGE_ENCRYPTION_SECRET_TYPE_LAST,
+              "passphrase",
+);
+
+VIR_ENUM_IMPL(virStorageEncryptionFormat,
+              VIR_STORAGE_ENCRYPTION_FORMAT_LAST,
+              "default", "qcow", "luks",
+);
+
+static void
+virStorageEncryptionInfoDefFree(virStorageEncryptionInfoDefPtr def)
+{
+    VIR_FREE(def->cipher_name);
+    VIR_FREE(def->cipher_mode);
+    VIR_FREE(def->cipher_hash);
+    VIR_FREE(def->ivgen_name);
+    VIR_FREE(def->ivgen_hash);
+}
+
+
+static void
+virStorageEncryptionSecretFree(virStorageEncryptionSecretPtr secret)
+{
+    if (!secret)
+        return;
+    virSecretLookupDefClear(&secret->seclookupdef);
+    VIR_FREE(secret);
+}
+
+void
+virStorageEncryptionFree(virStorageEncryptionPtr enc)
+{
+    size_t i;
+
+    if (!enc)
+        return;
+
+    for (i = 0; i < enc->nsecrets; i++)
+        virStorageEncryptionSecretFree(enc->secrets[i]);
+    virStorageEncryptionInfoDefFree(&enc->encinfo);
+    VIR_FREE(enc->secrets);
+    VIR_FREE(enc);
+}
+
+static virStorageEncryptionSecretPtr
+virStorageEncryptionSecretCopy(const virStorageEncryptionSecret *src)
+{
+    virStorageEncryptionSecretPtr ret = g_new0(virStorageEncryptionSecret, 1);
+
+    ret->type = src->type;
+    virSecretLookupDefCopy(&ret->seclookupdef, &src->seclookupdef);
+
+    return ret;
+}
+
+
+static int
+virStorageEncryptionInfoDefCopy(const virStorageEncryptionInfoDef *src,
+                                virStorageEncryptionInfoDefPtr dst)
+{
+    dst->cipher_size = src->cipher_size;
+    dst->cipher_name = g_strdup(src->cipher_name);
+    dst->cipher_mode = g_strdup(src->cipher_mode);
+    dst->cipher_hash = g_strdup(src->cipher_hash);
+    dst->ivgen_name = g_strdup(src->ivgen_name);
+    dst->ivgen_hash = g_strdup(src->ivgen_hash);
+
+    return 0;
+}
+
+
+virStorageEncryptionPtr
+virStorageEncryptionCopy(const virStorageEncryption *src)
+{
+    virStorageEncryptionPtr ret;
+    size_t i;
+
+    ret = g_new0(virStorageEncryption, 1);
+
+    ret->secrets = g_new0(virStorageEncryptionSecretPtr, src->nsecrets);
+    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;
+    }
+
+    if (virStorageEncryptionInfoDefCopy(&src->encinfo, &ret->encinfo) < 0)
+        goto error;
+
+    return ret;
+
+ error:
+    virStorageEncryptionFree(ret);
+    return NULL;
+}
+
+static virStorageEncryptionSecretPtr
+virStorageEncryptionSecretParse(xmlXPathContextPtr ctxt,
+                                xmlNodePtr node)
+{
+    VIR_XPATH_NODE_AUTORESTORE(ctxt)
+    virStorageEncryptionSecretPtr ret;
+    g_autofree char *type_str = NULL;
+
+    ret = g_new0(virStorageEncryptionSecret, 1);
+
+    ctxt->node = node;
+
+    if (!(type_str = virXPathString("string(./@type)", ctxt))) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("unknown volume encryption secret type"));
+        goto cleanup;
+    }
+
+    if ((ret->type = virStorageEncryptionSecretTypeFromString(type_str)) < 0) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("unknown volume encryption secret type %s"),
+                       type_str);
+        goto cleanup;
+    }
+
+    if (virSecretLookupParseSecret(node, &ret->seclookupdef) < 0)
+        goto cleanup;
+
+    return ret;
+
+ cleanup:
+    virStorageEncryptionSecretFree(ret);
+    return NULL;
+}
+
+
+static int
+virStorageEncryptionInfoParseCipher(xmlNodePtr info_node,
+                                    virStorageEncryptionInfoDefPtr info)
+{
+    g_autofree char *size_str = NULL;
+
+    if (!(info->cipher_name = virXMLPropString(info_node, "name"))) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("cipher info missing 'name' attribute"));
+        return -1;
+    }
+
+    if ((size_str = virXMLPropString(info_node, "size")) &&
+        virStrToLong_uip(size_str, NULL, 10, &info->cipher_size) < 0) {
+        virReportError(VIR_ERR_XML_ERROR,
+                       _("cannot parse cipher size: '%s'"),
+                       size_str);
+        return -1;
+    }
+
+    if (!size_str) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("cipher info missing 'size' attribute"));
+        return -1;
+    }
+
+    info->cipher_mode = virXMLPropString(info_node, "mode");
+    info->cipher_hash = virXMLPropString(info_node, "hash");
+
+    return 0;
+}
+
+
+static int
+virStorageEncryptionInfoParseIvgen(xmlNodePtr info_node,
+                                   virStorageEncryptionInfoDefPtr info)
+{
+    if (!(info->ivgen_name = virXMLPropString(info_node, "name"))) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("missing ivgen info name string"));
+        return -1;
+    }
+
+    info->ivgen_hash = virXMLPropString(info_node, "hash");
+
+    return 0;
+}
+
+
+virStorageEncryptionPtr
+virStorageEncryptionParseNode(xmlNodePtr node,
+                              xmlXPathContextPtr ctxt)
+{
+    VIR_XPATH_NODE_AUTORESTORE(ctxt)
+    xmlNodePtr *nodes = NULL;
+    virStorageEncryptionPtr encdef = NULL;
+    virStorageEncryptionPtr ret = NULL;
+    g_autofree char *format_str = NULL;
+    int n;
+    size_t i;
+
+    ctxt->node = node;
+
+    encdef = g_new0(virStorageEncryption, 1);
+
+    if (!(format_str = virXPathString("string(./@format)", ctxt))) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("unknown volume encryption format"));
+        goto cleanup;
+    }
+
+    if ((encdef->format =
+         virStorageEncryptionFormatTypeFromString(format_str)) < 0) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("unknown volume encryption format type %s"),
+                       format_str);
+        goto cleanup;
+    }
+
+    if ((n = virXPathNodeSet("./secret", ctxt, &nodes)) < 0)
+        goto cleanup;
+
+    if (n > 0) {
+        encdef->secrets = g_new0(virStorageEncryptionSecretPtr, n);
+        encdef->nsecrets = n;
+
+        for (i = 0; i < n; i++) {
+            if (!(encdef->secrets[i] =
+                  virStorageEncryptionSecretParse(ctxt, nodes[i])))
+                goto cleanup;
+        }
+    }
+
+    if (encdef->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) {
+        xmlNodePtr tmpnode;
+
+        if ((tmpnode = virXPathNode("./cipher[1]", ctxt))) {
+            if (virStorageEncryptionInfoParseCipher(tmpnode, &encdef->encinfo) < 0)
+                goto cleanup;
+        }
+
+        if ((tmpnode = virXPathNode("./ivgen[1]", ctxt))) {
+            /* If no cipher node, then fail */
+            if (!encdef->encinfo.cipher_name) {
+                virReportError(VIR_ERR_XML_ERROR, "%s",
+                               _("ivgen element found, but cipher is missing"));
+                goto cleanup;
+            }
+
+            if (virStorageEncryptionInfoParseIvgen(tmpnode, &encdef->encinfo) < 0)
+                goto cleanup;
+        }
+    }
+
+    ret = g_steal_pointer(&encdef);
+
+ cleanup:
+    VIR_FREE(nodes);
+    virStorageEncryptionFree(encdef);
+
+    return ret;
+}
+
+
+static int
+virStorageEncryptionSecretFormat(virBufferPtr buf,
+                                 virStorageEncryptionSecretPtr secret)
+{
+    const char *type;
+
+    if (!(type = virStorageEncryptionSecretTypeToString(secret->type))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("unexpected volume encryption secret type"));
+        return -1;
+    }
+
+    virSecretLookupFormatSecret(buf, type, &secret->seclookupdef);
+
+    return 0;
+}
+
+
+static void
+virStorageEncryptionInfoDefFormat(virBufferPtr buf,
+                                  const virStorageEncryptionInfoDef *enc)
+{
+    virBufferEscapeString(buf, "<cipher name='%s'", enc->cipher_name);
+    virBufferAsprintf(buf, " size='%u'", enc->cipher_size);
+    if (enc->cipher_mode)
+        virBufferEscapeString(buf, " mode='%s'", enc->cipher_mode);
+    if (enc->cipher_hash)
+        virBufferEscapeString(buf, " hash='%s'", enc->cipher_hash);
+    virBufferAddLit(buf, "/>\n");
+
+    if (enc->ivgen_name) {
+        virBufferEscapeString(buf, "<ivgen name='%s'", enc->ivgen_name);
+        if (enc->ivgen_hash)
+            virBufferEscapeString(buf, " hash='%s'", enc->ivgen_hash);
+        virBufferAddLit(buf, "/>\n");
+    }
+}
+
+
+int
+virStorageEncryptionFormat(virBufferPtr buf,
+                           virStorageEncryptionPtr enc)
+{
+    const char *format;
+    size_t i;
+
+    if (!(format = virStorageEncryptionFormatTypeToString(enc->format))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "%s", _("unexpected encryption format"));
+        return -1;
+    }
+    virBufferAsprintf(buf, "<encryption format='%s'>\n", format);
+    virBufferAdjustIndent(buf, 2);
+
+    for (i = 0; i < enc->nsecrets; i++) {
+        if (virStorageEncryptionSecretFormat(buf, enc->secrets[i]) < 0)
+            return -1;
+    }
+
+    if (enc->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS &&
+        enc->encinfo.cipher_name)
+        virStorageEncryptionInfoDefFormat(buf, &enc->encinfo);
+
+    virBufferAdjustIndent(buf, -2);
+    virBufferAddLit(buf, "</encryption>\n");
+
+    return 0;
+}
diff --git a/src/conf/storage_encryption_conf.h b/src/conf/storage_encryption_conf.h
new file mode 100644 (file)
index 0000000..0799421
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * storage_encryption_conf.h: volume encryption information
+ *
+ * Copyright (C) 2009-2011, 2014 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "internal.h"
+#include "virbuffer.h"
+#include "virsecret.h"
+#include "virenum.h"
+
+#include <libxml/tree.h>
+
+typedef enum {
+    VIR_STORAGE_ENCRYPTION_SECRET_TYPE_PASSPHRASE = 0,
+
+    VIR_STORAGE_ENCRYPTION_SECRET_TYPE_LAST
+} virStorageEncryptionSecretType;
+VIR_ENUM_DECL(virStorageEncryptionSecret);
+
+typedef struct _virStorageEncryptionSecret virStorageEncryptionSecret;
+typedef virStorageEncryptionSecret *virStorageEncryptionSecretPtr;
+struct _virStorageEncryptionSecret {
+    int type; /* virStorageEncryptionSecretType */
+    virSecretLookupTypeDef seclookupdef;
+};
+
+/* It's possible to dictate the cipher and if necessary iv */
+typedef struct _virStorageEncryptionInfoDef virStorageEncryptionInfoDef;
+typedef virStorageEncryptionInfoDef *virStorageEncryptionInfoDefPtr;
+struct _virStorageEncryptionInfoDef {
+    unsigned int cipher_size;
+    char *cipher_name;
+    char *cipher_mode;
+    char *cipher_hash;
+    char *ivgen_name;
+    char *ivgen_hash;
+};
+
+typedef enum {
+    /* "default" is only valid for volume creation */
+    VIR_STORAGE_ENCRYPTION_FORMAT_DEFAULT = 0,
+    VIR_STORAGE_ENCRYPTION_FORMAT_QCOW, /* Both qcow and qcow2 */
+    VIR_STORAGE_ENCRYPTION_FORMAT_LUKS,
+
+    VIR_STORAGE_ENCRYPTION_FORMAT_LAST,
+} virStorageEncryptionFormatType;
+VIR_ENUM_DECL(virStorageEncryptionFormat);
+
+typedef struct _virStorageEncryption virStorageEncryption;
+typedef virStorageEncryption *virStorageEncryptionPtr;
+struct _virStorageEncryption {
+    int format; /* virStorageEncryptionFormatType */
+    int payload_offset;
+
+    size_t nsecrets;
+    virStorageEncryptionSecretPtr *secrets;
+
+    virStorageEncryptionInfoDef encinfo;
+};
+
+virStorageEncryptionPtr virStorageEncryptionCopy(const virStorageEncryption *src)
+    ATTRIBUTE_NONNULL(1);
+
+void virStorageEncryptionFree(virStorageEncryptionPtr enc);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStorageEncryption, virStorageEncryptionFree);
+
+virStorageEncryptionPtr virStorageEncryptionParseNode(xmlNodePtr node,
+                                                      xmlXPathContextPtr ctxt);
+int virStorageEncryptionFormat(virBufferPtr buf,
+                               virStorageEncryptionPtr enc);
+
+/* A helper for VIR_STORAGE_ENCRYPTION_FORMAT_QCOW */
+enum {
+  VIR_STORAGE_QCOW_PASSPHRASE_SIZE = 16
+};
index 6f39ab4bd020e69e566a1fb0cda70edd6e10c3e2..e66ccdedefafd2242452e6a86b2bb47802834c41 100644 (file)
 
 #pragma once
 
+#include "storage_encryption_conf.h"
 #include "virbitmap.h"
 #include "virenum.h"
 #include "virobject.h"
 #include "virpci.h"
 #include "virseclabel.h"
 #include "virsecret.h"
-#include "virstorageencryption.h"
 
 /* Types of disk backends (host resource).  Comparable to the public
  * virStorageVolType, except we have an undetermined state, don't have
index b13d0db2091acb0b9cbc2a160d0f69793dc97e96..e8fe8e6c1219167bfee8f8e5cd7071885cd595b5 100644 (file)
@@ -1047,6 +1047,12 @@ virStorageVolTypeFromString;
 virStorageVolTypeToString;
 
 
+# conf/storage_encryption_conf.h
+virStorageEncryptionFormat;
+virStorageEncryptionFree;
+virStorageEncryptionParseNode;
+
+
 # conf/storage_event.h
 virStoragePoolEventLifecycleNew;
 virStoragePoolEventRefreshNew;
@@ -3206,12 +3212,6 @@ virSocketAddrSetIPv6AddrNetOrder;
 virSocketAddrSetPort;
 
 
-# util/virstorageencryption.h
-virStorageEncryptionFormat;
-virStorageEncryptionFree;
-virStorageEncryptionParseNode;
-
-
 # util/virstoragefile.h
 virStorageFileCanonicalizePath;
 virStorageFileGetNPIVKey;
index b510f0ebe9bb8c4bec5d54213089862fe4cc54b6..c077c5cc99f7bb61eb1cbdf3c97e5b01380f28b1 100644 (file)
@@ -88,7 +88,6 @@ util_sources = [
   'virsecret.c',
   'virsocket.c',
   'virsocketaddr.c',
-  'virstorageencryption.c',
   'virstoragefile.c',
   'virstring.c',
   'virsysinfo.c',
diff --git a/src/util/virstorageencryption.c b/src/util/virstorageencryption.c
deleted file mode 100644 (file)
index c893f0b..0000000
+++ /dev/null
@@ -1,366 +0,0 @@
-/*
- * virstorageencryption.c: volume encryption information
- *
- * Copyright (C) 2009-2014 Red Hat, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library.  If not, see
- * <http://www.gnu.org/licenses/>.
- */
-
-#include <config.h>
-
-#include <fcntl.h>
-#include <unistd.h>
-
-#include "internal.h"
-
-#include "virbuffer.h"
-#include "viralloc.h"
-#include "virstorageencryption.h"
-#include "virxml.h"
-#include "virerror.h"
-#include "viruuid.h"
-#include "virfile.h"
-#include "virsecret.h"
-#include "virstring.h"
-
-#define VIR_FROM_THIS VIR_FROM_STORAGE
-
-VIR_ENUM_IMPL(virStorageEncryptionSecret,
-              VIR_STORAGE_ENCRYPTION_SECRET_TYPE_LAST,
-              "passphrase",
-);
-
-VIR_ENUM_IMPL(virStorageEncryptionFormat,
-              VIR_STORAGE_ENCRYPTION_FORMAT_LAST,
-              "default", "qcow", "luks",
-);
-
-static void
-virStorageEncryptionInfoDefFree(virStorageEncryptionInfoDefPtr def)
-{
-    VIR_FREE(def->cipher_name);
-    VIR_FREE(def->cipher_mode);
-    VIR_FREE(def->cipher_hash);
-    VIR_FREE(def->ivgen_name);
-    VIR_FREE(def->ivgen_hash);
-}
-
-
-static void
-virStorageEncryptionSecretFree(virStorageEncryptionSecretPtr secret)
-{
-    if (!secret)
-        return;
-    virSecretLookupDefClear(&secret->seclookupdef);
-    VIR_FREE(secret);
-}
-
-void
-virStorageEncryptionFree(virStorageEncryptionPtr enc)
-{
-    size_t i;
-
-    if (!enc)
-        return;
-
-    for (i = 0; i < enc->nsecrets; i++)
-        virStorageEncryptionSecretFree(enc->secrets[i]);
-    virStorageEncryptionInfoDefFree(&enc->encinfo);
-    VIR_FREE(enc->secrets);
-    VIR_FREE(enc);
-}
-
-static virStorageEncryptionSecretPtr
-virStorageEncryptionSecretCopy(const virStorageEncryptionSecret *src)
-{
-    virStorageEncryptionSecretPtr ret = g_new0(virStorageEncryptionSecret, 1);
-
-    ret->type = src->type;
-    virSecretLookupDefCopy(&ret->seclookupdef, &src->seclookupdef);
-
-    return ret;
-}
-
-
-static int
-virStorageEncryptionInfoDefCopy(const virStorageEncryptionInfoDef *src,
-                                virStorageEncryptionInfoDefPtr dst)
-{
-    dst->cipher_size = src->cipher_size;
-    dst->cipher_name = g_strdup(src->cipher_name);
-    dst->cipher_mode = g_strdup(src->cipher_mode);
-    dst->cipher_hash = g_strdup(src->cipher_hash);
-    dst->ivgen_name = g_strdup(src->ivgen_name);
-    dst->ivgen_hash = g_strdup(src->ivgen_hash);
-
-    return 0;
-}
-
-
-virStorageEncryptionPtr
-virStorageEncryptionCopy(const virStorageEncryption *src)
-{
-    virStorageEncryptionPtr ret;
-    size_t i;
-
-    ret = g_new0(virStorageEncryption, 1);
-
-    ret->secrets = g_new0(virStorageEncryptionSecretPtr, src->nsecrets);
-    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;
-    }
-
-    if (virStorageEncryptionInfoDefCopy(&src->encinfo, &ret->encinfo) < 0)
-        goto error;
-
-    return ret;
-
- error:
-    virStorageEncryptionFree(ret);
-    return NULL;
-}
-
-static virStorageEncryptionSecretPtr
-virStorageEncryptionSecretParse(xmlXPathContextPtr ctxt,
-                                xmlNodePtr node)
-{
-    VIR_XPATH_NODE_AUTORESTORE(ctxt)
-    virStorageEncryptionSecretPtr ret;
-    g_autofree char *type_str = NULL;
-
-    ret = g_new0(virStorageEncryptionSecret, 1);
-
-    ctxt->node = node;
-
-    if (!(type_str = virXPathString("string(./@type)", ctxt))) {
-        virReportError(VIR_ERR_XML_ERROR, "%s",
-                       _("unknown volume encryption secret type"));
-        goto cleanup;
-    }
-
-    if ((ret->type = virStorageEncryptionSecretTypeFromString(type_str)) < 0) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("unknown volume encryption secret type %s"),
-                       type_str);
-        goto cleanup;
-    }
-
-    if (virSecretLookupParseSecret(node, &ret->seclookupdef) < 0)
-        goto cleanup;
-
-    return ret;
-
- cleanup:
-    virStorageEncryptionSecretFree(ret);
-    return NULL;
-}
-
-
-static int
-virStorageEncryptionInfoParseCipher(xmlNodePtr info_node,
-                                    virStorageEncryptionInfoDefPtr info)
-{
-    g_autofree char *size_str = NULL;
-
-    if (!(info->cipher_name = virXMLPropString(info_node, "name"))) {
-        virReportError(VIR_ERR_XML_ERROR, "%s",
-                       _("cipher info missing 'name' attribute"));
-        return -1;
-    }
-
-    if ((size_str = virXMLPropString(info_node, "size")) &&
-        virStrToLong_uip(size_str, NULL, 10, &info->cipher_size) < 0) {
-        virReportError(VIR_ERR_XML_ERROR,
-                       _("cannot parse cipher size: '%s'"),
-                       size_str);
-        return -1;
-    }
-
-    if (!size_str) {
-        virReportError(VIR_ERR_XML_ERROR, "%s",
-                       _("cipher info missing 'size' attribute"));
-        return -1;
-    }
-
-    info->cipher_mode = virXMLPropString(info_node, "mode");
-    info->cipher_hash = virXMLPropString(info_node, "hash");
-
-    return 0;
-}
-
-
-static int
-virStorageEncryptionInfoParseIvgen(xmlNodePtr info_node,
-                                   virStorageEncryptionInfoDefPtr info)
-{
-    if (!(info->ivgen_name = virXMLPropString(info_node, "name"))) {
-        virReportError(VIR_ERR_XML_ERROR, "%s",
-                       _("missing ivgen info name string"));
-        return -1;
-    }
-
-    info->ivgen_hash = virXMLPropString(info_node, "hash");
-
-    return 0;
-}
-
-
-virStorageEncryptionPtr
-virStorageEncryptionParseNode(xmlNodePtr node,
-                              xmlXPathContextPtr ctxt)
-{
-    VIR_XPATH_NODE_AUTORESTORE(ctxt)
-    xmlNodePtr *nodes = NULL;
-    virStorageEncryptionPtr encdef = NULL;
-    virStorageEncryptionPtr ret = NULL;
-    g_autofree char *format_str = NULL;
-    int n;
-    size_t i;
-
-    ctxt->node = node;
-
-    encdef = g_new0(virStorageEncryption, 1);
-
-    if (!(format_str = virXPathString("string(./@format)", ctxt))) {
-        virReportError(VIR_ERR_XML_ERROR, "%s",
-                       _("unknown volume encryption format"));
-        goto cleanup;
-    }
-
-    if ((encdef->format =
-         virStorageEncryptionFormatTypeFromString(format_str)) < 0) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("unknown volume encryption format type %s"),
-                       format_str);
-        goto cleanup;
-    }
-
-    if ((n = virXPathNodeSet("./secret", ctxt, &nodes)) < 0)
-        goto cleanup;
-
-    if (n > 0) {
-        encdef->secrets = g_new0(virStorageEncryptionSecretPtr, n);
-        encdef->nsecrets = n;
-
-        for (i = 0; i < n; i++) {
-            if (!(encdef->secrets[i] =
-                  virStorageEncryptionSecretParse(ctxt, nodes[i])))
-                goto cleanup;
-        }
-    }
-
-    if (encdef->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) {
-        xmlNodePtr tmpnode;
-
-        if ((tmpnode = virXPathNode("./cipher[1]", ctxt))) {
-            if (virStorageEncryptionInfoParseCipher(tmpnode, &encdef->encinfo) < 0)
-                goto cleanup;
-        }
-
-        if ((tmpnode = virXPathNode("./ivgen[1]", ctxt))) {
-            /* If no cipher node, then fail */
-            if (!encdef->encinfo.cipher_name) {
-                virReportError(VIR_ERR_XML_ERROR, "%s",
-                               _("ivgen element found, but cipher is missing"));
-                goto cleanup;
-            }
-
-            if (virStorageEncryptionInfoParseIvgen(tmpnode, &encdef->encinfo) < 0)
-                goto cleanup;
-        }
-    }
-
-    ret = g_steal_pointer(&encdef);
-
- cleanup:
-    VIR_FREE(nodes);
-    virStorageEncryptionFree(encdef);
-
-    return ret;
-}
-
-
-static int
-virStorageEncryptionSecretFormat(virBufferPtr buf,
-                                 virStorageEncryptionSecretPtr secret)
-{
-    const char *type;
-
-    if (!(type = virStorageEncryptionSecretTypeToString(secret->type))) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("unexpected volume encryption secret type"));
-        return -1;
-    }
-
-    virSecretLookupFormatSecret(buf, type, &secret->seclookupdef);
-
-    return 0;
-}
-
-
-static void
-virStorageEncryptionInfoDefFormat(virBufferPtr buf,
-                                  const virStorageEncryptionInfoDef *enc)
-{
-    virBufferEscapeString(buf, "<cipher name='%s'", enc->cipher_name);
-    virBufferAsprintf(buf, " size='%u'", enc->cipher_size);
-    if (enc->cipher_mode)
-        virBufferEscapeString(buf, " mode='%s'", enc->cipher_mode);
-    if (enc->cipher_hash)
-        virBufferEscapeString(buf, " hash='%s'", enc->cipher_hash);
-    virBufferAddLit(buf, "/>\n");
-
-    if (enc->ivgen_name) {
-        virBufferEscapeString(buf, "<ivgen name='%s'", enc->ivgen_name);
-        if (enc->ivgen_hash)
-            virBufferEscapeString(buf, " hash='%s'", enc->ivgen_hash);
-        virBufferAddLit(buf, "/>\n");
-    }
-}
-
-
-int
-virStorageEncryptionFormat(virBufferPtr buf,
-                           virStorageEncryptionPtr enc)
-{
-    const char *format;
-    size_t i;
-
-    if (!(format = virStorageEncryptionFormatTypeToString(enc->format))) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       "%s", _("unexpected encryption format"));
-        return -1;
-    }
-    virBufferAsprintf(buf, "<encryption format='%s'>\n", format);
-    virBufferAdjustIndent(buf, 2);
-
-    for (i = 0; i < enc->nsecrets; i++) {
-        if (virStorageEncryptionSecretFormat(buf, enc->secrets[i]) < 0)
-            return -1;
-    }
-
-    if (enc->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS &&
-        enc->encinfo.cipher_name)
-        virStorageEncryptionInfoDefFormat(buf, &enc->encinfo);
-
-    virBufferAdjustIndent(buf, -2);
-    virBufferAddLit(buf, "</encryption>\n");
-
-    return 0;
-}
diff --git a/src/util/virstorageencryption.h b/src/util/virstorageencryption.h
deleted file mode 100644 (file)
index 352dd37..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * virstorageencryption.h: volume encryption information
- *
- * Copyright (C) 2009-2011, 2014 Red Hat, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library.  If not, see
- * <http://www.gnu.org/licenses/>.
- */
-
-#pragma once
-
-#include "internal.h"
-#include "virbuffer.h"
-#include "virsecret.h"
-#include "virenum.h"
-
-#include <libxml/tree.h>
-
-typedef enum {
-    VIR_STORAGE_ENCRYPTION_SECRET_TYPE_PASSPHRASE = 0,
-
-    VIR_STORAGE_ENCRYPTION_SECRET_TYPE_LAST
-} virStorageEncryptionSecretType;
-VIR_ENUM_DECL(virStorageEncryptionSecret);
-
-typedef struct _virStorageEncryptionSecret virStorageEncryptionSecret;
-typedef virStorageEncryptionSecret *virStorageEncryptionSecretPtr;
-struct _virStorageEncryptionSecret {
-    int type; /* virStorageEncryptionSecretType */
-    virSecretLookupTypeDef seclookupdef;
-};
-
-/* It's possible to dictate the cipher and if necessary iv */
-typedef struct _virStorageEncryptionInfoDef virStorageEncryptionInfoDef;
-typedef virStorageEncryptionInfoDef *virStorageEncryptionInfoDefPtr;
-struct _virStorageEncryptionInfoDef {
-    unsigned int cipher_size;
-    char *cipher_name;
-    char *cipher_mode;
-    char *cipher_hash;
-    char *ivgen_name;
-    char *ivgen_hash;
-};
-
-typedef enum {
-    /* "default" is only valid for volume creation */
-    VIR_STORAGE_ENCRYPTION_FORMAT_DEFAULT = 0,
-    VIR_STORAGE_ENCRYPTION_FORMAT_QCOW, /* Both qcow and qcow2 */
-    VIR_STORAGE_ENCRYPTION_FORMAT_LUKS,
-
-    VIR_STORAGE_ENCRYPTION_FORMAT_LAST,
-} virStorageEncryptionFormatType;
-VIR_ENUM_DECL(virStorageEncryptionFormat);
-
-typedef struct _virStorageEncryption virStorageEncryption;
-typedef virStorageEncryption *virStorageEncryptionPtr;
-struct _virStorageEncryption {
-    int format; /* virStorageEncryptionFormatType */
-    int payload_offset;
-
-    size_t nsecrets;
-    virStorageEncryptionSecretPtr *secrets;
-
-    virStorageEncryptionInfoDef encinfo;
-};
-
-virStorageEncryptionPtr virStorageEncryptionCopy(const virStorageEncryption *src)
-    ATTRIBUTE_NONNULL(1);
-
-void virStorageEncryptionFree(virStorageEncryptionPtr enc);
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStorageEncryption, virStorageEncryptionFree);
-
-virStorageEncryptionPtr virStorageEncryptionParseNode(xmlNodePtr node,
-                                                      xmlXPathContextPtr ctxt);
-int virStorageEncryptionFormat(virBufferPtr buf,
-                               virStorageEncryptionPtr enc);
-
-/* A helper for VIR_STORAGE_ENCRYPTION_FORMAT_QCOW */
-enum {
-  VIR_STORAGE_QCOW_PASSPHRASE_SIZE = 16
-};