All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: Christoph Hellwig <hch@lst.de>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 5/6] parallels: use pread
Date: Wed, 05 May 2010 16:19:30 +0200	[thread overview]
Message-ID: <4BE17E72.4020308@redhat.com> (raw)
In-Reply-To: <20100504104504.GE6388@lst.de>

Am 04.05.2010 12:45, schrieb Christoph Hellwig:
> Use pread instead of lseek + read in preparation of using the qemu
> block API.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> 
> Index: qemu-kevin/block/parallels.c
> ===================================================================
> --- qemu-kevin.orig/block/parallels.c	2010-05-03 13:00:09.711253925 +0200
> +++ qemu-kevin/block/parallels.c	2010-05-03 13:04:15.686033993 +0200
> @@ -83,7 +83,7 @@ static int parallels_open(BlockDriverSta
>  
>      s->fd = fd;
>  
> -    if (read(fd, &ph, sizeof(ph)) != sizeof(ph))
> +    if (pread(fd, &ph, sizeof(ph), 0) != sizeof(ph))
>          goto fail;
>  
>      if (memcmp(ph.magic, HEADER_MAGIC, 16) ||
> @@ -93,14 +93,11 @@ static int parallels_open(BlockDriverSta
>  
>      bs->total_sectors = le32_to_cpu(ph.nb_sectors);
>  
> -    if (lseek(s->fd, 64, SEEK_SET) != 64)
> -	goto fail;
> -
>      s->tracks = le32_to_cpu(ph.tracks);
>  
>      s->catalog_size = le32_to_cpu(ph.catalog_entries);
>      s->catalog_bitmap = qemu_malloc(s->catalog_size * 4);
> -    if (read(s->fd, s->catalog_bitmap, s->catalog_size * 4) !=
> +    if (pread(s->fd, s->catalog_bitmap, s->catalog_size * 4, 64) !=
>  	s->catalog_size * 4)
>  	goto fail;
>      for (i = 0; i < s->catalog_size; i++)
> @@ -114,28 +111,18 @@ fail:
>      return -1;
>  }
>  
> -static inline int seek_to_sector(BlockDriverState *bs, int64_t sector_num)
> +static int64_t seek_to_sector(BlockDriverState *bs, int64_t sector_num)
>  {
>      BDRVParallelsState *s = bs->opaque;
>      uint32_t index, offset;
> -    uint64_t position;
>  
>      index = sector_num / s->tracks;
>      offset = sector_num % s->tracks;
>  
> -    // not allocated
> +    /* not allocated */
>      if ((index > s->catalog_size) || (s->catalog_bitmap[index] == 0))
>  	return -1;
> -
> -    position = (uint64_t)(s->catalog_bitmap[index] + offset) * 512;
> -
> -//    fprintf(stderr, "sector: %llx index=%x offset=%x pointer=%x position=%x\n",
> -//	sector_num, index, offset, s->catalog_bitmap[index], position);
> -
> -    if (lseek(s->fd, position, SEEK_SET) != position)
> -	return -1;
> -
> -    return 0;
> +    return (uint64_t)(s->catalog_bitmap[index] + offset) * 512;
>  }
>  
>  static int parallels_read(BlockDriverState *bs, int64_t sector_num,
> @@ -144,11 +131,13 @@ static int parallels_read(BlockDriverSta
>      BDRVParallelsState *s = bs->opaque;
>  
>      while (nb_sectors > 0) {
> -	if (!seek_to_sector(bs, sector_num)) {
> -	    if (read(s->fd, buf, 512) != 512)
> -		return -1;
> -	} else
> +        uint64_t position = seek_to_sector(bs, sector_num);
> +        if (position >= 0) {

position should be a signed int64_t, otherwise the condition is always true.

Kevin

  reply	other threads:[~2010-05-05 14:20 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-04 10:43 [Qemu-devel] simple block driver cleanups Christoph Hellwig
2010-05-04 10:44 ` [Qemu-devel] [PATCH 2/6] bochs: use qemu block API Christoph Hellwig
2010-05-04 10:44 ` [Qemu-devel] [PATCH 3/6] cloop: use pread Christoph Hellwig
2010-05-04 10:44 ` [Qemu-devel] [PATCH 4/6] cloop: use qemu block API Christoph Hellwig
2010-05-04 10:45 ` [Qemu-devel] [PATCH 5/6] parallels: use pread Christoph Hellwig
2010-05-05 14:19   ` Kevin Wolf [this message]
2010-05-05 18:11     ` Christoph Hellwig
2010-05-04 10:45 ` [Qemu-devel] [PATCH 6/6] parallels: use qemu block API Christoph Hellwig
2010-05-04 12:38 ` [Qemu-devel] simple block driver cleanups Kevin Wolf
2010-05-04 13:22   ` Christoph Hellwig
2010-05-05 14:28     ` Kevin Wolf
2010-05-05 18:10       ` Christoph Hellwig

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=4BE17E72.4020308@redhat.com \
    --to=kwolf@redhat.com \
    --cc=hch@lst.de \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.