From: Stefan Hajnoczi <stefanha@gmail.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: pbonzini@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com,
lcapitulino@redhat.com
Subject: Re: [Qemu-devel] [PATCH 05/16] qemu-io: Don't use global bs in command implementations
Date: Wed, 5 Jun 2013 14:28:39 +0200 [thread overview]
Message-ID: <20130605122839.GA31478@stefanha-thinkpad.muc.redhat.com> (raw)
In-Reply-To: <1369754856-30036-6-git-send-email-kwolf@redhat.com>
On Tue, May 28, 2013 at 05:27:25PM +0200, Kevin Wolf wrote:
> Pass in the BlockDriverState to the command handlers instead of using
> the global variable. This is an important step to make the commands
> usable outside of qemu-io.
>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
> cmd.c | 6 ++-
> cmd.h | 8 ++-
> qemu-io.c | 165 ++++++++++++++++++++++++++++++++++----------------------------
> 3 files changed, 100 insertions(+), 79 deletions(-)
>
> diff --git a/cmd.c b/cmd.c
> index 214c6f7..d501aab 100644
> --- a/cmd.c
> +++ b/cmd.c
> @@ -57,7 +57,7 @@ check_command(
> const cmdinfo_t *ci)
> {
> if (check_func)
> - return check_func(ci);
> + return check_func(qemuio_bs, ci);
> return 1;
> }
>
> @@ -103,7 +103,7 @@ command(
> return 0;
> }
> optind = 0;
> - return ct->cfunc(argc, argv);
> + return ct->cfunc(qemuio_bs, argc, argv);
> }
>
> const cmdinfo_t *
> @@ -452,6 +452,7 @@ static cmdinfo_t quit_cmd;
> /* ARGSUSED */
> static int
> quit_f(
> + BlockDriverState *bs,
> int argc,
tabs vs spaces. I try to keep the existing style unless I decide to
reformat the entire section of code.
Not trying to start a flamewar but this file appears to use tabs and IMO
you should stick to that instead of mixing spaces :-).
> char **argv)
> {
> @@ -490,6 +491,7 @@ help_all(void)
>
> static int
> help_f(
> + BlockDriverState *bs,
> int argc,
> char **argv)
> {
> diff --git a/cmd.h b/cmd.h
> index 4dcfe88..ccf6336 100644
> --- a/cmd.h
> +++ b/cmd.h
> @@ -17,9 +17,13 @@
> #ifndef __COMMAND_H__
> #define __COMMAND_H__
>
> +#include "qemu-common.h"
> +
> #define CMD_FLAG_GLOBAL ((int)0x80000000) /* don't iterate "args" */
>
> -typedef int (*cfunc_t)(int argc, char **argv);
> +extern BlockDriverState *qemuio_bs;
> +
> +typedef int (*cfunc_t)(BlockDriverState *bs, int argc, char **argv);
> typedef void (*helpfunc_t)(void);
>
> typedef struct cmdinfo {
> @@ -41,7 +45,7 @@ extern int ncmds;
> void help_init(void);
> void quit_init(void);
>
> -typedef int (*checkfunc_t)(const cmdinfo_t *ci);
> +typedef int (*checkfunc_t)(BlockDriverState *bs, const cmdinfo_t *ci);
>
> void add_command(const cmdinfo_t *ci);
> void add_user_command(char *optarg);
cmd.h does not know about the block layer. I would use void *opaque
instead of BlockDriverState *bs. That way the file stays generic and
can be used in other command-line tools.
next prev parent reply other threads:[~2013-06-05 12:28 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-28 15:27 [Qemu-devel] [PATCH 00/16] Make qemu-io commands available in the monitor Kevin Wolf
2013-05-28 15:27 ` [Qemu-devel] [PATCH 01/16] qemu-io: Remove unused args_command Kevin Wolf
2013-05-28 16:18 ` Eric Blake
2013-05-28 15:27 ` [Qemu-devel] [PATCH 02/16] cutils: Support 'P' and 'E' suffixes in strtosz() Kevin Wolf
2013-05-28 16:29 ` Eric Blake
2013-05-28 15:27 ` [Qemu-devel] [PATCH 03/16] qemu-io: Make cvtnum() a wrapper around strtosz_suffix() Kevin Wolf
2013-05-28 16:42 ` Eric Blake
2013-05-28 15:27 ` [Qemu-devel] [PATCH 04/16] qemu-io: Handle cvtnum() errors in 'alloc' Kevin Wolf
2013-05-28 16:53 ` Eric Blake
2013-05-28 15:27 ` [Qemu-devel] [PATCH 05/16] qemu-io: Don't use global bs in command implementations Kevin Wolf
2013-05-28 15:37 ` Kevin Wolf
2013-05-28 17:02 ` Eric Blake
2013-06-05 12:28 ` Stefan Hajnoczi [this message]
2013-06-05 12:39 ` Kevin Wolf
2013-05-28 15:27 ` [Qemu-devel] [PATCH 06/16] qemu-io: Split off commands to qemu-io-cmds.c Kevin Wolf
2013-05-29 20:29 ` Eric Blake
2013-06-04 10:11 ` Kevin Wolf
2013-05-28 15:27 ` [Qemu-devel] [PATCH 07/16] qemu-io: Factor out qemuio_command Kevin Wolf
2013-05-29 21:11 ` Eric Blake
2013-06-05 12:33 ` Stefan Hajnoczi
2013-05-28 15:27 ` [Qemu-devel] [PATCH 08/16] qemu-io: Move 'help' function Kevin Wolf
2013-05-29 21:25 ` Eric Blake
2013-06-04 10:20 ` Kevin Wolf
2013-06-05 12:37 ` Stefan Hajnoczi
2013-05-28 15:27 ` [Qemu-devel] [PATCH 09/16] qemu-io: Move 'quit' function Kevin Wolf
2013-05-29 22:11 ` Eric Blake
2013-05-28 15:27 ` [Qemu-devel] [PATCH 10/16] qemu-io: Move qemu_strsep() to cutils.c Kevin Wolf
2013-05-29 22:12 ` Eric Blake
2013-05-28 15:27 ` [Qemu-devel] [PATCH 11/16] qemu-io: Move functions for registering and running commands Kevin Wolf
2013-05-30 2:27 ` Eric Blake
2013-06-05 12:42 ` Stefan Hajnoczi
2013-05-28 15:27 ` [Qemu-devel] [PATCH 12/16] qemu-io: Move command_loop() and friends Kevin Wolf
2013-05-28 15:27 ` [Qemu-devel] [PATCH 13/16] qemu-io: Move remaining helpers from cmd.c Kevin Wolf
2013-05-28 15:27 ` [Qemu-devel] [PATCH 14/16] qemu-io: Interface cleanup Kevin Wolf
2013-05-28 15:27 ` [Qemu-devel] [PATCH 15/16] qemu-io: Use the qemu version for -V Kevin Wolf
2013-05-28 15:27 ` [Qemu-devel] [PATCH 16/16] Make qemu-io commands available in the monitor Kevin Wolf
2013-05-28 16:07 ` Eric Blake
2013-05-29 8:13 ` Kevin Wolf
2013-05-29 12:05 ` Eric Blake
2013-05-29 17:51 ` Luiz Capitulino
2013-06-04 10:08 ` Kevin Wolf
2013-06-04 12:40 ` Luiz Capitulino
2013-06-04 12:49 ` Kevin Wolf
2013-06-04 13:09 ` Luiz Capitulino
2013-06-05 13:02 ` [Qemu-devel] [PATCH 00/16] " Stefan Hajnoczi
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=20130605122839.GA31478@stefanha-thinkpad.muc.redhat.com \
--to=stefanha@gmail.com \
--cc=kwolf@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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).