Compare commits

...

No commits in common. "c8s" and "c10s" have entirely different histories.
c8s ... c10s

10 changed files with 1 additions and 432 deletions

4
.gitignore vendored
View File

@ -1,4 +0,0 @@
SOURCES/prefixdevname-0.1.0-vendor.tar.gz
SOURCES/prefixdevname-0.1.0.tar.gz
/prefixdevname-0.1.0-vendor.tar.gz
/prefixdevname-0.1.0.tar.gz

View File

@ -1,43 +0,0 @@
From 1657894cf9a7a67de4e945d127d3a8ec8e3782a7 Mon Sep 17 00:00:00 2001
From: Michal Sekletar <msekleta@redhat.com>
Date: Tue, 14 Aug 2018 10:43:25 +0000
Subject: [PATCH] udev: assign new name to the interface directly and don't
rely on net_setup_link
---
rules/71-prefixdevname.rules | 2 +-
src/main.rs | 6 ++++--
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/rules/71-prefixdevname.rules b/rules/71-prefixdevname.rules
index 15e2e1e..c45da2f 100644
--- a/rules/71-prefixdevname.rules
+++ b/rules/71-prefixdevname.rules
@@ -6,6 +6,6 @@ ATTR{type}!="1", GOTO="net_ifnames_prefix_end"
IMPORT{cmdline}="net.ifnames.prefix"
ENV{net.ifnames.prefix}!="?*", GOTO="net_ifnames_prefix_end"
-PROGRAM="/usr/lib/udev/prefixdevname"
+PROGRAM="/usr/lib/udev/prefixdevname", RESULT=="?*", NAME="$result"
LABEL="net_ifnames_prefix_end"
diff --git a/src/main.rs b/src/main.rs
index 15bb6fa..54f4de4 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -86,8 +86,10 @@ fn main() {
exit_maybe_unlock(Some(&mut sema), 1);
}
- info!("New link file was generated at {}", link_config.link_file_path().into_os_string().into_string().unwrap());
- info!("Consider rebuilding initrd image, using \"dracut -f\"");
+ debug!("New link file was generated at {}", link_config.link_file_path().into_os_string().into_string().unwrap());
+ debug!("Consider rebuilding initrd image, using \"dracut -f\"");
+
+ println!("{}", next_link_name);
sema.unlock();
}
--
2.17.1

View File

@ -1,49 +0,0 @@
From b157be43805d90aef60c24530b9a0492abf00ebc Mon Sep 17 00:00:00 2001
From: Michal Sekletar <msekleta@redhat.com>
Date: Wed, 12 Sep 2018 14:36:34 +0000
Subject: [PATCH] dracut: introduce new dracut module prefixdevname-tools
This module will be used by lorax to make sure that prefixdevname is
included in initrd.img used for system installation.
---
Makefile | 2 ++
dracut/71prefixdevname-tools/module-setup.sh | 11 +++++++++++
2 files changed, 13 insertions(+)
create mode 100755 dracut/71prefixdevname-tools/module-setup.sh
diff --git a/Makefile b/Makefile
index fb930d4..982c5d9 100644
--- a/Makefile
+++ b/Makefile
@@ -25,9 +25,11 @@ check:
install:
mkdir -p $(DESTDIR)/usr/lib/udev/rules.d
mkdir -p $(DESTDIR)/usr/lib/dracut/modules.d/71prefixdevname
+ mkdir -p $(DESTDIR)/usr/lib/dracut/modules.d/71prefixdevname-tools
install -p -m 0755 target/release/$(NAME) $(DESTDIR)/usr/lib/udev/
install -p -m 644 rules/71-prefixdevname.rules $(DESTDIR)/usr/lib/udev/rules.d/
install -p -m 0755 dracut/71prefixdevname/module-setup.sh $(DESTDIR)/usr/lib/dracut/modules.d/71prefixdevname/
+ install -p -m 0755 dracut/71prefixdevname-tools/module-setup.sh $(DESTDIR)/usr/lib/dracut/modules.d/71prefixdevname-tools/
uninstall:
rm -f $(DESTDIR)/usr/lib/udev/$(NAME)
diff --git a/dracut/71prefixdevname-tools/module-setup.sh b/dracut/71prefixdevname-tools/module-setup.sh
new file mode 100755
index 0000000..0ff010e
--- /dev/null
+++ b/dracut/71prefixdevname-tools/module-setup.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+# Include the prefixdevname tools only if this was explicitely requested
+check() {
+ return 255
+}
+
+install() {
+ inst /usr/lib/udev/prefixdevname
+ inst_rules 71-prefixdevname.rules
+}
--
2.17.1

