Skip to content

Update LVM2Device sizes if the LVM2Device size is smaller than the PhysicalVolume size#61

Open
Miauwkeru wants to merge 12 commits intomainfrom
update-device-sizes
Open

Update LVM2Device sizes if the LVM2Device size is smaller than the PhysicalVolume size#61
Miauwkeru wants to merge 12 commits intomainfrom
update-device-sizes

Conversation

@Miauwkeru
Copy link
Copy Markdown
Contributor

@Miauwkeru Miauwkeru commented Mar 2, 2026

This seems to be the cause of fox-it/dissect#93
Where it, assumedly, tried to read beyond the LVM2Device disk size where it could not reach.

TODO

  • Generate test data that displays this behaviour
  • Create a test to show this behaviour is fixed

@Miauwkeru
Copy link
Copy Markdown
Contributor Author

@tuttimann I did find a issue in our lvm implementation, I believe this is also the issue you came accross in fox-it/dissect#93

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 2, 2026

Codecov Report

❌ Patch coverage is 95.45455% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 77.88%. Comparing base (59aff76) to head (d2c7a54).

Files with missing lines Patch % Lines
dissect/volume/lvm/metadata.py 94.44% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #61      +/-   ##
==========================================
+ Coverage   77.67%   77.88%   +0.20%     
==========================================
  Files          29       29              
  Lines        2343     2360      +17     
==========================================
+ Hits         1820     1838      +18     
+ Misses        523      522       -1     
Flag Coverage Δ
unittests 77.88% <95.45%> (+0.20%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Miauwkeru Miauwkeru requested a review from Schamper March 4, 2026 13:47
@Miauwkeru Miauwkeru requested review from twiggler March 12, 2026 09:28
twiggler
twiggler previously approved these changes Mar 30, 2026
Miauwkeru and others added 7 commits March 30, 2026 10:31
It takes the pv size of the PhysicalVolume and uses it when opening the
device
the size of the LVM2Device has been manually changed.
While the test functions as intended, you can't use a loopback device to
mount the file itself
Co-authored-by: twiggler <12800443+twiggler@users.noreply.github.com>
@Miauwkeru Miauwkeru force-pushed the update-device-sizes branch from 72f2bd1 to 0301a81 Compare March 30, 2026 08:31
@Miauwkeru Miauwkeru requested a review from Schamper March 30, 2026 09:29
@Miauwkeru Miauwkeru requested a review from Schamper April 1, 2026 08:54

size = max(stream.size, self.size)
runlist = [
(area.offset // SECTOR_SIZE, (area.size or size) // SECTOR_SIZE) for area in self.dev._data_area_descriptors
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This (area.size or size) is bothering me. I know it's also in the original open of LVM2Device, and I know I'm the one who put it there, but I don't understand why this logic is this way? Is this in the case there's only one data area that does not have a size specified?

I assume you have the internals of LVM2 better in your head right now than I do, could you comment on this?

Copy link
Copy Markdown
Contributor Author

@Miauwkeru Miauwkeru Apr 2, 2026

Choose a reason for hiding this comment

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

I looked a bit into it to be sure.
Seems a pv currently only supports one data area per pv, according to the lvm2 code.
This size is always put on 0.

There is also more evidence in the documentation / code of lvm2 that it only populates one data area, and always puts the size to 0 in the pvck. (https://gitlab.com/lvmteam/lvm2/-/blob/main/tools/pvck.c?ref_type=heads#L2425)

Before my the research it, I thought it could be 0 if and only if there was just one data area available. Where the 0 denoted the whole size of the disk. Which was also the assumption here I believe.

I do have a feeling that once multiple data areas are allowed in the PV, the 0 means that it should be as large as the remaining size. So in that case the current code would be wrong. But that is just speculation on my part

We can add a comment to it why it is like this. Or just use size for now and add other logic later once they use more data area sections. Ofc, with the later option also having a comment about the why.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe raise an error if there's more than one data area, and remove the list comprehension?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

that's fine, I'll make a patch for it

@Miauwkeru Miauwkeru requested a review from Schamper April 2, 2026 13:10
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you structure this file similarly to how it's done in fox-it/dissect.evidence#42?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As in directory structure or file structure. A "yes" would be valid for both

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants