qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: qemu-devel@nongnu.org, pkrempa@redhat.com, armbru@redhat.com,
	qemu-block@nongnu.org, mreitz@redhat.com
Subject: Re: [RFC PATCH 01/18] qemu-storage-daemon: Add barebone tool
Date: Wed, 13 Nov 2019 15:12:01 +0100	[thread overview]
Message-ID: <20191113141201.GD6471@linux.fritz.box> (raw)
In-Reply-To: <f04318fd-0ae3-75ca-c08f-eb186d12ce80@redhat.com>

Am 24.10.2019 um 15:50 hat Eric Blake geschrieben:
> On 10/17/19 8:01 AM, 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 <kwolf@redhat.com>
> > ---
> >   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
> 
> > +++ b/qemu-storage-daemon.c
> > @@ -0,0 +1,141 @@
> > +/*
> > + * QEMU storage daemon
> > + *
> > + * Copyright (c) 2019 Kevin Wolf <kwolf@redhat.com>
> > + *
> > + * 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.
> 
> Is there an intent to license this binary as BSD (by restricting sources
> that can be linked in), or is it going to end up as GPLv2+ for other
> reasons? If the latter, would it be better to license this file GPLv2+?

The binary will be GPLv2 either way. Maybe even GPLv2+, not sure about
that.

This file copies quite a bit from qemu-img.c and vl.c, so I'm using the
same license as there. Of course, the "bug" in my patch is that I also
need to keep not only the license text, but also the actual copyright
line from there. Will fix.

> 
> > + */
> > +
> > +#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>
> 
> Shouldn't system headers appear right after qemu/osdep.h?

I wasn't aware of this, but CODING_STYLE.rst agrees with you.

> > +
> > +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'},
> 
> I find it harder to maintain lists of options (which will get longer over
> time) when the order of the struct...
> 
> > +        {0, 0, 0, 0}
> > +    };
> > +
> > +    while ((c = getopt_long(argc, argv, ":hT:V", long_options, NULL)) != -1) {
> 
> ...the order of the short options...
> 
> > +        switch (c) {
> > +        case '?':
> > +            error_setg(errp, "Unknown option '%s'", argv[optind - 1]);
> > +            goto out;
> > +        case ':':
> > +            error_setg(errp, "Missing option argument for '%s'",
> > +                       argv[optind - 1]);
> > +            goto out;
> > +        case 'h':
> > +            help();
> > +            exit(EXIT_SUCCESS);
> > +        case 'V':
> > +            printf("qemu-storage-daemon version "
> > +                   QEMU_FULL_VERSION "\n" QEMU_COPYRIGHT "\n");
> > +            exit(EXIT_SUCCESS);
> > +        case 'T':
> > +            g_free(trace_file);
> > +            trace_file = trace_opt_parse(optarg);
> > +            break;
> 
> ...and the order of the case statements are not identical. Case-insensitive
> alphabetical may be easiest (matching your shortopt ordering of ":hT:V").

Makes sense. (I think I tried to remember to keep things in alphabetical
order at least sometimes, but apparently I didn't try hard enough.)

> > +        }
> > +    }
> > +    if (optind != argc) {
> > +        error_setg(errp, "Unexpected argument: %s", argv[optind]);
> > +        goto out;
> > +    }
> > +
> > +    if (!trace_init_backends()) {
> > +        error_setg(errp, "Could not initialize trace backends");
> > +        goto out;
> > +    }
> > +    trace_init_file(trace_file);
> > +    qemu_set_log(LOG_TRACE);
> > +
> > +    ret = 0;
> > +out:
> > +    g_free(trace_file);
> 
> Mark trace_file as g_auto, and you can avoid the out: label altogether.

Oooh, magic! :-)

