6

I am writing a Linux block device driver and I have a lot of the initialisation stuff working. However, when I finally call add_disk(), the module hangs during insmod.

The offending snippet is here:

set_capacity(gendisk, dev->nsectors);
add_disk(gendisk);

//this line is never reached
Inductiveload
  • 6,094
  • 4
  • 29
  • 55

1 Answers1

6

This appears to be caused by setting the capacity with set_capacity() before adding the disk. According to this mailing list, add_disk should be called on a gendisk with gendisk->capacity = 0, otherwise it hangs in check_partition().

The following appears to work:

set_capacity(gendisk, 0)
add_disk(gendisk);
set_capacity(gendisk, dev->nsectors);
Inductiveload
  • 6,094
  • 4
  • 29
  • 55
  • This doesn't work for me. The `add_disk()` is not stuck but when I `dd` to the device, I got `No space left on device` error message. – VincentHuang May 18 '18 at 03:49