cloudius-systems / osv

OSv, a new operating system for the cloud.
osv.io
Other
4.1k stars 603 forks source link

"panic: duplicate device" when mixing virtio and IDE disk #801

Open justinc1 opened 8 years ago

justinc1 commented 8 years ago

Adding a second disk to OSv VM caused a panic:

panic: duplicate device
[backtrace]
0x000000000022bc39 <abort(char const*, ...)+270>
0x0000000000636a69 <sys_panic+33>
0x0000000000668117 <device_register+147>
0x00000000006682a4 <device_create+162>
0x00000000004794d3 <ide::ide_drive::ide_drive(pci::device&)+273>
0x0000000000479ad7 <ide::ide_drive::probe(hw::hw_device*)+395>
...

The libvirt domain definition was like:

  <devices>
    <emulator>/usr/bin/kvm-spice</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/scratch/.pbs_vm_jobs/57d8ba6793e339f/node0103/1-osv-usr.img'/>
      <target dev='vda' bus='virtio'/>
      <boot order='1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
    </disk>
    <disk type='file' device='disk'>
       <driver name='qemu' type='raw'/>
       <source file='/scratch/.pbs_vm_jobs/57d8ba6793e339f/node0103/1-seed.img'/>
       <target dev='hda' bus='ide'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
     </disk> 

Switching the second disk type to virtio solved the problem (and this bug report is only to make error searchable)

   <address type='pci' domain='0x0000' bus='0x00' slot='0x0a' function='0x0'/>
nyh commented 7 years ago

I'm reopening because this is a real bug (maybe not an important one but a bug, nontheless).

The not-very-verbose "duplicate device" message comes because two devices chose the name "vblk0"... The virtio-blk driver supports multiple disks and can call them vblk0, vblk1, etc. - but the ide driver independently chose the name "vblk0". So if we have both a virtio and an IDE device, we get this conflict.

By the way, we also have other drivers which use the "vblk" prefix and an independent counter, so they can also chose the name vblk0 and lead to a similar error if a combination is used.

geraldo-netto commented 6 years ago

Hello @nyh / @justinc1 ,

Do you think it's okay if we change the ide mapping from "vblk0" to "ide0" and then, change the code accordingly to read from ide0 instead of "vblk0" in case it has a ide device?

Kind Regards, Geraldo Netto

justinc1 commented 6 years ago

There are quite a few places where vblk0 is blindly used. And @nyh said, " we also have other drivers which use the "vblk" prefix". So such change might require changes of all this files, resulting in

Better then to introduce o global vblk counter, and we can incrementally change all device drivers to use it?

nyh commented 6 years ago

Indeed, we have code (e.g., mount_zfs_rootfs()) which just assumes the disk is on /dev/vblk0.1 for example. So using the same global counter, indeed makes sense. This will solve the duplicate device file problem. However, it will create a new problem: Which of the two disks will be named /dev/vblk0 and which will be /dev/vblk1? Will it always be in the same order, or just randomly change? This can be a mess. The person who originally wanted to mix virtio and IDE should probably suggest what he'd want to do in this case :-)