From 43a885d8665bb76da11825fb1fce5781cf9954e7 Mon Sep 17 00:00:00 2001 From: Arvin Schnell Date: Wed, 22 Jun 2022 12:09:21 +0200 Subject: [PATCH] - handle rootprefix when reading fstab, crypttab and mdadm.conf --- LIBVERSION | 2 +- storage/ActiongraphImpl.cc | 7 ++++--- storage/Devices/BitlockerV2Impl.cc | 17 +++++++++-------- storage/Devices/BitlockerV2Impl.h | 4 ++-- storage/Devices/EncryptionImpl.cc | 4 ++-- storage/Devices/EncryptionImpl.h | 4 ++-- storage/Devices/LuksImpl.cc | 18 ++++++++++-------- storage/Devices/LuksImpl.h | 6 +++--- storage/Devices/MdImpl.cc | 11 +++++++---- storage/Devices/PlainEncryptionImpl.cc | 6 ++++-- storage/Environment.cc | 16 +++++++++++++++- storage/Environment.h | 21 +++++++++++++++++++++ storage/EnvironmentImpl.cc | 10 +++++++++- storage/EnvironmentImpl.h | 4 ++++ storage/Filesystems/BlkFilesystemImpl.cc | 2 +- storage/Filesystems/MountPoint.h | 2 ++ storage/Filesystems/MountPointImpl.cc | 4 ++-- storage/Filesystems/NfsImpl.cc | 5 +++-- storage/Filesystems/TmpfsImpl.cc | 5 +++-- storage/Prober.cc | 5 +++-- storage/Prober.h | 10 ++++++++-- storage/Storage.h | 4 ++-- storage/StorageImpl.cc | 13 +++++++++---- storage/SystemInfo/SystemInfoImpl.h | 12 ++++++------ testsuite/probe/prefixed-mockup.xml | 7 ++----- testsuite/probe/prefixed.cc | 4 ++-- utils/probe.cc | 8 +++++++- 27 files changed, 143 insertions(+), 68 deletions(-) diff --git a/LIBVERSION b/LIBVERSION index 32a6ce3c7..79e15fd49 100644 --- a/LIBVERSION +++ b/LIBVERSION @@ -1 +1 @@ -1.76.0 +1.77.0 diff --git a/storage/ActiongraphImpl.cc b/storage/ActiongraphImpl.cc index fe7dc3dc9..122a2d5c4 100644 --- a/storage/ActiongraphImpl.cc +++ b/storage/ActiongraphImpl.cc @@ -73,7 +73,7 @@ namespace storage if (!etc_fstab) { const Storage& storage = actiongraph.get_storage(); - string filename = storage.get_impl().prepend_rootprefix(ETC_FSTAB); + string filename = storage.prepend_rootprefix(ETC_FSTAB); etc_fstab = make_unique(filename); } @@ -88,7 +88,7 @@ namespace storage if (!etc_crypttab) { const Storage& storage = actiongraph.get_storage(); - string filename = storage.get_impl().prepend_rootprefix(ETC_CRYPTTAB); + string filename = storage.prepend_rootprefix(ETC_CRYPTTAB); etc_crypttab = make_unique(filename); } @@ -103,7 +103,7 @@ namespace storage if (!etc_mdadm) { const Storage& storage = actiongraph.get_storage(); - string filename = storage.get_impl().prepend_rootprefix(ETC_MDADM); + string filename = storage.prepend_rootprefix(ETC_MDADM); etc_mdadm = make_unique(filename); } @@ -772,6 +772,7 @@ namespace storage y2mil("commit begin"); y2mil("used features: " << get_used_features_names(used_features())); + y2mil("rootprefix: " << storage.get_rootprefix()); CommitData commit_data(*this, Tense::PRESENT_CONTINUOUS); diff --git a/storage/Devices/BitlockerV2Impl.cc b/storage/Devices/BitlockerV2Impl.cc index 6036c1a02..826444083 100644 --- a/storage/Devices/BitlockerV2Impl.cc +++ b/storage/Devices/BitlockerV2Impl.cc @@ -148,8 +148,8 @@ namespace storage bool - BitlockerV2::Impl::activate_bitlocker(const ActivateCallbacksV3* activate_callbacks, SystemInfo::Impl& system_info, - const string& name, const string& uuid) + BitlockerV2::Impl::activate_bitlocker(const ActivateCallbacksV3* activate_callbacks, const Storage& storage, + SystemInfo::Impl& system_info, const string& name, const string& uuid) { BitlockerInfo bitlocker_info; bitlocker_info.get_impl().device_name = name; @@ -158,7 +158,7 @@ namespace storage dev_t majorminor = system_info.getCmdUdevadmInfo(name).get_majorminor(); - const EtcCrypttab& etc_crypttab = system_info.getEtcCrypttab(); + const EtcCrypttab& etc_crypttab = system_info.getEtcCrypttab(storage.prepend_rootprefix(ETC_CRYPTTAB)); const CrypttabEntry* crypttab_entry = etc_crypttab.find_by_any_block_device(system_info, uuid, "", majorminor); @@ -171,7 +171,7 @@ namespace storage } else { - dm_table_name = bitlocker_info.get_impl().dm_table_name = next_free_cr_auto_name(system_info); + dm_table_name = bitlocker_info.get_impl().dm_table_name = next_free_cr_auto_name(storage, system_info); bitlocker_info.get_impl().is_dm_table_name_generated = true; } @@ -253,7 +253,7 @@ namespace storage bool - BitlockerV2::Impl::activate_bitlockers(const ActivateCallbacksV3* activate_callbacks) + BitlockerV2::Impl::activate_bitlockers(const ActivateCallbacksV3* activate_callbacks, const Storage& storage) { y2mil("activate_bitlockers"); @@ -284,7 +284,7 @@ namespace storage y2mil("inactive bitlocker name:" << key_value1.first << " uuid:" << uuid); - if (activate_bitlocker(activate_callbacks, system_info, key_value1.first, uuid)) + if (activate_bitlocker(activate_callbacks, storage, system_info, key_value1.first, uuid)) ret = true; } @@ -340,8 +340,9 @@ namespace storage BitlockerV2::Impl::probe_bitlockers(Prober& prober) { SystemInfo::Impl& system_info = prober.get_system_info(); + const Storage& storage = prober.get_storage(); const CmdDmsetupTable& cmd_dmsetup_table = system_info.getCmdDmsetupTable(); - const EtcCrypttab& etc_crypttab = system_info.getEtcCrypttab(); + const EtcCrypttab& etc_crypttab = system_info.getEtcCrypttab(storage.prepend_rootprefix(ETC_CRYPTTAB)); const Blkid& blkid = system_info.getBlkid(); /* @@ -387,7 +388,7 @@ namespace storage else if (crypttab_entry) dm_table_name = crypttab_entry->get_crypt_device(); else - dm_table_name = next_free_cr_auto_name(system_info); + dm_table_name = next_free_cr_auto_name(storage, system_info); BitlockerV2* bitlocker = BitlockerV2::create(prober.get_system(), dm_table_name); bitlocker->get_impl().uuid = uuid; diff --git a/storage/Devices/BitlockerV2Impl.h b/storage/Devices/BitlockerV2Impl.h index 042c332a4..195c10693 100644 --- a/storage/Devices/BitlockerV2Impl.h +++ b/storage/Devices/BitlockerV2Impl.h @@ -51,10 +51,10 @@ namespace storage virtual string get_pretty_classname() const override; - static bool activate_bitlocker(const ActivateCallbacksV3* activate_callbacks, + static bool activate_bitlocker(const ActivateCallbacksV3* activate_callbacks, const Storage& storage, SystemInfo::Impl& system_info, const string& name, const string& uuid); - static bool activate_bitlockers(const ActivateCallbacksV3* activate_callbacks); + static bool activate_bitlockers(const ActivateCallbacksV3* activate_callbacks, const Storage& storage); static bool deactivate_bitlockers(); diff --git a/storage/Devices/EncryptionImpl.cc b/storage/Devices/EncryptionImpl.cc index 62eccdc53..a6ed97f61 100644 --- a/storage/Devices/EncryptionImpl.cc +++ b/storage/Devices/EncryptionImpl.cc @@ -111,10 +111,10 @@ namespace storage string - Encryption::Impl::next_free_cr_auto_name(SystemInfo::Impl& system_info) + Encryption::Impl::next_free_cr_auto_name(const Storage& storage, SystemInfo::Impl& system_info) { const CmdDmsetupInfo& cmd_dmsetup_info = system_info.getCmdDmsetupInfo(); - const EtcCrypttab& etc_crypttab = system_info.getEtcCrypttab(); + const EtcCrypttab& etc_crypttab = system_info.getEtcCrypttab(storage.prepend_rootprefix(ETC_CRYPTTAB)); static int nr = 1; diff --git a/storage/Devices/EncryptionImpl.h b/storage/Devices/EncryptionImpl.h index 5ebef5b5f..ea446b522 100644 --- a/storage/Devices/EncryptionImpl.h +++ b/storage/Devices/EncryptionImpl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2016-2021] SUSE LLC + * Copyright (c) [2016-2022] SUSE LLC * * All Rights Reserved. * @@ -160,7 +160,7 @@ namespace storage * exist in the system and that the same name is never * returned twice. */ - static string next_free_cr_auto_name(SystemInfo::Impl& system_info); + static string next_free_cr_auto_name(const Storage& storage, SystemInfo::Impl& system_info); void add_key_file_option_and_execute(const string& cmd_line) const; diff --git a/storage/Devices/LuksImpl.cc b/storage/Devices/LuksImpl.cc index d5f83b69b..6c0076b3c 100644 --- a/storage/Devices/LuksImpl.cc +++ b/storage/Devices/LuksImpl.cc @@ -184,8 +184,9 @@ namespace storage bool - Luks::Impl::activate_luks(const ActivateCallbacks* activate_callbacks, SystemInfo::Impl& system_info, - const string& name, const string& uuid, const string& label) + Luks::Impl::activate_luks(const ActivateCallbacks* activate_callbacks, const Storage& storage, + SystemInfo::Impl& system_info, const string& name, const string& uuid, + const string& label) { LuksInfo luks_info; luks_info.get_impl().device_name = name; @@ -195,7 +196,7 @@ namespace storage dev_t majorminor = system_info.getCmdUdevadmInfo(name).get_majorminor(); - const EtcCrypttab& etc_crypttab = system_info.getEtcCrypttab(); + const EtcCrypttab& etc_crypttab = system_info.getEtcCrypttab(storage.prepend_rootprefix(ETC_CRYPTTAB)); const CrypttabEntry* crypttab_entry = etc_crypttab.find_by_any_block_device(system_info, uuid, label, majorminor); @@ -208,7 +209,7 @@ namespace storage } else { - dm_table_name = luks_info.get_impl().dm_table_name = next_free_cr_auto_name(system_info); + dm_table_name = luks_info.get_impl().dm_table_name = next_free_cr_auto_name(storage, system_info); luks_info.get_impl().is_dm_table_name_generated = true; } @@ -298,7 +299,7 @@ namespace storage bool - Luks::Impl::activate_lukses(const ActivateCallbacks* activate_callbacks) + Luks::Impl::activate_lukses(const ActivateCallbacks* activate_callbacks, const Storage& storage) { y2mil("activate_lukses"); @@ -325,7 +326,7 @@ namespace storage y2mil("inactive luks name:" << key_value1.first << " uuid:" << key_value1.second.luks_uuid << " label:" << key_value1.second.luks_label); - if (activate_luks(activate_callbacks, system_info, key_value1.first, + if (activate_luks(activate_callbacks, storage, system_info, key_value1.first, key_value1.second.luks_uuid, key_value1.second.luks_label)) ret = true; } @@ -382,8 +383,9 @@ namespace storage Luks::Impl::probe_lukses(Prober& prober) { SystemInfo::Impl& system_info = prober.get_system_info(); + const Storage& storage = prober.get_storage(); const CmdDmsetupTable& cmd_dmsetup_table = system_info.getCmdDmsetupTable(); - const EtcCrypttab& etc_crypttab = system_info.getEtcCrypttab(); + const EtcCrypttab& etc_crypttab = system_info.getEtcCrypttab(storage.prepend_rootprefix(ETC_CRYPTTAB)); const Blkid& blkid = system_info.getBlkid(); /* @@ -452,7 +454,7 @@ namespace storage else if (crypttab_entry) dm_table_name = crypttab_entry->get_crypt_device(); else - dm_table_name = next_free_cr_auto_name(system_info); + dm_table_name = next_free_cr_auto_name(storage, system_info); Luks* luks = Luks::create(prober.get_system(), dm_table_name); luks->get_impl().uuid = uuid; diff --git a/storage/Devices/LuksImpl.h b/storage/Devices/LuksImpl.h index 0c5fe3abc..73f2e997e 100644 --- a/storage/Devices/LuksImpl.h +++ b/storage/Devices/LuksImpl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2016-2021] SUSE LLC + * Copyright (c) [2016-2022] SUSE LLC * * All Rights Reserved. * @@ -53,11 +53,11 @@ namespace storage virtual string get_pretty_classname() const override; - static bool activate_luks(const ActivateCallbacks* activate_callbacks, + static bool activate_luks(const ActivateCallbacks* activate_callbacks, const Storage& storage, SystemInfo::Impl& system_info, const string& name, const string& uuid, const string& label); - static bool activate_lukses(const ActivateCallbacks* activate_callbacks); + static bool activate_lukses(const ActivateCallbacks* activate_callbacks, const Storage& storage); static bool deactivate_lukses(); diff --git a/storage/Devices/MdImpl.cc b/storage/Devices/MdImpl.cc index 96e1e8d0c..246aaf71c 100644 --- a/storage/Devices/MdImpl.cc +++ b/storage/Devices/MdImpl.cc @@ -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. * @@ -489,16 +489,19 @@ namespace storage { Partitionable::Impl::probe_pass_1a(prober); - const ProcMdstat::Entry& entry = prober.get_system_info().getProcMdstat().get_entry(get_sysfs_name()); + SystemInfo::Impl& system_info = prober.get_system_info(); + + const ProcMdstat::Entry& entry = system_info.getProcMdstat().get_entry(get_sysfs_name()); md_parity = entry.md_parity; chunk_size = entry.chunk_size; - const MdadmDetail& mdadm_detail = prober.get_system_info().getMdadmDetail(get_name()); + const MdadmDetail& mdadm_detail = system_info.getMdadmDetail(get_name()); uuid = mdadm_detail.uuid; metadata = mdadm_detail.metadata; md_level = mdadm_detail.level; - const EtcMdadm& etc_mdadm = prober.get_system_info().getEtcMdadm(); + const Storage& storage = prober.get_storage(); + const EtcMdadm& etc_mdadm = system_info.getEtcMdadm(storage.prepend_rootprefix(ETC_MDADM)); in_etc_mdadm = etc_mdadm.has_entry(uuid); } diff --git a/storage/Devices/PlainEncryptionImpl.cc b/storage/Devices/PlainEncryptionImpl.cc index e638a3f75..133efd9c7 100644 --- a/storage/Devices/PlainEncryptionImpl.cc +++ b/storage/Devices/PlainEncryptionImpl.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 SUSE LLC + * Copyright (c) [2019-2022] SUSE LLC * * All Rights Reserved. * @@ -30,6 +30,7 @@ #include "storage/EtcCrypttab.h" #include "storage/Prober.h" #include "storage/Utils/Format.h" +#include "storage/Storage.h" namespace storage @@ -69,8 +70,9 @@ namespace storage PlainEncryption::Impl::probe_plain_encryptions(Prober& prober) { SystemInfo::Impl& system_info = prober.get_system_info(); + const Storage& storage = prober.get_storage(); const CmdDmsetupTable& cmd_dmsetup_table = system_info.getCmdDmsetupTable(); - const EtcCrypttab& etc_crypttab = system_info.getEtcCrypttab(); + const EtcCrypttab& etc_crypttab = system_info.getEtcCrypttab(storage.prepend_rootprefix(ETC_CRYPTTAB)); const Blkid& blkid = system_info.getBlkid(); /* diff --git a/storage/Environment.cc b/storage/Environment.cc index 1c53c6e7f..5f52a8350 100644 --- a/storage/Environment.cc +++ b/storage/Environment.cc @@ -1,6 +1,6 @@ /* * Copyright (c) [2014-2015] Novell, Inc. - * Copyright (c) 2020 SUSE LLC + * Copyright (c) [2020-2022] SUSE LLC * * All Rights Reserved. * @@ -74,6 +74,20 @@ namespace storage } + const std::string& + Environment::get_rootprefix() const + { + return get_impl().get_rootprefix(); + } + + + void + Environment::set_rootprefix(const std::string& rootprefix) + { + get_impl().set_rootprefix(rootprefix); + } + + const string& Environment::get_devicegraph_filename() const { diff --git a/storage/Environment.h b/storage/Environment.h index dfdfa65f9..17d540bbc 100644 --- a/storage/Environment.h +++ b/storage/Environment.h @@ -1,5 +1,6 @@ /* * Copyright (c) [2014-2015] Novell, Inc. + * Copyright (c) 2022 SUSE LLC * * All Rights Reserved. * @@ -89,6 +90,26 @@ namespace storage */ TargetMode get_target_mode() const; + /** + * Query the rootprefix. + * + * The rootprefix is prepended to certain paths when accessing the system, + * e.g. when opening files like /etc/fstab and when mounting filesystems (that + * have rootprefixed set). + * + * The rootprefix is at least used for activate(), probe() and commit(). + */ + const std::string& get_rootprefix() const; + + /** + * Set the rootprefix. + * + * If a rootprefix is not needed it has to be empty. + * + * @see get_rootprefix() + */ + void set_rootprefix(const std::string& rootprefix); + const std::string& get_devicegraph_filename() const; void set_devicegraph_filename(const std::string& devicegraph_filename); diff --git a/storage/EnvironmentImpl.cc b/storage/EnvironmentImpl.cc index 8252f0012..6bb35406c 100644 --- a/storage/EnvironmentImpl.cc +++ b/storage/EnvironmentImpl.cc @@ -37,6 +37,13 @@ namespace storage } + void + Environment::Impl::set_rootprefix(const string& rootprefix) + { + Impl::rootprefix = rootprefix; + } + + void Environment::Impl::set_devicegraph_filename(const string& devicegraph_filename) { @@ -83,7 +90,8 @@ namespace storage { return out << "read-only:" << environment.read_only << " probe-mode:" << toString(environment.probe_mode) << " target-mode:" - << toString(environment.target_mode); + << toString(environment.target_mode) << " rootprefix:" + << environment.rootprefix; } diff --git a/storage/EnvironmentImpl.h b/storage/EnvironmentImpl.h index ed503ab1f..3a0cf997a 100644 --- a/storage/EnvironmentImpl.h +++ b/storage/EnvironmentImpl.h @@ -46,6 +46,9 @@ namespace storage TargetMode get_target_mode() const { return target_mode; } + const string& get_rootprefix() const { return rootprefix; } + void set_rootprefix(const string& rootprefix); + const string& get_devicegraph_filename() const { return devicegraph_filename; } void set_devicegraph_filename(const string& devicegraph_filename); @@ -69,6 +72,7 @@ namespace storage const ProbeMode probe_mode; const TargetMode target_mode; + string rootprefix; string devicegraph_filename; string arch_filename; string mockup_filename; diff --git a/storage/Filesystems/BlkFilesystemImpl.cc b/storage/Filesystems/BlkFilesystemImpl.cc index 963df80e1..5ee1c8795 100644 --- a/storage/Filesystems/BlkFilesystemImpl.cc +++ b/storage/Filesystems/BlkFilesystemImpl.cc @@ -712,7 +712,7 @@ namespace storage vector BlkFilesystem::Impl::find_etc_fstab_entries_unfiltered(SystemInfo::Impl& system_info) const { - const EtcFstab& etc_fstab = system_info.getEtcFstab(); + const EtcFstab& etc_fstab = system_info.getEtcFstab(get_storage()->prepend_rootprefix(ETC_FSTAB)); vector ret; diff --git a/storage/Filesystems/MountPoint.h b/storage/Filesystems/MountPoint.h index 645aa2897..11f72c15d 100644 --- a/storage/Filesystems/MountPoint.h +++ b/storage/Filesystems/MountPoint.h @@ -194,6 +194,8 @@ namespace storage * during mount operations. * * The default value is true (for historic reasons). + * + * @see Environment::get_rootprefix() */ bool is_rootprefixed() const; diff --git a/storage/Filesystems/MountPointImpl.cc b/storage/Filesystems/MountPointImpl.cc index e5150b488..4dbbfd738 100644 --- a/storage/Filesystems/MountPointImpl.cc +++ b/storage/Filesystems/MountPointImpl.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) [2017-2021] SUSE LLC + * Copyright (c) [2017-2022] SUSE LLC * * All Rights Reserved. * @@ -302,7 +302,7 @@ namespace storage MountPoint::Impl::get_rootprefixed_path() const { if (rootprefixed) - return get_storage()->get_impl().prepend_rootprefix(path); + return get_storage()->prepend_rootprefix(path); else return path; } diff --git a/storage/Filesystems/NfsImpl.cc b/storage/Filesystems/NfsImpl.cc index 2041014d1..d332a3d05 100644 --- a/storage/Filesystems/NfsImpl.cc +++ b/storage/Filesystems/NfsImpl.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) [2017-2020] SUSE LLC + * Copyright (c) [2017-2022] SUSE LLC * * All Rights Reserved. * @@ -116,6 +116,8 @@ namespace storage // TODO the old library filters the mount options SystemInfo::Impl& system_info = prober.get_system_info(); + const Storage& storage = prober.get_storage(); + const EtcFstab& etc_fstab = system_info.getEtcFstab(storage.prepend_rootprefix(ETC_FSTAB)); /* * The key of the map is a pair of server and path of the NFS mounts. @@ -126,7 +128,6 @@ namespace storage entries_t entries; - const EtcFstab& etc_fstab = system_info.getEtcFstab(); for (int i = 0; i < etc_fstab.get_entry_count(); ++i) { const FstabEntry* fstab_entry = etc_fstab.get_entry(i); diff --git a/storage/Filesystems/TmpfsImpl.cc b/storage/Filesystems/TmpfsImpl.cc index 751b0ca31..324224bcf 100644 --- a/storage/Filesystems/TmpfsImpl.cc +++ b/storage/Filesystems/TmpfsImpl.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 SUSE LLC + * Copyright (c) [2020-2022] SUSE LLC * * All Rights Reserved. * @@ -69,9 +69,10 @@ namespace storage Tmpfs::Impl::probe_tmpfses(Prober& prober) { SystemInfo::Impl& system_info = prober.get_system_info(); + const Storage& storage = prober.get_storage(); + const EtcFstab& etc_fstab = system_info.getEtcFstab(storage.prepend_rootprefix(ETC_FSTAB)); vector fstab_entries; - const EtcFstab& etc_fstab = system_info.getEtcFstab(); for (int i = 0; i < etc_fstab.get_entry_count(); ++i) { const FstabEntry* fstab_entry = etc_fstab.get_entry(i); diff --git a/storage/Prober.cc b/storage/Prober.cc index 8c6db7074..2ec0bb772 100644 --- a/storage/Prober.cc +++ b/storage/Prober.cc @@ -157,8 +157,9 @@ namespace storage } - Prober::Prober(const ProbeCallbacks* probe_callbacks, Devicegraph* system, SystemInfo::Impl& system_info) - : probe_callbacks(probe_callbacks), system(system), system_info(system_info) + Prober::Prober(const Storage& storage, const ProbeCallbacks* probe_callbacks, Devicegraph* system, + SystemInfo::Impl& system_info) + : storage(storage), probe_callbacks(probe_callbacks), system(system), system_info(system_info) { /** * Difficulties: diff --git a/storage/Prober.h b/storage/Prober.h index 056620c0c..508a23da0 100644 --- a/storage/Prober.h +++ b/storage/Prober.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2016-2020] SUSE LLC + * Copyright (c) [2016-2022] SUSE LLC * * All Rights Reserved. * @@ -37,6 +37,7 @@ namespace storage using std::vector; + class Storage; class ProbeCallbacks; class Devicegraph; class Device; @@ -76,7 +77,10 @@ namespace storage /** * The constructor probes the system and places the result in system. */ - Prober(const ProbeCallbacks* probe_callbacks, Devicegraph* system, SystemInfo::Impl& system_info); + Prober(const Storage& storage, const ProbeCallbacks* probe_callbacks, Devicegraph* system, + SystemInfo::Impl& system_info); + + const Storage& get_storage() const { return storage; } const ProbeCallbacks* get_probe_callbacks() const { return probe_callbacks; } @@ -105,6 +109,8 @@ namespace storage private: + const Storage& storage; + const ProbeCallbacks* probe_callbacks; Devicegraph* system; diff --git a/storage/Storage.h b/storage/Storage.h index 232da407e..a3564794f 100644 --- a/storage/Storage.h +++ b/storage/Storage.h @@ -546,8 +546,8 @@ namespace storage */ void set_default_mount_by(MountByType default_mount_by); - const std::string& get_rootprefix() const; - void set_rootprefix(const std::string& rootprefix); + const std::string& get_rootprefix() const ST_DEPRECATED; + void set_rootprefix(const std::string& rootprefix) ST_DEPRECATED; /** * Prepends the root prefix to a mount point if necessary. diff --git a/storage/StorageImpl.cc b/storage/StorageImpl.cc index 9e84340ff..3dbedbf6e 100644 --- a/storage/StorageImpl.cc +++ b/storage/StorageImpl.cc @@ -52,7 +52,8 @@ namespace storage Storage::Impl::Impl(Storage& storage, const Environment& environment) : storage(storage), environment(environment), arch(false), lock(environment.is_read_only(), !environment.get_impl().is_do_lock()), - default_mount_by(MountByType::UUID), tmp_dir("libstorage-XXXXXX") + default_mount_by(MountByType::UUID), rootprefix(environment.get_rootprefix()), + tmp_dir("libstorage-XXXXXX") { y2mil("constructed Storage with " << environment); y2mil("libstorage-ng version " VERSION); @@ -97,6 +98,8 @@ namespace storage y2mil("activate begin"); + y2mil("rootprefix: " << get_rootprefix()); + const ActivateCallbacksV3* activate_callbacks_v3 = dynamic_cast(activate_callbacks); Multipath::Impl::activate_multipaths(activate_callbacks); @@ -112,10 +115,10 @@ namespace storage if (LvmLv::Impl::activate_lvm_lvs(activate_callbacks)) again = true; - if (Luks::Impl::activate_lukses(activate_callbacks)) + if (Luks::Impl::activate_lukses(activate_callbacks, storage)) again = true; - if (activate_callbacks_v3 && BitlockerV2::Impl::activate_bitlockers(activate_callbacks_v3)) + if (activate_callbacks_v3 && BitlockerV2::Impl::activate_bitlockers(activate_callbacks_v3, storage)) again = true; if (!again) @@ -177,6 +180,8 @@ namespace storage { y2mil("probe begin"); + y2mil("rootprefix: " << get_rootprefix()); + CallbacksGuard callbacks_guard(probe_callbacks); if (exist_devicegraph("probed")) @@ -243,7 +248,7 @@ namespace storage arch = system_info.getArch(); - Prober prober(probe_callbacks, probed, system_info); + Prober prober(storage, probe_callbacks, probed, system_info); } diff --git a/storage/SystemInfo/SystemInfoImpl.h b/storage/SystemInfo/SystemInfoImpl.h index 4af68f93e..f6a44a89d 100644 --- a/storage/SystemInfo/SystemInfoImpl.h +++ b/storage/SystemInfo/SystemInfoImpl.h @@ -77,9 +77,9 @@ namespace storage Impl(); ~Impl(); - const EtcFstab& getEtcFstab() { return etc_fstab.get(); } - const EtcCrypttab& getEtcCrypttab() { return etc_crypttab.get(); } - const EtcMdadm& getEtcMdadm() { return etc_mdadm.get(); } + const EtcFstab& getEtcFstab(const string& path) { return etc_fstab.get(path); } + const EtcCrypttab& getEtcCrypttab(const string& path) { return etc_crypttab.get(path); } + const EtcMdadm& getEtcMdadm(const string& path) { return etc_mdadm.get(path); } const Arch& getArch() { return arch.get(); } const Dir& getDir(const string& path) { return dirs.get(path); } @@ -232,9 +232,9 @@ namespace storage }; - LazyObject etc_fstab; - LazyObject etc_crypttab; - LazyObject etc_mdadm; + LazyObjects etc_fstab; + LazyObjects etc_crypttab; + LazyObjects etc_mdadm; LazyObject arch; LazyObjects dirs; diff --git a/testsuite/probe/prefixed-mockup.xml b/testsuite/probe/prefixed-mockup.xml index bd5e3df8b..cb2475292 100644 --- a/testsuite/probe/prefixed-mockup.xml +++ b/testsuite/probe/prefixed-mockup.xml @@ -747,13 +747,10 @@ - /etc/crypttab + /mnt/etc/crypttab - /etc/fstab - proc /proc proc defaults 0 0 - sysfs /sys sysfs noauto 0 0 - usbfs /proc/bus/usb usbfs noauto 0 0 + /mnt/etc/fstab /proc/mounts diff --git a/testsuite/probe/prefixed.cc b/testsuite/probe/prefixed.cc index 7e64e6792..6bbb9d643 100644 --- a/testsuite/probe/prefixed.cc +++ b/testsuite/probe/prefixed.cc @@ -20,11 +20,11 @@ BOOST_AUTO_TEST_CASE(probe) { set_logger(get_stdout_logger()); - Environment environment(true, ProbeMode::READ_MOCKUP, TargetMode::DIRECT); + Environment environment(true, ProbeMode::READ_MOCKUP, TargetMode::CHROOT); + environment.set_rootprefix("/mnt"); environment.set_mockup_filename("prefixed-mockup.xml"); Storage storage(environment); - storage.set_rootprefix("/mnt"); storage.probe(); const Devicegraph* probed = storage.get_probed(); diff --git a/utils/probe.cc b/utils/probe.cc index 7f7924d46..5aa41abf9 100644 --- a/utils/probe.cc +++ b/utils/probe.cc @@ -24,6 +24,7 @@ bool save_mockup = false; bool load_mockup = false; bool ignore_probe_errors = false; View view = View::ALL; +string rootprefix; class MyProbeCallbacks : public ProbeCallbacks @@ -60,7 +61,7 @@ doit() probe_mode = ProbeMode::READ_MOCKUP; Environment environment(true, probe_mode, TargetMode::DIRECT); - + environment.set_rootprefix(rootprefix); environment.set_mockup_filename("mockup.xml"); MyProbeCallbacks my_probe_callbacks; @@ -116,6 +117,7 @@ main(int argc, char **argv) { "load-mockup", no_argument, 0, 4 }, { "ignore-probe-errors", no_argument, 0, 5 }, { "view", required_argument, 0, 6 }, + { "rootprefix", required_argument, 0, 7 }, { 0, 0, 0, 0 } }; @@ -165,6 +167,10 @@ main(int argc, char **argv) } break; + case 7: + rootprefix = optarg; + break; + default: usage(); }