Skip to content

BCF-6552: [REAR] REAR tries to map the disk that has been commented in the disklayout.conf file on the source machine#83

Open
Barys Barysenka (BarysBarysenka) wants to merge 3 commits intodevelopfrom
feature/BCF-6552-rear-disk-mapping-during-recovery
Open

BCF-6552: [REAR] REAR tries to map the disk that has been commented in the disklayout.conf file on the source machine#83
Barys Barysenka (BarysBarysenka) wants to merge 3 commits intodevelopfrom
feature/BCF-6552-rear-disk-mapping-during-recovery

Conversation

@BarysBarysenka

prevent failure when mapping excluded disks in df.txt

Copilot AI review requested due to automatic review settings March 10, 2026 09:35
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adjusts ReaR’s migration-mode layout mapping step to avoid aborting recovery when df.txt contains references to disks that were excluded/commented out in the source layout, while keeping strict failures for core layout/config files.

Changes:

  • Treat failures applying layout mappings to $VAR_DIR/layout/config/df.txt as a warning (do not fail the overall mapping step).
  • Keep hard-failure behavior for disklayout.conf ($LAYOUT_FILE) and /etc/rear/rescue.conf.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

LogPrintError "Failed to apply disk layout mappings to $file_to_migrate"
applied_mappings_to_all_files="no"
if [ "$file_to_migrate" = "$original_disk_space_usage_file" ] ; then
LogPrint "Warning: Failed to apply disk layout mappings to $file_to_migrate (likely due to unmapped excluded disks)."
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The codebase consistently prefixes warning-level user messages with "WARNING:" (often using LogPrint), but this message uses "Warning:". Consider changing it to match existing wording/format (e.g., "WARNING: Failed …"), to keep log scanning/grep behavior consistent.

Suggested change
LogPrint "Warning: Failed to apply disk layout mappings to $file_to_migrate (likely due to unmapped excluded disks)."
LogPrint "WARNING: Failed to apply disk layout mappings to $file_to_migrate (likely due to unmapped excluded disks)."

Copilot uses AI. Check for mistakes.
LogPrintError "Failed to apply disk layout mappings to $file_to_migrate"
applied_mappings_to_all_files="no"
if [ "$file_to_migrate" = "$original_disk_space_usage_file" ] ; then
LogPrint "Warning: Failed to apply disk layout mappings to $file_to_migrate (likely due to unmapped excluded disks)."
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning text asserts a specific root cause ("likely due to unmapped excluded disks"), but this isn't actually checked here and could mislead troubleshooting if apply_layout_mappings failed for another reason. Consider rephrasing to a more factual message (e.g., that failure is being ignored for df.txt because it may include excluded devices).

Suggested change
LogPrint "Warning: Failed to apply disk layout mappings to $file_to_migrate (likely due to unmapped excluded disks)."
LogPrint "Warning: Failed to apply disk layout mappings to $file_to_migrate; continuing without mappings for this file (it may include excluded devices)."

Copilot uses AI. Check for mistakes.
@svlv
Copy link

original_disk_space_usage_file is used in 420_autoresize_last_partitions.sh to calculate last_part_used_bytes.

It means that disk layout mapping must be applied to original_disk_space_usage_file at least to check the original disk space usage when it is necessary.

What does original_disk_space_usage_file contain in case of error?

E.g. the original system has /dev/sda which is not used and /dev/sdb which is used, next, during recovery /dev/sdb is mapped to /dev/sda; what will original_disk_space_usage_file look like after failure? Will it contain two entries for /dev/sda?

@svlv
Copy link

The issue is related to AUTOEXCLUDE_PATH and df.txt: auto-excluded disks are commented out in disklayout.conf but are not commented out in df.txt

Steps to reproduce:

  1. Use, e.g., /tmp/disk1 as mount point (/tmp is in AUTOEXCLUDE_PATH; please note, that /mnt is not in AUTOEXCLUDE_PATH in Cove by default):
    mkfs.ext4 /dev/sda; mkdir /tmp/disk1; mount /dev/sda /tmp/disk1;
  2. Do backup and check the df.txt file:
    E.g., on my test machine running RHEL 10, df.txt contains the following lines:
