[PATCH 09/15] nwfilter: Make a common UUID lookup function from driver

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

 



Rather than separate calls, use a common call and generate a better
error message which includes the incorrect uuidstr

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/nwfilter/nwfilter_driver.c | 35 ++++++++++++++++++++---------------
 1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c
index 650c528..781a7a0 100644
--- a/src/nwfilter/nwfilter_driver.c
+++ b/src/nwfilter/nwfilter_driver.c
@@ -356,6 +356,21 @@ nwfilterStateCleanup(void)
 }
 
 
+static virNWFilterObjPtr
+nwfilterObjFromNWFilter(const unsigned char *uuid)
+{
+    virNWFilterObjPtr obj;
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
+
+    if (!(obj = virNWFilterObjListFindByUUID(driver->nwfilters, uuid))) {
+        virUUIDFormat(uuid, uuidstr);
+        virReportError(VIR_ERR_NO_NWFILTER,
+                       _("no nwfilter with matching uuid '%s'"), uuidstr);
+    }
+    return obj;
+}
+
+
 static virNWFilterPtr
 nwfilterLookupByUUID(virConnectPtr conn,
                      const unsigned char *uuid)
@@ -365,14 +380,11 @@ nwfilterLookupByUUID(virConnectPtr conn,
     virNWFilterPtr ret = NULL;
 
     nwfilterDriverLock();
-    obj = virNWFilterObjListFindByUUID(driver->nwfilters, uuid);
+    obj = nwfilterObjFromNWFilter(uuid);
     nwfilterDriverUnlock();
 
-    if (!obj) {
-        virReportError(VIR_ERR_NO_NWFILTER,
-                       "%s", _("no nwfilter with matching uuid"));
+    if (!obj)
         goto cleanup;
-    }
     def = virNWFilterObjGetDef(obj);
 
     if (virNWFilterLookupByUUIDEnsureACL(conn, def) < 0)
@@ -528,12 +540,8 @@ nwfilterUndefine(virNWFilterPtr nwfilter)
     virNWFilterWriteLockFilterUpdates();
     virNWFilterCallbackDriversLock();
 
-    obj = virNWFilterObjListFindByUUID(driver->nwfilters, nwfilter->uuid);
-    if (!obj) {
-        virReportError(VIR_ERR_NO_NWFILTER,
-                       "%s", _("no nwfilter with matching uuid"));
+    if (!(obj = nwfilterObjFromNWFilter(nwfilter->uuid)))
         goto cleanup;
-    }
     def = virNWFilterObjGetDef(obj);
 
     if (virNWFilterUndefineEnsureACL(nwfilter->conn, def) < 0)
@@ -575,14 +583,11 @@ nwfilterGetXMLDesc(virNWFilterPtr nwfilter,
     virCheckFlags(0, NULL);
 
     nwfilterDriverLock();
-    obj = virNWFilterObjListFindByUUID(driver->nwfilters, nwfilter->uuid);
+    obj = nwfilterObjFromNWFilter(nwfilter->uuid);
     nwfilterDriverUnlock();
 
-    if (!obj) {
-        virReportError(VIR_ERR_NO_NWFILTER,
-                       "%s", _("no nwfilter with matching uuid"));
+    if (!obj)
         goto cleanup;
-    }
     def = virNWFilterObjGetDef(obj);
 
     if (virNWFilterGetXMLDescEnsureACL(nwfilter->conn, def) < 0)
-- 
2.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]
  Powered by Linux