commit 409d671fe0d16ed491a0f04bc025b8416f66dbf0 Author: overweight <5324761+overweight@user.noreply.gitee.com> Date: Mon Sep 30 11:09:33 2019 -0400 Package init diff --git a/0000-netcf-call-aug_load-at-most-once-per-second.patch b/0000-netcf-call-aug_load-at-most-once-per-second.patch new file mode 100644 index 0000000..ba09b0c --- /dev/null +++ b/0000-netcf-call-aug_load-at-most-once-per-second.patch @@ -0,0 +1,85 @@ +From 9b5f4eb57af28a604cd7ac8b2c1be9e49f0b517d Mon Sep 17 00:00:00 2001 +From: Laine Stump +Date: Mon, 28 Sep 2015 17:11:11 -0400 +Subject: [PATCH] call aug_load() at most once per second + +Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1268384 + +Previously, netcf would call aug_load() at the start of each public +API call, and rely on augeas quickly determining if the files needed +to be reread based on checking the mtime of all files. With a large +number of files (i.e. several hundred ifcfg files) just checking the +mtime of all files ends up taking quite a long time; enough to turn a +simple "virsh iface-list" of 300 bridges + 300 vlans into a 22 second +ordeal. + +With this patch applied, netcf will only call aug_load() at most once +every second, resulting in runtime for virsh iface-list going down to +< 1 second. + +The trade-off is that the results of a netcf API call could be up to 1 +second out of date (but only due to changes in the config external to +netcf). Since ifcfg files change very infrequently, this is likely +acceptable. +--- + src/dutil_linux.c | 8 +++++++- + src/dutil_linux.h | 1 + + 2 files changed, 8 insertions(+), 1 deletion(-) + +diff --git a/src/dutil_linux.c b/src/dutil_linux.c +index 0850593..24f4d95 100644 +--- a/src/dutil_linux.c ++++ b/src/dutil_linux.c +@@ -32,6 +32,7 @@ + #include + #include + #include ++#include + + #include + #include +@@ -151,6 +152,7 @@ int remove_augeas_xfm_table(struct netcf *ncf, + */ + augeas *get_augeas(struct netcf *ncf) { + int r; ++ time_t current_time; + + if (ncf->driver->augeas == NULL) { + augeas *aug; +@@ -186,9 +188,12 @@ augeas *get_augeas(struct netcf *ncf) { + } + ncf->driver->copy_augeas_xfm = 0; + ncf->driver->load_augeas = 1; ++ ncf->driver->load_augeas_time = 0; + } + +- if (ncf->driver->load_augeas) { ++ current_time = time(NULL); ++ if (ncf->driver->load_augeas && ++ ncf->driver->load_augeas_time != current_time) { + augeas *aug = ncf->driver->augeas; + + r = aug_load(aug); +@@ -207,6 +212,7 @@ augeas *get_augeas(struct netcf *ncf) { + } + ERR_THROW(r > 0, ncf, EOTHER, "errors in loading some config files"); + ncf->driver->load_augeas = 0; ++ ncf->driver->load_augeas_time = current_time; + } + return ncf->driver->augeas; + error: +diff --git a/src/dutil_linux.h b/src/dutil_linux.h +index a06a15c..75ac631 100644 +--- a/src/dutil_linux.h ++++ b/src/dutil_linux.h +@@ -41,6 +41,7 @@ struct driver { + struct nl_sock *nl_sock; + struct nl_cache *link_cache; + struct nl_cache *addr_cache; ++ time_t load_augeas_time; + unsigned int load_augeas : 1; + unsigned int copy_augeas_xfm : 1; + unsigned int augeas_xfm_num_tables; +-- +2.4.3 + diff --git a/0001-netcf-optimize-aug_match-query-for-all-ifcfg-files-related.patch b/0001-netcf-optimize-aug_match-query-for-all-ifcfg-files-related.patch new file mode 100644 index 0000000..b69938e --- /dev/null +++ b/0001-netcf-optimize-aug_match-query-for-all-ifcfg-files-related.patch @@ -0,0 +1,114 @@ +From 396e4e0698d9fb542f2eb8b32790a069e1c0df61 Mon Sep 17 00:00:00 2001 +From: Laine Stump +Date: Wed, 7 Oct 2015 13:49:45 -0400 +Subject: [PATCH] optimize aug_match() query for all ifcfg files related to an + interface + +This resolves: + + https://bugzilla.redhat.com/show_bug.cgi?id=1271341 (Fedora) + https://bugzilla.redhat.com/show_bug.cgi?id=1269613 (RHEL7) + +The original augeas search term used by netcf to find, for example, all the +ifcfg files associated with device "br1" was: + + "/files/etc/sysconfig/network-scripts/*[ " + "DEVICE = 'br1' or BRIDGE = 'br1' or MASTER = 'br1' or MASTER = " + "../*[BRIDGE = 'br1']/DEVICE ]/DEVICE" + +This is *extremely* inefficient - on a test host with 514 host +bridges, each with an attached vlan interface, a dumpxml of all +toplevel interfaces took 6m40s (*after* installing an augeas that +included augeas upstream commits a659f09a, 41e989ca, and 23d5e480 +which were all pushed after the augeas-1.4.0 release). + +In these two messages: + + https://www.redhat.com/archives/augeas-devel/2015-October/msg00003.html + https://www.redhat.com/archives/augeas-devel/2015-October/msg00004.html + +David Lutterkort suggested changing the search term to: + + "(/files/etc/sysconfig/network-scripts/*[(DEVICE|BRIDGE|MASTER) = 'br1']" + "|/files/etc/sysconfig/network-scripts/*[MASTER]" + "[MASTER = ../*[BRIDGE = 'br1']/DEVICE ])/DEVICE + +That's what this patch does. Testing shows that it is functionally +equivalent, and reduces the dumpxml time in the previously described +test from 6m40s down to 17 seconds. +--- + src/drv_redhat.c | 44 ++++++++++++++++++++++++++++++++++---------- + 1 file changed, 34 insertions(+), 10 deletions(-) + +diff --git a/src/drv_redhat.c b/src/drv_redhat.c +index 4935f98..092ef5c 100644 +--- a/src/drv_redhat.c ++++ b/src/drv_redhat.c +@@ -88,6 +88,38 @@ static const struct augeas_xfm_table augeas_xfm_common = + { .size = ARRAY_CARDINALITY(augeas_xfm_common_pv), + .pv = augeas_xfm_common_pv }; + ++/* aug_all_related_ifcfgs() - return the count of (and optionally a list ++ * of, if matches != NULL) the paths for all ifcfg files that are ++ * related to the interface "name". ++ */ ++static ++int aug_all_related_ifcfgs(struct netcf *ncf, char ***matches, const char *name) { ++ int nmatches; ++ ++ /* this includes the ifcfg files for: ++ * ++ * 1) the named interface itself (DEVICE=$name) ++ * ++ * 2) any interface naming $name as a bridge it is attached to ++ * (BRIDGE=$name) ++ * ++ * 3) any interface naming $name as the master of a bond it is ++ * enslaved to (MASTER=$name) ++ * ++ * 4) any interface with a MASTER, where the device named as ++ * MASTER contains a BRIDGE=$name *and* DEVICE=$itself (thus ++ * catching ethernet devices that are enslaved to a bond that ++ * is attached to a bridge). ++ */ ++ nmatches = aug_fmt_match(ncf, matches, ++ "(%s[(DEVICE|BRIDGE|MASTER) = '%s']" ++ "|%s[MASTER][MASTER = ../*[BRIDGE = '%s']/DEVICE " ++ "])/DEVICE", ++ ifcfg_path, name, ifcfg_path, name); ++ return nmatches; ++ ++} ++ + /* Entries in a ifcfg file that tell us that the interface + * is not a toplevel interface + */ +@@ -108,12 +140,7 @@ static int is_slave(struct netcf *ncf, const char *intf) { + static bool has_ifcfg_file(struct netcf *ncf, const char *name) { + int nmatches; + +- nmatches = aug_fmt_match(ncf, NULL, +- "%s[ DEVICE = '%s'" +- " or BRIDGE = '%s'" +- " or MASTER = '%s'" +- " or MASTER = ../*[BRIDGE = '%s']/DEVICE ]/DEVICE", +- ifcfg_path, name, name, name, name); ++ nmatches = aug_all_related_ifcfgs(ncf, NULL, name); + return nmatches > 0; + } + +@@ -588,10 +615,7 @@ static xmlDocPtr aug_get_xml_for_nif(struct netcf_if *nif) { + int ndevs = 0, nint = 0; + + ncf = nif->ncf; +- ndevs = aug_fmt_match(ncf, &devs, +- "%s[ DEVICE = '%s' or BRIDGE = '%s' or MASTER = '%s'" +- " or MASTER = ../*[BRIDGE = '%s']/DEVICE ]/DEVICE", +- ifcfg_path, nif->name, nif->name, nif->name, nif->name); ++ ndevs = aug_all_related_ifcfgs(ncf, &devs, nif->name); + ERR_BAIL(ncf); + + nint = uniq_ifcfg_paths(ncf, ndevs, devs, &intf); +-- +2.4.3 + diff --git a/0002-netcf-linux-include-bond-element-for-bonds-with-no-slaves.patch b/0002-netcf-linux-include-bond-element-for-bonds-with-no-slaves.patch new file mode 100644 index 0000000..1508342 --- /dev/null +++ b/0002-netcf-linux-include-bond-element-for-bonds-with-no-slaves.patch @@ -0,0 +1,56 @@ +From cfe1eb87f7f152ab5d6456ef8ecd7aab38d376fa Mon Sep 17 00:00:00 2001 +From: Lubomir Rintel +Date: Wed, 27 May 2015 19:30:25 +0200 +Subject: [PATCH 1/2] linux: include element for bonds with no slaves + +The missing element makes libvirt sad: + + $ ncftool dumpxml --live nm-bond + + + + + + + + + $ virsh iface-dumpxml nm-bond + error: XML error: bond interface misses the bond element + +This is analogous what was done in d32a464c (Always add element to +bridge if, even if no physdev is attached) for bridges. +--- + src/dutil_linux.c | 9 ++++++--- + 1 file changed, 6 insertions(+), 3 deletions(-) + +diff --git a/src/dutil_linux.c b/src/dutil_linux.c +index 24f4d95..022eed0 100644 +--- a/src/dutil_linux.c ++++ b/src/dutil_linux.c +@@ -1055,9 +1055,6 @@ static void add_bond_info_cb(struct nl_object *obj, + || rtnl_link_get_master(iflink) != cb_data->master_ifindex) + return; + +- cb_data->bond = xml_node(cb_data->doc, cb_data->root, "bond"); +- ERR_NOMEM(cb_data->bond == NULL, ncf); +- + /* XXX - if we learn where to get bridge "mode" property, set it here */ + + /* XXX - need to add node like one of these: +@@ -1089,7 +1086,13 @@ static void add_bond_info(struct netcf *ncf, + if (ifindex == RTNL_LINK_NOT_FOUND) + return; + ++ cb_data.bond = xml_node(doc, root, "bond"); ++ ERR_NOMEM(cb_data.bond == NULL, ncf); ++ + nl_cache_foreach(ncf->driver->link_cache, add_bond_info_cb, &cb_data); ++ ++error: ++ return; + } + + +-- +2.4.3 + diff --git a/0003-netcf-Properly-classify-bond-devices-with-no-slaves.patch b/0003-netcf-Properly-classify-bond-devices-with-no-slaves.patch new file mode 100644 index 0000000..35f057e --- /dev/null +++ b/0003-netcf-Properly-classify-bond-devices-with-no-slaves.patch @@ -0,0 +1,35 @@ +From f3ec5157c7fc97e31c7b48e3a56da268de7e4216 Mon Sep 17 00:00:00 2001 +From: Laine Stump +Date: Tue, 13 Oct 2015 14:42:35 -0400 +Subject: [PATCH 2/2] Properly classify bond devices with no slaves + +Although initscripts only considers an interface to be a bond if it +has slaves, there are times when setting up a bond, or testing, when a +bond may not have any slaves (yet) but does have a BONDING_OPTS +attribute. Previously in those situations netcf would identify the +interface as a plain ethernet. This patch makes the check more +inclusive - now any interface with slaves *or* with a BONDING_OPTS +attribute is considered to be a bond. + +This patch was inspired by an earlier patch sent by Lubomir Rintel +which looked for BONDING_OPTS *instead of* looking for slaves. +--- + data/xml/redhat-put.xsl | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/data/xml/redhat-put.xsl b/data/xml/redhat-put.xsl +index ed56c66..89145e5 100644 +--- a/data/xml/redhat-put.xsl ++++ b/data/xml/redhat-put.xsl +@@ -135,7 +135,7 @@ + + + ++ match="tree[count(node[@label = 'BONDING_OPTS']) or (node[@label = 'DEVICE'][@value = //tree/node[@label = 'MASTER']/@value])][count(node[@label = 'BRIDGE']) = 0]"> + + + +-- +2.4.3 + diff --git a/netcf-0.2.8.tar.gz b/netcf-0.2.8.tar.gz new file mode 100644 index 0000000..6a0a482 Binary files /dev/null and b/netcf-0.2.8.tar.gz differ diff --git a/netcf.spec b/netcf.spec new file mode 100644 index 0000000..1d955a6 --- /dev/null +++ b/netcf.spec @@ -0,0 +1,107 @@ +Name: netcf +Version: 0.2.8 +Release: 13 +Summary: Cross-platform network configuration library +License: LGPLv2+ +URL: https://pagure.io/netcf +Source0: https://fedorahosted.org/released/%{name}/%{name}-%{version}.tar.gz + +Patch0000: 0000-netcf-call-aug_load-at-most-once-per-second.patch +Patch0001: 0001-netcf-optimize-aug_match-query-for-all-ifcfg-files-related.patch +Patch0002: 0002-netcf-linux-include-bond-element-for-bonds-with-no-slaves.patch +Patch0003: 0003-netcf-Properly-classify-bond-devices-with-no-slaves.patch + +BuildRequires: autoconf automake augeas-devel gcc git gettext-devel libnl3-devel libtool +BuildRequires: libxml2-devel libxslt-devel perl-podlators readline-devel systemd /usr/bin/pod2man + +Requires: bridge-utils systemd + +Provides: bundled(gnulib) %{name}-libs = %{version}-%{release} +Obsoletes: %{name}-libs = %{version}-%{release} + +%description +netcf is a cross-platform network configuration library. +It takes the description of a network interface in its own +platform-independent format and adapts the local system's network +configuration to provide that interface.And The libraries for %{name}. + +%package devel +Summary: Development files and Header files for %{name} +Requires: pkgconfig %{name} = %{version}-%{release} + +%description devel +The devel for %{name} + +%package_help + +%prep +%autosetup -n %{name}-%{version} -p1 -S git + +%build +autoreconf -if + +%configure --with-sysinit=systemd +%make_build + +%install +make install DESTDIR=$RPM_BUILD_ROOT SYSTEMD_UNIT_DIR=%{_unitdir} INSTALL="%{__install} -p" +%delete_la + +%check +make check + +%preun +%systemd_preun netcf-transaction.service + +%post +/sbin/ldconfig +%systemd_post netcf-transaction.service +/bin/systemctl --no-reload enable netcf-transaction.service >/dev/null 2>&1 || : + +%postun +/sbin/ldconfig +%systemd_postun netcf-transaction.service + +%files +%defattr(-,root,root) +%{_bindir}/ncftool +%{_datadir}/netcf +%{_libdir}/*.so.* +%{_unitdir}/netcf-transaction.service +%attr(0755, root, root) %{_libexecdir}/netcf-transaction.sh + +%files devel +%defattr(-,root,root) +%{_includedir}/* +%{_libdir}/*.so +%{_libdir}/libnetcf.a +%{_libdir}/pkgconfig/netcf.pc + +%files help +%defattr(-,root,root) +%{_mandir}/man1/ncftool.1* + +%changelog +* Tue Sep 24 2019 wangli - 0.2.8-13 +- Type:Enhance +- ID:NA +- SUG:NA +- DESC: openEuler Debranding + +* Thu Sep 05 2019 wangli - 0.2.8-12 +- Type:Enhance +- ID:NA +- SUG:NA +- DESC: openEuler Debranding + +* Wed Aug 14 2019 openEuler Buildteam - 0.2.8-11 +- Package init + +* Thu Aug 1 2019 luochunsheng - 0.2.8-10.h1 +- Type:Enhance +- ID:NA +- SUG:NA +- DESC: openEuler Debranding + +* Fri Jul 13 2018 luochunsheng - 0.2.8-10 +- Package Initialization