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

filesystem: store the actual size in bytes alongside the human readable size #1759

Merged
merged 1 commit into from
Aug 9, 2023

Conversation

ogayot
Copy link
Member

@ogayot ogayot commented Aug 9, 2023

Currently, the partition form stores the size as a human readable value (e.g., 123456K, 1.1G, 1.876G, 100G). When we exit the size field (i.e., upon losing focus), we convert the value to a number of bytes and then align it up to the nearest MiB (or whatever the alignment requirement is).

Unfortunately, after computing the aligned value, we turn it back into a human-readable string and store it as is. It is not okay because the conversion does not ensure that the alignment requirement is still honored.

For instance, if the user types in 1.1G, we do the following:

  • convert it to a number of bytes -> 1181116006.4 (surprise, it is not even an integer).
  • round it up to the nearest MiB -> 1181745152 (this is the correct value)
  • transform it into a human readable string and store it as is -> 1.1G - which actually corresponds to the original value.

This leads to an exception later when creating the partition:

        File "subiquity/models/filesystem.py", line 1841, in add_partition
          raise Exception(
       Exception: ('size %s or offset %s not aligned to %s', 1181116006, 1048576, 1048576)

Fixed by storing the actual size as a number of bytes - alongside the human readable size.

https://bugs.launchpad.net/subiquity/+bug/2013201

@ogayot ogayot force-pushed the fix-manual-size branch 5 times, most recently from 5b4b1b1 to 9f0bade Compare August 9, 2023 12:22
…le size

Currently, the partition form stores the size as a human readable value.
(e.g., 123456K, 1.1G, 1.876G, 100G). When we exit the size field (i.e., upon
losing focus), we convert the value to a number of bytes and then align
it up to the nearest MiB (or whatever the alignment requirement is).

Unfortunately, after computing the aligned value, we turn it back into a
human-readable string and store it as is. It is not okay because the
conversion does not ensure that the alignment requirement is still
honored.

For instance, if the user types in 1.1G, we do the following:

 * convert it to a number of bytes -> 1181116006.4 (surprise, it is not
   even an integer).

 * round it up to the nearest MiB -> 1181745152 (this is the correct
   value)

 * transform it into a human readable string and store it as is -> 1.1G
   - which actually corresponds to the original value.

This leads to an exception later when creating the partition:

    File "subiquity/models/filesystem.py", line 1841, in add_partition
      raise Exception(
   Exception: ('size %s or offset %s not aligned to %s', 1181116006, 1048576, 1048576)

Fixed by storing the actual size as a number of bytes - alongside the
human readable size.

Signed-off-by: Olivier Gayot <[email protected]>
@ogayot ogayot merged commit fdbcd40 into canonical:main Aug 9, 2023
10 checks passed
@ogayot ogayot deleted the fix-manual-size branch August 9, 2023 15:27
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