StorPool: resize of an encrypted volume does not account for the LUKS header (live resize fails with "Cannot grow device files", guest ends up 2 MiB short)

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

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

這個 Issue 還沒有評估資料。

描述

bug
problem

When a LUKS-encrypted volume on StorPool primary storage is resized, the
plugin resizes the StorPool volume to exactly the requested size. At creation
the plugin adds 2 MiB (2097152 bytes) for the LUKS header, but the resize path
does not.

Effects:

  1. Live resize fails inside QEMU. The agent runs virsh blockresize with the
    new size; QEMU needs new size + LUKS payload offset on the underlying block
    device, which is larger than the device, and returns:

    internal error: unable to execute QEMU command 'block_resize': Cannot grow device files
    

    The failure is not surfaced. notifyqemu() in resizevolume.sh only logs
    "failed to live resize", the script exits 0, the agent returns success and
    the resizeVolume job succeeds. The guest keeps seeing the old size.

  2. Size mismatch. CloudStack records the requested size, but once QEMU
    re-reads the device (VM stop/start, or a manual blockresize) the guest sees
    the requested size minus the LUKS header. The same shortfall applies to
    offline resize, without any error (from code reading, not tested).

  3. Rollback uses the same unadjusted size (from code reading, not tested).
    If the StorPool API call or the agent command fails, resizeVolume() calls
    StorPoolUtil.volumeUpdate(name, oldSize, true, ...), i.e. shrinkOk=true
    with the CloudStack size. For an encrypted volume that has never been
    resized the device is oldSize + 2097152, so this requests a 2 MiB shrink of
    a LUKS device.

Code references (main at cc30155defc89bce24a253df892a0494ae8bba1e):

The header allowance was introduced with StorPool encryption support in #7539.

versions

on all versions

The steps to reproduce the bug
  1. KVM zone with StorPool primary storage and a host that supports volume
    encryption. Create a custom-size disk offering with encrypt=true, tagged
    to the StorPool pool.
  2. Create a 10 GiB data volume from that offering and attach it to a running
    VM. On the host, blockdev --getsize64 on the StorPool device shows
    10739515392 (10 GiB + 2097152); the guest sees 10737418240.
  3. Resize the volume while the VM is running:
    cmk resize volume id= size=20
  4. Observe:
    • the resizeVolume job succeeds and CloudStack reports 20 GiB
    • blockdev --getsize64 shows 21474836480 (exactly 20 GiB, no allowance)
    • libvirtd logs the block_resize "Cannot grow device files" error
    • the guest still sees 10 GiB

Expected: the StorPool volume is resized to 20 GiB + 2097152, blockresize
succeeds, and the guest sees 20 GiB, matching what CloudStack reports.

What to do about it?

Apply the same allowance on resize as on create, for encrypted volumes only:

  • In updateVolumeByOffering and updateVolumeByStorPoolQoS, send
    payload.newSize + 2097152 to the StorPool API when the volume has a
    passphrase (or KMS key on main). updateVolumeByStorPoolQoS needs the
    volume passed in.
  • Use the same adjusted size for the rollback in resizeVolume().
  • Keep payload.newSize for the agent command and for the size stored in
    the database.

Sketch:

private static long getStorPoolVolumeSize(VolumeObject vol, long size) {
    boolean encrypted = vol.getPassphraseId() != null || vol.getKmsKeyId() != null;
    return encrypted ? size + 2097152 : size;
}

Volumes already resized under this bug have no allowance; the next resize
after the fix would correct them.

Separately, it may be worth surfacing the blockresize failure instead of
returning success, so a failed live resize is visible in the job result.

主要語言
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 摘要。