root / hw / xen_devconfig.c @ 562183de
History | View | Annotate | Download (4.7 kB)
1 | 2c8b24a3 | aliguori | #include "xen_backend.h" |
---|---|---|---|
2 | 2c8b24a3 | aliguori | |
3 | 2c8b24a3 | aliguori | /* ------------------------------------------------------------- */
|
4 | 2c8b24a3 | aliguori | |
5 | 2c8b24a3 | aliguori | struct xs_dirs {
|
6 | 2c8b24a3 | aliguori | char *xs_dir;
|
7 | 2c8b24a3 | aliguori | TAILQ_ENTRY(xs_dirs) list; |
8 | 2c8b24a3 | aliguori | }; |
9 | 2c8b24a3 | aliguori | static TAILQ_HEAD(xs_dirs_head, xs_dirs) xs_cleanup = TAILQ_HEAD_INITIALIZER(xs_cleanup);
|
10 | 2c8b24a3 | aliguori | |
11 | 2c8b24a3 | aliguori | static void xen_config_cleanup_dir(char *dir) |
12 | 2c8b24a3 | aliguori | { |
13 | 2c8b24a3 | aliguori | struct xs_dirs *d;
|
14 | 2c8b24a3 | aliguori | |
15 | 2c8b24a3 | aliguori | d = qemu_malloc(sizeof(*d));
|
16 | 2c8b24a3 | aliguori | d->xs_dir = dir; |
17 | 2c8b24a3 | aliguori | TAILQ_INSERT_TAIL(&xs_cleanup, d, list); |
18 | 2c8b24a3 | aliguori | } |
19 | 2c8b24a3 | aliguori | |
20 | 2c8b24a3 | aliguori | void xen_config_cleanup(void) |
21 | 2c8b24a3 | aliguori | { |
22 | 2c8b24a3 | aliguori | struct xs_dirs *d;
|
23 | 2c8b24a3 | aliguori | |
24 | 2c8b24a3 | aliguori | TAILQ_FOREACH(d, &xs_cleanup, list) { |
25 | 2c8b24a3 | aliguori | xs_rm(xenstore, 0, d->xs_dir);
|
26 | 2c8b24a3 | aliguori | } |
27 | 2c8b24a3 | aliguori | } |
28 | 2c8b24a3 | aliguori | |
29 | 2c8b24a3 | aliguori | /* ------------------------------------------------------------- */
|
30 | 2c8b24a3 | aliguori | |
31 | 2c8b24a3 | aliguori | static int xen_config_dev_mkdir(char *dev, int p) |
32 | 2c8b24a3 | aliguori | { |
33 | 2c8b24a3 | aliguori | struct xs_permissions perms[2] = {{ |
34 | 2c8b24a3 | aliguori | .id = 0, /* set owner: dom0 */ |
35 | 2c8b24a3 | aliguori | },{ |
36 | 2c8b24a3 | aliguori | .id = xen_domid, |
37 | 2c8b24a3 | aliguori | .perms = p, |
38 | 2c8b24a3 | aliguori | }}; |
39 | 2c8b24a3 | aliguori | |
40 | 2c8b24a3 | aliguori | if (!xs_mkdir(xenstore, 0, dev)) { |
41 | 2c8b24a3 | aliguori | xen_be_printf(NULL, 0, "xs_mkdir %s: failed\n", dev); |
42 | 2c8b24a3 | aliguori | return -1; |
43 | 2c8b24a3 | aliguori | } |
44 | 2c8b24a3 | aliguori | xen_config_cleanup_dir(qemu_strdup(dev)); |
45 | 2c8b24a3 | aliguori | |
46 | 2c8b24a3 | aliguori | if (!xs_set_permissions(xenstore, 0, dev, perms, 2)) { |
47 | 2c8b24a3 | aliguori | xen_be_printf(NULL, 0, "xs_set_permissions %s: failed\n", dev); |
48 | 2c8b24a3 | aliguori | return -1; |
49 | 2c8b24a3 | aliguori | } |
50 | 2c8b24a3 | aliguori | return 0; |
51 | 2c8b24a3 | aliguori | } |
52 | 2c8b24a3 | aliguori | |
53 | 2c8b24a3 | aliguori | static int xen_config_dev_dirs(const char *ftype, const char *btype, int vdev, |
54 | 2c8b24a3 | aliguori | char *fe, char *be, int len) |
55 | 2c8b24a3 | aliguori | { |
56 | 2c8b24a3 | aliguori | char *dom;
|
57 | 2c8b24a3 | aliguori | |
58 | 2c8b24a3 | aliguori | dom = xs_get_domain_path(xenstore, xen_domid); |
59 | 2c8b24a3 | aliguori | snprintf(fe, len, "%s/device/%s/%d", dom, ftype, vdev);
|
60 | 2c8b24a3 | aliguori | free(dom); |
61 | 2c8b24a3 | aliguori | |
62 | 2c8b24a3 | aliguori | dom = xs_get_domain_path(xenstore, 0);
|
63 | 2c8b24a3 | aliguori | snprintf(be, len, "%s/backend/%s/%d/%d", dom, btype, xen_domid, vdev);
|
64 | 2c8b24a3 | aliguori | free(dom); |
65 | 2c8b24a3 | aliguori | |
66 | 2c8b24a3 | aliguori | xen_config_dev_mkdir(fe, XS_PERM_READ | XS_PERM_WRITE); |
67 | 2c8b24a3 | aliguori | xen_config_dev_mkdir(be, XS_PERM_READ); |
68 | 2c8b24a3 | aliguori | return 0; |
69 | 2c8b24a3 | aliguori | } |
70 | 2c8b24a3 | aliguori | |
71 | 2c8b24a3 | aliguori | static int xen_config_dev_all(char *fe, char *be) |
72 | 2c8b24a3 | aliguori | { |
73 | 2c8b24a3 | aliguori | /* frontend */
|
74 | 2c8b24a3 | aliguori | if (xen_protocol)
|
75 | 2c8b24a3 | aliguori | xenstore_write_str(fe, "protocol", xen_protocol);
|
76 | 2c8b24a3 | aliguori | |
77 | 2c8b24a3 | aliguori | xenstore_write_int(fe, "state", XenbusStateInitialising);
|
78 | 2c8b24a3 | aliguori | xenstore_write_int(fe, "backend-id", 0); |
79 | 2c8b24a3 | aliguori | xenstore_write_str(fe, "backend", be);
|
80 | 2c8b24a3 | aliguori | |
81 | 2c8b24a3 | aliguori | /* backend */
|
82 | 2c8b24a3 | aliguori | xenstore_write_str(be, "domain", qemu_name ? qemu_name : "no-name"); |
83 | 2c8b24a3 | aliguori | xenstore_write_int(be, "online", 1); |
84 | 2c8b24a3 | aliguori | xenstore_write_int(be, "state", XenbusStateInitialising);
|
85 | 2c8b24a3 | aliguori | xenstore_write_int(be, "frontend-id", xen_domid);
|
86 | 2c8b24a3 | aliguori | xenstore_write_str(be, "frontend", fe);
|
87 | 2c8b24a3 | aliguori | |
88 | 2c8b24a3 | aliguori | return 0; |
89 | 2c8b24a3 | aliguori | } |
90 | 2c8b24a3 | aliguori | |
91 | 2c8b24a3 | aliguori | /* ------------------------------------------------------------- */
|
92 | 2c8b24a3 | aliguori | |
93 | 2c8b24a3 | aliguori | int xen_config_dev_blk(DriveInfo *disk)
|
94 | 2c8b24a3 | aliguori | { |
95 | 2c8b24a3 | aliguori | char fe[256], be[256]; |
96 | 2c8b24a3 | aliguori | int vdev = 202 * 256 + 16 * disk->unit; |
97 | 2c8b24a3 | aliguori | int cdrom = disk->bdrv->type == BDRV_TYPE_CDROM;
|
98 | 2c8b24a3 | aliguori | const char *devtype = cdrom ? "cdrom" : "disk"; |
99 | 2c8b24a3 | aliguori | const char *mode = cdrom ? "r" : "w"; |
100 | 2c8b24a3 | aliguori | |
101 | 2c8b24a3 | aliguori | snprintf(disk->bdrv->device_name, sizeof(disk->bdrv->device_name),
|
102 | 2c8b24a3 | aliguori | "xvd%c", 'a' + disk->unit); |
103 | 2c8b24a3 | aliguori | xen_be_printf(NULL, 1, "config disk %d [%s]: %s\n", |
104 | 2c8b24a3 | aliguori | disk->unit, disk->bdrv->device_name, disk->bdrv->filename); |
105 | 2c8b24a3 | aliguori | xen_config_dev_dirs("vbd", "qdisk", vdev, fe, be, sizeof(fe)); |
106 | 2c8b24a3 | aliguori | |
107 | 2c8b24a3 | aliguori | /* frontend */
|
108 | 2c8b24a3 | aliguori | xenstore_write_int(fe, "virtual-device", vdev);
|
109 | 2c8b24a3 | aliguori | xenstore_write_str(fe, "device-type", devtype);
|
110 | 2c8b24a3 | aliguori | |
111 | 2c8b24a3 | aliguori | /* backend */
|
112 | 2c8b24a3 | aliguori | xenstore_write_str(be, "dev", disk->bdrv->device_name);
|
113 | 2c8b24a3 | aliguori | xenstore_write_str(be, "type", "file"); |
114 | 2c8b24a3 | aliguori | xenstore_write_str(be, "params", disk->bdrv->filename);
|
115 | 2c8b24a3 | aliguori | xenstore_write_str(be, "mode", mode);
|
116 | 2c8b24a3 | aliguori | |
117 | 2c8b24a3 | aliguori | /* common stuff */
|
118 | 2c8b24a3 | aliguori | return xen_config_dev_all(fe, be);
|
119 | 2c8b24a3 | aliguori | } |
120 | 2c8b24a3 | aliguori | |
121 | 2c8b24a3 | aliguori | int xen_config_dev_nic(NICInfo *nic)
|
122 | 2c8b24a3 | aliguori | { |
123 | 2c8b24a3 | aliguori | char fe[256], be[256]; |
124 | 2c8b24a3 | aliguori | char mac[20]; |
125 | 2c8b24a3 | aliguori | |
126 | 2c8b24a3 | aliguori | snprintf(mac, sizeof(mac), "%02x:%02x:%02x:%02x:%02x:%02x", |
127 | 2c8b24a3 | aliguori | nic->macaddr[0], nic->macaddr[1], nic->macaddr[2], |
128 | 2c8b24a3 | aliguori | nic->macaddr[3], nic->macaddr[4], nic->macaddr[5]); |
129 | 2c8b24a3 | aliguori | xen_be_printf(NULL, 1, "config nic %d: mac=\"%s\"\n", nic->vlan->id, mac); |
130 | 2c8b24a3 | aliguori | xen_config_dev_dirs("vif", "qnic", nic->vlan->id, fe, be, sizeof(fe)); |
131 | 2c8b24a3 | aliguori | |
132 | 2c8b24a3 | aliguori | /* frontend */
|
133 | 2c8b24a3 | aliguori | xenstore_write_int(fe, "handle", nic->vlan->id);
|
134 | 2c8b24a3 | aliguori | xenstore_write_str(fe, "mac", mac);
|
135 | 2c8b24a3 | aliguori | |
136 | 2c8b24a3 | aliguori | /* backend */
|
137 | 2c8b24a3 | aliguori | xenstore_write_int(be, "handle", nic->vlan->id);
|
138 | 2c8b24a3 | aliguori | xenstore_write_str(be, "mac", mac);
|
139 | 2c8b24a3 | aliguori | |
140 | 2c8b24a3 | aliguori | /* common stuff */
|
141 | 2c8b24a3 | aliguori | return xen_config_dev_all(fe, be);
|
142 | 2c8b24a3 | aliguori | } |
143 | 9306acb5 | aliguori | |
144 | 9306acb5 | aliguori | int xen_config_dev_vfb(int vdev, const char *type) |
145 | 9306acb5 | aliguori | { |
146 | 9306acb5 | aliguori | char fe[256], be[256]; |
147 | 9306acb5 | aliguori | |
148 | 9306acb5 | aliguori | xen_config_dev_dirs("vfb", "vfb", vdev, fe, be, sizeof(fe)); |
149 | 9306acb5 | aliguori | |
150 | 9306acb5 | aliguori | /* backend */
|
151 | 9306acb5 | aliguori | xenstore_write_str(be, "type", type);
|
152 | 9306acb5 | aliguori | |
153 | 9306acb5 | aliguori | /* common stuff */
|
154 | 9306acb5 | aliguori | return xen_config_dev_all(fe, be);
|
155 | 9306acb5 | aliguori | } |
156 | 9306acb5 | aliguori | |
157 | 9306acb5 | aliguori | int xen_config_dev_vkbd(int vdev) |
158 | 9306acb5 | aliguori | { |
159 | 9306acb5 | aliguori | char fe[256], be[256]; |
160 | 9306acb5 | aliguori | |
161 | 9306acb5 | aliguori | xen_config_dev_dirs("vkbd", "vkbd", vdev, fe, be, sizeof(fe)); |
162 | 9306acb5 | aliguori | return xen_config_dev_all(fe, be);
|
163 | 9306acb5 | aliguori | } |
164 | 9306acb5 | aliguori | |
165 | 9306acb5 | aliguori | int xen_config_dev_console(int vdev) |
166 | 9306acb5 | aliguori | { |
167 | 9306acb5 | aliguori | char fe[256], be[256]; |
168 | 9306acb5 | aliguori | |
169 | 9306acb5 | aliguori | xen_config_dev_dirs("console", "console", vdev, fe, be, sizeof(fe)); |
170 | 9306acb5 | aliguori | return xen_config_dev_all(fe, be);
|
171 | 9306acb5 | aliguori | } |