All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 1/3] cow: use pread/pwrite
Date: Fri, 7 May 2010 17:17:09 +0200	[thread overview]
Message-ID: <20100507151709.GA15249@lst.de> (raw)
In-Reply-To: <20100507151658.GA15132@lst.de>

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

Signed-off-by: Christoph Hellwig <hch@lst.de>

Index: qemu/block/cow.c
===================================================================
--- qemu.orig/block/cow.c	2010-05-04 19:11:24.897004616 +0200
+++ qemu/block/cow.c	2010-05-04 19:12:29.010255070 +0200
@@ -78,7 +78,7 @@ static int cow_open(BlockDriverState *bs
     }
     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
 
     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 *b
     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++)

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

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-07 15:16 [Qemu-devel] [PATCH 0/3] cow conversion to the block API Christoph Hellwig
2010-05-07 15:17 ` Christoph Hellwig [this message]
2010-05-07 15:17 ` [Qemu-devel] [PATCH 2/3] cow: stop using mmap Christoph Hellwig
2010-05-10  9:41   ` Kevin Wolf
2010-05-10 10:46     ` Christoph Hellwig
2010-05-07 15:17 ` [Qemu-devel] [PATCH 3/3] cow: use qemu block API Christoph Hellwig
  -- strict thread matches above, loose matches on Subject: below --
2010-06-07 10:06 [Qemu-devel] [PATCH 1/3] cow: use pread/pwrite 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=20100507151709.GA15249@lst.de \
    --to=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.