예제 #1
0
파일: libxl_nic.c 프로젝트: TressaOrg/xen
int libxl_mac_to_device_nic(libxl_ctx *ctx, uint32_t domid,
                            const char *mac, libxl_device_nic *nic)
{
    libxl_device_nic *nics;
    int nb, rc, i;
    libxl_mac mac_n;

    rc = libxl__parse_mac(mac, mac_n);
    if (rc)
        return rc;

    nics = libxl_device_nic_list(ctx, domid, &nb);
    if (!nics)
        return ERROR_FAIL;

    memset(nic, 0, sizeof (libxl_device_nic));

    rc = ERROR_INVAL;
    for (i = 0; i < nb; ++i) {
        if (!libxl__compare_macs(&mac_n, &nics[i].mac)) {
            *nic = nics[i];
            rc = 0;
            i++; /* Do not dispose this NIC on exit path */
            break;
        }
        libxl_device_nic_dispose(&nics[i]);
    }

    for (; i<nb; i++)
        libxl_device_nic_dispose(&nics[i]);

    free(nics);
    return rc;
}
예제 #2
0
void libxl__remus_devices_setup(libxl__egc *egc, libxl__remus_devices_state *rds)
{
    int i, rc;

    STATE_AO_GC(rds->ao);

    rc = init_device_subkind(rds);
    if (rc)
        goto out;

    rds->num_devices = 0;
    rds->num_nics = 0;
    rds->num_disks = 0;

    if (rds->device_kind_flags & (1 << LIBXL__DEVICE_KIND_VIF))
        rds->nics = libxl_device_nic_list(CTX, rds->domid, &rds->num_nics);

    if (rds->device_kind_flags & (1 << LIBXL__DEVICE_KIND_VBD))
        rds->disks = libxl_device_disk_list(CTX, rds->domid, &rds->num_disks);

    if (rds->num_nics == 0 && rds->num_disks == 0)
        goto out;

    GCNEW_ARRAY(rds->devs, rds->num_nics + rds->num_disks);

    for (i = 0; i < rds->num_nics; i++) {
        rds->devs[rds->num_devices++] = remus_device_init(egc, rds,
                                                LIBXL__DEVICE_KIND_VIF,
                                                &rds->nics[i]);
    }

    for (i = 0; i < rds->num_disks; i++) {
        rds->devs[rds->num_devices++] = remus_device_init(egc, rds,
                                                LIBXL__DEVICE_KIND_VBD,
                                                &rds->disks[i]);
    }

    remus_devices_setup(egc, rds);

    return;

out:
    rds->callback(egc, rds, rc);
}
예제 #3
0
void libxl__checkpoint_devices_setup(libxl__egc *egc,
                                     libxl__checkpoint_devices_state *cds)
{
    int i;

    STATE_AO_GC(cds->ao);

    cds->num_devices = 0;
    cds->num_nics = 0;
    cds->num_disks = 0;

    if (cds->device_kind_flags & (1 << LIBXL__DEVICE_KIND_VIF))
        cds->nics = libxl_device_nic_list(CTX, cds->domid, &cds->num_nics);

    if (cds->device_kind_flags & (1 << LIBXL__DEVICE_KIND_VBD))
        cds->disks = libxl_device_disk_list(CTX, cds->domid, &cds->num_disks);

    if (cds->num_nics == 0 && cds->num_disks == 0)
        goto out;

    GCNEW_ARRAY(cds->devs, cds->num_nics + cds->num_disks);

    for (i = 0; i < cds->num_nics; i++) {
        cds->devs[cds->num_devices++] = checkpoint_device_init(egc, cds,
                                                LIBXL__DEVICE_KIND_VIF,
                                                &cds->nics[i]);
    }

    for (i = 0; i < cds->num_disks; i++) {
        cds->devs[cds->num_devices++] = checkpoint_device_init(egc, cds,
                                                LIBXL__DEVICE_KIND_VBD,
                                                &cds->disks[i]);
    }

    checkpoint_devices_setup(egc, cds);

    return;

out:
    cds->callback(egc, cds, 0);
}