Filesystem            1048576-blocks   Used Available Capacity Mounted on
/dev/mapper/rhel-root         25956M 10324M    15633M      40% /
efivarfs                          1M     1M        1M      23% /sys/firmware/efi/efivars
/dev/sdb2                       960M   580M      381M      61% /boot
/dev/sdb1                       599M     9M      591M       2% /boot/efi
/dev/sda                        974M     1M      907M       1% /tmp/disk2

Note, /dev/sda is not commented out.
However, in disklayout.conf /dev/sda and fs on /dev/sda are commented out:

...
#disk /dev/sda 1073741824 loop
...
#fs /dev/sda /tmp/disk2 ext4 uuid=2dfab626-638a-42c6-bf60-c3cab3368ff4 label= blocksize=4096 reserved_blocks=4% max_mounts=-1 check_interval=0d bytes_per_inode=16384 default_mount_options=user_xattr,acl options=rw,relatime,seclabel
  1. Do migration
    The error is:
Failed to apply layout mappings to /tmp/rear/var/lib/rear/layout/config/df.txt for /dev/sda (probably no mapping for /dev/sda in /tmp/rear/var/lib/rear/layout/disk_mappings)
Failed to apply disk layout mappings to /tmp/rear/var/lib/rear/layout/config/df.txt

df.txt contains the following lines:

Filesystem            1048576-blocks   Used Available Capacity Mounted on
/dev/mapper/rhel-root         25956M 10324M    15633M      40% /
efivarfs                          1M     1M        1M      23% /sys/firmware/efi/efivars
/dev/sda2                       960M   580M      381M      61% /boot
/dev/sda1                       599M     9M      591M       2% /boot/efi
_REAR1_                        974M     1M      907M       1% /tmp/disk2

Likely 320_autoexclude.sh which is responsible for auto-exclude must respect and comment out information df.txt as it is done for LAYOUT_FILE .

@BarysBarysenka Barys Barysenka (BarysBarysenka) force-pushed the feature/BCF-6552-rear-disk-mapping-during-recovery branch from 4eb5952 to a0bc56a Compare March 13, 2026 07:15
Comment on lines +20 to +25
if [ "$file_to_migrate" = "$original_disk_space_usage_file" ] ; then
LogPrint "WARNING: Failed to apply disk layout mappings to $file_to_migrate (likely due to unmapped excluded disks)."
else
LogPrintError "Failed to apply disk layout mappings to $file_to_migrate"
applied_mappings_to_all_files="no"
fi

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this change?

Copy link

@svlv Andrus Suvalau (svlv) Mar 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The answer was - yes, we need it for backup sessions done earlier (without the fix in the PR).

@BarysBarysenka Barys Barysenka (BarysBarysenka) force-pushed the feature/BCF-6552-rear-disk-mapping-during-recovery branch from a0bc56a to 1130ac6 Compare March 13, 2026 08:58
BCF-6552: [REAR] REAR tries to map the disk that has been commented in the disklayout.conf file on the source machine
@BarysBarysenka Barys Barysenka (BarysBarysenka) force-pushed the feature/BCF-6552-rear-disk-mapping-during-recovery branch from 1130ac6 to 742f4f1 Compare March 13, 2026 09:30
BCF-6552: [REAR] REAR tries to map the disk that has been commented in the disklayout.conf file on the source machine
DebugPrint "Automatically excluding $mountpoint from $original_disk_space_usage_file (belongs to $exclude in AUTOEXCLUDE_PATH)"
local mp_pattern
# Escape the mountpoint for use in the subsequent sed command
mp_pattern=$( echo "$mountpoint" | sed 's/[]\/$*.^[],]/\\&/g' )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a broken sed expression.

You are using sed s/search/replace/flags form here.

[] in the search part is the bracket expression, see Classes and Bracket Expressions.

If you want to use it correctly, you need to use [][\/$*.^,] in the search part.
See How do i replace [] brackets using SED for more detail.

Suggested change
mp_pattern=$( echo "$mountpoint" | sed 's/[]\/$*.^[],]/\\&/g' )
mp_pattern=$( echo "$mountpoint" | sed 's/[][\/$*.^,]/\\&/g' )

* fix sed regexpr

BCF-6552: [REAR] REAR tries to map the disk that has been commented in the disklayout.conf file on the source machine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants