Re: [libvirt] Re: [Libvir] [PATCH] Add bus attribute to disk target definition
On Tue, May 06, 2008 at 10:02:21PM +0100, Daniel P. Berrange wrote: sorry for the delay. Here's the newest version of the patch which should address all the issues that have been raised so far. Yes no. It didn't address the redundant re-ordering of -drive parameters when using boot=on, The reasoning here was (I mentioned this in a previous mail, too) that when qemu/kvm some day grows the ability to have more than one boot device specified with boot=on (using extboot or whatever), we're going to have to change things *anyway*. Ordering the devices according to boot priority seems like a reasonable guess as to what would be required to do, so I figured I'd leave it as is. nor re-add the -boot param to make PXE work again. Yes and no. In the latest patch I provided I only set use_extboot if there's only one boot device defined, and it's a virtio device, so PXE booting would use the old-style -boot n syntax. I literallly woke up this morning and instantly smacked my forehead due to another problem this introduced, so I'm happy you changed it. :) One further complication is that QEMU 0.9.1 has -drive support but not the extboot support, so boot=on can't be used there. It rather annoyingly complains qemu: unknowm parameter 'boot' in 'file=/home/berrange/boot.iso,media=cdrom,boot=on' Ah, figures. +if (!bus) +disk-bus = QEMUD_DISK_BUS_IDE; This was giving floppy disks a bus of 'ide' which isn't technically correct - they're really their own bus type - I reckon we should call it 'fdc'. Ah. Yes, I must admit that floppy disks were completely off my radar. This double loop is redundant - there's no need to pull bootable drives to the front of the list - this is why there's an explicit flag rather than relying on ordering. I did this for two reasons: a) I wanted to avoid the bootDisk, bootFloppy, bootCD variables approach you used. It just didn't appeal to me. *shrug* b) As I mentioned further up, this was also done in an attempt to match what would be needed when it becomes possible to specify ,boot=on for more than one device, but we can revisit this when that day comes. Your patch looks fine to me. Oh, and thanks for doing all the test cases as well. I didn't want to get started on those until we had agreed on the logic that should be applied. -- Soren Hansen | Virtualisation specialist | Ubuntu Server Team Canonical Ltd. | http://www.ubuntu.com/ signature.asc Description: Digital signature -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] Re: [Libvir] [PATCH] Add bus attribute to disk target definition
On Wed, May 07, 2008 at 09:38:26AM +0200, Soren Hansen wrote: Yes and no. In the latest patch I provided I only set use_extboot if there's only one boot device defined, and it's a virtio device, so PXE booting would use the old-style -boot n syntax. I literallly woke up this morning and instantly smacked my forehead due to another problem this introduced, so I'm happy you changed it. :) The thing is that you can specify multiple boot devices in the XML to set a priority, eg boot dev=network/ boot dev=hd/ Gets maps to '--boot nc' so in this scenario you'd have a virtio device being bootable, and also have PXE enabled. Oh, and thanks for doing all the test cases as well. I didn't want to get started on those until we had agreed on the logic that should be applied. FWIW, I always start with the test cases first defining the XML and QEMU args, and then write the impl until the test cases pass. Dan. -- |: Red Hat, Engineering, Boston -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 :| -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [Libvir] [PATCH] Add bus attribute to disk target definition
Hi, sorry for the delay. Here's the newest version of the patch which should address all the issues that have been raised so far. === modified file 'src/qemu_conf.c' --- old/src/qemu_conf.c 2008-04-30 12:30:55 + +++ new/src/qemu_conf.c 2008-05-06 17:58:44 + @@ -491,6 +491,8 @@ *flags |= QEMUD_CMD_FLAG_KQEMU; if (strstr(help, -no-reboot)) *flags |= QEMUD_CMD_FLAG_NO_REBOOT; +if (strstr(help, \n-drive)) +*flags |= QEMUD_CMD_FLAG_DRIVE_OPT; if (*version = 9000) *flags |= QEMUD_CMD_FLAG_VNC_COLON; ret = 0; @@ -568,6 +570,7 @@ xmlChar *source = NULL; xmlChar *target = NULL; xmlChar *type = NULL; +xmlChar *bus = NULL; int typ = 0; type = xmlGetProp(node, BAD_CAST type); @@ -598,6 +601,7 @@ } else if ((target == NULL) (xmlStrEqual(cur-name, BAD_CAST target))) { target = xmlGetProp(cur, BAD_CAST dev); +bus = xmlGetProp(cur, BAD_CAST bus); } else if (xmlStrEqual(cur-name, BAD_CAST readonly)) { disk-readonly = 1; } @@ -643,10 +647,9 @@ disk-readonly = 1; if ((!device || !strcmp((const char *)device, disk)) -strcmp((const char *)target, hda) -strcmp((const char *)target, hdb) -strcmp((const char *)target, hdc) -strcmp((const char *)target, hdd)) { +strncmp((const char *)target, hd, 2) +strncmp((const char *)target, sd, 2) +strncmp((const char *)target, vd, 2)) { qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, _(Invalid harddisk device name: %s), target); goto error; @@ -673,13 +676,28 @@ goto error; } +if (!bus) +disk-bus = QEMUD_DISK_BUS_IDE; +else if (STREQ((const char *)bus, ide)) +disk-bus = QEMUD_DISK_BUS_IDE; +else if (STREQ((const char *)bus, scsi)) +disk-bus = QEMUD_DISK_BUS_SCSI; +else if (STREQ((const char *)bus, virtio)) +disk-bus = QEMUD_DISK_BUS_VIRTIO; +else { +qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, _(Invalid bus type: %s), bus); +goto error; +} + xmlFree(device); xmlFree(target); xmlFree(source); +xmlFree(bus); return 0; error: +xmlFree(bus); xmlFree(type); xmlFree(target); xmlFree(source); @@ -1373,6 +1391,68 @@ return -1; } +static int qemudDiskCompare(const void *aptr, const void *bptr) { +struct qemud_vm_disk_def *a = (struct qemud_vm_disk_def *) aptr; +struct qemud_vm_disk_def *b = (struct qemud_vm_disk_def *) bptr; +if (a-device == b-device) +return virDiskNameToIndex(a-dst) - virDiskNameToIndex(b-dst); +else +return a-device - b-device; +} + +static const char *qemudBusIdToName(int busId) { +const char *busnames[] = { ide, +scsi, +virtio }; + + if (busId = 0 busId 3) + return busnames[busId]; + else + return 0; +} + +static char *qemudDriveOpt(struct qemud_vm_disk_def *disk, int boot) +{ +char opt[PATH_MAX]; + +switch (disk-device) { +case QEMUD_DISK_CDROM: +snprintf(opt, PATH_MAX, file=%s,if=ide,media=cdrom%s, + disk-src, boot ? ,boot=on : ); +break; +case QEMUD_DISK_FLOPPY: +snprintf(opt, PATH_MAX, file=%s,if=floppy%s, + disk-src, boot ? ,boot=on : ); +break; +case QEMUD_DISK_DISK: +snprintf(opt, PATH_MAX, file=%s,if=%s%s, + disk-src, qemudBusIdToName(disk-bus), boot ? ,boot=on : ); +break; +default: +return 0; +} +return strdup(opt); +} + +static char *qemudAddBootDrive(virConnectPtr conn, +struct qemud_vm_def *def, + char *handledDisks, + int type) { +int j = 0; +struct qemud_vm_disk_def *disk = def-disks; + +while (disk) { +if (!handledDisks[j] disk-device == type) { +handledDisks[j] = 1; +return qemudDriveOpt(disk, 1); +} +j++; +disk = disk-next; +} +qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + Requested boot device type %d, but no such device defined., type); +return 0; +} /* * Parses a libvirt XML definition of a guest, and populates the @@ -1762,7 +1842,6 @@ obj = xmlXPathEval(BAD_CAST /domain/devices/disk, ctxt); if ((obj != NULL) (obj-type == XPATH_NODESET) (obj-nodesetval != NULL) (obj-nodesetval-nodeNr = 0)) { -struct qemud_vm_disk_def *prev = NULL; for (i = 0; i obj-nodesetval-nodeNr; i++) { struct qemud_vm_disk_def *disk = calloc(1, sizeof(*disk));
[libvirt] Re: [Libvir] [PATCH] Add bus attribute to disk target definition
On Tue, May 06, 2008 at 08:11:11PM +0200, Soren Hansen wrote: sorry for the delay. Here's the newest version of the patch which should address all the issues that have been raised so far. Yes no. It didn't address the redundant re-ordering of -drive parameters when using boot=on, nor re-add the -boot param to make PXE work again. One further complication is that QEMU 0.9.1 has -drive support but not the extboot support, so boot=on can't be used there. It rather annoyingly complains qemu: unknowm parameter 'boot' in 'file=/home/berrange/boot.iso,media=cdrom,boot=on' === modified file 'src/qemu_conf.c' --- old/src/qemu_conf.c 2008-04-30 12:30:55 + +++ new/src/qemu_conf.c 2008-05-06 17:58:44 + @@ -491,6 +491,8 @@ *flags |= QEMUD_CMD_FLAG_KQEMU; if (strstr(help, -no-reboot)) *flags |= QEMUD_CMD_FLAG_NO_REBOOT; +if (strstr(help, \n-drive)) +*flags |= QEMUD_CMD_FLAG_DRIVE_OPT; Turns out that this needed to also check for 'boot=on' availability. @@ -673,13 +676,28 @@ goto error; } +if (!bus) +disk-bus = QEMUD_DISK_BUS_IDE; This was giving floppy disks a bus of 'ide' which isn't technically correct - they're really their own bus type - I reckon we should call it 'fdc'. +else if (STREQ((const char *)bus, ide)) +disk-bus = QEMUD_DISK_BUS_IDE; +else if (STREQ((const char *)bus, scsi)) +disk-bus = QEMUD_DISK_BUS_SCSI; +else if (STREQ((const char *)bus, virtio)) +disk-bus = QEMUD_DISK_BUS_VIRTIO; +else { +qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, _(Invalid bus type: %s), bus); +goto error; +} + xmlFree(device); xmlFree(target); xmlFree(source); +xmlFree(bus); return 0; error: +xmlFree(bus); xmlFree(type); xmlFree(target); xmlFree(source); @@ -1373,6 +1391,68 @@ return -1; } +static int qemudDiskCompare(const void *aptr, const void *bptr) { +struct qemud_vm_disk_def *a = (struct qemud_vm_disk_def *) aptr; +struct qemud_vm_disk_def *b = (struct qemud_vm_disk_def *) bptr; +if (a-device == b-device) +return virDiskNameToIndex(a-dst) - virDiskNameToIndex(b-dst); +else +return a-device - b-device; Typo - this should be comparing the 'bus' field rather than 'device' to get IDE, SCSI and VirtIO disks ordered correctly wrt to each other. +static const char *qemudBusIdToName(int busId) { +const char *busnames[] = { ide, +scsi, +virtio }; + + if (busId = 0 busId 3) + return busnames[busId]; + else + return 0; +} This can be changed to make use of the GNULIB 'verify_true' function to get a compile time check fo the array cardinality vs the enum length. +static char *qemudDriveOpt(struct qemud_vm_disk_def *disk, int boot) +{ +char opt[PATH_MAX]; + +switch (disk-device) { +case QEMUD_DISK_CDROM: +snprintf(opt, PATH_MAX, file=%s,if=ide,media=cdrom%s, + disk-src, boot ? ,boot=on : ); +break; +case QEMUD_DISK_FLOPPY: +snprintf(opt, PATH_MAX, file=%s,if=floppy%s, + disk-src, boot ? ,boot=on : ); +break; +case QEMUD_DISK_DISK: +snprintf(opt, PATH_MAX, file=%s,if=%s%s, + disk-src, qemudBusIdToName(disk-bus), boot ? ,boot=on : ); This is missing the 'index=NNN' parameter so IDE disks are not getting assigned to the correct bus/unit. eg if i define 'hda' and 'hdd' in the XML the guest gets given 'hda' and 'hdb'. @@ -1775,13 +1854,20 @@ goto error; } def-ndisks++; -disk-next = NULL; if (i == 0) { +disk-next = NULL; def-disks = disk; } else { -prev-next = disk; +struct qemud_vm_disk_def *ptr = def-disks; +while (ptr) { +if (!ptr-next || qemudDiskCompare(ptr-next, disk) 0) { The parameters to the compare function are inverted so the ordering is being reversed. @@ -2110,6 +2196,7 @@ struct qemud_vm_chr_def *parallel = vm-def-parallels; struct utsname ut; int disableKQEMU = 0; +int use_extboot = 0; /* Make sure the binary we are about to try exec'ing exists. * Technically we could catch the exec() failure, but that's @@ -2230,30 +2317,47 @@ goto no_memory; } -for (i = 0 ; i vm-def-os.nBootDevs ; i++) { -switch (vm-def-os.bootDevs[i]) { -case QEMUD_BOOT_CDROM: -boot[i] = 'd'; -break; -case QEMUD_BOOT_FLOPPY: -boot[i] = 'a'; -break; -case QEMUD_BOOT_DISK: -boot[i] =
[Libvir] [PATCH] Add bus attribute to disk target definition
Hi! I'd like to propose that the following patch gets applied against libvirt. It adds the option of putting a bus attribute on a disk target. To acommodate this, it also changes the way drives are defined for kvm from the old -hda /path/to/file -boot c style to the new -drive file=/path/to/file,if=ide,boot=on. This makes it possible to specify virtio, scsi, and ide disks. === modified file 'src/qemu_conf.c' --- src/qemu_conf.c 2008-04-28 15:14:59 + +++ src/qemu_conf.c 2008-04-29 07:43:11 + @@ -568,6 +568,7 @@ xmlChar *source = NULL; xmlChar *target = NULL; xmlChar *type = NULL; +xmlChar *bus = NULL; int typ = 0; type = xmlGetProp(node, BAD_CAST type); @@ -598,6 +599,7 @@ } else if ((target == NULL) (xmlStrEqual(cur-name, BAD_CAST target))) { target = xmlGetProp(cur, BAD_CAST dev); +bus = xmlGetProp(cur, BAD_CAST bus); } else if (xmlStrEqual(cur-name, BAD_CAST readonly)) { disk-readonly = 1; } @@ -646,7 +648,9 @@ strcmp((const char *)target, hda) strcmp((const char *)target, hdb) strcmp((const char *)target, hdc) -strcmp((const char *)target, hdd)) { +strcmp((const char *)target, hdd) +strcmp((const char *)target, hdd) +strncmp((const char *)target, vd, 2)) { qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, _(Invalid harddisk device name: %s), target); goto error; @@ -673,6 +677,20 @@ goto error; } +if (!bus) +disk-bus = QEMUD_DISK_BUS_IDE; +else if (!strcmp((const char *)bus, ide)) +disk-bus = QEMUD_DISK_BUS_IDE; +else if (!strcmp((const char *)bus, scsi)) +disk-bus = QEMUD_DISK_BUS_SCSI; +else if (!strcmp((const char *)bus, virtio)) +disk-bus = QEMUD_DISK_BUS_VIRTIO; +else { +qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, Invalid bus type: %s, bus); +goto error; +} + +xmlFree(bus); xmlFree(device); xmlFree(target); xmlFree(source); @@ -688,6 +706,8 @@ xmlFree(source); if (device) xmlFree(device); +if (bus) +xmlFree(bus); return -1; } @@ -1350,6 +1370,68 @@ return -1; } +static int qemudDiskCompare(const void *aptr, const void *bptr) { +struct qemud_vm_disk_def *a = (struct qemud_vm_disk_def *) aptr; +struct qemud_vm_disk_def *b = (struct qemud_vm_disk_def *) bptr; +if (a-device == b-device) +return virDiskNameToIndex(a-dst) - virDiskNameToIndex(b-dst); +else +return a-device - b-device; +} + +static const char *qemudBusIdToName(int busId) { +const char *busnames[] = { ide, +scsi, +virtio }; + + if (busId = 0 busId 3) + return busnames[busId]; + else + return 0; +} + +static char *qemudDriveOpt(struct qemud_vm_disk_def *disk, int boot) +{ +char opt[PATH_MAX]; + +switch (disk-device) { +case QEMUD_DISK_CDROM: +snprintf(opt, PATH_MAX, file=%s,if=ide,media=cdrom%s, + disk-src, boot ? ,boot=on : ); +break; +case QEMUD_DISK_FLOPPY: +snprintf(opt, PATH_MAX, file=%s,if=floppy%s, + disk-src, boot ? ,boot=on : ); +break; +case QEMUD_DISK_DISK: +snprintf(opt, PATH_MAX, file=%s,if=%s%s, + disk-src, qemudBusIdToName(disk-bus), boot ? ,boot=on : ); +break; +default: +return 0; +} +return strdup(opt); +} + +static char *qemudAddBootDrive(virConnectPtr conn, +struct qemud_vm_def *def, + char *handledDisks, + int type) { +int j = 0; +struct qemud_vm_disk_def *disk = def-disks; + +while (disk) { +if (!handledDisks[j] disk-device == type) { +handledDisks[j] = 1; +return qemudDriveOpt(disk, 1); +} +j++; +disk = disk-next; +} +qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + Requested boot device type %d, but no such device defined., type); +return 0; +} /* * Parses a libvirt XML definition of a guest, and populates the @@ -1739,7 +1821,6 @@ obj = xmlXPathEval(BAD_CAST /domain/devices/disk, ctxt); if ((obj != NULL) (obj-type == XPATH_NODESET) (obj-nodesetval != NULL) (obj-nodesetval-nodeNr = 0)) { -struct qemud_vm_disk_def *prev = NULL; for (i = 0; i obj-nodesetval-nodeNr; i++) { struct qemud_vm_disk_def *disk = calloc(1, sizeof(*disk)); if (!disk) { @@ -1752,13 +1833,20 @@ goto error; } def-ndisks++; -disk-next = NULL;
Re: [Libvir] [PATCH] Add bus attribute to disk target definition
On Tue, Apr 29, 2008 at 09:56:13AM +0200, Soren Hansen wrote: Hi! I'd like to propose that the following patch gets applied against libvirt. It adds the option of putting a bus attribute on a disk target. To acommodate this, it also changes the way drives are defined for kvm from the old -hda /path/to/file -boot c style to the new -drive file=/path/to/file,if=ide,boot=on. This makes it possible to specify virtio, scsi, and ide disks. @@ -646,7 +648,9 @@ strcmp((const char *)target, hda) strcmp((const char *)target, hdb) strcmp((const char *)target, hdc) -strcmp((const char *)target, hdd)) { +strcmp((const char *)target, hdd) +strcmp((const char *)target, hdd) These two lines test the same thing ! +strncmp((const char *)target, vd, 2)) { Its probably a better idea to just compress the explicit hda - hdd comparisons down into a single 'hd' prefix comparison, as you did with 'vd'. +if (!bus) +disk-bus = QEMUD_DISK_BUS_IDE; +else if (!strcmp((const char *)bus, ide)) +disk-bus = QEMUD_DISK_BUS_IDE; +else if (!strcmp((const char *)bus, scsi)) +disk-bus = QEMUD_DISK_BUS_SCSI; +else if (!strcmp((const char *)bus, virtio)) +disk-bus = QEMUD_DISK_BUS_VIRTIO; Can you use the STREQ macro here instead of strcmp. +else { +qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, Invalid bus type: %s, bus); +goto error; +} This line needs to be marked for translation, with _(...). You can run 'make syntax-check' for check for such issues. +static char *qemudAddBootDrive(virConnectPtr conn, +struct qemud_vm_def *def, + char *handledDisks, + int type) { +int j = 0; +struct qemud_vm_disk_def *disk = def-disks; + +while (disk) { +if (!handledDisks[j] disk-device == type) { +handledDisks[j] = 1; +return qemudDriveOpt(disk, 1); +} +j++; +disk = disk-next; +} +qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + Requested boot device type %d, but no such device defined., type); +return 0; +} @@ -2207,30 +2295,32 @@ goto no_memory; } -for (i = 0 ; i vm-def-os.nBootDevs ; i++) { -switch (vm-def-os.bootDevs[i]) { -case QEMUD_BOOT_CDROM: -boot[i] = 'd'; -break; -case QEMUD_BOOT_FLOPPY: -boot[i] = 'a'; -break; -case QEMUD_BOOT_DISK: -boot[i] = 'c'; -break; -case QEMUD_BOOT_NET: -boot[i] = 'n'; -break; -default: -boot[i] = 'c'; -break; +if (vm-def-virtType != QEMUD_VIRT_KVM) { This is wrong - both QEMU and KVM can support the -drive parameter, and not all KVM support it. You need to add a check in the method qemudExtractVersionInfo() to probe for availability of the -drive option, as we do with other opts - see QEMUD_CMD_FLAG_NO_REBOOT for example. Even if the -drive parameter is supported, it should still pass the -boot a/c/d/n parameter in. +if (vm-def-virtType == QEMUD_VIRT_KVM) { +char *handledDisks = NULL; +int j; + +handledDisks = calloc(sizeof(*handledDisks), vm-def-ndisks); + +if (!handledDisks) +goto no_memory; + +/* When using -drive notation, we need to provide the devices in boot + * preference order. */ +for (i = 0 ; i vm-def-os.nBootDevs ; i++) { +if (!((*argv)[++n] = strdup(-drive))) +goto no_memory; + +switch (vm-def-os.bootDevs[i]) { +case QEMUD_BOOT_CDROM: +if (!((*argv)[++n] = qemudAddBootDrive(conn, vm-def, handledDisks, QEMUD_DISK_CDROM))) +goto error; +break; + case QEMUD_BOOT_FLOPPY: +if (!((*argv)[++n] = qemudAddBootDrive(conn, vm-def, handledDisks, QEMUD_DISK_FLOPPY))) +goto error; +break; +case QEMUD_BOOT_DISK: +if (!((*argv)[++n] = qemudAddBootDrive(conn, vm-def, handledDisks, QEMUD_DISK_DISK))) +goto error; +break; +} +} There is nothing in the -drive parameter handling, AFAICT, that requires the boot drive to be listed first on the command line. So this first loop is not needed, and this second loop is sufficient, simply turn on the boot= flag on the first match drive type when iterating over the list. + +/* Pick up the rest of the devices */ +j=0; +while (disk) { +if (!handledDisks[j]) { +handledDisks[j] = 1; +if
Re: [Libvir] [PATCH] Add bus attribute to disk target definition
On Tue, Apr 29, 2008 at 02:27:00PM +0100, Daniel P. Berrange wrote: +strcmp((const char *)target, hdd) +strcmp((const char *)target, hdd) These two lines test the same thing ! Quite so. My bad. +strncmp((const char *)target, vd, 2)) { Its probably a better idea to just compress the explicit hda - hdd comparisons down into a single 'hd' prefix comparison, as you did with 'vd'. Hm.. Yes, I suppose that if you're using -drive notation, hd[e-z] starts making sense. Fixed. +if (!bus) +disk-bus = QEMUD_DISK_BUS_IDE; +else if (!strcmp((const char *)bus, ide)) +disk-bus = QEMUD_DISK_BUS_IDE; +else if (!strcmp((const char *)bus, scsi)) +disk-bus = QEMUD_DISK_BUS_SCSI; +else if (!strcmp((const char *)bus, virtio)) +disk-bus = QEMUD_DISK_BUS_VIRTIO; Can you use the STREQ macro here instead of strcmp. Erm... I *could*.. I'm curious, though, why e.g. the similar code right above it doesn't use STREQ if that's the preferred way to do it? IMO, it's better to change this sort of things all in one go, and keep everything consistent until then. +else { +qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, Invalid bus type: %s, bus); +goto error; +} This line needs to be marked for translation, with _(...). Fixed. You can run 'make syntax-check' for check for such issues. Yes, in theory :) In the real world, however, make syntax-check fails horribly here. I'll be fixing that up next. +static char *qemudAddBootDrive(virConnectPtr conn, +struct qemud_vm_def *def, + char *handledDisks, + int type) { +int j = 0; +struct qemud_vm_disk_def *disk = def-disks; + +while (disk) { +if (!handledDisks[j] disk-device == type) { +handledDisks[j] = 1; +return qemudDriveOpt(disk, 1); +} +j++; +disk = disk-next; +} +qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + Requested boot device type %d, but no such device defined., type); +return 0; +} @@ -2207,30 +2295,32 @@ goto no_memory; } -for (i = 0 ; i vm-def-os.nBootDevs ; i++) { -switch (vm-def-os.bootDevs[i]) { -case QEMUD_BOOT_CDROM: -boot[i] = 'd'; -break; -case QEMUD_BOOT_FLOPPY: -boot[i] = 'a'; -break; -case QEMUD_BOOT_DISK: -boot[i] = 'c'; -break; -case QEMUD_BOOT_NET: -boot[i] = 'n'; -break; -default: -boot[i] = 'c'; -break; +if (vm-def-virtType != QEMUD_VIRT_KVM) { This is wrong - both QEMU and KVM can support the -drive parameter, Oh, I wasn't aware. Hmm.. and not all KVM support it. You need to add a check in the method qemudExtractVersionInfo() to probe for availability of the -drive option, as we do with other opts - see QEMUD_CMD_FLAG_NO_REBOOT for example. Interesting. I'll add that. Even if the -drive parameter is supported, it should still pass the -boot a/c/d/n parameter in. Why? And how would you boot from a virtio device this way? There is nothing in the -drive parameter handling, AFAICT, that requires the boot drive to be listed first on the command line. So this first loop is not needed, and this second loop is sufficient, simply turn on the boot= flag on the first match drive type when iterating over the list. If you want to specify more than one boot device, the only way to determine the priority is by specifying them ordered by priority. At least, that's how it *ought* to be, but now I see that extboot only actually supports one boot device. :/ I could have sworn I had seen it work with both hard drive and cdrom. +int virDiskNameToIndex(const char *name) { +const char *ptr = NULL; +int idx = 0; + +if (strlen(name) 3) +return 0; + +switch (*name) { +case 'f': +case 'h': +case 'v': You need a case 's' there to allow for SCSI... Good point. I suppose I do so in qemudParseDiskXml as well (when checking the target). -- Soren Hansen | Virtualisation specialist | Ubuntu Server Team Canonical Ltd. | http://www.ubuntu.com/ signature.asc Description: Digital signature -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [Libvir] [PATCH] Add bus attribute to disk target definition
On Tue, Apr 29, 2008 at 04:10:40PM +0200, Soren Hansen wrote: On Tue, Apr 29, 2008 at 02:27:00PM +0100, Daniel P. Berrange wrote: +if (!bus) +disk-bus = QEMUD_DISK_BUS_IDE; +else if (!strcmp((const char *)bus, ide)) +disk-bus = QEMUD_DISK_BUS_IDE; +else if (!strcmp((const char *)bus, scsi)) +disk-bus = QEMUD_DISK_BUS_SCSI; +else if (!strcmp((const char *)bus, virtio)) +disk-bus = QEMUD_DISK_BUS_VIRTIO; Can you use the STREQ macro here instead of strcmp. Erm... I *could*.. I'm curious, though, why e.g. the similar code right above it doesn't use STREQ if that's the preferred way to do it? We've been slowly updating code to match these new standards when doing patches. You can run 'make syntax-check' for check for such issues. Yes, in theory :) In the real world, however, make syntax-check fails horribly here. I'll be fixing that up next. If you send details to the list, Jim will no doubt be able to point you in the right direction on this... Even if the -drive parameter is supported, it should still pass the -boot a/c/d/n parameter in. Why? And how would you boot from a virtio device this way? It is needed for PXE boot at least, and IMHO, QEMU should treat 'boot c' as if 'boot=on' were set for the first -drive parameter for back compat. There is nothing in the -drive parameter handling, AFAICT, that requires the boot drive to be listed first on the command line. So this first loop is not needed, and this second loop is sufficient, simply turn on the boot= flag on the first match drive type when iterating over the list. If you want to specify more than one boot device, the only way to determine the priority is by specifying them ordered by priority. At least, that's how it *ought* to be, but now I see that extboot only actually supports one boot device. :/ I could have sworn I had seen it work with both hard drive and cdrom. The QEMU code only allows a single boot device will abort if 1 has it if (extboot_drive != -1) { fprintf(stderr, qemu: two bootable drives specified\n); return -1; } Regards, Dan. -- |: Red Hat, Engineering, Boston -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 :| -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [Libvir] [PATCH] Add bus attribute to disk target definition
Daniel P. Berrange [EMAIL PROTECTED] wrote: On Tue, Apr 29, 2008 at 04:10:40PM +0200, Soren Hansen wrote: On Tue, Apr 29, 2008 at 02:27:00PM +0100, Daniel P. Berrange wrote: +if (!bus) +disk-bus = QEMUD_DISK_BUS_IDE; +else if (!strcmp((const char *)bus, ide)) +disk-bus = QEMUD_DISK_BUS_IDE; +else if (!strcmp((const char *)bus, scsi)) +disk-bus = QEMUD_DISK_BUS_SCSI; +else if (!strcmp((const char *)bus, virtio)) +disk-bus = QEMUD_DISK_BUS_VIRTIO; Can you use the STREQ macro here instead of strcmp. Erm... I *could*.. I'm curious, though, why e.g. the similar code right above it doesn't use STREQ if that's the preferred way to do it? We've been slowly updating code to match these new standards when doing patches. FYI, there's already a test for this, but it's currently disabled. If someone wants to turn it on (remove the sc_prohibit_strcmp line from Makefile.cfg) and fix all the new violations exposed by running make syntax-check, it sounds like it would be welcome, now. You can run 'make syntax-check' for check for such issues. Yes, in theory :) In the real world, however, make syntax-check fails horribly here. I'll be fixing that up next. If you send details to the list, Jim will no doubt be able to point you in the right direction on this... Yep. Though most of it is intended to be self explanatory. If not, please let me know and I'll fix the rules in Makefile.maint. -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [Libvir] [PATCH] Add bus attribute to disk target definition
Jim Meyering [EMAIL PROTECTED] wrote: Daniel P. Berrange [EMAIL PROTECTED] wrote: On Tue, Apr 29, 2008 at 04:10:40PM +0200, Soren Hansen wrote: On Tue, Apr 29, 2008 at 02:27:00PM +0100, Daniel P. Berrange wrote: +if (!bus) +disk-bus = QEMUD_DISK_BUS_IDE; +else if (!strcmp((const char *)bus, ide)) +disk-bus = QEMUD_DISK_BUS_IDE; +else if (!strcmp((const char *)bus, scsi)) +disk-bus = QEMUD_DISK_BUS_SCSI; +else if (!strcmp((const char *)bus, virtio)) +disk-bus = QEMUD_DISK_BUS_VIRTIO; Can you use the STREQ macro here instead of strcmp. Erm... I *could*.. I'm curious, though, why e.g. the similar code right above it doesn't use STREQ if that's the preferred way to do it? We've been slowly updating code to match these new standards when doing patches. FYI, there's already a test for this, but it's currently disabled. If someone wants to turn it on (remove the sc_prohibit_strcmp line from Makefile.cfg) and fix all the new violations exposed by running make syntax-check, it sounds like it would be welcome, now. In preparation for this, I've just relaxed the regexp in the check to allow for libvirt's varying coding styles (space or not between function name and opening parenthesis): tests: recognize more uses of strcmp. * Makefile.maint (sc_prohibit_strcmp): Relax regexp. = Index: Makefile.maint === RCS file: /data/cvs/libvirt/Makefile.maint,v retrieving revision 1.21 retrieving revision 1.22 diff -u -p -u -r1.21 -r1.22 --- Makefile.maint 21 Apr 2008 10:09:07 - 1.21 +++ Makefile.maint 29 Apr 2008 14:25:19 - 1.22 @@ -91,7 +91,7 @@ sc_prohibit_atoi_atof: # Use STREQ rather than comparing strcmp == 0, or != 0. sc_prohibit_strcmp: - @grep -nE '! *str''cmp \(|\str''cmp \([^)]+\) *==' \ + @grep -nE '! *str''cmp *\(|\str''cmp *\([^)]+\) *==' \ $$($(VC_LIST_EXCEPT)) \ { echo '$(ME): use STREQ in place of the above uses of str''cmp' \ 12; exit 1; } || : -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [Libvir] [PATCH] Add bus attribute to disk target definition
On Tue, Apr 29, 2008 at 03:17:14PM +0100, Daniel P. Berrange wrote: +if (!bus) +disk-bus = QEMUD_DISK_BUS_IDE; +else if (!strcmp((const char *)bus, ide)) +disk-bus = QEMUD_DISK_BUS_IDE; +else if (!strcmp((const char *)bus, scsi)) +disk-bus = QEMUD_DISK_BUS_SCSI; +else if (!strcmp((const char *)bus, virtio)) +disk-bus = QEMUD_DISK_BUS_VIRTIO; Can you use the STREQ macro here instead of strcmp. Erm... I *could*.. I'm curious, though, why e.g. the similar code right above it doesn't use STREQ if that's the preferred way to do it? We've been slowly updating code to match these new standards when doing patches. Well, if that's the way you do it, I'll follow suit.. However, I have to say that I pity the person that reads the code and finds these two sections of code that seem to do rather similar things, but use different functions to do it, and then has to work out what on earth the difference between the two might be. You can run 'make syntax-check' for check for such issues. Yes, in theory :) In the real world, however, make syntax-check fails horribly here. I'll be fixing that up next. If you send details to the list, Jim will no doubt be able to point you in the right direction on this... I'll do that in a minute. Thanks. Even if the -drive parameter is supported, it should still pass the -boot a/c/d/n parameter in. Why? And how would you boot from a virtio device this way? It is needed for PXE boot at least, and IMHO, Good point. QEMU should treat 'boot c' as if 'boot=on' were set for the first -drive parameter for back compat. Yes, indeed it should. Sadly, though, it doesn't. kvm -drive file=root.qcow,if=virtio -boot c fails miserably, while kvm -drive file=root.qcow,if=virtio,boot=on works beautifully. This logic is going to look horrible :( Something like: if boot == hd (one of the disks is a virtio disk) then use new style -drive foo,boot=on notation else use old style -boot [acdn] notation ? There is nothing in the -drive parameter handling, AFAICT, that requires the boot drive to be listed first on the command line. So this first loop is not needed, and this second loop is sufficient, simply turn on the boot= flag on the first match drive type when iterating over the list. If you want to specify more than one boot device, the only way to determine the priority is by specifying them ordered by priority. At least, that's how it *ought* to be, but now I see that extboot only actually supports one boot device. :/ I could have sworn I had seen it work with both hard drive and cdrom. The QEMU code only allows a single boot device will abort if 1 has it if (extboot_drive != -1) { fprintf(stderr, qemu: two bootable drives specified\n); return -1; } Yes, that's what I noticed earlier today, although I geniunely hope this is something that will be fixed at some point, and when that happy day comes, I've either guessed correctly as to how it will derive boot priorities and we won't have to fix anything, or I've guessed wrong, and then we'll be no worse off than if we didn't adopt this approach right now, AFAICS. -- Soren Hansen | Virtualisation specialist | Ubuntu Server Team Canonical Ltd. | http://www.ubuntu.com/ signature.asc Description: Digital signature -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [Libvir] [PATCH] Add bus attribute to disk target definition
On Tue, Apr 29, 2008 at 04:42:54PM +0200, Soren Hansen wrote: On Tue, Apr 29, 2008 at 03:17:14PM +0100, Daniel P. Berrange wrote: +if (!bus) +disk-bus = QEMUD_DISK_BUS_IDE; +else if (!strcmp((const char *)bus, ide)) +disk-bus = QEMUD_DISK_BUS_IDE; +else if (!strcmp((const char *)bus, scsi)) +disk-bus = QEMUD_DISK_BUS_SCSI; +else if (!strcmp((const char *)bus, virtio)) +disk-bus = QEMUD_DISK_BUS_VIRTIO; Can you use the STREQ macro here instead of strcmp. Erm... I *could*.. I'm curious, though, why e.g. the similar code right above it doesn't use STREQ if that's the preferred way to do it? We've been slowly updating code to match these new standards when doing patches. Well, if that's the way you do it, I'll follow suit.. However, I have to say that I pity the person that reads the code and finds these two sections of code that seem to do rather similar things, but use different functions to do it, and then has to work out what on earth the difference between the two might be. Here is an update to the HACKING file intended to describe some of the conventions in use... Dan Index: HACKING === RCS file: /data/cvs/libvirt/HACKING,v retrieving revision 1.1 diff -r1.1 HACKING 45a46,160 Low level memory management === Use of the malloc/free/realloc/calloc APIs is deprecated in the libvirt codebase, because they encourage a number of serious coding bugs and do not enable compile time verification of checks for NULL. Instead of these routines, use the macros from memory.h - eg to allocate a single object: virDomainPtr domain; if (VIR_ALLOC(domain) 0) { __virRaiseError(VIR_ERROR_NO_MEMORY) return NULL; } - eg to allocate an array of objects virDomainPtr domains; int ndomains = 10; if (VIR_ALLOC_N(domains, ndomains) 0) { __virRaiseError(VIR_ERROR_NO_MEMORY) return NULL; } - eg to allocate an array of object pointers virDomainPtr *domains; int ndomains = 10; if (VIR_ALLOC_N(domains, ndomains) 0) { __virRaiseError(VIR_ERROR_NO_MEMORY) return NULL; } - eg to re-allocate the array of domains to be longer ndomains = 20 if (VIR_REALLOC_N(domains, ndomains) 0) { __virRaiseError(VIR_ERROR_NO_MEMORY) return NULL; } - eg to free the domain VIR_FREE(domain); String comparisons == Do not use the strcmp, strncmp, etc functions directly. Instead use one of the following semantically named macros - For strict equality: STREQ(a,b) STRNEQ(a,b) - For case sensitive equality: STRCASEEQ(a,b) STRCASENEQ(a,b) - For strict equality of a substring: STREQLEN(a,b,n) STRNEQLEN(a,b,n) - For case sensitive equality of a substring: STRCASEEQLEN(a,b,n) STRCASENEQLEN(a,b,n) - For strict equality of a prefix: STRPREFIX(a,b) Variable length string buffer = If there is a need for complex string concatenations, avoid using the usual sequence of malloc/strcpy/strcat/snprintf functions and make use of the virBuffer API described in buf.h eg typical usage is as follows: char * somefunction(...) { virBuffer buf = VIR_BUFFER_INITIALIZER; ... virBufferAdd(buf, domain\n); virBufferVSprint(buf, memory%d/memory\n, memory); ... virBufferAdd(buf, /domain\n); if (virBufferError(buf)) { __virRaiseError(...); return NULL; } return virBufferContentAndReset(buf); } -- |: Red Hat, Engineering, Boston -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 :| -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list