[Devel] [PATCH RHEL7 COMMIT] net: openvswitch: add capability to specify ifindex of new links

Vasily Averin vvs at virtuozzo.com
Mon Aug 17 09:52:18 MSK 2020


The commit is pushed to "branch-rh7-3.10.0-1127.18.2.vz7.163.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1127.18.2.vz7.163.2
------>
commit a8abe8f949eb79a40ebfc81a8c5c66ef1f731889
Author: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
Date:   Mon Aug 17 09:52:18 2020 +0300

    net: openvswitch: add capability to specify ifindex of new links
    
    Patchset description:
    CRIU is preserving ifindexes of net devices after restoration, but current Open
    vSwitch API are not capable to do that. So we need to modify it, because
    - Restoring net devices with random ifindex will lead to some excessive
    work to restore master relationship.
    - OVS device taking another link ifindex will likely cause some problems and
    may snowball previous point.
    - Although OVS daemon is not supported yet, it is holding some tables which
    have ifindex.
    
    https://jira.sw.ru/browse/PSBM-105844
    
    Current patch description:
    Openvswitch creates several net devices, but unlike rtnetlink API there is
    no option to specify ifindex for link. This is crucial for criu during
    restore stage.
    Use ovs_header->dp_ifindex during OVS_DP_CMD_NEW as desired ifindex.
    Use OVS_VPORT_ATTR_IFINDEX during OVS_VPORT_CMD_NEW to specify new netdev
    ifindex. Both values were not relevant for corresponding requests, so
    existing software won't mess with it.
    
    https://jira.sw.ru/browse/PSBM-105844
    Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
    Reviewed-by: Vasily Averin <vvs at virtuozzo.com>
---
 net/openvswitch/datapath.c           | 16 ++++++++++++++--
 net/openvswitch/vport-internal_dev.c |  1 +
 net/openvswitch/vport.h              |  2 ++
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
index 6d63ace..47bf4db 100644
--- a/net/openvswitch/datapath.c
+++ b/net/openvswitch/datapath.c
@@ -1582,6 +1582,7 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
 	struct vport *vport;
 	struct ovs_net *ovs_net;
 	int err, i;
+	struct ovs_header *ovs_header = info->userhdr;
 
 	err = -EINVAL;
 	if (!a[OVS_DP_ATTR_NAME] || !a[OVS_DP_ATTR_UPCALL_PID])
@@ -1626,6 +1627,7 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
 	parms.dp = dp;
 	parms.port_no = OVSP_LOCAL;
 	parms.upcall_portids = a[OVS_DP_ATTR_UPCALL_PID];
+	parms.desired_ifindex = ovs_header->dp_ifindex;
 
 	ovs_dp_change(dp, a);
 
@@ -2013,7 +2015,10 @@ static int ovs_vport_cmd_new(struct sk_buff *skb, struct genl_info *info)
 	if (!a[OVS_VPORT_ATTR_NAME] || !a[OVS_VPORT_ATTR_TYPE] ||
 	    !a[OVS_VPORT_ATTR_UPCALL_PID])
 		return -EINVAL;
-	if (a[OVS_VPORT_ATTR_IFINDEX])
+
+	parms.type = nla_get_u32(a[OVS_VPORT_ATTR_TYPE]);
+
+	if (a[OVS_VPORT_ATTR_IFINDEX] && parms.type != OVS_VPORT_TYPE_INTERNAL)
 		return -EOPNOTSUPP;
 
 	port_no = a[OVS_VPORT_ATTR_PORT_NO]
@@ -2050,12 +2055,19 @@ restart:
 	}
 
 	parms.name = nla_data(a[OVS_VPORT_ATTR_NAME]);
-	parms.type = nla_get_u32(a[OVS_VPORT_ATTR_TYPE]);
 	parms.options = a[OVS_VPORT_ATTR_OPTIONS];
 	parms.dp = dp;
 	parms.port_no = port_no;
 	parms.upcall_portids = a[OVS_VPORT_ATTR_UPCALL_PID];
 
+	if (parms.type == OVS_VPORT_TYPE_INTERNAL) {
+		if (a[OVS_VPORT_ATTR_IFINDEX])
+			parms.desired_ifindex =
+				nla_get_u32(a[OVS_VPORT_ATTR_IFINDEX]);
+		else
+			parms.desired_ifindex = 0;
+	}
+
 	vport = new_vport(&parms);
 	err = PTR_ERR(vport);
 	if (IS_ERR(vport)) {
diff --git a/net/openvswitch/vport-internal_dev.c b/net/openvswitch/vport-internal_dev.c
index 2757f21..8ec8ae5 100644
--- a/net/openvswitch/vport-internal_dev.c
+++ b/net/openvswitch/vport-internal_dev.c
@@ -202,6 +202,7 @@ static struct vport *internal_dev_create(const struct vport_parms *parms)
 	if (vport->port_no == OVSP_LOCAL)
 		vport->dev->features |= NETIF_F_NETNS_LOCAL;
 
+	dev->ifindex = parms->desired_ifindex;
 	rtnl_lock();
 	err = register_netdevice(vport->dev);
 	if (err)
diff --git a/net/openvswitch/vport.h b/net/openvswitch/vport.h
index cda66c2..c5281b5 100644
--- a/net/openvswitch/vport.h
+++ b/net/openvswitch/vport.h
@@ -109,6 +109,8 @@ struct vport_parms {
 	enum ovs_vport_type type;
 	struct nlattr *options;
 
+	int desired_ifindex;
+
 	/* For ovs_vport_alloc(). */
 	struct datapath *dp;
 	u16 port_no;


More information about the Devel mailing list