
Daniel P. Berrange wrote:
On Mon, Aug 25, 2008 at 01:41:24PM -0400, Cole Robinson wrote:
+ + int idx = virDiskNameToIndex(newdisk->dst); + switch (newdisk->bus) { + /* Assume that if we are here, device targets don't exceed hypervisor + * limits, and we are already an appropriate device type */ + case VIR_DOMAIN_DISK_BUS_IDE: + /* Device name of the form 'ide{0-1}-cd{0-1}' */ + ret = asprintf(&devname, "ide%d-cd%d", ((idx - (idx % 2)) / 2), + (idx % 2)); + break; + case VIR_DOMAIN_DISK_BUS_SCSI: + /* Device name of the form 'scsi{bus#}-cd{0-6} + * Each bus holds seven devs */ + ret = asprintf(&devname, "scsi%d-cd%d", ((idx - (idx % 7)) / 7), + (idx % 7)); + break; + case VIR_DOMAIN_DISK_BUS_FDC: + /* Device name is 'floppy{0-1}' */ + ret = asprintf(&devname, "floppy%d", idx); + break; + + default: + qemudReportError(dom->conn, dom, NULL, VIR_ERR_NO_SUPPORT, + _("Cannot hotplug device with bus '%s'"), + virDomainDiskBusTypeToString(newdisk->bus)); + return -1; + }
I think this block could be re-factored a little into one or more helper methods, because I think we'll need to re-use this for hot-unplug of disks. I'd suggest a helper to turn the plain integer index into the (bus,device) index pair
virDiskNameToBusDeviceIndex(virDomainDiskDefPtr disk, int *busIdx, int *devIdx);
And then a QEMU specific function
char *virQEMUDeviceName(virDomainDiskDefPtr disk);
and have this call virDiskNameToBusDeviceIndex() and return the 'ide1-2' type string.
Okay, second cut attached. I followed your recommendations: virDiskNameToBusDeviceIndex added to domain_conf.c qemudDiskDeviceName added to qemu_driver.c I also hopefully solved the back compatibility issue. Seems -drive was added to qemu in Dec 07 (qemu commit 3759) and the device naming scheme was updated at the end of that month (qemu commit 3846), so checking for -drive should be a sufficient indicator that we need to use the new device name format. So if drive was detected (using the already present qemu_conf flag), we revert to the old style cdrom/fda naming style. I tested this on f8 using plain qemu (which lacks the -drive option) and it appeared to work as expected for cdrom and floppy devices. Thanks, Cole