[libvirt] [PATCH v2 1/9] libvirtd: Alter refcnt processing for domain server objects

John Ferlan jferlan at redhat.com
Sat Jul 7 12:10:59 UTC 2018


Once virNetDaemonAddServer returns, the @srv or @srvAdm have
either been added to the @dmn list increasing the refcnt or
there was an error. In either case, we can lower the refcnt
from virNetServerNew, but not set to NULL. Thus "using" the
hash table reference when adding programs later or allowing
the immediate free of the object on error.

The @dmn dispose function (virNetDaemonDispose) will handle
the Unref of each object during the virHashFree when the
object is removed from the hash table.

Signed-off-by: John Ferlan <jferlan at redhat.com>
Reviewed-by: Erik Skultety <eskultet at redhat.com>
Reviewed-by: Marc Hartmayer <mhartmay at linux.vnet.ibm.com>
---
 src/remote/remote_daemon.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c
index 9f3a5f38ad..f61d58f3e5 100644
--- a/src/remote/remote_daemon.c
+++ b/src/remote/remote_daemon.c
@@ -1036,6 +1036,7 @@ int main(int argc, char **argv) {
     char *remote_config_file = NULL;
     int statuswrite = -1;
     int ret = 1;
+    int rc;
     int pid_file_fd = -1;
     char *pid_file = NULL;
     char *sock_file = NULL;
@@ -1290,7 +1291,11 @@ int main(int argc, char **argv) {
         goto cleanup;
     }
 
-    if (virNetDaemonAddServer(dmn, srv) < 0) {
+    /* Add @srv to @dmn servers hash table and Unref to allow removal from
+     * hash table at @dmn disposal to decide when to free @srv */
+    rc = virNetDaemonAddServer(dmn, srv);
+    virObjectUnref(srv);
+    if (rc < 0) {
         ret = VIR_DAEMON_ERR_INIT;
         goto cleanup;
     }
@@ -1358,7 +1363,11 @@ int main(int argc, char **argv) {
         goto cleanup;
     }
 
-    if (virNetDaemonAddServer(dmn, srvAdm) < 0) {
+    /* Add @srvAdm to @dmn servers hash table and Unref to allow removal from
+     * hash table at @dmn disposal to decide when to free @srvAdm */
+    rc = virNetDaemonAddServer(dmn, srvAdm);
+    virObjectUnref(srvAdm);
+    if (rc < 0) {
         ret = VIR_DAEMON_ERR_INIT;
         goto cleanup;
     }
@@ -1479,11 +1488,9 @@ int main(int argc, char **argv) {
     }
 
     virObjectUnref(adminProgram);
-    virObjectUnref(srvAdm);
     virObjectUnref(qemuProgram);
     virObjectUnref(lxcProgram);
     virObjectUnref(remoteProgram);
-    virObjectUnref(srv);
     virObjectUnref(dmn);
 
     virNetlinkShutdown();
-- 
2.17.1




More information about the libvir-list mailing list