From patchwork Thu Nov 12 19:31:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nithin Raju X-Patchwork-Id: 543630 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (unknown [IPv6:2600:3c00::f03c:91ff:fe6e:bdf7]) by ozlabs.org (Postfix) with ESMTP id C238614030F for ; Fri, 13 Nov 2015 06:31:38 +1100 (AEDT) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 013F91097D; Thu, 12 Nov 2015 11:31:33 -0800 (PST) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx1e3.cudamail.com (mx1.cudamail.com [69.90.118.67]) by archives.nicira.com (Postfix) with ESMTPS id 26FB310933 for ; Thu, 12 Nov 2015 11:31:31 -0800 (PST) Received: from bar2.cudamail.com (localhost [127.0.0.1]) by mx1e3.cudamail.com (Postfix) with ESMTPS id 38C31420185 for ; Thu, 12 Nov 2015 12:31:30 -0700 (MST) X-ASG-Debug-ID: 1447356689-03dc530880371bd0001-byXFYA Received: from mx1-pf1.cudamail.com ([192.168.24.1]) by bar2.cudamail.com with ESMTP id tjUaDOeeTfQ32fxF (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 12 Nov 2015 12:31:29 -0700 (MST) X-Barracuda-Envelope-From: nithin@vmware.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.1 Received: from unknown (HELO smtp-outbound-2.vmware.com) (208.91.2.13) by mx1-pf1.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 12 Nov 2015 19:31:29 -0000 Received-SPF: pass (mx1-pf1.cudamail.com: SPF record at _spf.vmware.com designates 208.91.2.13 as permitted sender) X-Barracuda-Apparent-Source-IP: 208.91.2.13 X-Barracuda-RBL-IP: 208.91.2.13 Received: from sc9-mailhost3.vmware.com (sc9-mailhost3.vmware.com [10.113.161.73]) by smtp-outbound-2.vmware.com (Postfix) with ESMTP id 7C50E288FD for ; Thu, 12 Nov 2015 11:31:26 -0800 (PST) Received: from pa-dbc1118.eng.vmware.com (unknown [10.162.210.18]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id 5316940610; Thu, 12 Nov 2015 11:31:27 -0800 (PST) X-CudaMail-Envelope-Sender: nithin@vmware.com From: Nithin Raju To: dev@openvswitch.org X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-E1-1111074302 X-CudaMail-DTE: 111215 X-CudaMail-Originating-IP: 208.91.2.13 Date: Thu, 12 Nov 2015 11:31:22 -0800 X-ASG-Orig-Subj: [##CM-E1-1111074302##][PATCH 1/5] datapath-windows: refactor port enumeration code Message-Id: <1447356686-61244-2-git-send-email-nithin@vmware.com> X-Mailer: git-send-email 1.8.5.6 In-Reply-To: <1447356686-61244-1-git-send-email-nithin@vmware.com> References: <1447356686-61244-1-git-send-email-nithin@vmware.com> X-Barracuda-Connect: UNKNOWN[192.168.24.1] X-Barracuda-Start-Time: 1447356689 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-ASG-Whitelist: Header =?UTF-8?B?eFwtY3VkYW1haWxcLXdoaXRlbGlzdFwtdG8=?= X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 X-ASG-Whitelist: EmailCat (corporate) Subject: [ovs-dev] [PATCH 1/5] datapath-windows: refactor port enumeration code X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" We already have functions HvCreatePort() and HvCreateNic() to do the work. Might as well use that during port enumeration. More refactoring in later patches. Signed-off-by: Nithin Raju --- datapath-windows/ovsext/Switch.c | 6 ++- datapath-windows/ovsext/Vport.c | 89 ++++++++++++---------------------------- 2 files changed, 31 insertions(+), 64 deletions(-) diff --git a/datapath-windows/ovsext/Switch.c b/datapath-windows/ovsext/Switch.c index 2878e91..a783ea1 100644 --- a/datapath-windows/ovsext/Switch.c +++ b/datapath-windows/ovsext/Switch.c @@ -549,6 +549,7 @@ OvsActivateSwitch(POVS_SWITCH_CONTEXT switchContext) OVS_LOG_TRACE("Enter: activate switch %p, dpNo: %ld", switchContext, switchContext->dpNo); + switchContext->isActivated = TRUE; status = OvsAddConfiguredSwitchPorts(switchContext); if (status != NDIS_STATUS_SUCCESS) { @@ -563,10 +564,13 @@ OvsActivateSwitch(POVS_SWITCH_CONTEXT switchContext) OvsClearAllSwitchVports(switchContext); goto cleanup; } - switchContext->isActivated = TRUE; OvsPostEvent(OVS_DEFAULT_PORT_NO, OVS_DEFAULT_EVENT_STATUS); cleanup: + if (status != NDIS_STATUS_SUCCESS) { + switchContext->isActivated = TRUE; + } + OVS_LOG_TRACE("Exit: activate switch:%p, isActivated: %s, status = %lx", switchContext, (switchContext->isActivated ? "TRUE" : "FALSE"), status); diff --git a/datapath-windows/ovsext/Vport.c b/datapath-windows/ovsext/Vport.c index 3f90039..dac537f 100644 --- a/datapath-windows/ovsext/Vport.c +++ b/datapath-windows/ovsext/Vport.c @@ -376,6 +376,12 @@ HvCreateNic(POVS_SWITCH_CONTEXT switchContext, add_nic_done: NdisReleaseRWLock(switchContext->dispatchLock, &lockState); + if (status == STATUS_SUCCESS && + (vport->portType == NdisSwitchPortTypeInternal || + (vport->portType == NdisSwitchPortTypeExternal && + nicParam->NicIndex != 0))) { + AssignNicNameSpecial(vport); + } if (portNo != OVS_DPPORT_NUMBER_INVALID && event) { OvsPostEvent(portNo, event); } @@ -1017,6 +1023,10 @@ AssignNicNameSpecial(POVS_VPORT_ENTRY vport) status = ConvertInterfaceGuidToLuid(&vport->netCfgInstanceId, &interfaceLuid); if (status == STATUS_SUCCESS) { + /* + * Must be called from PASSIVE_LEVEL. Resulted in a + * STATUS_INVALID_DEVICE_REQUEST if not. + */ status = ConvertInterfaceLuidToAlias(&interfaceLuid, interfaceName, IF_MAX_STRING_SIZE + 1); if (status == STATUS_SUCCESS) { @@ -1333,8 +1343,11 @@ OvsRemoveTunnelVport(POVS_USER_PARAMS_CONTEXT usrParamsCtx, tunnelContext); } - - +/* + * -------------------------------------------------------------------------- + * Enumerates the ports on the Hyper-V switch. + * -------------------------------------------------------------------------- + */ NDIS_STATUS OvsAddConfiguredSwitchPorts(POVS_SWITCH_CONTEXT switchContext) { @@ -1342,7 +1355,6 @@ OvsAddConfiguredSwitchPorts(POVS_SWITCH_CONTEXT switchContext) ULONG arrIndex; PNDIS_SWITCH_PORT_PARAMETERS portParam; PNDIS_SWITCH_PORT_ARRAY portArray = NULL; - POVS_VPORT_ENTRY vport; OVS_LOG_TRACE("Enter: switchContext:%p", switchContext); @@ -1358,16 +1370,9 @@ OvsAddConfiguredSwitchPorts(POVS_SWITCH_CONTEXT switchContext) continue; } - vport = (POVS_VPORT_ENTRY)OvsAllocateVport(); - if (vport == NULL) { - status = NDIS_STATUS_RESOURCES; - goto cleanup; - } - OvsInitVportWithPortParam(vport, portParam); - status = InitHvVportCommon(switchContext, vport, TRUE); - if (status != NDIS_STATUS_SUCCESS) { - OvsFreeMemoryWithTag(vport, OVS_VPORT_POOL_TAG); - goto cleanup; + status = HvCreatePort(switchContext, portParam); + if (status != STATUS_SUCCESS && status != STATUS_DATA_NOT_ACCEPTED) { + break; } } @@ -1383,7 +1388,11 @@ cleanup: return status; } - +/* + * -------------------------------------------------------------------------- + * Enumerates the NICs on the Hyper-V switch. + * -------------------------------------------------------------------------- + */ NDIS_STATUS OvsInitConfiguredSwitchNics(POVS_SWITCH_CONTEXT switchContext) { @@ -1391,7 +1400,6 @@ OvsInitConfiguredSwitchNics(POVS_SWITCH_CONTEXT switchContext) PNDIS_SWITCH_NIC_ARRAY nicArray = NULL; ULONG arrIndex; PNDIS_SWITCH_NIC_PARAMETERS nicParam; - POVS_VPORT_ENTRY vport; OVS_LOG_TRACE("Enter: switchContext: %p", switchContext); /* @@ -1402,63 +1410,18 @@ OvsInitConfiguredSwitchNics(POVS_SWITCH_CONTEXT switchContext) goto cleanup; } for (arrIndex = 0; arrIndex < nicArray->NumElements; ++arrIndex) { - nicParam = NDIS_SWITCH_NIC_AT_ARRAY_INDEX(nicArray, arrIndex); /* * XXX: Check if the port is configured with a VLAN. Disallow such a * configuration, since we don't support tag-in-tag. - */ - - /* * XXX: Check if the port is connected to a VF. Disconnect the VF in * such a case. */ - if (nicParam->NicType == NdisSwitchNicTypeExternal && - nicParam->NicIndex != 0) { - POVS_VPORT_ENTRY virtExtVport = - (POVS_VPORT_ENTRY)switchContext->virtualExternalVport; - - vport = OvsAllocateVport(); - if (vport) { - OvsInitPhysNicVport(vport, virtExtVport, - nicParam->NicIndex); - OvsInitVportWithNicParam(switchContext, vport, nicParam); - status = InitHvVportCommon(switchContext, vport, TRUE); - if (status != NDIS_STATUS_SUCCESS) { - OvsFreeMemoryWithTag(vport, OVS_VPORT_POOL_TAG); - vport = NULL; - } - } else { - OVS_LOG_ERROR("Fail to allocate vport."); - continue; - } - } else { - vport = OvsFindVportByPortIdAndNicIndex(switchContext, - nicParam->PortId, - nicParam->NicIndex); - if (vport == NULL) { - OVS_LOG_ERROR( - "Could not found vport with portId: %d and nicIndex: %d.", - nicParam->PortId, nicParam->NicIndex); - continue; - } - OvsInitVportWithNicParam(switchContext, vport, nicParam); - } - - if (nicParam->NicType == NdisSwitchNicTypeInternal) { - /* - * Overwrite the 'portFriendlyName' of the internal vport. - * Note: - * The call to AssignNicNameSpecial() is needed here, because the - * necessary 'netCfgInstanceId' of the vport is available. - * On port creation the latter information is missing and the - * 'portFriendlyName' of the vport fails to be overwritten with the - * correct information. - */ - AssignNicNameSpecial(vport); - OvsInternalAdapterUp(vport->portNo, &nicParam->NetCfgInstanceId); + status = HvCreateNic(switchContext, nicParam); + if (status == NDIS_STATUS_SUCCESS) { + HvConnectNic(switchContext, nicParam); } } cleanup: