From: Stefan Hajnoczi <stefanha@gmail.com>
To: Reda Sallahi <fullmanet@gmail.com>
Cc: qemu-devel@nongnu.org, Kevin Wolf <kwolf@redhat.com>,
Fam Zheng <famz@redhat.com>,
qemu-block@nongnu.org, Max Reitz <mreitz@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 2/7] qemu-img: add iflag and oflag options to dd
Date: Mon, 22 Aug 2016 09:26:52 -0400 [thread overview]
Message-ID: <20160822132652.GD28679@stefanha-x1.localdomain> (raw)
In-Reply-To: <20160822075517.5859-3-fullmanet@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1790 bytes --]
On Mon, Aug 22, 2016 at 09:55:12AM +0200, Reda Sallahi wrote:
> +static int img_dd_oflag(const char *arg,
> + struct DdIo *in, struct DdIo *out,
> + struct DdInfo *dd)
> +{
> + const char *tok;
> + char *str, *tmp;
> + int ret = 0;
> + const struct DdSymbols flags[] = {
> + { "direct", C_DIRECT },
> + { "dsync", C_DSYNC },
> + { "sync", C_IOFLAG_SYNC },
> + { "seek_bytes", C_SEEK_BYTES },
> + { NULL, 0 }
> + };
> +
> + tmp = str = g_strdup(arg);
> +
> + while (tmp != NULL && !ret) {
> + tok = qemu_strsep(&tmp, ",");
> + int j;
> + for (j = 0; flags[j].name != NULL; j++) {
> + if (!strcmp(tok, flags[j].name)) {
> + out->flags |= flags[j].value;
> + break;
> + }
> + }
> + if (flags[j].name == NULL) {
> + error_report("invalid output flag: '%s'", tok);
> + ret = 1;
> + }
> + }
> +
> + g_free(str);
> + return ret;
> +}
img_dd_iflag()/img_dd_oflag() are duplicated code. I suggest a single
helper function that parses a DdSymbols array into a DdIo->flags field.
Then you can pass in either the iflag or the oflag DdSymbols arrays.
static int img_dd_oflag(const char *arg,
struct DdIo *in, struct DdIo *out,
struct DdInfo *dd)
{
return img_dd_xflag(arg, (DdSymbols[]){
{ "direct", C_DIRECT },
{ "dsync", C_DSYNC },
...
}, in);
}
static int img_dd_oflag(const char *arg,
struct DdIo *in, struct DdIo *out,
struct DdInfo *dd)
{
return img_dd_xflag(arg, (DdSymbols[]){
{ "direct", C_DIRECT },
{ "dsync", C_DSYNC },
...
}, out);
}
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
next prev parent reply other threads:[~2016-08-22 13:26 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-22 7:55 [Qemu-devel] [PATCH 0/7] qemu-img dd Reda Sallahi
2016-08-22 7:55 ` [Qemu-devel] [PATCH 1/7] qemu-img: add seek option to dd Reda Sallahi
2016-08-22 13:06 ` Stefan Hajnoczi
2016-08-22 7:55 ` [Qemu-devel] [PATCH 2/7] qemu-img: add iflag and oflag options " Reda Sallahi
2016-08-22 13:26 ` Stefan Hajnoczi [this message]
2016-08-22 7:55 ` [Qemu-devel] [PATCH 3/7] qemu-img: add more conv= conversions " Reda Sallahi
2016-08-22 13:35 ` Stefan Hajnoczi
2016-08-22 14:02 ` Reda Sallahi
2016-08-23 16:03 ` Stefan Hajnoczi
2016-08-22 7:55 ` [Qemu-devel] [PATCH 4/7] qemu-img: delete not used variable and an unecessary check Reda Sallahi
2016-08-22 13:36 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2016-08-22 7:55 ` [Qemu-devel] [PATCH 5/7] qemu-img: add status option to dd Reda Sallahi
2016-08-22 13:45 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2016-08-22 13:50 ` [Qemu-devel] " Reda Sallahi
2016-08-22 7:55 ` [Qemu-devel] [PATCH 6/7] qemu-img: clean up dd documentation Reda Sallahi
2016-08-22 13:46 ` Stefan Hajnoczi
2016-08-22 7:55 ` [Qemu-devel] [PATCH 7/7] qemu-img: add a test suite for the count option Reda Sallahi
2016-08-22 13:46 ` 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=20160822132652.GD28679@stefanha-x1.localdomain \
--to=stefanha@gmail.com \
--cc=famz@redhat.com \
--cc=fullmanet@gmail.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--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).