ia64/xen-unstable

changeset 370:9a6284b6a131

bitkeeper revision 1.172.2.1 (3e9d99f1bgmrT-dK132TjqTggS_oow)

Add support to domain_builder to enable domains>0 to be booted with
initrd's (initial ram disks).

To continue the fine tradition of layering hack upon hack in domain_builder,
if the 4th parameter to domain_builder starts 'initrd=' then it will
load the specified file as an initrd module, and pass that to the new kernel.

For example:
r ./newdom 128000 ../../../xenolinux-2.4.21-pre4/arch/xeno/boot/image 128.232.xx.xx initrd=/usr/groups/srgboot/xxx/initrd ip=128.232.xx.xx:128.232.32.20:128.232.32.1:255.255.240.0::eth0:off ramdisk_size=32804 root=/dev/ram0 rw

Someone really needs to rewrite domain_builder to take more sensible command
line arguments...
author iap10@labyrinth.cl.cam.ac.uk
date Wed Apr 16 17:59:13 2003 +0000 (2003-04-16)
parents 87768b015863
children 79f5506ed415
files tools/domain_builder/dom_builder.c xen/Makefile xen/common/domain.c xen/include/xeno/dom0_ops.h xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/dom0/dom0_ops.h
line diff
     1.1 --- a/tools/domain_builder/dom_builder.c	Wed Apr 16 12:44:16 2003 +0000
     1.2 +++ b/tools/domain_builder/dom_builder.c	Wed Apr 16 17:59:13 2003 +0000
     1.3 @@ -238,7 +238,7 @@ out:
     1.4   * manner. this way, many potentially messy things are avoided...
     1.5   */ 
     1.6  #define PAGE_TO_VADDR(_pfn) ((void *)(dom_mem->vaddr + ((_pfn) * PAGE_SIZE)))
     1.7 -static dom_meminfo_t *setup_guestos(int dom, int kernel_fd, 
     1.8 +static dom_meminfo_t *setup_guestos(int dom, int kernel_fd, int initrd_fd,
     1.9      unsigned long virt_load_addr, size_t ksize, dom_mem_t *dom_mem)
    1.10  {
    1.11      dom_meminfo_t *meminfo;
    1.12 @@ -260,6 +260,8 @@ static dom_meminfo_t *setup_guestos(int 
    1.13      pgt_updates = (page_update_request_t *)dom_mem->vaddr;
    1.14      alloc_index = dom_mem->tot_pages - 1;
    1.15  
    1.16 +    memset(meminfo, 0, sizeof(meminfo));
    1.17 +
    1.18      memcpy(page_array, (void *)dom_mem->vaddr, dom_mem->tot_pages * 4);
    1.19  
    1.20      /* Count bottom-level PTs, rounding up. Include one PTE for shared info. */
    1.21 @@ -365,6 +367,31 @@ static dom_meminfo_t *setup_guestos(int 
    1.22          goto out;
    1.23      }
    1.24  
    1.25 +    if( initrd_fd )
    1.26 +      {
    1.27 +	struct stat stat;
    1.28 +	unsigned long isize;
    1.29 +
    1.30 +	if(fstat(initrd_fd, &stat) < 0){
    1.31 +	  perror(PERR_STRING);
    1.32 +	  close(initrd_fd);
    1.33 +	  goto out;
    1.34 +	}
    1.35 +	isize = stat.st_size;
    1.36 +
    1.37 +	if( read(initrd_fd, ((char *)dom_mem->vaddr)+ksize, isize) != isize )
    1.38 +	  {
    1.39 +	    dberr("Error reading initrd image, could not"
    1.40 +		  " read the whole image. Terminating.\n");
    1.41 +	    goto out;
    1.42 +	  }
    1.43 +
    1.44 +	meminfo->virt_mod_addr = virt_load_addr + ksize;
    1.45 +	meminfo->virt_mod_len  = isize;
    1.46 +
    1.47 +      }
    1.48 +
    1.49 +
    1.50      ret = meminfo;
    1.51  out:
    1.52  
    1.53 @@ -404,16 +431,20 @@ int main(int argc, char **argv)
    1.54      size_t ksize;
    1.55      unsigned long load_addr;
    1.56      char status[1024];
    1.57 -    int kernel_fd;
    1.58 +    int kernel_fd, initrd_fd = 0;
    1.59      int count;
    1.60      int cmd_len;
    1.61      int rc = -1;
    1.62 +    int args_start = 4;
    1.63 +    char initrd_name[1024];
    1.64  
    1.65      unsigned long addr;
    1.66  
    1.67 +    /**** this argument parsing code is really _gross_. rewrite me! ****/
    1.68 +
    1.69      if(argc < 4) {
    1.70          dberr("Usage: dom_builder <kbytes_mem> <image> <num_vifs> "
    1.71 -	      "<boot_params>\n");
    1.72 +	      "[<initrd=initrd_name>] <boot_params>\n");
    1.73          goto out;
    1.74      }
    1.75  
    1.76 @@ -434,8 +465,22 @@ int main(int argc, char **argv)
    1.77  		   dom_data->domain, &dom_os_image))
    1.78          goto out;
    1.79  
    1.80 +    if( strncmp("initrd=", argv[args_start], 7) == 0 )
    1.81 +      {
    1.82 +	strncpy( initrd_name, argv[args_start]+7, sizeof(initrd_name) );
    1.83 +	initrd_name[sizeof(initrd_name)-1] = 0;
    1.84 +	printf("initrd present, name = %s\n", initrd_name );
    1.85 +	args_start++;
    1.86 +
    1.87 +	initrd_fd = open(initrd_name, O_RDONLY);
    1.88 +	if(initrd_fd < 0){
    1.89 +	  perror(PERR_STRING);
    1.90 +	  goto out;
    1.91 +	}
    1.92 +      }
    1.93 +
    1.94      /* the following code does the actual domain building */
    1.95 -    meminfo = setup_guestos(dom_data->domain, kernel_fd, load_addr, 
    1.96 +    meminfo = setup_guestos(dom_data->domain, kernel_fd, initrd_fd, load_addr, 
    1.97  			    ksize, &dom_os_image); 
    1.98      
    1.99      /* and unmap the new domain's memory image since we no longer need it */
   1.100 @@ -450,7 +495,7 @@ int main(int argc, char **argv)
   1.101      meminfo->num_vifs = atoi(argv[3]);
   1.102      meminfo->cmd_line[0] = '\0';
   1.103      cmd_len = 0;
   1.104 -    for(count = 4; count < argc; count++){
   1.105 +    for(count = args_start; count < argc; count++){
   1.106          if(cmd_len + strlen(argv[count]) > MAX_CMD_LEN - 1){
   1.107              dberr("Size of image boot params too big!\n");
   1.108              break;
     2.1 --- a/xen/Makefile	Wed Apr 16 12:44:16 2003 +0000
     2.2 +++ b/xen/Makefile	Wed Apr 16 17:59:13 2003 +0000
     2.3 @@ -5,7 +5,9 @@ include Rules.mk
     2.4  
     2.5  default: $(TARGET)
     2.6  	gzip -f -9 < $(TARGET) > $(TARGET).gz
     2.7 -#	objdump -D -S image >image.s
     2.8 +
     2.9 +debug:	
    2.10 +	objdump -D -S image >image.s
    2.11  
    2.12  install: $(TARGET)
    2.13  	gzip -f -9 < $(TARGET) > $(TARGET).gz
     3.1 --- a/xen/common/domain.c	Wed Apr 16 12:44:16 2003 +0000
     3.2 +++ b/xen/common/domain.c	Wed Apr 16 17:59:13 2003 +0000
     3.3 @@ -323,7 +323,16 @@ int final_setup_guestos(struct task_stru
     3.4      virt_startinfo_addr->shared_info = (shared_info_t *)meminfo->virt_shinfo_addr;
     3.5      virt_startinfo_addr->pt_base = meminfo->virt_load_addr + 
     3.6                      ((p->tot_pages - 1) << PAGE_SHIFT);
     3.7 -    
     3.8 +   
     3.9 +    /* module size and length */
    3.10 +
    3.11 +    virt_startinfo_addr->mod_start = meminfo->virt_mod_addr;
    3.12 +    virt_startinfo_addr->mod_len   = meminfo->virt_mod_len;
    3.13 +
    3.14 +	
    3.15 +    if( virt_startinfo_addr->mod_len )
    3.16 +	printk("Initrd module present %08x (%08x)\n",virt_startinfo_addr->mod_start, virt_startinfo_addr->mod_len);	
    3.17 + 
    3.18      /* Add virtual network interfaces and point to them in startinfo. */
    3.19      while (meminfo->num_vifs-- > 0) {
    3.20          net_vif = create_net_vif(p->domain);
     4.1 --- a/xen/include/xeno/dom0_ops.h	Wed Apr 16 12:44:16 2003 +0000
     4.2 +++ b/xen/include/xeno/dom0_ops.h	Wed Apr 16 17:59:13 2003 +0000
     4.3 @@ -51,6 +51,8 @@ typedef struct domain_launch
     4.4      unsigned long virt_startinfo_addr;
     4.5      unsigned int num_vifs;
     4.6      char cmd_line[MAX_CMD_LEN];
     4.7 +    unsigned long virt_mod_addr;
     4.8 +    unsigned long virt_mod_len;
     4.9  } dom_meminfo_t;
    4.10  
    4.11  typedef struct dom0_bvtctl_st
     5.1 --- a/xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/dom0/dom0_ops.h	Wed Apr 16 12:44:16 2003 +0000
     5.2 +++ b/xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/dom0/dom0_ops.h	Wed Apr 16 17:59:13 2003 +0000
     5.3 @@ -81,6 +81,8 @@ typedef struct domain_launch
     5.4      unsigned long virt_startinfo_addr;
     5.5      unsigned int num_vifs;
     5.6      char cmd_line[MAX_CMD_LEN];
     5.7 +    unsigned long virt_mod_addr;
     5.8 +    unsigned long virt_mod_len;
     5.9  } dom_meminfo_t;
    5.10  
    5.11