2009-04-22 19:19:39 +04:00
|
|
|
#include "xen_backend.h"
|
2010-08-24 19:22:24 +04:00
|
|
|
#include "blockdev.h"
|
2009-04-22 19:19:39 +04:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
|
|
|
struct xs_dirs {
|
|
|
|
char *xs_dir;
|
2009-09-12 11:36:22 +04:00
|
|
|
QTAILQ_ENTRY(xs_dirs) list;
|
2009-04-22 19:19:39 +04:00
|
|
|
};
|
2009-09-12 11:36:22 +04:00
|
|
|
static QTAILQ_HEAD(xs_dirs_head, xs_dirs) xs_cleanup = QTAILQ_HEAD_INITIALIZER(xs_cleanup);
|
2009-04-22 19:19:39 +04:00
|
|
|
|
|
|
|
static void xen_config_cleanup_dir(char *dir)
|
|
|
|
{
|
|
|
|
struct xs_dirs *d;
|
|
|
|
|
2011-08-21 07:09:37 +04:00
|
|
|
d = g_malloc(sizeof(*d));
|
2009-04-22 19:19:39 +04:00
|
|
|
d->xs_dir = dir;
|
2009-09-12 11:36:22 +04:00
|
|
|
QTAILQ_INSERT_TAIL(&xs_cleanup, d, list);
|
2009-04-22 19:19:39 +04:00
|
|
|
}
|
|
|
|
|
2010-03-21 22:13:02 +03:00
|
|
|
void xen_config_cleanup(void)
|
2009-04-22 19:19:39 +04:00
|
|
|
{
|
|
|
|
struct xs_dirs *d;
|
|
|
|
|
2009-09-12 11:36:22 +04:00
|
|
|
QTAILQ_FOREACH(d, &xs_cleanup, list) {
|
2009-04-22 19:19:39 +04:00
|
|
|
xs_rm(xenstore, 0, d->xs_dir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static int xen_config_dev_mkdir(char *dev, int p)
|
|
|
|
{
|
|
|
|
struct xs_permissions perms[2] = {{
|
|
|
|
.id = 0, /* set owner: dom0 */
|
|
|
|
},{
|
|
|
|
.id = xen_domid,
|
|
|
|
.perms = p,
|
|
|
|
}};
|
|
|
|
|
|
|
|
if (!xs_mkdir(xenstore, 0, dev)) {
|
|
|
|
xen_be_printf(NULL, 0, "xs_mkdir %s: failed\n", dev);
|
|
|
|
return -1;
|
|
|
|
}
|
2011-08-21 07:09:37 +04:00
|
|
|
xen_config_cleanup_dir(g_strdup(dev));
|
2009-04-22 19:19:39 +04:00
|
|
|
|
|
|
|
if (!xs_set_permissions(xenstore, 0, dev, perms, 2)) {
|
|
|
|
xen_be_printf(NULL, 0, "xs_set_permissions %s: failed\n", dev);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int xen_config_dev_dirs(const char *ftype, const char *btype, int vdev,
|
|
|
|
char *fe, char *be, int len)
|
|
|
|
{
|
|
|
|
char *dom;
|
|
|
|
|
|
|
|
dom = xs_get_domain_path(xenstore, xen_domid);
|
|
|
|
snprintf(fe, len, "%s/device/%s/%d", dom, ftype, vdev);
|
|
|
|
free(dom);
|
|
|
|
|
|
|
|
dom = xs_get_domain_path(xenstore, 0);
|
|
|
|
snprintf(be, len, "%s/backend/%s/%d/%d", dom, btype, xen_domid, vdev);
|
|
|
|
free(dom);
|
|
|
|
|
|
|
|
xen_config_dev_mkdir(fe, XS_PERM_READ | XS_PERM_WRITE);
|
|
|
|
xen_config_dev_mkdir(be, XS_PERM_READ);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int xen_config_dev_all(char *fe, char *be)
|
|
|
|
{
|
|
|
|
/* frontend */
|
|
|
|
if (xen_protocol)
|
|
|
|
xenstore_write_str(fe, "protocol", xen_protocol);
|
|
|
|
|
|
|
|
xenstore_write_int(fe, "state", XenbusStateInitialising);
|
|
|
|
xenstore_write_int(fe, "backend-id", 0);
|
|
|
|
xenstore_write_str(fe, "backend", be);
|
|
|
|
|
|
|
|
/* backend */
|
|
|
|
xenstore_write_str(be, "domain", qemu_name ? qemu_name : "no-name");
|
|
|
|
xenstore_write_int(be, "online", 1);
|
|
|
|
xenstore_write_int(be, "state", XenbusStateInitialising);
|
|
|
|
xenstore_write_int(be, "frontend-id", xen_domid);
|
|
|
|
xenstore_write_str(be, "frontend", fe);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int xen_config_dev_blk(DriveInfo *disk)
|
|
|
|
{
|
2012-06-13 12:11:49 +04:00
|
|
|
char fe[256], be[256], device_name[32];
|
2009-04-22 19:19:39 +04:00
|
|
|
int vdev = 202 * 256 + 16 * disk->unit;
|
2011-05-16 17:04:56 +04:00
|
|
|
int cdrom = disk->media_cd;
|
2009-04-22 19:19:39 +04:00
|
|
|
const char *devtype = cdrom ? "cdrom" : "disk";
|
|
|
|
const char *mode = cdrom ? "r" : "w";
|
2012-06-13 12:11:50 +04:00
|
|
|
const char *filename = qemu_opt_get(disk->opts, "file");
|
2009-04-22 19:19:39 +04:00
|
|
|
|
2012-06-13 12:11:49 +04:00
|
|
|
snprintf(device_name, sizeof(device_name), "xvd%c", 'a' + disk->unit);
|
2009-04-22 19:19:39 +04:00
|
|
|
xen_be_printf(NULL, 1, "config disk %d [%s]: %s\n",
|
2012-06-13 12:11:50 +04:00
|
|
|
disk->unit, device_name, filename);
|
2009-04-22 19:19:39 +04:00
|
|
|
xen_config_dev_dirs("vbd", "qdisk", vdev, fe, be, sizeof(fe));
|
|
|
|
|
|
|
|
/* frontend */
|
|
|
|
xenstore_write_int(fe, "virtual-device", vdev);
|
|
|
|
xenstore_write_str(fe, "device-type", devtype);
|
|
|
|
|
|
|
|
/* backend */
|
2012-06-13 12:11:49 +04:00
|
|
|
xenstore_write_str(be, "dev", device_name);
|
2009-04-22 19:19:39 +04:00
|
|
|
xenstore_write_str(be, "type", "file");
|
2012-06-13 12:11:50 +04:00
|
|
|
xenstore_write_str(be, "params", filename);
|
2009-04-22 19:19:39 +04:00
|
|
|
xenstore_write_str(be, "mode", mode);
|
|
|
|
|
|
|
|
/* common stuff */
|
|
|
|
return xen_config_dev_all(fe, be);
|
|
|
|
}
|
|
|
|
|
|
|
|
int xen_config_dev_nic(NICInfo *nic)
|
|
|
|
{
|
|
|
|
char fe[256], be[256];
|
|
|
|
char mac[20];
|
2012-08-04 15:29:55 +04:00
|
|
|
int vlan_id = -1;
|
2009-04-22 19:19:39 +04:00
|
|
|
|
2012-08-04 15:29:55 +04:00
|
|
|
net_hub_id_for_client(nic->netdev, &vlan_id);
|
2009-04-22 19:19:39 +04:00
|
|
|
snprintf(mac, sizeof(mac), "%02x:%02x:%02x:%02x:%02x:%02x",
|
2011-07-20 14:20:22 +04:00
|
|
|
nic->macaddr.a[0], nic->macaddr.a[1], nic->macaddr.a[2],
|
|
|
|
nic->macaddr.a[3], nic->macaddr.a[4], nic->macaddr.a[5]);
|
2012-08-04 15:29:55 +04:00
|
|
|
xen_be_printf(NULL, 1, "config nic %d: mac=\"%s\"\n", vlan_id, mac);
|
|
|
|
xen_config_dev_dirs("vif", "qnic", vlan_id, fe, be, sizeof(fe));
|
2009-04-22 19:19:39 +04:00
|
|
|
|
|
|
|
/* frontend */
|
2012-08-04 15:29:55 +04:00
|
|
|
xenstore_write_int(fe, "handle", vlan_id);
|
2009-04-22 19:19:39 +04:00
|
|
|
xenstore_write_str(fe, "mac", mac);
|
|
|
|
|
|
|
|
/* backend */
|
2012-08-04 15:29:55 +04:00
|
|
|
xenstore_write_int(be, "handle", vlan_id);
|
2009-04-22 19:19:39 +04:00
|
|
|
xenstore_write_str(be, "mac", mac);
|
|
|
|
|
|
|
|
/* common stuff */
|
|
|
|
return xen_config_dev_all(fe, be);
|
|
|
|
}
|
2009-04-22 19:19:44 +04:00
|
|
|
|
|
|
|
int xen_config_dev_vfb(int vdev, const char *type)
|
|
|
|
{
|
|
|
|
char fe[256], be[256];
|
|
|
|
|
|
|
|
xen_config_dev_dirs("vfb", "vfb", vdev, fe, be, sizeof(fe));
|
|
|
|
|
|
|
|
/* backend */
|
|
|
|
xenstore_write_str(be, "type", type);
|
|
|
|
|
|
|
|
/* common stuff */
|
|
|
|
return xen_config_dev_all(fe, be);
|
|
|
|
}
|
|
|
|
|
|
|
|
int xen_config_dev_vkbd(int vdev)
|
|
|
|
{
|
|
|
|
char fe[256], be[256];
|
|
|
|
|
|
|
|
xen_config_dev_dirs("vkbd", "vkbd", vdev, fe, be, sizeof(fe));
|
|
|
|
return xen_config_dev_all(fe, be);
|
|
|
|
}
|
|
|
|
|
|
|
|
int xen_config_dev_console(int vdev)
|
|
|
|
{
|
|
|
|
char fe[256], be[256];
|
|
|
|
|
|
|
|
xen_config_dev_dirs("console", "console", vdev, fe, be, sizeof(fe));
|
|
|
|
return xen_config_dev_all(fe, be);
|
|
|
|
}
|