Hi everyone,
I want to use grant table to transfer data by shared memory, and now want
to only share only one page. I try to learn how to use it by checking
aseemsethi''s
instruction<http://aseemsethi.wordpress.com/article/learning-grant-tables-29fizhrip655z-5/>and
gntdev.c. Although the sender seems OK, the reciever cannot map memory
by gref, and the ops.status always returns -1, meaning undefined error.
I‘m totally confused about this. I guess it might due to memory-allocating,
but perhaps not. Could someone give some hints to me? Thanks!
Here is part of my code.
In the sender:
static int server_alloc_one_page_to_grant(unsigned long* mypage,domid_t
rdom){
unsigned long addr=0;
gref=-1; //gref is globle
addr=get_zeroed_page(GFP_KERNEL);
if(addr==0){
printk("cannot alloc page\n");
}
sprintf((char*)addr,"%s\naaa\n","This is in
sender.");
gref=gnttab_grant_foreign_access(rdom,virt_to_mfn(addr),1);
if(gref<0){
free_page(addr);
}
printk("gref:%d\n",gref);
return gref;
}
and it seems works well.
But in reciver:
static int client_map_page(domid_t rdom,grant_ref_t ref,struct vm_struct**
pvm){
struct vm_struct *v_start;
struct gnttab_map_grant_ref ops;
struct gnttab_unmap_grant_ref unmap_ops;
memset(&ops,0,sizeof(ops));
memset(&ops,0,sizeof(unmap_ops));
v_start=alloc_vm_area(PAGE_SIZE,NULL);
if(v_start==0){
printk("could not allocate page in client.\n");
return -1;
}
/***************************things goes wrong
************************************************/
gnttab_set_map_op(&ops,(unsigned
long)v_start->addr,GNTMAP_host_map,ref,rdom);
if(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref,&ops,1)){
free_vm_area(v_start);
printk("\nHYPERVISOR map grant ref failed\n");
return -1;
}
//ops,status always equals to -1, and map failed
if(ops.status){
printk("xen:HYPERVISOR map grant ref failed
status=%d",ops.status);
free_vm_area(v_start);
return -1;
}
/*access memory by v_start->addr and unmap memory*/
...
}
_______________________________________________
Xen-users mailing list
Xen-users@lists.xen.org
http://lists.xen.org/xen-users