Re: [PATCH v2 4/7] qemu: Transient option gets avaiable for qcow2 and raw format disk

2020-09-13 Thread Masayoshi Mizuma
On Tue, Sep 08, 2020 at 03:14:42PM +0200, Peter Krempa wrote:
> On Fri, Aug 28, 2020 at 10:08:33 -0400, Masayoshi Mizuma wrote:
> > From: Masayoshi Mizuma 
> > 
> > Signed-off-by: Masayoshi Mizuma 
> > ---
> >  src/qemu/qemu_validate.c | 9 ++---
> >  1 file changed, 6 insertions(+), 3 deletions(-)
> > 
> > diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
> > index 488f258d00..82818a4fdc 100644
> > --- a/src/qemu/qemu_validate.c
> > +++ b/src/qemu/qemu_validate.c
> > @@ -2166,9 +2166,12 @@ qemuValidateDomainDeviceDefDiskFrontend(const 
> > virDomainDiskDef *disk,
> >  }
> >  
> >  if (disk->transient) {
> > -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
> > -   _("transient disks not supported yet"));
> > -return -1;
> > +if ((disk->src->format != VIR_STORAGE_FILE_QCOW2) &&
> > +(disk->src->format != VIR_STORAGE_FILE_RAW)) {
> 
> This needs a check that QEMU_CAPS_BLOCKDEV is available as it won't
> really work properly in pre-blockdev config. Also here you
> should reject any other unsupported configuration rather than in the
> code.

Thanks. I'll add the following validation.

diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 070f1c962b..9cf78ca0c9 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -2002,6 +2002,28 @@ qemuValidateDomainDeviceDefDiskSerial(const char *value)
 }
 
 
+static int
+qemuValidateDomainDeviceDefDiskTransient(const virDomainDiskDef *disk,
+ virQEMUCapsPtr qemuCaps)
+{
+if ((!qemuCaps) || !virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV))
+return false;
+
+if (disk->src->readonly)
+return false;
+
+if ((disk->src->format != VIR_STORAGE_FILE_QCOW2) &&
+(disk->src->format != VIR_STORAGE_FILE_RAW) &&
+(disk->src->type != VIR_STORAGE_TYPE_FILE)) {
+return false;
+}
+
+if (virStorageSourceIsEmpty(disk->src))
+return false;
+
+return true;
+}
+
 static int
 qemuValidateDomainDeviceDefDiskFrontend(const virDomainDiskDef *disk,
 virQEMUCapsPtr qemuCaps)
@@ -2186,7 +2208,8 @@ qemuValidateDomainDeviceDefDiskFrontend(const 
virDomainDiskDef *disk,
 }
 }
 
-if (disk->transient) {
+if ((disk->transient) &&
+!qemuValidateDomainDeviceDefDiskTransient(disk, qemuCaps)) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("transient disks not supported yet"));
 return -1;




Re: [PATCH v2 4/7] qemu: Transient option gets avaiable for qcow2 and raw format disk

2020-09-08 Thread Peter Krempa
On Fri, Aug 28, 2020 at 10:08:33 -0400, Masayoshi Mizuma wrote:
> From: Masayoshi Mizuma 
> 
> Signed-off-by: Masayoshi Mizuma 
> ---
>  src/qemu/qemu_validate.c | 9 ++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
> index 488f258d00..82818a4fdc 100644
> --- a/src/qemu/qemu_validate.c
> +++ b/src/qemu/qemu_validate.c
> @@ -2166,9 +2166,12 @@ qemuValidateDomainDeviceDefDiskFrontend(const 
> virDomainDiskDef *disk,
>  }
>  
>  if (disk->transient) {
> -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
> -   _("transient disks not supported yet"));
> -return -1;
> +if ((disk->src->format != VIR_STORAGE_FILE_QCOW2) &&
> +(disk->src->format != VIR_STORAGE_FILE_RAW)) {

This needs a check that QEMU_CAPS_BLOCKDEV is available as it won't
really work properly in pre-blockdev config. Also here you
should reject any other unsupported configuration rather than in the
code.

> +virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
> +   _("transient disks not supported yet"));
> +return -1;
> +}
>  }
>  
>  if (disk->iomode == VIR_DOMAIN_DISK_IO_NATIVE &&
> -- 
> 2.27.0
> 




[PATCH v2 4/7] qemu: Transient option gets avaiable for qcow2 and raw format disk

2020-08-28 Thread Masayoshi Mizuma
From: Masayoshi Mizuma 

Signed-off-by: Masayoshi Mizuma 
---
 src/qemu/qemu_validate.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 488f258d00..82818a4fdc 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -2166,9 +2166,12 @@ qemuValidateDomainDeviceDefDiskFrontend(const 
virDomainDiskDef *disk,
 }
 
 if (disk->transient) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("transient disks not supported yet"));
-return -1;
+if ((disk->src->format != VIR_STORAGE_FILE_QCOW2) &&
+(disk->src->format != VIR_STORAGE_FILE_RAW)) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("transient disks not supported yet"));
+return -1;
+}
 }
 
 if (disk->iomode == VIR_DOMAIN_DISK_IO_NATIVE &&
-- 
2.27.0