static int suspend_and_resume(virConnectPtr conn, const char *dom_name, unsigned int seconds) { int ret = -1; virDomainPtr dom; virDomainInfo dom_info; if (!(dom = virDomainLookupByName(conn, dom_name))) { ERROR("Unable to find domain '%s'", dom_name); goto cleanup; } if (virDomainGetInfo(dom, &dom_info) < 0) { ERROR("Unable to get domain info"); goto cleanup; } DEBUG("Domain state %d", dom_info.state); switch (dom_info.state) { case VIR_DOMAIN_NOSTATE: case VIR_DOMAIN_RUNNING: case VIR_DOMAIN_BLOCKED: /* In these states the domain can be suspended */ DEBUG("Suspending domain"); if (virDomainSuspend(dom) < 0) { ERROR("Unable to suspend domain"); goto cleanup; } DEBUG("Domain suspended. Entering sleep for %u seconds.", seconds); sleep(seconds); DEBUG("Sleeping done. Resuming the domain."); if (virDomainResume(dom) < 0) { ERROR("Unable to resume domain"); goto cleanup; } break; default: /* In all other states domain can't be suspended */ ERROR("Domain is not in a state where it can be suspended: %d", dom_info.state); goto cleanup; } ret = 0; cleanup: if (dom) virDomainFree(dom); return ret; }
/** * SuspendAndResumeDomain: * @id: the id of the domain * * extract the domain 0 information */ static void SuspendAndResumeDomain(int id) { virDomainPtr dom = NULL; /* the domain being checked */ int ret, state; /* Find the domain of the given id */ dom = virDomainLookupByID(conn, id); if (dom == NULL) { fprintf(stderr, "Failed to find Domain %d\n", id); goto error; } /* Check state */ state = checkDomainState(dom); if ((state == VIR_DOMAIN_RUNNING) || (state == VIR_DOMAIN_NOSTATE) || (state == VIR_DOMAIN_BLOCKED)) { printf("Suspending domain...\n"); ret = virDomainSuspend(dom); if (ret < 0) { fprintf(stderr, "Failed to suspend Domain %d\n", id); goto error; } state = checkDomainState(dom); if (state != VIR_DOMAIN_PAUSED) { fprintf(stderr, "Domain %d state is not suspended\n", id); } else { printf("Domain suspended, resuming it...\n"); } ret = virDomainResume(dom); if (ret < 0) { fprintf(stderr, "Failed to resume Domain %d\n", id); goto error; } state = checkDomainState(dom); if ((state == VIR_DOMAIN_RUNNING) || (state == VIR_DOMAIN_NOSTATE) || (state == VIR_DOMAIN_BLOCKED)) { printf("Domain resumed\n"); } else { fprintf(stderr, "Domain %d state indicate it is not resumed\n", id); } } else { fprintf(stderr, "Domain %d is not in a state where it should be suspended\n", id); goto error; } error: if (dom != NULL) virDomainFree(dom); }
bool VirshType::SoftSuspend() { vmprintf(D_FULLDEBUG, "Inside VirshType::SoftSuspend\n"); if( (m_configfile.Length() == 0)) { m_result_msg = VMGAHP_ERR_INTERNAL; return false; } if( m_is_soft_suspended ) { return true; } if( getVMStatus() != VM_RUNNING ) { m_result_msg = VMGAHP_ERR_VM_INVALID_OPERATION; return false; } priv_state priv = set_root_priv(); virDomainPtr dom = virDomainLookupByName(m_libvirt_connection, m_vm_name.Value()); set_priv(priv); if(dom == NULL) { virErrorPtr err = virConnGetLastError(m_libvirt_connection); vmprintf(D_ALWAYS, "Error finding domain %s: %s\n", m_vm_name.Value(), (err ? err->message : "No reason found")); return false; } int result = virDomainSuspend(dom); virDomainFree(dom); if( result == 0 ) { // pause succeeds. m_is_soft_suspended = true; return true; } // Failed to suspend a VM softly. // Instead of soft suspend, we use hard suspend. vmprintf(D_ALWAYS, "SoftSuspend failed, so try hard Suspend instead!.\n"); return Suspend(); }
void stop_all_vm() { int state, reason, count, i; // suspend all the VM-es (except for Domain-0) for (i = 1; i < numDomains; i++) virDomainSuspend(activeDomains[i]); // capture the time after suspend action clock_gettime(CLOCK_MONOTONIC, &tp_end); // this function will looped until all machines are paused. while (1) { count = 0; for (i = 1; i < numDomains; i++) { // check if the state is PAUSED virDomainGetState(activeDomains[i], &state, &reason, 0); if (state == VIR_DOMAIN_PAUSED) count++; } // break when all the machines are paused if (count == numDomains - 1) break; } }
static PromiseResult DownVirt(EvalContext *ctx, virConnectPtr vc, Attributes a, const Promise *pp) { virDomainPtr dom; virDomainInfo info; dom = virDomainLookupByName(vc, pp->promiser); PromiseResult result = PROMISE_RESULT_NOOP; if (dom) { if (virDomainGetInfo(dom, &info) == -1) { cfPS(ctx, LOG_LEVEL_ERR, PROMISE_RESULT_FAIL, pp, a, "Unable to probe virtual domain '%s'", pp->promiser); result = PromiseResultUpdate(result, PROMISE_RESULT_FAIL); virDomainFree(dom); return result; } switch (info.state) { case VIR_DOMAIN_BLOCKED: case VIR_DOMAIN_RUNNING: if (virDomainShutdown(dom) == -1) { cfPS(ctx, LOG_LEVEL_VERBOSE, PROMISE_RESULT_INTERRUPTED, pp, a, "Virtual domain '%s' failed to shutdown", pp->promiser); result = PromiseResultUpdate(result, PROMISE_RESULT_INTERRUPTED); virDomainFree(dom); return result; } cfPS(ctx, LOG_LEVEL_VERBOSE, PROMISE_RESULT_CHANGE, pp, a, "Virtual domain '%s' running, terminating", pp->promiser); result = PromiseResultUpdate(result, PROMISE_RESULT_CHANGE); break; case VIR_DOMAIN_SHUTOFF: case VIR_DOMAIN_SHUTDOWN: cfPS(ctx, LOG_LEVEL_VERBOSE, PROMISE_RESULT_NOOP, pp, a, "Virtual domain '%s' is down - promise kept", pp->promiser); break; case VIR_DOMAIN_PAUSED: cfPS(ctx, LOG_LEVEL_VERBOSE, PROMISE_RESULT_INTERRUPTED, pp, a, "Virtual domain '%s' is suspended - ignoring promise", pp->promiser); result = PromiseResultUpdate(result, PROMISE_RESULT_INTERRUPTED); break; case VIR_DOMAIN_CRASHED: if (virDomainSuspend(dom) == -1) { cfPS(ctx, LOG_LEVEL_VERBOSE, PROMISE_RESULT_INTERRUPTED, pp, a, "Virtual domain '%s' is crashed and failed to shutdown", pp->promiser); result = PromiseResultUpdate(result, PROMISE_RESULT_INTERRUPTED); virDomainFree(dom); return false; } cfPS(ctx, LOG_LEVEL_VERBOSE, PROMISE_RESULT_CHANGE, pp, a, "Virtual domain '%s' is in a crashed state, terminating", pp->promiser); result = PromiseResultUpdate(result, PROMISE_RESULT_CHANGE); break; default: Log(LOG_LEVEL_VERBOSE, "Virtual domain '%s' is reported as having no state, whatever that means", pp->promiser); break; } virDomainFree(dom); } else { cfPS(ctx, LOG_LEVEL_VERBOSE, PROMISE_RESULT_NOOP, pp, a, "Virtual domain '%s' cannot be found - take promise as kept", pp->promiser); } return result; }
static PromiseResult SuspendedVirt(EvalContext *ctx, virConnectPtr vc, Attributes a, const Promise *pp) { virDomainPtr dom; virDomainInfo info; dom = virDomainLookupByName(vc, pp->promiser); PromiseResult result = PROMISE_RESULT_NOOP; if (dom) { if (virDomainGetInfo(dom, &info) == -1) { cfPS(ctx, LOG_LEVEL_ERR, PROMISE_RESULT_FAIL, pp, a, "Unable to probe virtual domain '%s'", pp->promiser); result = PromiseResultUpdate(result, PROMISE_RESULT_FAIL); virDomainFree(dom); return result; } switch (info.state) { case VIR_DOMAIN_BLOCKED: case VIR_DOMAIN_RUNNING: if (virDomainSuspend(dom) == -1) { cfPS(ctx, LOG_LEVEL_VERBOSE, PROMISE_RESULT_INTERRUPTED, pp, a, "Virtual domain '%s' failed to suspend", pp->promiser); result = PromiseResultUpdate(result, PROMISE_RESULT_INTERRUPTED); virDomainFree(dom); return result; } cfPS(ctx, LOG_LEVEL_VERBOSE, PROMISE_RESULT_CHANGE, pp, a, "Virtual domain '%s' running, suspending", pp->promiser); result = PromiseResultUpdate(result, PROMISE_RESULT_CHANGE); break; case VIR_DOMAIN_SHUTDOWN: cfPS(ctx, LOG_LEVEL_VERBOSE, PROMISE_RESULT_INTERRUPTED, pp, a, "Virtual domain '%s' is shutting down", pp->promiser); result = PromiseResultUpdate(result, PROMISE_RESULT_INTERRUPTED); Log(LOG_LEVEL_VERBOSE, "It is currently impossible to know whether it will reboot or not - deferring promise check until it has completed its shutdown"); break; case VIR_DOMAIN_PAUSED: cfPS(ctx, LOG_LEVEL_VERBOSE, PROMISE_RESULT_NOOP, pp, a, "Virtual domain '%s' is suspended - promise kept", pp->promiser); break; case VIR_DOMAIN_SHUTOFF: cfPS(ctx, LOG_LEVEL_VERBOSE, PROMISE_RESULT_NOOP, pp, a, "Virtual domain '%s' is down - promise kept", pp->promiser); break; case VIR_DOMAIN_CRASHED: if (virDomainSuspend(dom) == -1) { cfPS(ctx, LOG_LEVEL_VERBOSE, PROMISE_RESULT_INTERRUPTED, pp, a, "Virtual domain '%s' is crashed has failed to suspend", pp->promiser); result = PromiseResultUpdate(result, PROMISE_RESULT_INTERRUPTED); virDomainFree(dom); return result; } cfPS(ctx, LOG_LEVEL_VERBOSE, PROMISE_RESULT_CHANGE, pp, a, "Virtual domain '%s' is in a crashed state, suspending", pp->promiser); result = PromiseResultUpdate(result, PROMISE_RESULT_CHANGE); break; default: Log(LOG_LEVEL_VERBOSE, "Virtual domain '%s' is reported as having no state, whatever that means", pp->promiser); break; } virDomainFree(dom); } else { cfPS(ctx, LOG_LEVEL_VERBOSE, PROMISE_RESULT_NOOP, pp, a, "Virtual domain '%s' cannot be found - take promise as kept", pp->promiser); } return result; }
int main(int argc, char *argv[]) { virConnectPtr conn; virDomainPtr vdp; int i=-1,ch; char *host; conn = virConnectOpen("xen:///"); if (conn == NULL) { fprintf(stderr, "Failed to open connection to xen:///\n"); return 1; } //host = virConnectGetHostname(conn); vdp=virDomainLookupByName(conn,"ubuntu_connection"); printf("\nMenu\n----\n1.Connect\n2.Suspend\n3.Resume\n 4.Shutdown\n"); printf("Enter your choice:\n"); scanf("%d",&ch); switch(ch) { case 1: i=virDomainCreate(vdp); if(i==0) { printf("Success\n"); }else{ printf("Failed\n"); } break; case 2: /* suspend*/ i=virDomainSuspend(vdp); if(i==0) { printf("Success\n"); }else{ printf("Failed\n"); } break; case 3: /*resume*/ i=virDomainResume(vdp); if(i==0) { printf("Success\n"); }else{ printf("Failed\n"); } break; case 4: /*shutdown*/ i=virDomainDestroy(vdp); if(i==0) { printf("Success\n"); }else{ printf("Failed\n"); } break; default: printf("INVALID"); virConnectClose(conn); return 0; } }
static int DownVirt(virConnectPtr vc, char *uri, Attributes a, Promise *pp) { virDomainPtr dom; virDomainInfo info; dom = virDomainLookupByName(vc, pp->promiser); if (dom) { if (virDomainGetInfo(dom, &info) == -1) { cfPS(cf_inform, CF_FAIL, "", pp, a, " !! Unable to probe virtual domain \"%s\"", pp->promiser); virDomainFree(dom); return false; } switch (info.state) { case VIR_DOMAIN_BLOCKED: case VIR_DOMAIN_RUNNING: if (virDomainShutdown(dom) == -1) { cfPS(cf_verbose, CF_INTERPT, "", pp, a, " -> Virtual domain \"%s\" failed to shutdown!\n", pp->promiser); virDomainFree(dom); return false; } cfPS(cf_verbose, CF_CHG, "", pp, a, " -> Virtual domain \"%s\" running, terminating\n", pp->promiser); break; case VIR_DOMAIN_SHUTOFF: case VIR_DOMAIN_SHUTDOWN: cfPS(cf_verbose, CF_NOP, "", pp, a, " -> Virtual domain \"%s\" is down - promise kept\n", pp->promiser); break; case VIR_DOMAIN_PAUSED: cfPS(cf_verbose, CF_INTERPT, "", pp, a, " -> Virtual domain \"%s\" is suspended - ignoring promise\n", pp->promiser); break; case VIR_DOMAIN_CRASHED: if (virDomainSuspend(dom) == -1) { cfPS(cf_verbose, CF_INTERPT, "", pp, a, " -> Virtual domain \"%s\" is crashed and failed to shutdown\n", pp->promiser); virDomainFree(dom); return false; } cfPS(cf_verbose, CF_CHG, "", pp, a, " -> Virtual domain \"%s\" is in a crashed state, terminating\n", pp->promiser); break; default: CfOut(cf_verbose, "", " !! Virtual domain \"%s\" is reported as having no state, whatever that means", pp->promiser); break; } virDomainFree(dom); } else { cfPS(cf_verbose, CF_NOP, "", pp, a, " -> Virtual domain \"%s\" cannot be found - take promise as kept\n", pp->promiser); } return true; }
static int SuspendedVirt(virConnectPtr vc, char *uri, Attributes a, Promise *pp) { virDomainPtr dom; virDomainInfo info; dom = virDomainLookupByName(vc, pp->promiser); if (dom) { if (virDomainGetInfo(dom, &info) == -1) { cfPS(cf_inform, CF_FAIL, "", pp, a, " !! Unable to probe virtual domain \"%s\"", pp->promiser); virDomainFree(dom); return false; } switch (info.state) { case VIR_DOMAIN_BLOCKED: case VIR_DOMAIN_RUNNING: if (virDomainSuspend(dom) == -1) { cfPS(cf_verbose, CF_INTERPT, "", pp, a, " -> Virtual domain \"%s\" failed to suspend!\n", pp->promiser); virDomainFree(dom); return false; } cfPS(cf_verbose, CF_CHG, "", pp, a, " -> Virtual domain \"%s\" running, suspending\n", pp->promiser); break; case VIR_DOMAIN_SHUTDOWN: cfPS(cf_verbose, CF_INTERPT, "", pp, a, " -> Virtual domain \"%s\" is shutting down\n", pp->promiser); CfOut(cf_verbose, "", " -> It is currently impossible to know whether it will reboot or not - deferring promise check until it has completed its shutdown"); break; case VIR_DOMAIN_PAUSED: cfPS(cf_verbose, CF_NOP, "", pp, a, " -> Virtual domain \"%s\" is suspended - promise kept\n", pp->promiser); break; case VIR_DOMAIN_SHUTOFF: cfPS(cf_verbose, CF_NOP, "", pp, a, " -> Virtual domain \"%s\" is down - promise kept\n", pp->promiser); break; case VIR_DOMAIN_CRASHED: if (virDomainSuspend(dom) == -1) { cfPS(cf_verbose, CF_INTERPT, "", pp, a, " -> Virtual domain \"%s\" is crashed has failed to suspend!\n", pp->promiser); virDomainFree(dom); return false; } cfPS(cf_verbose, CF_CHG, "", pp, a, " -> Virtual domain \"%s\" is in a crashed state, suspending\n", pp->promiser); break; default: CfOut(cf_verbose, "", " !! Virtual domain \"%s\" is reported as having no state, whatever that means", pp->promiser); break; } virDomainFree(dom); } else { cfPS(cf_verbose, CF_NOP, "", pp, a, " -> Virtual domain \"%s\" cannot be found - take promise as kept\n", pp->promiser); } return true; }
static int DownVirt(EvalContext *ctx, virConnectPtr vc, Attributes a, Promise *pp) { virDomainPtr dom; virDomainInfo info; dom = virDomainLookupByName(vc, pp->promiser); if (dom) { if (virDomainGetInfo(dom, &info) == -1) { cfPS(ctx, OUTPUT_LEVEL_INFORM, PROMISE_RESULT_FAIL, "", pp, a, " !! Unable to probe virtual domain \"%s\"", pp->promiser); virDomainFree(dom); return false; } switch (info.state) { case VIR_DOMAIN_BLOCKED: case VIR_DOMAIN_RUNNING: if (virDomainShutdown(dom) == -1) { cfPS(ctx, OUTPUT_LEVEL_VERBOSE, PROMISE_RESULT_INTERRUPTED, "", pp, a, " -> Virtual domain \"%s\" failed to shutdown!\n", pp->promiser); virDomainFree(dom); return false; } cfPS(ctx, OUTPUT_LEVEL_VERBOSE, PROMISE_RESULT_CHANGE, "", pp, a, " -> Virtual domain \"%s\" running, terminating\n", pp->promiser); break; case VIR_DOMAIN_SHUTOFF: case VIR_DOMAIN_SHUTDOWN: cfPS(ctx, OUTPUT_LEVEL_VERBOSE, PROMISE_RESULT_NOOP, "", pp, a, " -> Virtual domain \"%s\" is down - promise kept\n", pp->promiser); break; case VIR_DOMAIN_PAUSED: cfPS(ctx, OUTPUT_LEVEL_VERBOSE, PROMISE_RESULT_INTERRUPTED, "", pp, a, " -> Virtual domain \"%s\" is suspended - ignoring promise\n", pp->promiser); break; case VIR_DOMAIN_CRASHED: if (virDomainSuspend(dom) == -1) { cfPS(ctx, OUTPUT_LEVEL_VERBOSE, PROMISE_RESULT_INTERRUPTED, "", pp, a, " -> Virtual domain \"%s\" is crashed and failed to shutdown\n", pp->promiser); virDomainFree(dom); return false; } cfPS(ctx, OUTPUT_LEVEL_VERBOSE, PROMISE_RESULT_CHANGE, "", pp, a, " -> Virtual domain \"%s\" is in a crashed state, terminating\n", pp->promiser); break; default: CfOut(OUTPUT_LEVEL_VERBOSE, "", " !! Virtual domain \"%s\" is reported as having no state, whatever that means", pp->promiser); break; } virDomainFree(dom); } else { cfPS(ctx, OUTPUT_LEVEL_VERBOSE, PROMISE_RESULT_NOOP, "", pp, a, " -> Virtual domain \"%s\" cannot be found - take promise as kept\n", pp->promiser); } return true; }
void main() { virConnectPtr connection; virDomainPtr vdp_id, vdp_name; int i,ret_val=-1; int ch,ch_id,domainnum; int *domains; char name[25]; const char *active_name; connection = virConnectOpen("xen:///"); if (connection == NULL) { fprintf(stderr, "Error opening connection to XEN:/// \n"); exit(1); } else { domainnum=virConnectNumOfDomains(connection); domains=malloc(sizeof(int) * domainnum); domainnum = virConnectListDomains(connection, domains, domainnum); printf("\t\t ----Active Domains---- \n"); for (i = 0 ; i < domainnum ; i++) { vdp_id=virDomainLookupByID(connection,i); active_name=virDomainGetName(vdp_id); printf(" \t\t%s \n", active_name); } free(domains); while(1) { printf("1.Start\n2.Suspend\n3.Resume\n4.stop\n5.exit\n "); printf("Enter Your Choice : "); scanf("%d",&ch); if(ch != 5) { printf("\n Please Insert the Active Domian Name: "); scanf("%s",name); vdp_name = virDomainLookupByName(connection,name); } switch(ch) { case 1: ret_val=virDomainCreate(vdp_name); if(ret_val==0) printf("Domain %s started\n", name); else printf("Start Operation Failed\n"); break; case 2: ret_val=virDomainSuspend(vdp_name); if(ret_val==0) printf("Domain %s Suspended\n", name); else printf("Suspend Operation Failed\n"); break; case 3: ret_val=virDomainResume(vdp_name); if(ret_val==0) printf("Domain %s Resumed\n", name); else printf("Resume Operation Failed\n"); break; case 4: ret_val=virDomainShutdown(vdp_name); if(ret_val==0) printf("Domain %s Stopped\n", name); else printf("Stop Operation Failed\n"); break; case 5: exit(1); default: exit(1); } } virConnectClose(connection); } }
void main() { int i,val=-1,ch,no_domains; char name[50]; int *act_domains; virConnectPtr con_ptr; virDomainPtr dom_ptr; con_ptr = virConnectOpen("xen:///"); if (con_ptr == NULL) { fprintf(stderr, "Error opening connection to XEN:/// \n"); return 1; } else { no_domains=virConnectNumOfDomains(con_ptr); act_domains=malloc(sizeof(int) * no_domains); no_domains = virConnectListDomains(con_ptr, act_domains, no_domains); free(act_domains); while(1) { printf("1.Start\n2.Suspend\n3.Resume\n4.Shutdown\n5.exit "); scanf("%d",&ch); printf("\n Enter Active Domian name "); scanf("%s",&name); dom_ptr=virDomainLookupByName(con_ptr,name); switch(ch) { case 1: val=virDomainCreate(dom_ptr); if(val==0) printf("Success"); else printf("Failed"); break; case 2: val=virDomainSuspend(dom_ptr); if(val==0) printf("Success"); else printf("Failed"); break; case 3: val=virDomainResume(dom_ptr); if(val==0) printf("Success"); else printf("Failed"); break; case 4: val=virDomainShutdown(dom_ptr); if(val==0) printf("Success"); else printf("Failed"); break; default:exit(1); } } virConnectClose(con_ptr); } }
/** * @brief pauses the domain * @return if the domain was paused without error, otherwise false */ bool Domain::pause() { // TODO(txwikinger): check if it can be paused return (virDomainSuspend(m_domain) == 0); }
int main(int argc, char *argv[]) { virConnectPtr conn; virDomainPtr vdp; int val=-1; int choice; char *host; conn = virConnectOpen("xen:///"); if (conn == NULL) { fprintf(stderr, "Failed to open connection to xen:///\n"); return 1; } printf("1.Suspend\n2.Resume\n3.Stop\n4.Start\n4.Exit"); scanf("%d",&choice); while(1) { vdp=virDomainLookupById(conn,1); if(choice==1) { /* suspend*/ val=virDomainSuspend(vdp); if(val==0) { printf("Success"); }else{ printf("Failed"); } } else if(choice==2) { /*resume*/ val=virDomainResume(vdp); if(val==0) { printf("Success"); }else{ printf("Failed"); } } else if(choice==3) { /*shutdown*/ val=virDomainDestroy(vdp); if(val==0) { printf("Success"); }else{ printf("Failed"); } } else if(choice==4) { /*start*/ val=virDomainCreate(vdp); if(val==0) { printf("Success"); }else{ printf("Failed"); } } else if(choice==5) { virConnectClose(conn); break; } } return 0; }
void main() { int i,val=-1,choice,choice_id,num_domains; int *active_domains; virConnectPtr conn; virDomainPtr vdp; conn = virConnectOpen("xen:///"); if (conn == NULL) { fprintf(stderr, "Error opening connection to XEN:/// \n"); return 1; } else { //For finding Active Devices num_domains=virConnectNumOfDomains(conn); active_domanins=malloc(sizeof(int) * num_domains); num_domains = virConnectListDomains(conn, active_domains, num_domains); printf("Active domain IDs : \n"); for (i = 0 ; i < num_domains ; i++) { printf(" %d\n", active_domains[i]); } free(active_domains); while(1) { printf("1.Start\n2.Suspend\n3.Resume\n4.stop\n5.exit "); scanf("%d",&choice); printf("\n Please Insert the Active Domian ID "); scanf("%d",&choice_id); vdp=virDomainLookupById(conn,choice_id); switch(choice) { case 1:/* Start */ val=virDomainCreate(vdp); if(val==0) printf("Success"); else printf("Failed"); break; case 2:/* Suspend */ val=virDomainSuspend(vdp); if(val==0) printf("Success"); else printf("Failed"); break; case 3:/* Resume */ val=virDomainResume(vdp); if(val==0) printf("Success"); else printf("Failed"); break; case 4: /* stop */ val=virDomainStop(vdp); if(val==0) printf("Success"); else printf("Failed"); break; default:exit(1); } } virConnectClose(conn); } }