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

Allow image size specification using any SI or IEC unit #310

Merged
merged 1 commit into from
Aug 21, 2024

Commits on Jan 29, 2024

  1. Allow image size specification using any SI or IEC unit

    Currently, oz only allows image sizes to be specified as integer
    amounts of gibibytes or tebibytes (that's IEC power-of-two units).
    This is unfortunately inflexible. Consider that storage media are
    typically specified in SI power-of-ten sizes, so a USB stick may
    be 16 gigabytes (SI power-of-ten GB) in size - that's
    16,000,000,000 bytes. Let's say we want to build an image that
    will fit on such a USB stick. oz will only allow us to build an
    image of 15,032,385,536 bytes (14 gibibytes) or 16,106,127,360
    bytes (15 gibibytes). So we're either slightly too big, or leaving
    nearly a gigabyte on the table.
    
    This allows the image size to be specified in the TDL with most
    any IEC or SI unit suffix, from B (bytes) all the way up to YiB
    (yobibytes). A size with no suffix or the suffix "G" is taken as
    gibibytes and a size with the suffix "T" is taken as tebibytes,
    as before, but other ambiguous suffixes are not accepted. All
    casing is accepted. Behind the scenes, we convert the size to
    bytes and specify it that way in the libvirt XML when creating
    the image in _internal_generate_diskimage.
    
    This does change the interface of generate_diskimage(), by making
    the unit for the size argument bytes instead of gibibytes. I can't
    see a clean way to avoid this while allowing flexibility. I have
    checked, and AFAICT, among active projects, only oz itself and
    the ImageFactory TinMan plugin call this function. The TinMan
    plugin will need a trivial change to its fallback default value.
    
    Signed-off-by: Adam Williamson <[email protected]>
    AdamWill committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    b609f75 View commit details
    Browse the repository at this point in the history