* Re: Unable to bring up Mini-OS on x86_64
2006-05-17 0:46 Puthiyaparambil, Aravindh
@ 2006-05-17 11:48 ` Jacob Gorm Hansen
0 siblings, 0 replies; 8+ messages in thread
From: Jacob Gorm Hansen @ 2006-05-17 11:48 UTC (permalink / raw)
To: Puthiyaparambil, Aravindh; +Cc: xen-devel
[-- Attachment #1: Type: text/plain, Size: 1063 bytes --]
On 5/17/06, Puthiyaparambil, Aravindh <aravindh.puthiyaparambil@unisys.com>
> I did a fresh clone and a build and I am still running into the same
> issue. So it looks like there is a bug in xc_linux_build() and/or
> Mini-OS.
>
> What is the best way to debug libxc? I usually do fprintf(stderr,...)
> and the output shows up in xend-debug.log. But it is very flaky as
> sometimes messages are overwritten. Is there a better way to do prints?
I would recommend writing a small c program that calls libxc directly,
that will save you a bunch of time fighting the python/xend logging.
I have attached a patch with my own hand-rolled tools as an example.
The most interesting one is buscreate, which reads a config-file like:
kernel=/home/jacobg/xen-3.0-testing2.hg/linux-2.6.16-xen/vmlinux
mem=16
maxmem=16
console=1
initrd=/home/jacobg/domUinitrd
cmdline=mem=16M init=/linuxrc root=/dev/ram xencons=ttyS0
vbd=706,301,w
- and creates a domain without needing xend at all. xenstored and
xenconsoled need to be running though.
Jacob
[-- Attachment #2: migrationtools --]
[-- Type: application/octet-stream, Size: 21115 bytes --]
diff -r 0bfe5613711a tools/Makefile
--- a/tools/Makefile Thu May 11 10:43:24 2006 +0200
+++ b/tools/Makefile Tue May 16 10:35:46 2006 +0200
@@ -13,6 +13,7 @@ SUBDIRS += console
SUBDIRS += console
SUBDIRS += xenmon
SUBDIRS += guest-headers
+SUBDIRS += migrate
ifeq ($(VTPM_TOOLS),y)
SUBDIRS += vtpm_manager
SUBDIRS += vtpm
diff -r 0bfe5613711a tools/migrate/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/migrate/Makefile Tue May 16 10:35:46 2006 +0200
@@ -0,0 +1,73 @@
+XEN_ROOT=../..
+include $(XEN_ROOT)/tools/Rules.mk
+XEN_LIBXC = $(XEN_ROOT)/tools/libxc
+
+INSTALL = install
+INSTALL_PROG = $(INSTALL) -m0755
+INSTALL_DATA = $(INSTALL) -m0644
+INSTALL_DIR = $(INSTALL) -d -m0755
+
+MAJOR = 3.0
+MINOR = 0
+
+XEN_ROOT = ../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+BASECFLAGS=-Wall -g -Werror
+# Make gcc generate dependencies.
+BASECFLAGS += -Wp,-MD,.$(@F).d
+PROG_DEP = .*.d
+BASECFLAGS+= $(PROFILE)
+BASECFLAGS+= -I$(XEN_ROOT)/tools/libxc -I$(XEN_ROOT)/tools/xenstore
+BASECFLAGS+= -I.
+CFLAGS += $(BASECFLAGS)
+
+LDFLAGS += $(PROFILE) -L$(XEN_LIBXC)
+
+# Get gcc to generate the dependencies for us.
+CFLAGS += -Wp,-MD,.$(@F).d
+LDFLAGS += -L. -L$(XEN_XC) -L$(XEN_ROOT)/tools/xenstore
+DEPS = .*.d
+
+LDLIBS := -lxenctrl -lxenguest -lxenstore
+
+EXES := pack repair minimig buscreate purgedoms listdoms xdmesg
+
+all: $(EXES)
+
+pack: pack.o
+ $(LINK.o) $^ -o $@
+
+repair: repair.o
+ $(LINK.o) $^ -o $@
+
+buscreate: buscreate.o configfile.o
+ $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -L. -o $@
+
+listdoms: listdoms.o
+ $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -L. -o $@
+
+purgedoms: purgedoms.o
+ $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -L. -o $@
+
+xdmesg: xdmesg.o
+ $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -L. -o $@
+
+minimig: minimig.o
+ $(LINK.o) $^ -static -o $@
+
+install:
+ $(INSTALL_PROG) buscreate $(DESTDIR)/usr/sbin
+ $(INSTALL_PROG) listdoms $(DESTDIR)/usr/sbin
+ $(INSTALL_PROG) purgedoms $(DESTDIR)/usr/sbin
+ $(INSTALL_PROG) repair $(DESTDIR)/usr/sbin
+
+.PHONY: TAGS clean rpm install all
+
+TAGS:
+ etags -t *.c *.h
+
+clean:
+ rm -rf *.a *.so* *.o *.opic *.rpm $(LIB) *~ $(DEPS)
+ rm $(EXES)
+
diff -r 0bfe5613711a tools/migrate/buscreate.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/migrate/buscreate.c Tue May 16 10:35:46 2006 +0200
@@ -0,0 +1,337 @@
+#include <xenctrl.h>
+#include <xenguest.h>
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <xs.h>
+#include <fcntl.h>
+
+#include "configfile.h"
+#include "xenutil.h"
+#include "evtchn.h"
+
+
+int xc;
+struct xs_handle *xs;
+xs_transaction_t t;
+int evtchn_fd;
+
+#define xs_w(a,b) xs_write(xs,t,a,b,strlen(b))
+//#define xs_w(a,b) printf("%s <- %s\n",a,b); xs_write(xs,t,a,b,strlen(b))
+#define xs_begin() t = xs_transaction_start(xs)
+#define xs_end() xs_transaction_end(xs,t,0)
+
+void setup_console(int domid, int rconsole, unsigned long mfn_console)
+{
+ char s[256];
+ char s2[256];
+ char* home = xs_get_domain_path(xs,domid);
+
+ printf("dom %d home %s\n",domid,home);
+
+ xs_begin();
+ sprintf(s,"%s/domid",home);
+ sprintf(s2,"%d",domid);
+ xs_w(s,s2);
+
+ sprintf(s,"%s/console/ring-ref",home);
+ sprintf(s2,"%lu",mfn_console);
+ xs_w(s, s2 );
+
+ sprintf(s,"%s/console/port",home);
+ sprintf(s2,"%d",rconsole);
+ xs_w(s, s2 );
+
+ xs_end();
+
+}
+void setup_vif(int domid, int uuid)
+{
+ char s[256];
+ char s2[256];
+
+ char* home = xs_get_domain_path(xs,domid);
+ char* dom0_home = xs_get_domain_path(xs,0);
+
+ char backend[256];
+ char frontend[256];
+
+ printf("dom0_home is %s\n",dom0_home);
+ sprintf(backend,"%s/backend/vif/%d/%d",dom0_home,uuid,domid);
+ sprintf(frontend, "%s/device/vif/%d",home,uuid);
+
+
+
+ xs_begin();
+
+ sprintf(s,"%s/handle",frontend);
+ sprintf(s2,"%d",uuid);
+ xs_w(s, s2);
+
+ sprintf(s,"%s/mac",frontend);
+ xs_w(s, "aa:00:00:11:a6:02");
+
+ sprintf(s, "%s/backend-id", frontend);
+ xs_w(s, "0");
+
+ sprintf(s,"%s/backend",frontend);
+ xs_w(s, backend );
+
+ xs_end();
+
+ xs_begin();
+
+ sprintf(s,"%s/handle",backend);
+ sprintf(s2,"%d",uuid);
+ xs_w(s, s2);
+
+ sprintf(s,"%s/mac",backend);
+ xs_w(s, "aa:00:00:11:a6:02");
+
+ sprintf(s,"%s/frontend",backend);
+ xs_w(s, frontend );
+
+ sprintf(s,"%s/frontend-id",backend);
+ sprintf(s2,"%d",domid);
+ xs_w(s, s2 );
+
+
+ xs_end();
+
+
+
+}
+
+void setup_vbd(int domid, struct vbd* vbd)
+{
+
+ char s[256];
+ char s2[256];
+ char pdev[8];
+ char vdev[8];
+ char backend[256];
+ char frontend[256];
+ char node[16];
+
+ struct xs_permissions xsperms[2];
+ char* home = xs_get_domain_path(xs,domid);
+ char* dom0_home = xs_get_domain_path(xs,0);
+
+ xsperms[0].id = domid;
+ xsperms[0].perms = XS_PERM_READ | XS_PERM_WRITE;
+
+ printf("dom0_home is %s\n",dom0_home);
+ sprintf(pdev,"%u:%u",vbd->pdev>>8, vbd->pdev & 0xff);
+
+ sprintf(backend,"%s/backend/vbd/%d/%d",dom0_home,domid,vbd->vdev);
+ sprintf(frontend, "%s/device/vbd/%d",home,vbd->vdev);
+
+ xs_begin();
+ xs_mkdir(xs,t,backend);
+ xs_set_permissions(xs, t, backend, xsperms, 1);
+
+ sprintf(s,"%s/backend",frontend);
+ xs_w(s, backend );
+
+ sprintf(s, "%s/backend-id", frontend);
+ xs_w(s, "0");
+
+ sprintf(s, "%s/state", frontend);
+ xs_w(s, "1");
+
+
+ sprintf(s, "%s/virtual-device", frontend);
+ sprintf(vdev,"%u",vbd->vdev);
+ xs_w(s, vdev );
+
+
+ sprintf(s,"%s/domain",backend);
+ sprintf(s2,"%d",domid);
+ xs_w(s, s2);
+
+ sprintf(s,"%s/frontend",backend);
+ xs_w(s, frontend );
+
+ sprintf(s,"%s/frontend-id",backend);
+ sprintf(s2,"%d",domid);
+ xs_w(s, s2 );
+
+ sprintf(s, "%s/state", backend);
+ xs_w(s, "1");
+
+
+
+ sprintf(s, "%s/physical-device",backend);
+ xs_w(s, pdev );
+
+ sprintf(s, "%s/mode",backend);
+ xs_w(s, vbd->mode);
+
+ sprintf(node,"/dev/hda%d",vbd->vdev-0x300);
+
+#if 0
+ sprintf(s, "%s/dev",backend);
+ xs_w(s, node);
+
+ sprintf(s, "%s/node",backend);
+ xs_w(s, node);
+#endif
+
+ xs_end();
+
+}
+
+void usage(void)
+{
+ puts("\ncreate: create a new Xen domain, with settings read from file\n");
+ puts("usage: create [-p] configfile\n");
+ puts("flags:");
+ puts(" -p : purge all unpriv domains first\n");
+ exit(-1);
+}
+
+int main(int argc,char** argv)
+{
+ char kernel[256] = "";
+ char ramdisk[256] = "";
+ char cmdline[256] = "";
+ char cmdline2[256] = "";
+ char ip[16], ip2[16];
+ int console = 0;
+ int vif = 0;
+ int num_vbds;
+ struct vbd vbds[16];
+ int mem_mb = 16;
+ int maxmem_mb = 16;
+ int flag_purge=0;
+ int uuid;
+ int arg_pos=1;
+ int i;
+ char* cfgfile;
+ unsigned int domid = 0;
+ int rconsole = 0;
+ int rstore = 0;
+ unsigned long mfn_store, mfn_console;
+ struct xs_permissions xsperms[2];
+ char* home;
+
+
+ xen_domain_handle_t xen_handle = {0,};
+
+ if(argc<2) usage();
+
+ xc = xc_interface_open();
+ if(xc<0) goto xc_failed;
+
+ xs = xs_daemon_open();
+ if(xs<0) goto xs_failed;
+
+ evtchn_fd = open("/dev/xen/evtchn", O_RDWR);
+
+ //char pdev[] = "3:2";
+ //char pdev[16] = "";
+ //char vdev[] = "769";
+
+ for(i=1; i<argc-1; i++)
+ {
+ if(argv[i][0]=='-')
+ {
+ switch(argv[i][1])
+ {
+ case 'p':
+ flag_purge=1;
+ arg_pos++;
+ break;
+
+ default:
+ usage();
+ }
+ }
+
+ }
+ cfgfile = argv[arg_pos++];
+ read_config(cfgfile, ip, ip2, ramdisk, kernel, cmdline, &mem_mb, &maxmem_mb,
+ &console,&vif,&num_vbds,vbds);
+
+ printf("got %d\n",num_vbds);
+
+ if(flag_purge) purge_all_unpriv_domains(xc);
+
+
+
+ xc_domain_create(xc, ACM_DEFAULT_SSID, xen_handle, &domid);
+
+ if(arg_pos<argc)
+ {
+ sprintf(cmdline2,cmdline,atoi(argv[arg_pos]));
+ uuid = atoi(argv[arg_pos]);
+ }
+ else
+ {
+ strcpy(cmdline2,cmdline);
+ uuid = 10000+domid*100;
+ }
+
+ xc_domain_setmaxmem(xc,domid, maxmem_mb << 10);
+ xc_domain_memory_increase_reservation(xc,domid, mem_mb << 8, 0,0,0);
+ printf("%d\n",domid);
+
+ // 2) Build domain
+
+ rconsole = xc_evtchn_alloc_unbound(xc,domid,DOMID_SELF);
+ rstore = xc_evtchn_alloc_unbound(xc,domid,DOMID_SELF);
+ if(rstore<0 || rconsole<0) goto out;
+
+#if 0
+int xc_linux_build(int xc_handle,
+ uint32_t domid,
+ const char *image_name,
+ const char *initrd_name,
+ const char *cmdline,
+ const char *features,
+ unsigned long flags,
+ unsigned int store_evtchn,
+ unsigned long *store_mfn,
+ unsigned int console_evtchn,
+ unsigned long *console_mfn)
+#endif
+
+ if( xc_linux_build(xc, domid, kernel, ramdisk, cmdline2,NULL, 0,
+ rstore, &mfn_store, rconsole, &mfn_console))
+ goto out;
+
+ printf("intro %d, %08lx, %d\n",domid,mfn_store,rstore);
+
+ if(!xs_introduce_domain(xs, domid, mfn_store, rstore))
+ goto out;
+
+ xsperms[0].id = domid;
+ xsperms[0].perms = XS_PERM_READ | XS_PERM_WRITE;
+
+
+
+ if(console) setup_console(domid, rconsole, mfn_console);
+ home = xs_get_domain_path(xs,domid);
+ xs_begin();
+ xs_set_permissions(xs, t, home, xsperms, 1);
+ xs_end();
+
+ for(i=0; i<num_vbds; i++)
+ {
+ setup_vbd(domid,&vbds[i]);
+ }
+
+ if(vif) setup_vif(domid,0);
+
+
+ xc_domain_unpause(xc,domid);
+out:
+
+ xs_daemon_close(xs);
+xs_failed:
+ xc_interface_close(xc);
+xc_failed:
+
+ return 0;
+}
diff -r 0bfe5613711a tools/migrate/configfile.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/migrate/configfile.c Tue May 16 10:35:46 2006 +0200
@@ -0,0 +1,74 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "configfile.h"
+
+void read_config(char* cfgfile, char* ip, char* ip2, char* initrd,
+ char* kernel, char* cmdline, int* mem_mb, int* maxmem_mb,
+ int* console, int* vif, int* num_vbds,struct vbd* vbds)
+
+{
+ char key[256];
+ char value[256];
+ struct vbd* vbd = vbds;
+ FILE* f = fopen(cfgfile,"r");
+
+ *num_vbds=0;
+
+ if(!f)
+ {
+ printf("error opening cfg file %s\n", cfgfile);
+ exit(-1);
+ }
+
+ while( fscanf(f, "%[^=] = %[^\n]\n", key, value)!= EOF)
+ {
+ if(!strcmp(key, "kernel"))
+ {
+ strcpy(kernel,value);
+ }
+ else if(!strcmp(key, "initrd"))
+ {
+ strcpy(initrd,value);
+ }
+ else if(!strcmp(key, "ip"))
+ {
+ strcpy(ip,value);
+ }
+ else if(!strcmp(key, "ip2"))
+ {
+ strcpy(ip2,value);
+ }
+ else if(!strcmp(key, "cmdline"))
+ {
+ strcpy(cmdline,value);
+ }
+ else if(vbd && !strcmp(key, "vbd"))
+ {
+ strcpy(vbd->mode,"r");
+ sscanf(value, "%x,%x,%s\n", &vbd->pdev,&vbd->vdev,vbd->mode);
+ vbd++;
+ ++(*num_vbds);
+ }
+ else if(!strcmp(key, "mem"))
+ {
+ sscanf(value, "%dM", mem_mb);
+ }
+ else if(!strcmp(key, "maxmem"))
+ {
+ sscanf(value, "%dM", maxmem_mb);
+ }
+
+ else if(!strcmp(key, "console"))
+ {
+ sscanf(value, "%d", console);
+ }
+ else if(!strcmp(key, "vif"))
+ {
+ sscanf(value, "%d", vif);
+ }
+ }
+
+ fclose(f);
+}
diff -r 0bfe5613711a tools/migrate/configfile.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/migrate/configfile.h Tue May 16 10:35:46 2006 +0200
@@ -0,0 +1,10 @@
+struct vbd {
+ unsigned int pdev;
+ unsigned int vdev;
+ char mode[4];
+};
+
+extern void read_config(char* cfgfile, char* ip, char* ip2, char* initrd,
+ char* kernel, char* cmdline, int* mem_mb, int* maxmem_mb,
+ int* console, int* vif, int* num_vbds,struct vbd* vbd);
+
diff -r 0bfe5613711a tools/migrate/evtchn.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/migrate/evtchn.h Tue May 16 10:35:46 2006 +0200
@@ -0,0 +1,1 @@
+int evtchn_bind_interdomain(int xc, int evtchn_fd, int domid, int remote_port);
diff -r 0bfe5613711a tools/migrate/listdoms.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/migrate/listdoms.c Tue May 16 10:35:46 2006 +0200
@@ -0,0 +1,20 @@
+#include <stdio.h>
+#include <xenctrl.h>
+
+int main(int argc, char** argv)
+{
+ int xc_handle = xc_interface_open();
+ xc_dominfo_t infos[100];
+
+ int n = xc_domain_getinfo(xc_handle, 1, 100, infos);
+
+ int i;
+ for(i=0; i<n; i++)
+ {
+ printf("Domain %d, mem %lu kB\n",
+ (int)infos[i].domid,infos[i].nr_pages*4);
+
+ }
+
+ return 0;
+}
diff -r 0bfe5613711a tools/migrate/minimig.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/migrate/minimig.c Tue May 16 10:35:46 2006 +0200
@@ -0,0 +1,149 @@
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <string.h>
+
+#define PAGE_SIZE 4096
+#define O_DIRECT 040000
+
+int main(int argc,char** argv)
+{
+ size_t loader_size;
+ unsigned long loader_pages;
+ unsigned long offset = 0;
+ char* page;
+ char* loader = mmap(0, 8*PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0,0);
+ int f;
+ int i;
+ int o;
+ unsigned long num_mfns;
+ struct {
+ unsigned long pfn;
+ char page[PAGE_SIZE];
+ } data;
+
+
+ memset(loader,0,8*PAGE_SIZE);
+
+ if(argc>1) offset = atoi(argv[1]) * 4200 * PAGE_SIZE;
+
+ /* to work with O_DIRECT, we need to correctly align the loader. 512 bytes should be
+ * enough, but let's do PAGE_SIZE for now
+ */
+
+ f = open("loader", O_RDONLY);
+ if(f>=0)
+ {
+ size_t* a;
+
+ loader_size = read(f,loader+4, 8*PAGE_SIZE);
+ close(f);
+ loader_pages = (loader_size + 3*sizeof(size_t) + (PAGE_SIZE-1)) / PAGE_SIZE;
+ printf("loader pages %d\n", (int)loader_pages);
+ a = (size_t*) loader;
+
+ /* first long has length of loader minus arguments */
+ *a = loader_pages*PAGE_SIZE - 12;
+
+ a = (size_t*) ( loader+loader_pages * PAGE_SIZE - 8);
+ *a++ = sizeof(size_t); /* four bytes of args */
+ *a++ = 0x1000; /* argument: number of pages in checkpoint */
+
+ /* so loader and arguments ended up page-aligned after all */
+
+ }
+ else
+ {
+ puts("no file: 'loader'");
+ exit(-1);
+ }
+
+ page = mmap(0, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0,0);
+ o = open("/dev/hda1",O_WRONLY|O_TRUNC|O_DIRECT);
+
+ if(o<0)
+ {
+ printf("could not open output fd for write %d\n",o);
+ exit(-1);
+ }
+
+ printf("wiping /dev/hda1, fd %d\n",o);
+ memset(page,0,PAGE_SIZE);
+ for(i=0; i<0x1003; i++)
+ {
+ int r;
+
+ lseek(o, offset + i * PAGE_SIZE, SEEK_SET);
+ r = write(o, page, PAGE_SIZE);
+ if(r<0)
+ {
+ printf("r %d\n",r);
+ exit(-1);
+ }
+ }
+
+ /* write the loader and its args */
+ lseek(o, offset + 0, SEEK_SET);
+ write(o, loader, loader_pages * PAGE_SIZE);
+
+
+ f = open("/dev/checkpoint",O_RDONLY);
+ printf("writing checkpoint to fd %d\n",o);
+
+ if(f<0) switch(errno)
+ {
+ case ENOENT:
+ puts("no /dev/checkpoint!");
+ puts("please create with:\n\tmknod /dev/checkpoint c 1 12\n\tchmod 400 /dev/checkpoint");
+ exit(-1);
+ default:
+ puts("unable to open /dev/checkpoint");
+ exit(-1);
+ }
+
+ read(f, &num_mfns, sizeof(num_mfns));
+ printf("%08lx page frames\n", num_mfns);
+ if(num_mfns<=0) exit(-1);
+
+ for(;;)
+ {
+ int len = read(f, &data,sizeof(data));
+ int r;
+
+ if(len<0)
+ {
+ printf("we have arrived.\n");
+ close(o);
+ close(f);
+
+ /* if run as init we cannot exit */
+ //if(getpid()==1) while(1) sleep(100); else
+ exit(0);
+ }
+ lseek(o, offset + (loader_pages + data.pfn) * PAGE_SIZE, SEEK_SET);
+ memcpy(page,data.page,PAGE_SIZE);
+ r = write(o, page, PAGE_SIZE);
+
+ if(r<0)
+ {
+ printf("r %d\n",r);
+ exit(-1);
+ }
+
+ fsync(o);
+
+ if(len!=sizeof(data))
+ {
+ printf("last one , pfn %lu\n",data.pfn);
+ break;
+ }
+ }
+ close(o);
+ puts("done");
+
+ return 0;
+}
diff -r 0bfe5613711a tools/migrate/pack.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/migrate/pack.c Tue May 16 10:35:46 2006 +0200
@@ -0,0 +1,102 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/sendfile.h>
+
+#include <string.h>
+
+
+
+struct file {
+ char* name;
+ size_t size;
+ int fd;
+ int optional;
+};
+
+
+void stat_files(struct file* files,int num_files)
+{
+ int i;
+ for(i=0; i<num_files;i++)
+ {
+ struct file* f = &files[i];
+ f->fd = open(f->name, O_RDONLY);
+
+ if(f->name && *(f->name) && f->fd>=0)
+ {
+ struct stat stat;
+ fstat(f->fd, &stat);
+ f->size = stat.st_size;
+ printf("%s size %d\n", f->name, f->size);
+ }
+ else if(!f->optional)
+ {
+ printf("no file: '%s'\n",f->name);
+ exit(-1);
+ }
+ }
+}
+
+void write_file(FILE* out, struct file* f)
+{
+ char* d= malloc(f->size);
+ if(f->fd>=0)
+ {
+ printf("sending file %s\n", f->name);
+ if(read(f->fd,d,f->size)!=f->size)
+ {
+ printf("read err\n");
+ exit(-1);
+
+ }
+
+ fwrite(d, f->size,1,out);
+ free(d);
+ close(f->fd);
+ }
+}
+
+int main(int argc, char** argv)
+{
+ int args_size;
+ int i;
+ char cmdline[256];
+ int num_pfns = 0x1000;
+ struct file files[] = {
+ { "/root/bin/linux_loader", 0,0,0},
+ { "/root/vmlinux", 0,0,0},
+ { "/root/domUinitrd", 0,0,1}
+ };
+
+ const int num_files = sizeof(files)/sizeof(struct file);
+
+ FILE* out = fopen("/tmp/out.img","w");
+
+ memset(cmdline,0,sizeof(cmdline));
+ strcpy(cmdline,"mem=16M init=/linuxrc root=/dev/ram xencons=ttyS0");
+
+ printf("%d files\n", num_files);
+ stat_files(files,num_files);
+
+ fwrite(&files[0].size, sizeof(size_t),1,out);
+ write_file( out, &files[0] );
+
+ args_size = sizeof(cmdline) + 3*sizeof(size_t);
+ fwrite(&args_size, sizeof(args_size),1,out);
+
+ fwrite(&num_pfns, sizeof(num_pfns),1,out);
+ fwrite(cmdline, sizeof(cmdline),1,out);
+ fwrite(&files[1].size, sizeof(size_t),1,out);
+ fwrite(&files[2].size, sizeof(size_t),1,out);
+
+ for(i=1; i<num_files; i++) write_file( out, &files[i] );
+
+ fclose(out);
+
+ return 0;
+}
diff -r 0bfe5613711a tools/migrate/purgedoms.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/migrate/purgedoms.c Tue May 16 10:35:46 2006 +0200
@@ -0,0 +1,18 @@
+#include <xenctrl.h>
+#include <xenguest.h>
+
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <xs.h>
+#include <fcntl.h>
+
+#include "xenutil.h"
+
+int main(int argc, char** argv)
+{
+ purge_all_unpriv_domains( xc_interface_open() );
+ return 0;
+}
diff -r 0bfe5613711a tools/migrate/repair.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/migrate/repair.c Tue May 16 10:35:46 2006 +0200
@@ -0,0 +1,83 @@
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <string.h>
+
+
+#define PAGE_SIZE 4096
+#define O_DIRECT 040000
+
+int main(int argc, char** argv)
+{
+ int i;
+ int o,f;
+ size_t loader_size;
+ char* loader = mmap(0, 8*PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0,0);
+ unsigned long offset = 0;
+ unsigned long loader_pages;
+
+ if(argc>1) offset = atoi(argv[1]) * 4200 * PAGE_SIZE;
+
+ o = open("/tmp/chk.img",O_WRONLY|O_CREAT);
+ f = open("/dev/loop/6", O_RDONLY|O_DIRECT);
+ for(i=0; i<4100; i++)
+ {
+ lseek(f, offset + i*PAGE_SIZE, SEEK_SET);
+ read(f,loader,PAGE_SIZE);
+ lseek(o, i*PAGE_SIZE, SEEK_SET);
+ write(o,loader,PAGE_SIZE);
+ }
+ close(f);
+
+
+
+
+ f = open("/bin/loader", O_RDONLY);
+ if(f<0) f = open("loader", O_RDONLY);
+
+ memset(loader,0,8*PAGE_SIZE);
+
+ /* to work with O_DIRECT, we need to correctly align the loader. 512 bytes should be
+ * enough, but let's do PAGE_SIZE for now
+ */
+
+ if(f>=0)
+ {
+ size_t* a;
+ loader_size = read(f,loader+4, 8*PAGE_SIZE);
+ close(f);
+ loader_pages = (loader_size + 3*sizeof(size_t) + (PAGE_SIZE-1)) / PAGE_SIZE;
+ printf("loader pages %d\n", (int)loader_pages);
+ a = (size_t*) loader;
+
+ /* first long has length of loader minus arguments */
+ *a = loader_pages*PAGE_SIZE - 12;
+
+ a = (size_t*) ( loader+loader_pages * PAGE_SIZE - 8);
+ *a++ = sizeof(size_t); /* four bytes of args */
+ *a++ = 0x1000; /* argument: number of pages in checkpoint */
+
+ /* so loader and arguments ended up page-aligned after all */
+
+ }
+ else
+ {
+ puts("no file: 'loader'");
+ exit(-1);
+ }
+ /* write the loader and its args */
+ lseek(o, 0, SEEK_SET);
+ write(o, loader, loader_pages * PAGE_SIZE);
+
+
+
+
+ close(f);
+ close(o);
+
+ return 0;
+}
diff -r 0bfe5613711a tools/migrate/xdmesg.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/migrate/xdmesg.c Tue May 16 10:35:46 2006 +0200
@@ -0,0 +1,39 @@
+#include <xenctrl.h>
+#include <xenguest.h>
+
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#include <xs.h>
+#include <fcntl.h>
+
+#include <sys/mman.h>
+
+#define PAGE_SIZE 4096
+
+int xc;
+
+int main(int argc, char** argv)
+{
+ char* b= (char*) mmap(0,PAGE_SIZE, PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0,0);
+ char* a = b;
+ unsigned int n=PAGE_SIZE;
+ int i;
+
+ xc = xc_interface_open();
+
+ xc_readconsolering(xc,&b,&n,0);
+
+ for(i=0; i<n; i++) if(!isascii(a[i])) a[i]=' ';
+
+ a[n]='\0';
+
+ xc_interface_close(xc);
+
+ puts(a);
+
+ return 0;
+}
diff -r 0bfe5613711a tools/migrate/xenutil.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/migrate/xenutil.h Tue May 16 10:35:46 2006 +0200
@@ -0,0 +1,11 @@
+static inline void purge_all_unpriv_domains(int xc)
+{
+ xc_dominfo_t infos[128];
+ int n = xc_domain_getinfo(xc, 1,128, infos);
+
+ int i;
+ for(i=0; i<n; i++)
+ xc_domain_destroy(xc, infos[i].domid );
+
+}
+
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
^ permalink raw reply [flat|nested] 8+ messages in thread