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

storage: fix use of ptable parameter when calling reformat #2155

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ogayot
Copy link
Member

@ogayot ogayot commented Jan 30, 2025

When reformatting a disk using the following call:

manipulator.reformat(disk, ptable="something")

The ptable parameter would only appear to be honored if the disk did not contain any partition. This happened because the reformat() function sets the ptable of the disk first and then starts removing partitions using delete_partition() in a loop.

However, delete_partition() has a mechanism to reset the partition table to None when it is invoked on the last partition of a disk.

Therefore, the disk ended up with None as the partition table (ignoring the ptable value) if the disk contained any partition.

Fixed by moving the assignment of disk.ptable after removing partitions. Arguably, it is a mistake to change the partition table value before removing the partitions anyway.

When reformatting a disk using the following call:

  > manipulator.reformat(disk, ptable="something")

The ptable parameter would only appear to be honored if the disk did not
contain any partition. This happened because the reformat() function sets the
ptable of the disk first and then starts removing partitions using
delete_partition() in a loop.

However, delete_partition() has a mechanism to reset the partition table to
None when it is invoked on the last partition of a disk.

Therefore, the disk ended up with None as the partition table (ignoring the
ptable value) if the disk contained any partition.

Fixed by moving the assignment of disk.ptable after removing partitions.
Arguably, it is a mistake to change the partition table value before removing
the partitions anyway.

Signed-off-by: Olivier Gayot <[email protected]>
@@ -270,10 +270,10 @@ def clear(self, obj, wipe=None):

def reformat(self, disk, ptable=None, wipe=None):
Copy link
Member Author

@ogayot ogayot Jan 30, 2025

Choose a reason for hiding this comment

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

Note that using the default value for ptable will still have a different behavior on disks that have partitions vs on disks that have no partition.

For disks with partitions, disk.ptable will be reset to None (because model.remove_partition will do that)
For disks without partition, disk.ptable will be left untouched.

This feels inconsistent.

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.

2 participants