static int get_be_domid(const char *str) { int len1, len2; const char *ptr; char *tptr, num[10]; len2 = strsep_len(str, '/', 3); if ( len2 < 0 ) return -1; len1 = strsep_len(str, '/', 2); ptr = str + len1 + 1; strncpy(num, ptr, len2 - len1 - 1); tptr = num + (len2 - len1 - 1); *tptr = '\0'; return atoi(num); }
static int get_be_id(const char *str) { int len,end; const char *ptr; char *tptr, num[10]; len = strsep_len(str, '/', 6); end = strlen(str); if( (len < 0) || (end < 0) ) return -1; ptr = str + len + 1; strncpy(num, ptr, end - len); tptr = num + (end - (len + 1)); *tptr = '\0'; return atoi(num); }
void xenbus_dev_changed(const char *node, struct xen_bus_type *bus) { int exists, rootlen; struct xenbus_device *dev; char type[XEN_BUS_ID_SIZE]; const char *p, *root; if (char_count(node, '/') < 2) return; exists = xenbus_exists(XBT_NIL, node, ""); if (!exists) { xenbus_cleanup_devices(node, &bus->bus); return; } /* backend/<type>/... or device/<type>/... */ p = strchr(node, '/') + 1; snprintf(type, XEN_BUS_ID_SIZE, "%.*s", (int)strcspn(p, "/"), p); type[XEN_BUS_ID_SIZE-1] = '\0'; rootlen = strsep_len(node, '/', bus->levels); if (rootlen < 0) return; root = kasprintf(GFP_KERNEL, "%.*s", rootlen, node); if (!root) return; dev = xenbus_device_find(root, &bus->bus); if (!dev) xenbus_probe_node(bus, type, root); else put_device(&dev->dev); kfree(root); }
/** * Xenstore watch callback entry point. This code replaces the hotplug scripts, * and as soon as the xenstore backend driver entries are created, this script * gets called. */ static void ueblktap_probe(struct xs_handle *h, struct xenbus_watch *w, const char *bepath_im) { struct backend_info *be = NULL; char *frontend = NULL, *bepath = NULL, *p; int er, len; blkif_t *blkif; bepath = strdup(bepath_im); if (!bepath) { DPRINTF("No path\n"); return; } /* *asserts that xenstore structure is always 7 levels deep *e.g. /local/domain/0/backend/vbd/1/2049 */ len = strsep_len(bepath, '/', 7); if (len < 0) goto free_be; if (bepath[len] != '\0') goto free_be; be = malloc(sizeof(*be)); if (!be) { DPRINTF("ERROR: allocating backend structure\n"); goto free_be; } memset(be, 0, sizeof(*be)); frontend = NULL; er = xs_gather(h, bepath, "frontend-id", "%li", &be->frontend_id, "frontend", NULL, &frontend, NULL); if (er) { /* *Unable to find frontend entries, *bus-id is no longer valid */ DPRINTF("ERROR: Frontend-id check failed, removing backend: " "[%s]\n",bepath); /** * BE info should already exist, * free new mem and find old entry */ free(be); be = be_lookup_be(bepath); if ( (be != NULL) && (be->blkif != NULL) ) backend_remove(h, be); else goto free_be; if (bepath) free(bepath); return; } /* Are we already tracking this device? */ if (be_exists_be(bepath)) goto free_be; be->backpath = bepath; be->frontpath = frontend; list_add(&be->list, &belist); DPRINTF("[PROBE]\tADDED NEW DEVICE (%s)\n", bepath); DPRINTF("\tFRONTEND (%s),(%ld)\n", frontend,be->frontend_id); ueblktap_setup(h, bepath); return; free_be: if (frontend) free(frontend); if (bepath) free(bepath); if (be) free(be); }