All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH][RFC] rules: add persistent vf mac rules generator for SR-IOV device intel 82576
@ 2011-08-18 10:24 Li Dongyang
  2011-08-18 11:13 ` [PATCH][RFC] rules: add persistent vf mac rules generator for Kay Sievers
  2011-08-18 22:58 ` Marco d'Itri
  0 siblings, 2 replies; 3+ messages in thread
From: Li Dongyang @ 2011-08-18 10:24 UTC (permalink / raw)
  To: linux-hotplug

This is the rule generator for SR-IOV device intel 82576,
because the mac address of each Virtual Function interfaces are generated
randomly each time the igb driver loaded, this is a way to make the
mac of the VFs consistent cross reboots.
What we do is when we see the VFs up first time, we record each mac
and generate a rule, writing each mac into the rule and set it via ip utility
on the next boot.

and when we generate the rule, we block and wait on the files under /sys
cause sometimes the udev event is triggerd before the VFs are up completely,
and we might see no mac of the VFs if we do not block. However, during
installation of a system like SLES, the rule generator will stall
and wait for the file, so I think some suggestions are needed, Thanks

Signed-off-by: Li Dongyang <lidongyang@novell.com>
---
 Makefile.am                                        |   10 ++-
 .../75-persistent-mac-vf-generator.rules           |    1 +
 extras/rule_generator/set_vf_mac                   |   13 +++
 extras/rule_generator/vf_mac.functions             |   35 +++++++++
 extras/rule_generator/write_vf_mac_rules           |   81 ++++++++++++++++++++
 5 files changed, 137 insertions(+), 3 deletions(-)
 create mode 100644 extras/rule_generator/75-persistent-mac-vf-generator.rules
 create mode 100644 extras/rule_generator/set_vf_mac
 create mode 100644 extras/rule_generator/vf_mac.functions
 create mode 100644 extras/rule_generator/write_vf_mac_rules

diff --git a/Makefile.am b/Makefile.am
index 5347569..3f868ac 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -579,14 +579,18 @@ if ENABLE_RULE_GENERATOR
 # ------------------------------------------------------------------------------
 dist_libexec_SCRIPTS += \
 	extras/rule_generator/write_cd_rules \
-	extras/rule_generator/write_net_rules
+	extras/rule_generator/write_net_rules \
+	extras/rule_generator/write_vf_mac_rules \
+	extras/rule_generator/set_vf_mac
 
 udevhomedir = $(libexecdir)
-dist_udevhome_DATA = extras/rule_generator/rule_generator.functions
+dist_udevhome_DATA = extras/rule_generator/rule_generator.functions \
+		     extras/rule_generator/vf_mac.functions
 
 dist_udevrules_DATA += \
 	extras/rule_generator/75-cd-aliases-generator.rules \
-	extras/rule_generator/75-persistent-net-generator.rules
+	extras/rule_generator/75-persistent-net-generator.rules \
+	extras/rule_generator/75-persistent-mac-vf-generator.rules
 endif
 
 if ENABLE_UDEV_ACL
