]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virSecurityDACTransactionRun: Implement rollback
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 25 Sep 2018 08:36:13 +0000 (10:36 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 19 Dec 2018 14:32:06 +0000 (15:32 +0100)
When iterating over list of paths/disk sources to relabel it may
happen that the process fails at some point. In that case, for
the sake of keeping seclabel refcount (stored in XATTRs) in sync
with reality we have to perform rollback. However, if that fails
too the only thing we can do is warn user.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/security/security_dac.c

index f01d0b4732159cf56f19e69314da117aa66aa107..7be555903d35ad2615ba11247a4e8202970b9a5c 100644 (file)
@@ -229,7 +229,6 @@ virSecurityDACTransactionRun(pid_t pid ATTRIBUTE_UNUSED,
     for (i = 0; i < list->nItems; i++) {
         virSecurityDACChownItemPtr item = list->items[i];
 
-        /* TODO Implement rollback */
         if (!item->restore) {
             rv = virSecurityDACSetOwnership(list->manager,
                                             item->src,
@@ -246,6 +245,19 @@ virSecurityDACTransactionRun(pid_t pid ATTRIBUTE_UNUSED,
             break;
     }
 
+    for (; rv < 0 && i > 0; i--) {
+        virSecurityDACChownItemPtr item = list->items[i - 1];
+
+        if (!item->restore) {
+            virSecurityDACRestoreFileLabelInternal(list->manager,
+                                                   item->src,
+                                                   item->path);
+        } else {
+            VIR_WARN("Ignoring failed restore attempt on %s",
+                     NULLSTR(item->src ? item->src->path : item->path));
+        }
+    }
+
     if (list->lock)
         virSecurityManagerMetadataUnlock(list->manager, &state);