datapath-windows/ovsext/Vport.c
/*
 * --------------------------------------------------------------------------
 *  Creates a Vport entry for a Hyper-V switch port. 'nicIndex' is typically
 *  associated with a NIC than a port. We use it here for the special case
 *  where we need to create a Vport for an external NIC with NicIndex > 0.
 * --------------------------------------------------------------------------
 */
Creates a Vport entry for a Hyper-V switch port. 'nicIndex' is typically
associated with a NIC than a port. We use it here for the special case
where we need to create a Vport for an external NIC with NicIndex > 0.
Creates a Vport entry for a Hyper - V switch port . ' nicIndex ' is typically associated with a NIC than a port . We use it here for the special case where we need to create a Vport for an external NIC with NicIndex > 0 .
NDIS_STATUS
HvCreatePort(POVS_SWITCH_CONTEXT switchContext,
             PNDIS_SWITCH_PORT_PARAMETERS portParam,
             NDIS_SWITCH_NIC_INDEX nicIndex)
{
    POVS_VPORT_ENTRY vport;
    LOCK_STATE_EX lockState;
    NDIS_STATUS status = NDIS_STATUS_SUCCESS;
    BOOLEAN newPort = FALSE;
    VPORT_PORT_ENTER(portParam);
    NdisAcquireRWLockWrite(switchContext->dispatchLock, &lockState, 0);
    vport = OvsFindVportByPortIdAndNicIndex(switchContext,
                                            portParam->PortId, nicIndex);
    if (vport != NULL) {
        OVS_LOG_ERROR("Port add failed due to duplicate port name, "
                      "port Id: %u", portParam->PortId);
        status = STATUS_DATA_NOT_ACCEPTED;
        goto create_port_done;
    }
    vport = OvsFindVportByHvNameW(switchContext,
                                  portParam->PortFriendlyName.String,
                                  portParam->PortFriendlyName.Length);
    if (vport && vport->isAbsentOnHv == FALSE) {
        OVS_LOG_ERROR("Port add failed since a port already exists on "
                      "the specified port Id: %u, ovsName: %s",
                      portParam->PortId, vport->ovsName);
        status = STATUS_DATA_NOT_ACCEPTED;
        goto create_port_done;
    }
    if (vport != NULL) {
        ASSERT(vport->isAbsentOnHv);
        ASSERT(vport->portNo != OVS_DPPORT_NUMBER_INVALID);
        if (vport->portType != portParam->PortType) {
            OVS_LOG_INFO("Port add failed due to PortType change, port Id: %u"
                         " old: %u, new: %u", portParam->PortId,
                         vport->portType, portParam->PortType);
            status = STATUS_DATA_NOT_ACCEPTED;
            goto create_port_done;
        }
        vport->isAbsentOnHv = FALSE;
    } else {
        vport = (POVS_VPORT_ENTRY)OvsAllocateVport();
        if (vport == NULL) {
            status = NDIS_STATUS_RESOURCES;
            goto create_port_done;
        }
        newPort = TRUE;
    }
    OvsInitVportWithPortParam(vport, portParam);
    vport->nicIndex = nicIndex;
    UpdateSwitchCtxWithVport(switchContext, vport, newPort);
create_port_done:
    NdisReleaseRWLock(switchContext->dispatchLock, &lockState);
    VPORT_PORT_EXIT(portParam);
    return status;
}
NDIS_STATUS HvCreatePort ( POVS_SWITCH_CONTEXT switchContext , PNDIS_SWITCH_PORT_PARAMETERS portParam , NDIS_SWITCH_NIC_INDEX nicIndex ) { POVS_VPORT_ENTRY vport ; LOCK_STATE_EX lockState ; NDIS_STATUS status = NDIS_STATUS_SUCCESS ; BOOLEAN newPort = FALSE ; VPORT_PORT_ENTER ( portParam ) ; NdisAcquireRWLockWrite ( switchContext -> dispatchLock , & lockState , 0 ) ; vport = OvsFindVportByPortIdAndNicIndex ( switchContext , portParam -> PortId , nicIndex ) ; if ( vport != NULL ) { OVS_LOG_ERROR ( " " " " , portParam -> PortId ) ; status = STATUS_DATA_NOT_ACCEPTED ; goto create_port_done ; } vport = OvsFindVportByHvNameW ( switchContext , portParam -> PortFriendlyName . String , portParam -> PortFriendlyName . Length ) ; if ( vport && vport -> isAbsentOnHv == FALSE ) { OVS_LOG_ERROR ( " " " " , portParam -> PortId , vport -> ovsName ) ; status = STATUS_DATA_NOT_ACCEPTED ; goto create_port_done ; } if ( vport != NULL ) { ASSERT ( vport -> isAbsentOnHv ) ; ASSERT ( vport -> portNo != OVS_DPPORT_NUMBER_INVALID ) ; if ( vport -> portType != portParam -> PortType ) { OVS_LOG_INFO ( " " " " , portParam -> PortId , vport -> portType , portParam -> PortType ) ; status = STATUS_DATA_NOT_ACCEPTED ; goto create_port_done ; } vport -> isAbsentOnHv = FALSE ; } else { vport = ( POVS_VPORT_ENTRY ) OvsAllocateVport ( ) ; if ( vport == NULL ) { status = NDIS_STATUS_RESOURCES ; goto create_port_done ; } newPort = TRUE ; } OvsInitVportWithPortParam ( vport , portParam ) ; vport -> nicIndex = nicIndex ; UpdateSwitchCtxWithVport ( switchContext , vport , newPort ) ; create_port_done : NdisReleaseRWLock ( switchContext -> dispatchLock , & lockState ) ; VPORT_PORT_EXIT ( portParam ) ; return status ; }
Creates a Vport entry for a Hyper-V switch port.
Creates a Vport entry for a Hyper - V switch port .
/* Lookup by port ID. */ /*
     * Lookup by port name to see if this port with this name had been added
     * (and deleted) previously.
     */ /*
         * It should be possible to simply just mark this port as "not deleted"
         * given that the port Id and the name are the same and also provided
         * that the other properties that we cache have not changed.
         */