diff options
author | Keir Fraser <keir.fraser@citrix.com> | 2008-02-11 14:47:06 +0000 |
---|---|---|
committer | Keir Fraser <keir.fraser@citrix.com> | 2008-02-11 14:47:06 +0000 |
commit | 6193b2034d5adbd5ab0eac13326651108fe5e35b (patch) | |
tree | c7efcc039ce9c5180def8a05d2b9adec24d4a5f7 /tools | |
parent | 3f8e22de799b510d3ee20b730e4a30cc6c01dc6f (diff) | |
download | xen-6193b2034d5adbd5ab0eac13326651108fe5e35b.tar.gz xen-6193b2034d5adbd5ab0eac13326651108fe5e35b.tar.bz2 xen-6193b2034d5adbd5ab0eac13326651108fe5e35b.zip |
ioemu: cope with partial reads/writes when using the read()/write()
syscall interfaces.
Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/ioemu/block-raw.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/tools/ioemu/block-raw.c b/tools/ioemu/block-raw.c index 1ecf29cdb5..182d2ec55e 100644 --- a/tools/ioemu/block-raw.c +++ b/tools/ioemu/block-raw.c @@ -169,10 +169,16 @@ static int raw_pread(BlockDriverState *bs, int64_t offset, } 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 *bs, int64_t offset, } 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, |