From patchwork Fri Nov 13 00:12:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nithin Raju X-Patchwork-Id: 544008 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 8332A14142D for ; Fri, 13 Nov 2015 11:12:13 +1100 (AEDT) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 03356109A8; Thu, 12 Nov 2015 16:12:12 -0800 (PST) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx3v3.cudamail.com (mx3.cudamail.com [64.34.241.5]) by archives.nicira.com (Postfix) with ESMTPS id D4994109A7 for ; Thu, 12 Nov 2015 16:12:10 -0800 (PST) Received: from bar4.cudamail.com (localhost [127.0.0.1]) by mx3v3.cudamail.com (Postfix) with ESMTPS id D0F9816308B for ; Thu, 12 Nov 2015 17:12:09 -0700 (MST) X-ASG-Debug-ID: 1447373529-03dc2118841e820001-byXFYA Received: from mx3-pf1.cudamail.com ([192.168.14.2]) by bar4.cudamail.com with ESMTP id L6p55GNyojz0N9iE (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 12 Nov 2015 17:12:09 -0700 (MST) X-Barracuda-Envelope-From: nithin@vmware.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.14.2 Received: from unknown (HELO smtp-outbound-1.vmware.com) (208.91.2.12) by mx3-pf1.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 13 Nov 2015 00:12:09 -0000 Received-SPF: pass (mx3-pf1.cudamail.com: SPF record at _spf.vmware.com designates 208.91.2.12 as permitted sender) X-Barracuda-Apparent-Source-IP: 208.91.2.12 X-Barracuda-RBL-IP: 208.91.2.12 Received: from sc9-mailhost3.vmware.com (sc9-mailhost3.vmware.com [10.113.161.73]) by smtp-outbound-1.vmware.com (Postfix) with ESMTP id 714F628AC9 for ; Thu, 12 Nov 2015 16:12:07 -0800 (PST) Received: from pa-dbc1118.eng.vmware.com (unknown [10.162.210.18]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id 59B0C40607; Thu, 12 Nov 2015 16:12:08 -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-V1-1111066709 X-CudaMail-DTE: 111215 X-CudaMail-Originating-IP: 208.91.2.12 Date: Thu, 12 Nov 2015 16:12:06 -0800 X-ASG-Orig-Subj: [##CM-V1-1111066709##][PATCH] datapath-windows: Fix HvUpdateNic() to handle name changes Message-Id: <1447373526-10482-1-git-send-email-nithin@vmware.com> X-Mailer: git-send-email 1.8.5.6 X-Barracuda-Connect: UNKNOWN[192.168.14.2] X-Barracuda-Start-Time: 1447373529 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] datapath-windows: Fix HvUpdateNic() to handle name changes 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" If the name of an internal or external NIC changes, we need to disconnect the NIC from OVS since the name is the key. In this change, we generate a link down event. It is as though we got a call to HvDisconnectNic() for the old name and got a HvConnectNic() for the new name. Also, HvCreateNic() has been cleaned up to remove the code to look for existing vport. We won't have a vport now since we'd have deleted the vport in HvDeleteNic(). Signed-off-by: Nithin Raju --- datapath-windows/ovsext/Vport.c | 83 +++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/datapath-windows/ovsext/Vport.c b/datapath-windows/ovsext/Vport.c index 37d5e59..a80ab00 100644 --- a/datapath-windows/ovsext/Vport.c +++ b/datapath-windows/ovsext/Vport.c @@ -341,42 +341,21 @@ HvCreateNic(POVS_SWITCH_CONTEXT switchContext, */ if (nicParam->NicType == NdisSwitchNicTypeExternal && nicParam->NicIndex != 0) { + NDIS_SWITCH_PORT_PARAMETERS portParam; POVS_VPORT_ENTRY virtExtVport = (POVS_VPORT_ENTRY)switchContext->virtualExternalVport; - vport = OvsFindVportByPortIdAndNicIndex(switchContext, - nicParam->PortId, - nicParam->NicIndex); - if (vport == NULL) { - NDIS_SWITCH_PORT_PARAMETERS portParam; - /* Find by interface name */ - WCHAR interfaceName[IF_MAX_STRING_SIZE] = { 0 }; - NET_LUID interfaceLuid = { 0 }; - size_t len = 0; - status = ConvertInterfaceGuidToLuid(&nicParam->NetCfgInstanceId, - &interfaceLuid); - if (status == STATUS_SUCCESS) { - status = ConvertInterfaceLuidToAlias(&interfaceLuid, - interfaceName, - IF_MAX_STRING_SIZE + 1); - if (status == STATUS_SUCCESS) { - RtlStringCbLengthW(interfaceName, - IF_MAX_STRING_SIZE, - &len); - vport = OvsFindVportByHvNameW(switchContext, - interfaceName, - len); - } - } - - OvsCopyPortParamsFromVport(virtExtVport, &portParam); - NdisReleaseRWLock(switchContext->dispatchLock, &lockState); - status = HvCreatePort(switchContext, &portParam, - nicParam->NicIndex); - NdisAcquireRWLockWrite(switchContext->dispatchLock, &lockState, 0); - if (status != NDIS_STATUS_SUCCESS) { - goto add_nic_done; - } + ASSERT(virtExtVport); + ASSERT(OvsFindVportByPortIdAndNicIndex(switchContext, + nicParam->PortId, + nicParam->NicIndex) == NULL); + OvsCopyPortParamsFromVport(virtExtVport, &portParam); + NdisReleaseRWLock(switchContext->dispatchLock, &lockState); + status = HvCreatePort(switchContext, &portParam, + nicParam->NicIndex); + NdisAcquireRWLockWrite(switchContext->dispatchLock, &lockState, 0); + if (status != NDIS_STATUS_SUCCESS) { + goto add_nic_done; } } @@ -470,6 +449,8 @@ HvUpdateNic(POVS_SWITCH_CONTEXT switchContext, LOCK_STATE_EX lockState; UINT32 event = 0; IF_COUNTED_STRING portFriendlyName = {0}; + BOOLEAN nameChanged = FALSE; + BOOLEAN aliasLookup = FALSE; VPORT_NIC_ENTER(nicParam); @@ -486,6 +467,7 @@ HvUpdateNic(POVS_SWITCH_CONTEXT switchContext, (nicParam->NicType == NdisSwitchNicTypeExternal && nicParam->NicIndex != 0)) { GetNICAlias(&nicParam->NetCfgInstanceId, &portFriendlyName); + aliasLookup = TRUE; } NdisAcquireRWLockWrite(switchContext->dispatchLock, &lockState, 0); @@ -498,14 +480,20 @@ HvUpdateNic(POVS_SWITCH_CONTEXT switchContext, goto update_nic_done; } switch (nicParam->NicType) { + case NdisSwitchNicTypeExternal: case NdisSwitchNicTypeInternal: - { RtlCopyMemory(&vport->netCfgInstanceId, &nicParam->NetCfgInstanceId, sizeof (GUID)); - RtlCopyMemory(&vport->portFriendlyName, &portFriendlyName, - sizeof portFriendlyName); + if (aliasLookup) { + if (RtlCompareMemory(&vport->portFriendlyName, + &portFriendlyName, vport->portFriendlyName.Length) != + vport->portFriendlyName.Length) { + RtlCopyMemory(&vport->portFriendlyName, &portFriendlyName, + sizeof portFriendlyName); + nameChanged = TRUE; + } + } break; - } case NdisSwitchNicTypeSynthetic: case NdisSwitchNicTypeEmulated: if (!RtlEqualMemory(vport->vmMacAddress, nicParam->VMMacAddress, @@ -537,6 +525,17 @@ HvUpdateNic(POVS_SWITCH_CONTEXT switchContext, } vport->numaNodeId = nicParam->NumaNodeId; + if (nameChanged) { + OVS_EVENT_ENTRY event; + event.portNo = vport->portNo; + event.ovsType = vport->ovsType; + event.upcallPid = vport->upcallPid; + RtlCopyMemory(&event.ovsName, &vport->ovsName, sizeof event.ovsName); + event.type = OVS_EVENT_LINK_DOWN; + OvsRemoveAndDeleteVport(NULL, switchContext, vport, FALSE, TRUE); + OvsPostEvent(&event); + } + NdisReleaseRWLock(switchContext->dispatchLock, &lockState); /* @@ -599,14 +598,15 @@ HvDisconnectNic(POVS_SWITCH_CONTEXT switchContext, RtlCopyMemory(&event.ovsName, &vport->ovsName, sizeof event.ovsName); event.type = OVS_EVENT_LINK_DOWN; - NdisReleaseRWLock(switchContext->dispatchLock, &lockState); - /* * Delete the port from the hash tables accessible to userspace. After this * point, userspace should not be able to access this port. */ - OvsRemoveAndDeleteVport(NULL, switchContext, vport, FALSE, TRUE); - OvsPostEvent(&event); + if (vport != switchContext->virtualExternalVport) { + OvsRemoveAndDeleteVport(NULL, switchContext, vport, FALSE, TRUE); + OvsPostEvent(&event); + } + NdisReleaseRWLock(switchContext->dispatchLock, &lockState); if (isInternalPort) { OvsInternalAdapterDown(); @@ -653,6 +653,7 @@ HvDeleteNic(POVS_SWITCH_CONTEXT switchContext, if (vport->portType == NdisSwitchPortTypeExternal && vport->nicIndex != 0) { + /* This vport was created in HvCreateNic(). */ OvsRemoveAndDeleteVport(NULL, switchContext, vport, TRUE, FALSE); }