/* * Copyright (C) 2008, Red Hat * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * Authors: * Mark McLoughlin */ /* * Compile with: * gcc -g -Wall -lxenguest test-xen-domain-builder.c -o test-xen-domain-builder */ #include #include #include #define MEM_MB 64 #define IMAGE "/boot/vmlinux-2.6.24" #define INITRD NULL #define CMDLINE "" #define FEATURES NULL #define FLAGS 0 int main(int argc, char **argv) { int xc_handle, ret; uint32_t domid; unsigned int store_evtchn, console_evtchn; unsigned long store_mfn, console_mfn; xen_domain_handle_t uuid = { 0xb2, 0x93, 0x22, 0x1f, 0x1a, 0xaa, 0x20, 0xac, 0xbe, 0x36, 0xc4, 0xd7, 0x6b, 0x73, 0x92, 0x1, }; xc_handle = xc_interface_open(); if (xc_handle == -1) { fprintf(stderr, "xc_interface_open() failed\n"); return 1; } domid = 0; ret = xc_domain_create(xc_handle, 0, uuid, 0, &domid); if (ret != 0) { fprintf(stderr, "xc_dom_linux_build() failed\n"); goto fail; } store_evtchn = xc_evtchn_alloc_unbound(xc_handle, domid, 0); if (store_evtchn < 0) { fprintf(stderr, "Failed to allocate xenstore event channel\n"); goto fail; } console_evtchn = xc_evtchn_alloc_unbound(xc_handle, domid, 0); if (console_evtchn < 0) { fprintf(stderr, "Failed to allocate console event channel\n"); goto fail; } ret = xc_domain_setmaxmem(xc_handle, domid, MEM_MB << 10); if (ret != 0) { fprintf(stderr, "xc_domain_set_maxmem() failed\n"); goto fail; } ret = xc_domain_max_vcpus(xc_handle, domid, 1); if (ret != 0) { fprintf(stderr, "xc_domain_max_vcpus() failed\n"); goto fail; } ret = xc_linux_build(xc_handle, domid, MEM_MB, IMAGE, INITRD, CMDLINE, FEATURES, FLAGS, store_evtchn, &store_mfn, console_evtchn, &console_mfn); if (ret != 0) { fprintf(stderr, "xc_dom_linux_build() failed\n"); goto fail; } xc_interface_close(xc_handle); return 0; fail: if (domid) { xc_evtchn_reset(xc_handle, domid); xc_domain_destroy(xc_handle, domid); } xc_interface_close(xc_handle); return 1; }