aboutsummaryrefslogtreecommitdiffstats
path: root/target/imagebuilder
Commit message (Expand)AuthorAgeFilesLines
* build: split scripts/metadata.pl into target-metadata.pl and package-metadata.plFelix Fietkau2016-06-071-1/+1
* IB/SDK/toolchain: use lower cases filenamesAlexander Couzens2016-06-011-1/+1
* IB/SDK/toolchain: use VERSION_DIST_SANITIZED instead of VERSION_DISTAlexander Couzens2016-06-011-1/+1
* imagebuilder: Fix sorting package list breaks opkg dependency handling for pr...Daniel Dickinson2016-05-181-1/+1
* build: remove profile kernel/build system config override supportFelix Fietkau2016-05-151-1/+0
* target/imagebuilder: fix using new device profilesFelix Fietkau2016-05-131-13/+9
* imagebuilder: rename OpenWrt into LEDEAlexander Couzens2016-05-052-2/+2
* imagebuilder: use correct package directory when bundling kmods and libcJo-Philipp Wich2016-04-221-2/+2
* imagebuilder: fix standalone operationJo-Philipp Wich2016-04-131-1/+2
* images imagebuilder: Allow to add sanitized extra nameFelix Fietkau2016-01-031-2/+2
* targets: Use configured distribution name for SDK, IB, and Toolchain tarball ...Felix Fietkau2016-01-031-1/+1
* imagebuilder: store package lists in cache directoryJo-Philipp Wich2015-09-141-0/+2
* imagebuilder: run build prereq checks before building image to set up host co...Felix Fietkau2015-09-101-1/+16
* build: Prevent more gzip timestampsJohn Crispin2015-07-141-1/+1
* imagebuilder: create cache directory if needed (#18629)Jo-Philipp Wich2015-06-011-7/+7
* IB: make CONFIG_IB_STANDALONE the defaultJo-Philipp Wich2015-05-281-3/+4
* feeds: use common macro "FeedSourcesAppend" to populate opkg configurationsJo-Philipp Wich2015-05-281-12/+2
* IB: use online repositoriesJo-Philipp Wich2015-05-274-5/+40
* imagebuilder: align filename with SDKJo-Philipp Wich2015-02-071-5/+2
* imagebuilder: don't pregenerate package index, strip host binariesJo-Philipp Wich2015-02-061-2/+2
* imagebuilder: use FreeBSD compatible tar invocationJo-Philipp Wich2015-02-061-1/+1
* imagebuilder: fail with error if the passed profile name does not existJo-Philipp Wich2015-01-101-0/+8
* build: add version number to filenamesJo-Philipp Wich2015-01-081-1/+1
* target/imagebuilder: remove obsolete !TARGET_ROOTFS_INITRAMFS dependencyFelix Fietkau2014-10-311-1/+0
* postinst trigger: the new postinst trigger broke IBJohn Crispin2014-09-161-4/+5
* imagebuilder: remove postinst files before generating imageFelix Fietkau2014-08-311-0/+1
* build: introduce per feed repository supportJo-Philipp Wich2014-08-051-2/+2
* imagebuilder: fix typo that copied grub to the wrong folderJohn Crispin2014-07-241-2/+2
* imagebuilder: copy dts folderJohn Crispin2014-07-211-1/+5
* imagebuilder: x86 fails to build inside the imagebuilderJohn Crispin2014-07-101-1/+4
* target/imagebuilder: add missing package index (fixes #16675)Felix Fietkau2014-06-021-0/+1
* imagebuilder: bundle dtc (#12953, #14741)Jo-Philipp Wich2014-05-141-0/+2
* build: consistently use 'depends on' instead of 'depends'Felix Fietkau2013-04-171-3/+3
* imagebuilder: use file_copy to deploy files/ in the image generation phaseJo-Philipp Wich2012-12-021-9/+1
* imagebuilder: merge r25078 to align files/ handling with current buildrootJo-Philipp Wich2012-11-221-0/+8
* derive system from hostcc to allow building inside a chrootJohn Crispin2012-08-221-2/+2
* use bundle-libraries.sh to install required host utilities into imagebuilder ...Jo-Philipp Wich2012-08-151-1/+2
* package/index: filter out the libc package from the indexFelix Fietkau2012-06-111-0/+1
* add $(SUBTARGET) to the filename if availableJohn Crispin2012-05-301-1/+1
* imagebuilder: explicitly install the kernel .ipk before installing anything e...Felix Fietkau2012-05-141-0/+1
* build: rework verbosity level selectionFelix Fietkau2012-04-261-1/+1
* don't overwrite version.mk, substitute REVISION insteadJo-Philipp Wich2012-04-171-2/+2
* populate repositories.conf from version.mkJo-Philipp Wich2012-04-122-3/+4
* ImageBuilder: respect the PROFILE parameterGabor Juhos2012-01-241-4/+5
* Various enhancements from Manuel Munz <freifunk@somakoma.de> - don't regenera...Jo-Philipp Wich2011-09-091-2/+9
* imagebuilder: clean opkg files if requested (patch from #9866)Felix Fietkau2011-08-011-0/+1
* Send ipkg-make-index.sh output to stdoutJo-Philipp Wich2011-02-231-1/+1
* allow overriding BIN_DIR (#7412)Jo-Philipp Wich2010-10-261-1/+3
* copy kernel .config, needed by mkfs.jffs2 to detect compression capabilitiesJo-Philipp Wich2010-10-261-1/+3
* - sync with host opkg changes - get rid of autogenerated opkg.conf - utilize ...Jo-Philipp Wich2010-09-124-58/+14
/a> 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650
/*
 * Copyright (C) 2009      Citrix Ltd.
 * Author Vincent Hanquez <vincent.hanquez@eu.citrix.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation; version 2.1 only. with the special
 * exception on linking described in file LICENSE.
 *
 * 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 Lesser General Public License for more details.
 */
#ifndef LIBXL_H
#define LIBXL_H

#include <stdint.h>
#include <stdarg.h>
#include <netinet/in.h>
#include <xenctrl.h>
#include <xs.h>
#include <sys/wait.h> /* for pid_t */

struct libxl_dominfo {
    uint8_t uuid[16];
    uint32_t domid;
    uint8_t dying:1;
    uint8_t paused:1;
    uint8_t running:1;
    uint64_t max_memkb;
    uint64_t cpu_time;
    uint32_t vcpu_max_id;
    uint32_t vcpu_online;
};

struct libxl_poolinfo {
    uint32_t poolid;
};

struct libxl_vminfo {
    uint8_t uuid[16];
    uint32_t domid;
};

typedef struct {
    int xen_version_major;
    int xen_version_minor;
    char *xen_version_extra;
    char *compiler;
    char *compile_by;
    char *compile_domain;
    char *compile_date;
    char *capabilities;
    char *changeset;
    unsigned long virt_start;
    unsigned long pagesize;
    char *commandline;
} libxl_version_info;

struct libxl_ctx {
    xentoollog_logger *lg;
    xc_interface *xch;
    struct xs_handle *xsh;

    /* mini-GC */
    int alloc_maxsize;
    void **alloc_ptrs;

    /* for callers who reap children willy-nilly; caller must only
     * set this after libxl_init and before any other call - or
     * may leave them untouched */
    int (*waitpid_instead)(pid_t pid, int *status, int flags);
    libxl_version_info version_info;
};

const libxl_version_info* libxl_get_version_info(struct libxl_ctx *ctx);

typedef struct {
    bool hvm;
    bool hap;
    bool oos;
    int ssidref;
    char *name;
    uint8_t uuid[16];
    char **xsdata;
    char **platformdata;
    uint32_t poolid;
    char *poolname;
} libxl_domain_create_info;

typedef struct {
    /*
     * Path is always set if the file refernece is valid. However if
     * mapped is true then the actual file may already be unlinked.
     */
    char *path;
    int mapped;
    void *data;
    size_t size;
} libxl_file_reference;

/*
 * Instances of libxl_file_reference contained in this struct which
 * have been mapped (with libxl_file_reference_map) will be unmapped
 * by libxl_domain_build/restore. If either of these are never called
 * then the user is responsible for calling
 * libxl_file_reference_unmap.
 */
typedef struct {
    int max_vcpus;
    int cur_vcpus;
    int tsc_mode;
    uint32_t max_memkb;
    uint32_t target_memkb;
    uint32_t video_memkb;
    uint32_t shadow_memkb;
    bool disable_migrate;
    libxl_file_reference kernel;
    int hvm;
    union {
        struct {
            bool pae;
            bool apic;
            bool acpi;
            bool nx;
            bool viridian;
            char *timeoffset;
            bool hpet;
            bool vpt_align;
            int timer_mode;
        } hvm;
        struct {
            uint32_t   slack_memkb;
            const char *bootloader;
            const char *bootloader_args;
            char *cmdline;
            libxl_file_reference ramdisk;
            const char *features;
        } pv;
    } u;
} libxl_domain_build_info;

typedef struct {
    uint32_t store_port;
    unsigned long store_mfn;
    uint32_t console_port;
    unsigned long console_mfn;
} libxl_domain_build_state;

typedef struct {
#define XL_SUSPEND_DEBUG 1
#define XL_SUSPEND_LIVE 2
    int flags;
    int (*suspend_callback)(void *, int);
} libxl_domain_suspend_info;

typedef enum {
    XENFV = 1,
    XENPV,
} libxl_qemu_machine_type;

typedef struct {
    int domid;
    uint8_t uuid[16]; /* this is use only with stubdom, and must be different from the domain uuid */
    char *dom_name;
    char *device_model;
    char *saved_state;
    libxl_qemu_machine_type type;
    int videoram; /* size of the videoram in MB */
    bool stdvga; /* stdvga enabled or disabled */
    bool vnc; /* vnc enabled or disabled */
    char *vnclisten; /* address:port that should be listened on for the VNC server if vnc is set */
    char *vncpasswd; /* the VNC password */
    int vncdisplay; /* set VNC display number */
    bool vncunused; /* try to find an unused port for the VNC server */
    char *keymap; /* set keyboard layout, default is en-us keyboard */
    bool sdl; /* sdl enabled or disabled */
    bool opengl; /* opengl enabled or disabled (if enabled requires sdl enabled) */
    bool nographic; /* no graphics, use serial port */
    char *serial; /* serial port re-direct to pty deivce */
    char *boot; /* boot order, for example dca */
    bool usb; /* usb support enabled or disabled */
    char *usbdevice; /* enable usb mouse: tablet for absolute mouse, mouse for PS/2 protocol relative mouse */
    char *soundhw; /* enable sound hardware */
    bool apic; /* apic enabled or disabled */
    int vcpus; /* max number of vcpus */
    int vcpu_avail; /* vcpus actually available */
    int xen_platform_pci; /* enable/disable the xen platform pci device */
    char **extra; /* extra parameters pass directly to qemu, NULL terminated */
    /* Network is missing */
} libxl_device_model_info;

typedef struct {
    uint32_t backend_domid;
    uint32_t domid;
    int devid;
    bool vnc; /* vnc enabled or disabled */
    char *vnclisten; /* address:port that should be listened on for the VNC server if vnc is set */
    char *vncpasswd; /* the VNC password */
    int vncdisplay; /* set VNC display number */
    bool vncunused; /* try to find an unused port for the VNC server */
    char *keymap; /* set keyboard layout, default is en-us keyboard */
    bool sdl; /* sdl enabled or disabled */
    bool opengl; /* opengl enabled or disabled (if enabled requires sdl enabled) */
    char *display;
    char *xauthority;
} libxl_device_vfb;

typedef struct {
    uint32_t backend_domid;
    uint32_t domid;
    int devid;
} libxl_device_vkb;

typedef enum {
    CONSTYPE_XENCONSOLED,
    CONSTYPE_IOEMU,
} libxl_console_constype;

typedef struct {
    uint32_t backend_domid;
    uint32_t domid;
    int devid;
    libxl_console_constype constype;
    libxl_domain_build_state *build_state;
} libxl_device_console;

typedef enum {
    PHYSTYPE_QCOW = 1,
    PHYSTYPE_QCOW2,
    PHYSTYPE_VHD,
    PHYSTYPE_AIO,
    PHYSTYPE_FILE,
    PHYSTYPE_PHY,
} libxl_disk_phystype;

typedef struct {
    uint32_t backend_domid;
    uint32_t domid;
    char *physpath;
    libxl_disk_phystype phystype;
    char *virtpath;
    int unpluggable;
    int readwrite;
    int is_cdrom;
} libxl_device_disk;

typedef enum {
    NICTYPE_IOEMU = 1,
    NICTYPE_VIF,
} libxl_nic_type;

typedef struct {
    uint32_t backend_domid;
    uint32_t domid;
    int devid;
    int mtu;
    char *model;
    uint8_t mac[6];
    struct in_addr ip;
    char *bridge;
    char *ifname;
    char *script;
    libxl_nic_type nictype;
} libxl_device_nic;

typedef struct {
    int devid;
    uint8_t front_mac[6];
    uint8_t back_mac[6];
    uint32_t backend_domid;
    uint32_t domid;
    uint32_t trusted:1;
    uint32_t back_trusted:1;
    uint32_t filter_mac:1;
    uint32_t front_filter_mac:1;
    uint32_t pdev;
    uint32_t max_bypasses;
    char *bridge;
} libxl_device_net2;

typedef struct  {
    union {
        unsigned int value;
        struct {
            unsigned int reserved1:2;
            unsigned int reg:6;
            unsigned int func:3;
            unsigned int dev:5;
            unsigned int bus:8;
            unsigned int reserved2:7;
            unsigned int enable:1;
        };
    };
    unsigned int domain;
    unsigned int vdevfn;
    bool msitranslate;
    bool power_mgmt;
} libxl_device_pci;

enum {
    ERROR_VERSION = -1,
    ERROR_FAIL = -2,
    ERROR_NI = -3,
    ERROR_NOMEM = -4,
    ERROR_INVAL = -5,
    ERROR_BADFAIL = -6,
};

#define LIBXL_VERSION 0

/* context functions */
int libxl_ctx_init(struct libxl_ctx *ctx, int version, xentoollog_logger*);
int libxl_ctx_free(struct libxl_ctx *ctx);
int libxl_ctx_set_log(struct libxl_ctx *ctx, xentoollog_logger*);
int libxl_ctx_postfork(struct libxl_ctx *ctx);

/* domain related functions */
int libxl_domain_make(struct libxl_ctx *ctx, libxl_domain_create_info *info, uint32_t *domid);
int libxl_domain_build(struct libxl_ctx *ctx, libxl_domain_build_info *info, uint32_t domid, /* out */ libxl_domain_build_state *state);
int libxl_domain_restore(struct libxl_ctx *ctx, libxl_domain_build_info *info,
                         uint32_t domid, int fd, libxl_domain_build_state *state,
                         libxl_device_model_info *dm_info);
int libxl_domain_suspend(struct libxl_ctx *ctx, libxl_domain_suspend_info *info,
                          uint32_t domid, int fd);
int libxl_domain_resume(struct libxl_ctx *ctx, uint32_t domid);
int libxl_domain_shutdown(struct libxl_ctx *ctx, uint32_t domid, int req);
int libxl_domain_destroy(struct libxl_ctx *ctx, uint32_t domid, int force);

int libxl_file_reference_map(struct libxl_ctx *ctx, libxl_file_reference *f);
int libxl_file_reference_unmap(struct libxl_ctx *ctx, libxl_file_reference *f);

/*
 * Run the configured bootloader for a PV domain and update
 * info->kernel, info->u.pv.ramdisk and info->u.pv.cmdline as
 * appropriate (any initial values present in these fields must have
 * been allocated with malloc).
 *
 * Is a NOP on non-PV domains or those with no bootloader configured.
 *
 * Users should call libxl_file_reference_unmap on the kernel and
 * ramdisk to cleanup or rely on libxl_domain_{build,restore} to do
 * it.
 */
int libxl_run_bootloader(struct libxl_ctx *ctx,
                         libxl_domain_build_info *info,
                         libxl_device_disk *disk,
                         uint32_t domid);

char *libxl_uuid2string(struct libxl_ctx *ctx, uint8_t uuid[16]);
  /* 0 means ERROR_ENOMEM, which we have logged */

/* events handling */

typedef enum {
    DOMAIN_DEATH,
    DISK_EJECT,
} libxl_event_type;

typedef struct {
    /* event type */
    libxl_event_type type;
    /* data for internal use of the library */
    char *path;
    char *token;
} libxl_event;

typedef struct {
    char *path;
    char *token;
} libxl_waiter;


int libxl_get_wait_fd(struct libxl_ctx *ctx, int *fd);
/* waiter is allocated by the caller */
int libxl_wait_for_domain_death(struct libxl_ctx *ctx, uint32_t domid, libxl_waiter *waiter);
/* waiter is a preallocated array of num_disks libxl_waiter elements */
int libxl_wait_for_disk_ejects(struct libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disks, int num_disks, libxl_waiter *waiter);
int libxl_get_event(struct libxl_ctx *ctx, libxl_event *event);
int libxl_stop_waiting(struct libxl_ctx *ctx, libxl_waiter *waiter);
int libxl_free_event(libxl_event *event);
int libxl_free_waiter(libxl_waiter *waiter);

int libxl_event_get_domain_death_info(struct libxl_ctx *ctx, uint32_t domid, libxl_event *event, xc_domaininfo_t *info);
int libxl_event_get_disk_eject_info(struct libxl_ctx *ctx, uint32_t domid, libxl_event *event, libxl_device_disk *disk);

int libxl_domain_rename(struct libxl_ctx *ctx, uint32_t domid,
                        const char *old_name, const char *new_name,
                        xs_transaction_t trans);
  /* if old_name is NULL, any old name is OK; otherwise we check
   * transactionally that the domain has the old old name; if
   * trans is not 0 we use caller's transaction and caller must do retries */

int libxl_domain_pause(struct libxl_ctx *ctx, uint32_t domid);
int libxl_domain_unpause(struct libxl_ctx *ctx, uint32_t domid);

int libxl_domain_core_dump(struct libxl_ctx *ctx, uint32_t domid, const char *filename);

int libxl_domain_setmaxmem(struct libxl_ctx *ctx, uint32_t domid, uint32_t target_memkb);
int libxl_set_memory_target(struct libxl_ctx *ctx, uint32_t domid, uint32_t target_memkb, int enforce);

int libxl_vncviewer_exec(struct libxl_ctx *ctx, uint32_t domid, int autopass);
int libxl_console_exec(struct libxl_ctx *ctx, uint32_t domid, int cons_num);
/* libxl_primary_console_exec finds the domid and console number
 * corresponding to the primary console of the given vm, then calls
 * libxl_console_exec with the right arguments (domid might be different
 * if the guest is using stubdoms).
 * This function can be called after creating the device model, in
 * case of HVM guests, and before libxl_run_bootloader in case of PV
 * guests using pygrub. */ 
int libxl_primary_console_exec(struct libxl_ctx *ctx, uint32_t domid_vm);

int libxl_domain_info(struct libxl_ctx*, struct libxl_dominfo *info_r,
                      uint32_t domid);
struct libxl_dominfo * libxl_list_domain(struct libxl_ctx*, int *nb_domain);
struct libxl_poolinfo * libxl_list_pool(struct libxl_ctx*, int *nb_pool);
struct libxl_vminfo * libxl_list_vm(struct libxl_ctx *ctx, int *nb_vm);

typedef struct libxl_device_model_starting libxl_device_model_starting;
int libxl_create_device_model(struct libxl_ctx *ctx,
                              libxl_device_model_info *info,
                              libxl_device_disk *disk, int num_disks,
                              libxl_device_nic *vifs, int num_vifs,
                              libxl_device_model_starting **starting_r);
int libxl_create_xenpv_qemu(struct libxl_ctx *ctx, libxl_device_vfb *vfb,
                            int num_console, libxl_device_console *console,
                            libxl_device_model_starting **starting_r);
  /* Caller must either: pass starting_r==0, or on successful
   * return pass *starting_r (which will be non-0) to
   * libxl_confirm_device_model or libxl_detach_device_model. */
int libxl_confirm_device_model_startup(struct libxl_ctx *ctx,
                              libxl_device_model_starting *starting);
int libxl_detach_device_model(struct libxl_ctx *ctx,
                              libxl_device_model_starting *starting);
  /* DM is detached even if error is returned */

typedef struct {
    char *backend;
    uint32_t backend_id;
    char *frontend;
    uint32_t frontend_id;
    int devid;
    int state;
    int evtch;
    int rref;
} libxl_diskinfo;

int libxl_device_disk_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk);
int libxl_device_disk_del(struct libxl_ctx *ctx, libxl_device_disk *disk, int wait);
libxl_device_disk *libxl_device_disk_list(struct libxl_ctx *ctx, uint32_t domid, int *num);
int libxl_device_disk_getinfo(struct libxl_ctx *ctx, uint32_t domid,
                              libxl_device_disk *disk, libxl_diskinfo *diskinfo);
int libxl_cdrom_insert(struct libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk);

/*
 * Make a disk available in this domain. Returns path to a device.
 */
const char * libxl_device_disk_local_attach(struct libxl_ctx *ctx, libxl_device_disk *disk);
int libxl_device_disk_local_detach(struct libxl_ctx *ctx, libxl_device_disk *disk);

typedef struct {
    char *backend;
    uint32_t backend_id;
    char *frontend;
    uint32_t frontend_id;
    int devid;
    int state;
    char *script;
    uint8_t mac[6];
    int evtch;
    int rref_tx;
    int rref_rx;
} libxl_nicinfo;

int libxl_device_nic_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic);
int libxl_device_nic_del(struct libxl_ctx *ctx, libxl_device_nic *nic, int wait);
libxl_nicinfo *libxl_list_nics(struct libxl_ctx *ctx, uint32_t domid, unsigned int *nb);

int libxl_device_console_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_console *console);

int libxl_device_vkb_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_vkb *vkb);
int libxl_device_vkb_clean_shutdown(struct libxl_ctx *ctx, uint32_t domid);
int libxl_device_vkb_hard_shutdown(struct libxl_ctx *ctx, uint32_t domid);

int libxl_device_vfb_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_vfb *vfb);
int libxl_device_vfb_clean_shutdown(struct libxl_ctx *ctx, uint32_t domid);
int libxl_device_vfb_hard_shutdown(struct libxl_ctx *ctx, uint32_t domid);

