Revision bbd2274c

View differences:

include/LifeCycleManager.h
157 157
    /**
158 158
     *  Cleans up a VM, canceling any pending or ongoing action and closing
159 159
     *  the history registers
160
     *      @param vm with the lock aquired
160
     *
161
     * @param vm with the lock acquired
162
     * @param dispose true if the vm will end in DONE, false to resubmit to PENDING
163
     * @param image_id If the VM is in the middle of a save as operation, an
164
     * image may need to be set to error state.
161 165
     */
162
    void clean_up_vm (VirtualMachine *vm, bool dispose);
166
    void clean_up_vm (VirtualMachine *vm, bool dispose, int& image_id);
163 167

  
164 168
    void save_success_action(int vid);
165 169

  
src/lcm/LifeCycleActions.cc
565 565
/* -------------------------------------------------------------------------- */
566 566
/* -------------------------------------------------------------------------- */
567 567

  
568
void  LifeCycleManager::delete_action(int vid)
568
void LifeCycleManager::delete_action(int vid)
569 569
{
570 570
    VirtualMachine * vm;
571 571

  
......
573 573
    DispatchManager * dm = nd.get_dm();
574 574
    TransferManager * tm = nd.get_tm();
575 575

  
576
    ImagePool*        ipool = nd.get_ipool();
577
    Image*            image;
578

  
579
    int image_id;
580

  
576 581
    vm = vmpool->get(vid,true);
577 582

  
578 583
    if ( vm == 0 )
......
612 617
        break;
613 618

  
614 619
        default:
615
            clean_up_vm(vm, true);
620
            clean_up_vm(vm, true, image_id);
616 621
            dm->trigger(DispatchManager::DONE, vid);
617 622
        break;
618 623
    }
619 624

  
620 625
    vm->unlock();
621 626

  
622
    return;
627
    image = ipool->get(image_id, true);
628

  
629
    if ( image != 0 )
630
    {
631
        image->set_state(Image::ERROR);
632

  
633
        ipool->update(image);
634

  
635
        image->unlock();
636
    }
623 637
}
624 638

  
625 639
/* -------------------------------------------------------------------------- */
......
633 647
    DispatchManager * dm = nd.get_dm();
634 648
    TransferManager * tm = nd.get_tm();
635 649

  
650
    ImagePool*        ipool = nd.get_ipool();
651
    Image*            image;
652

  
653
    int image_id;
654

  
636 655
    vm = vmpool->get(vid,true);
637 656

  
638 657
    if ( vm == 0 )
......
667 686
        break;
668 687

  
669 688
        default:
670
            clean_up_vm(vm, false);
689
            clean_up_vm(vm, false, image_id);
671 690
        break;
672 691
    }
673 692

  
674 693
    vm->unlock();
694

  
695
    image = ipool->get(image_id, true);
696

  
697
    if ( image != 0 )
698
    {
699
        image->set_state(Image::ERROR);
700

  
701
        ipool->update(image);
702

  
703
        image->unlock();
704
    }
675 705
}
676 706

  
677 707
/* -------------------------------------------------------------------------- */
678 708
/* -------------------------------------------------------------------------- */
679 709

  
680
void  LifeCycleManager::clean_up_vm(VirtualMachine * vm, bool dispose)
710
void  LifeCycleManager::clean_up_vm(VirtualMachine * vm, bool dispose, int& image_id)
681 711
{
682 712
    int    cpu, mem, disk;
683 713
    time_t the_time = time(0);
......
687 717
    TransferManager *       tm  = nd.get_tm();
688 718
    VirtualMachineManager * vmm = nd.get_vmm();
689 719

  
690
    ImagePool*              ipool = nd.get_ipool();
691

  
692 720
    VirtualMachine::LcmState state = vm->get_lcm_state();
693 721
    int                      vid   = vm->get_oid();
694 722

  
......
770 798
        case VirtualMachine::HOTPLUG_SAVEAS_SUSPENDED:
771 799
            tm->trigger(TransferManager::DRIVER_CANCEL, vid);
772 800

  
773
            int image_id;
774 801
            vm->cancel_saveas_disk(image_id);
775 802

  
776
            // TODO: Remove potential deadlock, vm is locked and we shouldn't
777
            // unlock it. Maybe we could add a trigger to ImageManager
778

  
779
            Image* image;
780

  
781
            image = ipool->get(image_id, true);
782

  
783
            if ( image != 0 )
784
            {
785
                image->set_state(Image::ERROR);
786

  
787
                ipool->update(image);
788

  
789
                image->unlock();
790
            }
791

  
792 803
            vm->set_running_etime(the_time);
793 804
            vmpool->update_history(vm);
794 805

  

Also available in: Unified diff