revertSnapshot fails with an NPE when the snapshot's volume has been deleted

Aperta
#14,644 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@bhouse-nexthop ci sta già lavorando.

Dal 9/11/2026.

  • #14646 di @bhouse-nexthop — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
java

Direzione di ricerca

Start by reading SnapshotManagerImpl.revertSnapshot and the snapshot copy path that chooses a source zone; the issue identifies findById() as the lookup that returns null for removed volumes. Then inspect VolumeApiServiceImpl.allocVolume and TemplateManagerImpl.createPrivateTemplate for snapshot based creation when the volume row is missing. Add clear errors for the missing volume cases and use the snapshot's recorded zone for copy; done when all four API paths handle these cases without an NPE.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

problem

revertSnapshot fails with a NullPointerException when the snapshot's volume has been deleted:

Cannot invoke "com.cloud.storage.VolumeVO.getState()" because "volume" is null
    at com.cloud.storage.snapshot.SnapshotManagerImpl.revertSnapshot

SnapshotManagerImpl.revertSnapshot looks the volume up with findById(), which does not return removed volumes, and uses the result without a null check. Volume snapshots outlive their volume, so any snapshot of a deleted volume hits this. The caller gets an internal error instead of being told why the snapshot cannot be reverted.

A few other snapshot APIs have the same gap:

  • copySnapshot without sourcezoneid takes the source zone from the volume, also looked up with findById(). For a snapshot of a deleted volume it fails with Cannot invoke "com.cloud.storage.Volume.getDataCenterId()" because "volume" is null. The copy itself does not need the volume, and the same copy works when sourcezoneid is passed.
  • createVolume from a snapshot and createTemplate from a snapshot look the volume up including removed rows, so a deleted volume is fine. They still NPE when the volume row itself is gone (parentVolume.getPassphraseId() in VolumeApiServiceImpl.allocVolume; for createTemplate, the template record is created and the job then fails in TemplateManagerImpl.createPrivateTemplate). A missing row is the case in #14599.
versions

4.22, and main.

The steps to reproduce the bug
  1. Create a data volume, attach it to a VM, and take a volume snapshot of it.
  2. Detach and delete the volume. The snapshot remains.
  3. Call revertSnapshot id=<snapshot>. It fails with the NPE above.
  4. Call copySnapshot id=<snapshot> destzoneids=<another zone> without sourcezoneid. It fails with the getDataCenterId() NPE.

For createVolume snapshotid= and createTemplate snapshotid=, the volume row has to be missing from the volumes table.

What to do about it?
  • revertSnapshot: refuse with a clear error when the snapshot's volume no longer exists.
  • copySnapshot: when the volume is gone, take the source zone from the snapshot, which records the zone it was taken in.
  • createVolume and createTemplate from a snapshot: refuse with a clear error when the volume row is missing, instead of failing with an NPE.
Lingua principale
Java
Stelle
3.1k
Fork
1.4k
Merge medio
7g 16h
PR unite (30g)
15

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/cloudstack

Tutte le issue di apache/cloudstack

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.