#define PCI_BDF                "%04x:%02x:%02x.%01x"
#define PCI_BDF_VDEVFN         "%04x:%02x:%02x.%01x@%02x"
int libxl_device_pci_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev);
int libxl_device_pci_remove(struct libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev);
int libxl_device_pci_shutdown(struct libxl_ctx *ctx, uint32_t domid);
libxl_device_pci *libxl_device_pci_list(struct libxl_ctx *ctx, uint32_t domid, int *num);
int libxl_device_pci_init(libxl_device_pci *pcidev, unsigned int domain,
                          unsigned int bus, unsigned int dev,
                          unsigned int func, unsigned int vdevfn);

/*
 * Functions for allowing users of libxl to store private data
 * relating to a domain.  The data is an opaque sequence of bytes and
 * is not interpreted or used by libxl.
 *
 * Data is indexed by the userdata userid, which is a short printable
 * ASCII string.  The following list is a registry of userdata userids
 * (the registry may be updated by posting a patch to xen-devel):
 *
 *  userid      Data contents
 *   "xl"        domain config file in xl format, Unix line endings
 *
 * libxl does not enforce the registration of userdata userids or the
 * semantics of the data.  For specifications of the data formats
 * see the code or documentation for the libxl caller in question.
 */
int libxl_userdata_store(struct libxl_ctx *ctx, uint32_t domid,
                              const char *userdata_userid,
                              const uint8_t *data, int datalen);
  /* If datalen==0, data is not used and the user data for
   * that domain and userdata_userid is deleted. */
