Interrupted running-VM volume snapshot leaves the VM on an orphan overlay, disk reverts on next start

未關閉
#14,691 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
5/5
預估耗時
一週以上
新手友好度
15/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
java

研究方向

Start in KVMStorageProcessor, following the volume snapshot path to mergeSnapshotIntoBaseFileWithoutEvents(), and check how Script.runScript() turns a non-zero virsh blockcommit exit into a null result. Agent death is handled in Agent.java at the ReadyCommand System.exit(1). Done means a failed merge fails the snapshot rather than marking it BackedUp, and the design for recovering from an orphan overlay is agreed in the thread first.

由索引模型根據 Issue 內容生成。

描述

bug
problem

A volume snapshot (non-incremental) of a running VM does three steps in KVMStorageProcessor:

  1. snapshotCreateXML(DISK_ONLY) moves the disk onto a new overlay /mnt/<pool>/<random uuid> (instant).
  2. qemu-img convert copies the frozen base to the snapshot location (minutes to hours, depends on volume size).
  3. virsh blockcommit --active --wait --pivot merges the overlay back into the base.

If step 3 never starts, the VM keeps running on the overlay while volumes.path still points to the base.
The next stop/start builds the domain from volumes.path, so every write since the snapshot started is silently
lost (it only exists in the orphan overlay). After a start the base is written again, so the overlay can no longer
simply be committed back.

There are two ways step 3 never starts.

A. The agent JVM goes away during the convert.

  • SIGKILL / OOM kill of the agent.
  • The agent's own System.exit(1) in Agent.java (ReadyCommand with details) after a failed reconnect. Reproduced by
    making the management server fail the reconnect with Unable to acquire lock on host while the convert was running.

B. virsh blockcommit fails before the job starts, and the failure is reported as success.
Script.runScript() returns null when execute() returns an error, so mergeSnapshotIntoBaseFileWithoutEvents()
gets null for any non-zero exit and logs Successfully merged snapshot. The snapshot ends BackedUp.
Reproduced with:

  • a NAS backup (backup-begin) started during the convert and still running at merge time:
    Operation not supported: disk 'vdb' already in active block job;
  • the domain job held by another operation for more than 30 s:
    Timed out during operation: cannot acquire state change lock.

NAS backups do not go through the VM work queue and do not check for volumes in Snapshotting, so nothing prevents
this overlap.

versions

ACS 4.20+

The steps to reproduce the bug
  1. Running VM with a data disk on NFS, write some data so the convert takes a while.
  2. Take a volume snapshot of the data disk.
  3. As soon as virsh domblklist shows the disk on a new bare-UUID file, either:
    • kill -9 the agent JVM; or
    • start a backup: virsh backup-begin <vm> (push or pull mode) and keep it running until the merge.
  4. Write data in the guest, then stop and start the VM from CloudStack.
What to do about it?

Expected:
The merge either completes, or the snapshot fails and the VM is not left on an overlay that CloudStack does not track.

Actual:
The VM runs on /mnt/<pool>/<uuid> (backing file = the volume). Case B logs:

WARN  Process [N] for command [/bin/bash -c virsh blockcommit <vm> vdb --base ... --pivot ] encountered the error: [error: Operation not supported: disk 'vdb' already in active block job].
DEBUG Successfully merged snapshot [<overlay uuid>] into VM [<vm>] ...

Later snapshots of the volume fail with VM [...] has no disk with path [<base>].
After stop/start the guest reads the data from the time the snapshot started.

Proposed fix

  1. Detect merge failures. Make Script.runScript() (or at least the merge call) return an error on a non-zero
    exit. After the merge, check that the domain disk source is the base path again. If the disk has another block
    job, wait and retry the commit. If it still fails, fail the snapshot with a clear error instead of BackedUp.
  2. Recover after agent death. Before creating the overlay, write a marker (vm, disk, base, overlay) on the shared primary pool, keyed by volume. On every VM start, and on agent start once the pools are mounted, any host that finds a marker reconciles the volume:
  • Domain still running on the overlay: run blockcommit --active --pivot, or pivot the commit job that is already running.
  • Domain gone: commit the overlay offline with qemu-img commit, then start.
  • Overlay still locked by a live qemu: refuse to start.
  • Base written since the marker: never commit, raise an alert and keep the overlay.
    Remove the marker only after domblklist shows the base path again.
  1. Do not exit with commands in progress. On a ReadyCommand with details, reconnect (as isExitOnFailures()=false
    already does) instead of System.exit(1), at least while commands are in progress.
  2. Serialize NAS backups with volume snapshots of the same VM (VM work queue or refuse while a volume is
    Snapshotting).
主要語言
Java
星號
3.1k
分支
1.4k
平均合併
7 天 16 小時
30 天內合併 PR
15

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

apache/cloudstack 的其他 Issue

查看 apache/cloudstack 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。