NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

kern/60999: raidframe failed to use whole wedge for raid components



>Number:         60999
>Category:       kern
>Synopsis:       raidframe failed to use whole wedge for raid components
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Nov 13 16:55:00 +0000 2026
>Originator:     Wolfgang Stukenbrock
>Release:        NetBSD 10.1
>Organization:
>Environment:
NetBSD  10.1 NetBSD 10.1 (GENERIC) #3: Mon Jan 20 15:08:00 CET 2025  ncadmin@amnesia:/nsw-data/nsw/NetBSD-10.1/N+C-build/.OBJDIR_amd64/nsw-data/nsw/NetBSD-10.1/src/sys/arch/amd64/compile/GENERIC amd64

>Description:
When e.g. raid mirror as in my case is setup from wedge localted on GPT partitioned disks, the size used for the raid device is shorten by the offset of the partition on the disk.

Example:

# gpt show wd1
       start        size  index  contents
           0           1         PMBR
           1           1         Pri GPT header
           2          32         Pri GPT table
          34        2014         Unused
        2048      262144      1  GPT part - EFI System
      264192  1953524992      2  GPT part - NetBSD RAIDFrame component
  1953789184  1953239951      3  GPT part - NetBSD FFSv1/FFSv2
  3907029135          32         Sec GPT table
  3907029167           1         Sec GPT header
# dkctl wd1
strategy:
/dev/rwd1: priocscan

getcache:
/dev/rwd1: read cache enabled
/dev/rwd1: write-back cache enabled
/dev/rwd1: read cache enable is not changeable
/dev/rwd1: write cache enable is changeable
/dev/rwd1: cache parameters are not savable
/dev/rwd1: cache Force Unit Access (FUA) supported
/dev/rwd1: cache Disable Page Out (DPO) not supported

listwedges:
/dev/rwd1: 3 wedges:
dk5: wd1_UEFI, 262144 blocks at 2048, type: msdos
dk6: wd1_raid, 1953524992 blocks at 264192, type: raidframe
dk9: wd1_spare, 1953239951 blocks at 1953789184, type: ffs

# raidctl -s raid1
Components:
            /dev/dk6: optimal
           /dev/dk11: optimal
No spares.
Component label for /dev/dk6:
   Row: 0, Column: 0, Num Rows: 1, Num Columns: 2
   Version: 2, Serial Number: 16694, Mod Counter: 60
   Clean: No, Status: 0
   sectPerSU: 128, SUsPerPU: 1, SUsPerRU: 1
   Queue size: 1, blocksize: 512, numBlocks: 1953260800
   RAID Level: 1
   Autoconfig: No
   Root partition: No
   Last configured as: raid1
Component label for /dev/dk11:
   Row: 0, Column: 1, Num Rows: 1, Num Columns: 2
   Version: 2, Serial Number: 16694, Mod Counter: 60
   Clean: No, Status: 0
   sectPerSU: 128, SUsPerPU: 1, SUsPerRU: 1
   Queue size: 1, blocksize: 512, numBlocks: 1953260800
   RAID Level: 1
   Autoconfig: No
   Root partition: No
   Last configured as: raid1
Parity status: clean
Reconstruction is 100% complete.
Parity Re-write is 100% complete.
Copyback is 100% complete.
# bc
1953524992-264192
1953260800
^D#

the raid components are reported to have
numBlocks: 1953260800
but the wedge used has size 1953524992

as the bc above show, the difference is exactly the offset of this partition.

I have not tested with a small partition started at an offset larger as the partition size till now. But if the offset is subtracted in this case to we will end up with a negative number of blocks (or a very large one in case the interger is unsigned).
>How-To-Repeat:
format a disk with gpt and create a raid-partition-wedge somewhere in the middle of the disk.
(of cause two disks in similar way for the next step)
then create a raid-mirror out of the created dk devices (dk6 and dk11 in my case)

You will see that the space used inside raid-device significant shorter than the created wedges for the raid.
The difference is exactly the offset of the wedge on the disk.
>Fix:
I already looked into sources but have not found where the offset 'is subtracted' till now.

For setting up the component the following code in getdisksize() is called:

        /*
         * We attempt to get the wedge information first if it exists,
         * because the label does not support larger size disks.
         */
        error = VOP_IOCTL(vp, DIOCGWEDGEINFO, &dkw, FREAD, NOCRED);
        if (error == 0) {
                pdk = disk_find(dkw.dkw_parent);
                if (pdk != NULL) {
                        secsize = DEV_BSIZE << pdk->dk_blkshift;
                        numsec  = dkw.dkw_size;
                } else
                        error = ENODEV;
        }


The IOCTL is doing this:
        case DIOCGWEDGEINFO: {
                struct dkwedge_info *dkw = data;

                strlcpy(dkw->dkw_devname, device_xname(sc->sc_dev),
                    sizeof(dkw->dkw_devname));
                memcpy(dkw->dkw_wname, sc->sc_wname, sizeof(dkw->dkw_wname));
                dkw->dkw_wname[sizeof(dkw->dkw_wname) - 1] = '\0';
                strlcpy(dkw->dkw_parent, sc->sc_parent->dk_name,
                    sizeof(dkw->dkw_parent));
                dkw->dkw_offset = sc->sc_offset;
                dkw->dkw_size = dkwedge_size(sc);
                strlcpy(dkw->dkw_ptype, sc->sc_ptype, sizeof(dkw->dkw_ptype));

                break;
        }

and kdwedge_size() is defined like this:
static uint64_t
dkwedge_size(struct dkwedge_softc *sc)
{
        uint64_t size;

        rw_enter(&sc->sc_sizelock, RW_READER);
        size = sc->sc_size;
        rw_exit(&sc->sc_sizelock);

        return size;
}



So only values found inside wedge information are directly used.
Due to the fact that gpt show reports correct values (as setup before)
the values inside the strutures seems to be OK.

But after this raidframe does not know the offset - so cannot subtract it.

Perhaps the maintainer of raidframe has an idea where this loss of blocks can happen.
I have no time right now to instrument everything for deeper debugging - sorry.


 




Home | Main Index | Thread Index | Old Index