int main(int argc, char **argv) { if(argc < 4) { exit(1); //error } user_id=atoi(argv[1]); clust_id=atoi(argv[2]); node_id=atoi(argv[3]); clusterCfgRead(); //virSetErrorFunc(NULL, customGlobalErrorFunc); virConnectPtr conn; if (virInitialize() < 0) { fprintf(stderr, "Failed to initialize libvirt"); return 12; } //virEventRegisterDefaultImpl(); conn = virConnectOpen("qemu:///system"); //xen+unix:/// if (!conn) { printf("error opening\n"); return 13; } /* coming here we have to restore the snapshot of the vm */ // Build the path to restore the saved snapshot snap$.img [$=node_id] char path[512]; memset(path,0,512); sprintf(path,"%s/%d/%d/snap%d.img",clusterHomeDir,user_id,clust_id,node_id); if( virDomainRestore(conn,path)!=0) { exit(21); } /*---------------------------------------------------------- */ if (conn && virConnectClose(conn) < 0){ printf("error closing\n"); return 16; } return 0; }
bool VirshType::Resume() { vmprintf(D_FULLDEBUG, "Inside VirshType::Resume\n"); if((m_configfile.Length() == 0)) { m_result_msg = VMGAHP_ERR_INTERNAL; return false; } // If a VM is soft suspended, resume it first. ResumeFromSoftSuspend(); if( getVMStatus() == VM_RUNNING ) { return true; } if( !m_restart_with_ckpt && ( getVMStatus() != VM_SUSPENDED) ) { m_result_msg = VMGAHP_ERR_VM_INVALID_OPERATION; return false; } m_restart_with_ckpt = false; m_is_checkpointed = false; if( check_vm_read_access_file(m_suspendfile.Value(), true) == false ) { m_result_msg = VMGAHP_ERR_VM_INVALID_SUSPEND_FILE; return false; } priv_state priv = set_root_priv(); int result = virDomainRestore(m_libvirt_connection, m_suspendfile.Value()); set_priv(priv); if( result != 0 ) { // Read error output // char *temp = cmd_out.print_to_delimed_string("/"); // m_result_msg = temp; // free( temp ); return false; } setVMStatus(VM_RUNNING); m_cpu_time = 0; // Delete suspend file unlink(m_suspendfile.Value()); m_suspendfile = ""; return true; }