qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 1/3] cow: use pread/pwrite
  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
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2010-05-07 15:17 UTC (permalink / raw)
  To: qemu-devel

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++)

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Qemu-devel] [PATCH 1/3] cow: use pread/pwrite
@ 2010-06-07 10:06 Christoph Hellwig
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2010-06-07 10:06 UTC (permalink / raw)
  To: qemu-devel

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++)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-06-07 10:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-07 10:06 [Qemu-devel] [PATCH 1/3] cow: use pread/pwrite Christoph Hellwig
  -- strict thread matches above, loose matches on Subject: below --
2010-05-07 15:16 [Qemu-devel] [PATCH 0/3] cow conversion to the block API Christoph Hellwig
2010-05-07 15:17 ` [Qemu-devel] [PATCH 1/3] cow: use pread/pwrite Christoph Hellwig

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).