Revision ade6513a src/image/ImageManagerActions.cc

View differences:

src/image/ImageManagerActions.cc
287 287
        case Image::ERROR:
288 288
        case Image::USED_PERS:
289 289
        case Image::LOCKED:
290
            ostringstream oss;
291

  
292
            oss << "Releasing image in wrong state: "
293
                << Image::state_to_str(img->get_state());
294

  
295
            NebulaLog::log("ImM", Log::ERROR, oss.str());
290
            NebulaLog::log("ImM", Log::ERROR, "Release cloning image"
291
                " in wrong state");
296 292
            break;
297 293
    }
298 294

  
......
564 560
/* -------------------------------------------------------------------------- */
565 561
/* -------------------------------------------------------------------------- */
566 562

  
567
int ImageManager::can_clone_image(  int             cloning_id,
568
                                    ostringstream&  oss_error)
563
int ImageManager::can_clone_image(int cloning_id, ostringstream&  oss_error)
569 564
{
570 565
    Image *       img;
571 566

  
......
607 602
/* -------------------------------------------------------------------------- */
608 603
/* -------------------------------------------------------------------------- */
609 604

  
610
int ImageManager::clone_image(int   new_id,
611
                              int   cloning_id,
612
                              const string& ds_data,
613
                              string& error)
605
int ImageManager::set_clone_state(int new_id, int cloning_id, std::string& error)
614 606
{
615
    const ImageManagerDriver* imd = get();
616

  
617
    ostringstream oss;
618
    Image *       img;
619

  
620
    string  path;
621
    string  img_tmpl;
622
    string* drv_msg;
623

  
624
    if ( imd == 0 )
625
    {
626
        error = "Could not get datastore driver";
627

  
628
        NebulaLog::log("ImM", Log::ERROR, error);
629
        return -1;
630
    }
631

  
632
    img = ipool->get(cloning_id, true);
607
    int     rc  = 0;
608
    Image * img = ipool->get(cloning_id, true);
633 609

  
634 610
    if (img == 0)
635 611
    {
......
652 628
            }
653 629

  
654 630
            ipool->update(img);
655

  
656
            img->unlock();
657
        break;
631
            break;
658 632

  
659 633
        case Image::USED:
660 634
        case Image::CLONE:
661 635
            img->inc_cloning(new_id);
662

  
663 636
            ipool->update(img);
664

  
665
            img->unlock();
666
        break;
637
            break;
667 638

  
668 639
        case Image::USED_PERS:
669 640
        case Image::INIT:
......
671 642
        case Image::ERROR:
672 643
        case Image::DELETE:
673 644
        case Image::LOCKED:
674
            oss << "Cannot clone image in state: "
675
                << Image::state_to_str(img->get_state());
645
            error = "Cannot clone image in current state";
646
            rc    = -1;
647
            break;
648
    }
676 649

  
677
            error = oss.str();
678
            img->unlock();
679
            return -1;
680
        break;
650
    img->unlock();
651

  
652
    return rc;
653
}
654

  
655
/* -------------------------------------------------------------------------- */
656
/* -------------------------------------------------------------------------- */
657

  
658
int ImageManager::clone_image(int   new_id,
659
                              int   cloning_id,
660
                              const string& ds_data,
661
                              string& error)
662
{
663
    const ImageManagerDriver* imd = get();
664

  
665
    ostringstream oss;
666
    Image *       img;
667

  
668
    string  path;
669
    string  img_tmpl;
670
    string* drv_msg;
671

  
672
    if ( imd == 0 )
673
    {
674
        error = "Could not get datastore driver";
675

  
676
        NebulaLog::log("ImM", Log::ERROR, error);
677
        return -1;
678
    }
679

  
680
    if ( set_clone_state(new_id, cloning_id, error) == -1 )
681
    {
682
        return -1;
681 683
    }
682 684

  
683 685
    img = ipool->get(new_id,true);
684 686

  
685
    if (img == 0) //TODO: Rollback cloning counter
687
    if (img == 0)
686 688
    {
689
        release_cloning_image(cloning_id, new_id);
690

  
687 691
        error = "Target image deleted during cloning operation";
688 692
        return -1;
689 693
    }

Also available in: Unified diff