From: Jens Axboe Date: Tue, 31 Jan 2006 08:11:01 +0000 (+0100) Subject: [PATCH] blkparse: don't do partial reads in read_data() X-Git-Tag: blktrace-0.99.1~91 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=5c0f40f757e864e11e2844955776dedd14e4d3cd;p=blktrace.git [PATCH] blkparse: don't do partial reads in read_data() 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. --- diff --git a/blkparse.c b/blkparse.c index 459fdee..5af31a7 100644 --- a/blkparse.c +++ b/blkparse.c @@ -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;