]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virSecurityManagerMetadataLock: Expand the comment on deadlocks
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 18 Jul 2019 08:58:19 +0000 (10:58 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 18 Jul 2019 13:13:05 +0000 (15:13 +0200)
Document why we need to sort paths while it's still fresh in my
memory.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Tested-by: Daniel Henrique Barboza <danielhb413@gmail.com>
src/security/security_manager.c

index c205c3bf1707415a4cd5580665c54a1a684ce281..ade2c96141711f43a03de5230ca099d3f7be9f64 100644 (file)
@@ -1289,7 +1289,12 @@ virSecurityManagerMetadataLock(virSecurityManagerPtr mgr ATTRIBUTE_UNUSED,
     if (VIR_ALLOC_N(fds, npaths) < 0)
         return NULL;
 
-    /* Sort paths to lock in order to avoid deadlocks. */
+    /* Sort paths to lock in order to avoid deadlocks with other
+     * processes. For instance, if one process wants to lock
+     * paths A B and there's another that is trying to lock them
+     * in reversed order a deadlock might occur.  But if we sort
+     * the paths alphabetically then both processes will try lock
+     * paths in the same order and thus no deadlock can occur. */
     qsort(paths, npaths, sizeof(*paths), cmpstringp);
 
     for (i = 0; i < npaths; i++) {