[libvirt] [PATCH 5/6] qemu: Format 'write-cache' parameter for disk frontends

John Ferlan jferlan at redhat.com
Wed Apr 11 15:19:34 UTC 2018



On 04/04/2018 04:13 AM, Peter Krempa wrote:
> The disk cache mode translates to various frontend and backend
> attributes for the qemu block layer. For the frontend device the
> 'writeback' parameter is used and provided as 'write-cache'. Implement
> this so that we can later switch to using -blockdev where we will not
> pass the cachemode directly any more.
> 
> Signed-off-by: Peter Krempa <pkrempa at redhat.com>
> ---
>  src/qemu/qemu_command.c | 27 +++++++++++++++++++++++++++
>  1 file changed, 27 insertions(+)
> 
> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> index bbd3cd0a7d..83e263e9f9 100644
> --- a/src/qemu/qemu_command.c
> +++ b/src/qemu/qemu_command.c
> @@ -1882,6 +1882,30 @@ qemuCheckIOThreads(const virDomainDef *def,
>  }
> 
> 
> +static int
> +qemuBuildDriveDevCacheStr(virDomainDiskDefPtr disk,
> +                          virBufferPtr buf,
> +                          virQEMUCapsPtr qemuCaps)
> +{
> +    bool wb;
> +
> +    if (disk->cachemode == VIR_DOMAIN_DISK_CACHE_DEFAULT)
> +        return 0;
> +
> +    if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DISK_WRITE_CACHE))
> +        return 0;

As I noted in patch 4 - this is checking a bit that's defined in QEMU
2.7 on some arches, but the test in patch 6 (probably should be in this
patch) would seem to indicate QEMU 2.12 is required.

> +
> +    if (qemuDomainDiskCachemodeFlags(disk->cachemode, &wb, NULL, NULL) < 0)
> +        return -1;

Wouldn't bother with -1 since we already know that cachemode will be
valid (e.g. from my comments in patch 4).


John

> +
> +    virBufferStrcat(buf, ",write-cache=",
> +                    virTristateSwitchTypeToString(virTristateSwitchFromBool(wb)),
> +                    NULL);
> +
> +    return 0;
> +}
> +
> +
>  char *
>  qemuBuildDriveDevStr(const virDomainDef *def,
>                       virDomainDiskDefPtr disk,
> @@ -2194,6 +2218,9 @@ qemuBuildDriveDevStr(const virDomainDef *def,
>          }
>      }
> 
> +    if (qemuBuildDriveDevCacheStr(disk, &opt, qemuCaps) < 0)
> +        goto error;
> +
>      if (virBufferCheckError(&opt) < 0)
>          goto error;
> 




More information about the libvir-list mailing list