Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- handle rootprefix when reading fstab, crypttab and mdadm.conf #884

Merged
merged 1 commit into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LIBVERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.76.0
1.77.0
7 changes: 4 additions & 3 deletions storage/ActiongraphImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<EtcFstab>(filename);
}
Expand All @@ -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<EtcCrypttab>(filename);
}
Expand All @@ -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<EtcMdadm>(filename);
}
Expand Down Expand Up @@ -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);

Expand Down
17 changes: 9 additions & 8 deletions storage/Devices/BitlockerV2Impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand All @@ -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;
}

Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();

/*
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions storage/Devices/BitlockerV2Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions storage/Devices/EncryptionImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions storage/Devices/EncryptionImpl.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) [2016-2021] SUSE LLC
* Copyright (c) [2016-2022] SUSE LLC
*
* All Rights Reserved.
*
Expand Down Expand Up @@ -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;

Expand Down
18 changes: 10 additions & 8 deletions storage/Devices/LuksImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand All @@ -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;
}

Expand Down Expand Up @@ -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");

Expand All @@ -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;
}
Expand Down Expand Up @@ -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();

/*
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions storage/Devices/LuksImpl.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) [2016-2021] SUSE LLC
* Copyright (c) [2016-2022] SUSE LLC
*
* All Rights Reserved.
*
Expand Down Expand Up @@ -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();

Expand Down
11 changes: 7 additions & 4 deletions storage/Devices/MdImpl.cc
Original file line number Diff line number Diff line change
@@ -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.
*
Expand Down Expand Up @@ -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);
}

Expand Down
6 changes: 4 additions & 2 deletions storage/Devices/PlainEncryptionImpl.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019 SUSE LLC
* Copyright (c) [2019-2022] SUSE LLC
*
* All Rights Reserved.
*
Expand Down Expand Up @@ -30,6 +30,7 @@
#include "storage/EtcCrypttab.h"
#include "storage/Prober.h"
#include "storage/Utils/Format.h"
#include "storage/Storage.h"


namespace storage
Expand Down Expand Up @@ -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();

/*
Expand Down
16 changes: 15 additions & 1 deletion storage/Environment.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) [2014-2015] Novell, Inc.
* Copyright (c) 2020 SUSE LLC
* Copyright (c) [2020-2022] SUSE LLC
*
* All Rights Reserved.
*
Expand Down Expand Up @@ -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
{
Expand Down
21 changes: 21 additions & 0 deletions storage/Environment.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) [2014-2015] Novell, Inc.
* Copyright (c) 2022 SUSE LLC
*
* All Rights Reserved.
*
Expand Down Expand Up @@ -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);

Expand Down
10 changes: 9 additions & 1 deletion storage/EnvironmentImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}


Expand Down
4 changes: 4 additions & 0 deletions storage/EnvironmentImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
Expand Down
Loading