[PATCH v2 3/7] storage: Add a struct for auth secret

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

 



From: Osier Yang <jyang@xxxxxxxxxx>

Create _virStoragePoolAuthSecret for the _virStoragePoolAuthCephx to abstract
parsing the XML secret object.
---
 src/conf/storage_conf.c | 68 ++++++++++++++++++++++++++++---------------------
 src/conf/storage_conf.h | 14 ++++++----
 2 files changed, 48 insertions(+), 34 deletions(-)

diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 997df54..3b789f7 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -452,6 +452,43 @@ virStoragePoolObjRemove(virStoragePoolObjListPtr pools,
     }
 }
 
+static int
+virStoragePoolDefParseAuthSecret(xmlXPathContextPtr ctxt,
+                                 virStoragePoolAuthSecretPtr secret)
+
+{
+    char *uuid = NULL;
+    int ret = -1;
+
+    uuid = virXPathString("string(./auth/secret/@uuid)", ctxt);
+    secret->usage = virXPathString("string(./auth/secret/@usage)", ctxt);
+    if (uuid == NULL && secret->usage == NULL) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("missing auth secret uuid or usage attribute"));
+        return -1;
+    }
+
+    if (uuid != NULL) {
+        if (secret->usage != NULL) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("either auth secret uuid or usage expected"));
+            goto cleanup;
+        }
+        if (virUUIDParse(uuid, secret->uuid) < 0) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("invalid auth secret uuid"));
+            goto cleanup;
+        }
+        secret->uuidUsable = true;
+    } else {
+        secret->uuidUsable = false;
+    }
+
+    ret = 0;
+cleanup:
+    VIR_FREE(uuid);
+    return ret;
+}
 
 static int
 virStoragePoolDefParseAuthChap(xmlXPathContextPtr ctxt,
@@ -494,9 +531,6 @@ static int
 virStoragePoolDefParseAuthCephx(xmlXPathContextPtr ctxt,
                                 virStoragePoolAuthCephxPtr auth)
 {
-    char *uuid = NULL;
-    int ret = -1;
-
     auth->username = virXPathString("string(./auth/@username)", ctxt);
     if (auth->username == NULL) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
@@ -504,34 +538,10 @@ virStoragePoolDefParseAuthCephx(xmlXPathContextPtr ctxt,
         return -1;
     }
 
-    uuid = virXPathString("string(./auth/secret/@uuid)", ctxt);
-    auth->secret.usage = virXPathString("string(./auth/secret/@usage)", ctxt);
-    if (uuid == NULL && auth->secret.usage == NULL) {
-        virReportError(VIR_ERR_XML_ERROR, "%s",
-                       _("missing auth secret uuid or usage attribute"));
+    if (virStoragePoolDefParseAuthSecret(ctxt, &auth->secret) < 0)
         return -1;
-    }
-
-    if (uuid != NULL) {
-        if (auth->secret.usage != NULL) {
-            virReportError(VIR_ERR_XML_ERROR, "%s",
-                           _("either auth secret uuid or usage expected"));
-            goto cleanup;
-        }
-        if (virUUIDParse(uuid, auth->secret.uuid) < 0) {
-            virReportError(VIR_ERR_XML_ERROR, "%s",
-                           _("invalid auth secret uuid"));
-            goto cleanup;
-        }
-        auth->secret.uuidUsable = true;
-    } else {
-        auth->secret.uuidUsable = false;
-    }
 
-    ret = 0;
-cleanup:
-    VIR_FREE(uuid);
-    return ret;
+    return 0;
 }
 
 static int
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index c183427..452f583 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -148,6 +148,14 @@ enum virStoragePoolAuthType {
     VIR_STORAGE_POOL_AUTH_CEPHX,
 };
 
+typedef struct _virStoragePoolAuthSecret virStoragePoolAuthSecret;
+typedef virStoragePoolAuthSecret *virStoragePoolAuthSecretPtr;
+struct _virStoragePoolAuthSecret {
+    unsigned char uuid[VIR_UUID_BUFLEN];
+    char *usage;
+    bool uuidUsable;
+};
+
 typedef struct _virStoragePoolAuthChap virStoragePoolAuthChap;
 typedef virStoragePoolAuthChap *virStoragePoolAuthChapPtr;
 struct _virStoragePoolAuthChap {
@@ -159,11 +167,7 @@ typedef struct _virStoragePoolAuthCephx virStoragePoolAuthCephx;
 typedef virStoragePoolAuthCephx *virStoragePoolAuthCephxPtr;
 struct _virStoragePoolAuthCephx {
     char *username;
-    struct {
-            unsigned char uuid[VIR_UUID_BUFLEN];
-            char *usage;
-            bool uuidUsable;
-    } secret;
+    virStoragePoolAuthSecret secret;
 };
 
 /*
-- 
1.8.1.4

--
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]