From patchwork Thu Mar 12 22:46:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shirshov X-Patchwork-Id: 11435647 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DA9FF92A for ; Thu, 12 Mar 2020 22:49:40 +0000 (UTC) Received: from bastion.fedoraproject.org (bastion01.fedoraproject.org [209.132.181.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 97F4E206CD for ; Thu, 12 Mar 2020 22:49:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 97F4E206CD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=libteam-bounces@lists.fedorahosted.org Received: from mailman01.phx2.fedoraproject.org (mailman01.phx2.fedoraproject.org [10.5.126.36]) by bastion01.phx2.fedoraproject.org (Postfix) with ESMTP id 7447D607A2F9; Thu, 12 Mar 2020 22:49:39 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 bastion01.phx2.fedoraproject.org 7447D607A2F9 Received: from mailman01.phx2.fedoraproject.org (localhost [IPv6:::1]) by mailman01.phx2.fedoraproject.org (Postfix) with ESMTP id 5EE5C5D60EB8F; Thu, 12 Mar 2020 22:49:39 +0000 (UTC) Received: by mailman01.phx2.fedoraproject.org (Postfix, from userid 991) id 418525D60EB91; Thu, 12 Mar 2020 22:49:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mailman01.phx2.fedoraproject.org X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=disabled version=3.4.0 Received: from smtp-mm-ib01.fedoraproject.org (smtp-mm-ib01.vpn.fedoraproject.org [192.168.1.83]) by mailman01.phx2.fedoraproject.org (Postfix) with ESMTP id 744C95D5AC6A8 for ; Thu, 12 Mar 2020 22:49:34 +0000 (UTC) Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by smtp-mm-ib01.fedoraproject.org (Postfix) with ESMTPS id 0216E605D2D9 for ; Thu, 12 Mar 2020 22:49:34 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id t24so3793741pgj.7 for ; Thu, 12 Mar 2020 15:49:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PVI7+Of/T5eHkLrIajvy+oaZgGwHVquXlqwUasg5z5M=; b=qRsr09L1zIHbSvj740UC4Yupz1SwazsGCr1eEhzHnVdfpR6kchx1l1UGFTivj1fJPo hnNY/i3al03oUEL3zntweB6QlqASgZ6gqDE30P7ZLy0JGd8riCcZS59w3HIQHma2J6Vb b6CiY21SjV8rlMztzIswYQizLn0eBZfabreMab2lmu1JXFnYvSkgw2WKzQQTm7D+AXQ5 758t37CbuDJRbppiGxHOZbbazF57SEKkTuSUEB5e/sqGlhNQwHy/zLnGJNg2W6eRsErE LWwq21iU+Ue+HJXSIdXVrYepNtliMZSzJhhymnCYTUblgTK5xBzE/fNwzxxkhoxH0kis eXXg== X-Gm-Message-State: ANhLgQ1MbrmzrYj4O7x4MsKiTloE/Ac+iAe88DBhO9usALFpgECiatcy 1kLSVNqBYdrfyBfk0cBuG3fdn6t4 X-Google-Smtp-Source: ADFU+vuiNsDSXtCW3Klf3kKpV3aLsOX1CRZkrSjVxHMsZM/wSWbOmOVjx9LDFXyaNGUM0yVWW5izRQ== X-Received: by 2002:a62:ab07:: with SMTP id p7mr8723922pff.318.1584053372724; Thu, 12 Mar 2020 15:49:32 -0700 (PDT) Received: from localhost.localdomain (50-47-141-89.evrt.wa.frontiernet.net. [50.47.141.89]) by smtp.gmail.com with ESMTPSA id nl3sm10725051pjb.12.2020.03.12.15.49.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 Mar 2020 15:49:32 -0700 (PDT) From: Shuotian Cheng X-Google-Original-From: Shuotian Cheng To: libteam@lists.fedorahosted.org Subject: [PATCH] Fix ifinfo_link_with_port race condition with newlink Date: Thu, 12 Mar 2020 15:46:41 -0700 Message-Id: <1584053201-19150-2-git-send-email-shuche@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1584053201-19150-1-git-send-email-shuche@microsoft.com> References: <20200312174045.GB2272@nanopsycho.orion> <1584053201-19150-1-git-send-email-shuche@microsoft.com> Message-ID-Hash: RYVFSI6UEDER36VEXELC5QDBGLLQKCRU X-Message-ID-Hash: RYVFSI6UEDER36VEXELC5QDBGLLQKCRU X-MailFrom: pavel.contrib@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Pavel Shirshov , jiri@resnulli.us, Pavel Shirshov X-Mailman-Version: 3.1.1 Precedence: list List-Id: Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Pavel Shirshov When a member port is enslaved into a port channel immediately after the port channel was created, it is possible to get member port ifinfo structure not initialized for the member port because of a race condition. The race condition here occurs because order of following events is not strict: - adding the member port to the port channel; - creating ifinfo structure for the member port. The error message "Failed to link port with ifinfo" is thrown when a member port is tried to be added to the team handler's port list before ifinfo structure was initialized. To fix this situation ifinfo_find_create() is used to search member ports ifinfo structure in ifinfo_link_with_port(). Signed-off-by: Shuotian Cheng Signed-off-by: Pavel Shirshov --- libteam/ifinfo.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libteam/ifinfo.c b/libteam/ifinfo.c index 46d56a2..a15788b 100644 --- a/libteam/ifinfo.c +++ b/libteam/ifinfo.c @@ -453,7 +453,10 @@ int ifinfo_link_with_port(struct team_handle *th, uint32_t ifindex, { struct team_ifinfo *ifinfo; - ifinfo = ifinfo_find(th, ifindex); + if (port) + ifinfo = ifinfo_find_create(th, ifindex); + else + ifinfo = ifinfo_find(th, ifindex); if (!ifinfo) return -ENOENT; if (ifinfo->linked)