[PATCH] blkparse: don't do partial reads in read_data()
authorJens Axboe <axboe@suse.de>
Tue, 31 Jan 2006 08:11:01 +0000 (09:11 +0100)
committerJens Axboe <axboe@suse.de>
Tue, 31 Jan 2006 08:11:01 +0000 (09:11 +0100)
If we do a partial read, the trace may look ok because the magic is there,
but we will have lost it and the next read() will be confused. So only
return early if we read zero bytes and we must not block, otherwise wait
around for the remaining data.

blkparse.c

index 459fdee7ecd2111136d181ce277ae9745ddf3b58..5af31a7ae69e9b5832445f728409372412411531 100644 (file)
@@ -1723,7 +1723,16 @@ static int read_data(int fd, void *buffer, int bytes, int block)
                        if (errno != EAGAIN)
                                perror("read");
 
-                       return -1;
+                       /*
+                        * never do partial reads. we can return if we
+                        * didn't read anything and we should not block,
+                        * otherwise wait for data
+                        */
+                       if ((bytes_left == bytes) && !block)
+                               return 1;
+
+                       usleep(10);
+                       continue;
                } else {
                        p += ret;
                        bytes_left -= ret;