[libvirt] [PATCH v2 1/2] util: Deduplicate code in virNetlinkEventServiceStopAll

Commit 15a71e60 introduced the virNetlinkEventServiceStopAll function, and the code in virNetlinkEventServiceStop is copied to this function. can use virNetlinkEventServiceStop instead. --- src/util/virnetlink.c | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index 92ecf77..fad1e8e 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -775,32 +775,13 @@ virNetlinkEventServiceStop(unsigned int protocol) int virNetlinkEventServiceStopAll(void) { - size_t i, j; + size_t i; virNetlinkEventSrvPrivatePtr srv = NULL; VIR_INFO("stopping all netlink event services"); - for (i = 0; i < MAX_LINKS; i++) { - srv = server[i]; - if (!srv) - continue; - - virNetlinkEventServerLock(srv); - nl_close(srv->netlinknh); - virNetlinkFree(srv->netlinknh); - virEventRemoveHandle(srv->eventwatch); - - for (j = 0; j < srv->handlesCount; j++) { - if (srv->handles[j].deleted == VIR_NETLINK_HANDLE_VALID) - virNetlinkEventRemoveClientPrimitive(j, i); - } - - server[i] = NULL; - virNetlinkEventServerUnlock(srv); - - virMutexDestroy(&srv->lock); - VIR_FREE(srv); - } + for (i = 0; i < MAX_LINKS; i++) + virNetlinkEventServiceStop(i); return 0; } -- 2.8.3

handles stored in virNetlinkEventSrvPrivatePtr should be freed when stop netlink event service. --- src/util/virnetlink.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index fad1e8e..7988312 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -758,6 +758,7 @@ virNetlinkEventServiceStop(unsigned int protocol) } server[protocol] = NULL; + VIR_FREE(srv->handles); virNetlinkEventServerUnlock(srv); virMutexDestroy(&srv->lock); -- 2.8.3

On 05/18/2017 12:06 AM, Wang King wrote:
handles stored in virNetlinkEventSrvPrivatePtr should be freed when stop netlink event service.
Altered the commit message to describe which commit introduced and just fit that into the text...
--- src/util/virnetlink.c | 1 + 1 file changed, 1 insertion(+)
Reviewed-by: John Ferlan <jferlan@redhat.com> Will push soon - tks, John
diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index fad1e8e..7988312 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -758,6 +758,7 @@ virNetlinkEventServiceStop(unsigned int protocol) }
server[protocol] = NULL; + VIR_FREE(srv->handles); virNetlinkEventServerUnlock(srv);
virMutexDestroy(&srv->lock);

On 05/18/2017 12:06 AM, Wang King wrote:
Commit 15a71e60 introduced the virNetlinkEventServiceStopAll function, and the code in virNetlinkEventServiceStop is copied to this function. can use virNetlinkEventServiceStop instead. --- src/util/virnetlink.c | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-)
diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index 92ecf77..fad1e8e 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -775,32 +775,13 @@ virNetlinkEventServiceStop(unsigned int protocol) int virNetlinkEventServiceStopAll(void) { - size_t i, j; + size_t i; virNetlinkEventSrvPrivatePtr srv = NULL;
^^^ This wasn't necessary either... I'll remove it before pushing. Reviewed-by: John Ferlan <jferlan@redhat.com> John
VIR_INFO("stopping all netlink event services");
- for (i = 0; i < MAX_LINKS; i++) { - srv = server[i]; - if (!srv) - continue; - - virNetlinkEventServerLock(srv); - nl_close(srv->netlinknh); - virNetlinkFree(srv->netlinknh); - virEventRemoveHandle(srv->eventwatch); - - for (j = 0; j < srv->handlesCount; j++) { - if (srv->handles[j].deleted == VIR_NETLINK_HANDLE_VALID) - virNetlinkEventRemoveClientPrimitive(j, i); - } - - server[i] = NULL; - virNetlinkEventServerUnlock(srv); - - virMutexDestroy(&srv->lock); - VIR_FREE(srv); - } + for (i = 0; i < MAX_LINKS; i++) + virNetlinkEventServiceStop(i);
return 0; }
participants (2)
-
John Ferlan
-
Wang King