Ejemplo n.º 1
0
int xc_suspend_evtchn_init(xc_interface *xch, xc_evtchn *xce, int domid, int port)
{
    int rc, suspend_evtchn = -1;

    if (lock_suspend_event(xch, domid))
        return -EINVAL;

    suspend_evtchn = xc_evtchn_bind_interdomain(xce, domid, port);
    if (suspend_evtchn < 0) {
        ERROR("failed to bind suspend event channel: %d", suspend_evtchn);
        goto cleanup;
    }

    rc = xc_domain_subscribe_for_suspend(xch, domid, port);
    if (rc < 0) {
        ERROR("failed to subscribe to domain: %d", rc);
        goto cleanup;
    }

    /* event channel is pending immediately after binding */
    xc_await_suspend(xch, xce, suspend_evtchn);

    return suspend_evtchn;

cleanup:
    xc_suspend_evtchn_release(xch, xce, domid, suspend_evtchn);

    return -1;
}
Ejemplo n.º 2
0
int xc_suspend_evtchn_init_sane(xc_interface *xch, xc_evtchn *xce,
                                int domid, int port, int *lockfd)
{
    int rc, suspend_evtchn = -1;

    if (lock_suspend_event(xch, domid, lockfd)) {
        errno = EINVAL;
        goto cleanup;
    }

    suspend_evtchn = xc_evtchn_bind_interdomain(xce, domid, port);
    if (suspend_evtchn < 0) {
        ERROR("failed to bind suspend event channel: %d", suspend_evtchn);
        goto cleanup;
    }

    rc = xc_domain_subscribe_for_suspend(xch, domid, port);
    if (rc < 0) {
        ERROR("failed to subscribe to domain: %d", rc);
        goto cleanup;
    }

    return suspend_evtchn;

cleanup:
    xc_suspend_evtchn_release(xch, xce, domid, suspend_evtchn, lockfd);

    return -1;
}
Ejemplo n.º 3
0
static int suspend_evtchn_init(int xc, int domid)
{
    struct xs_handle *xs;
    char path[128];
    char *portstr;
    unsigned int plen;
    int port;
    int rc;

    si.xce = -1;
    si.suspend_evtchn = -1;

    xs = xs_daemon_open();
    if (!xs) {
        warnx("failed to get xenstore handle");
        return -1;
    }
    sprintf(path, "/local/domain/%d/device/suspend/event-channel", domid);
    portstr = xs_read(xs, XBT_NULL, path, &plen);
    xs_daemon_close(xs);

    if (!portstr || !plen) {
        warnx("could not read suspend event channel");
        return -1;
    }

    port = atoi(portstr);
    free(portstr);

    si.xce = xc_evtchn_open();
    if (si.xce < 0) {
        warnx("failed to open event channel handle");
        goto cleanup;
    }

    si.suspend_evtchn = xc_evtchn_bind_interdomain(si.xce, domid, port);
    if (si.suspend_evtchn < 0) {
        warnx("failed to bind suspend event channel: %d", si.suspend_evtchn);
        goto cleanup;
    }

    rc = xc_domain_subscribe_for_suspend(xc, domid, port);
    if (rc < 0) {
        warnx("failed to subscribe to domain: %d", rc);
        goto cleanup;
    }

    /* event channel is pending immediately after binding */
    await_suspend();

    return 0;

  cleanup:
    suspend_evtchn_release();

    return -1;
}