All of lore.kernel.org
 help / color / mirror / Atom feed
From: Samuel Thibault <samuel.thibault@eu.citrix.com>
To: xen-devel@lists.xensource.com
Subject: [PATCH] ioemu: cope with partial reads/writes
Date: Mon, 11 Feb 2008 12:00:42 +0000	[thread overview]
Message-ID: <20080211120042.GA9475@implementation.uk.xensource.com> (raw)

ioemu: cope with partial reads/writes

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>

diff -r bab9e298450a tools/ioemu/block-raw.c
--- a/tools/ioemu/block-raw.c	Mon Feb 11 10:57:17 2008 +0000
+++ b/tools/ioemu/block-raw.c	Mon Feb 11 11:57:37 2008 +0000
@@ -169,10 +169,16 @@ static int raw_pread(BlockDriverState *b
     }
     s->lseek_err_cnt=0;
 
-    ret = read(s->fd, buf, count);
-    if (ret == count) 
-        goto label__raw_read__success;
+    uint64_t done;
+    for (done = 0; done < count; done += ret) {
+	ret = read(s->fd, buf + done, count - done);
+	if (ret == -1) 
+	    goto label__raw_read__error;
+    }
+    ret = count;
+    goto label__raw_read__success;
     
+label__raw_read__error:
     DEBUG_BLOCK_PRINT("raw_read(%d:%s, %" PRId64 ", %p, %d) [%" PRId64 "] read failed %d : %d = %s\n", 
         s->fd, 
         bs->filename, 
@@ -234,9 +240,16 @@ static int raw_pwrite(BlockDriverState *
     }
     s->lseek_err_cnt = 0;
 
-    ret = write(s->fd, buf, count);
-    if (ret == count) 
-        goto label__raw_write__success;
+    uint64_t done;
+    for (done = 0; done < count; done += ret) {
+	ret = write(s->fd, buf + done, count - done);
+	if (ret == -1) 
+	    goto label__raw_write__error;
+    }
+    ret = count;
+    goto label__raw_write__success;
+
+label__raw_write__error:
     
     DEBUG_BLOCK_PRINT("raw_write(%d:%s, %" PRId64 ", %p, %d) [%" PRId64 "] write failed %d : %d = %s\n", 
         s->fd, 

                 reply	other threads:[~2008-02-11 12:00 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20080211120042.GA9475@implementation.uk.xensource.com \
    --to=samuel.thibault@eu.citrix.com \
    --cc=xen-devel@lists.xensource.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.