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.
Thanks,
Jacob
------------------------------------------------------------------------
#include <xenctrl.h>
#include <xenguest.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <xs.h>
#include <fcntl.h>
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 <xenctrl.h>
#include <xenguest.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <xs.h>
#include <fcntl.h>
#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;
}