s390: Fix buggy assignment
[qemu.git] / hw / xen_devconfig.c
blobea8f8c4c2df69277ff4c6b10723ec7d8f87caac9
1 #include "xen_backend.h"
3 /* ------------------------------------------------------------- */
5 struct xs_dirs {
6 char *xs_dir;
7 QTAILQ_ENTRY(xs_dirs) list;
8 };
9 static QTAILQ_HEAD(xs_dirs_head, xs_dirs) xs_cleanup = QTAILQ_HEAD_INITIALIZER(xs_cleanup);
11 static void xen_config_cleanup_dir(char *dir)
13 struct xs_dirs *d;
15 d = qemu_malloc(sizeof(*d));
16 d->xs_dir = dir;
17 QTAILQ_INSERT_TAIL(&xs_cleanup, d, list);
20 void xen_config_cleanup(void)
22 struct xs_dirs *d;
24 QTAILQ_FOREACH(d, &xs_cleanup, list) {
25 xs_rm(xenstore, 0, d->xs_dir);
29 /* ------------------------------------------------------------- */
31 static int xen_config_dev_mkdir(char *dev, int p)
33 struct xs_permissions perms[2] = {{
34 .id = 0, /* set owner: dom0 */
35 },{
36 .id = xen_domid,
37 .perms = p,
38 }};
40 if (!xs_mkdir(xenstore, 0, dev)) {
41 xen_be_printf(NULL, 0, "xs_mkdir %s: failed\n", dev);
42 return -1;
44 xen_config_cleanup_dir(qemu_strdup(dev));
46 if (!xs_set_permissions(xenstore, 0, dev, perms, 2)) {
47 xen_be_printf(NULL, 0, "xs_set_permissions %s: failed\n", dev);
48 return -1;
50 return 0;
53 static int xen_config_dev_dirs(const char *ftype, const char *btype, int vdev,
54 char *fe, char *be, int len)
56 char *dom;
58 dom = xs_get_domain_path(xenstore, xen_domid);
59 snprintf(fe, len, "%s/device/%s/%d", dom, ftype, vdev);
60 free(dom);
62 dom = xs_get_domain_path(xenstore, 0);
63 snprintf(be, len, "%s/backend/%s/%d/%d", dom, btype, xen_domid, vdev);
64 free(dom);
66 xen_config_dev_mkdir(fe, XS_PERM_READ | XS_PERM_WRITE);
67 xen_config_dev_mkdir(be, XS_PERM_READ);
68 return 0;
71 static int xen_config_dev_all(char *fe, char *be)
73 /* frontend */
74 if (xen_protocol)
75 xenstore_write_str(fe, "protocol", xen_protocol);
77 xenstore_write_int(fe, "state", XenbusStateInitialising);
78 xenstore_write_int(fe, "backend-id", 0);
79 xenstore_write_str(fe, "backend", be);
81 /* backend */
82 xenstore_write_str(be, "domain", qemu_name ? qemu_name : "no-name");
83 xenstore_write_int(be, "online", 1);
84 xenstore_write_int(be, "state", XenbusStateInitialising);
85 xenstore_write_int(be, "frontend-id", xen_domid);
86 xenstore_write_str(be, "frontend", fe);
88 return 0;
91 /* ------------------------------------------------------------- */
93 int xen_config_dev_blk(DriveInfo *disk)
95 char fe[256], be[256];
96 int vdev = 202 * 256 + 16 * disk->unit;
97 int cdrom = disk->bdrv->type == BDRV_TYPE_CDROM;
98 const char *devtype = cdrom ? "cdrom" : "disk";
99 const char *mode = cdrom ? "r" : "w";
101 snprintf(disk->bdrv->device_name, sizeof(disk->bdrv->device_name),
102 "xvd%c", 'a' + disk->unit);
103 xen_be_printf(NULL, 1, "config disk %d [%s]: %s\n",
104 disk->unit, disk->bdrv->device_name, disk->bdrv->filename);
105 xen_config_dev_dirs("vbd", "qdisk", vdev, fe, be, sizeof(fe));
107 /* frontend */
108 xenstore_write_int(fe, "virtual-device", vdev);
109 xenstore_write_str(fe, "device-type", devtype);
111 /* backend */
112 xenstore_write_str(be, "dev", disk->bdrv->device_name);
113 xenstore_write_str(be, "type", "file");
114 xenstore_write_str(be, "params", disk->bdrv->filename);
115 xenstore_write_str(be, "mode", mode);
117 /* common stuff */
118 return xen_config_dev_all(fe, be);
121 int xen_config_dev_nic(NICInfo *nic)
123 char fe[256], be[256];
124 char mac[20];
126 snprintf(mac, sizeof(mac), "%02x:%02x:%02x:%02x:%02x:%02x",
127 nic->macaddr[0], nic->macaddr[1], nic->macaddr[2],
128 nic->macaddr[3], nic->macaddr[4], nic->macaddr[5]);
129 xen_be_printf(NULL, 1, "config nic %d: mac=\"%s\"\n", nic->vlan->id, mac);
130 xen_config_dev_dirs("vif", "qnic", nic->vlan->id, fe, be, sizeof(fe));
132 /* frontend */
133 xenstore_write_int(fe, "handle", nic->vlan->id);
134 xenstore_write_str(fe, "mac", mac);
136 /* backend */
137 xenstore_write_int(be, "handle", nic->vlan->id);
138 xenstore_write_str(be, "mac", mac);
140 /* common stuff */
141 return xen_config_dev_all(fe, be);
144 int xen_config_dev_vfb(int vdev, const char *type)
146 char fe[256], be[256];
148 xen_config_dev_dirs("vfb", "vfb", vdev, fe, be, sizeof(fe));
150 /* backend */
151 xenstore_write_str(be, "type", type);
153 /* common stuff */
154 return xen_config_dev_all(fe, be);
157 int xen_config_dev_vkbd(int vdev)
159 char fe[256], be[256];
161 xen_config_dev_dirs("vkbd", "vkbd", vdev, fe, be, sizeof(fe));
162 return xen_config_dev_all(fe, be);
165 int xen_config_dev_console(int vdev)
167 char fe[256], be[256];
169 xen_config_dev_dirs("console", "console", vdev, fe, be, sizeof(fe));
170 return xen_config_dev_all(fe, be);