Public bug reported:

We discovered an issue when trying to create imsm container with mdadm
on dm-device.

Environment:
OS: Ubuntu 24.04
Kernel: inbox 6.6.0

Scenario:

1. Create dm device
# echo -e '0 195312 linear /dev/nvme2n1 0' | dmsetup create nvme2n1DM

2. Create IMSM container.
# dmdev=$(readlink -f /dev/mapper/nvme2n1DM)
# export IMSM_DEVNAME_AS_SERIAL=1 IMSM_NO_PLATFORM=1; mdadm --create 
/dev/md/container --metadata=imsm --raid-disks=1 $dmdev --force

Expected result:
Container is created.

Actual result:

Error message is displayed
# mdadm: imsm: /dev/dm-0 is a partition, cannot be used in IMSM
Container is not created.

Additional info:

Mdadm uses ioctl call underneath to check if device is a partition.
Here's the function:

int test_partition(int fd)
{
     /* Check if fd is a whole-disk or a partition.
      * BLKPG will return EINVAL on a partition, and BLKPG_DEL_PARTITION
      * will return ENXIO on an invalid partition number.
      */
     struct blkpg_ioctl_arg a;
     struct blkpg_partition p;
     a.op = BLKPG_DEL_PARTITION;
     a.data = (void*)&p;
     a.datalen = sizeof(p);
     a.flags = 0;
     memset(a.data, 0, a.datalen);
     p.pno = 1<<30;
     if (ioctl(fd, BLKPG, &a) == 0)
         /* Very unlikely, but not a partition */
         return 0;
     if (errno == ENXIO || errno == ENOTTY)
         /* not a partition */
         return 0;

     return 1;
}

We established that the behavior is caused by regression in ioctl.
Thread: 
https://lore.kernel.org/all/caoyef9vsmqkmcqjo1k6ykgnujwn-nzfxy17n3f-cmike1ty...@mail.gmail.com/
Fix: 
https://lore.kernel.org/all/[email protected]/

We established that ioctl call on dm-device returns EINVAL as if it was a 
partition.
Note that this function was was working unchanged for last 10+years and the 
issue was fixed in newer kenel.

** Affects: ubuntu
     Importance: Undecided
         Status: New


** Tags: vroc

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2059092

Title:
  [VROC] mdadm detects dm-device as partition

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+bug/2059092/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to