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 3/7] qemu-img: add more conv= conversions to dd
Date: Mon, 22 Aug 2016 09:35:26 -0400 [thread overview]
Message-ID: <20160822133526.GE28679@stefanha-x1.localdomain> (raw)
In-Reply-To: <20160822075517.5859-4-fullmanet@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2489 bytes --]
On Mon, Aug 22, 2016 at 09:55:13AM +0200, Reda Sallahi wrote:
> static int img_dd_conv(const char *arg,
> struct DdIo *in, struct DdIo *out,
> struct DdInfo *dd)
> {
> - if (!strcmp(arg, "notrunc")) {
> - dd->conv |= C_NOTRUNC;
> - return 0;
> - } else {
> - error_report("invalid conversion: '%s'", arg);
> - return 1;
> + const char *tok;
> + char *str, *tmp;
> + int ret = 0;
> + const struct DdSymbols conv[] = {
> + { "notrunc", C_NOTRUNC },
> + { "sync", C_SYNC },
> + { "noerror", C_NOERROR },
> + { "fdatasync", C_FDATASYNC },
> + { "fsync", C_FSYNC },
> + { "excl", C_EXCL },
> + { "nocreat", C_NOCREAT },
> + { "sparse", C_SPARSE },
> + { NULL, 0 }
> + };
> +
> + tmp = str = g_strdup(arg);
> +
> + while (tmp != NULL && !ret) {
> + tok = qemu_strsep(&tmp, ",");
> + int j;
> + for (j = 0; conv[j].name != NULL; j++) {
> + if (!strcmp(tok, conv[j].name)) {
> + if ((dd->conv | conv[j].value) & C_EXCL &&
> + (dd->conv | conv[j].value) & C_NOCREAT) {
> + error_report("cannot combine excl and nocreat");
> + ret = 1;
> + break;
> + }
> + dd->conv |= conv[j].value;
> + break;
> + }
> + }
> + if (conv[j].name == NULL) {
> + error_report("invalid conversion: '%s'", tok);
> + ret = 1;
> + }
> }
> +
> + g_free(str);
> + return ret;
> }
This function is very similar to img_dd_iflag/oflag. The code
duplication can be avoided if you perform the (dd->conv | conv[j].value)
& C_EXCL && (dd->conv | conv[j].value) & C_NOCREAT later.
> @@ -4325,20 +4388,43 @@ static int img_dd(int argc, char **argv)
>
> for (out_pos = out.offset * obsz; in_pos < size; block_count++) {
> int in_ret, out_ret;
> + bsz = in.bsz;
>
> if (in_pos + in.bsz > size) {
> - in_ret = blk_pread(blk1, in_pos, in.buf, size - in_pos);
> - } else {
> - in_ret = blk_pread(blk1, in_pos, in.buf, in.bsz);
> + bsz = size - in_pos;
> + }
> +
> + if (dd.conv & C_SYNC) {
> + memset(in.buf, 0, in.bsz);
> }
Why is memset necessary?
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
next prev parent reply other threads:[~2016-08-22 13:35 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
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 [this message]
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=20160822133526.GE28679@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).