qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Kevin Wolf" <kwolf@redhat.com>,
	"László Érsek" <lersek@redhat.com>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Max Reitz" <mreitz@redhat.com>
Subject: [Qemu-devel] [PATCH for-2.2 1/3] block/raw-posix: Fix preallocating write() loop
Date: Tue, 18 Nov 2014 11:23:04 +0100	[thread overview]
Message-ID: <1416306186-19053-2-git-send-email-mreitz@redhat.com> (raw)
In-Reply-To: <1416306186-19053-1-git-send-email-mreitz@redhat.com>

write() may write less bytes than requested; in this case, the number of
bytes written is returned. This is the byte count we should be
subtracting from the number of bytes still to be written, and not the
byte count we requested to write.

Reported-by: László Érsek <lersek@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
An interesting anecdote: My German man page for write(2) says the
following about its return value:

> Bei Erfolg wird Null zurückgegeben.

Which translates to:

> On success, zero is returned.

Whereas write(2) for LANG=C says the following (which is correct):

> On success, the number of bytes written is returned (zero indicates
> nothing was written).

I think I know why I somehow prefer the English versions...
---
 block/raw-posix.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/raw-posix.c b/block/raw-posix.c
index e100ae2..4e6552f 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1457,7 +1457,7 @@ static int raw_create(const char *filename, QemuOpts *opts, Error **errp)
                                  "Could not write to the new file");
                 break;
             }
-            left -= num;
+            left -= result;
         }
         fsync(fd);
         g_free(buf);
-- 
1.9.3

  reply	other threads:[~2014-11-18 10:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-18 10:23 [Qemu-devel] [PATCH for-2.2 0/3] block/raw-posix: Fixes for preallocation Max Reitz
2014-11-18 10:23 ` Max Reitz [this message]
2014-11-18 10:23 ` [Qemu-devel] [PATCH for-2.2 2/3] block/raw-posix: Only sync after successful preallocation Max Reitz
2014-11-18 10:23 ` [Qemu-devel] [PATCH for-2.2 3/3] block/raw-posix: Catch fsync() errors Max Reitz
2014-11-18 11:11 ` [Qemu-devel] [PATCH for-2.2 0/3] block/raw-posix: Fixes for preallocation 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=1416306186-19053-2-git-send-email-mreitz@redhat.com \
    --to=mreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=lersek@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).