# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1203343943 0
# Node ID 408acef82ffb5451bca9bd18fb5b3bf151eefc43
# Parent f2811c8c09f000b2a5724397492401dde4553da4
ioemu: cope with partial reads/writes when using the read()/write()
syscall interfaces.
Signed-off-by: Samuel Thibault <samuel.thibault@xxxxxxxxxxxxx>
xen-unstable changeset: 17018:a1b83b3b04491868d7e5aac594ed8ce0070d8c38
xen-unstable date: Mon Feb 11 14:47:06 2008 +0000
---
tools/ioemu/block-raw.c | 27 ++++++++++++++++++++-------
1 files changed, 20 insertions(+), 7 deletions(-)
diff -r f2811c8c09f0 -r 408acef82ffb tools/ioemu/block-raw.c
--- a/tools/ioemu/block-raw.c Mon Feb 18 14:09:56 2008 +0000
+++ b/tools/ioemu/block-raw.c Mon Feb 18 14:12:23 2008 +0000
@@ -167,10 +167,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,
@@ -232,9 +238,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,
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|