Esempio n. 1
0
int
nodeDeviceDestroy(virNodeDevicePtr dev)
{
    int ret = -1;
    virNodeDeviceObjPtr obj = NULL;
    virNodeDeviceDefPtr def;
    char *wwnn = NULL, *wwpn = NULL;
    int parent_host = -1;

    if (!(obj = nodeDeviceObjFindByName(dev->name)))
        return -1;
    def = virNodeDeviceObjGetDef(obj);

    nodeDeviceLock();

    if (virNodeDeviceDestroyEnsureACL(dev->conn, def) < 0)
        goto cleanup;

    if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) < 0)
        goto cleanup;

    /* virNodeDeviceGetParentHost will cause the device object's lock
     * to be taken, so grab the object def which will have the various
     * fields used to search (name, parent, parent_wwnn, parent_wwpn,
     * or parent_fabric_wwn) and drop the object lock. */
    virNodeDeviceObjUnlock(obj);
    obj = NULL;
    if ((parent_host = virNodeDeviceObjGetParentHost(&driver->devs, def,
                                                     EXISTING_DEVICE)) < 0)
        goto cleanup;

    if (virVHBAManageVport(parent_host, wwpn, wwnn, VPORT_DELETE) < 0)
        goto cleanup;

    ret = 0;

 cleanup:
    nodeDeviceUnlock();
    virNodeDeviceObjUnlock(obj);
    VIR_FREE(wwnn);
    VIR_FREE(wwpn);
    return ret;
}
Esempio n. 2
0
int
nodeDeviceDestroy(virNodeDevicePtr dev)
{
    int ret = -1;
    virNodeDeviceObjPtr obj = NULL;
    char *parent_name = NULL, *wwnn = NULL, *wwpn = NULL;
    int parent_host = -1;

    nodeDeviceLock();
    obj = virNodeDeviceFindByName(&driver->devs, dev->name);
    nodeDeviceUnlock();

    if (!obj) {
        virReportError(VIR_ERR_NO_NODE_DEVICE,
                       _("no node device with matching name '%s'"),
                       dev->name);
        goto out;
    }

    if (virNodeDeviceDestroyEnsureACL(dev->conn, obj->def) < 0)
        goto out;

    if (virNodeDeviceGetWWNs(obj->def, &wwnn, &wwpn) == -1)
        goto out;


    /* virNodeDeviceGetParentHost will cause the device object's lock to be
     * taken, so we have to dup the parent's name and drop the lock
     * before calling it.  We don't need the reference to the object
     * any more once we have the parent's name.  */
    if (VIR_STRDUP(parent_name, obj->def->parent) < 0) {
        virNodeDeviceObjUnlock(obj);
        obj = NULL;
        goto out;
    }
    virNodeDeviceObjUnlock(obj);
    obj = NULL;

    if (virNodeDeviceGetParentHost(&driver->devs,
                                   dev->name,
                                   parent_name,
                                   &parent_host) == -1) {
        goto out;
    }

    if (virManageVport(parent_host,
                       wwpn,
                       wwnn,
                       VPORT_DELETE) == -1) {
        goto out;
    }

    ret = 0;
 out:
    if (obj)
        virNodeDeviceObjUnlock(obj);
    VIR_FREE(parent_name);
    VIR_FREE(wwnn);
    VIR_FREE(wwpn);
    return ret;
}