Kevin



  reply	other threads:[~2019-11-13 14:12 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-17 13:01 [RFC PATCH 00/18] Add qemu-storage-daemon Kevin Wolf
2019-10-17 13:01 ` [RFC PATCH 01/18] qemu-storage-daemon: Add barebone tool Kevin Wolf
2019-10-24 13:50   ` Eric Blake
2019-11-13 14:12     ` Kevin Wolf [this message]
2019-11-06 12:11   ` Max Reitz
2019-11-07 16:21   ` Markus Armbruster
2019-10-17 13:01 ` [RFC PATCH 02/18] qemu-storage-daemon: Add --object option Kevin Wolf
2019-11-07 20:36   ` Markus Armbruster
2019-11-14 12:05     ` Kevin Wolf
2019-11-18  9:10       ` Markus Armbruster
2019-10-17 13:01 ` [RFC PATCH 03/18] stubs: Add arch_type Kevin Wolf
2019-10-17 13:01 ` [RFC PATCH 04/18] stubs: Add blk_by_qdev_id() Kevin Wolf
2019-11-08  9:03   ` Markus Armbruster
2019-10-17 13:01 ` [RFC PATCH 05/18] qemu-storage-daemon: Add --blockdev option Kevin Wolf
2019-11-08 13:29   ` Markus Armbruster
2019-10-17 13:01 ` [RFC PATCH 06/18] qemu-storage-daemon: Add --nbd-server option Kevin Wolf
2019-11-06 12:51   ` Max Reitz
2019-11-06 19:25     ` Eric Blake
2019-11-07  8:33       ` Kevin Wolf
2019-11-07 13:45         ` Eric Blake
2019-11-07 15:27           ` Kevin Wolf
2019-11-07 15:36             ` Eric Blake
2019-11-08 15:36     ` Markus Armbruster
2019-10-17 13:01 ` [RFC PATCH 07/18] blockdev-nbd: Boxed argument type for nbd-server-add Kevin Wolf
2019-10-17 13:01 ` [RFC PATCH 08/18] qemu-storage-daemon: Add --export option Kevin Wolf
2019-11-06 13:11   ` Max Reitz
2019-11-06 13:34     ` Kevin Wolf
2019-11-06 13:39       ` Max Reitz
2019-11-08 15:57       ` Markus Armbruster
2019-10-17 13:01 ` [RFC PATCH 09/18] qemu-storage-daemon: Add main loop Kevin Wolf
2019-11-08 16:02   ` Markus Armbruster
2019-10-17 13:01 ` [RFC PATCH 10/18] qemu-storage-daemon: Add --chardev option Kevin Wolf
2019-11-08 16:27   ` Markus Armbruster
2019-10-17 13:01 ` [RFC PATCH 11/18] monitor: Move monitor option parsing to monitor/monitor.c Kevin Wolf
2019-10-17 13:01 ` [RFC PATCH 12/18] stubs: Update monitor stubs for qemu-storage-daemon Kevin Wolf
2019-11-08 16:45   ` Markus Armbruster
2019-10-17 13:01 ` [RFC PATCH 13/18] qapi: Create module 'monitor' Kevin Wolf
2019-11-11  9:36   ` Markus Armbruster
2019-10-17 13:02 ` [RFC PATCH 14/18] monitor: Create monitor/qmp-cmds-monitor.c Kevin Wolf
2019-10-17 13:02 ` [RFC PATCH 15/18] qapi: Support empty modules Kevin Wolf
2019-11-12  8:29   ` Markus Armbruster
2019-10-17 13:02 ` [RFC PATCH 16/18] qapi: Create 'pragma' module Kevin Wolf
2019-11-12  9:41   ` Markus Armbruster
2019-10-17 13:02 ` [RFC PATCH 17/18] monitor: Move qmp_query_qmp_schema to qmp-cmds-monitor.c Kevin Wolf
2019-10-17 13:02 ` [RFC PATCH 18/18] qemu-storage-daemon: Add --monitor option Kevin Wolf
2019-11-06 14:32   ` Max Reitz
2019-11-07 10:12     ` Kevin Wolf
2019-11-07 10:44       ` Max Reitz
2019-11-08  8:59   ` Markus Armbruster
2019-11-12 14:25   ` Markus Armbruster
2019-11-13 10:58     ` Kevin Wolf
2019-11-13 13:53       ` Markus Armbruster
2019-10-24 11:33 ` [RFC PATCH 00/18] Add qemu-storage-daemon Kevin Wolf
2019-10-24 13:55 ` Vladimir Sementsov-Ogievskiy
2019-11-14 10:44   ` Kevin Wolf
2019-11-05 15:52 ` Stefan Hajnoczi
2019-11-06 14:37 ` Max Reitz
2019-11-06 14:58   ` Kevin Wolf
2019-11-06 15:35     ` Max Reitz
2019-11-06 17:13     ` Eric Blake
2019-11-21 10:32     ` Stefan Hajnoczi
2019-11-21 11:08       ` Kevin Wolf
2019-12-12 11:16         ` Stefan Hajnoczi
2019-11-07 10:33 ` Daniel P. Berrangé
2019-11-07 12:03   ` Kevin Wolf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191113141201.GD6471@linux.fritz.box \
    --to=kwolf@redhat.com \
    --cc=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=pkrempa@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).