Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 2000896

Summary: thin_repair cannot rebuild broken superblock if the thin-pool has empty devices
Product: Red Hat Enterprise Linux 8 Reporter: Ming-Hung Tsai <mtsai>
Component: device-mapper-persistent-dataAssignee: Ming-Hung Tsai <mtsai>
Status: CLOSED ERRATA QA Contact: Filip Suba <fsuba>
Severity: low Docs Contact:
Priority: medium    
Version: 8.5CC: agk, heinzm, jbrassow, lmiksik, lvm-team, mcsontos, msnitzer, thornber
Target Milestone: rcKeywords: Triaged
Target Release: ---Flags: pm-rhel: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: device-mapper-persistent-data-0.9.0-5.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 2020660 (view as bug list) Environment:
Last Closed: 2022-05-10 15:21:35 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2020660    

Description Ming-Hung Tsai 2021-09-03 10:16:52 UTC
thin_repair is capable of rebuilding the thin-pool superblock if it broke. However, it doesn't work if the thin-pool has one or more empty devices. None of the devices could be recovered in this situation.


Version-Release number of selected component (if applicable):
v0.9.0-el8


Steps to Reproduce:

1. Create a thin metadata with one empty device, using thin_restore:

```shell
# dd if=/dev/zero of=src.bin bs=1M count=4
# thin_restore -i src.xml -o src.bin
```

src.xml is listed below:

```xml
<superblock uuid="" time="0" transaction="1" flags="0" version="2" data_block_size="128" nr_data_blocks="1024">
  <device dev_id="1" mapped_blocks="16" transaction="0" creation_time="0" snap_time="0">
    <range_mapping origin_begin="0" data_begin="0" length="16" time="1"/>
  </device>
  <device dev_id="2" mapped_blocks="0" transaction="0" creation_time="0" snap_time="0">
  </device>
</superblock>
```

2. Wipe the superblock 

```shell
# dd if=/dev/zero of=src.bin bs=4K count=1 conv=notrunc
```

3. Try repairing the broken metadata, using 'thin_dump --repair' or thin_repair

```shell
# thin_dump --repair --transaction-id 1 --data-block-size 128 --nr-data-blocks 1024 src.bin
```


Actual results:

None of the devices are recovered

```xml
<superblock uuid="" time="100000" transaction="1" flags="0" version="2" data_block_size="128" nr_data_blocks="1024">
</superblock>
```


Expected results:

The output should be identical to the `src.xml`

Comment 3 Ming-Hung Tsai 2021-09-03 11:40:14 UTC
Having an unwritten, empty thin-volume might not be a common case. However, the patch could avoid potential issues, and reduce the effort of customer support.

Patch has been upstreamed. The link below is the backport. Two new test cases were added accordingly.
https://github.com/mingnus/thin-provisioning-tools/commit/d3f796f5e35162b0867ee2ba8de781f14ad35c61

# autoconf
# ./configure --enable-testing
# make functional-test

thin-dump
  ...
  repair-superblock
    ...
    with-empty-devices ..................................... pass

thin-repair
  ...
  superblock
    ...
    with-empty-devices ..................................... pass

Comment 9 Filip Suba 2021-11-22 13:05:08 UTC
Verified with device-mapper-persistent-data-0.9.0-5.el8.

# thin_restore -i src.xml -o src.bin
Restoring: [==================================================]   100%
# dd if=/dev/zero of=src.bin bs=4K count=1 conv=notrunc
1+0 records in
1+0 records out
4096 bytes (4.1 kB, 4.0 KiB) copied, 3.625e-05 s, 113 MB/s
# thin_dump --repair --transaction-id 1 --data-block-size 128 --nr-data-blocks 1024 src.bin
<superblock uuid="" time="1" transaction="1" flags="0" version="2" data_block_size="128" nr_data_blocks="1024">
  <device dev_id="1" mapped_blocks="16" transaction="0" creation_time="0" snap_time="0">
    <range_mapping origin_begin="0" data_begin="0" length="16" time="1"/>
  </device>
  <device dev_id="2" mapped_blocks="0" transaction="0" creation_time="0" snap_time="0">
  </device>
</superblock>

Comment 11 errata-xmlrpc 2022-05-10 15:21:35 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (device-mapper-persistent-data bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2022:2033