Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package libstorage-ng for openSUSE:Factory checked in at 2022-11-26 18:45:04 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/libstorage-ng (Old) and /work/SRC/openSUSE:Factory/.libstorage-ng.new.1597 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "libstorage-ng" Sat Nov 26 18:45:04 2022 rev:188 rq:1038185 version:4.5.53 Changes: -------- --- /work/SRC/openSUSE:Factory/libstorage-ng/libstorage-ng.changes 2022-11-18 15:42:48.686371852 +0100 +++ /work/SRC/openSUSE:Factory/.libstorage-ng.new.1597/libstorage-ng.changes 2022-11-26 18:45:06.839092133 +0100 @@ -1,0 +2,10 @@ +Fri Nov 25 11:37:41 UTC 2022 - aschn...@suse.com + +- merge gh#openSUSE/libstorage-ng#905 +- read filters for udev links from config file +- limit allowed by-id links for NVMEs (bsc#1205352) +- make integration-tests subpackage noarch +- cleanup +- 4.5.53 + +-------------------------------------------------------------------- Old: ---- libstorage-ng-4.5.52.tar.xz New: ---- libstorage-ng-4.5.53.tar.xz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ libstorage-ng.spec ++++++ --- /var/tmp/diff_new_pack.utaQKt/_old 2022-11-26 18:45:07.659096993 +0100 +++ /var/tmp/diff_new_pack.utaQKt/_new 2022-11-26 18:45:07.663097017 +0100 @@ -18,7 +18,7 @@ %define libname %{name}1 Name: libstorage-ng -Version: 4.5.52 +Version: 4.5.53 Release: 0 Summary: Library for storage management License: GPL-2.0-only @@ -149,6 +149,7 @@ Summary: Integration tests for libstorage-ng Group: Development/Tools/Other Requires: libstorage-ng-python3 +BuildArch: noarch %description integration-tests This package contains integration tests for libstorage-ng. @@ -168,7 +169,9 @@ make %{?_smp_mflags} %check -make %{?_smp_mflags} check VERBOSE=1 LOCALEDIR=%{buildroot}%{_datadir}/locale +make %{?_smp_mflags} check VERBOSE=1 \ + LIBSTORAGE_CONFDIR=%{buildroot}%{_datadir}/libstorage \ + LIBSTORAGE_LOCALEDIR=%{buildroot}%{_datadir}/locale %install %make_install @@ -193,6 +196,8 @@ %license %{_docdir}/%{name}/LICENSE %{_libdir}/libstorage-ng.so.* %ghost /run/libstorage-ng +%dir %{_datadir}/libstorage +%{_datadir}/libstorage/udev-filters.json %files devel %{_libdir}/libstorage-ng.so ++++++ libstorage-ng-4.5.52.tar.xz -> libstorage-ng-4.5.53.tar.xz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/Makefile.am new/libstorage-ng-4.5.53/Makefile.am --- old/libstorage-ng-4.5.52/Makefile.am 2022-11-11 02:13:36.000000000 +0100 +++ new/libstorage-ng-4.5.53/Makefile.am 2022-11-25 12:37:41.000000000 +0100 @@ -4,7 +4,7 @@ VERSION = $(shell utils/git2log --version VERSION ; cat VERSION) -SUBDIRS = storage doc po utils examples testsuite bindings integration-tests +SUBDIRS = storage doc po data utils examples testsuite bindings integration-tests AUTOMAKE_OPTIONS = foreign dist-xz no-dist-gzip subdir-objects diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/README.md new/libstorage-ng-4.5.53/README.md --- old/libstorage-ng-4.5.52/README.md 2022-11-11 02:13:36.000000000 +0100 +++ new/libstorage-ng-4.5.53/README.md 2022-11-25 12:37:41.000000000 +0100 @@ -60,7 +60,7 @@ ```sh make -j$(nproc) install DESTDIR=/tmp/scratch -make -j$(nproc) check LOCALEDIR=/tmp/scratch/usr/share/locale +make -j$(nproc) check LIBSTORAGE_LOCALEDIR=/tmp/scratch/usr/share/locale LIBSTORAGE_CONFDIR=/tmp/scratch/usr/share/libstorage ``` diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/VERSION new/libstorage-ng-4.5.53/VERSION --- old/libstorage-ng-4.5.52/VERSION 2022-11-11 02:13:36.000000000 +0100 +++ new/libstorage-ng-4.5.53/VERSION 2022-11-25 12:37:41.000000000 +0100 @@ -1 +1 @@ -4.5.52 +4.5.53 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/configure.ac new/libstorage-ng-4.5.53/configure.ac --- old/libstorage-ng-4.5.52/configure.ac 2022-11-11 02:13:36.000000000 +0100 +++ new/libstorage-ng-4.5.53/configure.ac 2022-11-25 12:37:41.000000000 +0100 @@ -107,6 +107,7 @@ doc/autodocs/html/Makefile doc/autodocs/xml/Makefile po/Makefile + data/Makefile utils/Makefile examples/Makefile examples/SystemInfo/Makefile diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/data/Makefile.am new/libstorage-ng-4.5.53/data/Makefile.am --- old/libstorage-ng-4.5.52/data/Makefile.am 1970-01-01 01:00:00.000000000 +0100 +++ new/libstorage-ng-4.5.53/data/Makefile.am 2022-11-25 12:37:41.000000000 +0100 @@ -0,0 +1,10 @@ +# +# Makefile.am for libstorage/data +# + +EXTRA_DIST = udev-filters.json + +install-data-local: + install -d -m 755 $(DESTDIR)/usr/share/libstorage + install -D -m 644 udev-filters.json $(DESTDIR)/usr/share/libstorage/ + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/data/udev-filters.json new/libstorage-ng-4.5.53/data/udev-filters.json --- old/libstorage-ng-4.5.52/data/udev-filters.json 1970-01-01 01:00:00.000000000 +0100 +++ new/libstorage-ng-4.5.53/data/udev-filters.json 2022-11-25 12:37:41.000000000 +0100 @@ -0,0 +1,21 @@ +{ + "Disk" : { + "allowed-path-patterns" : [ "ccw-*", "scsi-*", "pci-*", "platform-*" ], + "allowed-id-patterns" : [ "ata-*", "scsi-*", "wwn-*", + "nvme-uuid.*", "nvme-eui.*", "nvme-nvme.*", + "usb-*", "mmc-*" ] + }, + "Dasd" : { + "allowed-path-patterns" : [ "ccw-*" ], + "allowed-id-patterns" : [ "ccw-*" ] + }, + "Md" : { + "allowed-id-patterns" : [ "md-uuid-*" ] + }, + "DmRaid" : { + "allowed-id-patterns" : [ "raid-*" ] + }, + "Multipath" : { + "allowed-id-patterns" : [ "scsi-*", "wwn-*", "dm-name-*", "dm-uuid-*" ] + } +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/doc/udev.md new/libstorage-ng-4.5.53/doc/udev.md --- old/libstorage-ng-4.5.52/doc/udev.md 2022-11-11 02:13:36.000000000 +0100 +++ new/libstorage-ng-4.5.53/doc/udev.md 2022-11-25 12:37:41.000000000 +0100 @@ -13,3 +13,11 @@ A whitelist will also reduce the risk of using erroneous udev links, e.g. see bsc #1063249 and bsc #1140630. +The configuration is loaded from the file udev-filters.json. This is +so far not documented since in detail since it may have to change +depending on future development of udev. + +Unresolved bugs concerning udev links: +- pmem (bsc #1140630) +- nvme (bsc #1205352) + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/libstorage-ng.spec.in new/libstorage-ng-4.5.53/libstorage-ng.spec.in --- old/libstorage-ng-4.5.52/libstorage-ng.spec.in 2022-11-11 02:13:36.000000000 +0100 +++ new/libstorage-ng-4.5.53/libstorage-ng.spec.in 2022-11-25 12:37:41.000000000 +0100 @@ -149,6 +149,7 @@ Summary: Integration tests for libstorage-ng Group: Development/Tools/Other Requires: libstorage-ng-python3 +BuildArch: noarch %description integration-tests This package contains integration tests for libstorage-ng. @@ -162,13 +163,15 @@ autoreconf -fvi %configure \ - --docdir="%{_docdir}/%{name}" \ - --disable-static \ - --disable-silent-rules + --docdir="%{_docdir}/%{name}" \ + --disable-static \ + --disable-silent-rules make %{?_smp_mflags} %check -make %{?_smp_mflags} check VERBOSE=1 LOCALEDIR=%{buildroot}%{_datadir}/locale +make %{?_smp_mflags} check VERBOSE=1 \ + LIBSTORAGE_CONFDIR=%{buildroot}%{_datadir}/libstorage \ + LIBSTORAGE_LOCALEDIR=%{buildroot}%{_datadir}/locale %install %make_install @@ -193,6 +196,8 @@ %license %{_docdir}/%{name}/LICENSE %{_libdir}/libstorage-ng.so.* %ghost /run/libstorage-ng +%dir %{_datadir}/libstorage +%{_datadir}/libstorage/udev-filters.json %files devel %{_libdir}/libstorage-ng.so diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/storage/Devices/BlkDeviceImpl.cc new/libstorage-ng-4.5.53/storage/Devices/BlkDeviceImpl.cc --- old/libstorage-ng-4.5.52/storage/Devices/BlkDeviceImpl.cc 2022-11-11 02:13:36.000000000 +0100 +++ new/libstorage-ng-4.5.53/storage/Devices/BlkDeviceImpl.cc 2022-11-25 12:37:41.000000000 +0100 @@ -110,13 +110,13 @@ if (!cmd_udevadm_info.get_by_path_links().empty()) { udev_paths = cmd_udevadm_info.get_by_path_links(); - process_udev_paths(udev_paths); + process_udev_paths(udev_paths, prober.get_udev_filters()); } if (!cmd_udevadm_info.get_by_id_links().empty()) { udev_ids = cmd_udevadm_info.get_by_id_links(); - process_udev_ids(udev_ids); + process_udev_ids(udev_ids, prober.get_udev_filters()); } } } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/storage/Devices/BlkDeviceImpl.h new/libstorage-ng-4.5.53/storage/Devices/BlkDeviceImpl.h --- old/libstorage-ng-4.5.52/storage/Devices/BlkDeviceImpl.h 2022-11-11 02:13:36.000000000 +0100 +++ new/libstorage-ng-4.5.53/storage/Devices/BlkDeviceImpl.h 2022-11-25 12:37:41.000000000 +0100 @@ -30,6 +30,7 @@ #include "storage/Devices/BlkDevice.h" #include "storage/Devices/DeviceImpl.h" #include "storage/FreeInfo.h" +#include "storage/Utils/UdevFilters.h" namespace storage @@ -186,8 +187,8 @@ virtual void log_diff(std::ostream& log, const Device::Impl& rhs_base) const override = 0; virtual void print(std::ostream& out) const override = 0; - virtual void process_udev_paths(vector<string>& udev_paths) const { udev_paths.clear(); } - virtual void process_udev_ids(vector<string>& udev_ids) const { udev_ids.clear(); } + virtual void process_udev_paths(vector<string>& udev_paths, const UdevFilters& udev_filters) const { udev_paths.clear(); } + virtual void process_udev_ids(vector<string>& udev_ids, const UdevFilters& udev_filters) const { udev_ids.clear(); } void wipe_device() const; void discard_device() const; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/storage/Devices/DasdImpl.cc new/libstorage-ng-4.5.53/storage/Devices/DasdImpl.cc --- old/libstorage-ng-4.5.52/storage/Devices/DasdImpl.cc 2022-11-11 02:13:36.000000000 +0100 +++ new/libstorage-ng-4.5.53/storage/Devices/DasdImpl.cc 2022-11-25 12:37:41.000000000 +0100 @@ -1,6 +1,6 @@ /* * Copyright (c) [2014-2015] Novell, Inc. - * Copyright (c) [2016-2020] SUSE LLC + * Copyright (c) [2016-2022] SUSE LLC * * All Rights Reserved. * @@ -320,24 +320,16 @@ void - Dasd::Impl::process_udev_paths(vector<string>& udev_paths) const + Dasd::Impl::process_udev_paths(vector<string>& udev_paths, const UdevFilters& udev_filters) const { - // See doc/udev.md. - - erase_if(udev_paths, [](const string& udev_path) { - return !boost::starts_with(udev_path, "ccw-"); - }); + udev_filter(udev_paths, udev_filters.dasd.allowed_path_patterns); } void - Dasd::Impl::process_udev_ids(vector<string>& udev_ids) const + Dasd::Impl::process_udev_ids(vector<string>& udev_ids, const UdevFilters& udev_filters) const { - // See doc/udev.md. - - erase_if(udev_ids, [](const string& udev_id) { - return !boost::starts_with(udev_id, "ccw-"); - }); + udev_filter(udev_ids, udev_filters.dasd.allowed_id_patterns); } } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/storage/Devices/DasdImpl.h new/libstorage-ng-4.5.53/storage/Devices/DasdImpl.h --- old/libstorage-ng-4.5.52/storage/Devices/DasdImpl.h 2022-11-11 02:13:36.000000000 +0100 +++ new/libstorage-ng-4.5.53/storage/Devices/DasdImpl.h 2022-11-25 12:37:41.000000000 +0100 @@ -1,6 +1,6 @@ /* * Copyright (c) [2014-2015] Novell, Inc. - * Copyright (c) [2016-2021] SUSE LLC + * Copyright (c) [2016-2022] SUSE LLC * * All Rights Reserved. * @@ -97,8 +97,8 @@ virtual void log_diff(std::ostream& log, const Device::Impl& rhs_base) const override; virtual void print(std::ostream& out) const override; - virtual void process_udev_paths(vector<string>& udev_paths) const override; - virtual void process_udev_ids(vector<string>& udev_ids) const override; + virtual void process_udev_paths(vector<string>& udev_paths, const UdevFilters& udev_filters) const override; + virtual void process_udev_ids(vector<string>& udev_ids, const UdevFilters& udev_filters) const override; private: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/storage/Devices/DiskImpl.cc new/libstorage-ng-4.5.53/storage/Devices/DiskImpl.cc --- old/libstorage-ng-4.5.52/storage/Devices/DiskImpl.cc 2022-11-11 02:13:36.000000000 +0100 +++ new/libstorage-ng-4.5.53/storage/Devices/DiskImpl.cc 2022-11-25 12:37:41.000000000 +0100 @@ -335,34 +335,16 @@ void - Disk::Impl::process_udev_paths(vector<string>& udev_paths) const + Disk::Impl::process_udev_paths(vector<string>& udev_paths, const UdevFilters& udev_filters) const { - // See doc/udev.md. - - static const vector<string> allowed_prefixes = { "scsi-", "pci-", "ccw-", "platform-" }; - - erase_if(udev_paths, [](const string& udev_path) { - return none_of(allowed_prefixes.begin(), allowed_prefixes.end(), [&udev_path](const string& prefix) - { return boost::starts_with(udev_path, prefix); }); - }); + udev_filter(udev_paths, udev_filters.disk.allowed_path_patterns); } void - Disk::Impl::process_udev_ids(vector<string>& udev_ids) const + Disk::Impl::process_udev_ids(vector<string>& udev_ids, const UdevFilters& udev_filters) const { - // See doc/udev.md. - - // pmem- yet not listed here due to bsc #1140630 - - static const vector<string> allowed_prefixes = { "ata-", "scsi-", "usb-", "wwn-", "nvme-", "mmc-" }; - - erase_if(udev_ids, [](const string& udev_id) { - return none_of(allowed_prefixes.begin(), allowed_prefixes.end(), [&udev_id](const string& prefix) - { return boost::starts_with(udev_id, prefix); }); - }); - - stable_partition(udev_ids.begin(), udev_ids.end(), string_starts_with("ata-")); + udev_filter(udev_ids, udev_filters.disk.allowed_id_patterns); } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/storage/Devices/DiskImpl.h new/libstorage-ng-4.5.53/storage/Devices/DiskImpl.h --- old/libstorage-ng-4.5.52/storage/Devices/DiskImpl.h 2022-11-11 02:13:36.000000000 +0100 +++ new/libstorage-ng-4.5.53/storage/Devices/DiskImpl.h 2022-11-25 12:37:41.000000000 +0100 @@ -107,8 +107,8 @@ virtual void log_diff(std::ostream& log, const Device::Impl& rhs_base) const override; virtual void print(std::ostream& out) const override; - virtual void process_udev_paths(vector<string>& udev_paths) const override; - virtual void process_udev_ids(vector<string>& udev_ids) const override; + virtual void process_udev_paths(vector<string>& udev_paths, const UdevFilters& udev_filters) const override; + virtual void process_udev_ids(vector<string>& udev_ids, const UdevFilters& udev_filters) const override; virtual Text do_create_text(Tense tense) const override; virtual void do_create() override; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/storage/Devices/DmRaidImpl.cc new/libstorage-ng-4.5.53/storage/Devices/DmRaidImpl.cc --- old/libstorage-ng-4.5.52/storage/Devices/DmRaidImpl.cc 2022-11-11 02:13:36.000000000 +0100 +++ new/libstorage-ng-4.5.53/storage/Devices/DmRaidImpl.cc 2022-11-25 12:37:41.000000000 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) [2017-2021] SUSE LLC + * Copyright (c) [2017-2022] SUSE LLC * * All Rights Reserved. * @@ -271,13 +271,16 @@ void - DmRaid::Impl::process_udev_ids(vector<string>& udev_ids) const + DmRaid::Impl::process_udev_paths(vector<string>& udev_paths, const UdevFilters& udev_filters) const { - // See doc/udev.md. + udev_filter(udev_paths, udev_filters.dm_raid.allowed_path_patterns); + } + - erase_if(udev_ids, [](const string& udev_id) { - return !boost::starts_with(udev_id, "raid-"); - }); + void + DmRaid::Impl::process_udev_ids(vector<string>& udev_ids, const UdevFilters& udev_filters) const + { + udev_filter(udev_ids, udev_filters.dm_raid.allowed_id_patterns); } } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/storage/Devices/DmRaidImpl.h new/libstorage-ng-4.5.53/storage/Devices/DmRaidImpl.h --- old/libstorage-ng-4.5.52/storage/Devices/DmRaidImpl.h 2022-11-11 02:13:36.000000000 +0100 +++ new/libstorage-ng-4.5.53/storage/Devices/DmRaidImpl.h 2022-11-25 12:37:41.000000000 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) [2017-2021] SUSE LLC + * Copyright (c) [2017-2022] SUSE LLC * * All Rights Reserved. * @@ -90,7 +90,8 @@ virtual void log_diff(std::ostream& log, const Device::Impl& rhs_base) const override; virtual void print(std::ostream& out) const override; - virtual void process_udev_ids(vector<string>& udev_ids) const override; + virtual void process_udev_paths(vector<string>& udev_paths, const UdevFilters& udev_filters) const override; + virtual void process_udev_ids(vector<string>& udev_ids, const UdevFilters& udev_filters) const override; private: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/storage/Devices/MdImpl.cc new/libstorage-ng-4.5.53/storage/Devices/MdImpl.cc --- old/libstorage-ng-4.5.52/storage/Devices/MdImpl.cc 2022-11-11 02:13:36.000000000 +0100 +++ new/libstorage-ng-4.5.53/storage/Devices/MdImpl.cc 2022-11-25 12:37:41.000000000 +0100 @@ -827,13 +827,16 @@ void - Md::Impl::process_udev_ids(vector<string>& udev_ids) const + Md::Impl::process_udev_paths(vector<string>& udev_paths, const UdevFilters& udev_filters) const { - // See doc/udev.md. + udev_filter(udev_paths, udev_filters.md.allowed_path_patterns); + } + - erase_if(udev_ids, [](const string& udev_id) { - return !boost::starts_with(udev_id, "md-uuid-"); - }); + void + Md::Impl::process_udev_ids(vector<string>& udev_ids, const UdevFilters& udev_filters) const + { + udev_filter(udev_ids, udev_filters.md.allowed_id_patterns); } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/storage/Devices/MdImpl.h new/libstorage-ng-4.5.53/storage/Devices/MdImpl.h --- old/libstorage-ng-4.5.52/storage/Devices/MdImpl.h 2022-11-11 02:13:36.000000000 +0100 +++ new/libstorage-ng-4.5.53/storage/Devices/MdImpl.h 2022-11-25 12:37:41.000000000 +0100 @@ -1,6 +1,6 @@ /* * Copyright (c) [2014-2015] Novell, Inc. - * Copyright (c) [2016-2021] SUSE LLC + * Copyright (c) [2016-2022] SUSE LLC * * All Rights Reserved. * @@ -142,7 +142,8 @@ virtual void log_diff(std::ostream& log, const Device::Impl& rhs_base) const override; virtual void print(std::ostream& out) const override; - virtual void process_udev_ids(vector<string>& udev_ids) const override; + virtual void process_udev_paths(vector<string>& udev_paths, const UdevFilters& udev_filters) const override; + virtual void process_udev_ids(vector<string>& udev_ids, const UdevFilters& udev_filters) const override; virtual uf_t used_features(UsedFeaturesDependencyType used_features_dependency_type) const override; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/storage/Devices/MultipathImpl.cc new/libstorage-ng-4.5.53/storage/Devices/MultipathImpl.cc --- old/libstorage-ng-4.5.52/storage/Devices/MultipathImpl.cc 2022-11-11 02:13:36.000000000 +0100 +++ new/libstorage-ng-4.5.53/storage/Devices/MultipathImpl.cc 2022-11-25 12:37:41.000000000 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) [2017-2021] SUSE LLC + * Copyright (c) [2017-2022] SUSE LLC * * All Rights Reserved. * @@ -326,19 +326,16 @@ void - Multipath::Impl::process_udev_ids(vector<string>& udev_ids) const + Multipath::Impl::process_udev_paths(vector<string>& udev_paths, const UdevFilters& udev_filters) const { - // See doc/udev.md. - - static const vector<string> allowed_prefixes = { "scsi-", "wwn-", "dm-name-", "dm-uuid-" }; + udev_filter(udev_paths, udev_filters.multipath.allowed_path_patterns); + } - erase_if(udev_ids, [](const string& udev_id) { - return none_of(allowed_prefixes.begin(), allowed_prefixes.end(), [&udev_id](const string& prefix) - { return boost::starts_with(udev_id, prefix); }); - }); - stable_partition(udev_ids.begin(), udev_ids.end(), string_starts_with("wwn-")); - stable_partition(udev_ids.begin(), udev_ids.end(), string_starts_with("scsi-")); + void + Multipath::Impl::process_udev_ids(vector<string>& udev_ids, const UdevFilters& udev_filters) const + { + udev_filter(udev_ids, udev_filters.multipath.allowed_id_patterns); } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/storage/Devices/MultipathImpl.h new/libstorage-ng-4.5.53/storage/Devices/MultipathImpl.h --- old/libstorage-ng-4.5.52/storage/Devices/MultipathImpl.h 2022-11-11 02:13:36.000000000 +0100 +++ new/libstorage-ng-4.5.53/storage/Devices/MultipathImpl.h 2022-11-25 12:37:41.000000000 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) [2017-2021] SUSE LLC + * Copyright (c) [2017-2022] SUSE LLC * * All Rights Reserved. * @@ -94,7 +94,8 @@ virtual void log_diff(std::ostream& log, const Device::Impl& rhs_base) const override; virtual void print(std::ostream& out) const override; - virtual void process_udev_ids(vector<string>& udev_ids) const override; + virtual void process_udev_paths(vector<string>& udev_paths, const UdevFilters& udev_filters) const override; + virtual void process_udev_ids(vector<string>& udev_ids, const UdevFilters& udev_filters) const override; virtual Text do_deactivate_text(Tense tense) const override; virtual void do_deactivate() const override; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/storage/Devices/PartitionImpl.cc new/libstorage-ng-4.5.53/storage/Devices/PartitionImpl.cc --- old/libstorage-ng-4.5.52/storage/Devices/PartitionImpl.cc 2022-11-11 02:13:36.000000000 +0100 +++ new/libstorage-ng-4.5.53/storage/Devices/PartitionImpl.cc 2022-11-25 12:37:41.000000000 +0100 @@ -534,20 +534,20 @@ void - Partition::Impl::process_udev_paths(vector<string>& udev_paths) const + Partition::Impl::process_udev_paths(vector<string>& udev_paths, const UdevFilters& udev_filters) const { const Partitionable* partitionable = get_partitionable(); - partitionable->get_impl().process_udev_paths(udev_paths); + partitionable->get_impl().process_udev_paths(udev_paths, udev_filters); } void - Partition::Impl::process_udev_ids(vector<string>& udev_ids) const + Partition::Impl::process_udev_ids(vector<string>& udev_ids, const UdevFilters& udev_filters) const { const Partitionable* partitionable = get_partitionable(); - partitionable->get_impl().process_udev_ids(udev_ids); + partitionable->get_impl().process_udev_ids(udev_ids, udev_filters); } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/storage/Devices/PartitionImpl.h new/libstorage-ng-4.5.53/storage/Devices/PartitionImpl.h --- old/libstorage-ng-4.5.52/storage/Devices/PartitionImpl.h 2022-11-11 02:13:36.000000000 +0100 +++ new/libstorage-ng-4.5.53/storage/Devices/PartitionImpl.h 2022-11-25 12:37:41.000000000 +0100 @@ -1,6 +1,6 @@ /* * Copyright (c) [2014-2015] Novell, Inc. - * Copyright (c) [2016-2021] SUSE LLC + * Copyright (c) [2016-2022] SUSE LLC * * All Rights Reserved. * @@ -129,8 +129,8 @@ virtual void log_diff(std::ostream& log, const Device::Impl& rhs_base) const override; virtual void print(std::ostream& out) const override; - virtual void process_udev_paths(vector<string>& udev_paths) const override; - virtual void process_udev_ids(vector<string>& udev_ids) const override; + virtual void process_udev_paths(vector<string>& udev_paths, const UdevFilters& udev_filters) const override; + virtual void process_udev_ids(vector<string>& udev_ids, const UdevFilters& udev_filters) const override; virtual Partition* get_non_impl() override { return to_partition(Device::Impl::get_non_impl()); } virtual const Partition* get_non_impl() const override { return to_partition(Device::Impl::get_non_impl()); } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/storage/EnvironmentImpl.cc new/libstorage-ng-4.5.53/storage/EnvironmentImpl.cc --- old/libstorage-ng-4.5.52/storage/EnvironmentImpl.cc 2022-11-11 02:13:36.000000000 +0100 +++ new/libstorage-ng-4.5.53/storage/EnvironmentImpl.cc 2022-11-25 12:37:41.000000000 +0100 @@ -185,7 +185,9 @@ "LD_PRELOAD", "LIBSTORAGE_BTRFS_QGROUPS", "LIBSTORAGE_BTRFS_SNAPSHOT_RELATIONS", + "LIBSTORAGE_CONFDIR", "LIBSTORAGE_DEVELOPER_MODE", + "LIBSTORAGE_LOCALEDIR", "LIBSTORAGE_LOCKFILE_ROOT", "LIBSTORAGE_MDADM_ACTIVATE_METHOD", "LIBSTORAGE_MULTIPLE_DEVICES_BTRFS", diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/storage/Filesystems/MountableImpl.cc new/libstorage-ng-4.5.53/storage/Filesystems/MountableImpl.cc --- old/libstorage-ng-4.5.52/storage/Filesystems/MountableImpl.cc 2022-11-11 02:13:36.000000000 +0100 +++ new/libstorage-ng-4.5.53/storage/Filesystems/MountableImpl.cc 2022-11-25 12:37:41.000000000 +0100 @@ -374,7 +374,7 @@ if (mount_point->get_path() == "/") { - string path = get_storage()->prepend_rootprefix("/etc"); + string path = get_storage()->prepend_rootprefix(ETC_DIR); if (access(path.c_str(), R_OK) != 0) createPath(path); } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/storage/Prober.h new/libstorage-ng-4.5.53/storage/Prober.h --- old/libstorage-ng-4.5.52/storage/Prober.h 2022-11-11 02:13:36.000000000 +0100 +++ new/libstorage-ng-4.5.53/storage/Prober.h 2022-11-25 12:37:41.000000000 +0100 @@ -29,6 +29,7 @@ #include <functional> #include "storage/SystemInfo/SystemInfo.h" +#include "storage/Utils/UdevFilters.h" namespace storage @@ -84,6 +85,8 @@ const ProbeCallbacks* get_probe_callbacks() const { return probe_callbacks; } + const UdevFilters& get_udev_filters() const { return udev_filters; } + Devicegraph* get_system() { return system; } SystemInfo::Impl& get_system_info() { return system_info; } @@ -113,6 +116,8 @@ const ProbeCallbacks* probe_callbacks; + const UdevFilters udev_filters; + Devicegraph* system; SystemInfo::Impl& system_info; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/storage/Utils/JsonFile.cc new/libstorage-ng-4.5.53/storage/Utils/JsonFile.cc --- old/libstorage-ng-4.5.52/storage/Utils/JsonFile.cc 2022-11-11 02:13:36.000000000 +0100 +++ new/libstorage-ng-4.5.53/storage/Utils/JsonFile.cc 2022-11-25 12:37:41.000000000 +0100 @@ -20,6 +20,8 @@ */ +#include <stdio.h> +#include <sys/stat.h> #include <functional> #include <memory> #include <sstream> @@ -27,6 +29,7 @@ #include "storage/Utils/JsonFile.h" #include "storage/Utils/ExceptionImpl.h" #include "storage/Utils/AppUtil.h" +#include "storage/Utils/Format.h" namespace storage @@ -59,6 +62,53 @@ } + JsonFile::JsonFile(const string& filename) + { + FILE* fp = fopen(filename.c_str(), "r"); + if (!fp) + ST_THROW(IOException(sformat("open for json file '%s' failed", filename))); + + struct stat st; + if (fstat(fileno(fp), &st) != 0) + { + fclose(fp); + ST_THROW(IOException(sformat("stat for json file '%s' failed", filename))); + } + + vector<char> data(st.st_size); + if (fread(data.data(), 1, st.st_size, fp) != (size_t)(st.st_size)) + { + fclose(fp); + ST_THROW(Exception(sformat("read for json file '%s' failed", filename))); + } + + if (fclose(fp) != 0) + { + ST_THROW(Exception(sformat("close for json file '%s' failed", filename))); + } + + json_tokener* tokener = json_tokener_new(); + + root = json_tokener_parse_ex(tokener, data.data(), st.st_size); + + if (json_tokener_get_error(tokener) != json_tokener_success) + { + json_tokener_free(tokener); + json_object_put(root); + ST_THROW(Exception(sformat("parsing json file '%s' failed", filename))); + } + + if (tokener->char_offset != st.st_size) + { + json_tokener_free(tokener); + json_object_put(root); + ST_THROW(Exception(sformat("excessive content in json file '%s'", filename))); + } + + json_tokener_free(tokener); + } + + JsonFile::~JsonFile() { json_object_put(root); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/storage/Utils/JsonFile.h new/libstorage-ng-4.5.53/storage/Utils/JsonFile.h --- old/libstorage-ng-4.5.52/storage/Utils/JsonFile.h 2022-11-11 02:13:36.000000000 +0100 +++ new/libstorage-ng-4.5.53/storage/Utils/JsonFile.h 2022-11-25 12:37:41.000000000 +0100 @@ -49,6 +49,8 @@ JsonFile(const vector<string>& lines); + JsonFile(const string& filename); + ~JsonFile(); json_object* get_root() { return root; } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/storage/Utils/Makefile.am new/libstorage-ng-4.5.53/storage/Utils/Makefile.am --- old/libstorage-ng-4.5.52/storage/Utils/Makefile.am 2022-11-11 02:13:36.000000000 +0100 +++ new/libstorage-ng-4.5.53/storage/Utils/Makefile.am 2022-11-25 12:37:41.000000000 +0100 @@ -11,6 +11,7 @@ CommentedConfigFile.cc CommentedConfigFile.h \ ColumnConfigFile.cc ColumnConfigFile.h \ Diff.cc Diff.h \ + UdevFilters.cc UdevFilters.h \ Text.cc Text.h \ Format.h \ MountPointPath.h MountPointPath.cc \ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/storage/Utils/StorageDefines.h new/libstorage-ng-4.5.53/storage/Utils/StorageDefines.h --- old/libstorage-ng-4.5.52/storage/Utils/StorageDefines.h 2022-11-11 02:13:36.000000000 +0100 +++ new/libstorage-ng-4.5.53/storage/Utils/StorageDefines.h 2022-11-25 12:37:41.000000000 +0100 @@ -38,9 +38,13 @@ #define DEV_DISK_BY_PARTUUID_DIR DEV_DIR "/disk/by-partuuid" #define DEV_DISK_BY_PARTLABEL_DIR DEV_DIR "/disk/by-partlabel" +#define ETC_DIR "/etc" #define SYSFS_DIR "/sys" #define PROC_DIR "/proc" +#define ETC_LIBSTORAGE_DIR ETC_DIR "/libstorage" +#define USR_SHARE_LIBSTORAGE_DIR "/usr/share/libstorage" + #define EFIVARS_DIR SYSFS_DIR "/firmware/efi/efivars" #define LOCKFILE_DIR "/run/libstorage-ng" @@ -52,6 +56,10 @@ #define DEV_ZERO_FILE DEV_DIR "/zero" #define DEV_URANDOM_FILE DEV_DIR "/urandom" +#define UDEV_FILTERS_FILE "udev-filters.json" +#define ETC_LIBSTORAGE_UDEV_FILTERS_FILE ETC_LIBSTORAGE_DIR "/" UDEV_FILTERS_FILE +#define USR_SHARE_LIBSTORAGE_UDEV_FILTERS_FILE USR_SHARE_LIBSTORAGE_DIR "/" UDEV_FILTERS_FILE + // commands diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/storage/Utils/UdevFilters.cc new/libstorage-ng-4.5.53/storage/Utils/UdevFilters.cc --- old/libstorage-ng-4.5.52/storage/Utils/UdevFilters.cc 1970-01-01 01:00:00.000000000 +0100 +++ new/libstorage-ng-4.5.53/storage/Utils/UdevFilters.cc 2022-11-25 12:37:41.000000000 +0100 @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2022 SUSE LLC + * + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as published + * by the Free Software Foundation. + * + * 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, contact Novell, Inc. + * + * To contact Novell about this file by physical or electronic mail, you may + * find current contact information at www.novell.com. + */ + + +#include <fnmatch.h> + +#include "storage/Utils/UdevFilters.h" +#include "storage/Utils/ExceptionImpl.h" +#include "storage/Utils/StorageTmpl.h" +#include "storage/Utils/LoggerImpl.h" +#include "storage/Utils/StorageDefines.h" + + +namespace storage +{ + + std::ostream& + operator<<(std::ostream& s, const UdevFilter& udev_filter) + { + s << "allowed-path-patterns:" << udev_filter.allowed_path_patterns + << " allowed-id-patterns:" << udev_filter.allowed_id_patterns; + + return s; + } + + + UdevFilters::UdevFilters() + { + // Only for check during build. + const char* confdir = getenv("LIBSTORAGE_CONFDIR"); + if (confdir) + { + load(string(confdir) + "/" UDEV_FILTERS_FILE); + return; + } + + // While loading the filters from /etc only IO-Exceptions are caught. Thus if the + // file exists it must also be valid. + + try + { + y2mil("loading " << ETC_LIBSTORAGE_UDEV_FILTERS_FILE); + load(ETC_LIBSTORAGE_UDEV_FILTERS_FILE); + } + catch (const IOException& e) + { + ST_CAUGHT(e); + + y2mil("loading " << USR_SHARE_LIBSTORAGE_UDEV_FILTERS_FILE); + load(USR_SHARE_LIBSTORAGE_UDEV_FILTERS_FILE); + } + + y2mil(*this); + } + + + void + UdevFilters::load(const string& filename) + { + JsonFile json(filename); + + json_object* root = json.get_root(); + + parse1(root, "Disk", disk); + parse1(root, "Dasd", dasd); + parse1(root, "Md", md); + parse1(root, "DmRaid", dm_raid); + parse1(root, "Multipath", multipath); + } + + + void + UdevFilters::parse1(json_object* root, const char* name, UdevFilter& udev_filter) const + { + json_object* object2 = json_object_object_get(root, name); + if (object2) + udev_filter = parse2(object2); + } + + + UdevFilter + UdevFilters::parse2(json_object* object) const + { + UdevFilter ret; + + json_object* object2 = json_object_object_get(object, "allowed-path-patterns"); + if (object2) + ret.allowed_path_patterns = parse3(object2); + + json_object* object3 = json_object_object_get(object, "allowed-id-patterns"); + if (object3) + ret.allowed_id_patterns = parse3(object3); + + return ret; + } + + + vector<string> + UdevFilters::parse3(json_object* object) const + { + vector<string> ret; + + if (!json_object_is_type(object, json_type_array)) + ST_THROW(Exception("value of allowed-*-patterns entry not an array")); + + for (size_t i = 0; i < json_object_array_length(object); ++i) + { + json_object* name = json_object_array_get_idx(object, i); + if (!json_object_is_type(name, json_type_string)) + ST_THROW(Exception("element of allowed-*-patterns array not a string")); + + ret.push_back(json_object_get_string(name)); + } + + return ret; + } + + + std::ostream& + operator<<(std::ostream& s, const UdevFilters& udev_filters) + { + s << "disk: " << udev_filters.disk << '\n'; + s << "dasd: " << udev_filters.dasd << '\n'; + s << "md: " << udev_filters.md << '\n'; + s << "dm-raid: " << udev_filters.dm_raid << '\n'; + s << "multipath: " << udev_filters.multipath << '\n'; + + return s; + } + + + void + udev_filter(vector<string>& names, const vector<string>& allowed_patterns) + { + const int flags = 0; + + vector<string>::iterator it = names.begin(); + + for (const string& allowed_pattern : allowed_patterns) + { + it = stable_partition(it, names.end(), [&allowed_pattern](const string& name) { + return fnmatch(allowed_pattern.c_str(), name.c_str(), flags) == 0; + }); + } + + names.erase(it, names.end()); + } + +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/storage/Utils/UdevFilters.h new/libstorage-ng-4.5.53/storage/Utils/UdevFilters.h --- old/libstorage-ng-4.5.52/storage/Utils/UdevFilters.h 1970-01-01 01:00:00.000000000 +0100 +++ new/libstorage-ng-4.5.53/storage/Utils/UdevFilters.h 2022-11-25 12:37:41.000000000 +0100 @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2022 SUSE LLC + * + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as published + * by the Free Software Foundation. + * + * 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, contact Novell, Inc. + * + * To contact Novell about this file by physical or electronic mail, you may + * find current contact information at www.novell.com. + */ + + +#ifndef UDEV_FILTERS_H +#define UDEV_FILTERS_H + + +#include "storage/Utils/JsonFile.h" + + +namespace storage +{ + using namespace std; + + + // See doc/udev.md. + + + class UdevFilter + { + public: + + vector<string> allowed_path_patterns; + vector<string> allowed_id_patterns; + + friend std::ostream& operator<<(std::ostream& s, const UdevFilter& udev_filter); + + }; + + + class UdevFilters + { + public: + + UdevFilters(); + + UdevFilter disk; + UdevFilter dasd; + UdevFilter md; + UdevFilter dm_raid; + UdevFilter multipath; + + friend std::ostream& operator<<(std::ostream& s, const UdevFilters& udev_filters); + + private: + + void load(const string& filename); + + void parse1(json_object* root, const char* name, UdevFilter& udev_filter) const; + UdevFilter parse2(json_object* object) const; + vector<string> parse3(json_object* object) const; + + }; + + + /** + * Remove names not matching any pattern. Matching names are ordered according to the + * order of the patterns. + */ + void + udev_filter(vector<string>& names, const vector<string>& allowed_patterns); + +} + + +#endif diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/testsuite/Utils/Makefile.am new/libstorage-ng-4.5.53/testsuite/Utils/Makefile.am --- old/libstorage-ng-4.5.52/testsuite/Utils/Makefile.am 2022-11-11 02:13:36.000000000 +0100 +++ new/libstorage-ng-4.5.53/testsuite/Utils/Makefile.am 2022-11-25 12:37:41.000000000 +0100 @@ -9,7 +9,7 @@ check_PROGRAMS = enum.test udev-encoding.test humanstring.test region.test \ exception.test topology.test alignment.test math.test systemcmd.test \ dirname.test basename.test algorithm.test format.test join.test \ - regex.test sort-by.test jsonfile.test rootprefix.test + regex.test sort-by.test jsonfile.test rootprefix.test udev-filters.test AM_DEFAULT_SOURCE_EXT = .cc diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/testsuite/Utils/humanstring.cc new/libstorage-ng-4.5.53/testsuite/Utils/humanstring.cc --- old/libstorage-ng-4.5.52/testsuite/Utils/humanstring.cc 2022-11-11 02:13:36.000000000 +0100 +++ new/libstorage-ng-4.5.53/testsuite/Utils/humanstring.cc 2022-11-25 12:37:41.000000000 +0100 @@ -26,7 +26,7 @@ Fixture() { - const char* localedir = getenv("LOCALEDIR"); + const char* localedir = getenv("LIBSTORAGE_LOCALEDIR"); if (localedir) bindtextdomain("libstorage-ng", localedir); } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/testsuite/Utils/udev-encoding.cc new/libstorage-ng-4.5.53/testsuite/Utils/udev-encoding.cc --- old/libstorage-ng-4.5.52/testsuite/Utils/udev-encoding.cc 2022-11-11 02:13:36.000000000 +0100 +++ new/libstorage-ng-4.5.53/testsuite/Utils/udev-encoding.cc 2022-11-25 12:37:41.000000000 +0100 @@ -4,9 +4,7 @@ #include <boost/test/unit_test.hpp> -#include <stdlib.h> #include <iostream> -#include <locale> #include "storage/Utils/AppUtil.h" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libstorage-ng-4.5.52/testsuite/Utils/udev-filters.cc new/libstorage-ng-4.5.53/testsuite/Utils/udev-filters.cc --- old/libstorage-ng-4.5.52/testsuite/Utils/udev-filters.cc 1970-01-01 01:00:00.000000000 +0100 +++ new/libstorage-ng-4.5.53/testsuite/Utils/udev-filters.cc 2022-11-25 12:37:41.000000000 +0100 @@ -0,0 +1,115 @@ + +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE libstorage + +#include <boost/test/unit_test.hpp> + +#include <iostream> + +#include "storage/Utils/UdevFilters.h" + + +using namespace std; +using namespace storage; + + +namespace std +{ + ostream& operator<<(ostream& s, const vector<string>& names) + { + s << "{"; + for (vector<string>::const_iterator it = names.begin(); it != names.end(); ++it) + s << (it == names.begin() ? " " : ", ") << *it; + s << " }"; + + return s; + } +} + + +BOOST_AUTO_TEST_CASE(test1) +{ + const vector<string> patterns = { "scsi-*", "ata-*" }; + + vector<string> names = { "ata-456", "ata-123", "scsi-123", "scsi-123.0", "lol-123" }; + udev_filter(names, patterns); + + BOOST_CHECK_EQUAL(names, vector<string>({ "scsi-123", "scsi-123.0", "ata-456", "ata-123" })); +} + + +BOOST_AUTO_TEST_CASE(test2) +{ + const vector<string> patterns = { "ata-*" }; + + vector<string> names = { "ata-123", "lol-123", "ata-123", "lol-123" }; + udev_filter(names, patterns); + + BOOST_CHECK_EQUAL(names, vector<string>({ "ata-123", "ata-123" })); +} + + +BOOST_AUTO_TEST_CASE(test3) +{ + const vector<string> patterns = { "scsi-ata-*", "scsi-*" }; + + vector<string> names = { "scsi-ata-123", "lol-123" }; + udev_filter(names, patterns); + + BOOST_CHECK_EQUAL(names, vector<string>({ "scsi-ata-123" })); +} + + +BOOST_AUTO_TEST_CASE(test4) +{ + const vector<string> patterns = { "scsi.*" }; + + vector<string> names = { "scsi.123", "lol-123" }; + udev_filter(names, patterns); + + BOOST_CHECK_EQUAL(names, vector<string>({ "scsi.123" })); +} + + +BOOST_AUTO_TEST_CASE(test5) +{ + const vector<string> patterns = { "scsi.*" }; + + vector<string> names = { "scsi.123", "lol-123" }; + udev_filter(names, patterns); + + BOOST_CHECK_EQUAL(names, vector<string>({ "scsi.123" })); +} + + +BOOST_AUTO_TEST_CASE(test6) +{ + const vector<string> patterns = { "scsi-[123]ATA-*" }; + + vector<string> names = { "scsi-1ATA-123", "scsi-4ATA-123", "lol-123" }; + udev_filter(names, patterns); + + BOOST_CHECK_EQUAL(names, vector<string>({ "scsi-1ATA-123" })); +} + + +BOOST_AUTO_TEST_CASE(test7) +{ + const vector<string> patterns = { "scsi-?ATA-*" }; + + vector<string> names = { "scsi-2ATA-123", "scsi-1ATA-123", "lol-123" }; + udev_filter(names, patterns); + + BOOST_CHECK_EQUAL(names, vector<string>({ "scsi-2ATA-123", "scsi-1ATA-123" })); +} + + +BOOST_AUTO_TEST_CASE(test8) +{ + const vector<string> patterns = { "ata-*-x" }; + + vector<string> names = { "ata-123-x", "ata-123-y", "sata-123-x" }; + udev_filter(names, patterns); + + BOOST_CHECK_EQUAL(names, vector<string>({ "ata-123-x" })); +}