qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: aliguori@linux.vnet.ibm.com
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 03/11] cloop: use pread
Date: Fri,  7 May 2010 17:13:59 +0200	[thread overview]
Message-ID: <1273245247-24827-4-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1273245247-24827-1-git-send-email-kwolf@redhat.com>

From: Christoph Hellwig <hch@lst.de>

Use pread instead of lseek + read in preparation of using the qemu
block API.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/cloop.c |   32 +++++++++++++++++---------------
 1 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/block/cloop.c b/block/cloop.c
index e4f995b..9fe2a42 100644
--- a/block/cloop.c
+++ b/block/cloop.c
@@ -62,23 +62,22 @@ static int cloop_open(BlockDriverState *bs, const char *filename, int flags)
     bs->read_only = 1;
 
     /* read header */
-    if(lseek(s->fd,128,SEEK_SET)<0) {
-cloop_close:
-	close(s->fd);
-	return -1;
+    if (pread(s->fd, &s->block_size, 4, 128) < 4) {
+        goto cloop_close;
     }
-    if(read(s->fd,&s->block_size,4)<4)
-	goto cloop_close;
-    s->block_size=be32_to_cpu(s->block_size);
-    if(read(s->fd,&s->n_blocks,4)<4)
-	goto cloop_close;
-    s->n_blocks=be32_to_cpu(s->n_blocks);
+    s->block_size = be32_to_cpu(s->block_size);
+
+    if (pread(s->fd, &s->n_blocks, 4, 128 + 4) < 4) {
+        goto cloop_close;
+    }
+    s->n_blocks = be32_to_cpu(s->n_blocks);
 
     /* read offsets */
-    offsets_size=s->n_blocks*sizeof(uint64_t);
-    s->offsets=(uint64_t*)qemu_malloc(offsets_size);
-    if(read(s->fd,s->offsets,offsets_size)<offsets_size)
+    offsets_size = s->n_blocks * sizeof(uint64_t);
+    s->offsets = qemu_malloc(offsets_size);
+    if (pread(s->fd, s->offsets, offsets_size, 128 + 4 + 4) < offsets_size) {
 	goto cloop_close;
+    }
     for(i=0;i<s->n_blocks;i++) {
 	s->offsets[i]=be64_to_cpu(s->offsets[i]);
 	if(i>0) {
@@ -98,6 +97,10 @@ cloop_close:
     s->sectors_per_block = s->block_size/512;
     bs->total_sectors = s->n_blocks*s->sectors_per_block;
     return 0;
+
+cloop_close:
+    close(s->fd);
+    return -1;
 }
 
 static inline int cloop_read_block(BDRVCloopState *s,int block_num)
@@ -106,8 +109,7 @@ static inline int cloop_read_block(BDRVCloopState *s,int block_num)
 	int ret;
         uint32_t bytes = s->offsets[block_num+1]-s->offsets[block_num];
 
-	lseek(s->fd, s->offsets[block_num], SEEK_SET);
-        ret = read(s->fd, s->compressed_block, bytes);
+        ret = pread(s->fd, s->compressed_block, bytes, s->offsets[block_num]);
         if (ret != bytes)
             return -1;
 
-- 
1.6.6.1

  parent reply	other threads:[~2010-05-07 15:15 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-07 15:13 [Qemu-devel] [PULL 00/11] Block patches Kevin Wolf
2010-05-07 15:13 ` [Qemu-devel] [PATCH 01/11] block: Remove semicolon in BDRV_SECTOR_MASK macro Kevin Wolf
2010-05-07 15:13 ` [Qemu-devel] [PATCH 02/11] qemu-nbd: Improve error reporting Kevin Wolf
2010-05-07 15:13 ` Kevin Wolf [this message]
2010-05-07 15:14 ` [Qemu-devel] [PATCH 04/11] cloop: use qemu block API Kevin Wolf
2010-05-07 15:14 ` [Qemu-devel] [PATCH 05/11] ide: Fix ide_dma_cancel Kevin Wolf
2010-05-07 15:14 ` [Qemu-devel] [PATCH 06/11] bochs: use pread Kevin Wolf
2010-05-07 15:14 ` [Qemu-devel] [PATCH 07/11] bochs: use qemu block API Kevin Wolf
2010-05-07 15:14 ` [Qemu-devel] [PATCH 08/11] block: Avoid unchecked casts for AIOCBs Kevin Wolf
2010-05-07 15:14 ` [Qemu-devel] [PATCH 09/11] block: Fix protocol detection for Windows devices Kevin Wolf
2010-05-07 15:14 ` [Qemu-devel] [PATCH 10/11] block: Fix bdrv_commit Kevin Wolf
2010-05-07 15:14 ` [Qemu-devel] [PATCH 11/11] block/vdi: Allow disk images of size 0 Kevin Wolf

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=1273245247-24827-4-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=aliguori@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).