[Libvir] Problem in Migrating domain....

manon.mani at wipro.com manon.mani at wipro.com
Thu Apr 3 11:14:45 UTC 2008



Hi...

This is my program for Domain Migrating using virDomainMigrate() Function....



#include <stdlib.h>
#include <stdio.h>
#include <libvirt/libvirt.h>

static virConnectPtr conn = NULL; /* the hypervisor connection */

static int
checkDomainState(virDomainPtr dom) 
{
    virDomainInfo info;        /* the information being fetched */
    int ret;

    ret = virDomainGetInfo(dom, &info);
    if (ret < 0) 
    {
	return(-1);
    }
    return(info.state);
}


static void
migrate(int id)
{
  
   virDomainPtr dom = NULL;   /* the domain being checked */
   virDomainPtr dom1= NULL;
    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;
    }

   state = checkDomainState(dom);
    if ((state == VIR_DOMAIN_RUNNING))
        {
              
          dom1=virDomainMigrate(dom,conn,VIR_MIGRATE_LIVE,NULL,NULL,0); 
           if(dom1==NULL)
              {
                 fprintf(stderr,"Failed to migrate");
              }
            else
              {
                 fprintf(stderr,"migrate successfully");
              }
        }
error:
    if (dom != NULL)
        virDomainFree(dom);
}
int main(int argc, char **argv) {
    int id = 0;

    /* NULL means connect to local Xen hypervisor */
    conn = virConnectOpen(NULL);
    if (conn == NULL) {
        fprintf(stderr, "Failed to connect to hypervisor\n");
	goto error;
    }

    if (argc > 1) {
        id = atoi(argv[1]);
    }
    if (id == 0) {
        int i, j, ids[10];
	i = virConnectListDomains(conn, &ids[0], 10);
	if (i < 0) {
	    fprintf(stderr, "Failed to list the domains\n");
	    goto error;
	}
	for (j = 0;j < i;j++) {
	    if (ids[j] != 0) {
	        id = ids[j];
		break;
	    }
	}
    }
    if (id == 0) {
	fprintf(stderr, "Failed find a running guest domain\n");
	goto error;
    }
   migrate(id);

error:
    if (conn != NULL)
	virConnectClose(conn);
    return(0);
}


When I Compile this by the command 

gcc `pkg-config --cflags --libs libvirt` migrate1.c

I got the error...

migrate1.c: In function ‘migrate’:
migrate1.c:67: warning: assignment makes pointer from integer without a cast
/tmp/ccmgmkE1.o: In function `migrate':
migrate1.c:(.text+0xd4): undefined reference to `virDomainMigrate'
collect2: ld returned 1 exit status

Can you help me...

with regard,
Mano
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20080403/2afd9202/attachment-0001.htm>


More information about the libvir-list mailing list