From mboxrd@z Thu Jan 1 00:00:00 1970 From: Anthony Liguori Subject: Re: xenstore documentation Date: Tue, 04 Oct 2005 13:20:32 -0500 Message-ID: <4342C7F0.4030508@us.ibm.com> References: <1128429737.30221.12.camel@localhost.localdomain> <1128430090.30221.16.camel@localhost.localdomain> <1128431831.30221.24.camel@localhost.localdomain> <43429A1C.1090006@us.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Jacob Gorm Hansen Cc: harry , xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org Jacob Gorm Hansen wrote: >hi Anthony, others > >I have converted your pseudocode to C, but I am still not able to >connect the device. I hope it's OK that I attach my code that I have >trouble getting working, if anyone could try to run it or comment if >anything obvious looks wrong. > >The two files are businit.c and buscreate.c. The former inits xenstore >and dom0, and the latter creates a domU and attempts to connect hda1. > > I'll run play with it tomorrow. Some people are having problems with block devices timing out. You should verify you can create a domain with a block device with Xend to determine if it's your platform. Regards, Anthony Liguori >Thanks, >Jacob > > >------------------------------------------------------------------------ > >#include >#include > >#include >#include >#include >#include > >#include >#include > > >int main(int argc,char** argv) >{ > int xc = xc_interface_open(); > struct xs_handle *xs = xs_daemon_open(); > char home[] = "/local/domain/0"; > > int lstore = 0; > int rstore = 0; > > xc_evtchn_bind_interdomain(xc, 0, 0, &lstore, &rstore); > unsigned long mfn_store = xc_init_store(xc, rstore); > xs_mkdir(xs,home); > xs_introduce_domain(xs, 0, mfn_store, lstore, home); > > return 0; > >} > > > >------------------------------------------------------------------------ > >#include >#include > >#include >#include >#include >#include > >#include >#include > > >#define xs_write(a,b,c,d) printf("write %s <- %s : %d\n", b,c,xs_write(a,b,c,d)); >#define xs_transaction_end(a,b) printf("end : %d\n", xs_transaction_end(a,b)); >int main(int argc,char** argv) >{ > int xc = xc_interface_open(); > struct xs_handle *xs = xs_daemon_open(); > > char kernel[] = "/vmlinux"; > char ramdisk[] = "/domUinitrd"; > char cmdline[] = "init=/linuxrc root=/dev/ram"; > char pdev[] = "0x301"; > char vdev[] = "0x301"; > int vcpus = 1; > char home[256]; > > unsigned long memory = 64*1024*1024; > > int domid = 0; > xc_domain_create(xc, ACM_DEFAULT_SSID, &domid); > xc_domain_setmaxmem(xc,domid, memory >> 10); > xc_domain_memory_increase_reservation(xc,domid, memory >> 12, 0,0,0); > > // 2) Build domain > int lconsole = 0; > int rconsole = 0; > int lstore = 0; > int rstore = 0; > unsigned long mfn_store, mfn_console; > > xc_evtchn_bind_interdomain(xc, 0, domid, &lconsole, &rconsole); > xc_evtchn_bind_interdomain(xc, DOMID_SELF, domid, &lstore, &rstore); > > xc_linux_build(xc, domid, kernel, ramdisk, cmdline, 0, vcpus, > rstore, &mfn_store, rconsole, &mfn_console); > > sprintf(home,"/local/domain/%d",domid); > xs_introduce_domain(xs, domid, mfn_store, lstore, home); > > char s[256]; > char s2[256]; > > sprintf(s,"%s/console/ring-ref",home); > sprintf(s2,"%lu",mfn_console); > xs_write(xs, s, s2, strlen(s2)); > > sprintf(s,"%s/console/port",home); > sprintf(s2,"%d",lconsole); > xs_write(xs, s, s2, strlen(s2)); > > // 3) Create block device (pdev, vdev); > int uuid = 1000 + domid; > > char* dom0_home = xs_get_domain_path(xs,0); > printf("dom0_home is %s\n",dom0_home); > > char backend[256]; > char frontend[256]; > sprintf(backend,"%s/backend/vbd/%d/%d",dom0_home,uuid,domid); > sprintf(frontend, "%s/device/vbd/%d",home,uuid); > > > xs_transaction_start(xs); > sprintf(s,"%s/frontend",backend); > xs_write(xs, s, frontend, strlen(frontend)); > > sprintf(s,"%s/frontend-id",backend); > sprintf(s2,"%d",domid); > xs_write(xs, s, s2, strlen(s2)); > xs_transaction_end(xs,0); > > > xs_transaction_start(xs); > sprintf(s,"%s/backend",frontend); > xs_write(xs, s, backend, strlen(backend)); > > sprintf(s, "%s/backend-id", frontend); > xs_write(xs, s, "0",1); > > sprintf(s, "%s/virtual-device", frontend); > xs_write(xs, s, vdev, strlen(vdev)); > xs_transaction_end(xs,0); > > > > sprintf(s, "%s/physical-device",backend); > xs_write(xs, s, pdev, strlen(pdev)); > > xc_domain_unpause(xc,domid); > > return 0; >} > >