diff --git a/extras/rule_generator/75-persistent-mac-vf-generator.rules b/extras/rule_generator/75-persistent-mac-vf-generator.rules
new file mode 100644
index 0000000..d18eea9
--- /dev/null
+++ b/extras/rule_generator/75-persistent-mac-vf-generator.rules
@@ -0,0 +1 @@
+ATTR{vendor}="0x8086", ATTR{device}="0x10ca", ENV{PCI_SLOT_NAME}="%k", ENV{MATCHADDR}="$attr{address}", RUN+="write_vf_mac_rules"
diff --git a/extras/rule_generator/set_vf_mac b/extras/rule_generator/set_vf_mac
new file mode 100644
index 0000000..e539a7c
--- /dev/null
+++ b/extras/rule_generator/set_vf_mac
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+. /lib/udev/vf_mac.functions
+
+PCI_SLOT_NAME=$1
+VF_MAC=$2
+
+get_pf_name $PCI_SLOT_NAME
+get_vf_id $PCI_SLOT_NAME
+
+/sbin/ip link set dev $PF_INF_NAME vf $VF_ID mac $VF_MAC
+
+exit 0
diff --git a/extras/rule_generator/vf_mac.functions b/extras/rule_generator/vf_mac.functions
new file mode 100644
index 0000000..19896d7
--- /dev/null
+++ b/extras/rule_generator/vf_mac.functions
@@ -0,0 +1,35 @@
+# functions used by set_vf_mac and write_vf_mac_rules
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation version 2 of the License.
+
+get_pf_name() {
+	local pci_slot_id="$1"
+        local name
+	while [ 1 ]; do
+		if [ -d /sys/bus/pci/devices/${pci_slot_id}/physfn/net/ ]; then
+			break
+		fi
+	done
+        for name in /sys/bus/pci/devices/${pci_slot_id}/physfn/net/* ;do
+                PF_INF_NAME=${name##*/}
+        done
+}
+
+get_vf_id() {
+	local pci_slot_id="$1"
+        local name
+	while [ 1 ]; do
+                if [ -d /sys/bus/pci/devices/${pci_slot_id}/physfn/ ]; then
+                        break
+                fi
+        done
+        for name in /sys/bus/pci/devices/${pci_slot_id}/physfn/virtfn* ;do
+                readlink "$name" | grep -q "$pci_slot_id"
+                if [ $? -eq 0 ] ;then
+                        VF_ID=${name##${name%%?}}
+                        return 0
+                fi
+        done
+}
diff --git a/extras/rule_generator/write_vf_mac_rules b/extras/rule_generator/write_vf_mac_rules
new file mode 100644
index 0000000..6f4a9ca
--- /dev/null
+++ b/extras/rule_generator/write_vf_mac_rules
@@ -0,0 +1,81 @@
+#!/bin/sh
+
+# This script is run to create persistent network device naming rules
+# based on properties of the device.
+# If the interface needs to be renamed, INTERFACE_NEW=<name> will be printed
+# on stdout to allow udev to IMPORT it.
+
+# variables used to communicate:
+#   PCI_SLOT_NAME         The pci slot name of one virtual function inited
+
+# Copyright (C) 2011 Li Dongyang <lidongyang@novell.com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+
+RULES_FILE='/etc/udev/rules.d/70-persistent-mac-vf.rules'
+
+. /lib/udev/rule_generator.functions
+. /lib/udev/vf_mac.functions
+
+if [ -z "$PCI_SLOT_NAME" ]; then
+        echo "missing \$PCI_SLOT_NAME" >&2
+        exit 1
+fi
+
+if [ -e $RULES_FILE ]; then
+        grep -q $PCI_SLOT_NAME $RULES_FILE
+        if [ $? -eq 0 ]; then
+                exit 0
+        fi
+fi
+
+write_rule() {
+        local pci_slot_name="$1"
+        local vf_mac="$2"
+        local comment="$3"
+
+        {
+        if [ "$PRINT_HEADER" ]; then
+                PRINT_HEADER+                echo "# This file was automatically generated by the $0"
+                echo "# program, run by the persistent-mac-vf-generator.rules rules file."
+                echo "#"
+                echo "# You can modify it, as long as you keep each rule on a single"
+                echo "# line, and change only the value of the MAC you want."
+        fi
+
+        echo ""
+        [ "$comment" ] && echo "# $comment"
+        echo "SUBSYSTEM=\"pci\", ACTION=\"change\", KERNEL=\"$pci_slot_name\", RUN+=\"set_vf_mac $pci_slot_name $vf_mac\""
+        } >> $RULES_FILE
+}
+
+get_pf_name $PCI_SLOT_NAME
+get_vf_id $PCI_SLOT_NAME
+
+VF_MAC=$(ip link show $PF_INF_NAME | grep "vf $VF_ID")
+VF_MAC=${VF_MAC##* }
+
+# Prevent concurrent processes from modifying the file at the same time.
+lock_rules_file
+
+# Check if the rules file is writeable.
+choose_rules_file
+
+write_rule "$PCI_SLOT_NAME" "$VF_MAC"
+
+unlock_rules_file
+
+exit 0
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH][RFC] rules: add persistent vf mac rules generator for
  2011-08-18 10:24 [PATCH][RFC] rules: add persistent vf mac rules generator for SR-IOV device intel 82576 Li Dongyang
@ 2011-08-18 11:13 ` Kay Sievers
  2011-08-18 22:58 ` Marco d'Itri
  1 sibling, 0 replies; 3+ messages in thread
From: Kay Sievers @ 2011-08-18 11:13 UTC (permalink / raw)
  To: linux-hotplug

On Thu, Aug 18, 2011 at 12:24, Li Dongyang <lidongyang@novell.com> wrote:
> This is the rule generator for SR-IOV device intel 82576,
> because the mac address of each Virtual Function interfaces are generated
> randomly each time the igb driver loaded, this is a way to make the
> mac of the VFs consistent cross reboots.
> What we do is when we see the VFs up first time, we record each mac
> and generate a rule, writing each mac into the rule and set it via ip utility
> on the next boot.
>
> and when we generate the rule, we block and wait on the files under /sys
> cause sometimes the udev event is triggerd before the VFs are up completely,
> and we might see no mac of the VFs if we do not block. However, during
> installation of a system like SLES, the rule generator will stall
> and wait for the file, so I think some suggestions are needed, Thanks

We are about to kill the entire rule_generator in the next months. It
has too man problems, and does not really solve any real world
problem:
The majority of systems does not rely on predictable names, and does
not need any automatic rules mangling from the hotplug path.

The systems who rely on predictable names need manual configuration
anyway. So we will just require explicit configuration for predictable
names instead of automatically generating system config from the
hotplug path.

The rule_generator cause too many problems to continue it. The
intersection of systems who need it and the systems which do not have
manual config anyway is almost zero, so it makes not much sense to
continue that road.

The current plan is to have a generic format for network configuration
and create udev rules and systemd service files on-the-fly at bootup,
before udev is even started. The generated udev rules will trigger
when devices show up in the hotplug path and rename the interfaces.
Systemd will start a service for the every configured interface which
will apply the needed IP config or start things like the dhcp client.
Unconfigured interfaces without a specific matching configuration file
will just keep the kernel's name, there will be no try to create any
persistent records for it.

This all is expected to happen during the next months, and the code to
do this will likely be merged into systemd and not udev. The udev rule
generator will be deleted in the longer run. We tried, but we need to
admit today, that it isn't the solution we are looking for, to solve
issues regarding predictable network interface names.

Thanks,
Kay

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH][RFC] rules: add persistent vf mac rules generator for
  2011-08-18 10:24 [PATCH][RFC] rules: add persistent vf mac rules generator for SR-IOV device intel 82576 Li Dongyang
  2011-08-18 11:13 ` [PATCH][RFC] rules: add persistent vf mac rules generator for Kay Sievers
@ 2011-08-18 22:58 ` Marco d'Itri
  1 sibling, 0 replies; 3+ messages in thread
From: Marco d'Itri @ 2011-08-18 22:58 UTC (permalink / raw)
  To: linux-hotplug

On Aug 18, Kay Sievers <kay.sievers@vrfy.org> wrote:

> We are about to kill the entire rule_generator in the next months. It
> has too man problems, and does not really solve any real world
> problem:
> The majority of systems does not rely on predictable names, and does
> not need any automatic rules mangling from the hotplug path.
For the records: the Debian community so far has not found any reason to
retire the rules generators, since they solve problems experienced by
our users base and do not cause significant troubles.
I plan to keep maintaining this code as long as it will be needed, and I
welcome coordination with other interested vendors.

> This all is expected to happen during the next months, and the code to
> do this will likely be merged into systemd and not udev. The udev rule
This probably rules it out as a solution for Debian: there are serious
doubts that systemd will be ever adopted since it is actively hostile to
supporting the toy ports.

-- 
ciao,
Marco

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-08-18 22:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-18 10:24 [PATCH][RFC] rules: add persistent vf mac rules generator for SR-IOV device intel 82576 Li Dongyang
2011-08-18 11:13 ` [PATCH][RFC] rules: add persistent vf mac rules generator for Kay Sievers
2011-08-18 22:58 ` Marco d'Itri

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.