From f9674fc2928586d07b60ef0d46dcd0dce417955d Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Tue, 14 Feb 2012 11:13:39 +0100 Subject: [PATCH 14/99] cow: use pread/pwrite RH-Author: Kevin Wolf Message-id: <1329218101-24213-15-git-send-email-kwolf@redhat.com> Patchwork-id: 37208 O-Subject: [RHEL-6.3 qemu-kvm PATCH v2 14/96] cow: use pread/pwrite Bugzilla: 783950 RH-Acked-by: Paolo Bonzini RH-Acked-by: Marcelo Tosatti RH-Acked-by: Laszlo Ersek From: Christoph Hellwig Bugzilla: 783950 Use pread/pwrite instead of lseek + read/write in preparation of using the qemu block API. Signed-off-by: Christoph Hellwig Signed-off-by: Kevin Wolf (cherry picked from commit 122bb9e32df488accad35ce6a52c3a2a5c33e4be) --- block/cow.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) Signed-off-by: Michal Novotny --- block/cow.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/block/cow.c b/block/cow.c index 8e21f02..932daee 100644 --- a/block/cow.c +++ b/block/cow.c @@ -78,7 +78,7 @@ static int cow_open(BlockDriverState *bs, const char *filename, int flags) } s->fd = fd; /* see if it is a cow image */ - if (read(fd, &cow_header, sizeof(cow_header)) != sizeof(cow_header)) { + if (pread(fd, &cow_header, sizeof(cow_header), 0) != sizeof(cow_header)) { goto fail; } @@ -159,8 +159,8 @@ static int cow_read(BlockDriverState *bs, int64_t sector_num, while (nb_sectors > 0) { if (is_changed(s->cow_bitmap, sector_num, nb_sectors, &n)) { - lseek(s->fd, s->cow_sectors_offset + sector_num * 512, SEEK_SET); - ret = read(s->fd, buf, n * 512); + ret = pread(s->fd, buf, n * 512, + s->cow_sectors_offset + sector_num * 512); if (ret != n * 512) return -1; } else { @@ -186,8 +186,8 @@ static int cow_write(BlockDriverState *bs, int64_t sector_num, BDRVCowState *s = bs->opaque; int ret, i; - lseek(s->fd, s->cow_sectors_offset + sector_num * 512, SEEK_SET); - ret = write(s->fd, buf, nb_sectors * 512); + ret = pwrite(s->fd, buf, nb_sectors * 512, + s->cow_sectors_offset + sector_num * 512); if (ret != nb_sectors * 512) return -1; for (i = 0; i < nb_sectors; i++) -- 1.7.7.5