Bug 192237

Summary: Floating point error when creating partition on dm device
Product: [Fedora] Fedora Reporter: Mark McLoughlin <markmc>
Component: partedAssignee: Dave Cantrell <dcantrell>
Status: CLOSED RAWHIDE QA Contact: Brock Organ <borgan>
Severity: medium Docs Contact:
Priority: medium    
Version: rawhideCC: agk, clausen, dwysocha, mbroz, pjones
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: parted-1.7.1 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2006-09-26 06:49:02 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Mark McLoughlin 2006-05-18 15:12:16 UTC
In recent kernels, dm allows user-space to set the geometry of a device:

http://www.redhat.com/archives/dm-devel/2006-February/msg00137.html

So, by default, HDIO_GETGEO now returns zero for the geometry paramters rather
than returning -ENOTTY

This causes a divide-by-zero in linux.c:_device_probe_geometry():

  if (!ioctl (arch_specific->fd, HDIO_GETGEO, &geometry)) {
      dev->hw_geom.sectors = geometry.sectors;
      dev->hw_geom.heads = geometry.heads;
      dev->hw_geom.cylinders
            = dev->length / (dev->hw_geom.heads
                             * dev->hw_geom.sectors)
                          / (dev->sector_size / PED_SECTOR_SIZE);

Suggest either checking for zero return on these paramets and falling back to
the default values.

(Of course, you could probably also argue that dm should continue returning
-ENOTTY when the geometry hasn't been set. cc-ing agk)

To reproduce:

$> dd if=/dev/zero of=/tmp/t.img bs=1M count=0 seek=4096
0+0 records in
0+0 records out
0 bytes (0 B) copied, 7.3e-05 seconds, 0.0 kB/s
$> losetup /dev/loop0 /tmp/t.img
$> echo "0 8388608 linear /dev/loop0 0" | dmsetup create foo
$> parted /dev/mapper/foo mklabel msdos
Floating point exception

Comment 1 Alasdair Kergon 2006-09-13 18:37:09 UTC
man 4 sd says:

If the geometry information is not available, zero will be returned for all of
the parameters.


Comment 2 Dave Cantrell 2006-09-13 18:43:50 UTC
Just tried the reproducer listed above on rawhide.  I don't get the floating
point exception.

I have parted-1.7.1-15.fc6 in rawhide right now.

Can the reporter please try rawhide to verify the problem is gone (or still exists)?

Thanks.

Comment 3 Mark McLoughlin 2006-09-26 06:49:02 UTC
Right, it's fixed now:

        if (!ioctl (arch_specific->fd, HDIO_GETGEO, &geometry)
                        && geometry.sectors && geometry.heads) {