int libxl_userdata_retrieve(struct libxl_ctx *ctx, uint32_t domid,
                                 const char *userdata_userid,
                                 uint8_t **data_r, int *datalen_r);
  /* On successful return, *data_r is from malloc.
   * If there is no data for that domain and userdata_userid,
   * *data_r and *datalen_r will be set to 0.
   * data_r and datalen_r may be 0.
   * On error return, *data_r and *datalen_r are undefined.
   */

typedef enum {
    POWER_BUTTON,
    SLEEP_BUTTON
} libxl_button;

int libxl_button_press(struct libxl_ctx *ctx, uint32_t domid, libxl_button button);

struct libxl_vcpuinfo {
    uint32_t vcpuid; /* vcpu's id */
    uint32_t cpu; /* current mapping */
    uint8_t online:1; /* currently online (not hotplugged)? */
    uint8_t blocked:1; /* blocked waiting for an event? */
    uint8_t running:1; /* currently scheduled on its CPU? */
    uint64_t vcpu_time; /* total vcpu time ran (ns) */
    uint64_t *cpumap; /* current cpu's affinities */
};

struct libxl_physinfo {
    uint32_t threads_per_core;
    uint32_t cores_per_socket;

    uint32_t max_cpu_id;
    uint32_t nr_cpus;
    uint32_t cpu_khz;

