We can update device and attach device(cdrom) with the boot order unchanged.
But the boot order check method will report an error:
"boot order %d is already used by another device"
In fact the boot order is used by itself, we just want to keep it as before.
This patch improves boot order check to distinguish the owner.
Signed-off-by: Wang Rui <moon.wangrui(a)huawei.com>
Signed-off-by: Zhou Yimin <zhouyimin(a)huawei.com>
---
src/conf/device_conf.c | 13 +++++++++++++
src/conf/device_conf.h | 12 ++++++++++++
src/conf/domain_conf.c | 31 +++++++++++++++++++++++++++----
src/conf/domain_conf.h | 9 ---------
4 files changed, 52 insertions(+), 13 deletions(-)
diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c
index 5ffe159..907a7b8 100644
--- a/src/conf/device_conf.c
+++ b/src/conf/device_conf.c
@@ -144,6 +144,19 @@ virDevicePCIAddressEqual(virDevicePCIAddress *addr1,
return false;
}
+bool
+virDeviceDriveAddressEqual(virDomainDeviceDriveAddressPtr addr1,
+ virDomainDeviceDriveAddressPtr addr2)
+{
+ if (addr1->controller == addr2->controller &&
+ addr1->bus == addr2->bus &&
+ addr1->target == addr2->target &&
+ addr1->unit == addr2->unit) {
+ return true;
+ }
+ return false;
+}
+
int
virInterfaceLinkParseXML(xmlNodePtr node,
virInterfaceLinkPtr lnk)
diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h
index f067a35..afcf0ee 100644
--- a/src/conf/device_conf.h
+++ b/src/conf/device_conf.h
@@ -55,6 +55,15 @@ struct _virDevicePCIAddress {
int multi; /* enum virDomainDeviceAddressPCIMulti */
};
+typedef struct _virDomainDeviceDriveAddress virDomainDeviceDriveAddress;
+typedef virDomainDeviceDriveAddress *virDomainDeviceDriveAddressPtr;
+struct _virDomainDeviceDriveAddress {
+ unsigned int controller;
+ unsigned int bus;
+ unsigned int target;
+ unsigned int unit;
+};
+
typedef struct _virInterfaceLink virInterfaceLink;
typedef virInterfaceLink *virInterfaceLinkPtr;
struct _virInterfaceLink {
@@ -74,6 +83,9 @@ int virDevicePCIAddressFormat(virBufferPtr buf,
bool virDevicePCIAddressEqual(virDevicePCIAddress *addr1,
virDevicePCIAddress *addr2);
+bool virDeviceDriveAddressEqual(virDomainDeviceDriveAddressPtr addr1,
+ virDomainDeviceDriveAddressPtr addr2);
+
int virInterfaceLinkParseXML(xmlNodePtr node,
virInterfaceLinkPtr lnk);
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index aafc05e..d2c4a0a 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -19953,12 +19953,35 @@ virDomainDeviceInfoCheckBootIndex(virDomainDefPtr def
ATTRIBUTE_UNUSED,
virDomainDeviceInfoPtr newinfo = opaque;
if (info->bootIndex == newinfo->bootIndex) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("boot order %d is already used by another device"),
- newinfo->bootIndex);
- return -1;
+ /* check if the same boot order is used by another device or itself */
+ if (info->type != newinfo->type) {
+ goto error;
+ } else {
+ switch ((virDomainDeviceAddressType) newinfo->type) {
+ case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
+ if (virDevicePCIAddressEqual(&info->addr.pci,
+ &newinfo->addr.pci))
+ return 0;
+ else
+ goto error;
+ case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE:
+ if (virDeviceDriveAddressEqual(&info->addr.drive,
+ &newinfo->addr.drive))
+ return 0;
+ else
+ goto error;
+ default:
+ goto error;
+ }
+ }
}
return 0;
+
+ error:
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("boot order %d is already used by another device"),
+ newinfo->bootIndex);
+ return -1;
}
int
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 57297cd..3bddc80 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -236,15 +236,6 @@ typedef enum {
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST
} virDomainDeviceAddressType;
-typedef struct _virDomainDeviceDriveAddress virDomainDeviceDriveAddress;
-typedef virDomainDeviceDriveAddress *virDomainDeviceDriveAddressPtr;
-struct _virDomainDeviceDriveAddress {
- unsigned int controller;
- unsigned int bus;
- unsigned int target;
- unsigned int unit;
-};
-
typedef struct _virDomainDeviceVirtioSerialAddress virDomainDeviceVirtioSerialAddress;
typedef virDomainDeviceVirtioSerialAddress *virDomainDeviceVirtioSerialAddressPtr;
struct _virDomainDeviceVirtioSerialAddress {
--
1.7.12.4