[libvirt] [PATCH] Simplify some redundant locking while unref'ing objects

From: "Daniel P. Berrange" <berrange@redhat.com> There is no need to hold the mutex when unref'ing virObject instances Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- src/conf/domain_conf.c | 4 +--- src/qemu/qemu_driver.c | 4 ++-- src/rpc/virnetserver.c | 3 --- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 4aa08d0..0514540 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -741,9 +741,7 @@ static void virDomainObjListDataFree(void *payload, const void *name ATTRIBUTE_UNUSED) { virDomainObjPtr obj = payload; - virDomainObjLock(obj); - if (virObjectUnref(obj)) - virDomainObjUnlock(obj); + virObjectUnref(obj); } int virDomainObjListInit(virDomainObjListPtr doms) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 6848924..e963ed3 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3499,8 +3499,8 @@ endjob: ignore_value(qemuDomainObjEndAsyncJob(driver, wdEvent->vm)); unlock: - if (virObjectUnref(wdEvent->vm)) - virDomainObjUnlock(wdEvent->vm); + virDomainObjUnlock(wdEvent->vm); + virObjectUnref(wdEvent->vm); qemuDriverUnlock(driver); VIR_FREE(wdEvent); } diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c index 23493bd..ae4ed46 100644 --- a/src/rpc/virnetserver.c +++ b/src/rpc/virnetserver.c @@ -191,10 +191,7 @@ static void virNetServerHandleJob(void *jobOpaque, void *opaque) if (virNetServerProcessMsg(srv, job->client, job->prog, job->msg) < 0) goto error; - virNetServerLock(srv); virObjectUnref(job->prog); - virNetServerUnlock(srv); - virObjectUnref(job->client); VIR_FREE(job); return; -- 1.7.11.2

On 09/25/2012 02:29 PM, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
There is no need to hold the mutex when unref'ing virObject instances
Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- src/conf/domain_conf.c | 4 +--- src/qemu/qemu_driver.c | 4 ++-- src/rpc/virnetserver.c | 3 --- 3 files changed, 3 insertions(+), 8 deletions(-)
ACK.
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 4aa08d0..0514540 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -741,9 +741,7 @@ static void virDomainObjListDataFree(void *payload, const void *name ATTRIBUTE_UNUSED) { virDomainObjPtr obj = payload; - virDomainObjLock(obj); - if (virObjectUnref(obj)) - virDomainObjUnlock(obj); + virObjectUnref(obj); }
We now have several of these one-liner cleanup functions. Is it worth making a common hash wrapper function that calls virObjectUnref on the object, rather than having to reinvent lots of one-liners, as a followup patch? -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Tue, Sep 25, 2012 at 05:49:39PM -0600, Eric Blake wrote:
On 09/25/2012 02:29 PM, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
There is no need to hold the mutex when unref'ing virObject instances
Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- src/conf/domain_conf.c | 4 +--- src/qemu/qemu_driver.c | 4 ++-- src/rpc/virnetserver.c | 3 --- 3 files changed, 3 insertions(+), 8 deletions(-)
ACK.
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 4aa08d0..0514540 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -741,9 +741,7 @@ static void virDomainObjListDataFree(void *payload, const void *name ATTRIBUTE_UNUSED) { virDomainObjPtr obj = payload; - virDomainObjLock(obj); - if (virObjectUnref(obj)) - virDomainObjUnlock(obj); + virObjectUnref(obj); }
We now have several of these one-liner cleanup functions. Is it worth making a common hash wrapper function that calls virObjectUnref on the object, rather than having to reinvent lots of one-liners, as a followup patch?
Yes, it probably is worthwhile. I actually remember you mentioning this when I first posted the virObject patches Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
participants (2)
-
Daniel P. Berrange
-
Eric Blake