direct-io.hg

changeset 14120:a20ec270998b

Write Xen ELF notes into xenstore on domain build.
Signed-off-by: Brendan Cully <brendan@cs.ubc.ca>
author kfraser@localhost.localdomain
date Mon Feb 26 09:59:33 2007 +0000 (2007-02-26)
parents 78c0ae1f77f2
children 64d80037e524
files tools/libxc/xc_dom_compat_linux.c tools/libxc/xenguest.h tools/python/xen/lowlevel/xc/xc.c tools/python/xen/xend/XendDomainInfo.py xen/arch/x86/domain_build.c xen/common/libelf/libelf-dominfo.c xen/include/public/elfnote.h xen/include/public/libelf.h
line diff
     1.1 --- a/tools/libxc/xc_dom_compat_linux.c	Mon Feb 26 09:28:30 2007 +0000
     1.2 +++ b/tools/libxc/xc_dom_compat_linux.c	Mon Feb 26 09:59:33 2007 +0000
     1.3 @@ -122,6 +122,31 @@ int xc_linux_build(int xc_handle, uint32
     1.4      return rc;
     1.5  }
     1.6  
     1.7 +int xc_dom_linux_build(int xc_handle,
     1.8 +                       struct xc_dom_image *dom,
     1.9 +                       uint32_t domid,
    1.10 +                       unsigned int mem_mb,
    1.11 +                       const char *image_name,
    1.12 +                       const char *initrd_name,
    1.13 +                       unsigned long flags,
    1.14 +                       unsigned int store_evtchn,
    1.15 +                       unsigned long *store_mfn,
    1.16 +                       unsigned int console_evtchn, unsigned long *console_mfn)
    1.17 +{
    1.18 +    int rc;
    1.19 +
    1.20 +    if ( (rc = xc_dom_kernel_file(dom, image_name)) != 0 )
    1.21 +        return rc;
    1.22 +    if ( initrd_name && strlen(initrd_name) &&
    1.23 +         ((rc = xc_dom_ramdisk_file(dom, initrd_name)) != 0) )
    1.24 +        return rc;
    1.25 +
    1.26 +    return xc_linux_build_internal(dom, xc_handle, domid,
    1.27 +                                   mem_mb, flags,
    1.28 +                                   store_evtchn, store_mfn,
    1.29 +                                   console_evtchn, console_mfn);
    1.30 +}
    1.31 +
    1.32  /*
    1.33   * Local variables:
    1.34   * mode: C
     2.1 --- a/tools/libxc/xenguest.h	Mon Feb 26 09:28:30 2007 +0000
     2.2 +++ b/tools/libxc/xenguest.h	Mon Feb 26 09:59:33 2007 +0000
     2.3 @@ -91,6 +91,20 @@ int xc_linux_build(int xc_handle,
     2.4                     unsigned int console_evtchn,
     2.5                     unsigned long *console_mfn);
     2.6  
     2.7 +/** The same interface, but the dom structure is managed by the caller */
     2.8 +struct xc_dom_image;
     2.9 +int xc_dom_linux_build(int xc_handle,
    2.10 +		       struct xc_dom_image *dom,
    2.11 +		       uint32_t domid,
    2.12 +		       unsigned int mem_mb,
    2.13 +		       const char *image_name,
    2.14 +		       const char *ramdisk_name,
    2.15 +		       unsigned long flags,
    2.16 +		       unsigned int store_evtchn,
    2.17 +		       unsigned long *store_mfn,
    2.18 +		       unsigned int console_evtchn,
    2.19 +		       unsigned long *console_mfn);
    2.20 +
    2.21  /**
    2.22   * This function will create a domain for a paravirtualized Linux
    2.23   * using buffers for kernel and initrd
     3.1 --- a/tools/python/xen/lowlevel/xc/xc.c	Mon Feb 26 09:28:30 2007 +0000
     3.2 +++ b/tools/python/xen/lowlevel/xc/xc.c	Mon Feb 26 09:59:33 2007 +0000
     3.3 @@ -18,6 +18,8 @@
     3.4  #include <arpa/inet.h>
     3.5  
     3.6  #include "xenctrl.h"
     3.7 +#include <xen/elfnote.h>
     3.8 +#include "xc_dom.h"
     3.9  #include <xen/hvm/hvm_info_table.h>
    3.10  #include <xen/hvm/params.h>
    3.11  
    3.12 @@ -371,13 +373,17 @@ static PyObject *pyxc_linux_build(XcObje
    3.13                                    PyObject *args,
    3.14                                    PyObject *kwds)
    3.15  {
    3.16 -    uint32_t dom;
    3.17 +    uint32_t domid;
    3.18 +    struct xc_dom_image *dom;
    3.19      char *image, *ramdisk = NULL, *cmdline = "", *features = NULL;
    3.20      int flags = 0;
    3.21      int store_evtchn, console_evtchn;
    3.22      unsigned int mem_mb;
    3.23      unsigned long store_mfn = 0;
    3.24      unsigned long console_mfn = 0;
    3.25 +    PyObject* elfnote_dict;
    3.26 +    PyObject* elfnote = NULL;
    3.27 +    int i;
    3.28  
    3.29      static char *kwd_list[] = { "domid", "store_evtchn", "memsize",
    3.30                                  "console_evtchn", "image",
    3.31 @@ -386,22 +392,52 @@ static PyObject *pyxc_linux_build(XcObje
    3.32                                  "features", NULL };
    3.33  
    3.34      if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiiis|ssis", kwd_list,
    3.35 -                                      &dom, &store_evtchn, &mem_mb,
    3.36 +                                      &domid, &store_evtchn, &mem_mb,
    3.37                                        &console_evtchn, &image,
    3.38                                        /* optional */
    3.39                                        &ramdisk, &cmdline, &flags,
    3.40                                        &features) )
    3.41          return NULL;
    3.42  
    3.43 -    if ( xc_linux_build(self->xc_handle, dom, mem_mb, image,
    3.44 -                        ramdisk, cmdline, features, flags,
    3.45 -                        store_evtchn, &store_mfn,
    3.46 -                        console_evtchn, &console_mfn) != 0 ) {
    3.47 -        return pyxc_error_to_exception();
    3.48 +    xc_dom_loginit();
    3.49 +    if (!(dom = xc_dom_allocate(cmdline, features)))
    3.50 +	return pyxc_error_to_exception();
    3.51 +
    3.52 +    if ( xc_dom_linux_build(self->xc_handle, dom, domid, mem_mb, image,
    3.53 +			    ramdisk, flags, store_evtchn, &store_mfn,
    3.54 +			    console_evtchn, &console_mfn) != 0 ) {
    3.55 +	goto out;
    3.56      }
    3.57 -    return Py_BuildValue("{s:i,s:i}", 
    3.58 +
    3.59 +    if (!(elfnote_dict = PyDict_New()))
    3.60 +	goto out;
    3.61 +    for (i = 0; i < XEN_ELFNOTE_MAX; i++) {
    3.62 +	switch (dom->parms.elf_notes[i].type) {
    3.63 +	case XEN_ENT_NONE:
    3.64 +	    continue;
    3.65 +	case XEN_ENT_LONG:
    3.66 +	    elfnote = Py_BuildValue("k", dom->parms.elf_notes[i].data.num);
    3.67 +	    break;
    3.68 +	case XEN_ENT_STR:
    3.69 +	    elfnote = Py_BuildValue("s", dom->parms.elf_notes[i].data.str);
    3.70 +	    break;
    3.71 +	}
    3.72 +	PyDict_SetItemString(elfnote_dict,
    3.73 +			     dom->parms.elf_notes[i].name,
    3.74 +			     elfnote);
    3.75 +	Py_DECREF(elfnote);
    3.76 +    }
    3.77 +
    3.78 +    xc_dom_release(dom);
    3.79 +
    3.80 +    return Py_BuildValue("{s:i,s:i,s:N}", 
    3.81                           "store_mfn", store_mfn,
    3.82 -                         "console_mfn", console_mfn);
    3.83 +                         "console_mfn", console_mfn,
    3.84 +			 "notes", elfnote_dict);
    3.85 +
    3.86 +  out:
    3.87 +    xc_dom_release(dom);
    3.88 +    return pyxc_error_to_exception();
    3.89  }
    3.90  
    3.91  static PyObject *pyxc_hvm_build(XcObject *self,
     4.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Mon Feb 26 09:28:30 2007 +0000
     4.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Mon Feb 26 09:59:33 2007 +0000
     4.3 @@ -302,6 +302,8 @@ class XendDomainInfo:
     4.4      @type store_mfn: int
     4.5      @ivar console_mfn: xenconsoled mfn
     4.6      @type console_mfn: int
     4.7 +    @ivar notes: OS image notes
     4.8 +    @type notes: dictionary
     4.9      @ivar vmWatch: reference to a watch on the xenstored vmpath
    4.10      @type vmWatch: xen.xend.xenstore.xswatch
    4.11      @ivar shutdownWatch: reference to watch on the xenstored domain shutdown
    4.12 @@ -354,6 +356,7 @@ class XendDomainInfo:
    4.13          self.store_mfn = None
    4.14          self.console_port = None
    4.15          self.console_mfn = None
    4.16 +        self.notes = {}
    4.17  
    4.18          self.vmWatch = None
    4.19          self.shutdownWatch = None
    4.20 @@ -776,13 +779,29 @@ class XendDomainInfo:
    4.21  
    4.22          def f(n, v):
    4.23              if v is not None:
    4.24 -                to_store[n] = str(v)
    4.25 +                if type(v) == bool:
    4.26 +                    to_store[n] = v and "1" or "0"
    4.27 +                else:
    4.28 +                    to_store[n] = str(v)
    4.29  
    4.30          f('console/port',     self.console_port)
    4.31          f('console/ring-ref', self.console_mfn)
    4.32          f('store/port',       self.store_port)
    4.33          f('store/ring-ref',   self.store_mfn)
    4.34  
    4.35 +        # elfnotes
    4.36 +        for n, v in self.notes.iteritems():
    4.37 +            n = n.lower().replace('_', '-')
    4.38 +            if n == 'features':
    4.39 +                for v in v.split('|'):
    4.40 +                    v = v.replace('_', '-')
    4.41 +                    if v.startswith('!'):
    4.42 +                        f('image/%s/%s' % (n, v[1:]), False)
    4.43 +                    else:
    4.44 +                        f('image/%s/%s' % (n, v), True)
    4.45 +            else:
    4.46 +                f('image/%s' % n, v)
    4.47 +
    4.48          to_store.update(self._vcpuDomDetails())
    4.49  
    4.50          log.debug("Storing domain details: %s", scrub_password(to_store))
    4.51 @@ -1462,6 +1481,8 @@ class XendDomainInfo:
    4.52              self.store_mfn = channel_details['store_mfn']
    4.53              if 'console_mfn' in channel_details:
    4.54                  self.console_mfn = channel_details['console_mfn']
    4.55 +            if 'notes' in channel_details:
    4.56 +                self.notes = channel_details['notes']
    4.57  
    4.58              self._introduceDomain()
    4.59  
     5.1 --- a/xen/arch/x86/domain_build.c	Mon Feb 26 09:28:30 2007 +0000
     5.2 +++ b/xen/arch/x86/domain_build.c	Mon Feb 26 09:59:33 2007 +0000
     5.3 @@ -28,6 +28,7 @@
     5.4  #include <asm/paging.h>
     5.5  
     5.6  #include <public/version.h>
     5.7 +#include <public/elfnote.h>
     5.8  #include <public/libelf.h>
     5.9  
    5.10  extern unsigned long initial_images_nrpages(void);
     6.1 --- a/xen/common/libelf/libelf-dominfo.c	Mon Feb 26 09:28:30 2007 +0000
     6.2 +++ b/xen/common/libelf/libelf-dominfo.c	Mon Feb 26 09:59:33 2007 +0000
     6.3 @@ -119,13 +119,18 @@ int elf_xen_parse_note(struct elf_binary
     6.4          str = elf_note_desc(elf, note);
     6.5          elf_msg(elf, "%s: %s = \"%s\"\n", __FUNCTION__,
     6.6                  note_desc[type].name, str);
     6.7 +        parms->elf_notes[type].type = XEN_ENT_STR;
     6.8 +        parms->elf_notes[type].data.str = str;
     6.9      }
    6.10      else
    6.11      {
    6.12          val = elf_note_numeric(elf, note);
    6.13          elf_msg(elf, "%s: %s = 0x%" PRIx64 "\n", __FUNCTION__,
    6.14                  note_desc[type].name, val);
    6.15 +        parms->elf_notes[type].type = XEN_ENT_LONG;
    6.16 +        parms->elf_notes[type].data.num = val;
    6.17      }
    6.18 +    parms->elf_notes[type].name = note_desc[type].name;
    6.19  
    6.20      switch ( type )
    6.21      {
     7.1 --- a/xen/include/public/elfnote.h	Mon Feb 26 09:28:30 2007 +0000
     7.2 +++ b/xen/include/public/elfnote.h	Mon Feb 26 09:59:33 2007 +0000
     7.3 @@ -157,6 +157,11 @@
     7.4  #define XEN_ELFNOTE_L1_MFN_VALID  13
     7.5  
     7.6  /*
     7.7 + * The number of the highest elfnote defined.
     7.8 + */
     7.9 +#define XEN_ELFNOTE_MAX XEN_ELFNOTE_L1_MFN_VALID
    7.10 +
    7.11 +/*
    7.12   * System information exported through crash notes.
    7.13   *
    7.14   * The kexec / kdump code will create one XEN_ELFNOTE_CRASH_INFO 
     8.1 --- a/xen/include/public/libelf.h	Mon Feb 26 09:28:30 2007 +0000
     8.2 +++ b/xen/include/public/libelf.h	Mon Feb 26 09:59:33 2007 +0000
     8.3 @@ -174,12 +174,28 @@ int elf_reloc(struct elf_binary *elf);
     8.4  
     8.5  #define UNSET_ADDR          ((uint64_t)-1)
     8.6  
     8.7 +enum xen_elfnote_type {
     8.8 +    XEN_ENT_NONE = 0,
     8.9 +    XEN_ENT_LONG = 1,
    8.10 +    XEN_ENT_STR  = 2
    8.11 +};
    8.12 +
    8.13 +struct xen_elfnote {
    8.14 +    enum xen_elfnote_type type;
    8.15 +    const char *name;
    8.16 +    union {
    8.17 +	const char *str;
    8.18 +	uint64_t num;
    8.19 +    } data;
    8.20 +};
    8.21 +
    8.22  struct elf_dom_parms {
    8.23      /* raw */
    8.24      const char *guest_info;
    8.25      const void *elf_note_start;
    8.26      const void *elf_note_end;
    8.27 -
    8.28 +    struct xen_elfnote elf_notes[XEN_ELFNOTE_MAX + 1];
    8.29 +  
    8.30      /* parsed */
    8.31      char guest_os[16];
    8.32      char guest_ver[16];