[RFC,05/18] qemu-storage-daemon: Add --blockdev option
diff mbox series

Message ID 20191017130204.16131-6-kwolf@redhat.com
State New
Headers show
Series
  • Add qemu-storage-daemon
Related show

Commit Message

Kevin Wolf Oct. 17, 2019, 1:01 p.m. UTC
This adds a --blockdev option to the storage daemon that works the same
as the -blockdev option of the system emulator.

In order to be able to link with blockdev.o, we also need to change
stream.o from common-obj to block-obj, which is where all other block
jobs already are.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 qemu-storage-daemon.c | 29 +++++++++++++++++++++++++++++
 Makefile              |  5 ++++-
 Makefile.objs         |  7 +++++++
 block/Makefile.objs   |  2 +-
 4 files changed, 41 insertions(+), 2 deletions(-)

Comments

Markus Armbruster Nov. 8, 2019, 1:29 p.m. UTC | #1
Kevin Wolf <kwolf@redhat.com> writes:

> This adds a --blockdev option to the storage daemon that works the same
> as the -blockdev option of the system emulator.
>
> In order to be able to link with blockdev.o, we also need to change
> stream.o from common-obj to block-obj, which is where all other block
> jobs already are.
>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  qemu-storage-daemon.c | 29 +++++++++++++++++++++++++++++
>  Makefile              |  5 ++++-
>  Makefile.objs         |  7 +++++++
>  block/Makefile.objs   |  2 +-
>  4 files changed, 41 insertions(+), 2 deletions(-)
>
> diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c
> index 48d6af43a6..904e3c3a46 100644
> --- a/qemu-storage-daemon.c
> +++ b/qemu-storage-daemon.c
> @@ -28,6 +28,10 @@
>  #include "crypto/init.h"
>  
>  #include "qapi/error.h"
> +#include "qapi/qapi-visit-block-core.h"
> +#include "qapi/qapi-commands-block-core.h"
> +#include "qapi/qobject-input-visitor.h"
> +
>  #include "qemu-common.h"
>  #include "qemu-version.h"
>  #include "qemu/config-file.h"
> @@ -53,6 +57,13 @@ static void help(void)
>  "                         specify tracing options\n"
>  "  -V, --version          output version information and exit\n"
>  "\n"
> +"  --blockdev [driver=]<driver>[,node-name=<N>][,discard=ignore|unmap]\n"
> +"             [,cache.direct=on|off][,cache.no-flush=on|off]\n"
> +"             [,read-only=on|off][,auto-read-only=on|off]\n"
> +"             [,force-share=on|off][,detect-zeroes=on|off|unmap]\n"
> +"             [,driver specific parameters...]\n"
> +"                         configure a block backend\n"
> +"\n"
>  "  --object <properties>  define a QOM object such as 'secret' for\n"
>  "                         passwords and/or encryption keys\n"
>  "\n"
> @@ -62,6 +73,7 @@ QEMU_HELP_BOTTOM "\n",
>  
>  enum {
>      OPTION_OBJECT = 256,
> +    OPTION_BLOCKDEV,
>  };
>  
>  static QemuOptsList qemu_object_opts = {
> @@ -82,6 +94,7 @@ static int process_options(int argc, char *argv[], Error **errp)
>      static const struct option long_options[] = {
>          {"help", no_argument, 0, 'h'},
>          {"object", required_argument, 0, OPTION_OBJECT},
> +        {"blockdev", required_argument, 0, OPTION_BLOCKDEV},
>          {"version", no_argument, 0, 'V'},
>          {"trace", required_argument, NULL, 'T'},
>          {0, 0, 0, 0}
> @@ -123,6 +136,22 @@ static int process_options(int argc, char *argv[], Error **errp)
>                  qemu_opts_del(opts);
>                  break;
>              }
> +            break;
> +        case OPTION_BLOCKDEV:
> +            {
> +                Visitor *v;
> +                BlockdevOptions *options;
> +
> +                v = qobject_input_visitor_new_str(optarg, "driver",
> +                                                  &error_fatal);
> +
> +                visit_type_BlockdevOptions(v, NULL, &options, &error_fatal);
> +                visit_free(v);
> +
> +                qmp_blockdev_add(options, &error_fatal);
> +                qapi_free_BlockdevOptions(options);
> +                break;
> +            }
>          }
>      }
>      if (optind != argc) {

Unlike --object, --blockdev is already QAPIfied, albeit crudely.

Similar difference to vl.c as for --object: vl.c records the option for
later processing, while here you process it right away.  Simpler and
saner.

I figure you intend to do all options this way.

Should you explain the difference in a commit message?  A comment?

[...]

Patch
diff mbox series

diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c
index 48d6af43a6..904e3c3a46 100644
--- a/qemu-storage-daemon.c
+++ b/qemu-storage-daemon.c
@@ -28,6 +28,10 @@ 
 #include "crypto/init.h"
 
 #include "qapi/error.h"
+#include "qapi/qapi-visit-block-core.h"
+#include "qapi/qapi-commands-block-core.h"
+#include "qapi/qobject-input-visitor.h"
+
 #include "qemu-common.h"
 #include "qemu-version.h"
 #include "qemu/config-file.h"
@@ -53,6 +57,13 @@  static void help(void)
 "                         specify tracing options\n"
 "  -V, --version          output version information and exit\n"
 "\n"
+"  --blockdev [driver=]<driver>[,node-name=<N>][,discard=ignore|unmap]\n"
+"             [,cache.direct=on|off][,cache.no-flush=on|off]\n"
+"             [,read-only=on|off][,auto-read-only=on|off]\n"
+"             [,force-share=on|off][,detect-zeroes=on|off|unmap]\n"
+"             [,driver specific parameters...]\n"
+"                         configure a block backend\n"
+"\n"
 "  --object <properties>  define a QOM object such as 'secret' for\n"
 "                         passwords and/or encryption keys\n"
 "\n"
@@ -62,6 +73,7 @@  QEMU_HELP_BOTTOM "\n",
 
 enum {
     OPTION_OBJECT = 256,
+    OPTION_BLOCKDEV,
 };
 
 static QemuOptsList qemu_object_opts = {
@@ -82,6 +94,7 @@  static int process_options(int argc, char *argv[], Error **errp)
     static const struct option long_options[] = {
         {"help", no_argument, 0, 'h'},
         {"object", required_argument, 0, OPTION_OBJECT},
+        {"blockdev", required_argument, 0, OPTION_BLOCKDEV},
         {"version", no_argument, 0, 'V'},
         {"trace", required_argument, NULL, 'T'},
         {0, 0, 0, 0}
@@ -123,6 +136,22 @@  static int process_options(int argc, char *argv[], Error **errp)
                 qemu_opts_del(opts);
                 break;
             }
+            break;
+        case OPTION_BLOCKDEV:
+            {
+                Visitor *v;
+                BlockdevOptions *options;
+
+                v = qobject_input_visitor_new_str(optarg, "driver",
+                                                  &error_fatal);
+
+                visit_type_BlockdevOptions(v, NULL, &options, &error_fatal);
+                visit_free(v);
+
+                qmp_blockdev_add(options, &error_fatal);
+                qapi_free_BlockdevOptions(options);
+                break;
+            }
         }
     }
     if (optind != argc) {
diff --git a/Makefile b/Makefile
index 76338d0ab4..b913d4d736 100644
--- a/Makefile
+++ b/Makefile
@@ -432,6 +432,8 @@  dummy := $(call unnest-vars,, \
                 qga-vss-dll-obj-y \
                 block-obj-y \
                 block-obj-m \
+                storage-daemon-obj-y \
+                storage-daemon-obj-m \
                 crypto-obj-y \
                 crypto-user-obj-y \
                 qom-obj-y \
@@ -469,6 +471,7 @@  TARGET_DIRS_RULES := $(foreach t, all clean install, $(addsuffix /$(t), $(TARGET
 SOFTMMU_ALL_RULES=$(filter %-softmmu/all, $(TARGET_DIRS_RULES))
 $(SOFTMMU_ALL_RULES): $(authz-obj-y)
 $(SOFTMMU_ALL_RULES): $(block-obj-y)
+$(SOFTMMU_ALL_RULES): $(storage-daemon-obj-y)
 $(SOFTMMU_ALL_RULES): $(chardev-obj-y)
 $(SOFTMMU_ALL_RULES): $(crypto-obj-y)
 $(SOFTMMU_ALL_RULES): $(io-obj-y)
@@ -558,7 +561,7 @@  qemu-img.o: qemu-img-cmds.h
 qemu-img$(EXESUF): qemu-img.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS)
 qemu-nbd$(EXESUF): qemu-nbd.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS)
 qemu-io$(EXESUF): qemu-io.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS)
-qemu-storage-daemon$(EXESUF): qemu-storage-daemon.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS)
+qemu-storage-daemon$(EXESUF): qemu-storage-daemon.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(storage-daemon-obj-y) $(COMMON_LDADDS)
 
 qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o $(COMMON_LDADDS)
 
diff --git a/Makefile.objs b/Makefile.objs
index abcbd89654..00fdf54500 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -37,6 +37,13 @@  qom-obj-y = qom/
 
 io-obj-y = io/
 
+#######################################################################
+# storage-daemon-obj-y is code used by qemu-storage-daemon (these objects are
+# used for system emulation, too, but specified separately there)
+
+storage-daemon-obj-y = block/
+storage-daemon-obj-y += blockdev.o iothread.o
+
 ######################################################################
 # Target independent part of system emulation. The long term path is to
 # suppress *all* target specific code in case of system emulation, i.e. a
diff --git a/block/Makefile.objs b/block/Makefile.objs
index e394fe0b6c..d24fc93b7f 100644
--- a/block/Makefile.objs
+++ b/block/Makefile.objs
@@ -44,7 +44,7 @@  block-obj-y += crypto.o
 block-obj-y += aio_task.o
 block-obj-y += backup-top.o
 
-common-obj-y += stream.o
+block-obj-y += stream.o
 
 nfs.o-libs         := $(LIBNFS_LIBS)
 iscsi.o-cflags     := $(LIBISCSI_CFLAGS)