All of lore.kernel.org
 help / color / mirror / Atom feed
* xc_domain_create
@ 2008-08-31 17:37 Shaun R.
  2008-08-31 18:01 ` xc_domain_create Keir Fraser
  2008-08-31 20:46 ` xc_domain_create Geoffrey Lefebvre
  0 siblings, 2 replies; 3+ messages in thread
From: Shaun R. @ 2008-08-31 17:37 UTC (permalink / raw)
  To: xen-devel

Can anybody show me a basic example of using this function to create a 
domain with the following config...

---------------------------------------------------------------------------------------------------
kernel="/boot/vmlinux-2.6.16.29-11774"
memory=256
name="user1"
vif=[ 'vifname=user1.0' , 'mac=FE:FD:CC:0F:87:45' ]
dhcp=""
disk=[ 
'tap:aio:/home/user1/disks/root_fs.img,sda1,w','tap:aio:/home/user1/disks/swap.img,sdb1,w' 
 ]
root="/dev/sda1 ro"
extra=""
ip="10.0.0.2"
netmask="255.255.255.248"
gateway="10.0.0.1"
dhcp=""
nfs_server=""
--------------------------------------------------------------------------------------------------

the xenctrl.h file shows this

int xc_domain_create(int xc_handle,
                     uint32_t ssidref,
                     xen_domain_handle_t handle,
                     uint32_t flags,
                     uint32_t *pdomid);


looks like i need to generate a ssidref, how can i do that?

xen_domain_handle_t handle i assume is what gets set with the domain info i 
just created?

I dont understand the flags, looking at other code it looks like this is 
where i need to pass all the config data but i'm unsure how.

pdomid, not sure what this is for.

If anybody can show me a basic example that would get me started in the 
right direction it would be much appreciated.


~Shaun 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: xc_domain_create
  2008-08-31 17:37 xc_domain_create Shaun R.
@ 2008-08-31 18:01 ` Keir Fraser
  2008-08-31 20:46 ` xc_domain_create Geoffrey Lefebvre
  1 sibling, 0 replies; 3+ messages in thread
From: Keir Fraser @ 2008-08-31 18:01 UTC (permalink / raw)
  To: Shaun R., xen-devel

On 31/8/08 18:37, "Shaun R." <mailinglists@unix-scripts.com> wrote:

> I dont understand the flags, looking at other code it looks like this is
> where i need to pass all the config data but i'm unsure how.

Not really -- a good deal of the configuration data gets cooked and written
to xenstored.

> pdomid, not sure what this is for.
> 
> If anybody can show me a basic example that would get me started in the
> right direction it would be much appreciated.

I'd start a domain with that config using xend, see what gets written to
xenstore (xenstore-ls) and then cook up a small program of your own to write
the same and then invoke xc_domain_create(), xc_dom_build(),
xc_domain_unpause(), etc.

Or you could try to work out how xend does it by looking at the python
source.

 -- Keir

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: xc_domain_create
  2008-08-31 17:37 xc_domain_create Shaun R.
  2008-08-31 18:01 ` xc_domain_create Keir Fraser
@ 2008-08-31 20:46 ` Geoffrey Lefebvre
  1 sibling, 0 replies; 3+ messages in thread
From: Geoffrey Lefebvre @ 2008-08-31 20:46 UTC (permalink / raw)
  To: Shaun R.; +Cc: xen-devel

[-- Attachment #1: Type: text/plain, Size: 2176 bytes --]

Hi,

Interesting coincidence. I was just working on something similar. Here
is example code that I just cooked up to start a mini-os domain. Not
the best code since many things are hardcoded but it seems to work on
a mini-os domain with no devices apart from the xen emergency console.
Getting the devices going and adding the proper entries in xenstore
are left as an exercise to the reader :).

Also, there is no support for mem ballooning, you have to reserve some
memory when booting xen.

Hopefully this helps you a bit.

cheers,

geoffrey

