int xen_config_dev_blk(DriveInfo *disk) { char fe[256], be[256], device_name[32]; int vdev = 202 * 256 + 16 * disk->unit; int cdrom = disk->media_cd; const char *devtype = cdrom ? "cdrom" : "disk"; const char *mode = cdrom ? "r" : "w"; const char *filename = qemu_opt_get(disk->opts, "file"); snprintf(device_name, sizeof(device_name), "xvd%c", 'a' + disk->unit); xen_be_printf(NULL, 1, "config disk %d [%s]: %s\n", disk->unit, device_name, filename); 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 */ xenstore_write_str(be, "dev", device_name); xenstore_write_str(be, "type", "file"); xenstore_write_str(be, "params", filename); xenstore_write_str(be, "mode", mode); /* common stuff */ return xen_config_dev_all(fe, be); }
int domain_setup(struct domain *d) { int rc; /* Allocate/Store the domain UUID in /struct domain/. */ domain_read_uuid(d); /* xc_getphysinfo to check if this domain is PV or HVM. */ domain_read_is_pv_domain(d); /* Assign the slot passed by the toostack through Xenstore to this domain. * - Slot read from /vm/<uuid>/slot (uuid needs to be known beforehand) * - Also setup relevant nodes in XenStore to manage that slot. */ rc = domain_assign_slot(d); if (rc) return rc; /* Slot 0 (UIVM) special case. * XXX: Stuff in here might be deprecated... */ if (d->slot == 0) { char path[128], perm[128]; xenstore_dom_write(d->domid, "http://1.0.0.0/auth.html", "login/url"); xenstore_dom_write(d->domid, "3", "login/state"); sprintf(perm, "n%d", d->domid); sprintf(path, "/local/domain/%d/report/state", d->domid); xenstore_write_int(3, path); xenstore_chmod(perm, 1, path); sprintf(path, "/local/domain/%d/report/url", d->domid); xenstore_write("http://1.0.0.0/create_report.html", path); xenstore_chmod(perm, 1, path); } /* Watch on node attr/desktopDimensions for resize events? * XXX: Isn't that HVM/Windows only ? */ if (!xenstore_dom_watch(d->domid, domain_calculate_abs_scaling, d, "attr/desktopDimensions")) warning("%s: Could not setup xenstore watch on switcher/command." " Slot will be static.", __func__); /* Handle PM events. * Setup watch on Xenstore node <dompath>/power-state. */ if (!xenstore_dom_watch(d->domid, domain_power_state, d, "power-state")) warning("%s: Could not setup xenstore watch on power-state." " Power-management event will not be handled properly.", __func__); domain_power_state("power-state", d); /* Initialise display position for mouse switching. * XXX: Uses <dompath>/switcher/<slot>/{left,right} and talks with * xenvm over dbus. */ domain_mouse_switch_config(d); d->initialised = true; 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_nic(NICInfo *nic) { char fe[256], be[256]; char mac[20]; int vlan_id = -1; net_hub_id_for_client(nic->netdev, &vlan_id); snprintf(mac, sizeof(mac), "%02x:%02x:%02x:%02x:%02x:%02x", nic->macaddr.a[0], nic->macaddr.a[1], nic->macaddr.a[2], nic->macaddr.a[3], nic->macaddr.a[4], nic->macaddr.a[5]); 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)); /* frontend */ xenstore_write_int(fe, "handle", vlan_id); xenstore_write_str(fe, "mac", mac); /* backend */ xenstore_write_int(be, "handle", vlan_id); xenstore_write_str(be, "mac", mac); /* common stuff */ return xen_config_dev_all(fe, be); }
int xenstore_write_be_int(struct XenDevice *xendev, const char *node, int ival) { return xenstore_write_int(xendev->be, node, ival); }
//Exactly what it says on the tin. void write_battery_status_to_xenstore(unsigned int battery_index) { struct battery_status * status; char bst[35], xenstore_path[128]; int num_batteries, current_battery_level; if (battery_index >= num_battery_structs_allocd) { cleanup_removed_battery(battery_index); } num_batteries = get_num_batteries_present(); if (num_batteries == 0) { xenstore_write("0", XS_BATTERY_PRESENT); return; } else { xenstore_write("1", XS_BATTERY_PRESENT); } status = &last_status[battery_index]; //Delete the BST and reset the "present" flag if the battery is not currently present. if (status->present != YES) { snprintf(xenstore_path, 255, "%s%i/%s", XS_BATTERY_PATH, battery_index, XS_BST_LEAF); xenstore_rm(xenstore_path); snprintf(xenstore_path, 255, "%s%i/%s", XS_BATTERY_PATH, battery_index, XS_BATTERY_PRESENT_LEAF); xenstore_write("0", xenstore_path); return; } //Build the BST structure. memset(bst, 0, 35); snprintf(bst, 3, "%02x", 16); write_ulong_lsb_first(bst+2, status->state); write_ulong_lsb_first(bst+10, status->present_rate); write_ulong_lsb_first(bst+18, status->remaining_capacity); write_ulong_lsb_first(bst+26, status->present_voltage); //Ensure the directory exists before trying to write the leaves make_xenstore_battery_dir(battery_index); //Now write the leaves. snprintf(xenstore_path, 255, XS_BATTERY_PATH "%i/" XS_BST_LEAF, battery_index); xenstore_write(bst, xenstore_path); snprintf(xenstore_path, 255, "%s%i/%s", XS_BATTERY_PATH, battery_index, XS_BATTERY_PRESENT_LEAF); xenstore_write("1", xenstore_path); //Here for compatibility--will be removed eventually if (battery_index == 0) xenstore_write(bst, XS_BST); else xenstore_write(bst, XS_BST1); current_battery_level = get_current_battery_level(); if (current_battery_level == NORMAL || get_ac_adapter_status() == ON_AC) xenstore_rm(XS_CURRENT_BATTERY_LEVEL); else { xenstore_write_int(current_battery_level, XS_CURRENT_BATTERY_LEVEL); notify_com_citrix_xenclient_xcpmd_battery_level_notification(xcdbus_conn, XCPMD_SERVICE, XCPMD_PATH); xcpmd_log(LOG_ALERT, "Battery level below normal - %d!\n", current_battery_level); } #ifdef XCPMD_DEBUG xcpmd_log(LOG_DEBUG, "~Updated battery information in xenstore\n"); #endif }
static void switcher_domid(struct domain *d, uint32_t domid) { char perm[8]; char path[64]; char perms[128]; char *tmp = 0; int stubdom_domid; int slot; struct domain *d_pvm; if (domain_with(domid,&domid)) { error("domain %d already exists", domid); return; } d->domid = domid; domain_read_uuid(d); domain_read_is_pv_domain(d); slot = domain_read_slot(d); // Ensures that no "zombie" domains are taking up valuable switcher slots. // Ideally, this shouldn't be necessary-- but in development environments // it's possible for interesting things to happen (e.g. for a developer to // destroy a stub-domain without giving us notice of the termination.) // This safeguard function isn't strictly neccessary, but it's lightweight // and prevents some awful behavior (including huge delays) if developers do // manage to do fun things like kernel panic their stubdomains. if(slot_occupied_by_dead_domain(slot)) { warning("slot %d is held by a dead domain; cleaning up", slot); domain_gone(domain_with(slot, &slot)); } if (domain_with(slot,&slot) || (slot == -1)) { error("slot %d already taken (wanted by domain %d)",slot,domid); return; } d->slot = slot; info("New domain %d (slot %d)", domid, slot); /* init xenstore nodes and permissions for midori secure window and status report */ if (slot == 0) { xenstore_dom_write(domid, "http://1.0.0.0/auth.html", "login/url"); xenstore_dom_write(domid, "3", "login/state"); sprintf(perm, "n%d", domid); sprintf(path, "/local/domain/%d/report/state", domid); xenstore_write_int(3, path); xenstore_chmod(perm, 1, path); sprintf(path, "/local/domain/%d/report/url", domid); xenstore_write("http://1.0.0.0/create_report.html", path); xenstore_chmod (perm, 1, path); } xenstore_dom_write(domid, "", "switcher/command"); sprintf(perms, "r%d", domid); xenstore_dom_chmod(domid, perms, 1, "switcher/command"); if (!xenstore_dom_watch(domid, domain_command, d, "switcher/command")) warning("failed to install xenstore watch! switcher/command"); d->rel_x_mult = MAX_MOUSE_ABS_X / DEFAULT_RESOLUTION_X; d->rel_y_mult = MAX_MOUSE_ABS_Y / DEFAULT_RESOLUTION_Y; d->desktop_xres = d->desktop_yres = 0; if (!xenstore_dom_watch(d->domid, domain_calculate_abs_scaling, d, "attr/desktopDimensions")) warning("failed to install xenstore watch! attr/desktopDimensions"); d->is_pvm = 0; d->keyboard_led_code = 0; xenstore_dom_write_int(d->domid, 0, "switcher/have_gpu"); if (!xenstore_dom_watch(domid, domain_power_state, d, "power-state")) warning("failed to install xenstore watch! power-state"); domain_power_state("power-state",d); d_pvm = domain_with(is_pvm, &one); domain_surface_disabled_detect_init(d); xen_vkbd_backend_create(d); domain_read_has_secondary_gpu(d); domain_mouse_switch_config(d); focus_update_domain(d); /* call our callbacks*/ struct callbacklist* c = domainstart_callback; while (c) { c->callback(d); c = c->next; } /* we are ready to receive switch commands for this domain */ xenstore_dom_write(domid, "true", "switcher/ready"); }