Uploaded image for project: 'RHEL'
  1. RHEL
  2. RHEL-123523

[RHEL10.2] ZeroDivisionError when creating LVM volume without size specification

Linking RHIVOS CVEs to...Migration: Automation ...RHELPRIO AssignedTeam ...SWIFT: POC ConversionSync from "Extern...XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Undefined Undefined
    • None
    • rhel-10.2
    • rhel-system-roles
    • None
    • None
    • None
    • rhel-system-roles
    • None
    • False
    • False
    • Hide

      None

      Show
      None
    • None
    • None
    • None
    • None
    • Unspecified
    • Unspecified
    • Unspecified
    • None

                                                                                                                                         
      When creating an LVM volume without specifying a `size` parameter (using the default value `size: 0` from `defaults/main.yml`), the blivet module crashes with a `ZeroDivisionError`.

       Root Cause

      In `library/blivet.py` line 1127, the `_trim_size()` method performs a division operation:

      ```python
      def _trim_size(self, size, parent_device):
          trim_percent = (1.0 - float(parent_device.free_space / size)) * 100
          log.debug("size: %s ; %s", size, trim_percent)
          ...
      ```

      When `size` is `0` (the default value from `defaults/main.yml` line 36), this causes a division by zero error.

       

      ```yaml
      - name: Reproduce ZeroDivisionError
        hosts: all
        become: true
        vars:
          storage_safe_mode: false
          storage_pools:
            - name: test_pool
              type: lvm
              disks:
                - sda  # Change to an unused disk on your system
              volumes:
                - name: test_volume
                  # No size specified - uses default size: 0
                  fs_type: xfs
        roles:
          - rhel-system-roles.storage
      ```
       

      patch

      ```python
      def _trim_size(self, size, parent_device):    # If size is 0, use all available free space (auto-fill)
          if size == Size(0):
              log.info("auto-fill volume '%s': using all available free space (%s)",
                       self._volume['name'], parent_device.free_space)
              return parent_device.free_space    trim_percent = (1.0 - float(parent_device.free_space / size)) * 100
          log.debug("size: %s ; %s", size, trim_percent)
          ...
      ```
       

       

      rhel-system-roles-1.110.0-0.1.el10.noarch

      python3-blivet-3.10.0-23.el10.noarch

      6.12.0-141.el10.x86_64

              rmeggins@redhat.com Richard Megginson
              guazhang@redhat.com Guangwu Zhang
              Richard Megginson Richard Megginson
              Guangwu Zhang Guangwu Zhang
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated: