static int testCompareFiles(const char *xml, const char *sexpr) { char *sexprData = NULL; char *gotxml = NULL; int id; char * tty; int vncport; int ret = -1; virDomainDefPtr def = NULL; virConnectPtr conn; struct _xenUnifiedPrivate priv; conn = virGetConnect(); if (!conn) goto fail; if (virTestLoadFile(sexpr, &sexprData) < 0) goto fail; memset(&priv, 0, sizeof(priv)); /* Many puppies died to bring you this code. */ priv.caps = caps; conn->privateData = &priv; if (virMutexInit(&priv.lock) < 0) goto fail; if (xenGetDomIdFromSxprString(sexprData, &id) < 0) goto fail; xenUnifiedLock(&priv); tty = xenStoreDomainGetConsolePath(conn, id); vncport = xenStoreDomainGetVNCPort(conn, id); xenUnifiedUnlock(&priv); if (!(def = xenParseSxprString(sexprData, tty, vncport, caps, xmlopt))) goto fail; if (!virDomainDefCheckABIStability(def, def)) { fprintf(stderr, "ABI stability check failed on %s", xml); goto fail; } if (!(gotxml = virDomainDefFormat(def, caps, 0))) goto fail; if (virTestCompareToFile(gotxml, xml) < 0) goto fail; ret = 0; fail: VIR_FREE(sexprData); VIR_FREE(gotxml); virDomainDefFree(def); virObjectUnref(conn); return ret; }
/** * xenStoreListDomains: * @conn: pointer to the hypervisor connection * @ids: array to collect the list of IDs of active domains * @maxids: size of @ids * * Collect the list of active domains, and store their ID in @maxids * * Returns the number of domain found or -1 in case of error */ int xenStoreListDomains(virConnectPtr conn, int *ids, int maxids) { xenUnifiedPrivatePtr priv = conn->privateData; int ret; xenUnifiedLock(priv); ret = xenStoreDoListDomains(conn, priv, ids, maxids); xenUnifiedUnlock(priv); return ret; }
static void xenStoreWatchEvent(int watch ATTRIBUTE_UNUSED, int fd ATTRIBUTE_UNUSED, int events, void *data) { char **event; char *path; char *token; unsigned int stringCount; xenStoreWatchPtr sw; virConnectPtr conn = data; xenUnifiedPrivatePtr priv = conn->privateData; if (!priv) return; /* only set a watch on read and write events */ if (events & (VIR_EVENT_HANDLE_ERROR | VIR_EVENT_HANDLE_HANGUP)) return; xenUnifiedLock(priv); if (!priv->xshandle) goto cleanup; event = xs_read_watch(priv->xshandle, &stringCount); if (!event) goto cleanup; path = event[XS_WATCH_PATH]; token = event[XS_WATCH_TOKEN]; sw = xenStoreFindWatch(priv->xsWatchList, path, token); if (sw) sw->cb(conn, path, token, sw->opaque); VIR_FREE(event); cleanup: xenUnifiedUnlock(priv); }
static void xenInotifyEvent(int watch ATTRIBUTE_UNUSED, int fd, int events ATTRIBUTE_UNUSED, void *data) { char buf[1024]; char fname[1024]; struct inotify_event *e; int got; char *tmp, *name; virConnectPtr conn = data; xenUnifiedPrivatePtr priv = NULL; VIR_DEBUG("got inotify event"); if (conn && conn->privateData) { priv = conn->privateData; } else { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("conn, or private data is NULL")); return; } xenUnifiedLock(priv); reread: got = read(fd, buf, sizeof(buf)); if (got == -1) { if (errno == EINTR) goto reread; goto cleanup; } tmp = buf; while (got) { if (got < sizeof(struct inotify_event)) goto cleanup; /* bad */ VIR_WARNINGS_NO_CAST_ALIGN e = (struct inotify_event *)tmp; VIR_WARNINGS_RESET tmp += sizeof(struct inotify_event); got -= sizeof(struct inotify_event); if (got < e->len) goto cleanup; tmp += e->len; got -= e->len; name = (char *)&(e->name); snprintf(fname, 1024, "%s/%s", priv->configDir, name); if (e->mask & (IN_DELETE | IN_MOVED_FROM)) { virObjectEventPtr event = xenInotifyDomainEventFromFile(conn, fname, VIR_DOMAIN_EVENT_UNDEFINED, VIR_DOMAIN_EVENT_UNDEFINED_REMOVED); if (event) xenUnifiedDomainEventDispatch(conn->privateData, event); else virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("looking up dom")); if (xenInotifyRemoveDomainConfigInfo(conn, fname) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Error adding file to config cache")); goto cleanup; } } else if (e->mask & (IN_CREATE | IN_CLOSE_WRITE | IN_MOVED_TO)) { virObjectEventPtr event; if (xenInotifyAddDomainConfigInfo(conn, fname) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Error adding file to config cache")); goto cleanup; } event = xenInotifyDomainEventFromFile(conn, fname, VIR_DOMAIN_EVENT_DEFINED, VIR_DOMAIN_EVENT_DEFINED_ADDED); if (event) xenUnifiedDomainEventDispatch(conn->privateData, event); else virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("looking up dom")); } } cleanup: xenUnifiedUnlock(priv); }
static int testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion) { char *xmlData = NULL; char *sexprData = NULL; char *gotxml = NULL; int id; char * tty; int vncport; int ret = -1; virDomainDefPtr def = NULL; virConnectPtr conn; struct _xenUnifiedPrivate priv; conn = virGetConnect(); if (!conn) goto fail; if (virtTestLoadFile(xml, &xmlData) < 0) goto fail; if (virtTestLoadFile(sexpr, &sexprData) < 0) goto fail; memset(&priv, 0, sizeof priv); /* Many puppies died to bring you this code. */ priv.xendConfigVersion = xendConfigVersion; priv.caps = caps; conn->privateData = &priv; if (virMutexInit(&priv.lock) < 0) goto fail; id = xenGetDomIdFromSxprString(sexprData, xendConfigVersion); xenUnifiedLock(&priv); tty = xenStoreDomainGetConsolePath(conn, id); vncport = xenStoreDomainGetVNCPort(conn, id); xenUnifiedUnlock(&priv); if (!(def = xenParseSxprString(sexprData, xendConfigVersion, tty, vncport))) goto fail; if (!(gotxml = virDomainDefFormat(def, 0))) goto fail; if (STRNEQ(xmlData, gotxml)) { virtTestDifference(stderr, xmlData, gotxml); goto fail; } ret = 0; fail: free(xmlData); free(sexprData); free(gotxml); virDomainDefFree(def); if (conn) virUnrefConnect(conn); return ret; }