Curious code in autostart_array
Hi, guys:
My copy of 2.6.17-rc5 has the following code in autostart_array():
mdp_disk_t *desc = sb->disks + i; dev_t dev = MKDEV(desc->major, desc->minor); if (!dev) continue; if (dev == startdev) continue; if (MAJOR(dev) != desc->major || MINOR(dev) != desc->minor) continue;
Under what conditions do you think the last if() statement can fire? What is its purpose? This looks like an attempt to detect bit clipping. But what exactly?
Cheers,
-- Pete
Quoted 13 lines · Pete Zaitcev
Hi, guys:
My copy of 2.6.17-rc5 has the following code in
autostart_array():mdp_disk_t *desc = sb->disks + i; dev_t dev = MKDEV(desc->major, desc->minor); if (!dev) continue; if (dev == startdev) continue; if (MAJOR(dev) != desc->major || MINOR(dev) != desc->minor) continue;
Quoted 4 lines
Under what conditions do you think the last
if()statement can fire? What is its purpose? This looks like an attempt to detect bit clipping. But what exactly?
It can fire if either desc->major or desc->minor overflow the respective fields in dev_t. Unfortunately, it's not guaranteed to do so.
-hpa
Quoted 13 lines · On Thursday June 22, [email protected] wrote:
Hi, guys:
My copy of 2.6.17-rc5 has the following code in
autostart_array():mdp_disk_t *desc = sb->disks + i; dev_t dev = MKDEV(desc->major, desc->minor); if (!dev) continue; if (dev == startdev) continue; if (MAJOR(dev) != desc->major || MINOR(dev) != desc->minor) continue;
Quoted 3 lines
Under what conditions do you think the last
if()statement can fire? What is its purpose? This looks like an attempt to detect bit clipping. But what exactly?
First, be aware that this code (which is only available from the START_ARRAY ioctl) is scheduled to be removed from the kernel next month.
Second, the code substantially predates my involvement in md, but I suspect it is simple caution. desc->major and desc->minor have been read of the disk, so their values cannot be trusted.
They are both 32 bit and so could easily not be valid major/minor numbers. The test slightly reduces the number of silly thing that can go wrong if the data is bad (though the fact that the superblock is checksumed makes that fairly unlikely).
(or to put it another way: I don't know either :-)
NeilBrown
Quoted 6 lines · Neil Brown
Quoted 3 lines
dev_t dev = MKDEV(desc->major, desc->minor); if (MAJOR(dev) != desc->major || MINOR(dev) != desc->minor) continue;
desc->majoranddesc->minorhave been
read of the disk, so their values cannot be trusted.
Oh, right. Sorry.
-- Pete