[PATCH v2 10/10] migration: update image labels in dst after migration

Peng Liang posted 10 patches 1 month, 2 weeks ago

[PATCH v2 10/10] migration: update image labels in dst after migration

Posted by Peng Liang 1 month, 2 weeks ago
Bacause the timestamp XATTR (the uptime of the host) is used to validate
the remembered labels, it need to update after migration.

Signed-off-by: Peng Liang <liangpeng10@huawei.com>
---
 src/qemu/qemu_migration.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index dd226ea4bcb5..b82762aa0ffd 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -5619,6 +5619,7 @@ qemuMigrationDstFinish(virQEMUDriver *driver,
     qemuDomainJobInfo *jobInfo = NULL;
     bool inPostCopy = false;
     bool doKill = true;
+    size_t i;
 
     VIR_DEBUG("driver=%p, dconn=%p, vm=%p, cookiein=%s, cookieinlen=%d, "
               "cookieout=%p, cookieoutlen=%p, flags=0x%lx, retcode=%d",
@@ -5826,6 +5827,17 @@ qemuMigrationDstFinish(virQEMUDriver *driver,
     /* Guest is successfully running, so cancel previous auto destroy */
     qemuProcessAutoDestroyRemove(driver, vm);
 
+    for (i = 0; i < vm->def->ndisks; i++) {
+        virStorageSource *src = vm->def->disks[i]->src;
+
+        if (!virStorageSourceIsLocalStorage(src) || !src->path ||
+            virFileIsSharedFS(src->path) <= 0)
+            continue;
+
+        if (qemuSecurityUpdateImageLabel(driver, vm, src) < 0)
+            VIR_WARN("Failed to update security label for %s", src->path);
+    }
+
  endjob:
     if (!dom &&
         !(flags & VIR_MIGRATE_OFFLINE) &&
-- 
2.31.1