    uint64_t total_pages;
    uint64_t free_pages;
    uint64_t scrub_pages;

    uint32_t nr_nodes;
    uint32_t hw_cap[8];
    uint32_t phys_cap;
};

int libxl_get_physinfo(struct libxl_ctx *ctx, struct libxl_physinfo *physinfo);
struct libxl_vcpuinfo *libxl_list_vcpu(struct libxl_ctx *ctx, uint32_t domid,
                                       int *nb_vcpu, int *cpusize);
int libxl_set_vcpuaffinity(struct libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,
                           uint64_t *cpumap, int cpusize);
int libxl_set_vcpucount(struct libxl_ctx *ctx, uint32_t domid, uint32_t count);

int libxl_get_sched_id(struct libxl_ctx *ctx);


struct libxl_sched_credit {
    int weight;
    int cap;
};

int libxl_sched_credit_domain_get(struct libxl_ctx *ctx, uint32_t domid,
                                  struct libxl_sched_credit *scinfo);
int libxl_sched_credit_domain_set(struct libxl_ctx *ctx, uint32_t domid,
                                  struct libxl_sched_credit *scinfo);
int libxl_send_trigger(struct libxl_ctx *ctx, uint32_t domid,
                       char *trigger_name, uint32_t vcpuid);
int libxl_send_sysrq(struct libxl_ctx *ctx, uint32_t domid, char sysrq);
int libxl_send_debug_keys(struct libxl_ctx *ctx, char *keys);

