:p
atchew
Login
Disk targets were generated in virVMXParseConfig() with virVMXGenerateDiskTarget(). It works on combination of controller, fix offset, unit and prefix. While SCSI and SATA have same prefix "sd", function virVMXGenerateDiskTarget() could returned in some cases same targets. In this patch, after loaded SCSI and SATA disks to the def, it checks if in array exists any SATA disks after SCSI. If not, nothing happened. If yes, targets of all SATA disks are changed. Disk target is calculated as: last SCSI target value + n, where n is position of disk in array after last SCSI (1,2,..). Because assigned addresses of disks are generated from their indexes, for every changed SATA disk is called virDomainDiskDefAssignAddress() with the updated value. The corresponding tests have been modified to match the index changes. Signed-off-by: Adam Julis <ajulis@redhat.com> --- src/vmx/vmx.c | 32 ++++++++++++++++++++++++ tests/vmx2xmldata/esx-in-the-wild-12.xml | 4 +-- tests/vmx2xmldata/esx-in-the-wild-8.xml | 4 +-- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index XXXXXXX..XXXXXXX 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -XXX,XX +XXX,XX @@ virVMXParseConfig(virVMXContext *ctx, bool smbios_reflecthost = false; int controller; int bus; + int ndisk; + int last_scsi; + int offset = -1; int port; bool present; int scsi_virtualDev[4] = { -1, -1, -1, -1 }; @@ -XXX,XX +XXX,XX @@ virVMXParseConfig(virVMXContext *ctx, } } + /* now disks contain only SCSI and SATA, SATA could have same index (dst) as SCSI + * find last SCSI index in array and use it as offset for all SATA indexes + * (overwrite old values) + * finally, regenerate correct addresses, while it depends on the index */ + for (ndisk = 0; ndisk < def->ndisks; ndisk++) { + virDomainDiskDef *dsc = def->disks[ndisk]; + + if (dsc->bus == VIR_DOMAIN_DISK_BUS_SCSI) { + offset = virDiskNameToIndex(dsc->dst); + last_scsi = ndisk; + continue; + } + + if (offset > -1) { + VIR_FREE(def->disks[ndisk]->dst); + def->disks[ndisk]->dst = virIndexToDiskName(offset + ndisk - last_scsi, "sd"); + + if (virDomainDiskDefAssignAddress(NULL, def->disks[ndisk], def) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not assign address to disk '%1$s'"), + virDomainDiskGetSource(dsc)); + goto cleanup; + } + } + + else + break; + } + /* def:disks (ide) */ for (bus = 0; bus < 2; ++bus) { for (unit = 0; unit < 2; ++unit) { diff --git a/tests/vmx2xmldata/esx-in-the-wild-12.xml b/tests/vmx2xmldata/esx-in-the-wild-12.xml index XXXXXXX..XXXXXXX 100644 --- a/tests/vmx2xmldata/esx-in-the-wild-12.xml +++ b/tests/vmx2xmldata/esx-in-the-wild-12.xml @@ -XXX,XX +XXX,XX @@ <address type='drive' controller='0' bus='0' target='0' unit='0'/> </disk> <disk type='file' device='cdrom'> - <target dev='sda' bus='sata'/> + <target dev='sdb' bus='sata'/> <readonly/> - <address type='drive' controller='0' bus='0' target='0' unit='0'/> + <address type='drive' controller='0' bus='0' target='0' unit='1'/> </disk> <controller type='scsi' index='0' model='vmpvscsi'/> <controller type='sata' index='0'/> diff --git a/tests/vmx2xmldata/esx-in-the-wild-8.xml b/tests/vmx2xmldata/esx-in-the-wild-8.xml index XXXXXXX..XXXXXXX 100644 --- a/tests/vmx2xmldata/esx-in-the-wild-8.xml +++ b/tests/vmx2xmldata/esx-in-the-wild-8.xml @@ -XXX,XX +XXX,XX @@ </disk> <disk type='file' device='cdrom'> <source file='[692eb778-2d4937fe] CentOS-4.7.ServerCD-x86_64.iso'/> - <target dev='sda' bus='sata'/> + <target dev='sdd' bus='sata'/> <readonly/> - <address type='drive' controller='0' bus='0' target='0' unit='0'/> + <address type='drive' controller='0' bus='0' target='0' unit='3'/> </disk> <controller type='scsi' index='0' model='vmpvscsi'/> <controller type='sata' index='0'/> -- 2.45.2
Disk targets are generated in virVMXParseConfig() with virVMXGenerateDiskTarget(). It works on combination of controller, fix offset, unit and prefix. While SCSI and SATA have same prefix "sd", function virVMXGenerateDiskTarget() could returned in some cases same targets. In this patch, after loaded SCSI and SATA disks to the def, indexes are regenerated, now simply from position of the disk in array of disks (def). With this, required uniqueness is guaranteed. Because assigned addresses of disks are generated from their indexes, for every changed SATA disk is called virDomainDiskDefAssignAddress() with the updated value. The corresponding tests have been modified to match the index changes. Signed-off-by: Adam Julis <ajulis@redhat.com> --- Since previous version in mailing list was complicated for trying to preserve the indexes of SCSI and previous tests, this one going to straightforward, although it changes all (SCSI and SATA) indexes. It's not a bug, since we cannot guarantee the same naming inside the guest anyway. src/vmx/vmx.c | 19 +++++++++++++++++++ tests/vmx2xmldata/esx-in-the-wild-11.xml | 4 ++-- tests/vmx2xmldata/esx-in-the-wild-12.xml | 4 ++-- tests/vmx2xmldata/esx-in-the-wild-2.xml | 4 ++-- tests/vmx2xmldata/esx-in-the-wild-8.xml | 4 ++-- tests/vmx2xmldata/scsi-driver.xml | 12 ++++++------ 6 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index XXXXXXX..XXXXXXX 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -XXX,XX +XXX,XX @@ virVMXParseConfig(virVMXContext *ctx, virCPUDef *cpu = NULL; char *firmware = NULL; size_t saved_ndisks = 0; + size_t i; if (ctx->parseFileName == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -XXX,XX +XXX,XX @@ virVMXParseConfig(virVMXContext *ctx, } } + /* now disks contain only SCSI and SATA, SATA could have same name (dst) as SCSI + * so replace all their names with new ones to guarantee their uniqueness + * finally, regenerate correct addresses, while it depends on the index */ + + for (i = 0; i < def->ndisks; i++) { + virDomainDiskDef *disk = def->disks[i]; + + VIR_FREE(disk->dst); + disk->dst = virIndexToDiskName(i, "sd"); + + if (virDomainDiskDefAssignAddress(NULL, disk, def) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not assign address to disk '%1$s'"), + virDomainDiskGetSource(disk)); + goto cleanup; + } + } + /* def:disks (ide) */ for (bus = 0; bus < 2; ++bus) { for (unit = 0; unit < 2; ++unit) { diff --git a/tests/vmx2xmldata/esx-in-the-wild-11.xml b/tests/vmx2xmldata/esx-in-the-wild-11.xml index XXXXXXX..XXXXXXX 100644 --- a/tests/vmx2xmldata/esx-in-the-wild-11.xml +++ b/tests/vmx2xmldata/esx-in-the-wild-11.xml @@ -XXX,XX +XXX,XX @@ </disk> <disk type='file' device='disk'> <source file='[datastore] directory/esx6.7-rhel7.7-x86_64_3.vmdk'/> - <target dev='sdp' bus='scsi'/> - <address type='drive' controller='0' bus='0' target='0' unit='16'/> + <target dev='sdb' bus='scsi'/> + <address type='drive' controller='0' bus='0' target='0' unit='1'/> </disk> <controller type='scsi' index='0' model='vmpvscsi'/> <interface type='bridge'> diff --git a/tests/vmx2xmldata/esx-in-the-wild-12.xml b/tests/vmx2xmldata/esx-in-the-wild-12.xml index XXXXXXX..XXXXXXX 100644 --- a/tests/vmx2xmldata/esx-in-the-wild-12.xml +++ b/tests/vmx2xmldata/esx-in-the-wild-12.xml @@ -XXX,XX +XXX,XX @@ <address type='drive' controller='0' bus='0' target='0' unit='0'/> </disk> <disk type='file' device='cdrom'> - <target dev='sda' bus='sata'/> + <target dev='sdb' bus='sata'/> <readonly/> - <address type='drive' controller='0' bus='0' target='0' unit='0'/> + <address type='drive' controller='0' bus='0' target='0' unit='1'/> </disk> <controller type='scsi' index='0' model='vmpvscsi'/> <controller type='sata' index='0'/> diff --git a/tests/vmx2xmldata/esx-in-the-wild-2.xml b/tests/vmx2xmldata/esx-in-the-wild-2.xml index XXXXXXX..XXXXXXX 100644 --- a/tests/vmx2xmldata/esx-in-the-wild-2.xml +++ b/tests/vmx2xmldata/esx-in-the-wild-2.xml @@ -XXX,XX +XXX,XX @@ </disk> <disk type='file' device='cdrom'> <source file='[datastore] directory/Debian1-cdrom.iso'/> - <target dev='sdp' bus='scsi'/> + <target dev='sdb' bus='scsi'/> <readonly/> - <address type='drive' controller='1' bus='0' target='0' unit='0'/> + <address type='drive' controller='0' bus='0' target='0' unit='1'/> </disk> <disk type='file' device='cdrom'> <source file='/vmimages/tools-isoimages/linux.iso'/> diff --git a/tests/vmx2xmldata/esx-in-the-wild-8.xml b/tests/vmx2xmldata/esx-in-the-wild-8.xml index XXXXXXX..XXXXXXX 100644 --- a/tests/vmx2xmldata/esx-in-the-wild-8.xml +++ b/tests/vmx2xmldata/esx-in-the-wild-8.xml @@ -XXX,XX +XXX,XX @@ </disk> <disk type='file' device='cdrom'> <source file='[692eb778-2d4937fe] CentOS-4.7.ServerCD-x86_64.iso'/> - <target dev='sda' bus='sata'/> + <target dev='sdd' bus='sata'/> <readonly/> - <address type='drive' controller='0' bus='0' target='0' unit='0'/> + <address type='drive' controller='0' bus='0' target='0' unit='3'/> </disk> <controller type='scsi' index='0' model='vmpvscsi'/> <controller type='sata' index='0'/> diff --git a/tests/vmx2xmldata/scsi-driver.xml b/tests/vmx2xmldata/scsi-driver.xml index XXXXXXX..XXXXXXX 100644 --- a/tests/vmx2xmldata/scsi-driver.xml +++ b/tests/vmx2xmldata/scsi-driver.xml @@ -XXX,XX +XXX,XX @@ </disk> <disk type='file' device='disk'> <source file='[datastore] directory/harddisk2.vmdk'/> - <target dev='sdp' bus='scsi'/> - <address type='drive' controller='1' bus='0' target='0' unit='0'/> + <target dev='sdb' bus='scsi'/> + <address type='drive' controller='0' bus='0' target='0' unit='1'/> </disk> <disk type='file' device='disk'> <source file='[datastore] directory/harddisk3.vmdk'/> - <target dev='sdae' bus='scsi'/> - <address type='drive' controller='2' bus='0' target='0' unit='0'/> + <target dev='sdc' bus='scsi'/> + <address type='drive' controller='0' bus='0' target='0' unit='2'/> </disk> <disk type='file' device='disk'> <source file='[datastore] directory/harddisk4.vmdk'/> - <target dev='sdat' bus='scsi'/> - <address type='drive' controller='3' bus='0' target='0' unit='0'/> + <target dev='sdd' bus='scsi'/> + <address type='drive' controller='0' bus='0' target='0' unit='3'/> </disk> <controller type='scsi' index='0' model='buslogic'/> <controller type='scsi' index='1' model='lsilogic'/> -- 2.45.2