[libvirt] [PATCH] qemu: Validate disk against domain def on coldplug

Michal Privoznik posted 1 patch 4 years, 10 months ago
Test syntax-check passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/22d327722570d34e5c7042ecb67b5a82248532ee.1561556868.git.mprivozn@redhat.com
src/qemu/qemu_driver.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
[libvirt] [PATCH] qemu: Validate disk against domain def on coldplug
Posted by Michal Privoznik 4 years, 10 months ago
https://bugzilla.redhat.com/show_bug.cgi?id=1692296#c7

This is a counterpart for ddc72f99027 and implements the same
check for coldplug.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_driver.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index d6ab134196..ed5f832f59 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -8082,6 +8082,21 @@ qemuDomainUpdateDeviceLive(virDomainObjPtr vm,
     return ret;
 }
 
+
+static int
+qemuCheckDiskConfigAgainstDomain(const virDomainDef *def,
+                                 const virDomainDiskDef *disk)
+{
+    if (virDomainSCSIDriveAddressIsUsed(def, &disk->info.addr.drive)) {
+        virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                       _("Domain already contains a disk with that address"));
+        return -1;
+    }
+
+    return 0;
+}
+
+
 static int
 qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef,
                              virDomainDeviceDefPtr dev,
@@ -8110,6 +8125,8 @@ qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef,
             return -1;
         if (qemuCheckDiskConfig(disk, NULL) < 0)
             return -1;
+        if (qemuCheckDiskConfigAgainstDomain(vmdef, disk) < 0)
+            return -1;
         if (virDomainDiskInsert(vmdef, disk) < 0)
             return -1;
         /* vmdef has the pointer. Generic codes for vmdef will do all jobs */
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu: Validate disk against domain def on coldplug
Posted by Erik Skultety 4 years, 9 months ago
On Wed, Jun 26, 2019 at 03:47:48PM +0200, Michal Privoznik wrote:
> https://bugzilla.redhat.com/show_bug.cgi?id=1692296#c7
>
> This is a counterpart for ddc72f99027 and implements the same
> check for coldplug.
>
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/qemu/qemu_driver.c | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
>
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index d6ab134196..ed5f832f59 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -8082,6 +8082,21 @@ qemuDomainUpdateDeviceLive(virDomainObjPtr vm,
>      return ret;
>  }
>
> +
> +static int
> +qemuCheckDiskConfigAgainstDomain(const virDomainDef *def,

I'd probably name this function "qemuCheckDiskConfigAddress", since
AgainstDomain doesn't hint much, but it's not a big deal.

Reviewed-by: Erik Skultety <eskultet@redhat.com>

> +                                 const virDomainDiskDef *disk)
> +{
> +    if (virDomainSCSIDriveAddressIsUsed(def, &disk->info.addr.drive)) {
> +        virReportError(VIR_ERR_OPERATION_INVALID, "%s",
> +                       _("Domain already contains a disk with that address"));
> +        return -1;
> +    }
> +
> +    return 0;
> +}
> +
> +
>  static int
>  qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef,
>                               virDomainDeviceDefPtr dev,
> @@ -8110,6 +8125,8 @@ qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef,
>              return -1;
>          if (qemuCheckDiskConfig(disk, NULL) < 0)
>              return -1;
> +        if (qemuCheckDiskConfigAgainstDomain(vmdef, disk) < 0)
> +            return -1;
>          if (virDomainDiskInsert(vmdef, disk) < 0)
>              return -1;
>          /* vmdef has the pointer. Generic codes for vmdef will do all jobs */
> --
> 2.21.0
>
> --
> libvir-list mailing list
> libvir-list@redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list