Re: [Qemu-block] [Qemu-devel] [PATCH v3 23/38] blockdev: Pull out blockdev option extraction

2015-06-09 Thread Max Reitz

On 09.06.2015 02:37, Fam Zheng wrote:

On Wed, 06/03 21:44, Max Reitz wrote:

Extract some of the blockdev option extraction code from blockdev_init()
into its own function. This simplifies blockdev_init() and will allow
reusing the code in a different function added in a follow-up patch.

Signed-off-by: Max Reitz 
Reviewed-by: Eric Blake 
---
  blockdev.c | 201 +
  1 file changed, 108 insertions(+), 93 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index 8c91532..8d672ac 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -341,24 +341,123 @@ static bool check_throttle_config(ThrottleConfig *cfg, 
Error **errp)
  
  typedef enum { MEDIA_DISK, MEDIA_CDROM } DriveMediaType;
  
+static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags,

+ThrottleConfig *throttle_cfg, BlockdevDetectZeroesOptions *detect_zeroes,
+Error **errp)
+{
+const char *discard, *aio;

This breaks build without CONFIG_LINUX_AIO:

/home/fam/qemu/blockdev.c: In function ‘extract_common_blockdev_options’:
/home/fam/qemu/blockdev.c:348:27: error: unused variable ‘aio’ 
[-Werror=unused-variable]
  const char *discard, *aio;
^
cc1: all warnings being treated as errors


Thanks, I'll fix it.

Max


+Error *local_error = NULL;
+
+if (!qemu_opt_get_bool(opts, "read-only", false)) {
+*bdrv_flags |= BDRV_O_RDWR;
+}
+if (qemu_opt_get_bool(opts, "copy-on-read", false)) {
+*bdrv_flags |= BDRV_O_COPY_ON_READ;
+}
+
+if ((discard = qemu_opt_get(opts, "discard")) != NULL) {
+if (bdrv_parse_discard_flags(discard, bdrv_flags) != 0) {
+error_setg(errp, "Invalid discard option");
+return;
+}
+}
+
+if (qemu_opt_get_bool(opts, "cache.writeback", true)) {
+*bdrv_flags |= BDRV_O_CACHE_WB;
+}
+if (qemu_opt_get_bool(opts, "cache.direct", false)) {
+*bdrv_flags |= BDRV_O_NOCACHE;
+}
+if (qemu_opt_get_bool(opts, "cache.no-flush", false)) {
+*bdrv_flags |= BDRV_O_NO_FLUSH;
+}
+
+#ifdef CONFIG_LINUX_AIO
+if ((aio = qemu_opt_get(opts, "aio")) != NULL) {
+if (!strcmp(aio, "native")) {
+*bdrv_flags |= BDRV_O_NATIVE_AIO;
+} else if (!strcmp(aio, "threads")) {
+/* this is the default */
+} else {
+   error_setg(errp, "invalid aio option");
+   return;
+}
+}
+#endif

[snip]

Fam





Re: [Qemu-block] [Qemu-devel] [PATCH v3 23/38] blockdev: Pull out blockdev option extraction

2015-06-08 Thread Fam Zheng
On Wed, 06/03 21:44, Max Reitz wrote:
> Extract some of the blockdev option extraction code from blockdev_init()
> into its own function. This simplifies blockdev_init() and will allow
> reusing the code in a different function added in a follow-up patch.
> 
> Signed-off-by: Max Reitz 
> Reviewed-by: Eric Blake 
> ---
>  blockdev.c | 201 
> +
>  1 file changed, 108 insertions(+), 93 deletions(-)
> 
> diff --git a/blockdev.c b/blockdev.c
> index 8c91532..8d672ac 100644
> --- a/blockdev.c
> +++ b/blockdev.c
> @@ -341,24 +341,123 @@ static bool check_throttle_config(ThrottleConfig *cfg, 
> Error **errp)
>  
>  typedef enum { MEDIA_DISK, MEDIA_CDROM } DriveMediaType;
>  
> +static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags,
> +ThrottleConfig *throttle_cfg, BlockdevDetectZeroesOptions *detect_zeroes,
> +Error **errp)
> +{
> +const char *discard, *aio;

This breaks build without CONFIG_LINUX_AIO:

/home/fam/qemu/blockdev.c: In function ‘extract_common_blockdev_options’:
/home/fam/qemu/blockdev.c:348:27: error: unused variable ‘aio’ 
[-Werror=unused-variable]
 const char *discard, *aio;
   ^
cc1: all warnings being treated as errors

> +Error *local_error = NULL;
> +
> +if (!qemu_opt_get_bool(opts, "read-only", false)) {
> +*bdrv_flags |= BDRV_O_RDWR;
> +}
> +if (qemu_opt_get_bool(opts, "copy-on-read", false)) {
> +*bdrv_flags |= BDRV_O_COPY_ON_READ;
> +}
> +
> +if ((discard = qemu_opt_get(opts, "discard")) != NULL) {
> +if (bdrv_parse_discard_flags(discard, bdrv_flags) != 0) {
> +error_setg(errp, "Invalid discard option");
> +return;
> +}
> +}
> +
> +if (qemu_opt_get_bool(opts, "cache.writeback", true)) {
> +*bdrv_flags |= BDRV_O_CACHE_WB;
> +}
> +if (qemu_opt_get_bool(opts, "cache.direct", false)) {
> +*bdrv_flags |= BDRV_O_NOCACHE;
> +}
> +if (qemu_opt_get_bool(opts, "cache.no-flush", false)) {
> +*bdrv_flags |= BDRV_O_NO_FLUSH;
> +}
> +
> +#ifdef CONFIG_LINUX_AIO
> +if ((aio = qemu_opt_get(opts, "aio")) != NULL) {
> +if (!strcmp(aio, "native")) {
> +*bdrv_flags |= BDRV_O_NATIVE_AIO;
> +} else if (!strcmp(aio, "threads")) {
> +/* this is the default */
> +} else {
> +   error_setg(errp, "invalid aio option");
> +   return;
> +}
> +}
> +#endif

[snip]

Fam