[PATCH] virnetdev: Use VIR_WITH_MUTEX_LOCK_GUARD in virNetDevGenerateName()

Michal Privoznik posted 1 patch 2 years, 1 month ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/b6b3223bd9138b7a5e60a5a9acf9e8d0e1a07111.1647505420.git.mprivozn@redhat.com
src/util/virnetdev.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] virnetdev: Use VIR_WITH_MUTEX_LOCK_GUARD in virNetDevGenerateName()
Posted by Michal Privoznik 2 years, 1 month ago
The virNetDevGenerateName() function uses a global array of
virNetDevGenName structs to find next unused name for network
device. This obviously needs some locking and in fact each member
of the array has its own lock. However, these members are not
virObjects, they are just plain structs, therefore
VIR_WITH_MUTEX_LOCK_GUARD() must be used instead of
VIR_WITH_OBJECT_LOCK_GUARD() to lock individual mutexes.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/util/virnetdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index 5df48af60c..1c15a475fa 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -3616,7 +3616,7 @@ virNetDevGenerateName(char **ifname, virNetDevGenNameType type)
         g_autofree char *try = NULL;
         int id = 0;
 
-        VIR_WITH_OBJECT_LOCK_GUARD(&virNetDevGenNames[type].mutex) {
+        VIR_WITH_MUTEX_LOCK_GUARD(&virNetDevGenNames[type].mutex) {
             id = ++virNetDevGenNames[type].lastID;
 
             /* reset before overflow */
-- 
2.34.1
Re: [PATCH] virnetdev: Use VIR_WITH_MUTEX_LOCK_GUARD in virNetDevGenerateName()
Posted by Pavel Hrdina 2 years, 1 month ago
On Thu, Mar 17, 2022 at 09:23:40AM +0100, Michal Privoznik wrote:
> The virNetDevGenerateName() function uses a global array of
> virNetDevGenName structs to find next unused name for network
> device. This obviously needs some locking and in fact each member
> of the array has its own lock. However, these members are not
> virObjects, they are just plain structs, therefore
> VIR_WITH_MUTEX_LOCK_GUARD() must be used instead of
> VIR_WITH_OBJECT_LOCK_GUARD() to lock individual mutexes.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/util/virnetdev.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>