From patchwork Tue Aug 11 08:01:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 11708847 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 A9E4D109A for ; Tue, 11 Aug 2020 08:03:12 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 85C7820656 for ; Tue, 11 Aug 2020 08:03:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=xen.org header.i=@xen.org header.b="S5x8KVbr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 85C7820656 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k5PEd-0003v7-US; Tue, 11 Aug 2020 08:02:15 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k5PEc-0003tc-5m for xen-devel@lists.xenproject.org; Tue, 11 Aug 2020 08:02:14 +0000 X-Inumbo-ID: 53e06020-7d57-44ed-b070-05e1453e4c9f Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 53e06020-7d57-44ed-b070-05e1453e4c9f; Tue, 11 Aug 2020 08:02:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=eSmprS1bsesB0cQvNRI38Z139gI/ZjEmaiUVzzjZXv4=; b=S5x8KVbrxbU9txM7PfsxBvEg8M DtAJMTFQUnLErPOfvE3R48IX7bhErJxl2xNZGUF1cHx86gsUajNc91q7eoxOkfKJxD4LvRXD0zK9W DCitwEVJzOreK/ov6feZIwaKrt6nbBH51/ag+nF66bJEEny1RUMCC596PW+GCRBi/Rts=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k5PEX-0003un-6K; Tue, 11 Aug 2020 08:02:09 +0000 Received: from host86-143-223-30.range86-143.btcentralplus.com ([86.143.223.30] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k5PEW-0000k5-Ul; Tue, 11 Aug 2020 08:02:09 +0000 From: Paul Durrant To: xen-devel@lists.xenproject.org Subject: [PATCH v3 3/8] tools/hotplug/Linux: add remove_from_bridge() Date: Tue, 11 Aug 2020 09:01:57 +0100 Message-Id: <20200811080202.31163-4-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200811080202.31163-1-paul@xen.org> References: <20200811080202.31163-1-paul@xen.org> MIME-Version: 1.0 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Paul Durrant , Ian Jackson , Wei Liu Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Paul Durrant This patch adds a remove_from_bridge() function into xen-network-common.sh to partner with the existing add_to_bridge() function. The vif-bridge script is then modified to use it. Signed-off-by: Paul Durrant --- Cc: Ian Jackson Cc: Wei Liu v3: - Re-factored from "tools/hotplug: add remove_from_bridge() and improve debug output" and "tools/hotplug: combine add/online and remove/offline in vif-bridge..." in v2 --- tools/hotplug/Linux/vif-bridge | 7 +------ tools/hotplug/Linux/xen-network-common.sh | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/tools/hotplug/Linux/vif-bridge b/tools/hotplug/Linux/vif-bridge index e722090ca8..c3e409926d 100644 --- a/tools/hotplug/Linux/vif-bridge +++ b/tools/hotplug/Linux/vif-bridge @@ -84,12 +84,7 @@ case "$command" in ;; offline) - if which brctl >&/dev/null; then - do_without_error brctl delif "$bridge" "$dev" - else - do_without_error ip link set "$dev" nomaster - fi - do_without_error ifconfig "$dev" down + remove_from_bridge "$bridge" "$dev" ;; add) diff --git a/tools/hotplug/Linux/xen-network-common.sh b/tools/hotplug/Linux/xen-network-common.sh index ec3bd4ec4a..6a0904361f 100644 --- a/tools/hotplug/Linux/xen-network-common.sh +++ b/tools/hotplug/Linux/xen-network-common.sh @@ -141,6 +141,25 @@ add_to_bridge () { ip link set dev ${dev} up } +remove_from_bridge () { + local bridge=$1 + local dev=$2 + + do_without_error ip link set dev ${dev} down + + # Don't remove $dev from $bridge if it's not on the bridge. + if [ -e "/sys/class/net/${bridge}/brif/${dev}" ]; then + log debug "removing $dev from bridge $bridge" + if which brctl >&/dev/null; then + do_without_error brctl delif ${bridge} ${dev} + else + do_without_error ip link set ${dev} nomaster + fi + else + log debug "$dev not on bridge $bridge" + fi +} + # Usage: set_mtu bridge dev set_mtu () { local bridge=$1