- add parallel routines to support domain building via buffers
PATCH RESEND 1/1 - add parallel routines to support domain building via buffers
This patch adds a parallel set of APIs to the domain builders to allow images and ramdisks to be passed via buffer, rather than via file. This allows usage of the underlying domain building routines in "file-challenged" enviroments.
Specifically, xc_linux_build_mem is the buffer oriented version of the file-oriented xc_linux_build. Likewise, xc_hvm_build_mem is the buffer oriented analog of the file based xc_hvm_build.
This patch also implements a suggestion by Mark Williamson to have the internal APIs always directly use uncompressed buffers.
-b
tools/libxc/xc_hvm_build.c +104 -19
@@ -339,24 +339,29 @@ static int setup_guest(int xc_handle,return -1 ; } -int xc_hvm_build (int xc_handle, -uint32_t domid, -int memsize, -const char *image_name, -unsigned int control_evtchn, -unsigned int vcpus, -unsigned int acpi, -unsigned int apic, -unsigned int store_evtchn, -unsigned long *store_mfn) +static int xc_hvm_build_internal (int xc_handle, +uint32_t domid, +int memsize, +unsigned char *image, +unsigned long image_size, +unsigned int control_evtchn, +unsigned int vcpus, +unsigned int acpi, +unsigned int apic, +unsigned int store_evtchn, +unsigned long *store_mfn) {dom0_op_t launch_op, op;int rc, i;vcpu_guest_context_t st_ctxt, *ctxt = &st_ctxt;unsigned long nr_pages; -char *image =NULL ; -unsigned long image_size;xen_capabilities_info_t xen_caps; + +if ( (image ==NULL ) || (image_size ==0 ) ) + { +ERROR ("Image required" ); + goto error_out; + }if ( (rc =xc_version (xc_handle, XENVER_capabilities, &xen_caps)) !=0 ) {
@@ -376,9 +381,6 @@ int xc_hvm_build(int xc_handle,PERROR ("Could not find total pages for domain" ); goto error_out; } - -if ( (image =xc_read_kernel_image (image_name, &image_size)) ==NULL ) - goto error_out;if (mlock (&st_ctxt,sizeof (st_ctxt) ) ) {
@@ -398,15 +400,13 @@ int xc_hvm_build(int xc_handle,memset (ctxt,0 ,sizeof (*ctxt)); ctxt->flags =VGCF_HVM_GUEST ; -if (setup_guest (xc_handle, domid, memsize, image, image_size, nr_pages, +if (setup_guest (xc_handle, domid, memsize, (char *)image, image_size, nr_pages, ctxt, op.u.getdomaininfo.shared_info_frame, control_evtchn, vcpus, acpi, apic, store_evtchn, store_mfn) <0 ) {ERROR ("Error constructing guest OS" ); goto error_out; } - -free (image);/* FPU is set up to default initial state. */ memset (&ctxt->fpu_ctxt,0 ,sizeof (ctxt->fpu_ctxt));
@@ -451,7 +451,6 @@ int xc_hvm_build(int xc_handle,return rc; error_out: -free (image);return -1 ; }
@@ -581,6 +580,92 @@ loadelfimage(return 0 ; } +/* xc_hvm_build +* +* Create a domain for a virtualized Linux, using files/filenames +* +*/ + +int xc_hvm_build (int xc_handle, +uint32_t domid, +int memsize, +const char *image_name, +unsigned int control_evtchn, +unsigned int vcpus, +unsigned int acpi, +unsigned int apic, +unsigned int store_evtchn, +unsigned long *store_mfn) +{ +unsigned char *image; +int sts; +long image_size; + +/* Bring uncompressed image into memory */ + +if ( (image_name ==NULL ) || + ((image = (unsigned char *)xc_read_image (image_name, (unsigned long *)&image_size)) ==NULL )) +return -1 ; + + sts =xc_hvm_build_internal (xc_handle, domid, memsize, + image, image_size, + control_evtchn, vcpus, acpi, + apic, store_evtchn, store_mfn); +free (image); +return sts; +} + +/* xc_hvm_build_mem +* +* Create a domain for a virtualized Linux, using buffers +* +*/ + +int xc_hvm_build_mem (int xc_handle, +uint32_t domid, +int memsize, +unsigned char *image_buffer, +unsigned long image_size, +unsigned int control_evtchn, +unsigned int vcpus, +unsigned int acpi, +unsigned int apic, +unsigned int store_evtchn, +unsigned long *store_mfn) +{ +int sts; +unsigned long img_len; +unsigned char *img; + +/* Validate that there is a kernel buffer */ + +if ( (image_buffer ==NULL ) || (image_size ==0 ) ) + { +ERROR ("kernel image buffer not present" ); +return -EINVAL ; + } + + img =xc_inflate_buffer (image_buffer, image_size, &img_len); +if (img ==NULL ) + { +ERROR ("unable to inflate ram disk buffer" ); +return -1 ; + } + + sts =xc_hvm_build_internal (xc_handle, domid, memsize, + img, img_len, + control_evtchn, vcpus, acpi, + apic, store_evtchn, store_mfn); + +/* xc_inflate_buffer may return the original buffer pointer (for +for already inflated buffers), so exercise some care in freeing */ + +if ( (img !=NULL ) && (img != image_buffer) ) +free (img); + +return sts; +} +/* * Local variables: * mode: C
tools/libxc/xc_ia64_stubs.c +1 -1
@@ -645,7 +645,7 @@ int xc_hvm_build(int xc_handle, goto error_out; } -if ( (image =xc_read_kernel_image (image_name, &image_size)) ==NULL ){ +if ( (image =xc_read_image (image_name, &image_size)) ==NULL ){PERROR ("Could not read guest firmware image %s" ,image_name); goto error_out; }
tools/libxc/xc_linux_build.c +192 -78
351 lines not on this page · raw message
tools/libxc/xenguest.h +59 -0
75 lines not on this page · raw message
tools/libxc/xg_private.c +67 -3
94 lines not on this page · raw message
tools/libxc/xg_private.h +5 -1
@@ -26,7 +26,11 @@#endif -char *xc_read_kernel_image (const char *filename,unsigned long *size); +char *xc_read_image (const char *filename,unsigned long *size); +unsigned char *xc_inflate_buffer (unsigned char *in_buf, +unsigned long in_size, +unsigned long *out_size); +unsigned long csum_page (void * page);#define _PAGE_PRESENT 0x001
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel