Commit e8cb9fbd authored by Yathindra Naik's avatar Yathindra Naik

This commit has the 'explicit grant model for xenstore'.

- Previously, child nodes of directories inherited their parents capabilities.
- xc_get_caps gets the caps for a particular path/node from xenstore.
- This is then granted using xc_cap_grant API.
- As of now, we observe a timeout for backened driver.
parent b78094ea
......@@ -53,11 +53,11 @@
#include "list.h"
#include "xs_api.h"
#if 0
//#if 0
#define DPRINTF(_f, _a...) printf ( _f , ## _a )
#else
#define DPRINTF(_f, _a...) ((void)0)
#endif
//#else
//#define DPRINTF(_f, _a...) ((void)0)
//#endif
struct backend_info
{
......
......@@ -116,7 +116,7 @@ do_start () {
test "`uname`" != "NetBSD" || xenbackendd $XENBACKENDD_ARGS
echo Starting QEMU as disk backend for dom0
test -z "$QEMU_XEN" && QEMU_XEN=/usr/lib/xen/bin/qemu-system-i386
$QEMU_XEN -xen-domid 0 -xen-attach -name dom0 -nographic -M xenpv -daemonize -monitor /dev/null
$QEMU_XEN -D /tmp/ -xen-domid 0 -xen-attach -name dom0 -nographic -M xenpv -daemonize -monitor /dev/null
}
do_stop () {
echo Stopping xenconsoled
......
This diff is collapsed.
......@@ -482,8 +482,13 @@ static void bootloader_gotptys(libxl__egc *egc, libxl__openpty_state *op)
dom_console_xs_path = GCSPRINTF("%s/console/tty", dompath);
#ifdef CONFIG_XENCAP
rc = libxl__xs_write(gc, XBT_NULL, bl->domid, 'r', dom_console_xs_path, "%s",
dom_console_slave_tty_path);
#else
rc = libxl__xs_write(gc, XBT_NULL, dom_console_xs_path, "%s",
dom_console_slave_tty_path);
#endif
if (rc) {
LOGE(ERROR,"xs write console path %s := %s failed",
dom_console_xs_path, dom_console_slave_tty_path);
......
/*
* Copyright (C) 2010 Citrix Ltd.
* Author Vincent Hanquez <vincent.hanquez@eu.citrix.com>
......@@ -394,7 +395,10 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_create_info *info, libxl_capa
xs_transaction_t t = 0;
xen_domain_handle_t handle;
libxl_vminfo *vm_list;
#ifdef CONFIG_XENCAP
struct capability *caps;
struct capability list[2];
#endif
assert(!libxl_domid_valid_guest(*domid));
......@@ -430,12 +434,12 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_create_info *info, libxl_capa
#ifdef CONFIG_XENCAP
if ( cap != NULL )
{
ret = libxl_domain_setcap(ctx, cap, *domid);
if (ret) {
LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "cannot grant capabilities: %d", ret);
rc = ERROR_FAIL;
goto out;
}
ret = libxl_domain_setcap(ctx, cap, *domid);
if (ret) {
LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "cannot grant capabilities: %d", ret);
rc = ERROR_FAIL;
goto out;
}
}
#endif
ret = xc_cpupool_movedomain(ctx->xch, info->poolid, *domid);
......@@ -483,11 +487,29 @@ retry_transaction:
xs_rm(ctx->xsh, t, vm_path);
libxl__xs_mkdir(gc, t, vm_path, roperm, ARRAY_SIZE(roperm));
xs_rm(ctx->xsh, t, libxl_path);
libxl__xs_mkdir(gc, t, libxl_path, noperm, ARRAY_SIZE(noperm));
xs_write(ctx->xsh, t, libxl__sprintf(gc, "%s/vm", dom_path), vm_path, strlen(vm_path));
#ifdef CONFIG_XENCAP
caps = xs_get_caps(ctx->xsh, t, libxl__sprintf(gc, "%s/vm", dom_path));
if (caps == NULL)
LOG(ERROR, "Caps for %s is NULL!\n",dom_path);
if (!xc_cap_check(ctx->xch, *domid, 2, &caps[0])) {
list[0] = caps[0];
LOG(DEBUG, "Granting caps for %s/vm\n",dom_path);
LOG(DEBUG, "caps[0]: %d caps[1]: %d\n",caps[0].magic, caps[1].magic);
if (xc_cap_grant(ctx->xch, *domid, 2, &list, 1))
LOG(ERROR, "Granting caps for %s/vm failed\n",dom_path);
}
// delete this
if (!xc_cap_check(ctx->xch, *domid, 2, &caps[1])) {
list[0] = caps[1];
if (xc_cap_grant(ctx->xch, *domid, 2, &list, 1))
LOG(ERROR, "Granting caps for %s/vm failed\n",dom_path);
}
#endif
rc = libxl__domain_rename(gc, *domid, 0, info->name, t);
if (rc)
goto out;
......@@ -515,6 +537,18 @@ retry_transaction:
libxl__xs_mkdir(gc, t,
libxl__sprintf(gc, "%s/device/suspend/event-channel", dom_path),
rwperm, ARRAY_SIZE(rwperm));
#ifdef CONFIG_XENCAP
caps = xs_get_caps(ctx->xsh, t, libxl__sprintf(gc, "%s/device/suspend", dom_path));
if (caps == NULL)
LOG(ERROR, "Caps for %s/device/suspend is NULL!\n",dom_path);
if (!xc_cap_check(ctx->xch, *domid, 2, &caps[0])) {
list[0] = caps[0];
LOG(DEBUG, "Granting caps for %s/device/suspend\n",dom_path);
LOG(DEBUG, "caps[0]: %d caps[1]: %d\n",caps[0].magic, caps[1].magic);
if (xc_cap_grant(ctx->xch, *domid, 2, &list, 1))
LOG(ERROR, "Granting caps for %s/device/suspend failed\n",dom_path);
}
#endif
libxl__xs_mkdir(gc, t,
libxl__sprintf(gc, "%s/data", dom_path),
rwperm, ARRAY_SIZE(rwperm));
......@@ -550,6 +584,9 @@ retry_transaction:
LOGE(ERROR, "unable to write %s = 1", DISABLE_UDEV_PATH);
goto out;
}
#ifdef CONFIG_XENCAP
//xs_cap_grant(gc, t, DISABLE_UDEV_PATH, domid);
#endif
} else {
rc = libxl__xs_rm_checked(gc, t, DISABLE_UDEV_PATH);
if (rc) {
......@@ -560,12 +597,86 @@ retry_transaction:
xs_write(ctx->xsh, t, libxl__sprintf(gc, "%s/uuid", vm_path), uuid_string, strlen(uuid_string));
xs_write(ctx->xsh, t, libxl__sprintf(gc, "%s/name", vm_path), info->name, strlen(info->name));
#ifdef CONFIG_XENCAP
caps = xs_get_caps(ctx->xsh, t, libxl__sprintf(gc, "%s/uuid", vm_path));
if (caps == NULL)
LOG(ERROR, "Caps for %s/uuid is NULL!\n",vm_path);
if (!xc_cap_check(ctx->xch, *domid, 2, &caps[0])) {
list[0] = caps[0];
LOG(DEBUG, "Granting caps for %s/uuid\n",vm_path);
LOG(DEBUG, "caps[0]: %d caps[1]: %d\n",caps[0].magic, caps[1].magic);
if (xc_cap_grant(ctx->xch, *domid, 2, &list, 1))
LOG(ERROR, "Granting caps for %s/uuid failed\n",vm_path);
}
//delete this
if (!xc_cap_check(ctx->xch, *domid, 2, &caps[1])) {
list[0] = caps[1];
if (xc_cap_grant(ctx->xch, *domid, 2, &list, 1))
LOG(ERROR, "Granting caps for %s/uuid failed\n",vm_path);
}
caps = xs_get_caps(ctx->xsh, t, libxl__sprintf(gc, "%s/name", vm_path));
if (caps == NULL)
LOG(ERROR, "Caps for %s/name is NULL!\n",vm_path);
if (!xc_cap_check(ctx->xch, *domid, 2, &caps[0])) {
list[0] = caps[0];
LOG(DEBUG, "Granting caps for %s/name\n",vm_path);
LOG(DEBUG, "caps[0]: %d caps[1]: %d\n",caps[0].magic, caps[1].magic);
if (xc_cap_grant(ctx->xch, *domid, 2, &list, 1))
LOG(ERROR, "Granting caps for %s/name failed\n",vm_path);
}
//delete this
if (!xc_cap_check(ctx->xch, *domid, 2, &caps[1])) {
list[0] = caps[1];
if (xc_cap_grant(ctx->xch, *domid, 2, &list, 1))
LOG(ERROR, "Granting caps for %s/name failed\n",vm_path);
}
#endif
#ifdef CONFIG_XENCAP
libxl__xs_writev(gc, t, dom_path, info->xsdata, *domid, 'r');
libxl__xs_writev(gc, t, libxl__sprintf(gc, "%s/platform", dom_path), info->platformdata, *domid, 'r');
#else
libxl__xs_writev(gc, t, dom_path, info->xsdata);
libxl__xs_writev(gc, t, libxl__sprintf(gc, "%s/platform", dom_path), info->platformdata);
#endif
xs_write(ctx->xsh, t, libxl__sprintf(gc, "%s/control/platform-feature-multiprocessor-suspend", dom_path), "1", 1);
xs_write(ctx->xsh, t, libxl__sprintf(gc, "%s/control/platform-feature-xs_reset_watches", dom_path), "1", 1);
#ifdef CONFIG_XENCAP
caps = xs_get_caps(ctx->xsh, t, libxl__sprintf(gc, "%s/control/platform-feature-multiprocessor-suspend", dom_path));
if (caps == NULL)
LOG(ERROR, "Caps for %s/control/platform-feature-multiprocessor-suspend is NULL", dom_path);
if (!xc_cap_check(ctx->xch, *domid, 2, &caps[0])) {
list[0] = caps[0];
LOG(DEBUG, "Granting caps for %s/control/platform-feature-multiprocessor-suspend", dom_path);
LOG(DEBUG, "caps[0]: %d caps[1]: %d\n",caps[0].magic, caps[1].magic);
if (xc_cap_grant(ctx->xch, *domid, 2, &list, 1))
LOG(ERROR, "Granting caps for %s/control/platform-feature-multiprocessor-suspend is NULL", dom_path);
}
//delete this
if (!xc_cap_check(ctx->xch, *domid, 2, &caps[1])) {
list[0] = caps[1];
if (xc_cap_grant(ctx->xch, *domid, 2, &list, 1))
LOG(ERROR, "Granting caps for %s/control/platform-feature-multiprocessor-suspend is NULL", dom_path);
}
caps = xs_get_caps(ctx->xsh, t, libxl__sprintf(gc, "%s/control/platform-feature-xs_reset_watches", dom_path));
if (caps == NULL)
LOG(ERROR, "Caps for %s/control/platform-feature-xs_reset_watches is NULL", dom_path);
if (!xc_cap_check(ctx->xch, *domid, 2, &caps[0])) {
list[0] = caps[0];
LOG(DEBUG, "Granting caps for %s/control/platform-feature-xs_reset_watches", dom_path);
LOG(DEBUG, "caps[0]: %d caps[1]: %d\n",caps[0].magic, caps[1].magic);
if (xc_cap_grant(ctx->xch, *domid, 2, &list, 1))
LOG(ERROR, "Granting caps for %s/control/platform-feature-xs_reset_watches is NULL", dom_path);
}
// delete this
if (!xc_cap_check(ctx->xch, *domid, 2, &caps[1])) {
list[0] = caps[1];
if (xc_cap_grant(ctx->xch, *domid, 2, &list, 1))
LOG(ERROR, "Granting caps for %s/control/platform-feature-multiprocessor-suspend is NULL", dom_path);
}
#endif
if (!xs_transaction_end(ctx->xsh, t, 0)) {
if (errno == EAGAIN) {
t = 0;
......@@ -591,8 +702,14 @@ static int store_libxl_entry(libxl__gc *gc, uint32_t domid,
path = libxl__xs_libxl_path(gc, domid);
path = libxl__sprintf(gc, "%s/dm-version", path);
#ifdef CONFIG_XENCAP
return libxl__xs_write(gc, XBT_NULL, 0, 'b', path, "%s",
libxl_device_model_version_to_string(b_info->device_model_version));
#else
return libxl__xs_write(gc, XBT_NULL, path, "%s",
libxl_device_model_version_to_string(b_info->device_model_version));
#endif
}
/*----- main domain creation -----*/
......
......@@ -31,6 +31,20 @@ char *libxl__device_frontend_path(libxl__gc *gc, libxl__device *device)
device->devid);
}
#ifdef CONFIG_XENCAP
char *libxl__device_frontend_child(libxl__gc *gc, libxl__device *device)
{
char *dom_path = libxl__xs_get_dompath(gc, device->domid);
/* Console 0 is a special case */
if (device->kind == LIBXL__DEVICE_KIND_CONSOLE && device->devid == 0)
return libxl__sprintf(gc, "%s/console", dom_path);
return libxl__sprintf(gc, "%s/device/%s", dom_path,
libxl__device_kind_to_string(device->kind));
}
#endif
char *libxl__device_backend_path(libxl__gc *gc, libxl__device *device)
{
char *dom_path = libxl__xs_get_dompath(gc, device->backend_domid);
......@@ -88,12 +102,22 @@ int libxl__device_generic_add(libxl__gc *gc, xs_transaction_t t,
{
libxl_ctx *ctx = libxl__gc_owner(gc);
char *frontend_path, *backend_path;
#ifdef CONFIG_XENCAP
char *frontend_child;
#endif
struct xs_permissions frontend_perms[2];
struct xs_permissions backend_perms[2];
int create_transaction = t == XBT_NULL;
#ifdef CONFIG_XENCAP
struct capability *caps;
struct capability list[2];
#endif
frontend_path = libxl__device_frontend_path(gc, device);
backend_path = libxl__device_backend_path(gc, device);
#ifdef CONFIG_XENCAP
frontend_child = libxl__device_frontend_child(gc, device);
#endif
frontend_perms[0].id = device->domid;
frontend_perms[0].perms = XS_PERM_NONE;
......@@ -115,7 +139,45 @@ retry_transaction:
xs_mkdir(ctx->xsh, t, frontend_path);
xs_set_permissions(ctx->xsh, t, frontend_path, frontend_perms, ARRAY_SIZE(frontend_perms));
xs_write(ctx->xsh, t, libxl__sprintf(gc, "%s/backend", frontend_path), backend_path, strlen(backend_path));
#ifdef CONFIG_XENCAP
caps = xs_get_caps(ctx->xsh, t, libxl__sprintf(gc, "%s/backend",frontend_path));
if (caps == NULL)
LOG(ERROR, "Caps for %s/backend is NULL!\n",frontend_path);
if (!xc_cap_check(ctx->xch, device->domid, 2, &caps[0])) {
list[0] = caps[0];
LOG(DEBUG, "Granting caps for domid %d for %s/backend\n",device->domid, frontend_path);
LOG(DEBUG, "caps[0]: %d\n",caps[0].magic);
if (xc_cap_grant(ctx->xch, device->domid, 2, &list, 1))
LOG(DEBUG, "Granting caps for %s/backend failed\n",frontend_path);
}
if (!xc_cap_check(ctx->xch, device->domid, 2, &caps[1])) {
list[0] = caps[1];
LOG(DEBUG, "caps[1]: %d\n", caps[1].magic);
if (xc_cap_grant(ctx->xch, device->domid, 2, &list, 1))
LOG(DEBUG, "Granting caps for %s/backend failed\n",frontend_path);
}
caps = xs_get_caps(ctx->xsh, t, frontend_child);
if (caps == NULL)
LOG(ERROR, "Caps for %s is NULL!\n",frontend_child);
if (!xc_cap_check(ctx->xch, device->domid, 2, &caps[0])) {
list[0] = caps[0];
LOG(DEBUG, "Granting caps for domid %d for %s\n",device->domid, frontend_child);
LOG(DEBUG, "caps[0]: %d\n",caps[0].magic);
if (xc_cap_grant(ctx->xch, device->domid, 2, &list, 1))
LOG(DEBUG, "Granting caps for %s failed\n",frontend_child);
}
//delete this
if (!xc_cap_check(ctx->xch, device->domid, 2, &caps[1])) {
list[0] = caps[1];
if (xc_cap_grant(ctx->xch, device->domid, 2, &list, 1))
LOG(DEBUG, "Granting caps for %s failed\n",frontend_child);
}
#endif
#ifdef CONFIG_XENCAP
libxl__xs_writev(gc, t, frontend_path, fents, device->domid, 'b');
#else
libxl__xs_writev(gc, t, frontend_path, fents);
#endif
}
if (bents) {
......@@ -123,7 +185,29 @@ retry_transaction:
xs_mkdir(ctx->xsh, t, backend_path);
xs_set_permissions(ctx->xsh, t, backend_path, backend_perms, ARRAY_SIZE(backend_perms));
xs_write(ctx->xsh, t, libxl__sprintf(gc, "%s/frontend", backend_path), frontend_path, strlen(frontend_path));
#ifdef CONFIG_XENCAP
caps = xs_get_caps(ctx->xsh, t, libxl__sprintf(gc, "%s/frontend",backend_path));
if (caps == NULL)
LOG(ERROR, "Caps for %s/frontend is NULL!\n",backend_path);
if (!xc_cap_check(ctx->xch, device->domid, 2, &caps[0])) {
list[0] = caps[0];
LOG(DEBUG, "Granting caps for domid %d for %s/frontend\n", device->domid, backend_path);
LOG(DEBUG, "caps[0]: %d caps[1]: %d\n",caps[0].magic, caps[1].magic);
if (xc_cap_grant(ctx->xch, device->domid, 2, &list, 1))
LOG(DEBUG, "Granting caps for %s/frontend failed\n",backend_path);
}
// delete this
if (!xc_cap_check(ctx->xch, device->domid, 2, &caps[1])) {
list[0] = caps[1];
if (xc_cap_grant(ctx->xch, device->domid, 2, &list, 1))
LOG(DEBUG, "Granting caps for %s/frontend failed\n",backend_path);
}
#endif
#ifdef CONFIG_XENCAP
libxl__xs_writev(gc, t, backend_path, bents, device->domid, 'b');
#else
libxl__xs_writev(gc, t, backend_path, bents);
#endif
}
if (!create_transaction)
......
......@@ -823,6 +823,16 @@ void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state *sdss)
}
libxl__write_stub_dmargs(gc, dm_domid, guest_domid, args);
#ifdef CONFIG_XENCAP
libxl__xs_write(gc, XBT_NULL, dm_domid, 'r',
libxl__sprintf(gc, "%s/image/device-model-domid",
libxl__xs_get_dompath(gc, guest_domid)),
"%d", dm_domid);
libxl__xs_write(gc, XBT_NULL, dm_domid, 'r',
libxl__sprintf(gc, "%s/target",
libxl__xs_get_dompath(gc, dm_domid)),
"%d", guest_domid);
#else
libxl__xs_write(gc, XBT_NULL,
libxl__sprintf(gc, "%s/image/device-model-domid",
libxl__xs_get_dompath(gc, guest_domid)),
......@@ -831,6 +841,7 @@ void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state *sdss)
libxl__sprintf(gc, "%s/target",
libxl__xs_get_dompath(gc, dm_domid)),
"%d", guest_domid);
#endif
ret = xc_domain_set_target(ctx->xch, dm_domid, guest_domid);
if (ret<0) {
LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
......@@ -1095,9 +1106,15 @@ void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state *dmss)
if (b_info->type == LIBXL_DOMAIN_TYPE_HVM) {
path = xs_get_domain_path(ctx->xsh, domid);
#ifdef CONFIG_XENCAP
libxl__xs_write(gc, XBT_NULL, domid, 'r',
libxl__sprintf(gc, "%s/hvmloader/bios", path),
"%s", libxl_bios_type_to_string(b_info->u.hvm.bios));
#else
libxl__xs_write(gc, XBT_NULL,
libxl__sprintf(gc, "%s/hvmloader/bios", path),
"%s", libxl_bios_type_to_string(b_info->u.hvm.bios));
#endif
free(path);
}
......@@ -1107,8 +1124,13 @@ void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state *dmss)
if (b_info->type == LIBXL_DOMAIN_TYPE_HVM &&
b_info->device_model_version
== LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL)
#ifdef CONFIG_XENCAP
libxl__xs_write(gc, XBT_NULL, domid, 'r', libxl__sprintf(gc, "%s/disable_pf", path),
"%d", !libxl_defbool_val(b_info->u.hvm.xen_platform_pci));
#else
libxl__xs_write(gc, XBT_NULL, libxl__sprintf(gc, "%s/disable_pf", path),
"%d", !libxl_defbool_val(b_info->u.hvm.xen_platform_pci));
#endif
libxl_create_logfile(ctx,
libxl__sprintf(gc, "qemu-dm-%s", c_info->name),
......@@ -1132,7 +1154,11 @@ retry_transaction:
pass_stuff = libxl__calloc(gc, 3, sizeof(char *));
pass_stuff[0] = "vncpasswd";
pass_stuff[1] = vnc->passwd;
#ifdef CONFIG_XENCAP
libxl__xs_writev(gc,t,vm_path,pass_stuff,domid,'r');
#else
libxl__xs_writev(gc,t,vm_path,pass_stuff);
#endif
if (!xs_transaction_end(ctx->xsh, t, 0))
if (errno == EAGAIN)
goto retry_transaction;
......
......@@ -346,12 +346,25 @@ int libxl__build_post(libxl__gc *gc, uint32_t domid,
retry_transaction:
t = xs_transaction_start(ctx->xsh);
#ifdef CONFIG_XENCAP
libxl__xs_writev(gc, t, dom_path, ents, domid, 'r');
#else
libxl__xs_writev(gc, t, dom_path, ents);
#endif
if (info->type == LIBXL_DOMAIN_TYPE_HVM)
#ifdef CONFIG_XENCAP
libxl__xs_writev(gc, t, dom_path, hvm_ents, domid, 'r');
#else
libxl__xs_writev(gc, t, dom_path, hvm_ents);
#endif
#ifdef CONFIG_XENCAP
libxl__xs_writev(gc, t, dom_path, local_ents, domid, 'r');
libxl__xs_writev(gc, t, vm_path, vms_ents, domid, 'r');
#else
libxl__xs_writev(gc, t, dom_path, local_ents);
libxl__xs_writev(gc, t, vm_path, vms_ents);
#endif
if (!xs_transaction_end(ctx->xsh, t, 0))
if (errno == EAGAIN)
......@@ -576,7 +589,11 @@ int libxl__qemu_traditional_cmd(libxl__gc *gc, uint32_t domid,
char *path = NULL;
path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/command",
domid);
#ifdef CONFIG_XENCAP
return libxl__xs_write(gc, XBT_NULL, 0, 'b', path, "%s", cmd);
#else
return libxl__xs_write(gc, XBT_NULL, path, "%s", cmd);
#endif
}
struct libxl__physmap_info {
......@@ -639,16 +656,28 @@ int libxl__toolstack_restore(uint32_t domid, const uint8_t *buf,
ptr += sizeof(struct libxl__physmap_info) + pi->namelen;
xs_path = restore_helper(gc, domid, pi->phys_offset, "start_addr");
#ifdef CONFIG_XENCAP
ret = libxl__xs_write(gc, 0, domid, 'r', xs_path, "%"PRIx64, pi->start_addr);
#else
ret = libxl__xs_write(gc, 0, xs_path, "%"PRIx64, pi->start_addr);
#endif
if (ret)
return -1;
xs_path = restore_helper(gc, domid, pi->phys_offset, "size");
#ifdef CONFIG_XENCAP
ret = libxl__xs_write(gc, 0, domid, 'r', xs_path, "%"PRIx64, pi->size);
#else
ret = libxl__xs_write(gc, 0, xs_path, "%"PRIx64, pi->size);
#endif
if (ret)
return -1;
if (pi->namelen > 0) {
xs_path = restore_helper(gc, domid, pi->phys_offset, "name");
#ifdef CONFIG_XENCAP
ret = libxl__xs_write(gc, 0, domid, 'r', xs_path, "%s", pi->name);
#else
ret = libxl__xs_write(gc, 0, xs_path, "%s", pi->name);
#endif
if (ret)
return -1;
}
......
......@@ -143,8 +143,11 @@ int libxl__spawn_record_pid(libxl__gc *gc, libxl__spawn_state *spawn, pid_t pid)
rc = libxl__ev_child_xenstore_reopen(gc, spawn->what);
if (rc) goto out;
#ifdef CONFIG_XENCAP
r = libxl__xs_write(gc, XBT_NULL, 0, 'b', spawn->pidpath, "%d", pid);
#else
r = libxl__xs_write(gc, XBT_NULL, spawn->pidpath, "%d", pid);
#endif
if (r) {
LOGE(ERROR,
"write %s = %d: xenstore write failed", spawn->pidpath, pid);
......
......@@ -510,14 +510,32 @@ _hidden int libxl__remove_file_or_directory(libxl__gc *gc, const char *path);
_hidden char **libxl__xs_kvs_of_flexarray(libxl__gc *gc, flexarray_t *array, int length);
/* treats kvs as pairs of keys and values and writes each to dir. */
_hidden int libxl__xs_writev(libxl__gc *gc, xs_transaction_t t,
const char *dir, char **kvs);
#ifdef CONFIG_XENCAP
_hidden int libxl__xs_writev(libxl__gc *gc, xs_transaction_t t, const char *dir, char **kvs, uint32_t domid, char perm);
#else
_hidden int libxl__xs_writev(libxl__gc *gc, xs_transaction_t t, const char *dir, char **kvs);
#endif
#ifdef CONFIG_XENCAP
/* _atonce creates a transaction and writes all keys at once */
_hidden int libxl__xs_writev_atonce(libxl__gc *gc,
const char *dir, char **kvs, uint32_t domid, char perm);
#else
_hidden int libxl__xs_writev_atonce(libxl__gc *gc,
const char *dir, char **kvs);
#endif
#ifdef CONFIG_XENCAP
void libxl__xs_grant_caps(libxl__gc *gc, xs_transaction_t t, char *path, uint32_t domid, char perm);
#endif
#ifdef CONFIG_XENCAP
_hidden int libxl__xs_write(libxl__gc *gc, xs_transaction_t t,
uint32_t domid, char perm, const char *path, const char *fmt, ...) PRINTF_ATTRIBUTE(6, 7);
#else
_hidden int libxl__xs_write(libxl__gc *gc, xs_transaction_t t,
const char *path, const char *fmt, ...) PRINTF_ATTRIBUTE(4, 5);
const char *path, const char *fmt, ...) PRINTF_ATTRIBUTE(4, 5);
#endif
/* Each fn returns 0 on success.
* On error: returns -1, sets errno (no logging) */
......@@ -927,6 +945,9 @@ _hidden int libxl__device_generic_add(libxl__gc *gc, xs_transaction_t t,
libxl__device *device, char **bents, char **fents);
_hidden char *libxl__device_backend_path(libxl__gc *gc, libxl__device *device);
_hidden char *libxl__device_frontend_path(libxl__gc *gc, libxl__device *device);
#ifdef CONFIG_XENCAP
char *libxl__device_frontend_child(libxl__gc *gc, libxl__device *device);
#endif
_hidden int libxl__parse_backend_path(libxl__gc *gc, const char *path,
libxl__device *dev);
_hidden int libxl__device_destroy(libxl__gc *gc, libxl__device *dev);
......
......@@ -151,8 +151,13 @@ static int libxl__device_pci_add_xenstore(libxl__gc *gc, uint32_t domid, libxl_d
retry_transaction:
t = xs_transaction_start(ctx->xsh);
#ifdef CONFIG_XENCAP
libxl__xs_writev(gc, t, be_path,
libxl__xs_kvs_of_flexarray(gc, back, back->count), domid, 'r');
#else
libxl__xs_writev(gc, t, be_path,
libxl__xs_kvs_of_flexarray(gc, back, back->count));
#endif
if (!xs_transaction_end(ctx->xsh, t, 0))
if (errno == EAGAIN)
goto retry_transaction;
......@@ -167,6 +172,10 @@ static int libxl__device_pci_remove_xenstore(libxl__gc *gc, uint32_t domid, libx
char *be_path, *num_devs_path, *num_devs, *xsdev, *tmp, *tmppath;
int num, i, j;
xs_transaction_t t;
#ifdef CONFIG_XENCAP
struct capability *caps;
struct capability list[2];
#endif
be_path = libxl__sprintf(gc, "%s/backend/pci/%d/0", libxl__xs_get_dompath(gc, 0), domid);
num_devs_path = libxl__sprintf(gc, "%s/num_devs", be_path);
......@@ -204,6 +213,37 @@ retry_transaction:
t = xs_transaction_start(ctx->xsh);
xs_write(ctx->xsh, t, libxl__sprintf(gc, "%s/state-%d", be_path, i), "5", strlen("5"));
xs_write(ctx->xsh, t, libxl__sprintf(gc, "%s/state", be_path), "7", strlen("7"));
#ifdef CONFIG_XENCAP
caps = xs_get_caps(ctx->xsh, t, libxl__sprintf(gc, "%s/state-%d", be_path, i));
if (caps == NULL)
LOG(ERROR, "Caps for %s/state-%d is NULL!\n",be_path,i);
if (!xc_cap_check(ctx->xch, domid, 2, &caps[0])) {
list[0] = caps[0];
if (xc_cap_grant(ctx->xch, domid, 2, &list, 1))
LOG(ERROR, "Granting caps for %s/state-%d failed\n",be_path, i);
}
// delete this
if (!xc_cap_check(ctx->xch, domid, 2, &caps[1])) {
list[0] = caps[1];
if (xc_cap_grant(ctx->xch, domid, 2, &list, 1))
LOG(ERROR, "Granting caps for %s/state-%d failed\n",be_path, i);
}
caps = xs_get_caps(ctx->xsh, t, libxl__sprintf(gc, "%s/state", be_path));
if (caps == NULL)
LOG(ERROR, "Caps for %s/state is NULL!\n",be_path);
if (!xc_cap_check(ctx->xch, domid, 2, &caps[0])) {
list[0] = caps[0];
if (xc_cap_grant(ctx->xch, domid, 2, &list, 1))
LOG(ERROR, "Granting caps for %s/state failed\n",be_path);
}
// delete this
if (!xc_cap_check(ctx->xch, domid, 2, &caps[1])) {
list[0] = caps[1];
if (xc_cap_grant(ctx->xch, domid, 2, &list, 1))
LOG(ERROR, "Granting caps for %s/state failed\n",be_path);
}
#endif
if (!xs_transaction_end(ctx->xsh, t, 0))
if (errno == EAGAIN)
goto retry_transaction;
......@@ -223,7 +263,11 @@ retry_transaction2:
xs_rm(ctx->xsh, t, libxl__sprintf(gc, "%s/vdev-%d", be_path, i));
xs_rm(ctx->xsh, t, libxl__sprintf(gc, "%s/opts-%d", be_path, i));
xs_rm(ctx->xsh, t, libxl__sprintf(gc, "%s/vdevfn-%d", be_path, i));
#ifdef CONFIG_XENCAP
libxl__xs_write(gc, t, domid, 'r', num_devs_path, "%d", num - 1);
#else
libxl__xs_write(gc, t, num_devs_path, "%d", num - 1);
#endif
for (j = i + 1; j < num; j++) {
tmppath = libxl__sprintf(gc, "%s/state-%d", be_path, j);
tmp = libxl__xs_read(gc, t, tmppath);
......@@ -585,7 +629,11 @@ static void pci_assignable_driver_path_write(libxl__gc *gc,
pcidev->bus,
pcidev->dev,
pcidev->func);
#ifdef CONFIG_XENCAP
if ( libxl__xs_write(gc, XBT_NULL, 0, 'b', path, "%s", driver_path) < 0 ) {
#else
if ( libxl__xs_write(gc, XBT_NULL, path, "%s", driver_path) < 0 ) {
#endif
LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_WARNING,
"Write of %s to node %s failed.",
driver_path, path);
......@@ -823,14 +871,27 @@ static int qemu_pci_add_xenstore(libxl__gc *gc, uint32_t domid,
path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/parameter",
domid);
if (pcidev->vdevfn) {
#ifdef CONFIG_XENCAP
libxl__xs_write(gc, XBT_NULL, 0, 'b', path, PCI_BDF_VDEVFN","PCI_OPTIONS,
pcidev->domain, pcidev->bus, pcidev->dev,
pcidev->func, pcidev->vdevfn, pcidev->msitranslate,
pcidev->power_mgmt);
#else
libxl__xs_write(gc, XBT_NULL, path, PCI_BDF_VDEVFN","PCI_OPTIONS,
pcidev->domain, pcidev->bus, pcidev->dev,
pcidev->func, pcidev->vdevfn, pcidev->msitranslate,
pcidev->power_mgmt);
#endif
} else {
#ifdef CONFIG_XENCAP
libxl__xs_write(gc, XBT_NULL, 0, 'b', path, PCI_BDF","PCI_OPTIONS,
pcidev->domain, pcidev->bus, pcidev->dev,
pcidev->func, pcidev->msitranslate, pcidev->power_mgmt);
#else
libxl__xs_write(gc, XBT_NULL, path, PCI_BDF","PCI_OPTIONS,
pcidev->domain, pcidev->bus, pcidev->dev,
pcidev->func, pcidev->msitranslate, pcidev->power_mgmt);
#endif
}
libxl__qemu_traditional_cmd(gc, domid, "pci-ins");
......@@ -1129,8 +1190,13 @@ static int qemu_pci_remove_xenstore(libxl__gc *gc, uint32_t domid,
path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/state", domid);
state = libxl__xs_read(gc, XBT_NULL, path);
path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/parameter", domid);
#ifdef CONFIG_XENCAP
libxl__xs_write(gc, XBT_NULL, 0, 'b', path, PCI_BDF, pcidev->domain,
pcidev->bus, pcidev->dev, pcidev->func);
#else
libxl__xs_write(gc, XBT_NULL, path, PCI_BDF, pcidev->domain,
pcidev->bus, pcidev->dev, pcidev->func);
#endif
/* Remove all functions at once atomically by only signalling
* device-model for function 0 */
......
......@@ -103,7 +103,11 @@ static int store_serial_port_info(libxl__qmp_handler *qmp,
path = libxl__xs_get_dompath(gc, qmp->domid);
path = libxl__sprintf(gc, "%s/serial/%d/tty", path, port);
#ifdef CONFIG_XENCAP
ret = libxl__xs_write(gc, XBT_NULL, qmp->domid, 'r', path, "%s", chardev + 4);
#else
ret = libxl__xs_write(gc, XBT_NULL, path, "%s", chardev + 4);
#endif
GC_FREE;
return ret;
......@@ -162,7 +166,11 @@ static int qmp_write_domain_console_item(libxl__gc *gc, int domid,
path = libxl__xs_get_dompath(gc, domid);
path = libxl__sprintf(gc, "%s/console/%s", path, item);
#ifdef CONFIG_XENCAP
return libxl__xs_write(gc, XBT_NULL, domid, 'b', path, "%s", value);