On Sun, Aug 31, 2008 at 10:37 AM, Shaun R.
<mailinglists@unix-scripts.com> wrote:
> Can anybody show me a basic example of using this function to create a
> domain with the following config...
>
> ---------------------------------------------------------------------------------------------------
> kernel="/boot/vmlinux-2.6.16.29-11774"
> memory=256
> name="user1"
> vif=[ 'vifname=user1.0' , 'mac=FE:FD:CC:0F:87:45' ]
> dhcp=""
> disk=[
> 'tap:aio:/home/user1/disks/root_fs.img,sda1,w','tap:aio:/home/user1/disks/swap.img,sdb1,w'
> ]
> root="/dev/sda1 ro"
> extra=""
> ip="10.0.0.2"
> netmask="255.255.255.248"
> gateway="10.0.0.1"
> dhcp=""
> nfs_server=""
> --------------------------------------------------------------------------------------------------
>
> the xenctrl.h file shows this
>
> int xc_domain_create(int xc_handle,
>                    uint32_t ssidref,
>                    xen_domain_handle_t handle,
>                    uint32_t flags,
>                    uint32_t *pdomid);
>
>
> looks like i need to generate a ssidref, how can i do that?
>
> xen_domain_handle_t handle i assume is what gets set with the domain info i
> just created?
>
> I dont understand the flags, looking at other code it looks like this is
> where i need to pass all the config data but i'm unsure how.
>
> pdomid, not sure what this is for.
>
> If anybody can show me a basic example that would get me started in the
> right direction it would be much appreciated.
>
>
> ~Shaun
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xensource.com
> http://lists.xensource.com/xen-devel
>

[-- Attachment #2: sample.c --]
[-- Type: text/plain, Size: 2505 bytes --]

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <uuid/uuid.h>
#include <xenctrl.h>

int main(int argc, char **argv)
{
    int xc_handle;
    uint32_t ssidref;
    xen_domain_handle_t handle;
    uint32_t flags;
    uint32_t domid;
    unsigned int mem_mb = 32;
    unsigned int mem_kb = mem_mb * 1024;
    int rc;
    char *kernel_img = "./mini-os.gz";
    char uuid_str[37];
    unsigned int store_evtchn, console_evtchn;
    unsigned long store_mfn, console_mfn;

    xc_handle = xc_interface_open();
    if (xc_handle < 0) {
        printf("Error getting xc handle\n");
        exit(0);
    }

    uuid_generate(handle);

    uuid_unparse(handle, uuid_str);

    printf("domain uuid:%s\n", uuid_str);

    ssidref = 0;

    flags = 0;

    rc = xc_domain_create(xc_handle, ssidref, handle, flags, &domid);
    if (rc) {
        printf("Error creating domain:%d\n", rc);
        exit(0);
    }

    printf("Created domain with ID:%u\n", domid);

    /*set max # of vcpus*/
    rc = xc_domain_max_vcpus(xc_handle, domid, 1);
    if (rc) {
        printf("Unable to set max # of vcpus\n");
        exit(0);
    }

    /*set max mem*/
    rc = xc_domain_setmaxmem(xc_handle, domid, mem_kb);
    if (rc) {
        printf("Error setting max mem\n");
        exit(0);
    }

    /*set memmap size*/
    rc = xc_domain_set_memmap_limit(xc_handle, domid, mem_kb);
    if (rc) {
        printf("Error setting memmap size\n");
        exit(0);
    }

    printf("Loading guest kernel\n");

    /*allocate ports*/
    store_evtchn = xc_evtchn_alloc_unbound(xc_handle, domid, 0);
    console_evtchn = xc_evtchn_alloc_unbound(xc_handle, domid, 0);

    printf("store evtchn:%u console evtchn:%u\n", 
            store_evtchn,
            console_evtchn);

    /*load image using the linux builder*/
    rc = xc_linux_build(xc_handle, domid, mem_mb,
                        kernel_img, NULL, "", "",
                        flags, 
                        store_evtchn, &store_mfn,
                        console_evtchn, &console_mfn);

    if (rc) {
        printf("Unable to load guest kernel\n");
        exit(0);
    }

    printf("store mfn:%lx console mfn:%lx\n", store_mfn, console_mfn);

    /*TODO store domain information in xenstore*/

    /*TODO devices*/

    /*unpause domain*/
    rc = xc_domain_unpause(xc_handle, domid);
    if (rc) {
        printf("Unable to unpause domain\n");
        exit(0);
    }

    xc_interface_close(xc_handle);

    return 0;
}



[-- 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] 3+ messages in thread

end of thread, other threads:[~2008-08-31 20:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-31 17:37 xc_domain_create Shaun R.
2008-08-31 18:01 ` xc_domain_create Keir Fraser
2008-08-31 20:46 ` xc_domain_create Geoffrey Lefebvre

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.