stepping-stone / vm-manager

The stoney cloud web interface.
http://www.stoney-cloud.org/
Other
0 stars 0 forks source link

Only the first disk is deleted when removing a VM, Template or Dyn.VM #30

Closed dev-zero closed 10 years ago

dev-zero commented 10 years ago

While checking our disk images I found an image which was obviously a leftover from a deleted VM template. In that VM template it was attached as a secondary disk.

Looking through the code I found the following fragments:

VmController.php/VmTemplateController.php: actionDelete

                $vda = $vm->devices->getDiskByName('vda');
                $libvirt = CPhpLibvirt::getInstance();
                if (!$libvirt->deleteVolumeFile($vda->sstSourceFile)) {

This is the culprit for the problem described above.

VMs are affected too:

VmController.php: actionDelete

        if (!is_null($vm)) {
            if (!$vm->isActive()) {
                // delete sstDisk=vda->sstSourceFile
                $vda = $vm->devices->getDiskByName('vda');
                $libvirt = CPhpLibvirt::getInstance();
                if (!$libvirt->deleteVolumeFile($vda->sstSourceFile)) {
                    $this->sendAjaxAnswer(array('error' => 1, 'message' => 'Unable to delete Volume File for Vm \'' . $vm->sstDisplayName . '\'!'));
                }

... as are dynamic VMs:

VmController.php: actionDestroyVm

                    @unlink($vm->devices->getDiskByName('vda')->sstSourceFile);

For a dynamic VM only the first overlay image will be removed when it is destroyed.

dev-zero commented 10 years ago

This bug was reproducible in the version 1.2.10.4 (vm-manager version 1.2.18.9)