[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 11/18] raw-posix: Use pread/pwrite instead of lseek+
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 11/18] raw-posix: Use pread/pwrite instead of lseek+read/write |
Date: |
Fri, 30 Apr 2010 16:00:33 +0200 |
From: Stefan Hajnoczi <address@hidden>
This patch combines the lseek+read/write calls to use pread/pwrite
instead. This will result in fewer system calls and is already used by
AIO.
Thanks to Jan Kiszka <address@hidden> for identifying excessive
lseek and Christoph Hellwig <address@hidden> for confirming that this
approach should work.
Signed-off-by: Stefan Hajnoczi <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/raw-posix.c | 37 ++++---------------------------------
1 files changed, 4 insertions(+), 33 deletions(-)
diff --git a/block/raw-posix.c b/block/raw-posix.c
index 598ea19..7541ed2 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -105,7 +105,6 @@
typedef struct BDRVRawState {
int fd;
int type;
- unsigned int lseek_err_cnt;
int open_flags;
#if defined(__linux__)
/* linux floppy specific */
@@ -134,8 +133,6 @@ static int raw_open_common(BlockDriverState *bs, const char
*filename,
BDRVRawState *s = bs->opaque;
int fd, ret;
- s->lseek_err_cnt = 0;
-
s->open_flags = open_flags | O_BINARY;
s->open_flags &= ~O_ACCMODE;
if (bdrv_flags & BDRV_O_RDWR) {
@@ -243,19 +240,7 @@ static int raw_pread_aligned(BlockDriverState *bs, int64_t
offset,
if (ret < 0)
return ret;
- if (offset >= 0 && lseek(s->fd, offset, SEEK_SET) == (off_t)-1) {
- ++(s->lseek_err_cnt);
- if(s->lseek_err_cnt <= 10) {
- DEBUG_BLOCK_PRINT("raw_pread(%d:%s, %" PRId64 ", %p, %d) [%" PRId64
- "] lseek failed : %d = %s\n",
- s->fd, bs->filename, offset, buf, count,
- bs->total_sectors, errno, strerror(errno));
- }
- return -1;
- }
- s->lseek_err_cnt=0;
-
- ret = read(s->fd, buf, count);
+ ret = pread(s->fd, buf, count, offset);
if (ret == count)
goto label__raw_read__success;
@@ -276,12 +261,10 @@ static int raw_pread_aligned(BlockDriverState *bs,
int64_t offset,
/* Try harder for CDrom. */
if (bs->type == BDRV_TYPE_CDROM) {
- lseek(s->fd, offset, SEEK_SET);
- ret = read(s->fd, buf, count);
+ ret = pread(s->fd, buf, count, offset);
if (ret == count)
goto label__raw_read__success;
- lseek(s->fd, offset, SEEK_SET);
- ret = read(s->fd, buf, count);
+ ret = pread(s->fd, buf, count, offset);
if (ret == count)
goto label__raw_read__success;
@@ -313,19 +296,7 @@ static int raw_pwrite_aligned(BlockDriverState *bs,
int64_t offset,
if (ret < 0)
return -errno;
- if (offset >= 0 && lseek(s->fd, offset, SEEK_SET) == (off_t)-1) {
- ++(s->lseek_err_cnt);
- if(s->lseek_err_cnt) {
- DEBUG_BLOCK_PRINT("raw_pwrite(%d:%s, %" PRId64 ", %p, %d) [%"
- PRId64 "] lseek failed : %d = %s\n",
- s->fd, bs->filename, offset, buf, count,
- bs->total_sectors, errno, strerror(errno));
- }
- return -EIO;
- }
- s->lseek_err_cnt = 0;
-
- ret = write(s->fd, buf, count);
+ ret = pwrite(s->fd, buf, count, offset);
if (ret == count)
goto label__raw_write__success;
--
1.6.6.1
- [Qemu-devel] [PATCH 01/18] block: separate raw images from the file protocol, (continued)
- [Qemu-devel] [PATCH 01/18] block: separate raw images from the file protocol, Kevin Wolf, 2010/04/30
- [Qemu-devel] [PATCH 02/18] block: Split bdrv_open, Kevin Wolf, 2010/04/30
- [Qemu-devel] [PATCH 03/18] block: Avoid forward declaration of bdrv_open_common, Kevin Wolf, 2010/04/30
- [Qemu-devel] [PATCH 05/18] block: bdrv_has_zero_init, Kevin Wolf, 2010/04/30
- [Qemu-devel] [PATCH 06/18] vmdk: Fix COW, Kevin Wolf, 2010/04/30
- [Qemu-devel] [PATCH 08/18] vmdk: Convert to bdrv_open, Kevin Wolf, 2010/04/30
- [Qemu-devel] [PATCH 07/18] vmdk: Clean up backing file handling, Kevin Wolf, 2010/04/30
- [Qemu-devel] [PATCH 04/18] block: Open the underlying image file in generic code, Kevin Wolf, 2010/04/30
- [Qemu-devel] [PATCH 09/18] block: Set backing_hd to NULL after deleting it, Kevin Wolf, 2010/04/30
- [Qemu-devel] [PATCH 10/18] qcow2: Avoid shadowing variable in alloc_clusters_noref(), Kevin Wolf, 2010/04/30
- [Qemu-devel] [PATCH 11/18] raw-posix: Use pread/pwrite instead of lseek+read/write,
Kevin Wolf <=
- [Qemu-devel] [PATCH 12/18] block: Cache total_sectors to reduce bdrv_getlength calls, Kevin Wolf, 2010/04/30
- [Qemu-devel] [PATCH 14/18] qcow2: Remove abort on free_clusters failure, Kevin Wolf, 2010/04/30
- [Qemu-devel] [PATCH 17/18] qemu-img rebase: Fix output image corruption, Kevin Wolf, 2010/04/30
- [Qemu-devel] [PATCH 15/18] qcow2: Implement bdrv_truncate() for growing images, Kevin Wolf, 2010/04/30
- [Qemu-devel] [PATCH 18/18] block: Release allocated options after bdrv_open, Kevin Wolf, 2010/04/30
- [Qemu-devel] [PATCH 13/18] qemu-img: Add 'resize' command to grow/shrink disk images, Kevin Wolf, 2010/04/30
- [Qemu-devel] [PATCH 16/18] block: Add wr_highest_sector blockstat, Kevin Wolf, 2010/04/30