View File

@ -1,73 +0,0 @@
From c55c64cce2449b4616b3f71b42fedc1e3098a04c Mon Sep 17 00:00:00 2001
From: Michal Sekletar <msekleta@redhat.com>
Date: Fri, 21 Sep 2018 08:42:58 +0000
Subject: [PATCH] core: don't rename interfaces that already have the name in
expected format
---
src/main.rs | 5 +++++
src/util.rs | 27 +++++++++++++++++++++++++++
2 files changed, 32 insertions(+)
diff --git a/src/main.rs b/src/main.rs
index 54f4de4..5c1a42b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -37,6 +37,11 @@ fn main() {
exit_maybe_unlock(None, 0);
}
+ if ! rename_needed(&prefix).unwrap() {
+ info!("Interface name already has expected format, not renaming again");
+ exit_maybe_unlock(None, 0);
+ }
+
let mut sema = match Semaphore::new_with_name("net-prefix-ifnames") {
Ok(s) => s,
Err(e) => {
diff --git a/src/util.rs b/src/util.rs
index 85a1090..8727074 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -11,6 +11,14 @@ use regex::Regex;
use sema::*;
+pub fn rename_needed(prefix: &str) -> Result<bool, Box<Error>> {
+ // TODO: if INTERFACE is unset we should probably check sysname
+ let ifname = env::var("INTERFACE").unwrap_or("".to_string());
+ let re: Regex = Regex::new(&format!("{}\\d+", prefix)).unwrap();
+
+ Ok(!re.is_match(&ifname))
+}
+
pub fn hwaddr_valid<T: ToString>(hwaddr: &T) -> bool {
use std::num::ParseIntError;
@@ -161,4 +169,23 @@ mod tests {
fn long_prefix_not_ok() {
assert_eq!(false, prefix_ok(&"neeeeeeeeeeeeeeet"));
}
+
+ #[test]
+ fn rename_is_needed() {
+ env::set_var("INTERFACE", "eth0");
+
+ assert_eq!(rename_needed("net").unwrap(), true);
+ }
+
+ #[test]
+ fn rename_not_needed() {
+ env::set_var("INTERFACE", "net0");
+
+ assert_eq!(rename_needed("net").unwrap(), false);
+ }
+
+ #[test]
+ fn rename_needed_interface_unset() {
+ assert_eq!(rename_needed("net").unwrap(), true);
+ }
}
--
2.17.1

View File

@ -1,90 +0,0 @@
From 7f395e0bdb529f2ea6fe2234956e04869a3464e6 Mon Sep 17 00:00:00 2001
From: Michal Sekletar <msekleta@redhat.com>
Date: Fri, 2 Nov 2018 12:10:12 +0000
Subject: [PATCH] core: if interface already has name in expected format (i.e.
<prefix><number>) print the name to stdout
This is needed in order to prevent renaming back to name given by one of
built-in naming schemes.
For example, NIC appears in initrd (during system installation) and gets
renamed to net0. Later we switch root to anaconda's stage2 and all HW is
cold-plugged. Prefixdevname should figure out that renaming is not
necessary. However, if we don't print anything to stdout (i.e. nothing
gets assigned to NAME= variable) then logic in subsequent rules
eventually renames interface to some other name determined by net_id.
---
src/main.rs | 6 ++++--
src/util.rs | 20 ++++++++++----------
2 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/src/main.rs b/src/main.rs
index 5c1a42b..b0c02b8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -37,8 +37,10 @@ fn main() {
exit_maybe_unlock(None, 0);
}
- if ! rename_needed(&prefix).unwrap() {
- info!("Interface name already has expected format, not renaming again");
+ let ifname = event_device_name();
+
+ if ! rename_needed(&ifname, &prefix).unwrap() {
+ println!("{}", ifname);
exit_maybe_unlock(None, 0);
}
diff --git a/src/util.rs b/src/util.rs
index 8727074..98eb32f 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -11,14 +11,18 @@ use regex::Regex;
use sema::*;
-pub fn rename_needed(prefix: &str) -> Result<bool, Box<Error>> {
- // TODO: if INTERFACE is unset we should probably check sysname
- let ifname = env::var("INTERFACE").unwrap_or("".to_string());
+pub fn rename_needed(ifname: &str, prefix: &str) -> Result<bool, Box<Error>> {
let re: Regex = Regex::new(&format!("{}\\d+", prefix)).unwrap();
Ok(!re.is_match(&ifname))
}
+pub fn event_device_name() -> String {
+ let ifname = env::var("INTERFACE").unwrap_or("".to_string());
+
+ ifname.to_string()
+}
+
pub fn hwaddr_valid<T: ToString>(hwaddr: &T) -> bool {
use std::num::ParseIntError;
@@ -172,20 +176,16 @@ mod tests {
#[test]
fn rename_is_needed() {
- env::set_var("INTERFACE", "eth0");
-
- assert_eq!(rename_needed("net").unwrap(), true);
+ assert_eq!(rename_needed("eth0", "net").unwrap(), true);
}
#[test]
fn rename_not_needed() {
- env::set_var("INTERFACE", "net0");
-
- assert_eq!(rename_needed("net").unwrap(), false);
+ assert_eq!(rename_needed("net0", "net").unwrap(), false);
}
#[test]
fn rename_needed_interface_unset() {
- assert_eq!(rename_needed("net").unwrap(), true);
+ assert_eq!(rename_needed("", "net").unwrap(), true);
}
}
--
2.17.2

View File

@ -1,65 +0,0 @@
From 58886377310bb2190c6364aa3df83d1858183446 Mon Sep 17 00:00:00 2001
From: Michal Sekletar <msekleta@redhat.com>
Date: Fri, 2 Nov 2018 16:25:58 +0000
Subject: [PATCH] core: don't assign names to virtual network devices
---
src/main.rs | 5 +++++
src/util.rs | 20 ++++++++++++++++++++
2 files changed, 25 insertions(+)
diff --git a/src/main.rs b/src/main.rs
index b0c02b8..6eeb793 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -37,6 +37,11 @@ fn main() {
exit_maybe_unlock(None, 0);
}
+ if event_device_virtual() {
+ debug!("Called for virtual network device, ignoring");
+ exit_maybe_unlock(None, 0);
+ }
+
let ifname = event_device_name();
if ! rename_needed(&ifname, &prefix).unwrap() {
diff --git a/src/util.rs b/src/util.rs
index 98eb32f..50c6677 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -23,6 +23,12 @@ pub fn event_device_name() -> String {
ifname.to_string()
}
+pub fn event_device_virtual() -> bool {
+ let devpath = env::var("DEVPATH").unwrap_or("".to_string());
+
+ devpath.starts_with("/devices/virtual")
+}
+
pub fn hwaddr_valid<T: ToString>(hwaddr: &T) -> bool {
use std::num::ParseIntError;
@@ -188,4 +194,18 @@ mod tests {
fn rename_needed_interface_unset() {
assert_eq!(rename_needed("", "net").unwrap(), true);
}
+
+ #[test]
+ fn event_device_not_virtual() {
+ env::set_var("DEVPATH", "/devices/pci0000:00/0000:00:03.0/virtio0/net/eth0");
+
+ assert_eq!(event_device_virtual(), false);
+ }
+
+ #[test]
+ fn event_device_is_virtual() {
+ env::set_var("DEVPATH", "/devices/virtual/net/bond0");
+
+ assert_eq!(event_device_virtual(), true);
+ }
}
--
2.17.2

View File

@ -1,25 +0,0 @@
From 7205027f998d956df125da517d0eb9c03515f1f1 Mon Sep 17 00:00:00 2001
From: rpm-build <rpm-build>
Date: Fri, 10 Aug 2018 18:58:54 +0200
Subject: [PATCH] sema: fix cast (needed to build with rust-1.26)
---
src/sema.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/sema.rs b/src/sema.rs
index 4a9a63e..5be3dc8 100644
--- a/src/sema.rs
+++ b/src/sema.rs
@@ -16,7 +16,7 @@ impl Semaphore {
let s;
unsafe {
- s = libc::sem_open(raw_sema_name.as_ptr() as *const i8, libc::O_CREAT, libc::S_IRUSR | libc::S_IWUSR, 1);
+ s = libc::sem_open(raw_sema_name.as_ptr() as *const u8, libc::O_CREAT, libc::S_IRUSR | libc::S_IWUSR, 1);
if s.is_null() {
return Err(From::from("Failed to allocate named semaphore, sem_open() failed"));
}
--
2.14.4

1
dead.package Normal file
View File

@ -0,0 +1 @@
prefixdevname package is retired on branch c10s for CS-2174

View File

@ -1,81 +0,0 @@
Name: prefixdevname
Version: 0.1.0
Release: 6%{?dist}
Summary: Udev helper utility that provides network interface naming using user defined prefix
License: MIT
URL: https://www.github.com/msekletar/prefixdevname
Source0: https://github.com/msekletar/%{name}/releases/download/v%{version}/%{name}-%{version}.tar.gz
Source1: %{name}-%{version}-vendor.tar.gz
Patch0001: 0001-udev-assign-new-name-to-the-interface-directly-and-d.patch
Patch0002: 0002-dracut-introduce-new-dracut-module-prefixdevname-too.patch
Patch0003: 0003-core-don-t-rename-interfaces-that-already-have-the-n.patch
Patch0004: 0004-core-if-interface-already-has-name-in-expected-forma.patch
Patch0005: 0005-core-don-t-assign-names-to-virtual-network-devices.patch
Patch0999: 0999-sema-fix-cast-needed-to-build-with-rust-1.26.patch
ExclusiveArch: %{rust_arches}
BuildRequires: rust-toolset
BuildRequires: git
BuildRequires: systemd-devel
%description
This package provides udev helper utility that tries to consistently name all ethernet NICs using
user defined prefix (e.g. net.ifnames.prefix=net produces NIC names net0, net1, ...). Utility is
called from udev rule and it determines NIC name and writes out configuration file for udev's
net_setup_link built-in (e.g. /etc/systemd/network/71-net-ifnames-prefix-net0.link).
%prep
%setup -q
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
%ifarch s390 s390x ppc %{power64} aarch64
%patch999 -p1 -b .cast
%endif
%cargo_prep -V 1
%build
%cargo_build
%install
%make_install
%files
%defattr(-,root,root,-)
%license LICENSE
%doc README.md
%{_prefix}/lib/udev/%{name}
%{_prefix}/lib/udev/rules.d/*.rules
%dir %{_prefix}/lib/dracut/modules.d/71%{name}
%{_prefix}/lib/dracut/modules.d/71%{name}/*
%dir %{_prefix}/lib/dracut/modules.d/71%{name}-tools
%{_prefix}/lib/dracut/modules.d/71%{name}-tools/*
%changelog
* Wed Dec 19 2018 Michal Sekletár <msekleta@redhat.com> - 0.1.0-6
- rebuild with non-SCL toolset
* Mon Nov 05 2018 Michal Sekletár <msekleta@redhat.com> - 0.1.0-5
- if interface has name in expected format print it to stdout (#1643515)
- don't assign names to virtual devices (#1644294)
* Fri Sep 21 2018 Michal Sekletár <msekleta@redhat.com> - 0.1.0-4
- never rename interfaces that already have names in expected format (#1631650)
* Wed Sep 12 2018 Michal Sekletár <msekleta@redhat.com> - 0.1.0-3
- dracut: introduce new dracut module that includes prefixdevname to initrd.img
* Tue Aug 14 2018 Michal Sekletár <msekleta@redhat.com> - 0.1.0-2
- udev: assign new name to the interface directly by assigning to NAME
* Wed Aug 08 2018 Michal Sekletar <msekleta@redhat.com> - 0.1.0-1
- initial package

View File

@ -1,2 +0,0 @@
SHA512 (prefixdevname-0.1.0-vendor.tar.gz) = 5ba151799ed1f4a0416f2b0d67f73eeecda39c49b7397790b8d501b8d76f9230cff49785ee1e0a4004e225397c964fe3073118b65ebdf19ff9500f07edccbe66
SHA512 (prefixdevname-0.1.0.tar.gz) = f366a8e6cec096776e38c93ae2a1b1bd07375a48f67e744dfe7456262345671137dae3ebdde7acb44e9b0468f26e96991659839dbbd071d03d4491e8722a9c7f