joyent/smartos-live — Issue #65: Allow raw disks (or other GZ devices) to be used by guests
Author: trisk
Created: 2012-02-26 16:02:12+00:00
State: open

I have existing pools which I want to be managed by KVM guests running illumos and NexentaStor. On the older vmadmd in smartos-live 201109xx, I was able to add the physical disks by overloading the 'model' net-attr for devices.

For example, I have a
```xml

```
Corresponding to 'qemu-extra-opts' contents "-device ahci,id=ahci0,bus=pci.0,multifunction=on -device ide-drive,drive=sata0-disk0,bus=ahci0.0".

This was converted into qemu arguments:
"-drive file=/dev/rdsk/c2t514d0,if=none,id=sata-disk0,index=1,media=disk"

The current vmadmd does this instead:
"-drive file=/dev/rdsk/c2t514d0,if=undefined,index=1,media=disk"

startElement in VM.js assumes _all_ device elements are disks but only uses the net-attr child attributes for devices with paths matching "/dev\/.*disk[0-9]+" when setting properties. It tries to use direct attributes for the device element as well but I don't think any are allowed by the zonecfg DTD. This results in "undefined" for the 'model' property for any devices not matching "/dev\/.*disk[0-9]+".

```javascript
} else if (where === 'zone.device') {
// new disk device
for (prop in attrs) {
if (XML_PROPERTIES.disk.hasOwnProperty(prop)) {
use = XML_PROPERTIES.disk[prop];
disk[use] = attrs[prop];
} else {
VM.log('DEBUG', 'unknown disk prop: ' + prop);
}
}
if (!obj.hasOwnProperty('devices')) {
obj.devices = {};
}
obj.devices[disk.path] = disk;
stack.push(disk.path);
} else if (where.match(/zone\.device\.\/dev\/.*disk[0-9]+\.net-attr/)) {
if (XML_PROPERTIES.disk.hasOwnProperty(attrs.name)) {
use = XML_PROPERTIES.disk[attrs.name];
obj.devices[stack[2]][use] = attrs.value;
} else {
VM.log('DEBUG', 'unknown disk prop: ' + attrs.name);
}
}
```

One alternative might be for vmadmd to ignore device elements without a 'model' net-attr, so invalid "-drive" arguments are not passed to qemu. This would also allow non-disk devices (audio, etc.) to be passed through.

This would leave "-drive" to be manually specified in the 'qemu-extra-opts' attr. A helpful addition might be to keep constructing "-drive" for devices with another net-attr, whose value is passed directly to qemu (as 'model' was previously).

This is obviously not a complete solution for external devices but would make my life a lot easier.