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.
Daniel
--
|: Red Hat, Engineering, London -o-
http://people.redhat.com/berrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org -o-
http://ovirt.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|