[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [RFC PATCH 01/18] qemu-storage-daemon: Add barebone tool
From: |
Max Reitz |
Subject: |
Re: [RFC PATCH 01/18] qemu-storage-daemon: Add barebone tool |
Date: |
Wed, 6 Nov 2019 13:11:11 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.1 |
On 17.10.19 15:01, Kevin Wolf wrote:
> This adds a new binary qemu-storage-daemon that doesn't yet do more than
> some typical initialisation for tools and parsing the basic command
> options --version, --help and --trace.
>
> Signed-off-by: Kevin Wolf <address@hidden>
> ---
> configure | 2 +-
> qemu-storage-daemon.c | 141 ++++++++++++++++++++++++++++++++++++++++++
> Makefile | 1 +
> 3 files changed, 143 insertions(+), 1 deletion(-)
> create mode 100644 qemu-storage-daemon.c
>
> diff --git a/configure b/configure
> index 08ca4bcb46..bb3d55fb25 100755
> --- a/configure
> +++ b/configure
> @@ -6034,7 +6034,7 @@ tools=""
> if test "$want_tools" = "yes" ; then
> tools="qemu-img\$(EXESUF) qemu-io\$(EXESUF) qemu-edid\$(EXESUF) $tools"
> if [ "$linux" = "yes" -o "$bsd" = "yes" -o "$solaris" = "yes" ] ; then
> - tools="qemu-nbd\$(EXESUF) $tools"
> + tools="qemu-nbd\$(EXESUF) qemu-storage-daemon\$(EXESUF) $tools"
> fi
> if [ "$ivshmem" = "yes" ]; then
> tools="ivshmem-client\$(EXESUF) ivshmem-server\$(EXESUF) $tools"
> diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c
> new file mode 100644
> index 0000000000..a251dc255c
> --- /dev/null
> +++ b/qemu-storage-daemon.c
> @@ -0,0 +1,141 @@
> +/*
> + * QEMU storage daemon
> + *
> + * Copyright (c) 2019 Kevin Wolf <address@hidden>
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> copy
> + * of this software and associated documentation files (the "Software"), to
> deal
> + * in the Software without restriction, including without limitation the
> rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> + * THE SOFTWARE.
> + */
> +
> +#include "qemu/osdep.h"
> +
> +#include "block/block.h"
> +#include "crypto/init.h"
> +
> +#include "qapi/error.h"
> +#include "qemu-common.h"
> +#include "qemu-version.h"
> +#include "qemu/config-file.h"
> +#include "qemu/error-report.h"
> +#include "qemu/log.h"
> +#include "qemu/main-loop.h"
> +#include "qemu/module.h"
> +
> +#include "trace/control.h"
> +
> +#include <getopt.h>
> +
> +static void help(void)
> +{
> + printf(
> +"Usage: %s [options]\n"
> +"QEMU storage daemon\n"
> +"\n"
> +" -h, --help display this help and exit\n"
> +" -T, --trace [[enable=]<pattern>][,events=<file>][,file=<file>]\n"
> +" specify tracing options\n"
> +" -V, --version output version information and exit\n"
> +"\n"
> +QEMU_HELP_BOTTOM "\n",
> + error_get_progname());
> +}
> +
> +static int process_options(int argc, char *argv[], Error **errp)
> +{
> + int c;
> + char *trace_file = NULL;
> + int ret = -EINVAL;
> +
> + static const struct option long_options[] = {
> + {"help", no_argument, 0, 'h'},
> + {"version", no_argument, 0, 'V'},
> + {"trace", required_argument, NULL, 'T'},
> + {0, 0, 0, 0}
> + };
> +
> + while ((c = getopt_long(argc, argv, ":hT:V", long_options, NULL)) != -1)
> {
> + switch (c) {
> + case '?':
> + error_setg(errp, "Unknown option '%s'", argv[optind - 1]);
> + goto out;
Am I doing something wrong or is optind really not updated when '?' is
returned?
Because I’m getting this:
$ ./qemu-storage-daemon -42
qemu-storage-daemon: Unknown option './qemu-storage-daemon'
But OTOH I also get:
$ ./qemu-img create -42
qemu-img: unrecognized option 'create'
Try 'qemu-img --help' for more information
So, uh, well.
Max
signature.asc
Description: OpenPGP digital signature
- Re: [RFC PATCH 01/18] qemu-storage-daemon: Add barebone tool,
Max Reitz <=