struct libxl_xen_console_reader {
    char *buffer;
    unsigned int size;
    unsigned int count;
    unsigned int clear;
    unsigned int incremental;
    unsigned int index;
};

struct libxl_xen_console_reader *
    libxl_xen_console_read_start(struct libxl_ctx *ctx, int clear);
int libxl_xen_console_read_line(struct libxl_ctx *ctx,
                                struct libxl_xen_console_reader *cr,
                                char **line_r);
void libxl_xen_console_read_finish(struct libxl_ctx *ctx,
                                   struct libxl_xen_console_reader *cr);

uint32_t libxl_vm_get_start_time(struct libxl_ctx *ctx, uint32_t domid);

char *libxl_tmem_list(struct libxl_ctx *ctx, uint32_t domid, int use_long);
int libxl_tmem_freeze(struct libxl_ctx *ctx, uint32_t domid);
int libxl_tmem_destroy(struct libxl_ctx *ctx, uint32_t domid);
int libxl_tmem_thaw(struct libxl_ctx *ctx, uint32_t domid);
int libxl_tmem_set(struct libxl_ctx *ctx, uint32_t domid, char* name,
                   uint32_t set);
int libxl_tmem_shared_auth(struct libxl_ctx *ctx, uint32_t domid, char* uuid,
                           int auth);
int libxl_tmem_freeable(struct libxl_ctx *ctx);

typedef struct {
    char *backend;
    uint32_t backend_id;
    char *frontend;
    uint32_t frontend_id;
    int devid;
    int state;
    uint8_t mac[6];
    int trusted;
    uint8_t back_mac[6];
    int filter_mac;
} libxl_net2info;

int libxl_device_net2_add(struct libxl_ctx *ctx, uint32_t domid,
                          libxl_device_net2 *net2);
libxl_net2info *libxl_device_net2_list(struct libxl_ctx *ctx, uint32_t domid,
                                       unsigned int *nb);
int libxl_device_net2_del(struct libxl_ctx *ctx, libxl_device_net2 *net2,
                          int wait);

/* common paths */
const char *libxl_sbindir_path(void);
const char *libxl_bindir_path(void);
const char *libxl_libexec_path(void);
const char *libxl_libdir_path(void);
const char *libxl_sharedir_path(void);
const char *libxl_private_bindir_path(void);
const char *libxl_xenfirmwaredir_path(void);
const char *libxl_xen_config_dir_path(void);
const char *libxl_xen_script_dir_path(void);

#endif /* LIBXL_H */